!/usr/bin/env bash
add any rocks required for ci_tests to this list
lua-curl depends on a libcurl development package (i.e. libcurl4-openssl-dev)
!/usr/bin/env bash
!/usr/bin/env bash
fetch and unpack lua src
civetweb base dir
-L because it's a 302 redirect
this script installs a lua / luarocks environment in .travis/lua
this is necessary because travis docker architecture (the fast way)
does not permit sudo, and does not contain a useful lua installation
build luarocks
After this script is finished, you can configure your environment to
use it by sourcing lua_env.sh
The current versions when this script was written
!/usr/bin/env /bash
fetch and unpack luarocks
add to path required by luarocks installer
directory where this script is located
mv built lua install to target Lua dir
build lua
comment: cleanup source dirs
label: code-design
Allocate new message. Caller must hold the lock.
If client is too far behind, return all messages.
We have a message to store. Write-lock the ringbuffer,
grab the next message and copy data into it.
A handler for the /ajax/send_message endpoint.
Initialize random number generator. It will be used later on for
the session identifier creation.
vim:ts=2:sw=2:et
Protects messages, sessions, last_message_id
Get session object for the connection. Caller must hold the lock.
This file is part of the Civetweb project, http://code.google.com/p/civetweb
It implements an online chat server. For more details,
see the documentation on the project web site.
To test the application,
1. type "make" in the directory where this file lives
2. point your browser to http://127.0.0.1:8081
Redirect user to the login form. In the cookie, store the original URL
we came from, so that after the authorization we could redirect back.
In production environment we should ask an authentication system
to authenticate the user.
Here however we do trivial check that user and password are not empty
Authentication failure, redirect to login.
No suitable handler found, mark as not processed. Civetweb will
try to serve the request.
A handler for the /authorize endpoint.
Login page form sends user name and password to this endpoint.
Generate session ID. buf must be 33 bytes in size.
Note that it is easy to steal session cookies by sniffing traffic.
This is why all communication must be SSL-ed.
buf is allocated on stack and hopefully is large enough to hold all
messages (it may be too small if the ringbuffer is full and all
messages are large. in this case asserts will trigger).
comment: TODO(lsm): JSON-encode all text strings
label: code-design
Setup and start Civetweb
Allocate new session object
If "callback" param is present in query string, this is JSONP call.
Return 1 in this case, or 0 if "callback" is not specified.
Wrap an output in Javascript function call.
Fetch user name and password.
Describes single message sent to a chat. If user is empty (0 length),
the message is then originated from the server itself.
Session ID
Set user, needed by Javascript code
Delete original_url
Return 1 if request is authorized, 0 otherwise.
Get a get of messages with IDs greater than last_id and transform them
into a JSON string. Return that string to the caller. The string is
dynamically allocated, caller must free it. If there are no messages,
NULL is returned.
Message ID
User that have sent the message
Message text
Message timestamp, UTC
Large enough to hold all messages
Authentication success:
1. create new session
2. set session ID token in the cookie
3. remove original_url from the cookie - not needed anymore
4. redirect client back to the original URL
The most secure way is to stay HTTPS all the time. However, just to
show the technique, we redirect to HTTP after the successful
authentication. The danger of doing this is that session cookie can
be stolen and an attacker may impersonate the user.
Secure application must use HTTPS all the time.
Ringbuffer for messages
Current sessions
Empty user indicates server message
Session ID, must be unique
Random data used for extra user validation
Authenticated user
Expiration timestamp, UTC
Always authorize accesses to login page and to authorize URI
Read-lock the ringbuffer. Loop over all messages, making a JSON string.
A handler for the /ajax/get_messages endpoint.
Return a list of messages with ID greater than requested.
Wait until enter is pressed, then exit
Return 1 if username/password is allowed, 0 otherwise.
Describes web session.
This file is part of the Civetweb project,
http://sourceforge.net/projects/civetweb/
sourceforge.net/projects/civetweb/ -->
"}},lastModified:{},etag:{},ajax:function(a){function b(){e.success&&
e.success.call(k,o,i,x);e.global&&f("ajaxSuccess",[x,e])}function d(){e.complete&&e.complete.call(k,x,i);e.global&&f("ajaxComplete",[x,e]);e.global&&!--c.active&&c.event.trigger("ajaxStop")}function f(q,p){(e.context?c(e.context):c.event).trigger(q,p)}var e=c.extend(true,{},c.ajaxSettings,a),j,i,o,k=a&&a.context||e,n=e.type.toUpperCase();if(e.data&&e.processData&&typeof e.data!=="string")e.data=c.param(e.data,e.traditional);if(e.dataType==="jsonp"){if(n==="GET")N.test(e.url)||(e.url+=(ka.test(e.url)?
"&":"?")+(e.jsonp||"callback")+"=?");else if(!e.data||!N.test(e.data))e.data=(e.data?e.data+"&":"")+(e.jsonp||"callback")+"=?";e.dataType="json"}if(e.dataType==="json"&&(e.data&&N.test(e.data)||N.test(e.url))){j=e.jsonpCallback||"jsonp"+sb++;if(e.data)e.data=(e.data+"").replace(N,"="+j+"$1");e.url=e.url.replace(N,"="+j+"$1");e.dataType="script";A[j]=A[j]||function(q){o=q;b();d();A[j]=w;try{delete A[j]}catch(p){}z&&z.removeChild(C)}}if(e.dataType==="script"&&e.cache===null)e.cache=false;if(e.cache===
false&&n==="GET"){var r=J(),u=e.url.replace(wb,"$1_="+r+"$2");e.url=u+(u===e.url?(ka.test(e.url)?"&":"?")+"_="+r:"")}if(e.data&&n==="GET")e.url+=(ka.test(e.url)?"&":"?")+e.data;e.global&&!c.active++&&c.event.trigger("ajaxStart");r=(r=xb.exec(e.url))&&(r[1]&&r[1]!==location.protocol||r[2]!==location.host);if(e.dataType==="script"&&n==="GET"&&r){var z=s.getElementsByTagName("head")[0]||s.documentElement,C=s.createElement("script");C.src=e.url;if(e.scriptCharset)C.charset=e.scriptCharset;if(!j){var B=
false;C.onload=C.onreadystatechange=function(){if(!B&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){B=true;b();d();C.onload=C.onreadystatechange=null;z&&C.parentNode&&z.removeChild(C)}}}z.insertBefore(C,z.firstChild);return w}var E=false,x=e.xhr();if(x){e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);try{if(e.data||a&&a.contentType)x.setRequestHeader("Content-Type",e.contentType);if(e.ifModified){c.lastModified[e.url]&&x.setRequestHeader("If-Modified-Since",
c.lastModified[e.url]);c.etag[e.url]&&x.setRequestHeader("If-None-Match",c.etag[e.url])}r||x.setRequestHeader("X-Requested-With","XMLHttpRequest");x.setRequestHeader("Accept",e.dataType&&e.accepts[e.dataType]?e.accepts[e.dataType]+",
!
* jQuery JavaScript Library v1.4.2
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
* http://sizzlejs.com/
* Copyright 2010, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses.
*
* Date: Sat Feb 13 22:33:48 2010 -0500
This file is part of the Civetweb project,
http://sourceforge.net/projects/civetweb/
sourceforge.net/projects/civetweb/ -->
Set correct action for the login form. We assume that the SSL port
is the next one to insecure one.
Note that this page is self-sufficient, it does not load any other
CSS or Javascript file. This is done so because only this page is
allowed for non-authorized users. If we want to load other files
from the frontend, we need to change backend code to allow those
for non-authorized users. See chat.c :: must_authorize() function.
Keep only chat.maxVisibleMessages, delete older ones.
This file is part of Civetweb project,
http://sourceforge.net/projects/civetweb/
Backend URL, string.
'http://backend.address.com' or '' if backend is the same as frontend
vim:ts=2:sw=2:et
Deselect menu buttons
Select clicked button
Hide all main windows
Show main window
input.disabled = true;
Stop the server.
Always set Content-Length
Wait until user hits "enter". Server is running in separate thread.
Navigating to http://localhost:8080 will invoke begin_request_handler().
Send HTTP reply to the client
Start the web server.
List of options. Last element must be NULL.
Returning non-zero tells civetweb that our function has replied to
the client, and civetweb should not send client any more data.
Prepare the message we're going to send
This function will be called by civetweb on every new request.
Prepare callbacks structure. We have only one callback, the rest are NULL.
comment: Unused
label: code-design
User has submitted a form, show submitted data and a variable value
Parse form data. input1 and input2 are guaranteed to be NUL-terminated
Show HTML form.
Mark request as processed
Wait until user hits "enter"
Send reply to the client, showing submitted form values.
Copyright (c) 2014 the Civetweb developers
* Copyright (c) 2004-2012 Sergey Lyubka
* This file is a part of civetweb project, http://github.com/bel2125/civetweb
callback: called after uploading a file is completed
Startup options for the server
Test server will use this port
Display a welcome message
Start the server
This example is deprecated and no longer maintained.
* All relevant parts have been merged into the embedded_c example.
!_WIN32
See http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
Mark request as processed
Wait until thr user hits "enter", then stop the server
Main program: Set callbacks and start the server.
callback: used to generate all content
enctype="multipart/form-data"
Show HTML form.
close websock
chat message
init command
This example uses deprecated interfaces: global websocket callbacks.
They have been superseeded by URI specific callbacks.
See examples/embedded_c for an up to date example.
comment: todo: use mg_start_thread_id instead of mg_start_thread
label: code-design
comment: todo: wait for the thread instead of a timeout
label: requirement
keep alive
var connection;
var keepAlive = false;
function webSockKeepAlive() {
if (keepAlive) {
connection.send('ping'); // Send the message 'ping' to the server
setTimeout("webSockKeepAlive()", 10000);
}
}
function load() {
connection = new WebSocket("ws://127.0.0.1/MyWebSock");
connection.onopen = function () {
var send = "init " + Math.round(Math.random()*4294967294+1);
console.log('Client: ' + send);
connection.send(send);
keepAlive = true;
webSockKeepAlive();
};
connection.onerror = function (error) {
keepAlive = false;
connection.close();
console.log('WebSocket error: ' + error);
alert("WebSocket error");
};
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
if (e.data.substring(0,5) == "title") {window.document.title = e.data.substring(6);}
else if (e.data.substring(0,3) == "msg") {
var msgStr = document.getElementById('msg');
msgStr.innerHTML = msgStr.innerHTML + e.data.substring(4);
}
};
}
//
document_root: The path to the test function websock.htm
if the port is changed here, it needs to be changed in
websock.htm as well
This example uses deprecated interfaces: global websocket callbacks.
They have been superseeded by URI specific callbacks.
See examples/embedded_c for an up to date example.
port: use http standard to match websocket url in websock.htm:
ws://127.0.0.1/MyWebSock
return 0 to accept every connection
WEBSOCKET SERVER
Should get the acknowledge message
strlen(websocket_acknowledge_msg)
Connect client 3
* Copyright (c) 2014-2016 the Civetweb developers
* Copyright (c) 2014 Jordan Shelley
* https://github.com/jshelley
* License http://opensource.org/licenses/mit-license.php MIT License
First set up a websocket server
Won't get any message
Simple example program on how to use websocket client embedded C interface.
Send websocket welcome message
Client 3 should get the websocket welcome message
New interface:
Obsolete:
Send websocket acknowledge message
Can not send a websocket goodbye message here - the connection is already
* closed
return 1 to keep the connetion open
strlen(websocket_goodbye_msg)
Should get the websocket welcome message
***********************************************************************************
This example is superseeded by other examples, and no longer
* actively maintained.
* See examples/embedded_c for an up to date example.
Now connect a second client
Should get the goodbye message
WEBSOCKET CLIENT
Then connect a first client
strlen(websocket_welcome_msg)
Client 2 should get the websocket welcome message
check for websocket support
for Internet Explorer < 10 there are options for websocket support that
could be integrated into production code, but for now, we are expecting
browser support to be present for this demo
websocket connection
user connect/disconnect
comment:
Version 0.1 Contributed by William Greathouse 9-Sep-2013
Simple demo of WebSocket connection use. Not a great example of web coding,
but it is functional.
The meter displays are adapted from CSS-TRICKS Progress Bars by Chris Coyier
at http://css-tricks.com/css3-progress-bars/
label: code-design
Can be anything
user turn updates on/off
css-tricks.com/css3-progress-bars/
time to close the connection
simple structure for keeping track of websocket connection
second meter 0 to 500, by 10 every 0.5 second
Wait until user hits "enter"
echo back
get simple greeting for the web server
we should not send addional messages when close requested/acknowledged
websocket_ready_handler()
Once websocket negotiation is complete, start a server for the connection
websocket_close_handler()
When websocket is closed, tell the associated server to shut down
Arguments:
flags: first byte of websocket frame, see websocket RFC,
http://tools.ietf.org/html/rfc6455, section 5.2
data, data_len: payload data. Mask, if any, is already applied.
end of list
third meter 0 to 100, by 10 every 1.0 second
up to 16 independent client connections
turn on updates
client sent PING, respond with PONG
first meter 0 to 1000, by 5 every 0.1 second
keep connection open
** interpret data as commands here **
0.1 seconds
fprintf(stderr, "close handler\n"); /* called for every close, not just websockets */
Send initial meter updates
time base and structure periodic updates to client for demo
received PONG to our PING, no action
show the greeting and some basic information
if we are closing, server should not send new data
Send meter updates
comment: reset connection information to allow reuse by new client
label: code-design
ws_server_thread()
Simple demo server thread. Sends periodic updates to connected clients
Copyright (c) 2004-2012 Sergey Lyubka
This file is a part of civetweb project, http://github.com/bel2125/civetweb
v 0.1 Contributed by William Greathouse 9-Sep-2013
0.1 second
Send periodic PING to assure websocket remains connected, except if we are closing
While the connection is open, send periodic updates
websocket_connect_handler()
On new client connection, find next available server connection and store
new connection information. If no more server connections are available
tell civetweb to not accept the client request.
If client initiated close, respond with close message in acknowlegement
turn off updates
Add handler for all files with .foo extention
Add handler for /close extention
Call the form handler
Handler may access the request info using mg_get_request_info
Add handler for /A* and special handler for /A/B
Add HTTP site to open a websocket connection
Add handler for /form (serve a file outside the document root)
We know the content length in advance
* Copyright (c) 2013-2017 the CivetWeb developers
* Copyright (c) 2013 No Face Press, LLC
* License http://opensource.org/licenses/mit-license.php MIT License
example from https://github.com/civetweb/civetweb/issues/347
mg_printf(conn, "<script type=\"text/javascript\"><![CDATA[\n"); ...
* xhtml style
Check return value:
Stop the server
We must read until we find the end (chunked encoding
* or connection close), indicated my mg_read returning 0
Add HTTP site with auth
comment: MAX_WS_CLIENTS defines how many clients can connect to a websocket at the
* same time. The value 5 is very small and used here only for demonstration;
* it can be easily tested to connect more than MAX_WS_CLIENTS clients.
* A real server should use a much higher number, or better use a dynamic list
* of currently connected websocket clients.
label: code-design
Set a random password (4 digit number - bad idea from a security
* point of view, but this is an API demo, not a security tutorial),
* and store it in some directory within the document root (extremely
* bad idea, but this is still not a security tutorial).
* The reason we create a new password every time the server starts
* is just for demonstration - we don't want the browser to store the
* password, so when we repeat the test we start with a new password.
No valid authorization
comment: mg_printf(conn, "]]></script>\n"); ... xhtml style
label: code-design
Visual Studio 2010+ support llu
Add handler for /postresponse example
Simple example program on how to use CivetWeb embedded into a C program.
List all listening ports
Start CivetWeb web server
Add application specific SSL initialization
Add handler EXAMPLE_URI, to explain the example
Add handler for form data
IPv4
Wait until the server should be closed
Send error
Add handler for /B, /B/A, /B/B but not for /B*
WS site for the websocket connection
In this handler, we ignore the req_info and send the file "fileName".
Check if libcivetweb has been built with all required features.
Add a file upload handler for parsing files on the fly
It would be possible to check the request info here before calling
* mg_handle_form_request.
IPv6
Add handler for /cookie example
Just tell the user the new password generated for this test.
Windows will not work with path > 260 (MAX_PATH), unless we use
* the unicode API. However, this is just an example code: A real
* code will probably never store anything to D:\\somewhere and
* must be adapted to the specific needs anyhow.
Handler may access the request info using mg_get_request_info
Simple example program on how to use Embedded C++ interface.
This handler will handle "everything else", including
* requests to files. If this handler is installed,
* NO_FILES should be set.
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2013 No Face Press, LLC
* License http://opensource.org/licenses/mit-license.php MIT License
mg_printf(conn, "<script type=\"text/javascript\"><![CDATA[\n"); ...
* xhtml style
comment: mg_printf(conn, "]]></script>\n"); ... xhtml style
label: code-design
CivetServer server(options); // <-- C style start
<-- C++ style start
comment: The string is too long and probably truncated. Make sure an
* UTF-8 string is never truncated between the UTF-8 code bytes.
* This example code must be adapted to the specific needs.
label: code-design
*
* getParam(const char *, size_t, const char *, std::string &, size_t)
*
* Returns a query paramter contained in the supplied buffer. The
* occurance value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys.
*
* @param data the - query string (text)
* @param data_len - length of the query string
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*
* removeWebSocketHandler(const std::string &)
*
* Removes a web socket handler.
*
* @param uri - the exact URL used in addWebSocketHandler().
*
* Stores the user provided close handler
*
* Basic interface for a URI request handler. Handlers implementations
* must be reentrant.
*
* Callback method for GET request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* Callback method for authorization requests. It is up the this handler
* to generate 401 responses if authorization fails.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if authorization succeeded, false otherwise
*
* urlEncode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be encoded (0 terminated)
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*
* urlEncode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be encoded
* @param src_len - length of buffer to be decoded
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*
* authHandler(struct mg_connection *, void *cbdata)
*
* Handles the authorization requests.
*
* @param conn - the connection information
* @param cbdata - pointer to the CivetAuthHandler instance.
* @returns 1 if authorized, 0 otherwise
*
* closeHandler(struct mg_connection *)
*
* Handles closing a request (internal handler)
*
* @param conn - the connection information
*
* urlDecode(const std::string &, std::string &, bool)
*
* @param src - string to be decoded
* @param dst - destination string
* @param is_form_url_encoded - true if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*
* getContext()
*
* @return the context or 0 if not running.
forward declaration
*
* getListeningPorts()
*
* Returns a list of ports that are listening
*
* @return A vector of ports
*
* getParam(struct mg_connection *conn, const char *, std::string &, size_t)
*
* Returns a query paramter contained in the supplied buffer. The
* occurance value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys. Note that
*this
* function assumes that parameters are sent as text in http query string
* format, which is the default for web forms. This function will work for
* html forms with method="GET" and method="POST" attributes. In other
*cases,
* you may use a getParam version that directly takes the data instead of
*the
* connection as a first argument.
*
* @param conn - parameters are read from the data sent through this
*connection
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*
* Callback method for when websocket handshake is successfully completed,
*and connection is ready for data exchange.
*
* @param server - the calling server
* @param conn - the connection information
*
* urlDecode(const char *, std::string &, bool)
*
* @param src - buffer to be decoded (0 terminated)
* @param dst - destination string
* @param is_form_url_encoded true - if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*
* urlEncode(const std::string &, std::string &, bool)
*
* @param src - buffer to be encoded
* @param dst - destination string
* @param append - true if string should not be cleared before encoding.
*
* getParam(const std::string &, const char *, std::string &, size_t)
*
* Returns a query paramter contained in the supplied buffer. The
* occurance value is a zero-based index of a particular key name. This
* should not be confused with the index over all of the keys.
*
* @param data - the query string (text)
* @param name - the key to search for
* @param dst - the destination string
* @param occurrence - the occurrence of the selected name in the query (0
*based).
* @return true if key was found
*
* CivetServer
*
* Basic class for embedded web server. This has an URL mapping built-in.
*
* urlDecode(const char *, size_t, std::string &, bool)
*
* @param src - buffer to be decoded
* @param src_len - length of buffer to be decoded
* @param dst - destination string
* @param is_form_url_encoded - true if form url encoded
* form-url-encoded data differs from URI encoding in a way that it
* uses '+' as character for space, see RFC 1866 section 8.2.1
* http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
*
* Callback method for HEAD request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* Callback method for POST request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
_CIVETWEB_SERVER_H_
*
* Callback method for when a data frame has been received from the client.
*
* @param server - the calling server
* @param conn - the connection information
* @bits: first byte of the websocket frame, see websocket RFC at
*http://tools.ietf.org/html/rfc6455, section 5.2
* @data, data_len: payload, with mask (if any) already applied.
* @returns true to keep socket open, false to close it
*
* Callback method for when the connection is closed.
*
* @param server - the calling server
* @param conn - the connection information
*
* removeAuthHandler(const std::string &)
*
* Removes an authorization handler.
*
* @param uri - the exact URL used in addAuthHandler().
*
* getHeader(struct mg_connection *conn, const std::string &headerName)
* @param conn - the connection information
* @param headerName - header name to get the value from
* @returns a char array whcih contains the header value as string
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2013 No Face Press, LLC
*
* License http://opensource.org/licenses/mit-license.php MIT License
*
* addHandler(const std::string &, CivetHandler *)
*
* Adds a URI handler. If there is existing URI handler, it will
* be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - handler instance to use.
generic user context which can be set/read,
the server does nothing with this apart from keep it.
*
* Callback method for PATCH request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* addAuthHandler(const std::string &, CivetAuthHandler *)
*
* Adds a URI authorization handler. If there is existing URI authorization
* handler, it will be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - authorization handler instance to use.
*
* Basic interface for a websocket handler. Handlers implementations
* must be reentrant.
*
* Callback method for PUT request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* Callback method for DELETE request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* getCookie(struct mg_connection *conn, const std::string &cookieName,
*std::string &cookieValue)
*
* Puts the cookie value string that matches the cookie name in the
*cookieValue destinaton string.
*
* @param conn - the connection information
* @param cookieName - cookie name to get the value from
* @param cookieValue - cookie value is returned using thiis reference
* @returns the size of the cookie value string read.
*
* Exception class for thrown exceptions within the CivetHandler object.
*
* removeHandler(const std::string &)
*
* Removes a handler.
*
* @param uri - the exact URL used in addHandler().
*
* Callback method for when the client intends to establish a websocket
*connection, before websocket handshake.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true to keep socket open, false to close it
*
* requestHandler(struct mg_connection *, void *cbdata)
*
* Handles the incomming request.
*
* @param conn - the connection information
* @param cbdata - pointer to the CivetHandler instance.
* @returns 0 if implemented, false otherwise
*
* Destructor
*
* Basic interface for a URI authorization handler. Handler implementations
* must be reentrant.
*
* close()
*
* Stops server and frees resources.
*
* Constructor
*
* This automatically starts the sever.
* It is good practice to call getContext() after this in case there
* were errors starting the server.
*
* Note: CivetServer should not be used as a static instance in a Windows
* DLL, since the constructor creates threads and the destructor joins
* them again (creating/joining threads should not be done in static
* constructors).
*
* @param options - the web server options.
* @param callbacks - optional web server callback methods.
*
* @throws CivetException
__cplusplus
*
* Callback method for OPTIONS request.
*
* @param server - the calling server
* @param conn - the connection information
* @returns true if implemented, false otherwise
*
* addWebSocketHandler
*
* Adds a WebSocket handler for a specific URI. If there is existing URI
*handler, it will
* be replaced with this one.
*
* URI's are ordered and prefix (REST) URI's are supported.
*
* @param uri - URI to match.
* @param handler - handler instance to use.
*
* CivetCallbacks
*
* wrapper for mg_callbacks
This structure may be extended in future versions.
Called when civetweb is about to log a message. If callback returns
non-zero, civetweb does not log anything.
port number
Blocks until unique access is obtained to this connection. Intended for use
with websockets only.
Invoke this before mg_write or mg_printf when communicating with a
websocket if your code has server-initiated communication as well as
communication in direct response to a message.
Send contents of the entire file together with HTTP headers.
Parameters:
conn: Current connection information.
path: Full path to the file to send.
mime_type: Content-Type for file. NULL will cause the type to be
looked up by the file extension.
additional_headers: Additional custom header fields appended to the header.
Each header should start with an X-, to ensure it is
not included twice.
NULL does not append anything.
URL-decoded URI (relative). Can be NULL
* if the request_uri does not address a
* resource at the server host.
Called when civetweb initializes SSL library.
Parameters:
user_data: parameter user_data passed when starting the server.
Return value:
0: civetweb will set up the SSL certificate.
1: civetweb assumes the callback already set up the certificate.
-1: initializing ssl fails.
Skip this field (neither get nor store it). Continue with the
* next field.
Get the value of particular HTTP header.
This is a helper function. It traverses request_info->http_headers array,
and if the header is present in the array, returns its value. If it is
not present, NULL is returned.
redirect all requests: 0 = no, 1 = yes
Called when websocket request is received, before websocket handshake.
Return value:
0: civetweb proceeds with websocket handshake.
1: connection is closed immediately.
This callback is deprecated: Use mg_set_websocket_handler instead.
Return information associated with the request.
* Use this function to implement a server and get data about a request
* from a HTTP/HTTPS client.
* Note: Before CivetWeb 1.10, this function could be used to read
* a response from a server, when implementing a client, although the
* values were never returned in appropriate mg_request_info elements.
* It is strongly advised to use mg_get_response_info for clients.
Fetch value of certain cookie variable into the destination buffer.
Destination buffer is guaranteed to be '\0' - terminated. In case of
failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
parameter. This function returns only first occurrence.
Return:
On success, value length.
On error:
-1 (either "Cookie:" header is not present at all or the requested
parameter is not found).
-2 (destination buffer is NULL, zero length or too small to hold the
value).
User data pointer passed to mg_start()
Macros for enabling compiler-specific checks for printf-like arguments.
Read data from the remote end, return number of bytes read.
Return:
0 connection has been closed by peer. No more data could be read.
< 0 read error. No more data could be read from the connection.
> 0 number of bytes read into the buffer.
URL-decode input buffer into destination buffer.
0-terminate the destination buffer.
form-url-encoded data differs from URI encoding in a way that it
uses '+' as character for space, see RFC 1866 section 8.2.1
http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
Return: length of the decoded data, or -1 if dst buffer is too small.
Client's port
Stop parsing this request. Skip the remaining fields.
Stop the web server.
Must be called last, when an application wants to stop the web server and
release all associated resources. This function blocks until all Civetweb
threads are stopped. Context pointer becomes invalid.
utility methods to compare two buffers, case insensitive.
Old nomenclature.
Store body data into a file.
Return values definition for the "field_found" callback in
* mg_form_data_handler.
Note: The "file in memory" feature is a deletion candidate, since
* it complicates the code, and does not add any value compared to
* "mg_add_request_handler".
* See this discussion thread:
* https://groups.google.com/forum/#!topic/civetweb/h9HT4CmeYqI
* If you disagree, if there is any situation this is indeed useful
* and cannot trivially be replaced by another existing feature,
* please contribute to this discussion during the next 3 month
* (till end of April 2017), otherwise this feature might be dropped
* in future releases.
Get the value of particular configuration parameter.
The value returned is read-only. Civetweb does not allow changing
configuration at run time.
If given parameter name is not valid, NULL is returned. For valid
names, return value is guaranteed to be non-NULL. If parameter is not
set, zero-length string is returned.
Old nomenclature
Called when initializing a new connection object.
* Can be used to initialize the connection specific user data
* (mg_request_info->conn_data, mg_get_user_connection_data).
* When the callback is called, it is not yet known if a
* valid HTTP(S) request will be made.
* Parameters:
* conn: not yet fully initialized connection object
* conn_data: output parameter, set to initialize the
* connection specific user data
* Return value:
* must be 0
* Otherwise, the result is undefined
Called when civetweb tries to open a file. Used to intercept file open
calls, and serve file data from memory instead.
Parameters:
path: Full path to the file to open.
data_len: Placeholder for the file size, if file is served from
memory.
Return value:
NULL: do not serve file from memory, proceed with normal file open.
non-NULL: pointer to the file contents in memory. data_len must be
initialized with the size of the memory block.
Check which features where set when the civetweb library has been compiled.
The function explicitly addresses compile time defines used when building
the library - it does not mean, the feature has been initialized using a
mg_init_library call.
mg_check_feature can be called anytime, even before mg_init_library has
been called.
Parameters:
feature: specifies which feature should be checked
The value is a bit mask. The individual bits are defined as:
1 serve files (NO_FILES not set)
2 support HTTPS (NO_SSL not set)
4 support CGI (NO_CGI not set)
8 support IPv6 (USE_IPV6 set)
16 support WebSocket (USE_WEBSOCKET set)
32 support Lua scripts and Lua server pages (USE_LUA is set)
64 support server side JavaScript (USE_DUKTAPE is set)
128 support caching (NO_CACHING not set)
256 support server statistics (USE_SERVER_STATS is set)
The result is undefined, if bits are set that do not represent a
defined feature (currently: feature >= 512).
The result is undefined, if no bit is set (feature == 0).
Return:
If feature is available, the corresponding bit is set
If feature is not available, the bit is 0
Get a value of particular form variable.
Parameters:
data: pointer to form-uri-encoded buffer. This could be either POST data,
or request_info.query_string.
data_len: length of the encoded data.
var_name: variable name to decode from the buffer
dst: destination buffer for the decoded variable
dst_len: length of the destination buffer
Return:
On success, length of the decoded variable.
On error:
-1 (variable not found).
-2 (destination buffer is NULL, zero length or too small to hold the
decoded variable).
Destination buffer is guaranteed to be '\0' - terminated if it is not
NULL or zero length.
Return builtin mime type for the given file name.
For unrecognized extensions, "text/plain" is returned.
mg_set_websocket_handler
Set or remove handler functions for websocket connections.
This function works similar to mg_set_request_handler - see there.
comment: Called when websocket handshake is successfully completed, and
connection is ready for data exchange.
This callback is deprecated: Use mg_set_websocket_handler instead.
label: code-design
comment: Send data to the client using printf() semantics.
Works exactly like mg_write(), but allows to do message formatting.
label: code-design
Handle for the individual connection
This structure contains callback functions for handling form fields.
It is used as an argument to mg_handle_form_request.
Called when civetweb is about to log access. If callback returns
non-zero, civetweb does not log anything.
Connect to a websocket as a client
Parameters:
host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or
"localhost"
port: server port
use_ssl: make a secure connection to server
error_buffer, error_buffer_size: buffer for an error message
path: server path you are trying to connect to, i.e. if connection to
localhost/app, path should be "/app"
origin: value of the Origin HTTP header
data_func: callback that should be used when data is received from the
server
user_data: user supplied argument
Return:
On success, valid mg_connection object.
On error, NULL. Se error_buffer for details.
struct mg_websocket_subprotocols
*
* List of accepted subprotocols
Called when civetweb is about to serve Lua server page, if
Lua support is enabled.
Parameters:
lua_context: "lua_State *" pointer.
https port: 0 = no, 1 = yes
comment: TODO: add more data
label: requirement
Return array of struct mg_option, representing all valid configuration
options of civetweb.c.
The array is terminated by a NULL name option.
Maximum number of headers
Store the field value into a file.
Download data from the remote web server.
host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
port: port number, e.g. 80.
use_ssl: wether to use SSL connection.
error_buffer, error_buffer_size: error message placeholder.
request_fmt,...: HTTP request.
Return:
On success, valid pointer to the new connection, suitable for mg_read().
On error, NULL. error_buffer contains error message.
Example:
char ebuf[100];
struct mg_connection *conn;
conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
"%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
Called when data frame has been received from the client.
Parameters:
bits: first byte of the websocket frame, see websocket RFC at
http://tools.ietf.org/html/rfc6455, section 5.2
data, data_len: payload, with mask (if any) already applied.
Return value:
1: keep this websocket connection open.
0: close this websocket connection.
This callback is deprecated: Use mg_set_websocket_handler instead.
Number of HTTP headers
Get user data passed to mg_start from context.
comment: If the "field_found" callback returned FORM_FIELD_STORAGE_GET,
* this callback will receive the field data.
*
* Parameters:
* key: Name of the field ("name" property of the HTML input field).
* value: Value of the input field.
* user_data: Value of the member user_data of mg_form_data_handler
*
* Return value:
* TODO: Needs to be defined.
label: code-design
This structure needs to be passed to mg_start(), to let civetweb know
which callbacks to invoke. For a detailed description, see
https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
Deprecated: Use mg_get_valid_options instead.
Send data to a websocket server wrapped in a masked websocket frame. Uses
mg_lock_connection to ensure that the transmission is not interrupted,
i.e., when the application is proactively communicating and responding to
a request simultaneously.
Send data to a websocket server wrapped in a masked websocket frame.
This function is available when civetweb is compiled with -DUSE_WEBSOCKET
Return:
0 when the connection has been closed
-1 on error
>0 number of bytes written on success
CIVETWEB_HEADER_INCLUDED
Called when civetweb has received new HTTP request.
If the callback returns one, it must process the request
by sending valid HTTP headers and a body. Civetweb will not do
any further processing. Otherwise it must return zero.
Note that since V1.7 the "begin_request" function is called
before an authorization check. If an authorization check is
required, use a request_handler instead.
Return value:
0: civetweb will process the request itself. In this case,
the callback must not send any data to the client.
1-999: callback already processed the request. Civetweb will
not send any data after the callback returned. The
return code is stored as a HTTP status code for the
access log.
Get a formatted link corresponding to the current request
Parameters:
conn: current connection information.
buf: string buffer (out)
buflen: length of the string buffer
Returns:
<0: error
>=0: ok
Called when civetweb has uploaded a file to a temporary directory as a
result of mg_upload() call.
Note that mg_upload is deprecated. Use mg_handle_form_request instead.
Parameters:
file_name: full path name to the uploaded file.
Send contents of the entire file together with HTTP headers.
* Parameters:
* conn: Current connection handle.
* path: Full path to the file to send.
* mime_type: Content-Type for file. NULL will cause the type to be
* looked up by the file extension.
HTTP header value
Called when civetweb is closing a connection. The per-context mutex is
locked when this is invoked.
Websockets:
Before mg_set_websocket_handler has been added, it was primarily useful
for noting when a websocket is closing, and used to remove it from any
application-maintained list of clients.
Using this callback for websocket connections is deprecated: Use
mg_set_websocket_handler instead.
Connection specific data:
If memory has been allocated for the connection specific user data
(mg_request_info->conn_data, mg_get_user_connection_data),
this is the last chance to free it.
1 if SSL-ed, 0 if not
Allocate maximum headers
websocket subprotocol,
* accepted during handshake
Deprecated: use local_uri instead
Convenience function -- create detached thread.
Return: 0 on success, non-0 on error.
MG_LEGACY_INTERFACE
Callback types for websocket handlers in C/C++.
mg_websocket_connect_handler
Is called when the client intends to establish a websocket connection,
before websocket handshake.
Return value:
0: civetweb proceeds with websocket handshake.
1: connection is closed immediately.
mg_websocket_ready_handler
Is called when websocket handshake is successfully completed, and
connection is ready for data exchange.
mg_websocket_data_handler
Is called when a data frame has been received from the client.
Parameters:
bits: first byte of the websocket frame, see websocket RFC at
http://tools.ietf.org/html/rfc6455, section 5.2
data, data_len: payload, with mask (if any) already applied.
Return value:
1: keep this websocket connection open.
0: close this websocket connection.
mg_connection_close_handler
Is called, when the connection is closed.
mg_request_handler
Called when a new request comes in. This callback is URI based
and configured with mg_set_request_handler().
Parameters:
conn: current connection information.
cbdata: the callback data configured with mg_set_request_handler().
Returns:
0: the handler could not handle the request, so fall through.
1 - 999: the handler processed the request. The return code is
stored as a HTTP status code for the access log.
comment: Print error message to the opened error log stream.
This utilizes the provided logging configuration.
conn: connection (not used for sending data, but to get perameters)
fmt: format string without the line return
...: variable argument list
Example:
mg_cry(conn,"i like %s", "logging");
label: code-design
Get context information. Useful for server diagnosis.
Parameters:
ctx: Context handle
buffer: Store context information here.
buflen: Length of buffer (including a byte required for a terminating 0).
Return:
Available size of system information, exluding a terminating 0.
The information is complete, if the return value is smaller than buflen.
The result is a JSON formatted string, the exact content may vary.
Note:
It is possible to determine the required buflen, by first calling this
function with buffer = NULL and buflen = NULL. The required buflen is
one byte more than the returned value. However, since the available
context information changes, you should allocate a few bytes more.
Get the field value.
Check if the current request has a valid authentication token set.
* A file is used to provide a list of valid user names, realms and
* password hashes. The file can be created and modified using the
* mg_modify_passwords_file API function.
* Parameters:
* conn: Current connection handle.
* realm: Authentication realm. If NULL is supplied, the sever domain
* set in the authentication_domain configuration is used.
* filename: Path and name of a file storing multiple password hashes.
* Return:
* > 0 Valid authentication
* 0 Invalid authentication
* < 0 Error (all values < 0 should be considered as invalid
* authentication, future error codes will have negative
* numbers)
* -1 Parameter error
* -2 File not found
Send contents of the entire file together with HTTP headers.
URL part after '?', not including '?', or
NULL
Start web server.
Parameters:
callbacks: mg_callbacks structure with user-defined callbacks.
options: NULL terminated list of option_name, option_value pairs that
specify Civetweb configuration parameters.
Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
processing is required for these, signal handlers must be set up
after calling mg_start().
Example:
const char *options[] = {
"document_root", "/var/www",
"listening_ports", "80,443s",
NULL
};
struct mg_context *ctx = mg_start(&my_func, NULL, options);
Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
for the list of valid option and their possible values.
Return:
web server context, or NULL on error.
mg_set_request_handler
Sets or removes a URI mapping for a request handler.
This function uses mg_lock_context internally.
URI's are ordered and prefixed URI's are supported. For example,
consider two URIs: /a/b and /a
/a matches /a
/a/b matches /a/b
/a/c matches /a
Parameters:
ctx: server context
uri: the URI (exact or pattern) for the handler
handler: the callback handler to use when the URI is requested.
If NULL, an already registered handler for this URI will
be removed.
The URI used to remove a handler must match exactly the
one used to register it (not only a pattern match).
cbdata: the callback data to give to the handler when it is called.
Get user data set for the current connection.
Send data to the client.
Return:
0 when the connection has been closed
-1 on error
>0 number of bytes written on success
Client's IP address. Deprecated: use remote_addr instead
Send a part of the message body, if chunked transfer encoding is set.
* Only use this function after sending a complete HTTP request or response
* header with "Transfer-Encoding: chunked" set.
E.g. "1.0", "1.1"
"GET", "POST", etc
Close the connection opened by mg_download().
HTTP header name
Send HTTP error reply.
User supplied argument, passed to all callback functions.
Client certificate information
comment: Initialize this library. This should be called once before any other
* function from this library. This function is not guaranteed to be
* thread safe.
* Parameters:
* features: bit mask for features to be initialized.
* Return value:
* initialized features
* 0: error
label: requirement
Client certificate information (part of mg_request_info)
Process form data.
* Returns the number of fields handled, or < 0 in case of an error.
* Note: It is possible that several fields are already handled successfully
* (e.g., stored into files), before the request handling is stopped with an
* error. In this case a number < 0 is returned as well.
* In any case, it is the duty of the caller to remove files once they are
* no longer required.
New nomenclature
Return array of strings that represent valid configuration options.
For each option, option name and default value is returned, i.e. the
number of entries in the array equals to number_of_options x 2.
Array is NULL terminated.
Get context from connection.
Return information associated with a HTTP/HTTPS response.
* Use this function in a client, to check the response from
* the server.
Connect to a TCP server as a client (can be used to connect to a HTTP server)
Parameters:
host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or
"localhost"
port: server port
use_ssl: make a secure connection to server
error_buffer, error_buffer_size: buffer for an error message
Return:
On success, valid mg_connection object.
On error, NULL. Se error_buffer for details.
Opcodes, from http://tools.ietf.org/html/rfc6455
URL-decoded URI (absolute or relative,
* as in the request)
mg_set_auth_handler
Sets or removes a URI mapping for an authorization handler.
This function works similar to mg_set_request_handler - see there.
URL-encode input buffer into destination buffer.
returns the length of the resulting buffer or -1
is the buffer is too small.
Return CivetWeb version.
Authenticated user, or NULL if no auth
used
This callback function is called, if a new field has been found.
* The return value of this callback is used to define how the field
* should be processed.
*
* Parameters:
* key: Name of the field ("name" property of the HTML input field).
* filename: Name of a file to upload, at the client computer.
* Only set for input fields of type "file", otherwise NULL.
* path: Output parameter: File name (incl. path) to store the file
* at the server computer. Only used if FORM_FIELD_STORAGE_STORE
* is returned by this callback. Existing files will be
* overwritten.
* pathlen: Length of the buffer for path.
* user_data: Value of the member user_data of mg_form_data_handler
*
* Return value:
* The callback must return the intended storage for this field
* (See FORM_FIELD_STORAGE_*).
Called when a new worker thread is initialized.
Parameters:
ctx: context handle
thread_type:
0 indicates the master thread
1 indicates a worker thread handling client connections
2 indicates an internal helper thread (timer thread)
New nomenclature.
E.g. "OK"
__cplusplus
comment: MD5 hash given strings.
Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
ASCIIz strings. When function returns, buf will contain human-readable
MD5 hash. Example:
char buf[33];
mg_md5(buf, "aa", "bb", NULL);
label: code-design
Send data to a websocket client wrapped in a websocket frame. Uses
mg_lock_connection to ensure that the transmission is not interrupted,
i.e., when the application is proactively communicating and responding to
a request simultaneously.
Send data to a websocket client wrapped in a websocket frame.
This function is available when civetweb is compiled with -DUSE_WEBSOCKET
Return:
0 when the connection has been closed
-1 on error
>0 number of bytes written on success
Called when civetweb is about to send HTTP error to the client.
Implementing this callback allows to create custom error pages.
Parameters:
status: HTTP error status code.
Return value:
1: run civetweb error handler.
0: callback already handled the error.
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Get information on the system. Useful for support requests.
Parameters:
buffer: Store system information as string here.
buflen: Length of buffer (including a byte required for a terminating 0).
Return:
Available size of system information, exluding a terminating 0.
The information is complete, if the return value is smaller than buflen.
The result is a JSON formatted string, the exact content may vary.
Note:
It is possible to determine the required buflen, by first calling this
function with buffer = NULL and buflen = NULL. The required buflen is
one byte more than the returned value.
comment: If the "field_found" callback returned FORM_FIELD_STORAGE_STORE,
* the data will be stored into a file. If the file has been written
* successfully, this callback will be called. This callback will
* not be called for only partially uploaded files. The
* mg_handle_form_request function will either store the file completely
* and call this callback, or it will remove any partial content and
* not call this callback function.
*
* Parameters:
* path: Path of the file stored at the server.
* file_size: Size of the stored file in bytes.
* user_data: Value of the member user_data of mg_form_data_handler
*
* Return value:
* TODO: Needs to be defined.
label: code-design
Handle for the HTTP service itself
Read entire request body and store it in a file "path".
Return:
< 0 Error
>= 0 Number of bytes stored in file "path".
Get a value of particular form variable.
Parameters:
data: pointer to form-uri-encoded buffer. This could be either POST data,
or request_info.query_string.
data_len: length of the encoded data.
var_name: variable name to decode from the buffer
dst: destination buffer for the decoded variable
dst_len: length of the destination buffer
occurrence: which occurrence of the variable, 0 is the first, 1 the
second...
this makes it possible to parse a query like
b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
Return:
On success, length of the decoded variable.
On error:
-1 (variable not found).
-2 (destination buffer is NULL, zero length or too small to hold the
decoded variable).
Destination buffer is guaranteed to be '\0' - terminated if it is not
NULL or zero length.
Length (in bytes) of the request body,
can be -1 if no length was given.
mg_authorization_handler
Callback function definition for mg_set_auth_handler
Parameters:
conn: current connection information.
cbdata: the callback data configured with mg_set_request_handler().
Returns:
0: access denied
1: access granted
Called when civetweb context is deleted.
Parameters:
ctx: context handle
Deprecated: Use mg_get_server_ports instead.
Lock server context. This lock may be used to protect resources
that are shared between different connection/worker threads.
This structure contains information about the HTTP request.
Connection-specific user data
E.g. 200
Wait for a response from the server
Parameters:
conn: connection
ebuf, ebuf_len: error message placeholder.
timeout: time to wait for a response in milliseconds (if < 0 then wait
forever)
Return:
On success, >= 0
On error/timeout, < 0
1 = IPv4, 2 = IPv6, 3 = both
Called when civetweb has finished processing request.
Called after civetweb context has been created, before requests
are processed.
Parameters:
ctx: context handle
File upload functionality. Each uploaded file gets saved into a temporary
file and MG_UPLOAD event is sent.
Return number of uploaded files.
Deprecated: Use mg_handle_form_request instead.
comment: Get connection information. Useful for server diagnosis.
Parameters:
ctx: Context handle
idx: Connection index
buffer: Store context information here.
buflen: Length of buffer (including a byte required for a terminating 0).
Return:
Available size of system information, exluding a terminating 0.
The information is complete, if the return value is smaller than buflen.
The result is a JSON formatted string, the exact content may vary.
Note:
It is possible to determine the required buflen, by first calling this
function with buffer = NULL and buflen = NULL. The required buflen is
one byte more than the returned value. However, since the available
context information changes, you should allocate a few bytes more.
label: code-design
Send HTTP digest access authentication request.
* Browsers will send a user name and password in their next request, showing
* an authentication dialog if the password is not stored.
* Parameters:
* conn: Current connection handle.
* realm: Authentication realm. If NULL is supplied, the sever domain
* set in the authentication_domain configuration is used.
* Return:
* < 0 Error
Client's IP address as a string.
Set user data for the current connection.
Get text representation of HTTP status code.
Add, edit or delete the entry in the passwords file.
*
* This function allows an application to manipulate .htpasswd files on the
* fly by adding, deleting and changing user records. This is one of the
* several ways of implementing authentication on the server side. For another,
* cookie-based way please refer to the examples/chat in the source tree.
*
* Parameter:
* passwords_file_name: Path and name of a file storing multiple passwords
* realm: HTTP authentication realm (authentication domain) name
* user: User name
* password:
* If password is not NULL, entry modified or added.
* If password is NULL, entry is deleted.
*
* Return:
* 1 on success, 0 on error.
Get the list of ports that civetweb is listening on.
The parameter size is the size of the ports array in elements.
The caller is responsibility to allocate the required memory.
This function returns the number of struct mg_server_ports elements
filled in, or <0 in case of an error.
Un-initialize this library.
* Return value:
* 0: error
!/bin/sh
using "pass" for every password
remove last build
check if the build was successful
! /bin/sh
new scan build
pack build results for upload
check if we use the correct directory
copy files to build folder
return "ok"
data is "var1=val1&var2=val2...". Find variable first
Point s to the end of the value
No handler found, close connection
Add one extra character: in case the post-data is a text, it
is required as 0-termination.
Do not increment con_len, since the 0 terminating is not part
of the content (text or binary).
comment: malloc may fail for huge requests
label: code-design
Happens when a request hits the server before the context is saved
No handler found
Maximum cookie length as per microsoft is 4096.
http://msdn.microsoft.com/en-us/library/ms178194.aspx
Decode variable into destination buffer
get requests do store html <form> field values in the http
query_string
Point p to variable value
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2013 No Face Press, LLC
*
* License http://opensource.org/licenses/mit-license.php MIT License
Now update the variable index
comment: TODO: print error
label: code-design
3. call a "handle everything" callback, if registered
Asterisk
Get a random number (independent of C rand function)
comment: Function should never be called
label: code-design
range buffer is big enough
comment: TODO (low): If some data has been sent, a correct error
* reply can no longer be sent, so just close the connection
label: code-design
Step 1.2: Check websocket protocol version.
TODO (mid): Check the mg_send_http_error situations in this function
Calculate an estimate for the required space
assert(handler == NULL);
"Cache-Control: private\r\n" (= default)
File name is relative to the webserver working directory
* or it is absolute system path
Timeout: should retry
RFC2616 Section 10.1.2
REPORT method only allowed for CGI/Lua/LSP and callbacks.
Handler for error group, e.g., 5xx error
* handler
* for all server errors (500-599)
RFC 6585, Section 4
Set close flag, so the server thread can exit.
Initialize port and len as invalid.
File already exists
Do not show current dir (but show hidden files as they will
* also be removed)
Cannot get host from the Host: header.
* Fallback to our IP address.
http://en.wikipedia.org/wiki/WebM
File is read only
Here we can either generate and send a directory listing,
* or send an "access denied" error.
RFC2616 Section 10.2.3
Pointer to the beginning of the portion of the incoming websocket
* message queue.
* The original websocket upgrade request is never removed, so the queue
* begins after it.
Loop over multiple requests sent using the same connection
* (while "keep alive").
assert(s >= p);
Traverse index files list. For each entry, append it to the given
* path and see if the file exists. If it exists, break the loop
Gobble initial spaces
Redirect error code from -1 to -2 (destination buffer too
* small).
SSL descriptor
We are using non-blocking sockets. Thus, the
* set_sock_timeout(so.sock, timeout);
* call is no longer required.
Depending on the SDK, this function uses either
* (volatile unsigned int *) or (volatile LONG *),
* so whatever you use, the other SDK is likely to raise a warning.
This value is the last one
Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
We need an additional wait loop around this, because in some cases
* with TLSwe may get data from the socket but not from SSL_read.
* In this case we need to repeat at least once.
queue is full
123
!NO_CGI
AUTH_HANDLER
0 = nowhere, 1 = on disk, 2 = in memory
Important: on new connection, reset the receiving buffer. Credit
* goes to crule42.
success
RFC2616 Section 10.4.16
ignore leading whitespaces
Use "Cache-Control: max-age" instead of "Expires" header.
* Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age
Error
100 nsecs
Request is directed to another server: The server name is
* longer
* than
* the request name. Drop this case here to avoid overflows
* in
* the
* following checks.
Data block
If a file should not be cached, do not only send
* max-age=0, but also pragmas and Expires headers.
1 is CRYPTO_LOCK
keep legacy behavior
difftime for struct timespec. Return value is in seconds.
OK
comment: TODO: 1) uri is deprecated;
* 2) here, ri.uri is the http response code
label: code-design
Compiler information
If CGI file is a script, try to read the interpreter line
Is path itself a directory?
Read from the socket into the next available location in the
* message queue.
process HTTP connection
12. Directory uris should end with a slash
return 0 on success, just like fclose
And disabling them does not work either:
* #pragma clang diagnostic ignored "-Wno-error=date-time"
* #pragma clang diagnostic ignored "-Wdate-time"
* So we just have to disable ALL warnings for some lines
* of code.
Server did not recv anything -> just close the connection
Start master (listening) thread
RFC2616 Section 10.2.1
EBUSY
out of memory
Debug:
* printf("Missing function: %s\n", fp->name);
is still not MIT) and use dynamic binding like
body_len is the length of the entire queue in bytes
* len is the length of the current message
* data_len is the length of the current message's data payload
* header_len is the length of the current message's header
Get some operating system independent thread id
comment: File is bad and will be removed anyway.
label: code-design
Note: mg_snprintf will not cause a buffer overflow above.
* So, string truncation checks are not required here.
open a connection
so->lsa.sin6.sin6_family = AF_INET6; already set by mg_inet_pton
Add 1 to len for the + character we skipped before
RFC2616 Section 10.4.18
If the path is not complete, skip processing.
Access granted
Port is specified with a +, bind to IPv6 and IPv4, INADDR_ANY
IANA registered MIME types
* (http://www.iana.org/assignments/media-types)
* application types
This is the problematic case for CRYPTO_set_id_callback:
* The OS pthread_t can not be cast to unsigned long.
Server starts *now*
SSL context
defined(_WIN32) && !defined(__SYMBIAN32__) - \
WINDOWS / UNIX include block
PATCH method (RFC 5789)
Free Lua state of lua background task
chunksize not set correctly
Pointer to name (in user addr space).
Overflow case
Try to read until it succeeds, fails, times out, or the server
* shuts down.
padding added after data member
data is "var1=val1&var2=val2...". Find variable first
Wait until everything has stopped.
RFC2616 Section 10.5.4
Send a chunk, if "Transfer-Encoding: chunked" is used
copy from the remainder of the last received chunk
Total bytes sent to client
Receive error
Transfer-Encoding is chunked:
* 0 = not chunked,
* 1 = chunked, do data read yet,
* 2 = chunked, some data read,
* 3 = chunked, all data read
Public function to check http digest authentication header
processed
Parameter error
next try for a partial match, we will accept uri/something
defined(__GNUC__) || defined(__MINGW32__)
11. Handle put/delete/mkcol requests
RFC2616 Section 10.2 - Successful 2xx
model
6.2.2. Check if put authorization for static files is
* available.
may be NULL
sscanf() is safe here, since send_ssi_file() also uses buffer
* of size MG_BUF_LEN to get the tag. So strlen(tag) is
* always < MG_BUF_LEN.
Publish the content length back to the response info.
Parent
File properties filled by mg_fopen:
CGI error handler should show the status code
Fatal error - abort start. However, this situation should never
* occur in practice.
Size of the accepted socket queue
comment: This function is deprecated. Use mg_get_valid_options instead.
label: code-design
IPv6
comment: This is an "in-memory" file, that can not be replaced
label: code-design
RFC 6585, Section 5
finally try for pattern match
If file name is fishy, reset the file structure and return
* error.
* Note it is important to reset, not just return the error, cause
* functions like is_file_opened() check the struct.
comment: Appease "unused parameter" warnings
label: code-design
Put the temp file in place of real file
Compile-time option to control stack size,
* e.g. -DUSE_STACK_SIZE=16384
Return True if we should reply 304 Not Modified.
Do not compress ranges.
11.1. PUT method
!_WIN32 && !__SYMBIAN32__
IPv6 address, examples: see above
Add user-specified variables
Delete is not successful: Return 500 (Server error).
On Windows, the file creation time can be higher than the
* modification time, e.g. when a file is copied.
* Since the Last-Modified timestamp is used for caching
* it should be based on the most recent timestamp.
Buffer allocation successful. Store the string there.
or timeout occured
* => the code must stay in the while loop
lock while cert is reloading
thread was not created
strcat with additional NULL check to avoid clang scan-build warning.
Return buffered data
MINGW typedefs pid_t to int. Using #define here.
If PEM file is not specified and the init_ssl callback
* is not specified, skip SSL initialization.
closed
Each error code path in this function must send an error
Forward declaration for Windows
Feature check API function
Start a thread storing the thread context.
RFC2616 Section 10.3 - Redirection 3xx
Reallocate the buffer
Always put directories on top
REPORT method (RFC 3253)
Will only work for RFC 952 compliant hostnames,
* starting with a letter, containing only letters,
* digits and hyphen ('-'). Newer specs may allow
* more, but this is not guaranteed here, since it
* may interfere with rules for port option lists.
ext now points to the path suffix
defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
assert(conn->data_len <= conn->buf_size);
Deprecated: Use mg_get_server_ports instead.
Content length is not specified by the client.
RFC2616 Section 10.3.1
Two \r\n - standard compliant
assert(is_delete_request || connect_handler!=NULL ||
* ready_handler!=NULL || data_handler!=NULL ||
* close_handler!=NULL);
End of civetweb.c
We sent an "upgrade" request. For a correct websocket
* protocol handshake, we expect a "101 Continue" response.
* Otherwise it is a protocol violation. Maybe the HTTP
* Server does not know websockets.
14. directories
Don't wait if the server is going to be stopped.
Values from errno.h in Windows SDK (Visual Studio).
Decode variable into destination buffer
!EWOULDBLOCK
The second word is the URI
1.2. do a https redirect, if required. Do not decode URIs yet.
File exists (precondition for calling this function),
* but can not be opened by the server.
out: file found (directly)
mg_stat returns 0 if the file does not exist
POST or PUT request without content length set
Get Subject and issuer
set_ssl_option() function updates this array.
* It loads SSL library dynamically and changes NULLs to the actual addresses
* of respective functions. The macros above (like SSL_connect()) are really
* just calling these functions indirectly via the pointer.
No Tag
out: websocket connetion?
Calculate how much to read from the file in the buffer
ok = FALSE; already set by init
RFC2324 Section 2.3.2
file stored on disk
If we don't memset stat structure to zero, mtime will have
* garbage and strftime() will segfault later on in
* print_dir_entry(). memset is required only if mg_stat()
* fails. For more details, see
* http://code.google.com/p/mongoose/issues/detail?id=79
Thread local storage index
See https://www.chilkatsoft.com/p/p_299.asp
For given directory path, substitute it to valid index file.
* Return 1 if index file has been found, 0 if not found.
* If the file is found, it's stats is returned in stp.
isgraph or isspace = isprint
Read from IO channel - opened file descriptor, socket, or SSL descriptor.
* Return value:
* >=0 .. number of bytes successfully read
* -1 .. timeout
* -2 .. error
Add data bytes in the current chunk have been read,
* so we are expecting \r\n now.
9a. In case the server uses only callbacks, this uri is
* unknown.
* Then, all request handling ends here.
last_modified = now ... assumes the file may change during
* runtime,
* so every mg_fopen call may return different data
HTTP reply status code, e.g. 200
Master thread adds accepted socket to a queue
shutdown of the socket at client side
BEGIN: CLOCK_MONOTONIC = stopwatch (time differences)
:# is a comment
This server does not have any real files, thus the
* PUT/DELETE methods are not valid.
The headers "Host", "Sec-WebSocket-Key", "Sec-WebSocket-Protocol" and
* "Sec-WebSocket-Version" are also required.
* Don't check them here, since even an unsupported websocket protocol
* request still IS a websocket request (in contrast to a standard HTTP
* request). It will fail later in handle_websocket_request.
While the delimiter is quoted, look for the next delimiter.
Create a temporary file name. Length has been checked before.
Size of structures, aligned to 8 bytes
Ignore errors for readonly files
Process a connection - may handle multiple requests
* using the same connection.
* Must be called with a valid connection (conn and
* conn->ctx must be valid).
in: filename (must be valid)
PATCH method only allowed for CGI/Lua/LSP and callbacks.
Skip over '=' character
Avoid CRYPTO_cleanup_all_ex_data(); See discussion:
* https://wiki.openssl.org/index.php/Talk:Library_Initialization
The first word is the HTTP version
Dynamically load SSL library. Set up ctx->ssl_ctx pointer.
Mark required libraries
Keep reading the input (either opened file descriptor fd, or socket sock,
* or SSL descriptor ssl) into buffer buf, until \r\n\r\n appears in the
* buffer (which marks the end of HTTP request). Buffer buf may already
* have some data. The length of the data is stored in nread.
* Upon every read operation, increase nread by the number of bytes read.
Send len bytes from the opened file to the client.
Message is a valid request
!fileno MINGW #defines fileno
PROPPATCH, COPY, MOVE, LOCK, UNLOCK (RFC 2518)
Set linger option to avoid socket hanging out after close. This
* prevent ephemeral port exhaust problem under high QPS.
GCC seems to have a flaw with it's own socket macros:
* http://www.linuxquestions.org/questions/programming-9/impossible-to-use-gcc-with-wconversion-and-standard-socket-macros-841935/
C++ wants that for INT64_MAX
Some of the parameters may be NULL
Lua Script
not required anyway
This is a POST/PUT request, or another request with body data.
comment: user names may not contain a ':' and may not be empty,
* so lines starting with ':' may be used for a special purpose
label: code-design
Copy the data payload into the data pointer for the
* callback. Cast to 31 bit is OK, since we
* limited data_len
!USE_WEBSOCKET
Default: don't configure any linger
Content-Length header value
NO_CACHING
Send headers
Deallocate context itself
Sleep quantum in ms
CORS request is asking for additional headers
Last time throttled data was sent
p must correspond to end_word - 1
the ready handler returned false
Send 304 "Not Modified" - this must not send any body data
last_modified = conn->ctx.start_time;
* May be used it the data does not change during runtime. This
* allows
* browser caching. Since we do not know, we have to assume the file
* in memory may change.
File exists and is not a directory.
Terminate string
Print error message to the opened error log stream.
comment: clock_gettime is not implemented on OSX prior to 10.12
label: requirement
worst case
According to RFC 2616, Section 14.21, caching times should not exceed
* one year. A year with 365 days corresponds to 31536000 seconds, a
* leap
* year to 31622400 seconds. For the moment, we just send whatever has
* been configured, still the behavior for >1 year should be considered
* as undefined.
The pre-allocated buffer not large enough.
Can it be replaced?
HTTP (RFC 2616)
Tag is opening
draft-tbray-http-legally-restricted-status-05,
* Section 3
path does not exixt and can not be created
Propagate the error
USE_SERVER_STATS
Step 2: If a callback is responsible, call it.
comment: Alternative alloc_vprintf() for non-compliant C runtimes
label: code-design
comment: TODO: Check ssl_verify_peer and ssl_ca_path here.
* SSL_CTX_set_verify call is needed to switch off server
* certificate checking, which is off by default in OpenSSL and
* on in yaSSL.
label: code-design
This is an existing file (not a directory).
* Check if write permission is granted.
http://msdn.microsoft.com/en-us/library/ms739165(v=vs.85).aspx:
* "Note that enabling a nonzero timeout on a nonblocking socket
* is not recommended.", so set it to blocking now
Use a local copy here, since substitute_index_file will
* change the content of the file status
6. authorization check
94
Close, if keep alive is not enabled
Unknown success code
RFC2616 Section 10.5.5
Use 64-bit file offsets by default
Return OpenSSL error message (from CRYPTO lib)
done with OpenSSL
comment: Protect against directory disclosure attack by removing '..',
* excessive '/' and '\' characters
label: code-design
sendfile is only available for Linux
For the moment, use option c: We look for a proper file,
* but since a file request is not always a script resource,
* the authorization check might be different.
Request buffers are not pre-allocated. They are private to the
* request and do not contain any state information that might be
* of interest to anyone observing a server status.
This function is called from send_directory() and used for
* sorting directory entries by size, or name, or modification time.
* On windows, __cdecl specification is needed in case if project is built
* with __stdcall convention. qsort always requires __cdels callback.
Frame format: http://tools.ietf.org/html/rfc6455#section-5.2
Partial content
The websocket_client context has only this thread. If it runs out,
set the stop_flag to 2 (= "stopped").
2. if this ip has limited speed, set it for this connection
sscanf and the option splitting code ensure the following condition
RFC2616 Section 10.4.1
Open file for read only access
look for matching subprotocol
34
Publish the content length back to the request info.
read error
416 = Range Not Satisfiable
Ignore too long entries that may overflow path buffer
remove double backslash (check i > 0 to preserve UNC paths,
* like \\server\file.txt)
DNS is case insensitive, so use case insensitive string compare here
The RFC standard version (https://tools.ietf.org/html/rfc6455)
* requires a Sec-WebSocket-Key header.
GetVersion was declared deprecated
End of header key (*dp == ':')
Parsed Authorization header
Linux et al already use unicode. No need to convert.
Comma found. Store length and shift the list ptr
hpux
step 1. completed, the url is known now
comment: When using -Weverything, clang does not accept it's own headers
* in a release build configuration. Disable what is too much in
* -Weverything.
label: code-design
RFC2518 Section 10.2, RFC4918 Section 11.1
Set bits for available features according to API documentation.
* This bit mask is created at compile time, according to the active
* preprocessor defines. It is a single const value at runtime.
RFC says that all initial whitespaces should be ingored
Add this thread to cv's waiting list
must be a end of line
Memory information
pollres = 0 means timeout
Copy VARIABLE=VALUE\0 string into the free space
video
CGI scripts may support all HTTP methods
All calls to construct_etag use 64 byte buffer
POSIX dirent interface
Prepare the environment block
Size of the request + headers in a buffer
Initialize elements.
comment: TODO (mid): error handling depending on the error code.
* These codes are different between Windows and Linux.
* Currently there is no problem with failing send calls,
* if there is a reproducible situation, it should be
* investigated in detail.
label: code-design
Used by mg_(un)lock_connection to ensure
* atomic transmissions for websockets
see errno
File name is relative to the webserver root
Timeout occured, but no data available.
If there is anything beyond end_word, copy it.
Websocket Lua script
NO_SOCKLEN_T
Note: set_sock_timeout is not required for non-blocking sockets.
* Leave this function here (commented out) for reference until
* CivetWeb 1.9 is tested, and the tests confirme this function is
* no longer required.
timeout
Valid URIs according to RFC 3986
* (https://www.ietf.org/rfc/rfc3986.txt)
* must only contain reserved characters :/?#[]@!$&'()*+,;=
* and unreserved characters A-Z a-z 0-9 and -._~
* and % encoded symbols.
RFC2616 Section 10.2.5
IE uses commas, FF uses
* spaces
if an error occured, close the connection
Stringify binary data. Output buffer must be twice as big as input,
* because each byte takes 2 bytes in string representation
Point p to variable value
This is the hixie version
error
set an error, if not yet set
HTTP 1.1 default is keep alive
Convert in 32 bit words, if data is 4 byte aligned
RFC2518 Section 10.1
1 if gzip encoding is accepted
Check if the script file is in a path, allowed for script files.
* This can be used if uploading files is possible not only for the server
* admin, and the upload mechanism does not check the file extension.
update existing handler
nanoseconds
Return HTTP header value, or NULL if not found.
Then send length information, chunk and terminating \r\n.
Allocate new buffer
Initialize thread local storage
1.3. decode url (if config says so)
Child
Skip over leading LWS
timeout: return 0
comment: TODO: 1) uri is deprecated;
* 2) here, ri.uri is the http response code
label: code-design
Now read CGI reply into a buffer. We need to set correct
* status code, thus we need to see all HTTP headers first.
* Do not send anything back to client, until we buffer in all
* HTTP headers.
Parsing failure.
RFC2616 Section 10.4.15
See table: http://www.cplusplus.com/reference/cctype/
See IANA HTTP status code assignment:
* http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
Ok
seconds
Start a thread to read the websocket client connection
* This thread will automatically stop when mg_disconnect is
* called on the client connection
Describes listening socket, or socket which was accept()-ed by the master
* thread and queued for future handling by the worker thread.
BEGIN: unknown clock
Should get data, but got EOL
socket error - check errno
!defined(NO_SSL)
RFC2616 Section 10.4.2
Protocol violation
Allocate a new buffer.
Interface function. Parameters are provided by the user, so do
* at least some basic checks.
_WIN32_WCE
Flush current buffer
Check config, if index scripts may have sub-resources
defined(USE_WEBSOCKET)
Step 2.1 check and select subprotocol
Step 8: Check if the file exists at the server
Is port supposed to redirect everything to SSL
* port
Step 9: Check for zipped files:
Need to retry the function call "later".
* See https://linux.die.net/man/3/ssl_get_error
* This is typical for non-blocking sockets.
comment: TODO: for 1.10: restructure how files in memory are handled
label: code-design
Return 0 means, path itself is a directory.
RFC2616 Section 10.4.5
1. get the request url
Not chunked: content length is known
This is an SSL specific error
Send a response to CORS preflights only if
* access_control_allow_methods is not NULL and not an empty string.
* In this case, scripts can still handle CORS.
RFC2518 Section 10.3, RFC4918
* Section 11.2
Environment buffer
call init_thread for a worker thread (type 1)
Message is a valid response
comment: __attribute__((unused))
label: code-design
comment: request not yet handled by a handler or redirect, so the request
* is processed here
label: requirement
Step 4: Check if gzip encoded response is allowed
Flush if buffer is full
Copy socket to the queue and increment head
could use atomic compare exchange, but this
* seems overkill for statistics data
Throttling, bytes/sec. <= 0 means no
* throttle
Stop signal received: somebody called mg_stop. Quit.
Client
comment: TODO: set some error message
label: requirement
comment: NOTE: If SO_EXCLUSIVEADDRUSE is used,
* Windows might need a few seconds before
* the same port can be used again in the
* same process, so a short Sleep may be
* required between mg_stop and mg_start.
label: code-design
O_BINARY
HCP24: some changes to compare hole var_name
This version uses 8 byte body data in a GET request
ALTERNATIVE_QUEUE
could use SSL_CTX_set_default_passwd_cb_userdata
Since we know all sockets, we can shutdown the connections.
hope nobody uses this
Requests information
Mark memory as dead
Get system information. It can be printed or stored by the caller.
* Return the size of available information.
Delete is successful: Return 204 without content.
File should be created
Allow only if access_control_allow_headers is
* not NULL and not an empty string. If this
* configuration is set to *, allow everything.
* Otherwise this configuration must be a list
* of allowed HTTP header names.
accepted subprotocols for ws/wss requests.
Shut down signal
SSL is not supported
First satisfy needs of the server
http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx
EINTR can be generated on a socket with a timeout set even
* when SA_RESTART is effective for all relevant signals
* (see signal(7)).
* => stay in the while loop
comment: Shutdown according to
* https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
* http://stackoverflow.com/questions/29845527/how-to-properly-uninitialize-openssl
label: code-design
Darwin prior to 7.0 and Win32 do not have socklen_t
Using the given file format, user name and domain must not contain
* ':'
Flush buffer
Perform case-insensitive match of string against pattern
Make modifiable copy of the auth header
Only accept a full file path, not a Windows short (8.3) path.
timeout is handled by the while loop
mask flag and opcode
Implement the deprecated mg_upload function by calling the new
* mg_handle_form_request function. While mg_upload could only handle
* HTML forms sent as POST request in multipart/form-data format
* containing only file input elements, mg_handle_form_request can
* handle all form input elements and all standard request methods.
NOTE(lsm): order is important here. should_keep_alive() call
* is using parsed request, which will be invalid after
* memmove's below.
* Therefore, memorize should_keep_alive() result now for later
* use in loop exit condition.
Run SSL_shutdown twice to ensure completly close SSL connection
Step 1.3: Could check for "Host", but we do not really nead this
* value for anything, so just ignore it.
processing
A websocket protocoll has the following HTTP headers:
*
* Connection: Upgrade
* Upgrade: Websocket
Make sure the port is valid and vector ends with 's', 'r' or ','
Null-terminate the destination
assert(connect_handler==NULL && ready_handler==NULL &&
* data_handler==NULL && close_handler==NULL);
Deallocate request handlers
Request too long
Unknown server error code
Set to 1 if the content is gzipped, in which
* case we need a "Content-Eencoding: gzip" header
character is ok
destructor not supported for Windows
Length of the message being read at the front of the
* queue. Cast to 31 bit is OK, since we limited
* data_len before.
remove existing handler
comment: Set some extra bits not defined in the API documentation.
* These bits may change without further notice.
label: documentation
Get a unique thread ID as unsigned long, independent from the data type
* of thread IDs defined by the operating system API.
* If two calls to mg_current_thread_id return the same value, they calls
* are done from the same thread. If they return different values, they are
* done from different threads. (Provided this function is used in the same
* process context and threads are not repeatedly created and deleted, but
* CivetWeb does not do that).
* This function must match the signature required for SSL id callbacks:
* CRYPTO_set_id_callback
comment: TODO: check if it is still used in response_info
label: code-design
comment: TODO: handle non-local request (PROXY)
label: code-design
Convert the nonce from the client to a number.
Linear congruential generator
ASN1_digest is deprecated. Do the calculation manually,
* using EVP_Digest.
Open failed
if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined
Regard empty password as no password - remove user record.
data points to the place where the message is stored when passed to
* the
* websocket_data callback. This is either mem on the stack, or a
* dynamically allocated buffer if it is too large.
This function only checks if the uri is valid, not if it is
* addressing the current server. So civetweb can also be used
* as a proxy server.
Check if the request is directed to a different server.
URI: /path_to_script/ ... using index.cgi
This file can not be sent using sendfile.
* This might be the case for pseudo-files in the
* /sys/ and /proc/ file system.
* Use the regular user mode copy code instead.
Send chunk of data that may have been read after the headers
The body data is completed when the connection
* is closed.
Allocate a mutex for this connection to allow communication both
* within the request handler and from elsewhere in the application
Ignore SIGPIPE signal, so if browser cancels the request, it
* won't kill the whole process.
Do not delete anything shorter
Check for quotechar
comment: Avoid warnings for Xcode 7. It seems it does no longer exist in Xcode 8
label: code-design
Step 5: The websocket connection has been accepted
BEGIN: CLOCK_PROCESS = CPU usage of process
Assume the data may change during runtime by setting
* last_modified = now
END: unknown clock
comment: TODO: get timeout def
label: code-design
The converted number corresponds to the time the nounce has been
* created. This should not be earlier than the server start.
Parse HTTP request, fill in mg_request_info structure.
* This function modifies the buffer by NUL-terminating
* HTTP request components, header names and header values.
* Parameters:
* buf (in/out): pointer to the HTTP header to parse and split
* len (in): length of HTTP header buffer
* re (out): parsed header as mg_request_info
* buf and ri must be valid pointers (not NULL), len>0.
* Returns <0 on error.
!NO_SSL
Check for a valid HTTP version key
Step 10: Script resources may handle sub-resources
Find end of HTTP header
Return stringified MD5 hash for list of strings. Buffer must be 33 bytes.
standard case if called from close_socket_gracefully
Look at the "path" extension and figure what mime type it has.
* Store mime type in the vector.
Step 1: Set all initially unknown outputs to zero
RFC7238 Section 3
Name/Pattern of the URI.
comment: TODO: specific error message
label: code-design
Request is directed to another server: It could be a
* substring
* like notmyserver.com
Next would be the HTTP version
Get SSL client certificate information (if set)
If any ACL is set, deny by default
For every system, "(sizeof(int) == sizeof(void *))" is either always
* true or always false. One of the two branches is unreachable in any case.
* Unfortunately the C standard does not define a way to check this at
* compile time, since the #if preprocessor conditions can not use the sizeof
* operator as an argument.
USE_LUA
comment: TODO: check for openSSL 1.1
label: requirement
For sockets, wait for the socket using select
Script was in an illegal path
Make up and send the status line
Check end of word
RFC 2774, Section 7
Check if the nonce is too high, so it has not (yet) been used by the
* server.
Reset buffer, so we can always use strcat.
Connection structure has been pre-allocated
Convert to Unicode and back. If doubly-converted string does not
* match the original, something is fishy, reject.
Wrap pointers if needed
SSL context for client connections
deallocate system name string
Fatal error - abort start. However, this situation should
* never occur in practice.
comment: Enable unused function warning again
label: code-design
Store the ssl library handle.
RFC2616 Section 10.4.13
Get context information. It can be printed or stored by the caller.
* Return the size of available information.
mg_stat must fill all fields, also for files in memory
Put so socket structure into the queue
comment: FIXME(lsm): fix this.
label: code-design
pthread cond not available
SCRIPT_NAME
Start the server
none found
RFC2616 Section 10.1.1
NOTE(lsm): due to a bug in MSIE, we do not compare the URI
sf_sent<0 means error, thus fall back to the classic way
comment: not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
label: code-design
Now we know that our FIN is ACK-ed, safe to close
End of initial operating system specific define block.
If truncated, add "..."
Helper function for deprecated mg_upload.
Request to create a directory has been fulfilled successfully.
* No need to put a file.
add mask
comment: TODO: (void)mg_snprintf(NULL, dst, dst_size, "implement strftime()
* for WinCE");
label: code-design
Step 5: If there is no root directory, don't look for files.
put_dir returns -1 if the path is too long
comment: Signal mg_stop() that we're done.
* WARNING: This must be the very last thing this
* thread does, as ctx becomes invalid after this line.
label: code-design
Both read and were successful, adjust counters
Try to delete it.
Compile-time option to control stack size, e.g.
* -DUSE_STACK_SIZE=16384
Windows SO_REUSEADDR lets many procs binds to a
* socket, SO_EXCLUSIVEADDRUSE makes the bind fail
* if someone already has the socket -- DTL
ORDERPATCH (RFC 3648)
1 if connection must be closed
!NO_POPEN
linked list of uri handlers
Mark handles that should not be inherited. See
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx
Request/response has content length set
comment: We should subtract the time used in select from remaining
* "milliseconds", in particular if called from mg_poll with a
* timeout quantum.
* Unfortunately, the remaining time is not stored in "tv" in all
* implementations, so the result in "tv" must be considered undefined.
* See http://man7.org/linux/man-pages/man2/select.2.html
label: code-design
Could be a hostname
asterisk
GCC does not realize one branch is unreachable, so it raises some
* pointer cast warning within the unreachable branch.
The first word has to be the HTTP method
Send host, port, uri and (if it exists) ?query_string
8.3: If the request target is a directory, there could be
* a substitute file (index.html, index.cgi, ...).
Tag to long for buffer
This is an IO error. Look at errno.
RFC2616 Section 10.4.6
Context has been created - init user libraries
error callint poll
According to https://en.wikipedia.org/wiki/Symbian#History,
* Symbian is no longer maintained since 2014-01-01.
* Recent versions of CivetWeb are no longer tested for Symbian.
* It makes no sense, to support an abandoned operating system.
* All remaining "#ifdef __SYMBIAN__" cases will be droped from
* the code sooner or later.
Note that root == NULL is a regular use case here. This occurs,
* if all requests are handled by callbacks, so the WEBSOCKET_ROOT
* config is not required.
Currently gz files can not be scripts.
A file should be created or overwritten.
Some ANSI #includes are not available on Windows CE
assert(fp != NULL);
Update lsa port in case of random free ports
If Range: header specified, act accordingly
Deallocate config parameters
EAGAIN/EWOULDBLOCK:
* standard case if called from close_socket_gracefully
* => should return -1
IPv4
Strings returned from bn_bn2hex must be freed using OPENSSL_free,
* see https://linux.die.net/man/3/bn_bn2hex
call the init_connection callback if assigned
Create substitutes for POSIX functions in Win32.
Unified socket address. For IPv6 support, add IPv6 address structure in
* the
* union u.
Step 4: Check if there is a responsible websocket handler.
For every compiler, either "sizeof(pthread_t) > sizeof(unsigned long)"
* or not, so one of the two conditions will be unreachable by construction.
* Unfortunately the C standard does not define a way to check this at
* compile time, since the #if preprocessor conditions can not use the sizeof
* operator as an argument.
Check if the method is known to the server. The list of all known
* HTTP methods can be found here at
* http://www.iana.org/assignments/http-methods/http-methods.xhtml
RFC2616 Section 10.4 - Client Error 4xx
Step 6: Call the ready handler
See CONTEXT_* above
Store the <
Set default value if needed
There should be already an error message
Timeout in s:
comment: Print message to buffer. If buffer is large enough to hold the message,
* return buffer. If buffer is to small, allocate large enough buffer on
* heap,
* and return allocated buffer.
label: code-design
Adjust length for trailing LWS
1.1.1970 in filedate
put_dir returns 0 if path is a directory
Point s to the end of the value
comment: This standard handler is only used for real files.
* Scripts should support the OPTIONS method themselves, to allow a
* maximum flexibility.
* Lua and CGI scripts may fully support CORS this way (including
* preflights).
label: code-design
Could not parse the CGI response. Check if some error message on
* stderr.
Log is written to a file and/or a callback. If both are not set,
* executing the rest of the function is pointless.
Buffer size
Yes it does, break the loop
comment: va_copy should always be a macro, C99 and C++11 - DTL
label: code-design
Send all current and obsolete cache opt-out directives.
Return 1 on success. Always initializes the ah structure.
Calculate SHA1 fingerprint and store as a hex string
Yes, they are optional
RFC 6585, Section 6
_WIN32
Parse HTTP headers from the given buffer, advance buf pointer
* to the point where parsing stopped.
* All parameters must be valid pointers (not NULL).
* Return <0 on error.
The master thread ID
Threads have different return types on Windows and Unix.
Free client certificate info
Return 1 if request is authorised, 0 otherwise.
ignore leading whitespaces
Open file for writing, create and append
Check if the server may write this file
Scan user-defined mime types first, in case user wants to
* override default mime types.
Get serial number
Here stop_flag is 1 - Initiate shutdown.
comment: All file operations need to be rewritten to solve #246.
label: code-design
comment: Legacy INIT, if mg_start is called without mg_init_library.
* Note: This may cause a memory leak
label: code-design
Return NULL or the relative uri at the current server
value of request_timeout is in seconds, config in milliseconds
Lua_State for a websocket connection
Encode 'path' which is assumed UTF-8 string, into UNICODE string.
* wbuf and wbuf_len is a target buffer and its length.
The worker thread IDs
Take connection [idx]. This connection is not locked in
* any way, so some other thread might use it.
"The masking key is a 32-bit value chosen at random by the client."
* http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5
Out of memory
Set socket family to IPv6, do not use IPV6_V6ONLY
Server version
Other request
Signaled when socket is produced
Call consume_socket() even when ctx->stop_flag > 0, to let it
* signal sq_empty condvar to wake up the master waiting in
* produce_socket()
ready
Set close flag, so keep-alive loops will stop
RFC2616 Section 10.1 - Informational 1xx
6.3. This is either a OPTIONS, GET, HEAD or POST request,
* or it is a PUT or DELETE request to a resource that does not
* correspond to a file. Check authorization.
Timeout
Set to 1 if mg_stat is called for a directory
No option known to set thread name for MinGW
Do not open file (used in is_file_in_memory)
CGI is not supported
assert(option != NULL);
assert(option[0] != '\0');
11.4. PATCH method
* This method is not supported for static resources,
* only for scripts (Lua, CGI) and callbacks.
to expose flockfile and friends in stdio.h
Check the user's password, return 1 if OK
This is always the case, if sf_file is not a "normal" file,
* e.g., for sending data from the output of a CGI process.
See also https://www.mnot.net/cache_docs/
mg_init_library counter
End of the list
If it is a directory, print directory entries too if Depth is not 0
comment: TODO: Remove this unlock as well, when lock is moved.
label: code-design
This is not a valid field.
The handler did NOT handle the request.
for setgroups()
User supplied argument for the handler function.
Set IPv6 only option, but don't abort on errors.
The second word is the status as a number
This is a valid CORS preflight, and the server is configured
* to
* handle it automatically.
char **envp
IPv6 hex string is 46 chars
Send user defined error pages, if defined
Cross-origin resource sharing (CORS).
Prepare connection data structure
fail early, don't waste time checking other header
* fields
if it's not the end of line, there must be a next word
Protects nonce_count
filep->is_directory = 0; filep->gzipped = 0; .. already done by
* memset
Use memcpy for alignment
control characters and spaces are invalid
RFC 2295, Section 8.1
Do not add truncated strings to the environment
This happens, e.g., in calls from parse_auth_header,
* if the user name contains a " character.
HTTPS connection
Define the initial recursion depth for procesesing htpasswd files that
* include other htpasswd
* (or even the same) files. It is not difficult to provide a file or files
* s.t. they force civetweb
* to infinitely recurse and then crash.
ebuf is set by connect_socket,
* free all memory and return NULL;
Value is either quote-delimited, or ends at first comma or space.
Reset all outputs
Initialize thread local storage before calling any callback
WINDOWS / UNIX include block
Directory entry
No more data to read
comment: WinCE-TODO: define stat, remove, rename, _rmdir, _lseeki64
label: code-design
file stored in memory
Do not show current dir and hidden files
Size was set by the callback
comment: TODO (mid): Add a webdav unit test first, before changing
* anything here.
label: test
Prepare Etag, Date, Last-Modified headers. Must be in UTC,
* according to
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
comment: Show no warning in case system functions are not used.
label: code-design
Visual Studio 6 does not know __func__ or __FUNCTION__
* The rest of MS compilers use __FUNCTION__, not C99 __func__
* Also use _strtoui64 on modern M$ compilers
RFC2616 Section 10.3.5
The 'path' given to us points to the directory. Remove all trailing
* directory separator characters from the end of the path, and
* then append single directory separator character.
Close files
Combining two pseudo-random number generators and a high resolution
* part
* of the current server time will make it hard (impossible?) to guess
* the
* next number.
RFC2616 Section 10.4.7
If Content-Length is not set for a request with body data
* (e.g., a PUT or POST request), we do not know in advance
* how much data should be read.
comment: Return fake connection structure. Used for logging, if connection
* is not applicable at the moment of logging.
label: code-design
Return -1 in an error case
Set reuse option, but don't abort on errors.
16-bit length field
Does it exist?
Check if the config_options and the corresponding enum have compatible
* sizes.
Finally check if the server corresponds to the authentication
* domain of the server (the server domain).
* Allow full matches (like http://mydomain.com/path/file.ext), and
* allow subdomain matches (like http://www.mydomain.com/path/file.ext),
* but do not allow substrings (like
* http://notmydomain.com/path/file.ext
* or http://mydomain.com.fake/path/file.ext).
pthread_t may be any data type, so a simple cast to unsigned long
* can rise a warning/error, depending on the platform.
* Here memcpy is used as an anything-to-anything cast.
Ignore truncation in access log
This code uses static_assert to check some conditions.
* Unfortunately some compilers still do not support it, so we have a
* replacement function here.
stdin read
Truncate here and set the key name
All SSI tags start with <!--#
END: CLOCK_REALTIME
Note that C callbacks are no longer called when Lua is
* responsible, so C can no longer filter callbacks for Lua.
Legacy before split into local_uri and request_uri
Convert month to the month number. Return -1 on error, or month number
comment: TODO (mid): This check does not seem to make any sense !
label: code-design
Append VARIABLE=VALUE\0 string to the buffer, and add a respective
* pointer into the vars array. Assumes env != NULL and fmt != NULL.
Reallocate existing block
key == pthread_getspecific(sTlsKey);
restore the string
Number of requests handled by this connection
Behaves like realloc(), but frees original pointer on failure
Reference counter for crypto library.
8.2: Check if it is a script type.
Do nothing, callback has served the request. Store
* then return value as status code for the log and discard
* all data from the client not used by the callback.
The connection struct, pre-
* allocated for each worker
Chunked encoding: 3=chunk read completely
* completely
_WIN32 && !__SYMBIAN32__
For Windows, change all slashes to backslashes in path names.
Depending on the OpenSSL version, the callback may be
* 'void (*)(SSL *, int, int)' or 'void (*)(const SSL *, int, int)'
* yielding in an "incompatible-pointer-type" warning for the other
* version. It seems to be "unclear" what is correct:
* https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1147526
* https://www.openssl.org/docs/man1.0.2/ssl/ssl.html
* https://www.openssl.org/docs/man1.1.0/ssl/ssl.html
* https://github.com/openssl/openssl/blob/1d97c8435171a7af575f73c526d79e1ef0ee5960/ssl/ssl.h#L1173
* Disable this warning here.
* Alternative would be a version dependent ssl_info_callback and
* a const-cast to call 'char *SSL_get_app_data(SSL *ssl)' there.
defined(__GNUC__)
Protects (max|num)_threads
Discard all buffered data for this request
Set the time the request was received. This value should be used for
* timeouts.
comment: unused if NO_FILES is defined
label: code-design
connected with IPv6
assert(conn->request_len < 0 || conn->data_len >= conn->request_len);
Server start time, used for authentication
* and for diagnstics.
Tag is closing
stdout write
!NO_CACHING
Set linger timeout
Reserved for future use, must be zero.
BEGIN: CLOCK_THREAD = CPU usage of thread
Deprecated function mg_upload - use mg_handle_form_request instead.
assert(ebuf[0] != '\0');
comment: TODO: Define mg_response_info and implement parsing
label: code-design
Parse all HTTP headers
Ignore if a file in memory is inside a folder
We got ready to write. Don't check the timeout
* but directly go back to write again.
Error, no bytes read
NO_SSL_DL
Random number generator will initialize at the first call
For a given PUT path, create all intermediate subdirectories.
* Return 0 if the path itself is a directory.
* Return 1 if the path leads to a file.
* Return -1 for if the path is too long.
* Return -2 if path can not be created.
http://www.webdav.org/specs/rfc4918.html, 9.1:
* Some PROPFIND results MAY be cached, with care,
* as there is no cache validation mechanism for
* most properties. This method is both safe and
* idempotent (see Section 9.1 of [RFC2616]).
Apply mask if necessary
A helper function for checking if a comma separated list of values
* contains
* the given option (case insensitvely).
* 'header' can be NULL, in which case false is returned.
A helper function for traversing a comma separated list of values.
* It returns a list pointer shifted to the next value, or NULL if the end
* of the list found.
* Value is stored in val vector. If value has form "x=y", then eq_val
* vector is initialized to point to the "y" part, and val vector length
* is adjusted to point only to "x".
Unknown redirection code
join worker thread
Remote socket address
Read frame payload from the first message in the queue into
* data and advance the queue by moving the memory in place.
Not initialized yet
C runtime is not standard compliant, vsnprintf() returned -1.
* Switch to alternative code path that uses incremental
* allocations.
ignore error on read only file
Parse a buffer:
* Forward the string pointer till the end of a word, then
* terminate it and forward till the begin of the next word.
Windows return values: see
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx
This is the end of the header
5.2. check if the request will be handled by a callback
Handle to algorithm used for fingerprint
text
Calculate Sec-WebSocket-Accept reply from Sec-WebSocket-Key.
Step 1.1: Check Sec-WebSocket-Key.
This is just a quick fix if the client offers multiple
* protocols. The handler should have a list of accepted
* protocols on his own
* and use it to select one protocol among those the client
* has
* offered.
It could be an absolute uri:
Just a single protocol -> accept it.
Delete was successful: Return 204 without content.
Must be 0x1000.
Calculate number of bytes added to the environment
Parse UTC date-time string, and return the corresponding time_t value.
is_file_in_memory returned true
Step 3.2: Lua is responsible: call it.
Time (since system start) when the request
* was received
CGI must be executed in its own directory. 'dir' must point to the
* directory containing executable program, 'p' must point to the
* executable program name relative to 'dir'.
http://en.wikipedia.org/wiki/Advanced_Audio_Coding
Allocation failed, exit the loop and then close the
* connection
Features
Socket already closed by client/peer, close socket without linger
Buffer is big enough
Alternative queue is well tested and should be the new default
ok
Use a const cast here and modify the string.
* We are going to restore the string later.
callback already processed the request. Store the
return value as a status code for the access log.
RFC2616 Section 10.5.3
The RFC version (https://tools.ietf.org/html/rfc6455) is 13.
audio
pthread_setname_np first appeared in glibc in version 2.12
DEBUG
Note that since V1.7 the "begin_request" function is called
* before an authorization check. If an authorization check is
* required, use a request_handler instead.
RFC2616 Section 10.3.4
However, the reasonable default is to not accept a nonce from a
* previous start, so if anyone changed the access rights between
* two restarts, a new login is required.
Include the header file here, so the CivetWeb interface is defined for the
* entire implementation, including the following forward definitions.
Allocate context and initialize reasonable general case defaults.
Linux uses -1 on error, Windows NULL.
could use atomic compare exchange, but this
* seems overkill for statistics data
not recognized on older compiler versions
Signaled when socket is consumed
out: file status structure
Send header
This is a file in memory, but we cannot store the
* properties
* now.
* Called from "is_file_in_memory" function.
Connected client
Wakeup workers that are waiting for connections to handle.
1 if in handler for user defined error
* pages
done
RFC 6585, Section 3
comment: TODO: retry condition
label: code-design
No more data to write
comment: Data type of linger structure elements may differ,
* so we don't know what cast we need here.
* Disable type conversion warnings.
label: code-design
How many bytes of content have been read
Windows file systems are not case sensitive, but you can still use
* uppercase and lowercase letters (on all modern file systems).
* The server can check if the URI uses the same upper/lowercase
* letters an the file system, effectively making Windows servers
* case sensitive (like Linux servers are). It is still not possible
* to use two files with the same name in different cases on Windows
* (like /a and /A) - this would be possible in Linux.
* As a default, Windows is not case sensitive, but the case sensitive
* file name check can be activated by an additional configuration.
Return 0 on success, non-zero if an error occurs.
Connection object will be null if something goes wrong
Handler for http/https or authorization requests.
stdin write
We are in a tag, either SSI tag or html tag
comment: Keep stderr and stdout in two different pipes.
* Stdout will be sent back to the client,
* stderr should go into a server error log.
label: code-design
The previous code must not add any header starting with X- to make
* sure no one of the additional_headers is included twice
String truncation in buf may only occur if
* error_handler is too long. This string is
* from the config, not from a client.
RFC2616 Section 10.4.12
file is in memory
RFC2616 Section 10.2.4
comment: TODO (Feature): Add config value for allowed script path.
* Default: All allowed.
label: code-design
comment: Here we are at a dead end:
* According to URI matching, a callback should be
* responsible for handling the request,
* we called it, but the callback declared itself
* not responsible.
* We use a goto here, to get out of this dead end,
* and continue with the default handling.
* A goto here is simpler and better to understand
* than some curious loop.
label: code-design
assert(connect_handler==NULL && ready_handler==NULL &&
* data_handler==NULL && close_handler==NULL);
Thread ID (-1=caller thread).
RFC2616 Section 10.3.6
Check if the uri is valid.
* return 0 for invalid uri,
* return 1 for *,
* return 2 for relative uri,
* return 3 for absolute uri without port,
* return 4 for absolute uri with port
Step 2: Check if the request attempts to modify the file system
0 = undef, numerical value may change in different
* versions. For the current definition, see
* mg_get_connection_info_impl
protocol found, port set
Is keep alive allowed by the server
assert(conn->data_len >= 0);
For client connections, mg_context is fake. Since we need to set a
* callback function, we need to create a copy and modify it.
If we can't find the actual file, look for the file
* with the same name but a .gz extension. If we find it,
* use that and set the gzipped flag in the file struct
* to indicate that the response need to have the content-
* encoding: gzip header.
* We can only do this if the browser declares support.
Open the given file and temporary file
If new user, just add it
large enough, so there will be no overflow
ws/wss client context
No body allowed. Close the connection.
Print properties for the requested resource itself
If a callback has been specified, call it.
in/out: request (must be valid)
If the queue is empty, wait. We're idle at this point.
free context
Step 3: Check if it is a websocket request, and modify the document
* root if required
User-defined callback function
We have returned all buffered data. Read new data from the remote
* socket.
Two newline, no carriage return - not standard compliant,
* but
* it
* should be accepted
DEBUG_TRACE
125
This error code is unknown. This should not happen.
1.1. split into url and query string
call the connection_close callback if assigned
Step 8: Call the close handler
no handler to set, this was a remove request to a non-existing
* handler
Everything else but a 3 digit code is invalid
TRACE method (RFC 2616) is not supported for security reasons
Linux, ... (not Windows)
NOTE: Maybe some data has already been sent.
NO_SSL
Value has form "x=y", adjust pointers and lengths
* so that val points to "x", and eq_val points to "y".
Check explicit wish of the client
port remains 0 if the protocol is not found
USE_DUKTAPE
Perform redirect and auth checks before calling begin_request()
* handler.
* Otherwise, begin_request() would need to perform auth checks and
* redirects.
GetProcAddress() returns pointer to function
Unknown informational status code
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
Establish the client connection and request upgrade
8.1: File exists.
Reset attributes. DO NOT TOUCH is_ssl, remote_ip, remote_addr,
* remote_port
Do not read more than the total content length of the
* request.
comment: Disable spurious conversion warning for GCC
label: code-design
HAVE_POLL
Use of fopen here is OK, since fname is only ASCII
However, Linux does not return 0 on success either.
abort scan as soon as one malformed character is found
Config option name, config types, default value
normal end
URI: /path_to_script/script.cgi
comment: appease "unused variable" warning for release builds
label: code-design
Init variables
Reset user data, after close callback is called.
* Do not reuse it. If the user needs a destructor,
* it must be done in the connection_close callback.
in: size of filename buffer
The request addresses a CGI resource, Lua script or
* server-side javascript.
* The URI corresponds to the script itself (like
* /path/script.cgi), and there is no additional resource
* path (like /path/script.cgi/something).
* Requests that modify (replace or delete) a resource, like
* PUT and DELETE requests, should replace/delete the script
* file.
* Requests that read or write from/to a resource, like GET and
* POST requests, should call the script and return the
* generated response.
Internal function. Assumes conn is valid
Send read bytes to the client, exit the loop on error
HTTP 1.1 assumes keep alive if "Connection:" header is not set
* This function must tolerate situations when connection info is not
* set up, for example if request parsing failed.
The rest of the line is the value
Use read() instead of fread(), because if we're reading from the
* CGI pipe, fread() may block until IO buffer is filled up. We
* cannot afford to block and must pass all read bytes immediately
* to the client.
Move the queue forward len bytes
Control characters are not allowed, including zero
Skip all following slashes, backslashes and double-dots
nonce is from a previous start of the server and no longer valid
* (replay attack?)
comment: Initialize this library. This function does not need to be thread safe.
label: requirement
RFC3229 Section 10.4.1
END: CLOCK_MONOTONIC
POSIX return values: see
* http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html
server context
vsnprintf must not be used in any system, * \ \ \ \
* but this define only works well for Windows.
NOTE: override filep->size only on success. Otherwise, it
* might
* break constructs like if (!mg_stat() || !mg_fopen()) ...
RFC2616 Section 10.5.1
RFC 2817 Section 4
1.4. clean URIs, so a path like allowed_dir/../forbidden_file is
* not possible
RFC2616 Section 10.4.8
RFC2518 Section 10.6, RFC4918
* Section 11.5
comment: TODO: deal with legacy
label: requirement
Using filename_buf_len - 1 because memmove() for PATH_INFO may shift
* part of the path one byte on the right.
The mg_upload function is superseeded by mg_handle_form_request.
5.1. first test, if the request targets the regular http(s)://
* protocol namespace or the websocket ws(s):// protocol namespace.
Step 6: Determine the local file path from the root path and the
* request uri.
Handler for specific error, e.g. 404 error
Copy the stuff to temporary file
Print first entry - link to a parent directory
Not required for non-blocking sockets.
set_sock_timeout(conn->client.sock, timeout);
Sanity check the offset
Mask for all nonce values
Allocation failed. Return -1 as "out of memory" error.
dummy for SSL argument to push/pull
inline 7-bit length field
No truncation check for ebuf
Copy socket from the queue and increment tail
pthread mutex not available
Adjust number of bytes to read.
OPENSSL_API_1_1
Unknown request error code
assert(auth_handler == NULL);
Other status codes, not shown in the IANA HTTP status code
* assignment.
* E.g., "de facto" standards due to common use, ...
Loop continuously, reading messages from the socket, invoking the
* callback, and waiting repeatedly until an error occurs.
out: handled by a script?
Lua server page: an SSI like page containing mostly plain
* html
* code
* plus some tags with server generated contents.
SSL callback documentation:
* https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_info_callback.html
* https://linux.die.net/man/3/ssl_set_info_callback
fetch a new chunk
Error sending the body data
put_dir returns -2 if the directory can not be created
reset all members of fileacc
non-constant aggregate initializer: issued due to missing C99 support
pem is not NULL here
Execution time information
13. Handle other methods than GET/HEAD
lfsr will be only 0 if has not been initialized,
* so this code is called only once.
unspecified - may change with the next version
First check if it is a list or just a single value.
could be deprecated global callback
SSL function name
Substitute file is a script file
Ignore any empty entries.
Skip the characters until one of the delimiters characters found.
* 0-terminate resulting word. Skip the delimiter and following whitespaces.
* Advance pointer to buffer to the next word. Return found 0-terminated
* word.
* Delimiters can be quoted with quotechar.
USE_TIMERS
comment: Some proper reactions would be:
* a) close the connections without sending anything
* b) send a 404 not found
* c) try if there is a file matching the URI
* It would be possible to do a, b or c in the callback
* implementation, and return 1 - we cannot do anything
* here, that is not possible in the callback.
*
* TODO: What would be the best reaction here?
* (Note: The reaction may change, if there is a better
*idea.)
label: code-design
Request is directed to a different port
Copy the mask before we shift the queue and destroy it
Errors 1xx, 204 and 304 MUST NOT send a body
next handler in a linked list
WinCE has no pipes
Prepare full path to the index file
We use (signed) cast below because MSVC 6 compiler cannot
* convert unsigned __int64 to double. Sigh.
-1 for path too long,
* -2 for path can not be created.
Invalid request
Use mg_cry here, since gpass has been configured.
Quick fix (for 1.9.x):
defined(_WIN32) && !defined(__SYMBIAN32__) - \
WINDOWS / UNIX include block
ssl already initialized
Unread data from the last chunk
13.2. Handle OPTIONS for files
Set linger option according to configuration
End of headers reached.
BEGIN: CLOCK_REALTIME = wall clock (date and time)
RFC2616 Section 10.5.2
RFC2616 Section 10.3.8
Thread index within ctx
Error while parsing headers
If there is no substitute file, the server could return
* a directory listing in a later step
DTL -- including winsock2.h works better if lean and mean
USE_WEBSOCKET
Local file path and name, corresponding to requested URI
* is now stored in "filename" variable.
failed
Convert time_t to a string. According to RFC2616, Sec 14.18, this must be
* included in all responses other than 100, 101, 5xx.
Translate serial number to a hex string
SEARCH (RFC 5323)
File properties filled by mg_stat:
handler type
image
Important: using local struct mg_file to test path for
* is_directory flag. If filep is used, mg_stat() makes it
* appear as if auth file was opened.
* TODO(mid): Check if this is still required after rewriting
* mg_stat
first try for an exact match
see CONNECTION_TYPE_* above
Opcode == 8, connection close
comment: TODO: handle error
label: requirement
For fseeko(), ftello()
Yes, they are mandatory
gai_strerror could be used to convert gai_ret to a string
defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1
Support PATH_INFO for CGI scripts.
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Handler for all errors
Reject wrong versions
Include \n
A relative uri starts with a / character
Find end of status text
No error, but 0 bytes sent. May be EOF?
File does not exist. This is not always a problem here.
On the fly compression allowed
RFC2616 Section 10.5.6
If we compiled with Mac OSX 10.12 or later, then clock_gettime will be
* declared but it may be NULL at runtime. So we need to check before using
* it.
comment: not registered types
* (http://reference.sitepoint.com/html/mime-types-full,
* http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php, ..)
label: documentation
Open file for writing, create and overwrite
RFC2616 Section 10.4.4
Read the server config to check how long a file may be cached.
* The configuration is in seconds.
file is on disk
Server is to be stopped.
Listening socket
This is an unknown version
Delete not successful (file locked).
find a free worker slot and signal it
WinCE does not support CGI pipes
comment: TODO (low): Replace "membuf" implementation by a "file in memory"
* support library. Use some struct mg_file_in_memory *mf; instead of
* membuf char pointer.
label: code-design
File is already compressed. No "on the fly" compression.
Copy remaining data
Not an SSI tag
some data has been read, or no data was requested
This structure helps to create an environment for the spawned CGI
* program.
* Environment is an array of "VARIABLE=VALUE\0" ASCIIZ strings,
* last element must be NULL.
* However, on Windows there is a requirement that all these
* VARIABLE=VALUE\0
* strings must reside in a contiguous buffer. The end of the buffer is
* marked by two '\0' characters.
* We satisfy both worlds: we create an envp array (which is vars), all
* entries are actually pointers inside buf.
handle request to local server
This thread has been removed from cv's waiting list
Step 7: URI rewriting
one worker thread will be created
Space available in buf
dlsym() on UNIX returns void *. ISO C forbids casts of data
* pointers to function pointers. We need to use a union to make a
* cast.
Disable deprecation warning in VS2005
Use the global passwords file, if specified by auth_gpass option,
* or search for .htpasswd in the requested directory.
RFC2616 Section 10.4.3
16 = Max. thread length in Linux/OSX/..
Check license (zlib has a permissive license, but
__SYMBIAN32__
6.2.1. thus, the server must have real files
Request is directed to another server:
* The server name is different.
Call duktape to generate the page
The chain of threads
Bind to IPv4 only, since IPv6 is not built in.
Return at least a category according to RFC 2616 Section 10.
Accepted sockets
defined for tdm-gcc so we can use getnameinfo
The max request size
RFC2518 Section 10.4, RFC4918 Section 11.3
assert(conn->consumed_content == 0);
The request sent by the client could not be understood by
* the server, or it was incomplete or a timeout. Send an
* error message and close the connection.
Implementation of POSIX opendir/closedir/readdir for Windows.
Do not lock when getting the callback value, here and below.
* I suppose this is fine, since function cannot disappear in the
* same way string option can.
The pre-allocated buffer is large enough.
* Use it to store the string and return the address.
Initialize output string
6.2. this request is a PUT/DELETE to a real file
WinCE has no popen
Poll returned either success (1) or error (-1).
* Forward both to the caller.
output: socket, must not be NULL
The number of configured worker threads.
RFC2616 Section 10.4.10
Full request not yet received
6.1. a custom authorization handler is installed
Deallocate SSL context
Cannot determine if socket is already closed. This should
* not occur and never did in a test. Log an error message
* and continue.
Is valid
function has been selected for automatic inline expansion
Initialize locking callbacks, needed for thread safety.
* http://www.openssl.org/support/faq.html#PROG1
file does not exist and will not be created
3 indicates a websocket client thread
GCC_VERSION >= 40500
This will fail file is the file is in memory
Make sure child closes all pipe descriptors. It must dup them to 0,1
Using fmt as a non-literal is intended here, since it is mostly called
* indirectly by mg_snprintf
Note that POSIX/Winsock's send() is threadsafe
* http://stackoverflow.com/questions/1981372/are-parallel-calls-to-send-recv-on-the-same-socket-valid
* but mongoose's mg_printf/mg_write is not (because of the loop in
* push(), although that is only a problem if the packet is large or
* outgoing buffer is full).
C callback has returned non-zero, do not proceed with
* handshake.
Apple OSX section
comment: Convert variable name into uppercase, and change - to _
label: code-design
Reset ip_version to 0 of there is an error
on linux we can use the old prctl function
comment: Todo: check if cors_origin is in cors_orig_cfg.
* Or, let the client check this.
label: requirement
TCP_USER_TIMEOUT/RFC5482 (http://tools.ietf.org/html/rfc5482):
* max. time waiting for the acknowledged of TCP data before the connection
* will be forcefully closed and ETIMEDOUT is returned to the application.
* If this option is not set, the default timeout of 20-30 minutes is used.
Default is "no".
Since we use a sleep quantum of some seconds to check for recv
* timeouts, we will just wait a few seconds in mg_join_thread.
Free existing block
conditional expression is constant: introduced by FD_SET(..)
Verify given socket address against the ACL.
* Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
10. Request is handled by a script
Handle SSI tag
Not yet a valid request/response
This legacy interface only works for the IPv4 case
comment: Join all worker threads to avoid leaking threads.
label: code-design
Cross-origin resource sharing (CORS), see
* http://www.html5rocks.com/en/tutorials/cors/,
* http://www.html5rocks.com/static/images/cors_server_flowchart.png
* -
* preflight is not supported for files.
RFC7540 Section 9.1.2
Incomplete request
We need to get the client thread out of the select/recv call
* here.
Get connection information. It can be printed or stored by the caller.
* Return the size of available information.
!_WIN32_WCE
File did not exist before fopen was called.
* Maybe it has been created now. Get stat info
* like creation time now.
if this file is in fact a pre-gzipped file, rewrite its filename
* it's important to rewrite the filename after resolving
* the mime type from it, to preserve the actual file's type
convert 1-3 remaining bytes if ((dataLen % 4) != 0)
Initialize SSL library
TODO: SSL_CTX_set_verify(conn->client_ssl_ctx,
* SSL_VERIFY_PEER, verify_ssl_server);
Response code not even within reasonable range
Terminate and forward to the next word
absolute uri (with/without port)
There is no callback, and Lua is not responsible either.
11.2. DELETE method
_MSC_VER
For files, just wait a fixed time,
* maybe an average disk seek time.
Unsupported WEBDAV Methods:
4. Check for CORS preflight requests and handle them (if configured).
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
Valid request
Forward until a space is found - use isgraph here
If callback returns 0, civetweb sets up the SSL certificate.
* If it returns 1, civetweb assumes the calback already did this.
* If it returns -1, initializing ssl fails.
forward_body_data failed.
* The error code has already been sent to the client,
* and conn->status_code is already set.
Return null terminated string of given maximum length.
* Report errors if length is exceeded.
Data information
assert(discard_len >= 0);
Should we support client certificates?
Create the file if does not exist
Buffer for received data
Read and discard pending incoming data. If we do not do that and
* close
* the socket, the data in the send buffer may be discarded. This
* behaviour is seen on Windows, when client keeps sending data
* when server decides to close the connection; then when client
* does recv() it gets no data back.
Terminate string and forward buf to next line
comment: TODO: not thread safe
label: requirement
comment: TODO: add interface to compression module
label: code-design
Send the rest of buffered data
Currently CivetWeb does not nead read+write access.
closing
assert(buffered_len >= 0);
comment: TODO: Check if this lock should be moved to user land.
* Currently the server sets this lock for websockets, but
* not for any other connection. It must be set for every
* conn read/written by more than one thread, no matter if
* it is a websocket or regular connection.
label: code-design
0 means "do not cache". All values <0 are reserved
* and may be used differently in the future.
If we're stopping, sq_head may be equal to sq_tail.
Reply with a 404 Not Found. We are still at a standard
* HTTP request here, before the websocket handshake, so
* we can still send standard HTTP error replies.
<inttypes.h> wants this for C++
Check whether full request is buffered. Return:
* -1 if request or response is malformed
* 0 if request or response is not yet fully buffered
* >0 actual request length, including last \r\n\r\n
Use global passwords file
Close write end fdin and read end fdout and fderr
output: socket address, must not be NULL
comment: TODO: POSIX returns either EAGAIN or EWOULDBLOCK in both cases,
* if the timeout is reached and if the socket was set to non-
* blocking in close_socket_gracefully, so we can not distinguish
* here. We have to wait for the timeout in both cases for now.
label: code-design
this index file is a script
Try to create intermediate directory
All threads exited, no sync is needed. Destroy thread mutex and
* condvars
Linear feedback shift register
Local socket address
Function pointer
init
According to the HTTP standard
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
* URI can be an asterisk (*) or should start with slash (relative uri),
* or it should start with the protocol (absolute uri).
Determine 32/64 bit data mode.
* see https://en.wikipedia.org/wiki/64-bit_computing
-2 means "3rd party thread"
in ms
Search for \n from p till the end of stream
Valid listening port specification is: [ip_address:]port[s]
* Examples for IPv4: 80, 443s, 127.0.0.1:3128, 192.0.2.3:8080s
* Examples for IPv6: [::]:80, [::1]:80,
* [2001:0db8:7654:3210:FEDC:BA98:7654:3210]:443s
* see https://tools.ietf.org/html/rfc3513#section-2.2
* In order to bind to both, IPv4 and IPv6, you can either add
* both ports using 8080,[::]:8080, or the short form +8080.
* Both forms differ in detail: 8080,[::]:8080 create two sockets,
* one only accepting IPv4 the other only IPv6. +8080 creates
* one socket accepting IPv4 and IPv6. Depending on the IPv6
* environment, they might work differently, or might not work
* at all - it must be tested what options work best in the
* relevant network environment.
Bytes sent this second
http://sourceforge.net/p/predef/wiki/Compilers/
If the queue is full, wait
Used nonces, used for authentication
2147479552 (0x7FFFF000) is a limit found by experiment on
* 64 bit Linux (2^31 minus one memory page of 4k?).
common use
Check for recursion
Fill in IP, port info early so even if SSL setup below fails,
* error handler would have the corresponding info.
* Thanks to Johannes Winkelmann for the patch.
Send FIN to the client
defined(_WIN32_WCE)
Read file, byte by byte, and look for SSI include tags
Only in case n=0 (timeout), repeat calling the write function
http://www.webdav.org/specs/rfc4918.html, 9.1:
* When MKCOL is invoked without a request body,
* the newly created collection SHOULD have no
* members. A MKCOL request message may contain
* a message body. The precise behavior of a MKCOL
* request when the body is present is undefined,
* ... ==> We do not support MKCOL with body data.
* This method is idempotent, but not safe (see
* Section 9.1 of [RFC2616]). Responses to this
* method MUST NOT be cached.
This is an already existing directory,
* so there is nothing to do for the server.
path too long
If a file is in memory, set all "stat" members and the membuf pointer of
* output filep and return 1, otherwise return 0 and don't modify anything.
Try to find .htpasswd in requested directory.
PATH_INFO part of the URL
MacOS needs that. If we do not zero it, subsequent bind() will fail.
* Also, all-zeroes in the socket address means binding to all addresses
* for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT).
Similar array as ssl_sw. These functions could be located in different
* lib.
comment: Disable bogus compiler warning -Wdate-time
label: code-design
stdout read
After exec, all signal handlers are restored to their default
* values, with one exception of SIGCHLD. According to
* POSIX.1-2001 and Linux's implementation, SIGCHLD's handler will
* leave unchanged after exec if it was set to be ignored. Restore
* it to default action.
RFC2616 Section 10.3.2
EINVAL - Clock ID is unknown
non-ascii characters must be % encoded
No custom error page. Send default error page.
!_WIN32
end of list
Translate subject and issuer to a string
Number of variables available in var
current mask and opcode, overwritten by
* memmove()
SSL called from an unknown thread: Create some thread index.
comment: Short name is used.
label: code-design
The maximum length of the path to the password file is limited
e.g., def from https://zlib.net/zlib_how.html
Number of variables stored in var
Only for memory statistics
64-bit length field
124
Writes PROPFIND properties for a collection element
13.3. everything but GET and HEAD (e.g. POST)
#define TCP_USER_TIMEOUT (18)
Parse authorization header
comment: We don't use a lock here. Calling mg_stop with the same ctx from
* two threads is not allowed.
label: code-design
Not breaking the loop, process next websocket frame.
non-script files will not have sub-resources
Server side nonce check is valuable in all situations but one:
* if the server restarts frequently, but the client should not see
* that, so the server should accept nonces from previous starts.
Remote user name
Add data to buffer
comment: Do not allow control characters like newline in user name and domain.
* Do not allow excessively long names either.
label: code-design
96
While getaddrinfo on Windows will work with [::1],
* getaddrinfo on Linux only works with ::1 (without []).
File is open for writing. If fclose fails, there was probably an
* error flushing the buffer to disk, so the file on disk might be
* broken. Delete it and return an error to the caller.
RFC2616 Section 10.4.9
Ignore errors. We can't call
* mg_cry here anyway ;-)
RFC2616 Section 10.4.17
Is port SSL-ed
Out of range
Lua in-server module script: a CGI like script used to
* generate
* the
* entire reply.
out: filename
!defined(NO_FILES)
Close so child gets an EOF.
Index block
'type cast' : conversion from 'int' to 'HANDLE' of greater size
Free the request buffer.
Other arguments must not be empty
Poll returned timeout (0).
Make a pointer to the free space int the buffer
fonts
to close
If a Lua background script has been configured, start it.
It could be the hixie draft version
* (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76).
HTTP 1.0 (and earlier) default is to close the connection
Allocate new block
What operating system is running
Head of the socket queue
may be null
no function prototype given: converting '()' to '(void)'
60
We are not in a tag yet.
regular end of content
first time reading from this connection
Windows is not standard-compliant, and vsnprintf() returns -1 if
* buffer is too small. Also, older versions of msvcrt.dll do not have
* _vscprintf(). However, if size is 0, vsnprintf() behaves correctly.
* Therefore, we make two passes: on first pass, get required message
* length.
* On second pass, actually print the message.
Windows and Visual Studio Compiler
Read the rest of CGI output and send to the client
This is the heart of the Civetweb's logic.
* This function is called when the request is read, parsed and validated,
* and Civetweb must decide what action to take: serve a file, or
* a directory, or call embedded function, etcetera.
Describes a string (chunk of memory).
Multiple protocols -> accept the last one.
Read the nonce from the response.
Substitute files have already been handled above.
ACL (RFC 3744)
User-defined data
must be a end of a word, but not a line
#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
First check if the port is the same (IPv4 and IPv6).
Space taken in buf
ws/wss client
For PHP
request is authorized or does not need authorization
mg_fopen will open a file either in memory or on the disk.
* The input parameter path is a string in UTF-8 encoding.
* The input parameter mode is MG_FOPEN_MODE_*
* On success, either fp or membuf will be set in the output
* struct file. All status members will also be set.
* The function returns 1 on success, 0 on error.
Do an unsigned comparison in some conditions below
some intermediate directory has an index file
System info
illegal character for chunk length
HCP24: now check is it a substring or a full cookie name
RFC2616 Section 10.5 - Server Error 5xx
If SSL is loaded dynamically, dlopen/dlclose is required.
not consumed
assert(is_delete_request || (handler!=NULL));
everything is invalid for the moment (might change in the
* future)
The support for duktape is still in alpha version state.
* The name of this config option might change.
connected with IPv4
SSL loaded dynamically from DLL.
* I put the prototypes here to be independent from OpenSSL source
* installation.
Connections information
62
Step 3.1: Check if Lua is responsible.
assert(auth_handler != NULL);
Store the crypto library handle.
In contrast to OpenSSL, wolfSSL does not support certificate
* chain files that contain private keys and certificates in
* SSL_CTX_use_certificate_chain_file.
* The CivetWeb-Server used pem-Files that contained both information.
* In order to make wolfSSL work, it is split in two files.
* One file that contains key and certificate used by the server and
* an optional chain file for the ssl stack.
Sort and print directory entries
A http to https forward port has been specified,
* but no https port to forward to.
The protocol is a comma separated list of names.
comment: Who on earth came to the conclusion, using __DATE__ should rise
* an "expansion of date or time macro is not reproducible"
* warning. That's exactly what was intended by using this macro.
* Just disable this nonsense warning.
label: code-design
NOTE(lsm): order is important here. SSL certificates must
* be initialized before listening ports. UID must be set last.
comment: TODO
label: requirement
stderr read
all file related outputs have already been set to 0, just return
Write data to the IO channel - opened file descriptor, socket or SSL
* descriptor.
* Return value:
* >=0 .. number of bytes successfully written
* -1 .. timeout
* -2 .. error
If there is a connection header from the client, obey
If no index file exists, restore directory path
in: request (must be valid)
SSL functions may fail and require to be called again:
* see https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html
* Here "func" could be SSL_connect or SSL_accept.
Callback for the master thread (type 0)
If only port is specified, bind to IPv4, INADDR_ANY
comment: filename and conn could be unused, if all preocessor conditions
* are false (no script language supported).
label: code-design
Time (wall clock) when connection was
* established
Deallocate worker thread ID array
1 if in read_websocket
Free certificate memory
will not overflow
fclose failed. This might have different reasons, but a likely
* one is "no space on disk", http 507.
max 64 headers
Important! When having connections with and without auth
* would cause double free and then crash
92
+ MicroSoft extensions
* https://msdn.microsoft.com/en-us/library/aa142917.aspx
since the return value is
* int, we may not read more
* bytes
Client sent an "Expect: xyz" header and xyz is not 100-continue.
We do not set a "Cache-Control" header here, but leave the default.
* Since browsers do not send an OPTIONS request, we can not test the
* effect anyway.
Use some UID as session context ID.
Set stop flag, so all threads know they have to exit.
comment: Call poll, but only for a maximum time of a few seconds.
* This will allow to stop the server after some seconds, instead
* of having to wait for a long socket timeout.
label: code-design
11. File does not exist, or it was configured that it should be
* hidden
the file is cached in memory
Read from file, exit the loop on error
civetweb should process the request
Use case sensitive compare function
State
Exit the loop if callback signals to exit (server side),
* or "connection close" opcode received (client side).
RFC2616 Section 10.2.7
Lua rejected the new client
If send failed, wait before retry
current mask and opcode
See http://www.cplusplus.com/reference/cctype/
Worker threads take accepted socket from the queue
File name is relative to the currect document
Prepended CONFIG_ to avoid conflict with the
* socket option typedef TCP_NODELAY.
Authorize against the opened passwords file. Return 1 if authorized.
_WIN32 / else
Use default of the standard
Handler for ws/wss (websocket) requests.
client context: loops must end
comment: conn is currently unused
label: code-design
Append a pointer to the added string into the envp array
!NO_FILES
comment: Avoid unused warning if NO_SSL is set and DEBUG_TRACE is not
used
label: code-design
First store the length information in a text buffer.
Tag is still open
This included all leading \r and \n (isspace)
Step 1: Check websocket protocol version.
See #199 (https://github.com/civetweb/civetweb/issues/199)
Parent closes only one side of the pipes.
* If we don't mark them as closed, close() attempt before
* return from this function throws an exception on Windows.
* Windows does not like when closed descriptor is closed again.
Request info
Connection info
RFC2616 Section 10.4.14
RFC2616 Section 10.4.11
actually, range requests don't play well with a pre-gzipped
* file (since the range is specified in the uncompressed space)
Civetweb configuration parameters
comment: TODO (low): check if this is still required
label: requirement
No handler set - assume "OK"
The rest of the line is the status text
This following lines are just meant as a reminder to use the mg-functions
* for memory management
RFC5842 Section 7.1
RFC2616 Section 10.3.3
No need to continue processing files once we have a
* match, since nothing will reset it back
* to 0.
The "file in memory" feature is a candidate for deletion.
* Please join the discussion at
* https://groups.google.com/forum/#!topic/civetweb/h9HT4CmeYqI
unknown content length
CGI needs it as REMOTE_USER
RFC2616 Section 10.2.2
Valid response
Next character after the port number
State as string
Tail of the socket queue
Calculate how much space is left in the buffer
We already know there is no more data buffered in conn->buf
* but there is more available in the SSL layer. So don't poll
* conn->client.sock yet.
NOTE(lsm): on QNX, poll() returns POLLRDNORM after the
* successful poll, and POLLIN is defined as
* (POLLRDNORM | POLLRDBAND)
* Therefore, we're checking pfd[i].revents & POLLIN, not
* pfd[i].revents == POLLIN.
HPUX defines socklen_t incorrectly as size_t which is 64bit on
* Itanium. Without defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED
* the prototypes use int* rather than socklen_t* which matches the
* actual library expectation. When called with the wrong size arg
* accept() returns a zero client inet addr and check_acl() always
* fails. Since socklen_t is widely used below, just force replace
* their typedef with int. - DTL
No conn
It was defined for WEBDAV in RFC 3253, Sec. 3.6
* (https://tools.ietf.org/html/rfc3253#section-3.6), but seems
* to be useful for REST in case a "GET request with body" is
* required.
WEBDAV (RFC 2518)
!defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
Retrieve requested HTTP header multiple values, and return the number of
* found occurences
stderr write
Build date
Should we stop event loop
process HTTPS connection
filep is initialized in mg_stat: all fields with memset to,
* some fields like size and modification date with values
Destroy other context global data structures mutex
8. handle websocket requests
5.2.1. A callback will handle this request. All requests
* handled
* by a callback have to be considered as requests to a script
* resource.
no can do
comment: Depending on USE_WEBSOCKET and NO_SSL, some oft the protocols might be
* not supported. Clang raises an "unreachable code" warning for parts of ?:
* unreachable, but splitting into four different #ifdef clauses here is more
* complicated.
label: code-design
Loop over passwords file
13.1. Handle PROPFIND
!defined(NO_THREAD_NAME)
comment: GCC unused function attribute seems fundamentally broken.
* Several attempts to tell the compiler "THIS FUNCTION MAY BE USED
* OR UNUSED" for individual functions failed.
* Either the compiler creates an "unused-function" warning if a
* function is not marked with __attribute__((unused)).
* On the other hand, if the function is marked with this attribute,
* but is used, the compiler raises a completely idiotic
* "used-but-marked-unused" warning - and
* #pragma GCC diagnostic ignored "-Wused-but-marked-unused"
* raises error: unknown option after ‘#pragma GCC diagnostic’.
* Disable this warning completely, until the GCC guys sober up
* again.
label: code-design
Step 7: Enter the read loop
11.3. MKCOL method
linked list of shared lua websockets
comment: clean zombies
label: code-design
Read the first line of the script into the buffer
RFC2518 Section 10.5, RFC4918
* Section 11.4
Check after term
comment: The "non blocking" property should already be
* inherited from the parent socket. Set it for
* non-compliant socket implementations.
label: code-design
Substitute file found. Copy stat to the output, then
* check if the file is a script file
5. interpret the url to find out how the request must be handled
comment: TODO(lsm, low): propagate an error to the caller
label: code-design
Start worker threads
relative uri
comment: Unused.
label: code-design
Don't use mg_cry here, but only a trace, since this is
* a typical case. It will occur for every directory
* without a password file.
Close, if civetweb framework needs to close
HPUX 11 does not have monotonic, fall back to realtime
No more data left to read
Start WinSock for Windows
Increase priority of the master thread
Windows specific
5.2.2. No callback is responsible for this request. The URI
* addresses a file based resource (static content or Lua/cgi
* scripts in the file system).
Get the next step of both random number generators.
RFC2616 Section 10.2.6
Un-initialize this library.
Wait for a thread to finish.
DTL add for SO_EXCLUSIVE
Add all headers as HTTP_* variables
NOTE(lsm): this enum shoulds be in sync with the config_options below.
conn is assumed to be valid in this internal function
not OPENSSL_API_1_1
Test for different ways to format this string
Allocate space to hold websocket payload
Not connected
URI: /path_to_script/script.cgi/path_info
Step 3: No callback. Check if Lua is responsible.
comment: TODO: check if conn->ctx can be set
label: requirement
For flockfile() on Linux
Implementation of API function for HTTP clients
Mark the queue as advanced
END: CLOCK_PROCESS
Total size of data in a buffer
9b. This request is either for a static file or resource handled
* by a script file. Thus, a DOCUMENT_ROOT must exist.
Handler for authorization requests
first try to find an existing handler
If peem is NULL and conn->ctx->callbacks.init_ssl is not,
* refresh_trust still can not work.
Request is directed to this server - full name match.
the value is not required
No content
+ 11 methods from RFC 3253
comment: goto spawn_cleanup;
label: code-design
7. check if there are request handlers for this uri
comment: TODO(Feature): this is no longer a boolean, but yes/no/optional
label: code-design
END: CLOCK_THREAD
comment: TODO (mid): Define proper return values - maybe return length?
* For the first test use <0 for error and >0 for OK
label: code-design
Set the thread name for debugging purposes in Visual Studio
* http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
Set TCP keep-alive. This is needed because if HTTP-level
* keep-alive
* is enabled, and client resets the connection, server won't get
* TCP FIN or RST and will keep the connection open forever. With
* TCP keep-alive, next keep-alive handshake will figure out that
* the client is down and will close the server end.
* Thanks to Igor Klopov who suggested the patch.
Substitute file is a regular file
comment: Disable TCP Nagle's algorithm. Normally TCP packets are coalesced
* to effectively fill up the underlying IP packet payload and
* reduce the overhead of sending lots of small buffers. However
* this hurts the server's throughput (ie. operations per second)
* when HTTP 1.1 persistent connections are used and the responses
* are relatively small (eg. less than 1400 bytes).
label: code-design
out: put/delete a file?
Check for a valid http method
The server must only return one value from this list.
Windows happily opens files with some garbage at the end of file name.
* For example, fopen("a.cgi ", "r") on Windows successfully opens
* "a.cgi", despite one would expect an error back.
* This function returns non-0 if path ends with some garbage.
If name=" is found, search for the closing "
Read new data
There are three ways to encode data from a HTML form:
* 1) method: GET (default)
* The form data is in the HTTP query string.
* 2) method: POST, enctype: "application/x-www-form-urlencoded"
* The form data is in the request body.
* The body is url encoded (the default encoding for POST).
* 3) method: POST, enctype: "multipart/form-data".
* The form data is in the request body of a multipart message.
* This is the typical way to handle file upload from a form.
If the boundary is already in the buffer, get the address,
* otherwise next will be NULL.
GET request: form data is in the query string.
Get the mandatory name="..." part of the Content-Disposition
* header.
comment: TODO: check Content-Type
label: requirement
No query string.
Copy boundary string to variable "boundary"
comment: Sanity check: The algorithm can not work if bl >= sizeof(buf),
* and it will not work effectively, if the buf is only a few byte
* larger than bl, or if buf can not hold the multipart header
* plus the boundary.
* Check some reasonable number here, that should be fulfilled by
* any reasonable request from every browser. If it is not
* fulfilled, it might be a hand-made request, intended to
* interfere with the algorithm.
label: code-design
No body data, but not a GET request.
* This is not a valid form request.
comment: Sanity check: A boundary string of less than 4 bytes makes
* no sense either.
label: code-design
Store the content of the buffer.
Read body data and split it in keys and values.
* The encoding is like in the "GET" case above: a=1&b&c=3&c=4.
* Here we use "POST", and read the data from the request body.
* The data read on the fly, so it is not required to buffer the
* entire request in memory before processing it.
comment: The initial sanity check
* (bl + 800 > sizeof(buf))
* is no longer required, since sizeof(buf) == 1024
*
* Original comment:
label: code-design
Malformed request (the filename field is optional, but if
* it exists, it needs to be terminated correctly).
Malformed request
Unknown Content-Type
Call callback
}
comment: And others complain, the result is unused.
label: code-design
All parts handled
We must do a binary search here, not a string search, since the buffer
* may contain '\x00' bytes, if binary data is transferred.
Copyright (c) 2016-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
RFC 2616 Sec. 2.2 defines a list of allowed
* separators, but many of them make no sense
* here, e.g. various brackets or slashes.
* If they are used, probably someone is
* trying to attack with curious hand made
* requests. Only ; , space and tab seem to be
* reasonable here. Ignore everything else.
End of handle_form.inl
If the boundary is quoted, trim the quotes
Next, we need to get the part header: Read until \r\n\r\n
TODO: Create a function to get "all_data_read" from
* the conn object. All data is read if the Content-Length
* has been reached, or if chunked encoding is used and
* the end marker has been read, or if the connection has
* been closed.
RFC 2046 permits the boundary string to be quoted.
Store the content to a file
if (field_storage == FORM_FIELD_STORAGE_READ) {
In theory, it could be possible that someone crafts
* a request like name=filename=xyz. Check if name and
* filename do not overlap.
Log error message and stop parsing the form data.
Skip \r\n\r\n
There has to be a BOUNDARY definition in the Content-Type header
No data
name= without quotes is also allowed
Try the same without quotes
Out of memory
In every "field_found" callback we ask what to do with the
* data ("field_storage"). This could be:
* FORM_FIELD_STORAGE_SKIP (0) ... ignore the value of this field
* FORM_FIELD_STORAGE_GET (1) ... read the data and call the get
* callback function
* FORM_FIELD_STORAGE_STORE (2) ... store the data in a file
* FORM_FIELD_STORAGE_READ (3) ... let the user read the data
* (for parsing long data on the fly)
* (currently not implemented)
* FORM_FIELD_STORAGE_ABORT (flag) ... stop parsing
Split data in a=1&b=xy&c=3&c=4 ...
The form data is in the request body data, encoded in key/value
* pairs.
avoid warning
Must not be smaller than ~900 - see sanity check
read error
comment: The idea of "field_storage=read" is to let the API user read
* data chunk by chunk and to some data processing on the fly.
* This should avoid the need to store data in the server:
* It should neither be stored in memory, like
* "field_storage=get" does, nor in a file like
* "field_storage=store".
* However, for a "GET" request this does not make any much
* sense, since the data is already stored in memory, as it is
* part of the query string.
label: code-design
Loop to read values larger than sizeof(buf)-keylen-2
Log error message and skip this field.
Remove from the buffer
The entire data has already been loaded, so there is no nead to
* call mg_read. We just need to split the query string into key-value
* pairs.
init here, to a avoid a false positive
"uninitialized variable used" warning
Equivalent to "upload" callback of "mg_upload".
Every part must end with \r\n, if there is another part.
* The end of the request has an extra --
End of the request
According to the RFC, every part has to have a header field like:
* Content-Disposition: form-data; name="..."
It could be somethingname= instead of name=
Stop parsing the request
Proceed to next entry
Skip all spaces between MULTIPART/FORM-DATA; and BOUNDARY=
Find boundary
Content-Type: application/octet-stream
Get the optional filename="..." part of the Content-Disposition
* header.
comment: This line is not required, but otherwise some compilers
* generate spurious warnings.
label: code-design
Set "towrite" to the number of bytes available
* in the buffer
TODO: Create a function to get "all_data_read"
* from the conn object. All data is read if the
* Content-Length has been reached, or if chunked
* encoding is used and the end marker has been
* read, or if the connection has been closed.
comment: we do not need mg_cry here, so conn is currently unused
label: code-design
This callback will deliver partial contents
comment: Do some sanity checks for boundary lengths
label: code-design
It could be somethingfilename= instead of filename=
stored successfully
The form data is in the request body data, encoded as multipart
* content (see https://www.ietf.org/rfc/rfc1867.txt,
* https://www.ietf.org/rfc/rfc2388.txt).
Call callback for new field
From RFC 2046:
* Boundary delimiters must not appear within the
* encapsulated material, and must be no longer
* than 70 characters, not counting the two
* leading hyphens.
Subtract the boundary length, to deal with
* cases the boundary is only partially stored
* in the buffer.
If filename=" is found, search for the closing "
Should we use a config file ?
Initialize the dialog elements
comment: Unused code from "string duplicate with escape"
label: code-design
Errno will still hold the error from fopen.
invalid number
Show usage if -h or --help options are specified
option set correctly
Trim additional spaces between option name and value - then
* (line+j) contains the option value
Set by init_system_info()
Get content of input line
Dialog proc for input dialog
Attach menu to the status bar
Run this app as agent
UNC path, e.g.
\\server\dir
initWithTitle:[NSString stringWithFormat:@"%s", server_name]
Make extra verification for certain options
mg_start copies all options to an internal buffer.
* The options data field here is not required anymore.
This should also be sufficient for "realpath", according to
* http://man7.org/linux/man-pages/man3/realpath.3.html, but in
* reality it does not seem to work.
strip UTF-8 BOM
Disable deprecation warning in VS2005
Required for some functions (tray icons, ...)
invalid boolean
defined(_WIN32) && !defined(__SYMBIAN32__) - WINDOWS / UNIX include \
block
For __MINGW32/64_MAJOR/MINOR_VERSION define
Setup signal handler: quit on Ctrl-C
integer number >= 0, e.g. number of threads
defined(_WIN32) && !defined(__SYMBIAN32__) - WINDOWS / UNIX include \
block
If option is already set and it is an absolute path,
leave it as it is -- it's already absolute.
for taskbar creation
Remove user
Edit passwords file: Remove user, if -R option is specified
WINDOWS / UNIX include block
Update config based on command line arguments
Advance to next character
No config file set. Path to exe found in arg[0].
* Use default file name next to the executable.
Required for unit testing
If value is the same as default, skip it
Win32 has a small GUI.
* Define some GUI elements and Windows message handlers.
Set by init_server_name()
comment: TODO (low, api makeover): options should be an array of key-value-pairs,
* like
* struct {const char * key, const char * value} options[]
* but it currently is an array with
* options[2*i] = key, options[2*i + 1] = value
* (probably with a MG_LEGACY_INTERFACE definition)
label: code-design
backup config file
Start option -I:
* Show system information and exit
* This is very useful for diagnosis.
<inttypes.h> wants this for C++
Do not open a password dialog, if the username is empty
Option already set. Overwrite
LPARAM pointer passed to WM_INITDIALOG
any text
Add status bar menu
Make sure we have absolute paths for files and directories
Initialize user data
Add version menu item
Invalid esc sequence
Load config file settings first
Line is only \
Add configuration menu item
Separator
Start Civetweb
Option not set yet. Add new option
Create the dialog
Loop over the lines in config file
Ignore empty lines and comments
alternative: SendMessage(hDlg, WM_COMMAND, ID_RESET_FILE, 0);
Set dialog handle for the caller
comment: Path to executable plus magic argument
label: code-design
C++ wants that for INT64_MAX
Dialog proc for password dialog
Get handle of input line
_WIN32
lines of text, separated by carriage return line feed
Use same defines as in civetweb.c before including system headers.
Add quit menu item
Terminate the string - then the string at (line+i) contains the
* option name
Copyright (c) 2013-2017 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Handle command line flags.
They override config file and default settings.
Create a password suggestion
Absolutize the path, and set the option
Set by start_civetweb()
invalid ESC sequence
Call Lua with additional CivetWeb specific Lua functions, if -L option
* is specified
Only allow one instance of this dialog to be open.
list of text items, separated by ,
Add delegate to process menu item actions
Add connect menu item
Return the WM_QUIT value.
comment: TODO: define what to do
label: code-design
Otherwise: CivetWeb can work without a config file
comment: TODO: This is not really uer friendly
label: code-design
Skip spaces, \r and \n at the end of the line
ignore result
boolean value, yes or no
Edit passwords file: Add user or change password, if -A option is
* specified
Advance mbl characters (+1 is below)
unknown option
try alternate config file
Reload field with this ID
If mg_start fails, it returns NULL
Window proc for taskbar icon
no break
Not absolute. Use the directory where civetweb executable lives
be the relative directory for everything.
Extract civetweb executable directory into path.
Load current string
Dialog proc for settings dialog
We've just sent our own quit message, with proper hwnd.
Call Duktape, if -E option is specified
Modify password
Set by process_command_line_arguments()
for tdm-gcc so we can use getconsolewindow
Passed to mg_start() by start_civetweb()
valid characters are 32 to 126
Set option
list of patterns, separated by |
For PATH_MAX on linux
Open the config file
For fseeko(), ftello()
The first command line parameter is a config file name.
Main loop should exit
Input dialog is not empty.
If we're under MacOS and started by launchd, then the second
argument is process serial number, -psn_.....
In this case, don't process arguments at all.
E.g. X:\dir
This is an input dialog
!CONFIG_FILE
Store hWnd in a parameter accessible by the parent, so we can
* bring this window to front if required.
Find the space character between option name and value
Make buffer available for input dialog
In case this causes a problem, disable the warning:
* #pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
* #pragma clang diagnostic ignored "-Wimplicit-function-declaration"
Text boxes for files have "..." buttons to open file browser. These
buttons have IDs that are ID_FILE_BUTTONS_DELTA higher than associated
text box ID.
Run the app
Invalid multi byte character
comment: TODO (low): check this option when it is set, instead of calling
* verify_existence later
label: code-design
read all configurations from a config file
18 bytes
No config file set. No path in arg[0] found.
* Use default file name in the current path.
Check whether option is already set
Init dialog with active settings
There is no input line in this dialog.
If config file was set in command line and open failed, die.
Create config file if it is not present yet
Get dialog parameters
Failed to open the file. Keep errno for the caller.
Use 64-bit file offsets by default
All dynamically created text boxes for options have IDs starting from
ID_CONTROLS, incremented by one.
Set dialog name
Add user
This option is evaluated by main.c, not civetweb.c - just skip it
* and return OK
0xffff5bb1
0xd4ef3085
accumulate block
0x8771f681
0xfffa3942
Define storage for little-endian or both types of CPUs.
Let [abcd k s t] denote the operation
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s).
0xd9d4d039
Let [abcd k s t] denote the operation
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s).
message length in bits, lsw first
Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
0xf7537e82
(dynamic only)
32-bit word
Process full blocks.
0xf4d50d87
data are properly aligned, a direct assignment is possible
Append a string to the message.
0xe8c7b756
0xc040b340
comment: 1 = big-endian, -1 = little-endian, 0 = unknown
label: code-design
0xc4ac5665
0xfd987193
0xffeff47d
0xf6bb4b60
Define storage only for big-endian CPUs.
0xfe2ce6e0
0xe6db99e5
$Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $
0xfc93a039
0xa8304613
Do the following 16 operations.
(static only)
cast through a (void *) should avoid a compiler warning,
see
https://github.com/bel2125/civetweb/issues/94#issuecomment-98112861
dynamic little-endian
0xf61e2562
comment:
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
label: documentation
0xab9423a7
0xc33707d6
0xf4292244
Save the length before padding.
comment:
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
label: code-design
* On big-endian machines, we must arrange the bytes in the
* right order.
Process a final partial block.
0xd8a1e681
0xe7d3fbc8
0x98badcfe
0xc1bdceee
0xeaa127fa
0xa4beea44
0x8f0ccc92
8-bit byte
0xd62f105d
Update the message length.
comment:
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.c is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
either statically or dynamically; added missing #include <string.h>
in library.
2002-03-11 lpd Corrected argument list for main(), and added int return
type, in test program and T value program.
2002-02-21 lpd Added missing #include <stdio.h> in test program.
2000-07-03 lpd Patched to eliminate warnings about "constant is
unsigned in ANSI C, signed in traditional"; made test program
self-checking.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1999-05-03 lpd Original version.
label: code-design
0xa679438e
Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s).
Pad to 56 bytes mod 64.
0xd76aa478
* This an amalgamation of md5.c and md5.h into a single file
* with all static declaration to reduce linker conflicts
* in Civetweb.
*
* The MD5_STATIC declaration was added to facilitate static
* inclusion.
* No Face Press, LLC
end extern "C"
digest buffer
0xf57c0faf
Round 4.
End of md5.inl
0xbebfbc70
comment:
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
label: code-design
Round 2.
Process an initial partial block.
Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s).
Round 3.
dynamic big-endian
Append the length.
0xeb86d391
0x895cd7be
0x8b44f7af
0xfd469501
$Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $
0xbd3af235
0x85845dd1
Round 1.
[64]
Initialize the algorithm.
0xe9b6c7aa
0xfde5380c
Finish the message and return the digest.
0x8d2a4c8a
Define the state of the MD5 Algorithm.
* On little-endian machines, we can process properly aligned
* data without copying it.
0xefcdab89
md5_INCLUDED
not aligned
0xa9e3e905
little-endian
0xa3014314
big-endian
0xfcefa3f8
Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
was started.)
add function conn.read
call the table "civetweb"
subfolder "conn.http_headers"
1 = nargs
Add "conn" object
Add "civetweb" object
0 = nargs
call the table "conn"
probably never reached, but satisfies static code analysis
add function conn.write
duk_push_global_stash(duk_ctx);
duk_get_prop_string(duk_ctx, -1, civetweb_conn_id);
conn = (struct mg_connection *)duk_to_pointer(duk_ctx, -1);
Note: This is only experimental support, so the API may still change.
ignore result
add string conn.r...
Create Duktape interpreter state
create a new table/object ("conn")
For evaluation purposes, currently only "send" is supported.
* All other ~50 functions will be added later.
Script is called "protected" (duk_peval_file), so script errors should
* never yield in a call to this function. Maybe calls prior to executing
* the script could raise a fatal error.
This file is part of the CivetWeb web server.
* See https://github.com/civetweb/civetweb/
* (C) 2015-2017 by the CivetWeb authors, MIT license.
Alternative: redefine a new, clean API from scratch (instead of using mg),
* or at least do not add problematic functions.
comment: TODO: the mg context should be added to duktape as well
label: code-design
End of mod_duktape.inl
mg.include: Include another .lp file
No truncation check for ebuf
Forward declarations
just one text: send it to all client
client id, opcode string and message text
mg.set_timeout for websockets
Variable found: return value to Lua
Get connection info for connection idx
path_type==NULL is the legacy use case with 1 argument
Do not closesocket(*psock); here, close it in __gc
Return the current "keep_alive" state. This may be false, even it
* keep_alive(true) has been called.
Assume the script does not support keep_alive. The script may change this
* by calling mg.keep_alive(true).
Register mg module
Lua server pages store the depth of mg.include, in order
* to detect recursions and prevent stack overflows.
mg.write for websockets
This function may be called with one parameter (boolean) to set the
keep_alive state.
Or without a parameter to just query the current keep_alive state.
Get option according to argument
comment: TODO (high): ip version
label: requirement
comment: unused
label: code-design
Syntax error or OOM. Error message is pushed on
* stack.
mg.get_var
Stack of includes
Allocate dynamically, so there is no internal limit for get_var
"relative" = file name is relative to the
* currect document
The civetweb internal random number generator will generate
* a 64 bit random number.
remote_ip is
deprecated, use
remote_addr
instead
mg.redirect: Redirect the request (internally).
mg.base64_encode
comment: TODO: dont use "bits" but fields with
a meaning according to
http://tools.ietf.org/html/rfc6455,
section 5.2
label: code-design
Preload
comment: not used
label: code-design
client id, opcode number and message text
lua_Number may be used as 52 bit integer
zero or one return value
mg.write: Send data to the client
comment: TODO (low): handle OOM
label: code-design
Error when loading the file (e.g. file not found,
* out of memory, ...)
comment: TODO: Delete lua_websock_data and remove it from the websocket list.
This must only be done, when all connections are closed, and all
asynchronous operations and timers are completed/expired.
label: code-design
This file is part of the CivetWeb web server.
* See https://github.com/civetweb/civetweb/
Execute a plain Lua script.
Correct number of arguments
mg.get_info
Register default mg.onerror function
mg.send_file
Remove from ws connection list.
comment: Variable not found (TODO (mid): may be string too long)
label: code-design
comment: TODO (low): Test if this could be used as a replacement for bit32.
* Check again with Lua 5.3 later.
label: test
mmap failed
The script file is loaded, now call it
comment: Lua error handler should show the status code
label: code-design
comment: unused parameters
label: code-design
File not found or not accessible
mg.get_time
opcode number and message text
call add
reg_int64: content_length
Get info according to argument
call mg.write()
Export mg.request_info
"virtual" = relative to document root.
mg.set_interval for websockets
Store script name and increment depth
comment: TODO(lsm, low): leave the stack balanced
label: code-design
Get context info for server context
Store context in the registry
no arguments
mg.url_decode
comment: TODO (low): This is an incomplete implementation of mmap for windows.
* Currently it is sufficient, but there are a lot of unused parameters.
* Better use a function "mg_map" which only has the required parameters,
* and implement it using mmap in Linux and CreateFileMapping in Windows.
* Noone should expect a full mmap for Windows here.
label: code-design
Silently stop processing chunks.
client id and message text
UUID library and function pointer
mg.keep_alive: Allow Lua pages to use the http keep-alive mechanism
opcode string and message text
add ws to list
"absolute" = file name is relative to the
* webserver working directory
* or it is absolute system path.
mg.get_response_code_text
handle_lsp_request returned an error code, meaning an error
* occured in the included page and mg.onerror returned non-zero.
* Stop processing.
mg_fopen opens the file and sets the size accordingly
Get context
comment: TODO (mid): not implemented yet
label: requirement
comment: shared_websock_list unused (see open TODO)
label: code-design
mg.cry: Log an error. Default value for mg.onerror.
End of mod_lua.inl
Export connection specific info
mg.random - might be better than math.random on some systems
Lua "number" is a IEEE 754 double precission float:
* https://en.wikipedia.org/wiki/Double-precision_floating-point_format
* Thus, mask with 2^53-1 to get an integer with the maximum
* precission available.
mg.md5
mg.get_mime_type
mg.uuid
Get context info for NULL context
Success loading chunk. Call it.
TODO (mid): Check if list entry and Lua state needs to be deleted
* (see websocket_close).
mg.url_encode
mg.read: Read data from the client (e.g., from a POST request)
Get LSP include history table
Error when executing the script
comment: <?= ?> means a variable is enclosed and its value should be
* printed
label: code-design
Lua state is ready to use
Syntax error
init ws list element
Map file in memory (size is known).
Script executed
Get system info
We're not sending HTTP headers here, Lua page must do it.
name only used for debugging
inc ref count
Methods and meta-methods supported by the object returned by connect.
* For meta-methods, see http://lua-users.org/wiki/MetatableEvents
comment: Keep the "connect" method for compatibility,
* but do not backport it to Lua 5.1.
* TODO: Redesign the interface.
label: code-design
reg_conn_function(L, "send_file", lsp_send_file, conn);
If the first argument is a number,
convert it to the corresponding text.
Lua uses 1 based index, C uses 0 based index
errors as strint return value
check if ws already in list
mg.get_cookie
lock list (mg_context global)
lua_close(L); must be done somewhere else
mg.get_option
Add padding and return the message digest.
SHA-1 in C
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
-----------------
Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
Corrected a problem which generated improper hash values on 16 bit machines
Routine SHA1Update changed from
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned int
len)
to
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned
long len)
The 'len' parameter was declared an int which works fine on 32 bit machines.
However, on 16 bit machines an int is too small for the shifts being done
against
it. This caused the hash function to generate incorrect values if len was
greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
Since the file IO in main() reads 16K at a time, any file 8K or larger would
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
"a"s).
I also changed the declaration of variables i & j in SHA1Update to
unsigned long from unsigned int for the same reason.
These changes should make no difference to any 32 bit implementations since
an
int and a long are the same size in those environments.
--
I also corrected a few compiler warnings generated by Borland C.
1. Added #include <process.h> for exit() prototype
2. Removed unused variable 'j' in SHA1Final
3. Changed exit(0) to return(0) at end of main.
ALL changes I made can be located by searching for comments containing 'JHB'
-----------------
Modified 8/98
By Steve Reid <sreid@sea-to-sky.net>
Still 100% public domain
1- Removed #include <process.h> and used return() instead of exit()
2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
-----------------
Modified 4/01
By Saul Kravitz <Saul.Kravitz@celera.com>
Still 100% PD
Modified to run on Compaq Alpha hardware.
-----------------
Modified 07/2002
By Ralph Giles <giles@ghostscript.com>
Still 100% public domain
modified for use with stdint types, autoconf
code cleanup, removed attribution comments
switched SHA1Final() argument order for consistency
use SHA1_ prefix for public api
move public api to sha1.h
little endian / intel byte order
I got the idea of expanding during the round function from SSLeay
Endian independent
comment:
11/2016 adapted for CivetWeb:
include sha1.h in sha1.c,
rename to sha1.inl
remove unused #ifdef sections
make endian independent
align buffer to 4 bytes
remove unused variable assignments
label: code-design
4 rounds of 20 operations each. Loop unrolled.
Should cause a SHA1_Transform()
blk0() and blk() perform the initial expand.
Wipe variables
SHA1 initialization constants
Copy context->state[] to working vars
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
Hash a single 512-bit block. This is the core of the algorithm.
SHA1Init - Initialize new context
(R0+R1), R2, R3, R4 are the different operations used in SHA1
Must use an aligned, read/write buffer
Add the working vars back into context.state[]
End of sha1.inl
/ capacity of current token
/ stores number of special character codes
Tokenizer_print(tok);
set metatable:
set __tostring metamethod
/ stores next token, if already determined
/ pointer to current token
*
LuaXML License
LuaXml is licensed under the terms of the MIT license reproduced below,
the same as Lua itself. This means that LuaXml is free software and can be
used for both academic and commercial purposes at absolutely no cost.
Copyright (C) 2007-2013 Gerald Franz, eludi.net
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
/ stores current read position
/ stores size of string to be tokenized
read elements
register default codes:
/ stores code table for special characters
/ stores current read context
/ stores string to be tokenized
parse tag header
new tag found
/ size of current token
--- internal tokenizer -------------------------------------------
void Tokenizer_print(Tokenizer* tok) { printf(" @%u %s\n", tok->i, !tok->m_token ? "(null)" : (tok->m_token[0]==ESC)?"(esc)" : (tok->m_token[0]==OPN)?"(open)": (tok->m_token[0]==CLS)?"(close)" : tok->m_token); fflush(stdout); }
/ stores currently allocated capacity for special character codes
regular attribute
this tag has no content, only attributes
trim whitespace
strip comments
--- local variables ----------------------------------------------
/ size of next token
interpet CDATA
parse tag and content:
use index 0 for storing the tag
--- auxliary functions -------------------------------------------
strip meta information
--- public methods -----------------------------------------------
previous tag is over
pop current table
Lua 5.1 detected
not supported
This header is intended to support Lua 5.1, Lua 5.2 and Lua 5.3 in the same
* C source code.
Lua 5.2 detected
Must use luaL_newstate() for 64 bit target
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
#ifndef CIVETWEB_LUA_H
Lua 5.3 detected
Shared helper to generate DUK_OPT_xxx and DUK_USE_xxx documentation.
XXX: unfinished placeholder
Add a header snippet for detecting presence of DUK_OPT_xxx feature
options which will be removed in Duktape 2.x.
Add a header snippet for providing a __OVERRIDE_DEFINES__ section.
XXX: unsigned constants?
Globals holding scanned metadata, helper snippets, etc
verbatim text for the entire line
comment: Derived defines (DUK_USE_INTEGER_LE, etc) from DUK_USE_BYTEORDER.
Duktape internals currently rely on the derived defines. This is
after sanity checks because the derived defines are marked removed.
label: code-design
Add original snippets. This fills in the required nodes
recursively.
comment: DUK_OPT_xxx always come from outside
label: code-design
print('#snippet ' + sub_fn)
already present
comment: XXX: more checks
label: code-design
Assume these provides come from outside.
Feature selection, system include, Date provider
Most #include statements are here
Remaining tags in alphabetic order
Automatic DUK_OPT_xxx feature option handling
key is known
Byte order and alignment defines are allowed to be missing,
a fill-in will handle them. This is necessary because for
some architecture byte order and/or alignment may vary between
targets and may be software configurable.
integer value
Figure out fill-ins by looking for snippets not in original
list and without any unserialized dependent nodes.
comment:
Autogeneration of option documentation
label: documentation
duk_config.h generation
print(repr(graph))
print(repr(snlist))
print('Resolved helper defines: %r' % resolved)
Detect and reject 'fast math'
comment: XXX: conditional warning, happens in some normal cases
print('WARNING: define %r required, not provided so far' % k)
label: code-design
Helper for building a text file from individual lines, injected files, etc.
Inserted values are converted to Snippets so that their provides/requires
information can be tracked. When non-C outputs are created, these will be
bogus but ignored.
Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
NOTE: careful with Python equality, e.g. "0 == False" is true.
Metadata to scan from config files.
Generate a duk_config.h where platform, architecture, and compiler are
all either autodetected or specified by user.
Autodetection is based on a configured list of supported platforms,
architectures, and compilers. For example, platforms.yaml defines the
supported platforms and provides a helper define (DUK_F_xxx) to use for
detecting that platform, and names the header snippet to provide the
platform-specific definitions. Necessary dependencies (DUK_F_xxx) are
automatically pulled in.
Automatic "fill ins" are used for mandatory platform, architecture, and
compiler defines which have a reasonable portable default. This reduces
e.g. compiler-specific define count because there are a lot compiler
macros which have a good default.
comment: XXX: require automatic detection to be signaled?
e.g. define DUK_USE_ALIGN_BY -1
define DUK_USE_BYTE_ORDER -1
label: code-design
Development time helper: add DUK_ACTIVE which provides a runtime C string
indicating what DUK_USE_xxx config options are active at run time. This
is useful in genconfig development so that one can e.g. diff the active
run time options of two headers. This is intended just for genconfig
development and is not available in normal headers.
Default value is false, and caller has emitted
an unconditional #undef, so don't emit a duplicate
Platform, architecture, compiler fillins. These are after all
detection so that e.g. DUK_SPRINTF() can be provided by platform
or compiler before trying a fill-in.
Main
comment: XXX: indicate feature option support, sanity checks enabled, etc
in general summary of options, perhaps genconfig command line?
label: code-design
sort under primary tag
comment: for line in stripped_lines: print(line)
label: code-design
comment: XXX: better to lookup compilers metadata
label: code-design
Compiler files must provide at least these (additional checks
in validate_compiler_file()). Fill-ins provide missing optionals.
Header snippet representation: lines, provides defines, requires defines.
comment: Find a header snippet which provides the missing define.
Some DUK_F_xxx files provide multiple defines, so we don't
necessarily know the snippet filename here.
label: code-design
signal to fillin
print('Tags: %r' % use_tags_list)
must be #define'd
Compatibility with Duktape 1.3
compiling Duktape from a single source file (duktape.c) version
compiling Duktape (not user application)
artifact, include guard
Forced options from multiple sources are gathered into a shared list
so that the override order remains the same as on the command line.
Avoid ambiguous hex escapes
Snippet provides it's own require; omit
print('config option %s not covered by manual snippets, emitting default automatically' % k)
comment: XXX: rst or other format
label: code-design
C string value
Platform files must provide at least these (additional checks
in validate_platform_file()). Fill-ins provide missing optionals.
shallow copy
Architecture files must provide at least these (additional checks
in validate_architecture_file()). Fill-ins provide missing optionals.
Generate a duk_config.h header with platform, compiler, and
architecture either autodetected (default) or specified by
user. Support for autogenerated DUK_OPT_xxx flags is also
selected by user.
comment: XXX: aware of target version
label: code-design
Preferred tags first
snippet list
comment: XXX: better to lookup architectures metadata
label: code-design
graph[A] = [ B, ... ] <-> B, ... provide something A requires.
x is a Snippet
Helper headers snippets.
lines of text and/or snippets
map from define to 'True' for now
map from define to 'True' for now
comment: Insert missing define dependencies into index 'idx_deps' repeatedly
until no unsatisfied dependencies exist. This is used to pull in
the required DUK_F_xxx helper defines without pulling them all in.
The resolution mechanism also ensures dependencies are pulled in the
correct order, i.e. DUK_F_xxx helpers may depend on each other (as
long as there are no circular dependencies).
XXX: this can be simplified a lot
label: code-design
strip last newline to avoid empty line
comment: DUK_USE_xxx are internal and they should not be 'requirements'
label: code-design
This is a fallback in case config option metadata is wrong.
byteorder provided by all architecture files
alignment provided by all architecture files
packed tval provided by all architecture files
print('Autoscanning snippet: %s' % fn)
for printing only
comment: XXX: detect and handle loops cleanly
label: code-design
Emit a default #define / #undef for an option based on
a config option metadata node (parsed YAML doc).
Object layout
Careful with order, snippet may self-reference its own
defines in which case there's no outward dependency.
(This is not 100% because the order of require/provide
matters and this is not handled now.)
Also, some snippets may #undef/#define another define but
they don't "provide" the define as such. Such redefinitions
are marked "/* redefine */" in the snippets. They're best
avoided (and not currently needed in Duktape 1.4.0).
comment: Add a header snippet for checking consistency of DUK_USE_xxx config
options, e.g. inconsistent options, invalid option values.
label: code-design
Helpers for duk_config.h generation
must be #define'd
may be #undef'd, as long as provided
may be #undef'd, as long as provided
may be #undef'd, as long as provided
Snippet may have further unresolved provides; add recursively
For some options like DUK_OPT_PACKED_TVAL the default comes
from platform definition.
comment: XXX: assume no newlines etc
label: code-design
Date provider snippet is after custom header and overrides, so that
the user may define e.g. DUK_USE_DATE_NOW_GETTIMEOFDAY in their
custom header.
comment: !/usr/bin/env python2
Process Duktape option metadata and produce various useful outputs:
- duk_config.h with specific or autodetected platform, compiler, and
architecture; forced options; sanity checks; etc
- option documentation for Duktape 1.x feature options (DUK_OPT_xxx)
- option documentation for Duktape 1.x/2.x config options (DUK_USE_xxx)
Genconfig tries to build all outputs based on modular metadata, so that
managing a large number of config options (which is hard to avoid given
the wide range of targets Duktape supports) remains maintainable.
Genconfig does *not* try to support all exotic platforms out there.
Instead, the goal is to allow the metadata to be extended, or to provide
a reasonable starting point for manual duk_config.h tweaking.
For Duktape 1.3 release the main goal was to autogenerate a Duktape 1.2
compatible "autodetect" header from legacy snippets, with other outputs
being experimental. For Duktape 1.4 duk_config.h is always created from
modular sources.
label: code-design
comment: Not exact but close enough. Doesn't handle string literals etc,
but these are not a concrete issue for scanning preprocessor
#define references.
Comment contents are stripped of any DUK_ prefixed text to avoid
incorrect requires/provides detection. Other comment text is kept;
in particular a "/* redefine */" comment must remain intact here.
(The 'redefine' hack is not actively needed now.)
Avoid Python 2.6 vs. Python 2.7 argument differences.
label: code-design
If manually-edited snippets don't #define or #undef a certain
config option, emit a default value here. This is useful to
fill-in for new config options not covered by manual snippets
(which is intentional).
position where to emit DUK_F_xxx dependencies
comment: XXX: platform/compiler could provide types; if so, need some signaling
defines like DUK_F_TYPEDEFS_DEFINED
label: code-design
comment: Compilers need a lot of defines; missing defines are automatically
filled in with defaults (which are mostly compiler independent), so
the requires define list is not very large.
label: code-design
comment: C preprocessor '#warning' is often supported
label: code-design
print('Resolving %r' % k)
Miscellaneous helpers
If a related feature option exists, it can be used to force
enable/disable the target feature. If neither feature option
(DUK_OPT_xxx or DUK_OPT_NO_xxx) is given, revert to default.
print('Deleting temporary directory: %r' % dirname)
at least one other node provides 'k'
Preferred tag order for generated C header files.
comment: XXX: better plumbing for lookup path
label: code-design
Add automatic DUK_OPT_XXX and DUK_OPT_NO_XXX handling for backwards
compatibility with Duktape 1.2 and before.
DUK_SETJMP, DUK_LONGJMP, DUK_JMPBUF_TYPE are optional, fill-in
provides if none defined.
for trailing newline
Forced options, last occurrence wins (allows a base config file to be
overridden by a more specific one).
DUK_F_xxx snippets
emit tag heading only if there are subsections
comment: XXX: placeholder, need to decide on markup conventions for YAML files
label: code-design
Number types
print('REQUIRES: %r' % m)
comment: XXX: better to lookup platforms metadata
label: code-design
verbatim value
comment: uppercase only, don't match DUK_USE_xxx for example
label: code-design
comment: XXX: assume no newlines etc
XXX: support compiler specific warning mechanisms
label: code-design
print('Effective tag order: %r' % tags)
comment: Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
print('PROVIDES: %r' % m.group(1))
label: code-design
DUK_F_UCLIBC is special because __UCLIBC__ is provided by an #include
file, so the check must happen after platform includes. It'd be nice
for this to be automatic (e.g. DUK_F_UCLIBC.h.in could indicate the
dependency somehow).
Emit forced options. If a corresponding option is already defined
by a snippet above, #undef it first.
DLL build affects visibility attributes on Windows but unfortunately
cannot be detected automatically from preprocessor defines or such.
DLL build status is hidden behind DUK_F_DLL_BUILD and there are two
ways for that to be set:
- Duktape 1.3 backwards compatible DUK_OPT_DLL_BUILD
- Genconfig --dll option
Preferred tag order for option documentation.
XXX: check that YAML parses
Pretty print a debugger command.
Duktape internal class numbers, must match C headers
Write a string into a buffer interpreting codepoints U+0000...U+00FF
* as bytes. Drop higher bits.
comment: XXX: add constants inline to preformatted output (e.g. for strings,
add a short escaped snippet as a comment on the line after the
compact argument list).
label: code-design
absFn -> true
Errors
true
We shouldn't come here, but if we do, JSON is a reasonable default.
Could emit a 'debug-value' event here, but that's not necessary
because the receiver will just collect statistics which can also
be done using the finished message.
comment: XXX: move this to the web UI so that the UI can control what
locals are listed (or perhaps show locals for all levels with
an expandable tree view).
label: code-design
There is no close() or destroy() for a passthrough stream, so just
close the outputParser which will cancel timers etc.
Raw bytes
Unicode string
Still waiting for version identification to complete.
comment: Pending flags are used to avoid requesting the same thing twice
while a previous request is pending. The flag-based approach is
quite awkward. Rework to use promises.
label: code-design
2-byte string
undefined
* JSON debug proxy
msg.varname is a proper Unicode strings here, and needs to be
converted into a protocol string (U+0000...U+00FF).
new object, old may be in circulation for a while
list of command names, merged client/target
XXX: normalize last newline (i.e. force a newline if contents don't
end with a newline)?
accumulate data
accumulated message until EOM
A PutVar call quite possibly changes the local variables so always
re-read locals afterwards. We don't need to wait for PutVar to
complete here; the requests will pipeline automatically and be
executed in order.
2-byte buffer
'./foo/bar.js' -> 'foo/bar.js'
whole
Commands initiated by Duktape
Not all streams will emit this.
Pretty print a dvalue. Useful for dumping etc.
Could also check for an empty request queue, but that's probably
too strict?
Technically we should wait for each delbreak reply but because
target processes the requests in order, it doesn't matter.
Protocol version handling. When dumping an output stream, the
caller gives a non-null protocolVersion so we don't read one here.
comment: Check if 'msg' would encode to the same JSON which was previously sent
to the web client. The caller then avoid resending unnecessary stuff.
label: code-design
Up-to-date list of breakpoints on target
comment: XXX: do pretty printing in debug client for now
label: code-design
console.log(JSON.stringify(msg));
Duktape heaphdr type constants, must match C headers
* Debugger implementation
*
* A debugger instance communicates with the debug target and maintains
* persistent debug state so that the current state can be resent to the
* socket.io client (web UI) if it reconnects. Whenever the debugger state
* is changed an event is generated. The socket.io handler will listen to
* state change events and push the necessary updates to the web UI, often
* in a rate limited fashion or using a client pull to ensure the web UI
* is not overloaded.
*
* The debugger instance assumes that if the debug protocol connection is
* re-established, it is always to the same target. There is no separate
* abstraction for a debugger session.
error
Decode and normalize source file contents: UTF-8, tabs to 8,
* CR LF to LF.
comment: unused/none
label: code-design
* Command line parsing and initialization
"notify" can be a string or "true"
Shouldn't come here.
4-byte signed integer
For the unquoted version we don't need to escape single or double
quotes.
unsigned
msg.input is a proper Unicode strings here, and needs to be
converted into a protocol string (U+0000...U+00FF).
nop: no callback
https://github.com/ryanmcgrath/wrench-js
varvalue is JSON parsed by the web UI for now, need special string
encoding here.
Command line options (defaults here, overwritten if necessary)
truncate higher bits
No actual requests sent by the target right now (just notifys).
Encode an ordinary Unicode string into a dvalue compatible format, i.e.
* into a byte array represented as codepoints U+0000...U+00FF. Concretely,
* encode with UTF-8 and then represent the bytes with U+0000...U+00FF.
console.log('Received json proxy input line: ' + line.toString('utf8'));
* Miscellaneous helpers
indicate 'v' is actually set
Dump effective options. Also provides a list of option names.
Although the underlying transport may not have a close() or destroy()
method or even a 'close' event, this method is always available and
will generate a 'transport-close'.
The caller is responsible for closing the underlying stream if that
is necessary.
A byline-parser is simple and good enough for now (assume
compact JSON with no newlines).
override
update run state now that we're paused
duk_tval number, any IEEE double
decode into hex
big endian ieee double
just trigger a sync, gets rate limited
comment: Convert a buffer into a string using Unicode codepoints U+0000...U+00FF.
* This is the NodeJS 'binary' encoding, but since it's being deprecated,
* reimplement it here. We need to avoid parsing strings as e.g. UTF-8:
* although Duktape strings are usually UTF-8/CESU-8 that's not always the
* case, e.g. for internal strings. Buffer values are also represented as
* strings in the debug protocol, so we must deal accurately with arbitrary
* byte arrays.
label: code-design
Marker objects for special protocol values
Fetch basic info right away
comment: Pretty print a dvalue for UI usage. Everything comes out as a ready-to-use
* string.
*
* XXX: Currently the debug client formats all values for UI use. A better
* solution would be to pass values in typed form and let the UI format them,
* so that styling etc. could take typing into account.
label: code-design
An eval call quite possibly changes the local variables so always
re-read locals afterwards. We don't need to wait for Eval to
complete here; the requests will pipeline automatically and be
executed in order.
Commands initiated by the debug client (= us)
res.status(200).json(val);
raw identification string
Create debugger and web UI singletons, tie them together and
start them.
* Debug protocol parser
*
* The debug protocol parser is an EventEmitter which parses debug messages
* from an input stream and emits 'debug-message' events for completed
* messages ending in an EOM. The parser also provides debug dumping, stream
* logging functionality, and statistics gathering functionality.
*
* This parser is used to parse both incoming and outgoing messages. For
* outgoing messages the only function is to validate and debug dump the
* messages we're about to send. The downside of dumping at this low level
* is that we can't match request and reply/error messages here.
*
* http://www.sitepoint.com/nodejs-events-and-eventemitter/
Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
* for UI usage without quotes.
Loose matching is tempting but counterproductive: filenames must
match 1:1 between the debug client and the debug target for e.g.
breakpoints to work as expected. Note that a breakpoint may be
assigned by selecting a file from a dropdown populated by scanning
the filesystem for available sources and there's no way of knowing
if the debug target uses the exact same name.
web UI singleton
transport connection to target
dummy passthrough for message dumping
parser for incoming debug messages
parser for outgoing debug messages (stats, dumping)
comment: XXX: make the client do this?
label: code-design
// This fails with "RangeError: Maximum call stack size exceeded" for some
// reason, so use a much slower variant.
for (i = 0, n = buf.length; i < n; i++) {
cp[i] = buf[i];
}
return String.fromCharCode.apply(String, cp);
We require a destroy() method from the actual target stream
Debug protocol integer
shift forces unsigned
Send a status request to trigger a status notify, result is ignored:
target sends a status notify instead of a meaningful reply
See doc/debugger.rst for format description.
Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
* for UI usage. Try UTF-8 decoding to get a nice Unicode string (JSON
* encoded) but if that fails, ensure that bytes are encoded transparently.
* The result is a quoted string with a special quote marker for a "raw"
* string when UTF-8 decoding fails. Very long strings are optionally
* clipped.
console.dir(argv);
Intentional invalid command
When we fall back to representing bytes, indicate that the string
is "raw" with a 'r"' prefix (a somewhat arbitrary convention).
U+0022 = ", U+0027 = '
number (IEEE double), big endian
We want the fileMap to contain the filename relative to
the search dir root.
Initial debugger connection
Represented signed 32-bit integers as plain integers.
Debugger code expects this for all fields that are not
duk_tval representations (e.g. command numbers and such).
Right now bytecode is a string containing a direct dump of the
bytecode in target endianness. Decode here so that the web UI
doesn't need to.
comment: The value key should not be used programmatically,
it is just there to make the dumps more readable.
label: code-design
msg.varname and msg.varvalue are proper Unicode strings here, they
need to be converted into protocol strings (U+0000...U+00FF).
Note: typeof null === 'object', so null special case explicitly
Parse complete dvalues (quite inefficient now) by trial parsing.
Consume a value only when it's fully present in 'buf'.
See doc/debugger.rst for format description.
0x80...0xbf: integers 0-63
pointer
* Source file manager
*
* Scan the list of search directories for Ecmascript source files and
* build an index of them. Provides a mechanism to find a source file
* based on a raw 'fileName' property provided by the debug target, and
* to provide a file list for the web UI.
*
* NOTE: it's tempting to do loose matching for filenames, but this does
* not work in practice. Filenames must match 1:1 with the debug target
* so that e.g. breakpoints assigned based on filenames found from the
* search paths will match 1:1 on the debug target. If this is not the
* case, breakpoints won't work as expected.
not cached, send (cache already updated)
CUSTOMTRANSPORT: to use a custom transport, change this.targetStream to
use your custom transport.
Resend all debugger state for new client
clear client state cache
Parse arguments.
not negative zero
stats and dumping
map from (merged) command name to number
stats for current debug connection
"request" can be a string or "true"
Use a PassThrough stream to debug dump and get stats for output messages.
Simply write outgoing data to both the targetStream and this passthrough
separately.
object
* Debugger output formatting
Read final, effective breakpoints from the target
cached
null
comment: XXX: unprintable characters etc? In some UI cases we'd want to
e.g. escape newlines and in others not.
label: code-design
4-byte string
String map for commands (debug dumping). A single map works (instead of
separate maps for each direction) because command numbers don't currently
overlap. So merge the YAML metadata.
nop
lightfunc
false
stream is closed/broken, don't parse anymore
trailing '"' intentionally missing
heapptr
Explicit rate limiter because this is a source of a lot of traffic.
* Minimal debug web console for Duktape command line tool
*
* See debugger/README.rst.
*
* The web UI socket.io communication can easily become a bottleneck and
* it's important to ensure that the web UI remains responsive. Basic rate
* limiting mechanisms (token buckets, suppressing identical messages, etc)
* are used here now. Ideally the web UI would pull data on its own terms
* which would provide natural rate limiting.
*
* Promises are used to structure callback chains.
*
* https://github.com/petkaantonov/bluebird
* https://github.com/petkaantonov/bluebird/blob/master/API.md
* https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns
Pretty print a debugger message given as an array of parsed dvalues.
* Result should be a pure ASCII one-liner.
Constants
Not possible in practice.
* Express setup and socket.io
Represent non-integers as IEEE double dvalues
UTF-8
comment: console logging is done at a higher level to match request/response
label: code-design
Ignore unknown notify messages
console.log(msg);
0x60...0x7f: strings with length 0-31
Delete matching breakpoints in reverse order so that indices
remain valid. We do this for all operations so that duplicates
are eliminated if present.
0xc0...0xff: integers 0-16383
close previous target connection
4-byte buffer
inform web UI
XXX: signal success to UI?
Bytecode opcode/extraop metadata
Token bucket rate limiter for a given callback. Calling code calls
* trigger() to request 'cb' to be called, and the rate limiter ensures
* that 'cb' is not called too often.
Poll various state items when running
pc is preincremented before adding
cache to avoid resending identical data
Here utf8.decode() is better than decoding using NodeJS buffer
operations because we want strict UTF-8 interpretation.
Right now the implementation is setInterval-based, but could also be
made timerless. There are so few rate limited resources that this
doesn't matter in practice.
Value could be a Node.js buffer directly, but
we prefer all dvalues to be JSON compatible
this.targetStream.destroy();
nop
Don't add a 'value' key to numbers.
preformatted dvalues
used to flag special values like undefined
comment: Pretty print a number for UI usage. Types and values should be easy to
* read and typing should be obvious. For numbers, support Infinity, NaN,
* and signed zeroes properly.
label: code-design
no bias in LDINTX
debugger singleton
current socket (or null)
Try to detach cleanly, timeout if no response
4-byte signed integer
heapptr
plain buffer
* Target binary connection handler
number (IEEE double), big endian
Encode arguments into dvalues.
comment: XXX: write a notify to target?
label: code-design
disconnect JSON client too (if not already disconnected)
* JSON proxy server
*
* Accepts an incoming JSON proxy client and connects to a debug target,
* tying the two connections together. Supports both a single connection
* and a persistent mode.
true
truncate higher bits
* JSON connection handler
Represented signed 32-bit integers as plain integers.
Debugger code expects this for all fields that are not
duk_tval representations (e.g. command numbers and such).
Not possible in practice.
* Main
indicate 'v' is actually set
comment: The value key should not be used programmatically,
it is just there to make the dumps more readable.
label: code-design
2-byte string
Once we're connected to the target, start read both binary and JSON
input. We don't want to read JSON input before this so that we can
always translate incoming messages to dvalues and write them out
without queueing. Any pending JSON messages will be queued by the
OS instead.
Generic handshake format: only relies on initial version field.
undefined
0x80...0xbf: integers 0-63
pointer
0x60...0x7f: strings with length 0-31
Represent non-integers as IEEE double dvalues.
0xc0...0xff: integers 0-16383
Trial parse dvalue(s) and debug messages.
default logger
log.l = 0; // enable debug and trace logging
4-byte buffer
comment: for manual testing of binary/json parsing robustness
label: code-design
2-byte buffer
Parse message type, determine initial marker for binary message.
Note that typeof null === 'object'.
* Config
* Misc helpers
comment:
* JSON debug proxy written in DukLuv
*
* This single file JSON debug proxy implementation is an alternative to the
* Node.js-based proxy in duk_debug.js. DukLuv is a much smaller dependency
* than Node.js so embedding DukLuv in a debug client is easier.
label: code-design
Feed the data one byte at a time when torture testing.
When this is invoked the proxy connection and the target connection
have both been closed.
Add an EOM, and write out the dvalues to the debug target.
* Detect missing 'var' declarations
whole
not negative zero
Receive data into 'incoming', resizing as necessary.
explicit flag for e.g. v === undefined
disconnect target too (if not already disconnected)
comment: XXX: it'd be nice to log remote peer host:port
label: code-design
make a copy, ensuring there's no slice offset
get underlying plain buffer
Trial parse JSON message(s).
This is still pretty awkward in Duktape 1.4.x.
Argument may be a "slice" and we want a copy of the slice
(not the full underlying buffer).
comment: XXX: Code assumes uv.write() will write fully. This is not necessarily
true; should add support for partial writes (or at least failing when
a partial write occurs).
label: code-design
Prevent new bindings on global object. This detects missing 'var'
declarations, e.g. "x = 123;" in a function without declaring it.
object
lightfunc
skip dukluv and script name
null
More detailed v1 handshake line.
comment: unnecessary but just in case
label: code-design
4-byte string
comment: unused/none
label: code-design
don't register any sockets/timers etc to exit
comment: In lenient mode if JSON parse fails just send back an _Error
and ignore the line (useful for initial development).
In non-lenient mode drop the connection here; if the failed line
was a request the client is expecting a reply/error message back
(otherwise it may go out of sync) but we can't send a synthetic
one (as we can't parse the request).
label: code-design
Trial parse handshake unless done.
false
!/usr/bin/env python2
Merge debugger YAML metadata files and output a merged JSON metadata file.
#exec-status
#center-area
#part-middle
#part-footer
<span id="source-filename">?</span>
No source loaded
#about-dialog
#part-header
#left-area
#right-area
comment: XXX: how to minimize the chance we'll further communciate with the
server or reconnect to it? socket.reconnection()?
label: code-design
comment: XXX: prevent retry of no-such-file by negative caching?
label: code-design
Eval may take seconds to complete so indicate it is pending.
Bytecode dialog highlight
If previous update is pending, abort and start a new one.
http://diveintohtml5.info/storage.html
Note: loadedFileName can be either from target or from server, but they
must match exactly. We could do a loose match here, but exact matches
are needed for proper breakpoint handling anyway.
Remove eval button "pulsating" glow when we get a result
may be null
Remove pending highlight once we're no longer running.
Update the "console" output based on lines sent by the server. The server
rate limits these updates to keep the browser load under control. Even
better would be for the client to pull this (and other stuff) on its own.
* Duktape debugger web client
*
* Talks to the NodeJS server using socket.io.
*
* http://unixpapa.com/js/key.html
If we just became paused, check for eval watch
Make copies of the requested file/line so that we have the proper
values in case they've changed.
* UI update handling when exec-status update arrives
Active breakpoints follow
Exact match is required.
comment: XXX: any faster way; elems doesn't have e.g. indexOf()
label: code-design
comment: XXX: ignore issue with last empty line for now
label: code-design
returns a Manager
Update interval for custom source highlighting.
Duktape now restricts execution status updates quite effectively so
there's no need to rate limit UI updates now.
comment: XXX: hacky transition, make source change visible
label: code-design
puff
slide, puff
onclick handler for exec status text
Source is updated periodically. Other code can also call doSourceUpdate()
directly if an immediate update is needed.
* AJAX request handling to fetch source files
comment: XXX: error transition here
label: requirement
If we're executing the file shown, highlight current line
comment: Scroll to requested line. This is not very clean, so a better solution
should be found:
https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView
http://erraticdev.blogspot.fi/2011/02/jquery-scroll-into-view-plugin-with.html
http://flesler.blogspot.fi/2007/10/jqueryscrollto.html
label: code-design
Make source window grey when running for a longer time, use a small
delay to avoid flashing grey when stepping.
comment: Source view
file that we want to be loaded in source view
scroll to line once file has been loaded
line that we want to highlight (if any)
currently loaded (shown) file
currently loaded file line count
true if currFileName (loosely) matches loadedFileName
if set, scroll loaded file to requested line
highlight line
line numbers which have been modified
(added classes etc, tracked for removing)
timer for updating source view
current AJAX request for fetching a source file (if any)
hack to reset button states
bytecode dialog active
index of currently highlighted line (or null)
index to first line of bytecode instructions
label: code-design
Remove previously added custom classes
Not really interesting in the UI
$('#server-info').text(new Date() + ': ' + JSON.stringify(msg));
Not 100% reliable if callstack has several functions of the same name
If no-one requested us to scroll to a specific line, finish.
Update buttons
http://stackoverflow.com/questions/14918787/jquery-scroll-to-bottom-of-div-even-after-it-updates
Stop queued animations so that we always scroll quickly to bottom
First line is special
AJAX request for the source.
* Initialization
About dialog, shown automatically on first startup.
Enter handling for eval input
https://forum.jquery.com/topic/bind-html-input-to-enter-key-keypress
Eval watch handling
We'd like to window.close() here but can't (not allowed from scripts).
Alert is the next best thing.
float
Bytecode dialog
Force source view to match currFileName only when running or when
just became paused (from running or detached).
nop
Force line update (scrollTop) only when running or just became paused.
Otherwise let user browse and scroll source files freely.
Not worth alerting about because source fetch errors happen
all the time, e.g. for dynamically evaluated code.
Execution state
previous execution state ('paused', 'running', etc)
previous debugger attached state (true, false, null)
current filename being executed
current function name being executed
current line being executed
current bytecode PC being executed
current execution state ('paused', 'running', 'detached', etc)
current debugger attached state (true or false)
current local variables
current callstack (from top to bottom)
current breakpoints
timestamp when last started running (if running)
(used to grey out the source file if running for long enough)
* Source view periodic update handling
If we just started running, store a timestamp so we can grey out the
source view only if we execute long enough (i.e. we're not just
stepping).
comment: The variable value is parsed as JSON right now, but it'd be better to
also be able to parse buffer values etc.
label: code-design
* Init socket.io and add handlers
don't clear eval input
* AJAX request for fetching the source list
This is worth alerting about as the UI is somewhat unusable
if we don't get a source list.
Update current execution state
Add breakpoints
* Helpers
Pause may take seconds to complete so indicate it is pending.
This must fit into the smallest pool entry.
Define to enable some debug printfs.
Use 'st' as udata.
comment: #define DUK_ALLOC_HYBRID_DEBUG
label: code-design
comment:
* Example memory allocator with pool allocation for small sizes and
* fallback into malloc/realloc/free for larger sizes or when the pools
* are exhausted.
*
* Useful to reduce memory churn or work around a platform allocator
* that doesn't handle a lot of small allocations efficiently.
label: code-design
Still fits, no shrink support.
'ptr' cannot be NULL.
DUK_ALLOC_HYBRID_H_INCLUDED
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
comment:
* Example memory allocator with machine parseable logging.
*
* Also sizes for reallocs and frees are logged so that the memory
* behavior can be essentially replayed to accurately determine e.g.
* optimal pool sizes for a pooled allocator.
*
* Allocation structure:
*
* [ alloc_hdr | user area ]
*
* ^ ^
* | `--- pointer returned to Duktape
* `--- underlying malloc ptr
label: code-design
Suppress warning.
comment: DUK_ALLOC_LOGGING_H_INCLUDED
label: code-design
Note: ajduk doesn't log oldsize (uses -1 instead)
comment: !/usr/bin/env python2
Analyze allocator logs and write total-bytes-in-use after every
operation to stdout. The output can be gnuplotted as:
$ python log2gnuplot.py </tmp/duk-alloc-log.txt >/tmp/output.txt
$ gnuplot
> plot "output.txt" with lines
label: code-design
A ptr/NULL/FAIL size
F ptr/NULL size
R ptr/NULL oldsize ptr/NULL/FAIL newsize
comment:
* Example torture memory allocator with memory wiping and check for
* out-of-bounds writes.
*
* Allocation structure:
*
* [ alloc_hdr | red zone before | user area | red zone after ]
*
* ^ ^
* | `--- pointer returned to Duktape
* `--- underlying malloc ptr
label: code-design
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
Suppress warning.
Force address change on every realloc.
DUK_ALLOC_TORTURE_H_INCLUDED
* Enter interactive mode if options indicate it
[ ... bytecode_filename src_data src_len filename ]
* Main
Example of sending an application specific debugger notification.
'p' points to a NUL (p == p_end) or a period.
avoid SIGPIPE killing process
Full completion, add a period, e.g. input 'Math' -> 'Math.'.
Here we know the eval arg exists but check anyway
DUK_CMDLINE_RLIMIT
* Misc helpers
A virtual '/tmp' exists by default:
* https://gist.github.com/evanw/e6be28094f34451bd5bd#file-temp-js-L3806-L3809
DUK_CMDLINE_LINENOISE_COMPLETION
Callback should avoid errors for now, so use
* duk_check_stack() rather than duk_require_stack().
Manual test for bytecode dump/load cycle: dump and load before
* execution. Enable manually, then run "make qecmatest" for a
* reasonably good coverage of different functions and programs.
try {
FS.unmount("/");
} catch (e) {
console.log("Failed to unmount default '/' MEMFS mount: " + e);
}
original, including partial last component
Ensure socket is closed even when detach is initiated by Duktape
* rather than debug client.
* Minimal Linenoise completion support
caller coerces
[ ... bytecode_filename src_data src_len function ]
Optional bytecode dump.
Print error objects with a stack trace specially.
* Note that getting the stack trace may throw an error
* so this also needs to be safe call wrapped.
* Duktape heap lifecycle
Manual test for duk_debugger_cooperate()
'idx_obj' points to the object matching the last
* full component, use [p_curr,p[ as a filter for
* that object.
Running stdin like a full file (reading all lines before
* compiling) is useful with emduk:
* cat test.js | ./emduk --run-stdin
should never happen, but just in case
Catches e.g. 'foo..bar' -> we want 'bar' only.
Print error to stderr and pop error.
* Signal handling setup
~2 GB
comment:
* Cleanup and exit
label: code-design
Partial ends in a period, e.g. 'Math.' -> complete all Math properties.
fatal_handler
comment: Very simplified "is identifier part" check.
label: code-design
Read until EOF, avoid fseek/stat because it won't work with stdin.
global
Defined in duk_cmdline_ajduk.c or alljoyn.js headers.
comment: This is not necessary but should be harmless.
label: code-design
'p' will either be p_start - 1 (ran out of buffer) or point to
* the first offending character.
nrets
comment: XXX: Here it'd be nice to get some stats for the compilation result
* when a suitable command line is given (e.g. code size, constant
* count, function count. These are available internally but not through
* the public API.
label: code-design
In non-interactive mode, success results are not written at all.
* It is important that the result value is not string coerced,
* as the string coercion may cause an error in some cases.
* In interactive mode, write to stdout so output won't
* interleave as easily.
*
* NOTE: the ToString() coercion may fail in some cases;
* for instance, if you evaluate:
*
* ( {valueOf: function() {return {}},
* toString: function() {return {}}});
*
* The error is:
*
* TypeError: failed to coerce with [[DefaultValue]]
* duk_api.c:1420
*
* These are handled now by the caller which also has stack
* trace printing support. User code can print out errors
* safely using duk_safe_to_string().
DUK_CMDLINE_FILEIO
comment: +25% and some extra
label: code-design
* Command line execution tool. Useful for test cases and manual testing.
*
* To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
* It is not the default to maximize portability. You can also compile in
* support for example allocators, grep for DUK_CMDLINE_*.
get_value
nret
for properties of plain strings etc
Not an Error instance, don't read "stack".
'this' binding
Source code.
comment: XXX: handle partial writes
label: code-design
DUK_CMDLINE_SIGNAL
comment: Emscripten specific: stdin EOF doesn't work as expected.
* Instead, when 'emduk' is executed using Node.js, a file
* piped to stdin repeats (!). Detect that repeat and cut off
* the stdin read. Ensure the loop repeats enough times to
* avoid detecting spurious loops.
*
* This only seems to work for inputs up to 256 bytes long.
label: code-design
skip code
* Simple file read/write bindings
* Usage
comment: XXX: There's no key quoting now, it would require replacing the
* last component with a ['foo\nbar'] style lookup when appropriate.
label: code-design
'p' now points to a string of the form 'foo.bar.quux'. Look up
* all the components except the last; treat the last component as
* a partial name which is used as a filter for the previous full
* component. All lookups are from the global object now.
p_curr == p_end allowed on purpose, to handle 'Math.' for example.
For automatic reattach testing.
Not found.
Use duk_compile_lstring_filename() variant which avoids interning
* the source code. This only really matters for low memory environments.
heap_udata: ignored by AjsHeap, use as marker
* Memory limit
fall thru
original, e.g. 'Math.'
DUK_CMDLINE_LINENOISE
* Execute from file handle etc
* Create heap
completion to last component
128 MB
signal(SIGPIPE, SIG_IGN);
EMSCRIPTEN
Bytecode.
in interactive mode, write to stdout
Try to use NODEFS to provide access to local files. Mount the
* CWD as /working, and then prepend "/working/" to relative native
* paths in file calls to get something that works reasonably for
* relative paths. Emscripten doesn't support replacing virtual
* "/" with host "/" (the default MEMFS at "/" can't be unmounted)
* but we can mount "/tmp" as host "/tmp" to allow testcase runs.
*
* https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html#filesystem-api-nodefs
* https://github.com/kripken/emscripten/blob/master/tests/fs/test_nodefs_rw.c
comment: Suppress warnings about plain fopen() etc.
label: code-design
suppress warning
try {
FS.mkdir("/tmp");
} catch (e) {
console.log("Failed to create virtual /tmp: " + e);
}
Should never happen, just in case.
* Execute any argument file(s)
comment: duk_safe_call() cleans up
label: code-design
* Parse options
an error 'taints' the execution
At the moment it's not possible to replace the default MEMFS mounted at '/':
* https://github.com/kripken/emscripten/issues/2040
* https://github.com/kripken/emscripten/blob/incoming/src/library_fs.js#L1341-L1358
comment: This is useful at the global level; libraries should avoid SIGPIPE though
label: code-design
nargs
Helper define to enable a feature set; can also use separate defines.
Last component is partial, complete.
comment: Workaround for snprintf() missing in older MSVC versions.
* Note that _snprintf() may not NUL terminate the string, but
* this difference does not matter here as a NUL terminator is
* always explicitly added.
label: code-design
Ignore array index keys: usually not desirable, and would
* also require ['0'] quoting.
Scan backwards for a maximal string which looks like a property
* chain (e.g. foo.bar.quux).
skip filename
comment:
* Heap initialization when using AllJoyn.js pool allocator (without any
* other AllJoyn.js integration). This serves as an example of how to
* integrate Duktape with a pool allocator and is useful for low memory
* testing.
*
* The pool sizes are not optimized here. The sizes are chosen so that
* you can look at the high water mark (hwm) and use counts (use) and see
* how much allocations are needed for each pool size. To optimize pool
* sizes more accurately, you can use --alloc-logging and inspect the memory
* allocation log which provides exact byte counts etc.
*
* https://git.allseenalliance.org/cgit/core/alljoyn-js.git
* https://git.allseenalliance.org/cgit/core/alljoyn-js.git/tree/ajs.c
label: code-design
This extern declaration is provided by duktape.h, array provided by duktape.c.
heapConfig
Enable heap dumps
duk_heap, with heap ptr compression, ROM strings+objects
...
Scan ROM pointer range for faster detection of "is 'p' a ROM pointer"
* later on.
heapSz
comment: not needed
label: requirement
numPools
comment:
* Simplified example of an external strings strategy where incoming strings
* are written sequentially into a fixed, memory mapped flash area.
*
* The example first scans if the string is already in the flash (which may
* happen if the same string is interned multiple times), then adds it to
* flash if there is space.
*
* This example is too slow to be used in a real world application: there
* should be e.g. a hash table to quickly check for strings that are already
* present in the string data (similarly to how string interning works in
* Duktape itself).
label: code-design
* Not present yet, check if we have space. Again, be careful to
* ensure there is space for a NUL following the input data.
Linear scan. An actual implementation would need some acceleration
* structure, e.g. select a sublist based on first character.
*
* NOTE: input string (behind 'ptr' with 'len' bytes) DOES NOT have a
* trailing NUL character. Any strings returned from this function
* MUST have a trailing NUL character.
* 'ajduk' specific functionality, examples for low memory techniques
Pointer compression with ROM strings/objects:
*
* For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM
* pointers. DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer
* compression range minimum to avoid duplication in user code.
to avoid empty source file
Ensure that we always get the heap_udata given in heap creation.
* (Useful for Duktape development, not needed for user programs.)
AjsHeap.dump(), allows Ecmascript code to dump heap status at suitable
* points.
heapNum
protected call not yet running
comment: The if-condition should be the fastest possible check
* for "is 'p' in ROM?". If pointer is in ROM, we'd like
* to compress it quickly. Here we just scan a ~1K array
* which is very bad for performance and for illustration
* only.
label: code-design
Ensure that we always get the heap_udata given in heap creation.
heap
* These strings are from util/duk_meta_to_strarray.py
comment:
* Check if we already have the string. Be careful to compare for
* NUL terminator too, it is NOT present in 'ptr'. This algorithm
* is too simplistic and way too slow for actual use.
label: code-design
duk_heap, with heap ptr compression, RAM strings+objects
This is a blind lookup, could check index validity.
* Duktape should never decompress a pointer which would
* be out-of-bounds here.
comment:
* External strings strategy intended for valgrind testing: external strings
* are allocated using malloc()/free() so that valgrind can be used to ensure
* that strings are e.g. freed exactly once.
label: code-design
* These strings are manually added, and would be gathered in some
* application specific manner.
comment: It's not worth it to make very small strings external, as
* they would take the same space anyway. Also avoids zero
* length degenerate case.
label: code-design
comment: Somewhat portable way of losing a const without warnings.
* Another approach is to cast through intptr_t, but that
* type is not always available.
label: code-design
* Example pointer compression functions.
*
* 'base' is chosen so that no non-NULL pointer results in a zero result
* which is reserved for NULL pointers.
* There is space, add the string to our collection, being careful
* to append the NUL.
DUK_CMDLINE_AJSHEAP
comment:
* Wrapped ajs_heap.c alloc functions
*
* Used to write an alloc log.
label: code-design
until_nul
We should really never be here: Duktape should only be
* compressing pointers which are in the ROM compressed
* pointers list, which are known at 'make dist' time.
* We go on, causing a pointer compression error.
* Simplified example of an external strings strategy where a set of strings
* is gathered during application compile time and baked into the application
* binary.
*
* Duktape built-in strings are available from duk_build_meta.json, see
* util/duk_meta_to_strarray.py. There may also be a lot of application
* specific strings, e.g. those used by application specific APIs. These
* must be gathered through some other means, see e.g. util/scan_strings.py.
* Execution timeout example
See userdata discussion in ajsheap_enc16().
duk_hthread, with heap ptr compression, ROM strings+objects
comment: potentially unused
label: code-design
comment: Userdata is not needed in this case but would be useful if heap
* pointer compression were used for multiple heaps. The userdata
* allows the callback to distinguish between heaps and their base
* pointers.
*
* If not needed, the userdata can be left out during compilation
* by simply ignoring the userdata argument of the pointer encode
* and decode macros. It is kept here so that any bugs in actually
* providing the value inside Duktape are revealed during compilation.
label: code-design
numHeaps
* Helpers
seconds
* Convert an 8-bit input string (e.g. ISO-8859-1) into CESU-8.
* Calling code supplies the "code page" as a 256-entry array of
* codepoints for the conversion.
*
* This is useful when input data is in non-UTF-8 format and must
* be converted at runtime, e.g. when compiling non-UTF-8 source
* code. Another alternative is to use e.g. iconv.
Temporary buffer length wraps.
max expansion is 1 input byte -> 3 output bytes
Decode an 8-bit string using 'codepage' into Unicode codepoints and
* re-encode into CESU-8. Codepage argument must point to a 256-entry
* table. Only supports BMP (codepoints U+0000 to U+FFFF).
[ ... tmp res ]
In CESU-8 all codepoints in [0x0000,0xFFFF] are
* allowed, including surrogates.
DUK_CODEPAGE_CONV_H_INCLUDED
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
Example: compile and run test source encoded in Windows codepage 1252.
undefined
Exercise all 3 byte lengths: any ASCII character is 1 byte, 0xFC maps to
* U+00FC which is 2 bytes, and 0x80 maps to U+20AC which is 3 bytes.
* Same as above, but if the exception inherits from std::exception, it's
* "what()" will be included in the error message.
* If you let your own C++ exceptions propagate out of a Duktape/C function
* it will be caught by Duktape and considered a programming error. Duktape
* will catch the exception and convert it to a Duktape error.
*
* This may be allowed in a later version once all the implications have been
* worked out.
ERROR: exception propagated to Duktape
* Example class with a destructor
suppress warning
* Example of how to use DUK_USE_CPP_EXCEPTIONS to support automatic
* variables (e.g. destructor calls) in Duktape/C functions.
*
* Compile with -DDUK_OPT_CPP_EXCEPTIONS:
*
* $ g++ -otest -DDUK_OPT_CPP_EXCEPTIONS -I<duktape_dist>/src/ \
* <duktape_dist>/src/duktape.c cpp_exceptions.cpp -lm
*
* or ensure duk_config.h has DUK_USE_CPP_EXCEPTIONS enabled using
* genconfig. When executed you should see something like:
*
* $ ./test
* my_class instance created
* my_class instance destroyed <== destructor gets called
* --> rc=1 (SyntaxError: parse error (line 1))
* [...]
*
* Duktape uses a custom exception class (duk_internal_exception) which
* doesn't inherit from any base class, so that catching any base classes
* in user code won't accidentally catch exceptions thrown by Duktape.
* You can use C++ exceptions inside Duktape/C functions for your own
* purposes but you should catch them before they propagate to Duktape.
* SyntaxError caused by eval exits Duktape/C function but destructors
* are executed.
* Same as above, but if the exception inherits from std::exception with
* a NULL what(). Duktape will describe the error as 'unknown' if so.
Handshake line is available for caller for the
* duration of the callback, and must not be freed
* by the caller.
Too small, resize.
just in case, if dvalues changed something
mixed endian (arm)
Define to enable error prints to stderr.
0x80 ... 0xbf
comment: IEEE double byte order, detect at run time (could also use
* preprocessor defines but that's verbose to make portable).
*
* >>> struct.unpack('>d', '1122334455667788'.decode('hex'))
* (3.841412024471731e-226,)
* >>> struct.unpack('>d', '8877665544332211'.decode('hex'))
* (-7.086876636573014e-268,)
* >>> struct.unpack('>d', '4433221188776655'.decode('hex'))
* (3.5294303071877444e+20,)
label: code-design
Handshake line is returned as a dvalue for convenience; it's
* not actually a part of the dvalue phase of the protocol.
Too big, resize so that we reclaim memory if we have just
* received a large string/buffer value.
little endian
0x00 ... 0x1f
comment:
* Example debug transport with a local debug message encoder/decoder.
*
* Provides a "received dvalue" callback for a fully parsed dvalue (user
* code frees dvalue) and a "cooperate" callback for e.g. UI integration.
* There are a few other callbacks. See test.c for usage examples.
*
* This transport implementation is not multithreaded which means that:
*
* - Callbacks to "received dvalue" callback come from the Duktape thread,
* either during normal execution or from duk_debugger_cooperate().
*
* - Calls into duk_trans_dvalue_send() must be made from the callbacks
* provided (e.g. "received dvalue" or "cooperate") which use the active
* Duktape thread.
*
* - The only exception to this is when Duktape is idle: you can then call
* duk_trans_dvalue_send() from any thread (only one thread at a time).
* When you next call into Duktape or call duk_debugger_cooperate(), the
* queued data will be read and processed by Duktape.
*
* There are functions for creating and freeing values; internally they use
* malloc() and free() for memory management. Duktape heap alloc functions
* are not used to minimize disturbances to the Duktape heap under debugging.
*
* Doesn't depend on C99 types; assumes "int" is at least 32 bits, and makes
* a few assumptions about format specifiers.
label: code-design
never here
0x60 ... 0x7f
Caller must provide a buffer at least DUK_DVALUE_TOSTRING_BUFLEN in size.
Harmless warning on some platforms (re: range)
Alloc size is len + 1 so that a NUL terminator is always
* guaranteed which is convenient, e.g. you can printf() the
* value safely.
big endian
Integers are network endian, read back into host format.
Portable IEEE double byteswap. Relies on runtime detection of
* host endianness.
Integers are written in network endian format.
IEEE doubles are network endian, read back into host format.
32 hex encoded or \xXX escaped bytes, possible "...", NUL
* Dvalue transport handling
Integers are network endian, read back into host format in
* a portable manner.
0xc0 ... 0xff
* Dvalue handling
comment: Define to enable debug prints to stderr.
label: code-design
end switch
* Duktape callbacks
Portable sign handling, doesn't assume 'int' is exactly 32 bits
* like a direct cast would.
Trial parse handshake line or dvalue(s).
IEEE doubles are written in network endian format.
Must cooperate until user callback provides data. From
* Duktape's perspective we MUST block until data is received.
mixed endian
0x20 ... 0x5f
comment: some extra to reduce resizes
label: code-design
Append data.
When read_offset is large enough, "rebase" buffer by deleting already
* read data and updating offsets.
big endian: ok as is
Convert argument dvalue into Duktape debug protocol format.
* Literal constants are used here for the debug protocol,
* e.g. initial byte 0x02 is REP, see doc/debugger.rst.
tolerates NULL
d: ieee double
sending towards Duktape (duktape read callback)
Buffer size needed by duk_dvalue_to_string().
buf: buffer data, len: buffer length
DUK_TRANS_DVALUE_H_INCLUDED
struct duk_dvalue 'tag' values, note that these have nothing to do with
* Duktape debug protocol inital byte. Struct fields used with the type
* are noted next to the define.
i: class number, buf: pointer data, len: pointer length
i: 32-bit signed integer
buf: pointer data, len: pointer length
Sending dvalues towards Duktape.
Duktape debug callbacks provided by the transport.
receiving from Duktape (duktape write callback)
buf: string data, len: string length
Could use a union for the value but the gain would be relatively small.
no fields
comment: 0=little endian, 1=big endian, 2=mixed endian
label: code-design
Initializing and freeing the transport context.
Dvalue handling.
i: lightfunc flags, buf: pointer data, len: pointer length
Attach debugger; this will fail with a fatal error here unless
* debugger support is compiled in. To fail more gracefully, call
* this under a duk_safe_call() to catch the error.
DumpHeap
fake ptr len
The Duktape handshake line is given in 'line' (without LF).
* The 'line' argument can be accessed for the duration of the
* callback (read only). Don't free 'line' here, the transport
* handles that.
medium, >= 32 chars
Evaluate simple test code, callbacks will "step over" until end.
*
* The test code here is just for exercising the debug transport.
* The 'evalMe' variable is evaluated (using debugger command Eval)
* before every step to force different dvalues to be carried over
* the transport.
duk_trans_dvalue_send_req_cmd() sends a REQ dvalue followed by
* an integer dvalue (command) for convenience.
classnum
Detached call forwarded as is.
0x14 = StepOver
* Example program using the dvalue debug transport.
long buffer, >= 65536 chars
TriggerStatus
suppress warning
Here a normal debug client would wait for dvalues until an EOM
* dvalue was received (which completes a debug message). The
* debug message would then be handled, possibly causing UI changes
* and/or causing debug commands to be sent to Duktape.
*
* The callback is responsible for eventually freeing the dvalue.
* Here we free it immediately, but an actual client would probably
* gather dvalues into an array or linked list to handle when the
* debug message was complete.
Duktape is not blocked; you can cooperate with e.g. a user
* interface here and send dvalues to Duktape, but don't block.
Also send a dummy TriggerStatus request with trailing dvalues
* ignored by Duktape; Duktape will parse the dvalues to be able to
* skip them, so that the dvalue encoding is exercised.
0x1e = Eval
comment: First time Duktape becomes blocked, send DumpHeap which
* exercises a lot of parsing code.
*
* NOTE: Valgrind may complain about reading uninitialized
* bytes. This is caused by the DumpHeap command writing out
* verbatim duk_tval values which are intentionally not
* always fully initialized for performance reasons.
label: code-design
short, <= 31 chars
Duktape is blocked on a read and won't continue until debug
* command(s) are sent.
*
* Normally you'd enter your own event loop here, and process
* events until something needs to be sent to Duktape. For
* example, the user might press a "Step over" button in the
* UI which would cause dvalues to be sent. You can then
* return from this callback.
*
* The code below sends some example messages for testing the
* dvalue handling of the transport.
*
* If you create dvalues manually and send them using
* duk_trans_dvalue_send(), you must free the dvalues after
* the send call returns using duk_dvalue_free().
lf_flags
DUK_TRANS_SOCKET_H_INCLUDED
comment: XXX: For now, close the listen socket because we won't accept new
* connections anyway. A better implementation would allow multiple
* debug attaches.
label: code-design
Duktape debug transport callback: (possibly partial) read.
This shouldn't happen.
should never happen
This TCP transport requires no write flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
* Example debug transport using a Linux/Unix TCP socket
*
* Provides a TCP server socket which a debug client can connect to.
* After that data is just passed through.
This TCP transport requires no read flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
backlog
In a production quality implementation there would be a sanity
* timeout here to recover from "black hole" disconnects.
Duktape debug transport callback: (possibly partial) write.
Write flush. If the transport combines multiple writes
* before actually sending, a write flush is an indication
* to write out any pending bytes: Duktape may not be doing
* any more writes on this occasion.
* Transport init and finish
* Duktape callbacks
nothing to read
also returns 0, which is correct
Read flush: Duktape may not be making any more read calls at this
* time. If the transport maintains a receive window, it can use a
* read flush as a signal to update the window status to the remote
* peer. A read flush is guaranteed to occur before Duktape stops
* reading for a while; it may occur in other situations as well so
* it's not a 100% reliable indication.
comment: not needed by the example
label: requirement
something to read
comment: XXX: For now, close the listen socket because we won't accept new
* connections anyway. A better implementation would allow multiple
* debug attaches.
label: code-design
Duktape debug transport callback: (possibly partial) read.
comment: MinGW workaround for missing getaddrinfo() etc:
* http://programmingrants.blogspot.fi/2009/09/tips-on-undefined-reference-to.html
label: code-design
This shouldn't happen.
This TCP transport requires no write flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
This TCP transport requires no read flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
In a production quality implementation there would be a sanity
* timeout here to recover from "black hole" disconnects.
Duktape debug transport callback: (possibly partial) write.
Write flush. If the transport combines multiple writes
* before actually sending, a write flush is an indication
* to write out any pending bytes: Duktape may not be doing
* any more writes on this occasion.
* Transport init and finish
* Example debug transport using a Windows TCP socket
*
* Provides a TCP server socket which a debug client can connect to.
* After that data is just passed through.
*
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
*
* Compiling 'duk' with debugger support using MSVC (Visual Studio):
*
* > cl /W3 /O2 /Feduk.exe
* /DDUK_OPT_DEBUGGER_SUPPORT /DDUK_OPT_INTERRUPT_COUNTER
* /DDUK_CMDLINE_DEBUGGER_SUPPORT
* /Iexamples\debug-trans-socket /Isrc
* examples\cmdline\duk_cmdline.c
* examples\debug-trans-socket\duk_trans_socket_windows.c
* src\duktape.c
*
* With MinGW:
*
* $ gcc -oduk.exe -Wall -O2 \
* -DDUK_OPT_DEBUGGER_SUPPORT -DDUK_OPT_INTERRUPT_COUNTER \
* -DDUK_CMDLINE_DEBUGGER_SUPPORT \
* -Iexamples/debug-trans-socket -Isrc \
* examples/cmdline/duk_cmdline.c \
* examples/debug-trans-socket/duk_trans_socket_windows.c \
* src/duktape.c -lm -lws2_32
* Duktape callbacks
also returns 0, which is correct
nothing to read
never here
Read flush: Duktape may not be making any more read calls at this
* time. If the transport maintains a receive window, it can use a
* read flush as a signal to update the window status to the remote
* peer. A read flush is guaranteed to occur before Duktape stops
* reading for a while; it may occur in other situations as well so
* it's not a 100% reliable indication.
comment: not needed by the example
label: requirement
something to read
Return a fixed time here as a dummy example.
* Dummy Date provider
*
* There are two minimally required macros which you must provide in
* duk_config.h:
*
* extern duk_double_t dummy_get_now(void);
*
* #define DUK_USE_DATE_GET_NOW(ctx) dummy_get_now()
* #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) 0
*
* Note that since the providers are macros, you don't need to use
* all arguments. Similarly, you can "return" fixed values as
* constants. Above, local timezone offset is always zero i.e.
* we're always in UTC.
*
* You can also provide optional macros to parse and format timestamps
* in a platform specific format. If not provided, Duktape will use
* ISO 8601 only (which is often good enough).
* Very simple example program for evaluating expressions from
* command line
nargs
nrets
* A few basic tests
XXX: or t->target + t->delay?
comment: Active timers. Dense list, terminates to end of list or first unused timer.
* The list is sorted by 'target', with lowest 'target' (earliest expiry) last
* in the list. When a timer's callback is being called, the timer is moved
* to 'timer_expiring' as it needs special handling should the user callback
* delete that particular timer.
label: code-design
ignore errors for now -> [ ... stash eventTimers ]
not found, append to list
Initialize global stash 'eventTimers'.
Update timer_count.
Misc
-> [ ... ]
-> [ ... stash eventTimers retval ]
One-shot timer (always removed) or removed by user callback.
Finally, register the callback to the global stash 'eventTimers' object.
* Determine poll() timeout (as close to poll() as possible as
* the wait is relative).
Interval timer, not removed by user callback. Queue back to
* timer list and bubble to its final sorted position.
deleted, perhaps by previous callback
Timer is now at the last position; use swaps to "bubble" it to its
* correct sorted position.
* If exit has been requested, exit without running further
* callbacks.
comment: mark to-be-deleted, cleaned up by next poll
label: code-design
last timer at timer_count - 1
Zero last element for clarity.
Socket poll state.
[ ... stash eventTimers ]
error
* Compact poll list by removing pollfds with fd == 0.
Set global 'EventLoop'.
eventTimers[timer_id] = callback
comment: zeroize unused entries for sanity
label: code-design
Last timer expires first (list is always kept sorted).
-> [ ... stash eventTimers func ]
delay/interval
oneshot=1 (setTimeout), repeated=0 (setInterval)
The callback associated with the timer is held in the "global stash",
* in <stash>.eventTimers[String(id)]. The references must be deleted
* when a timer struct is deleted.
Get Javascript compatible 'now' timestamp (millisecs since 1970).
events == 0 means stop listening to the FD
-> [ timer_id stash eventTimers ]
* Expire timers.
Shift elements downwards to keep the timer list dense
* (no need if last element).
* If exit requested, bail out as fast as possible.
't' expires later than 't-1', so swap them and repeat.
Timer to bubble is at index i, timer to compare to is
* at i-1 (both guaranteed to exist).
Return timer id.
Bubble last timer on timer list backwards until it has been moved to
* its proper sorted position (based on 'target' time).
next target time
i = input index
* j = output index (initially same as i)
The C state is now up-to-date, but we still need to delete
* the timer callback state from the global 'stash'.
'rc' fds active
clamping ensures that fits
* Expired timer(s) still exist?
timeout
* Move the timer to 'expiring' for the duration of the callback.
* Mark a one-shot timer deleted, compute a new target for an interval.
* Call timer callback. The callback can operate on the timer list:
* add new timers, remove timers. The callback can even remove the
* expired timer whose callback we're calling. However, because the
* timer being expired has been moved to 'timer_expiring', we don't
* need to worry about the timer's offset changing on the timer list.
comment: this is quite excessive for embedded use, but good for testing
label: code-design
if timeout, no need to check pollfd
The Ecmascript poll handler is passed through EventLoop.fdPollHandler
* which c_eventloop.js sets before we come here.
indexes:
* 0 = function (callback)
* 1 = delay
* 2 = boolean: oneshot
-> [ func delay oneshot stash eventTimers ]
comment:
* Unlike insertion, deletion needs a full scan of the timer list
* and an expensive remove. If no match is found, nothing is deleted.
* Caller gets a boolean return code indicating match.
*
* When a timer is being expired and its user callback is running,
* the timer has been moved to 'timer_expiring' and its deletion
* needs special handling: just mark it to-be-deleted and let the
* expiry code remove it.
label: code-design
nargs
* Poll for activity or timeout.
copy only if indices have diverged
timer has been requested for removal
-> [ global EventLoop fdPollHandler ]
Because a user callback can mutate the timer list (by adding or deleting
* a timer), we expire one timer and then rescan from the end again. There
* is a sanity limit on how many times we do this per expiry round.
keep output index the same
comment:
* Check socket activity, handle all sockets. Handling is offloaded to
* Ecmascript code (fd + revents).
*
* If FDs are removed from the poll list while we're processing callbacks,
* the entries are simply marked unused (fd set to 0) without actually
* removing them from the poll list. This ensures indices are not
* disturbed. The poll list is compacted before next poll().
label: code-design
numeric ID (returned from e.g. setTimeout); zero if unused
Should never happen, so return whatever.
delete eventTimers[timer_id]
't' expires earlier than (or same time as) 't-1', so we're done.
indexes:
* 0 = timer id
comment:
* C eventloop example.
*
* Timer management is similar to eventloop.js but implemented in C.
* In particular, timer insertion is an O(n) operation; in a real world
* eventloop based on a heap insertion would be O(log N).
label: code-design
print('unexpected revents, close fd');
no size control now
print('READ', Duktape.enc('jx', data));
* C eventloop example (c_eventloop.c).
*
* Ecmascript code to initialize the exposed API (setTimeout() etc) when
* using the C eventloop.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
This simple example doesn't have support for write blocking / draining
Connected
print('ACCEPT:', Duktape.enc('jx', acc_res));
Special case: callback arguments are provided.
[ arg1, arg2, ... ]
[ global(this), arg1, arg2, ... ]
print('activity on fd', fd, 'revents', revents);
* Timer API
comment:
* Socket handling
*
* Ideally this would be implemented more in C than here for more speed
* and smaller footprint: C code would directly maintain the callback state
* and such.
*
* Also for more optimal I/O, the buffer churn caused by allocating and
* freeing a lot of buffer values could be eliminated by reusing buffers.
* Socket reads would then go into a pre-allocated buffer, for instance.
label: code-design
retval ignored
print('UNKNOWN');
Legacy case: callback is a string.
oneshot
Normal case: callback given as a function without arguments.
Math.exp(0)...Math.exp(8) is an uneven distribution between 1...~2980.
Here the inserts take a lot of time because the underlying timer manager
* data structure has O(n) insertion performance.
* Test using timers and intervals with curses.
* Pure Ecmascript eventloop example.
*
* Timer state handling is inefficient in this trivial example. Timers are
* kept in an array sorted by their expiry time which works well for expiring
* timers, but has O(n) insertion performance. A better implementation would
* use a heap or some other efficient structure for managing timers so that
* all operations (insert, remove, get nearest timer) have good performance.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
comment: If exit requested, don't call any more callbacks. This allows
a callback to do cleanups and request exit, and can be sure that
no more callbacks are processed.
label: code-design
Remove the timer from the active list and process it. The user
callback may add new timers which is not a problem. The callback
may also delete timers which is not a problem unless the timer
being deleted is the timer whose callback we're running; this is
why the timer is recorded in this.expiring so that clearTimeout()
and clearInterval() can detect this situation.
sockets
fd -> callback
fd -> callback
fd -> callback
If the timer was one-shot, it's marked 'removed'. If the user callback
requested deletion for the timer, it's also marked 'removed'. If the
timer is an interval (and is not marked removed), insert it back into
the timer list.
this.dumpState();
Timer has expired and we're processing its callback. User
callback has requested timer deletion. Mark removed, so
that the timer is not reinserted back into the active list.
This is actually a common case because an interval may very
well cancel itself.
Special case: callback arguments are provided.
[ arg1, arg2, ... ]
[ global(this), arg1, arg2, ... ]
This simple example doesn't have support for write blocking / draining
no such ID, ignore
print('zero read for fd ' + fd + ', closing forcibly');
ignore result
print('UNKNOWN');
Legacy case: callback is a string.
timers
active timers, sorted (nearest expiry last)
set to timer being expired (needs special handling in clearTimeout/clearInterval)
no size control now
print('READ', Duktape.enc('jx', data));
print('revents ' + t.revents + ' for fd ' + fd + ', closing forcibly');
ignore result
misc
print('ACCEPT:', Duktape.enc('jx', acc_res));
* Create poll socket list. This is a very naive approach.
* On Linux, one could use e.g. epoll() and manage socket lists
* incrementally.
start
deleteCount
* Find 'i' such that we want to insert *after* timers[i] at index i+1.
* If no such timer, for-loop terminates with i-1, and we insert at -1+1=0.
print('exit requested, exit');
Remove timer/interval with a timer ID. The timer/interval can reside
either on the active list or it may be an expired timer (this.expiring)
whose user callback we're running when this function gets called.
Get timer with lowest expiry time. Since the active timers list is
sorted, it's always the last timer.
* Wait timeout for timer closest to expiry. Since the poll
* timeout is relative, get this as close to poll() as possible.
print(new Date(), 'poll_set OUT:', Duktape.enc('jx', poll_set));
* Do the actual poll.
* Timer API
*
* These interface with the singleton EventLoop.
print('UNKNOWN POLLOUT');
Timers to expire?
* Exit check (may be requested by a user callback)
comment: Timer on active list: mark removed (not really necessary, but
nice for dumping), and remove from active list.
label: code-design
insert after 't', to index i+1
* Event loop
*
* Timers are sorted by 'target' property which indicates expiry time of
* the timer. The timer expiring next is last in the array, so that
* removals happen at the end, and inserts for timers expiring in the
* near future displace as few elements in the array as possible.
print(new Date(), 'poll_set IN:', Duktape.enc('jx', poll_set));
* Here we must be careful with mutations: user callback may add and
* delete an arbitrary number of timers.
*
* Current solution is simple: check whether the timer at the end of
* the list has expired. If not, we're done. If it has expired,
* remove it from the active list, record it in this.expiring, and call
* the user callback. If user code deletes the this.expiring timer,
* there is special handling which just marks the timer deleted so
* it won't get inserted back into the active list.
*
* This process is repeated at most maxExpirys times to ensure we don't
* get stuck forever; user code could in principle add more and more
* already expired timers.
custom call
* Process expired timers.
* Process all sockets so that nothing is left unhandled for the
* next round.
flag for removal
Timer has not expired, and no other timer could have expired
either because the list is sorted.
Reinsert interval timer to correct sorted position. The timer
must be an interval timer because one-shot timers are marked
'removed' above.
Eat errors silently. When resizing curses window an EINTR
happens now.
Normal case: callback given as a function without arguments.
Set global 'FileIo'.
* File I/O binding example.
comment: XXX: pcall the string coercion
label: code-design
fall thru
comment: This is useful at the global level; libraries should avoid SIGPIPE though
label: code-design
nargs
nrets
[ ... global func ]
Duktape/C function, safe called
nret
Start a zero timer which will call _USERCODE from within
* the event loop.
Finally, launch eventloop. This call only returns after the
* eventloop terminates.
signal(SIGPIPE, SIG_IGN);
Compile input and place it into global _USERCODE
Print error to stderr and pop error.
NO_SIGNAL
comment: XXX: print error objects specially
label: code-design
* Main for evloop command line tool.
*
* Runs a given script from file or stdin inside an eventloop. The
* script can then access setTimeout() etc.
Set global 'Ncurses'.
XXX: no screen management now
comment:
* Ncurses bindings example.
*
* VALGRIND NOTE: when you use ncurses, there seems to be no way to get a
* clean valgrind run. Even if ncurses state is properly shut down, there
* will still be some residual leaks.
*
* Debian: install libncurses5-dev
label: code-design
[retarr]
-> [... retarr key]
Linux 2.6.17 and upwards, requires _GNU_SOURCE etc, not added
* now because we don't use it.
-> [... retarr fd]
enum_flags
leave enum on stack
* C wrapper for poll().
update revents
Set global 'Poll' with functions and constants.
-> [... enum key val events]
-> [... enum key val]
-> [... enum]
-> [... retarr val "revents" fds[i].revents]
[... enum key]
rc = ppoll(fds, n, &ts, NULL);
-> [... enum key key]
-> [... retarr val]
uppercase
ensure we get a plain buffer
Handle socket data carefully: if you convert it to a string,
it may not be valid UTF-8 etc. Here we operate on the data
directly in the buffer.
backlog
Set global 'Socket'.
MSG_NOSIGNAL: avoid SIGPIPE
* TCP sockets binding example.
fib.js
Pure Ecmascript version of low level helper
Check 'val' for primality
prime.js
Select available helper at load time
Find primes below one million ending in '9999'.
primecheck.c
nargs
ignore result
process.js
nargs
index
processlines.c
pop result/error
ignore result
uppercase.c
We're going to need 'sz' additional entries on the stack.
one return value
* Very simple example program
pop global
#args
suppress warning
pop eval result
nargs
comment:
* Pretty print JSON from stdin into indented JX.
label: code-design
comment: suppress warnings
label: code-design
nrets
-1 for filename
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
-> [ ... source filename ]
nrets
* Main
* Setup sandbox
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
must not return
256kB sandbox
* Sandboxing example
*
* Uses custom memory allocation functions which keep track of total amount
* of memory allocated, imposing a maximum total allocation size.
-> [ ... filename source ]
* Sandbox setup and test
Should be zero.
Suppress warning.
nargs
flags
Compile as program
* Memory allocator which backs to standard library memory functions but
* keeps a small header to track current allocation size.
*
* Many other sandbox allocation models are useful, e.g. preallocated pools.
* Execute code from specified file
* Mandelbrot example:
*
* $ ./duk mandel.js
* [...]
z -> z^2 + c
* -> (xx+i*yy)^2 + (x0+i*y0)
* -> xx*xx+i*2*xx*yy-yy*yy + x0 + i*y0
* -> (xx*xx - yy*yy + x0) + i*(2*xx*yy + y0)
xx^2 + yy^2 >= 4.0
capture in closure in case changed later
* Minimal console.log() polyfill
nop
* Ensure Error .fileName, .lineNumber, and .stack are not directly writable,
* but can be written using Object.defineProperty(). This matches Duktape
* 1.3.0 and prior.
*
* See: https://github.com/svaarala/duktape/pull/390.
already non-writable
already writable
* Ensure Error .fileName, .lineNumber, and .stack are directly writable
* without having to use Object.defineProperty(). This matches Duktape
* 1.4.0 behavior.
*
* See: https://github.com/svaarala/duktape/pull/390.
tag for unpacked duk_tval
tag for packed duk_tval
internal tag is fastint
public type is DUK_TYPE_NUMBER
* Helper to check if a number is internally represented as a fastint:
*
* if (Duktape.isFastint(x)) {
* print('fastint');
* } else {
* print('not a fastint (or not a number)');
* }
*
* NOTE: This helper depends on the internal tag numbering (defined in
* duk_tval.h) which is both version specific and depends on whether
* duk_tval is packed or not.
Tag number depends on duk_tval packing.
null or undefined
enumerable own keys
* Object.assign(), described in E6 Section 19.1.2.1
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.assign
* Object.prototype.__defineGetter__ polyfill
* Object.prototype.__defineSetter__ polyfill
comment:
* Performance.now() polyfill
*
* http://www.w3.org/TR/hr-time/#sec-high-resolution-time
*
* Dummy implementation which uses the Date built-in and has no higher
* resolution. If/when Duktape has a built-in high resolution timer
* interface, reimplement this.
label: code-design
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
* Git describe: v1.5.2
* Git branch: HEAD
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
alloc external with size zero
'i' is the first entry we'll keep
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
resend state next time executor is about to run
comment: XXX: avoid this check somehow
label: code-design
Should match Function.prototype.toString()
* Main struct
'/'
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Duktape.modLoaded[] module cache
[ obj handler trap ]
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
comment: size for formatting buffers
label: code-design
default case exists: go there if no case matches
registers are mutable, non-deletable
'{'
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
get or set a range of flags; m=first bit number, n=number of bits
[ level obj func pc line ]
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
[ arg1 ... argN this ]
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
Allocator functions.
next does not exist or next is not a letter
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
'enum'
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
just making sure
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
comment: XXX: string not shared because it is conditional
label: code-design
carry
Initial bytes for markers.
queue back to heap_allocated
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
print provider
form: { DecimalDigits , }, val1 = min count
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
DUK_TOK_LPAREN
caller ensures; rom objects are never bufferobjects now
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
1 -> needs a PUTVAR
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
leave out trailing 'unused' elements
comment: TODO: implement Proxy object support here
label: requirement
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
args start at index 2
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
eat colon
always set; points to a reserved valstack slot
Track number of escapes: necessary for proper keyword
* detection.
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
should never happen but default here
'env'
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
-> [val]
emitted
resume delete to target
-> [... obj]
success
+0.0
replacer is a mutation risk
parse key and value
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
No duk_bw_remove_ensure_slice(), functionality would be identical.
if boolean matches A, skip next inst
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
[ ... val ]
'true'
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
For now shared handler is fine.
may be less, since DELETED entries are NULLed by rehash
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
OK
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
maximum loopcount for peephole optimization
cleared before entering finally
flags for duk_hobject_get_own_propdesc() and variants
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
useful for patching jumps later
avoid attempts to add/remove object keys
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Local defines
comment: XXX: compression
label: code-design
already NULLed (by unwind)
Don't allow actual chars after equal sign.
-> [ Object defineProperty undefined obj key desc ]
whether to use macros or helper function depends on call count
DUK_USE_FASTINT
7: toISOString
comment: XXX: "read only object"?
label: code-design
no action
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
must hold DUK_VARARGS
capture is 'undefined', always matches!
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
'raw'
DUK_TOK_RPAREN
request to create catch binding
for object-bound identifiers
comment: XXX: compression (as an option)
label: code-design
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
first coerce to a plain value
-> [ ... func varmap enum ]
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
force_global
NB: use 's' as temp on purpose
Not odd, or y == -Infinity
* Global object built-ins
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
[ body formals ], formals is comma separated list that needs to be parsed
bytecode execution
thisArg
* Not found
XXX: duk_uarridx_t?
E5 Section 9.4, ToInteger()
force_new
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
avoid dereference after potential callstack realloc
* Pass 2
compensate for eval() call
set values into ret array
* Pick an object from the head (don't remove yet).
fast path
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
[ ... this tracedata sep this ]
* After arguments, allocate special registers (like shuffling temps)
[ ToObject(this) item1 ... itemN arr item(i) ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
This behavior mostly mimics Node.js now.
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
Encode a fastint from duk_tval ptr, no value stack effects.
'has'
DUK_TOK_COMMA
'void'
bufwriter for code
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
* UTF-8 / XUTF-8 / CESU-8 constants
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
DUK_TOK_IDENTIFIER
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
[ ... func varmap enum key value this ]
1: toDateString
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
Positive if local time ahead of UTC.
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
save stack top
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
Treat like a debugger statement: ignore when not attached.
'import'
Duktape/C API guaranteed entries (on top of args)
avoid warning (unsigned)
Helper which can be called both directly and with duk_safe_call().
[ ... template ]
-> [ buffer ]
comment: XXX: Here a "slice copy" would be useful.
label: code-design
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
duk_unicode_ids_m_let_noa[]
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
indirect allocs
Lightfuncs are always considered strict.
implies DUK_HOBJECT_IS_BUFFEROBJECT
safe, because matched (NUL causes a break)
* Packed tval sanity
longjmp type
should be first on 64-bit platforms
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[ ... | (crud) errobj ]
expensive flag
validation performed by duk__hexval
non-strict equality from here on
allocate catcher and populate it (should be atomic)
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
if 0, 'str16' used, if > 0, 'strlist16' used
probe sequence (open addressing)
token was preceded by a lineterm
-> [ ... ]
* Store entry state.
Perform an intermediate join when this many elements have been pushed
* on the value stack.
duk_unicode_ids_m_let_noabmp[]
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
'return'
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
comment: log level could be popped but that's not necessary
label: code-design
thread currently running (only one at a time)
numargs
already defined, good
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
Copy term name until end or '/'.
-> [ ... trap handler ]
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
DUK_TOK_DEBUGGER
Init newly allocated slots (only).
a complex (new) atom taints the result
[this value]
See: test-bug-tailcall-preventyield-assert.c.
check_object_coercible
comment: XXX: source code property
label: code-design
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
comment: XXX: unnecessary, handle in adjust
label: code-design
[ ... key trap handler ]
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
const
even for zero-length string
eat 'if'
14: getDay
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
function: create an arguments object on function call
-> [... target]
* Nice debug log.
comment: XXX: copy flags using a mask
label: code-design
[ ... func/retval ] -> [ ... ]
comment: XXX: optimize loops
label: code-design
up to 36 bit codepoints
no fractions in internal time
ditto
[key] -> []
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
[ buf? res ]
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
undefined -> skip (replaced with empty)
eat opening quote on first loop
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
no need to decref
18: getMinutes
'exports'
* Unicode letter check.
DUK_USE_MATH_BUILTIN
No field needed when strings are in ROM.
value was undefined/unsupported
eat 'function'
keep in valstack
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
step 11
IdentifierPart production with IdentifierStart and ASCII excluded
Internal timevalue is already NaN, so don't touch it.
flag for later write
GH-303
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
DUK_TOK_SEMICOLON
return value from Duktape.Thread.yield()
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Parts are in local time, convert when setting.
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
Backup 'caller' property and update its value.
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
Add function object.
finalization
[ ToObject(this) item1 ... itemN arr ]
0x50...0x5f
Rule table: first matching rule is used to determine what to do next.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* Init the heap object
Inherit from ROM-based global object: less RAM usage, less transparent.
Note: 0xff != DUK_BC_C_MAX
COMMA
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
comment: function must not be tail called
label: code-design
stage 3: update length (done by caller), decide return code
idx_space
statement does not terminate directive prologue
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
* Table for hex decoding ASCII hex digits
function: create new environment when called (see duk_hcompiledfunction)
pop regexp res_obj or match string
P
required if NAMEBINDING set
slow path decode
don't care value, year is mandatory
really 'not applicable' anymore, should not be referenced after this
skip jump conditionally
* Flags parsing (see E5 Section 15.10.4.1).
for updating (all are set to < 0 for virtual properties)
* Run (object) finalizers in the "to be finalized" work list.
'warn'
DUK_USE_FILE_IO
[... constructor arg1 ... argN final_cons fallback]
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
'Array' object, array length and index exotic behavior
a statement following a label cannot be a source element
* (a function declaration).
24: setMilliseconds
'\xffVarenv'
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
DUK_TOK_BREAK
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
DUK_TOK_MOD_EQ
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
Note: DST adjustment is determined using UTC time.
caller must check
2
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
log this with a normal debug level because this should be relatively rare
* Ecmascript execution, support primitives.
* replace()
out_clamped=NULL, RangeError if outside range
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
idx_args = idx_func + 2
handle comma and closing bracket
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
Note: this allows creation of internal strings.
DUK__FLD_DOUBLE
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
caller and arguments must use the same thrower, [[ThrowTypeError]]
bound function 'length' property is interesting
DUK_REPLACEMENTS_H_INCLUDED
[ ... error func ]
expt 0x000 is zero/subnormal
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
restore PC
allow negative PCs, behave as a no-op
'\xffValue'
* Activation defines
Step 15: insert itemCount elements into the hole made above
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
XXX: ARRAY_PART for Array prototype?
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
string is a valid array index
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
'Number'
buffer is behind a pointer, dynamic or external
* in
allow caller to give a const number with the DUK__CONST_MARKER
DUK_USE_JSON_DECNUMBER_FASTPATH
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
XXX: use DUK_HSTRING_FLAG_INTERNAL?
func support for [[HasInstance]] checked in the beginning of the loop
%p
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
pop key
implementation specific
* Log level check
comment: XXX: unify handling with native call.
label: code-design
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
39: setYear
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
E5.1 Section 15.9.1.6
DUK_USE_JSON_QUOTESTRING_FASTPATH
always in executor
because of valstack init policy
embed: func ptr
local
Sanity check
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
* Manipulate callstack for the call.
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
'typeof'
Execute bytecode until returned or longjmp().
overflow not possible, buffer limits
'interface'
zero everything unless requested not to do so
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
* Node.js Buffer.isBuffer()
DUK_TOK_COLON
B -> target register for next key
* C -> enum register
-> [ ... flags escaped_source bytecode ]
backref n -> saved indices [n*2, n*2+1]
value1 -> error object
remove key
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
comment: For short strings, use a fixed temp buffer.
label: code-design
label limits
marker values for hash part
DUK_TOK_GE
-> [ ... closure ]
NULL pointer is required to encode to zero, so memset is enough.
else an array initializer element
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
35: setUTCMonth
[ ... retval ]
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
'new' MemberExpression Arguments
assume plain values
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
[ ... val obj ]
-> [ ... re_obj input bc saved_buf lastIndex ]
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Duktape/C (nativefunction) object, exotic 'length'
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
'this' binding
[ ... val key ] -> [ ... key val ]
isAccessor
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
skip opening slash on first loop
transfer flags
DUK_TOK_INTERFACE
may be undefined
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
iteration statements allow continue
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
'while'
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
object is constructable
regexp support disabled
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
assume keys are compacted
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
advance, whatever the current token is; parse next token in regexp context
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
regs to allocate
preallocated temporaries (2) for variants 3 and 4
[ regexp input ]
function: function object is strict
DUK_TOK_ALSHIFT
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
call is a direct eval call
varname is still reachable
Leave 'setter' on stack
seconds
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
DUK_USE_VARIADIC_MACROS
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
key is now reachable in the valstack
MakeDate
Request callback should push values for reply to client onto valstack
inserted jump
[enum_target res]
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
Then reuse the unwound activation; callstack was not shrunk so there is always space
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
for storing/restoring the varmap binding for catch variable
r <- (2 * f) * b^(e+1)
'[...]'
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
function is strict
must work for nargs <= 0
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
don't run finalizers; leave finalizable objects in finalize_list for next round
[this value] -> [value this]
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
2: toTimeString
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
* Initialize function state for a zero-argument function
Guaranteed by recursion_limit setup so we don't have to
* check twice.
line continuation
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
'-Infinity'
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
type tag (public)
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
don't re-enter e.g. during Eval
mp <- b^e
special handling of fmt==NULL
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
parse value
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
function may call direct eval
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
[ array totalLength ]
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
-> [ ... key val val' ]
[ ... re_obj input ] -> [ ... re_obj input bc ]
valstack slot for 1st token value
side effects, possibly errors
NOTE: Multiple evaluation of 'ptr' in this macro.
Overflow of the execution counter is fine and doesn't break
* anything here.
mark-and-sweep: finalized (on previous pass)
curr is accessor, desc is data
[ func thisArg arg1 ... argN ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
this function
comment: 'tv' becomes invalid
label: code-design
is an actual function (not global/eval code)
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
'callee'
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
'byteOffset'
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
no operators
Strict: never allow function declarations outside top level.
[ ... arg1 ... argN envobj ]
* Field access
0x30...0x3f
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
true
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
only use the highest bit
Function values are handled completely above (including
* coercion results):
distinct bignums, easy mistake to make
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
DUK_TOK_INSTANCEOF
time
update entry, allocating if necessary
A structure for 'snapshotting' a point for rewinding
* Ecmascript call
cannot be arguments exotic
comment: this is not strictly necessary, but helps debugging
label: code-design
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
push initial function call to new thread stack; this is
* picked up by resume().
31: setUTCHours
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
format plus something to avoid just missing
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
if property already exists, overwrites silently
comment: 'val' is never NaN, so no need to normalize
label: code-design
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
may be reg or const
decl name
rnd_state for duk_util_tinyrandom.c
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
jump is inserted here
misc
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
only flag now
[... func this arg1 ... argN]
record previous atom info in case next token is a quantifier
-""-
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
not enumerable
%f and %lf both consume a 'long'
* Catcher defines
never executed
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
'('
important to do this *after* pushing, to make the thread reachable for gc
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
Should not happen.
init pointer fields to null
* toString(), valueOf()
success, fixup pointers
comment: XXX: several pointer comparison issues here
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
Check that value is a duk_hbufferobject and return a pointer to it.
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
Note: assumes that duk_util_probe_steps size is 32
guaranteed when building arguments
updates thread state, minimizes its allocations
'{"_inf":true}'
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
comment: TimeClip() should never be necessary
label: code-design
0x10-0x1f
E5.1 Section B.2.2, step 7.
Parser part masks.
end switch (tok)
negative -> complex atom
-> [ ... val root "" ]
result array
XXX: fast path for arrays?
-> [ ... ToObject(this) ToUint32(length) ]
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
0x00...0x0f
coercion order matters
'jc'
1 if property found, 0 otherwise
fixed-format
not strictly necessary because of lookahead '}' above
comment: XXX: must be able to represent -len
label: code-design
DUK_USE_DPRINT_COLORS
expect_eof
borrowed reference to catch variable name (or NULL if none)
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
lookup should prevent this
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
result index for filter()
either nonzero value is ok
bc
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
can't resize below 'top'
round up roughly to next 'grow step'
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
last array index explicitly initialized, +1
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
need side effects, not value
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
Note: for srclen=0, src may be NULL
never an empty match, so step 13.c.iii can't be triggered
Outer executor with setjmp/longjmp handling.
if B/C is >= this value, refers to a const
if debugging disabled
if true, the stack already contains the final result
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
when nothing is running, API calls are in non-strict mode
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
see duk_js_executor.c
Convert heap string index to a token (reserved words)
comment: XXX: refactor and share with other code
label: code-design
order must match constants in genbuiltins.py
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Ecmascript compliant [[Delete]](P, Throw).
-> [ ... str ]
args go here in parens
0xb0...0xbf
Write in big endian
only need to guarantee 1 more slot, but allocation growth is in chunks
comment: alloc function typedefs in duktape.h
label: code-design
i >= 0 would always be true
comment: XXX: inline into a prototype walking loop?
label: code-design
Lightfunc handling by ToObject() coercion.
DUK_BUFOBJ_UINT16ARRAY
'else'
'String' object, array index exotic behavior
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
Write unsigned 32-bit integer.
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
[ body formals source template closure ]
no refcount changes
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
First evaluate LHS fully to ensure all side effects are out.
properties object
Call handling and success path. Success path exit cleans
* up almost all state.
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
object is extensible
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
lookup name from an open declarative record's registers
relookup (side effects)
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
x <- y * z
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Catches >0x100000000 and negative values.
* Entry points
* Error built-ins
Packed or unpacked tval
* PC-to-line constants
top-down expression parser
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
fall through
x
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
fast path for ASCII
num_stack_res
%lx
* Not found as concrete or virtual
'Buffer'
[ ... env target target ]
DUK_TOK_LOR
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
triggers garbage digit check below
relevant array index is non-configurable, blocks write
comment: the NaN variant we use
label: code-design
* Compact the function template.
PRIMARY EXPRESSIONS
* indexOf(), lastIndexOf()
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
Automatic error throwing, retval check.
Fast path for the case where the register
* is a number (e.g. loop counter).
always push some string
spare
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
* Heap flags
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
get_value
clear array part flag only after switching
'!'
tv1 points to value storage
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
ascii fast path: avoid decoding utf-8
just in case
entry_top + 4
m- <- (* m- B)
UTC
no valstack space check
End of input (NUL) goes through slow path and causes SyntaxError.
[ ... enum_target res trap_result val ]
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
ptr_curr_pc != NULL only when bytecode executor is active.
Restore entry thread executor curr_pc stack frame pointer.
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
duk_hobject_set_length_zero(thr, func->h_funcs);
fall thru
see above
* Struct defines
[ ... name reg/null ] -> [ ... ]
mandatory if du.d is a NaN
duk_tval ptr for 'func' on stack (borrowed reference)
For tv1 == tv2, this is a no-op (no explicit check needed).
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
local copy to avoid relookups
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
* Hobject Ecmascript [[Class]].
Handle one slow path unit (or finish if we're done).
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
enough to cover the whole mantissa
DUK_TOK_BXOR_EQ
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
repl string scan
[key result] -> [result]
'\xffTracedata'
... and its 'message' from an instance property
AUTHORS.rst
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
prefer jump
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
automatic length update
args
'String'
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
not a vararg function
Shouldn't happen but check anyway.
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
No strs[] pointer.
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
e.g. DUK_OP_PREINCR
eat 'while'
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
input radix
char: use int cast
result
exponent digit
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
defprop_flags
s <- 2
spaces (nargs - 1) + newline
* Parse inner function
if accessor without getter, return value is undefined
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
who resumed us (if any)
out_clamped==NULL -> RangeError if outside range
relookup after possible realloc
[ ... regexp_object escaped_source bytecode ]
m+ <- (* m+ B)
bytecode opcode (or extraop) for binary ops
forget temp
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
absolute position for digit considered for rounding
-> [ ... this timeval_new ]
TypeError if wrong; class check, see E5 Section 15.10.6
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
same thread
'Boolean'
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
* Init the heap thread
XXX: need a duk_require_func_or_lfunc_coerce()
avoid referencing, invalidated
Don't support "straddled" source now.
* Object compaction.
*
* Compaction is assumed to never throw an error.
[ arg1 ... argN this loggerLevel loggerName ]
duk_tval intentionally skipped
* Since built-ins are not often extended, compact them.
* Compilation
Push a new ArrayBuffer (becomes view .buffer)
idx_start
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
may be NULL if no constants or inner funcs
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
empty expressions can be detected conveniently with nud/led counts
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
[ ... val callback thisArg val i obj ]
[ ... this tracedata sep this str1 ... strN ]
important chosen base types
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
must also check refzero_list
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
[ ... func ]
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Trigger at zero or below
Custom coercion for API
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
source ends before dest starts
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
64-bit OK because always >= 0
reg/const for switch value
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
no prototype, updated below
unwind to 'resume' caller
0xf0-0xff
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
1st related value (type specific)
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
Shared object part
always throw ReferenceError for unresolvable
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Shift to sign extend.
'^'
required_desc_flags
comment: Stack indices for better readability
label: code-design
* Try registers
no prototype or class yet
shadowed; update value
E5 Section 8.6.2 + custom classes
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
RELATIONAL EXPRESSION
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
Zero escape (also allowed in non-strict mode)
roughly 64 bytes
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
this is a bit approximate (errors out before max is reached); this is OK
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Convert buffer to result string.
default prototype (Note: 'thr' must be reachable)
we know these because enum objects are internally created
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
1 = num actual 'return values'
should never happen
'-' verbatim
Regexp tokens
avoid attempt to compact the current object
DUK_TOK_TRUE
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
min(incl)
may be equal
traceback depth ensures fits into 16 bits
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
DUK_TOK_GET
* Various
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
trailer
* Check whether we need to abandon an array part (if it exists)
[... env callee]
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
an Ecmascript function
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
end of bytecode
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
must be found: was found earlier, and cannot be inherited
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
shift in zeroes
free object and all auxiliary (non-heap) allocs
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
bytes in dest
stack[0] = regexp
* stack[1] = string
flags
Check for maximum buffer length.
'Thread'
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
Output #2: last component name
tc1 = false, tc2 = false
0
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
0x90-0x9f
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Write to entry part
To use the shared helper need the virtual index.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
LAYOUT 1
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
* Node.js Buffer.isEncoding()
array entries are all plain values
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
XXX: assert 'c' is an enumerator
two special escapes: '\' and '"', other printables as is
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
DUK_USE_AUGMENT_ERROR_THROW
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
comment: Most practical strings will go here.
label: code-design
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-> [ ... lval new_rval ]
sep (even before first one)
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
0x7F is special
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
Signed integers always map to 4 bytes now.
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
estimate is valid
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
always true, arg is unsigned
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
DUK_TOK_DO
* Slow path: potentially requires function calls for coercion
'ArrayBuffer'
Initialize index so that we skip internal control keys.
flags have been already cleared
* ArrayBuffer, DataView, and TypedArray constructors
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
-> [ ... this timeval_new timeval_new ]
DUK_TOK_CONST
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Slot C
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
At least: ... [err]
wrapped
whole or fraction digit
* Constructor calls
only 'length'
DUK_USE_DEBUGGER_DUMPHEAP
'toISOString'
'res' contains expression value
No other escape beginning with a digit in strict mode
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
[key setter this val key] -> [key retval]
point to start of 'reserved area'
Shared helper for match() steps 3-4, search() steps 3-4.
dummy
Just call the "original" Object.defineProperties() to
* finish up.
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
line terminator will be handled on next round
* Debug dumping
x in [2**31, 2**32[
Error path.
if a site already exists, nop: max one label site per statement
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
Start in paused state.
comment: XXX: much to improve (code size)
label: code-design
[ regexp string res_arr ]
range conversion with a "skip"
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
* Regular expression structs, constants, and bytecode defines.
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
DUK_TOK_DEFAULT
[key value] or [key undefined]
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
* Set lexer input position and reinitialize lookup window.
nargs
With lightfuncs, act 'func' may be NULL
return '(?:)'
DUK_USE_REFZERO_FINALIZER_TORTURE
next to use, highest used is top - 1
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
arg2 would be clobbered so reassign it to a temp.
standard behavior, step 3.f.i
avoid degenerate cases, so that (len - 1) won't underflow
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
'let'
* Halt execution helper
1110 xxxx; 3 bytes
ch1 = (r_increment << 8) + byte
variable name reg/const, if variable not register-bound
Cast converts magic to 16-bit signed value
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
entry part size
* Property not found in prototype chain.
function executes in strict mode
'data' is reachable through every compiled function which
* contains a reference.
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
note: long live range
* Object will be kept; queue object back to heap_allocated (to tail)
no change
DUK_USE_ASSERTIONS
force the property to 'undefined' to create a slot for it
Optimized for speed.
comment: prevent multiple in-progress detaches
label: requirement
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
DUK_TOK_THIS
index
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
3-letter log level strings
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
Must prevent finalizers which may have arbitrary side effects.
DUK_EXCEPTION_H_INCLUDED
invalidates h_buf pointer
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
comment: Higher footprint, less churn.
label: code-design
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
core property functions
25%, i.e. less than 25% used -> abandon
Allow empty fraction (e.g. "123.")
0xf0...0xff
don't allow const
this is just beneath bottom
* Duktape.Buffer: constructor
'Uint8Array'
* Helpers for writing multiple properties
exhaustive
refcounting requires direct heap frees, which in turn requires a dual linked heap
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
[ ... error ]
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
parse new token
1e9
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
* Misc shared helpers.
don't set 'n' at all, inherited value is used as name
';'
switch cmd
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
comment: XXX: some overlapping code; cleanup
label: code-design
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
from curr pc
* Maximum size check
isError flag for yield
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
no need to unwind callstack
* Array part
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
[ array totalLength bufres buf ]
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
[r1,r2] is the range
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
duk_handle_call / duk_handle_safe_call recursion depth limiting
DUK_HOBJECT_FLAG_NEWENV: handled below
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
common case, already closed, so skip
ignore millisecond fractions after 3
* unshift()
E5 Section 10.4.3
No built-in functions are constructable except the top
* level ones (Number, etc).
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
Bernstein hash init value is normally 5381
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
expt 0xfff is infinite/nan
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
%s
e.g. "x" < "xx"
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
SameValue
How much stack to require on entry to object/array encode
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
... name ': ' message
to exit
parenthesis count, 0 = top level
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
input string (may be a user pointer)
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
shared helper
* Fast buffer writer with spare management.
success/error path both do this
DUK_TOK_MUL
attempt to change from accessor to data property
allowed ascii whitespace
[ ... source? filename? ]
continue jump
-> [ ... key val ]
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
no need to create environment record now; leave as NULL
* Thread state check and book-keeping.
"/=" and not in regexp mode
for lastIndexOf, result may be -1 (mark immediate termination)
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
requested identifier
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
no return value -> don't replace created value
'Arguments' object and has arguments exotic behavior (non-strict callee)
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
Note: left shift, should mask
31 to 36
two level break
don't allow an empty match at the end of the string
'thr' is now reachable
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
Allow 'Infinity'
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
* Helpers for managing property storage size
if-digit-else-ctrl
Safe write calls which will ensure space first.
having this as a separate function provided a size benefit
code emission
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Debugging related API calls
-> [ ... func this arg1 ... argN _Args length ]
'Float64Array'
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
-> [ this ]
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
retval indicates delete failed
formatters always get one-based month/day-of-month
continue matching, set neg_tzoffset flag
bound function chain has already been resolved
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
standard JSON; array gaps
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
just check 'env'
comment: XXX: primitive to make array from valstack slice
label: code-design
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
consistency requires this
DUK_TOK_CASE
Nothing to initialize, strs[] is in ROM.
currently 6 characters of lookup are actually needed (duk_lexer.c)
index/length check guarantees
left.x1 -> res.x1
* Case conversion tables generated using src/extract_caseconv.py.
is global code
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
Note: not a valid stack index if num_stack_args == 0
* Convenience (independent of representation)
no refcounting
duk_handle_ecma_call_setup: setup for a resume()
escape any non-ASCII characters
if 0, 'str' used, if > 0, 'strlist' used
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
* pop(), push()
'DecEnv'
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
* Writability check
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
DUK_USE_JSON_STRINGIFY_FASTPATH
Update all labels with matching label_id.
guaranteed by duk_to_string()
already declared, must update binding value
DUK_USE_TRACEBACKS
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
ensures callstack_top - 1 >= 0
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
detached
'constructor'
disabled for now
idx_replacer
type to represent a straight register reference, with <0 indicating none
continue jump not patched, an INVALID opcode remains there
-> [ ... enum_target res trap_result ]
current (next) array index
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
'const'
all codepoints up to U+10FFFF
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
if no NaN handling flag, may still be NaN here, but not Inf
thr argument only used for thr->heap, so specific thread doesn't matter
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
[0x00000000, 0xffffffff]
fall through to error
[ ... key_obj key key ]
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
since no recursive error handler calls
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
numeric label_id (-1 reserved as marker)
irrelevant when out->value == NULL
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
DUK_USE_STRTAB_CHAIN
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
assume value is a number
comment: combines steps 3, 6; step 7 is not needed
label: requirement
* Debugger support
comment: XXX: spare handling, slow now
label: code-design
normal and constructor calls have identical semantics
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
Same coercion behavior as for Number.
the outer loop will recheck and exit
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
x == -Infinity
[ ... source? func_template ]
other call
lastIndex already set up for next match
* Macros to access the 'props' allocation.
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
[ ... source? filename? ] (depends on flags)
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
[ targetBuffer targetStart sourceStart sourceEnd ]
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
at least one opcode emitted
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
side effects, in theory (referenced by global env)
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
Allow naked fraction (e.g. ".123")
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
Other longjmp types are handled by executor before propagating
* the error here.
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
* Ecmascript/native function call or lightfunc call
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
computed live
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
callstack limits
A...P
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
Explicit length is only needed if it differs from 'nargs'.
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
(?:
Must be restored here to handle e.g. yields properly.
The base ID of the current require() function, resolution base
non-Reference deletion is always 'true', even in strict mode
jump to next loop, using reg_v34_iter as iterated value
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
max possible
punctuators (unlike the spec, also includes "/" and "/=")
DUK_BUFOBJ_FLOAT32ARRAY
[ ... ptr ]
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
12: getDate
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
'modLoaded'
* Assertions before
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
for zero size, don't push anything on valstack
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
heap level "stash" object (e.g., various reachability roots)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
c recursion check
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
Continue parsing after padding, allows concatenated,
* padded base64.
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
idx_step is +1 for indexOf, -1 for lastIndexOf
is a setter/getter
env created above to stack top
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
DUK_TOK_LNOT
XXX: sufficient to check 'strict', assert for 'is function'
check final character validity
* Init lexer context
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
idx_step is +1 for reduce, -1 for reduceRight
PatternCharacter, all excluded characters are matched by cases above
Note: -nargs alone would fail for nargs == 0, this is OK
curr and desc are accessors
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
func.prototype.constructor = func
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
prev value can be garbage, no decref
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
Stepped? Step out is handled by callstack unwind.
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
fills window
Caller must check character offset to be inside the string.
valstack will be unbalanced, which is OK
conservative
unconditional
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Duktape.modSearch
Set .buffer to the argument ArrayBuffer.
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
flags: ""
-> [ res_obj ]
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
eat '{' on entry
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
resume write to target
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
Else functionality is identical for function call and constructor
* call.
inclusive
Check that 'this' is a duk_hbufferobject and return a pointer to it.
utf-8 continuation bytes have the form 10xx xxxx
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
'-'
hobject management functions
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
'\xffBytecode'
Catch a double-to-int64 cast issue encountered in practice.
* DumpHeap command
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
[ ... buf loop ]
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
x <- y + z
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
[ ... re_obj input bc ]
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
push before advancing to keep reachable
* duk_hthread allocation and freeing.
[ ... pattern flags escaped_source bytecode ]
* Helper for updating callee 'caller' property.
eat 'do'
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
[ source template result ]
25 user flags
also stash it before constructor,
* in case we need it (as the fallback value)
omit print
Unary plus is used to force a fastint check, so must include
* downgrade check.
DUK__FLD_16BIT
comment: should never happen, but be robust
label: code-design
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
comment: XXX: comes out as signed now
label: code-design
flags
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
writable but not deletable
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
[ ... formals ]
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
See: tests/ecmascript/test-spec-bound-constructor.js
guaranteed to succeed
* Define new property
*
* Note: this may fail if the holder is not extensible.
used elements (includes DELETED)
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
-> [ ... key val replacer holder key ]
as is
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
comment: XXX: make this an internal helper
label: code-design
assumed to bottom relative
intentionally empty
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
aaaaaabb bbbbcccc ccdddddd
[[SetPrototypeOf]] standard behavior, E6 9.1.2
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
27: setUTCSeconds
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
no need to unwind catchstack
'Proxy' object
'errCreate'
coerce lval with ToString()
see algorithm
* reverse()
index is above internal buffer length -> property is fully normal
ensure never re-entered until rescue cycle complete
comment: order: most frequent to least frequent
label: code-design
comment: not very useful, used for debugging
label: code-design
catch stack depth
[ ... res_obj ]
* Lexer defines.
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
DUK_BUFOBJ_NODEJS_BUFFER
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
XXX: version specific array format instead?
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
roughly 2 kiB
Must avoid duk_pop() in exit path
basic types from duk_features.h
XXX: byte offset
* instanceof
ecmascript compiler limits
token type
-> [ ... key val replacer ]
call_flags
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Negative indices are always within allocated stack but
* must not go below zero index.
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
Exponent
general temp register
0xe0...0xef
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
[ arg1 ... argN this loggerLevel loggerName buffer ]
duplicate zeroing, expect for (possible) NULL inits
rc_varname and reg_varbind are ignored here
get as double to handle huge numbers correctly
enum_index
XXX: clarify on when and where DUK__CONST_MARKER is allowed
* Error helpers
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
'new'
evaluate to plain value, no forced register (temp/bound reg both ok)
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
DUK_USE_INTERRUPT_COUNTER
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
comment: XXX: could be eliminated with valstack adjust
label: code-design
[key val]
DUK_TOK_CATCH
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
[ ... arg1 ... argN envobj argobj ]
flags:nonstrict
pass2 allocation handles this
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
advance manually
comment: XXX: awkward
label: code-design
target out-of-bounds (but positive)
free some memory
constrained by string length
stable; precalculated for faster lookups
* Thread defines
same handling for identifiers and strings
-> [ ... lval rval rval.prototype ]
'implements'
'='
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
negative top-relative indices not allowed now
'instanceof'
avoid attempt to compact any objects
expression parsing helpers
return ToObject(this)
one token
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
not protected, respect reclimit, is a constructor call
DUK_TOK_BNOT
E5 Section 8.6.1
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
val is unsigned so >= 0
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
must have start and end
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
env and act may be NULL
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
-> [... enum key enum_target key]
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
* Unicode tables
[... obj]
Note: space must cater for both JX and JC.
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
Normal non-bound function.
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
current and previous token for parsing
probe sequence
message is empty -> return name
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
Currently nothing to free; 'data' is a heap object
'prototype'
'jx'
default prototype (Note: 'obj' must be reachable)
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
Unwind the topmost callstack entry before reusing it
internal define property: skip write silently if exists
since new_alloc_size > 0
borrowed, no refcount
allow e.g. '0x0009' and '00077'
DUK_BUFOBJ_DATAVIEW
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
find elements to swap
currently, always the case
* Detected label
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
* Helper macros
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
constants are strings or numbers now
'\n '
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
if (is_regexp)
[ thisArg arg1 ... argN func boundFunc ]
-Infinity
Undefine local defines
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Init built-in strings
* Two's complement arithmetic.
[... constructor arg1 ... argN]
no need to decref previous value
'finally'
Zero size compare not an issue with DUK_MEMCMP.
[ ... closure template val ]
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
may be NULL (but only if size is 0)
write to entry part
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
* Debug connection message write helpers
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
don't want an intermediate exposed state with func == NULL
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
XXX=
separators: space, space, colon
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
Slow path
Lightweight function: never bound, so terminate.
unconditionally; is_global==0
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
string limits
comment: function makes one or more slow path accesses
label: code-design
DUK_USE_AUGMENT_ERROR_CREATE
No need for a NULL/zero-size check because new_size > 0)
Assume value stack sizes (in elements) fits into duk_idx_t.
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
'>'
* Debug connection skip primitives
valstack index of 'func' and retval (relative to entry valstack_bottom)
XXX: array internal?
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
avoid key quotes when key is an ASCII Identifier
embed: nothing
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
* Memory allocation handling.
current assertion is quite strong: decref's and set to unused
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
element type
parsing in "scanning" phase (first pass)
regexp res_obj is at offset 4
Flags for duk_js_compare_helper().
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
no fractions
'Function'
29: setUTCMinutes
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
accept comma, expect new value
-> [ ... reviver holder name val ]
[ ... pattern flags escaped_source buffer ]
reg
empty match -> bump and continue
regexp execution limits
* Single source autogenerated distributable for Duktape 1.5.2.
*
* Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
* Git branch HEAD.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
SCANBUILD: "Dereference of null pointer", normal
catch or with binding is currently active
Note: unbalanced stack on purpose
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
expt values [0x001,0x7fe] = normal
Receiver: Proxy object
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
* Type error thrower, E5 Section 13.2.3.
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
XXX: init or assert catch depth etc -- all values
happens when hash part dropped
1x heap size
no need for decref/incref because value is a number
comment: XXX: this may now fail, and is not handled correctly
label: code-design
[key undefined] -> [key]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
stack top contains 'false'
LAYOUT 2
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
(
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
-> [ sep ToObject(this) len str ]
covered by comparison
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
For now, restrict result array into 32-bit length range.
coerce in-place
DUK_ERR_ASSERTION_ERROR: no macros needed
directive prologue status at entry
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
[ ... num ]
arrays MUST have a 'length' property
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
comment: Inner executor, performance critical.
label: code-design
significant from precision perspective
[ ... Logger clog logfunc clog ]
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
fits into duk_small_int_t
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
is eval code
* Iterate the bitstream (line diffs) until PC is reached
varmap is already in comp_ctx->curr_func.varmap_idx
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
[key setter this val] -> [key retval]
DUK_TOK_LAND
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
Note that multiple catchstack entries may refer to the same
* callstack entry.
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
DUK_HNATIVEFUNCTION_H_INCLUDED
check pointer at end
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
chain jumps for 'fall-through'
* after a case matches.
duk_unicode_ids_noa[]
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
reset longjmp
non-strict equality for buffers compares contents
all codepoints up to U+FFFF
recursion tracking happens here only
roughly 128 bytes
default clause matches next statement list (if any)
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
new value
MULTIPLICATIVE EXPRESSION
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
-> [ ... func this ]
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
caller checks
t has high mantissa
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
DUK_TOK_LCURLY
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
If 'day' is NaN, returns NaN.
* New length not lower than old length => no changes needed
* (not even array allocation).
* API oriented helpers
[enum_target res key true]
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
ADDITIVE EXPRESSION
macros
default case does not exist, or no statements present
* after default case: finish case evaluation
use temp_next for tracking register allocations
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
DUK_REGEXP_H_INCLUDED
comment: XXX: add fastint support?
label: requirement
FOUND
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
initialize for debug prints, needed if sce==NULL
start of valstack allocation
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
-> [ ... enum_target res trap handler target ]
derived types
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Must be a "pointer object", i.e. class "Pointer"
ES6 proxy
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
value of dbg_exec_counter when we last did a Date-based check
idx_retval unsigned
no negative sign for zero
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
looping should never happen
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
digit position is absolute, not relative
c
comment: Same test with volatiles
label: test
because callstack_top > 0
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
%d; only 16 bits are guaranteed
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Since we already started writing the reply, just emit nothing.
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
-> [ ... errhandler undefined(= this) errval ]
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
valid pc range is [0, length[
Current tracedata contains 2 entries per callstack entry.
[ ... errval ]
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
comment: XXX: no need for indirect call
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
valstack
not protected, respect reclimit, not constructor
Push the resulting view object and attach the ArrayBuffer.
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
unbalanced stack
value from hook
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
shared pop
* Struct defs
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: not really necessary
label: code-design
[ ... target ] -> [ ... target keys ]
Leading zero.
','
Make underlying buffer compact to match DUK_BW_GET_SIZE().
first heap allocated, match bit boundary
comment: XXX: more specific error classes?
label: code-design
25: setUTCMilliseconds
* Intermediate value helpers
Limits
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
[ sep ToObject(this) len sep result ]
* Variant 2 or 4
Lightfunc, always success.
step 11.c is relevant only if non-strict (checked in 11.c.ii)
XX==
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
Force exponential format. Used for toExponential().
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
wipe the capture range made by the atom (if any)
Anything else is not constructable.
attrs in E5 Section 15.3.5.1
* Use the index in the header to find the right starting point
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
maximum length of standard format tag that we support
buffer size is >= 1
ignore encoding for now
enable manually for dumping
(?=
require to be safe
Parser part count.
for side effects, result ignored
Now we can check offset validity.
Milliseconds between status notify and transport peeks.
Matching separator index is used in the control table
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
* Stringify implementation.
ToNumber() for a double is a no-op.
default: char escape (two chars)
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
negate result
* Lightfunc
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
Special handling for year sign.
[ arg1 ... argN obj length new_length ]
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
statements go here (if any) on next loop
'yield'
eat trailing comma
pruned
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
lookup results is ignored
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
resume caller must be an ecmascript func
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
errors out if out of memory
stack contains value (if requested), 'out_desc' is set
no issues with empty memcmp()
[str] -> [substr]
func is NULL for lightfunc
property attributes for identifier (relevant if value != NULL)
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
don't allow continue
respect reclimit, not constructor
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
0x60-0x6f
DUK_BUFOBJ_INT32ARRAY
Caller has already eaten the first char so backtrack one byte.
controls for minimum entry part growth
temp accumulation buffer
Unwind.
* Object built-ins
callstack index
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
take last entry
curr is data, desc is accessor
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
* Bitstream decoder
statement id allocation (running counter)
'public'
single match always
Note: 'curr' refers to 'length' propdesc
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
Steps 8-10 have been merged to avoid a "partial" variable.
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
duk_safe_call discipline
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
comment: XXX: encoding is ignored now.
label: code-design
use 'undefined' for value automatically
[ ... obj ... ]
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
Buffer length is bounded to 0xffff automatically, avoid compile warning.
Integer division which floors also negative values correctly.
consequence of above
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
backtrack (safe)
DUK__FLD_32BIT
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
comment: Note: reuse 'curr'
label: code-design
* Convert and push final string.
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
* Selftest code
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Get default hash part size for a certain entry part size.
Maximum number of digits generated.
[ ... func buf ] -> [ ... buf ]
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
e.g. DUK_OP_PREINCV
If neutered must return 0; offset is zeroed during
* neutering.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
breakpoints: [0,breakpoint_count[ gc reachable
comment: XXX: inefficient loop
label: code-design
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
Strings and ROM objects are never placed on the heap allocated list.
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
stack type fits into 16 bits
'set'
low to high
required, NULL implies detached
right associative
covers +Infinity
no size check is necessary
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
comment: XXX: best behavior for real world compatibility?
label: code-design
34: setMonth
20: getSeconds
refcount macros not defined without refcounting, caller must #ifdef now
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
comment: XXX: shared parsing?
label: code-design
Note: reject negative zero.
Delete entry in Duktape.modLoaded[] and rethrow.
already closed
'\xffFormals'
1
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
DUK_TOK_NEQ
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
no shrink
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
* Ecmascript bytecode
Current require() function
[ ... errobj ]
[... arr]
-> [ ... escaped_source ]
func
ignore fclose() error
DUK_TOK_RETURN
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
XXX: to util
Byte length would overflow.
register declarations in first pass
implicit this value always undefined for
* declarative environment records.
match_caps == 0 without regexps
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
* Object finalizer
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
-> [ ... proplist enum_obj key ]
elems in source and dest
E5 Section 15.4.5.1, step 4
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
DUK_USE_ROM_OBJECTS
stats for current expression being parsed
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
DUK_IVAL_XXX
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
* Error, fatal, and panic handling.
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
guaranteed by string limits
Slot A
terminates expression; e.g. post-increment/-decrement
ignore arguments, return undefined (E5 Section 15.3.4)
Thread state.
g...v
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
omit
always >= 0
Fixed buffer, no zeroing because we'll fill all the data.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
terminal type: no depth check
track cpos while scanning
DUK_TOK_SEQ
curr_pc synced by duk_handle_ecma_call_setup()
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
accessor flag not encoded explicitly
For now only needed by the debugger.
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
remove value
* Forward declarations
mm <- mp
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
rethrow
* Accessor macros for function specific data areas
Argument validation and func/args offset.
day number for Jan 1 since epoch
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
compact
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
"123." is allowed in some formats
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
NB: must accept reserved words as property name
no array part
* Misc
error message doesn't matter, ignored anyway
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
Currently nothing to free
comment: Convenience copies from heap/vm for faster access.
label: code-design
Reply with tvals pushed by request callback
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
'index'
index is above internal string length -> property is fully normal
LF line terminator; CR LF and Unicode lineterms are handled in slow path
* Misc helpers
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
bound chain resolved
base
Line format: <time> <entryLev> <loggerName>: <msg>
NEXTENUM jump slot: executed when enum finished
comment: prototype should be last, for readability
label: code-design
comment: XXX: direct implementation
label: requirement
Error codes.
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
* Property lookup
Constants for duk_hashstring().
roughly 1 kiB
advance by one character (code point) and one char_offset
no need to coerce
remove key and value
A regexp token value.
large context; around 2kB now
lexer character window helpers
at index 1
trivial cases
duplicate/invalid key checks; returns 1 if syntax error
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
original target at entry_top - 1
not emitted
comment: XXX: duk_ssize_t would be useful here
label: code-design
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
* Init lexer
'%'
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
DUK_TOK_NUMBER
IEEE exp without bias
31 bits
call handling
not exposed
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
For internal use: get array part value
10xx xxxx -> invalid
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
_Varmap is dense
DUK_TOK_BAND
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
indirect eval
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
* Some assertions (E5 Section 13.2).
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
preincrement and predecrement
Value would normally be omitted, replace with 'null'.
e.g. require('/foo'), empty terms not allowed
string is internal
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
success: leave varname in stack
safe
[ ... closure template len_value ]
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
[ ... func this (crud) retval ]
DUK_USE_DATE_PRS_STRPTIME
comment: Global case is more complex.
label: code-design
max, excl. varargs marker
should be a safe way to compute this
not an error
prev_token slot2
side effects, perform in-place
comment: XXX: turkish / azeri
label: code-design
current variable environment (may be NULL if delayed)
May happen in some out-of-memory corner cases.
* Store lexer position for a later rewind
-> [ ... this timeval ]
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
prev_token slot1
Note1
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
DUK_TOK_IMPORT
* Native call.
input offset tracking
-> [ ... closure template newobj closure ]
fixed arg count: value
chain jumps for case
* evaluation and checking
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
function call
full 3-byte -> 4-char conversions
regexp compilation limits
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
0x00: slow path
* other: as is
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
reject 'in' token (used for for-in)
Data area, fixed allocation, stable data ptrs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
DUK_LEXER_H_INCLUDED
type bit mask: types which certainly produce 'undefined'
XXX: for threads, compact value stack, call stack, catch stack?
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
second, parse flags
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
strict mode restrictions (E5 Section 12.2.1)
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
[ regexp ]
'\xffFinalizer'
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
output is never longer than input during resolution
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Fast path the binary case
* Unicode helpers
comment: XXX: zero assumption
label: code-design
* Assertions after
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
'Math'
1e8: protects against deeply nested inner functions
insert ranges instruction, range count patched in later
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
tc1 = false, tc2 = true
after this, return paths should 'goto finished' for decrement
obj_index
zero-width non-joiner
activation has active breakpoint(s)
Constants for built-in string data depacking.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
start (incl) and end (excl) of trimmed part
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
interpret e.g. '09' as '0', not NaN
* splice()
no argument given -> leave components untouched
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
character represents itself
eat 'return'
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
[ value offset end ]
Relies on NULL encoding to zero.
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
* Compilation and evaluation
Note: Identifier rejects reserved words
-> [ obj trap_result ]
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
caller ensures
* Not found (in registers or record objects). Declare
* to current variable environment.
comment: 'this' binding is not needed here
label: requirement
no need to check callable; duk_call() will do that
mark finalizer work list as reachability roots
Initial '{' has been checked and eaten by caller.
'\xffMap'
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
'NaN'
unsigned 31-bit range
DUK_USE_EXPLICIT_NULL_INIT
valgrind whine without this
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Exposed calls
key encountered as a setter
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
one i_step over
Shared prefix for all buffer types.
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
must restore reliably before returning
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
return 'res_arr' or 'null'
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
break jump
"123"
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
range check not necessary because all 4-bit values are mapped
floor(1.15 * (1 << 10))
expect_eof
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
* Stack constants
call: this.fmt(arg)
Combined step 11 (empty string special case) and 14-15.
w/o refcounting
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
Write fully.
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
object established using Function.prototype.bind()
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
output radix
resume check from proxy target
native function properties
1e8
Lightfunc flags packing and unpacking.
Helpers exposed for internal use
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
assertion omitted
-> [... obj finalizer]
does not fit into an uchar
need to normalize, may even cancel to 0
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
used for array, stack, and entry indices
[ ... name reg_bind ]
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
invalid value which never matches
Arrays never have other exotic behaviors.
0xxx xxxx [7 bits]
[ ... env target ]
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: alloc size in elements
label: code-design
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
note: caller 'sp' is intentionally not updated here
Underlying buffer (refcounted), may be NULL.
actual chars dropped (not just NUL term)
free-form
formals for 'func' (may be NULL if func is a C function)
comment: bytes of indent available for copying
label: code-design
* Valstack manipulation for results.
[obj key desc value get set curr_value varname]
* Add ._Tracedata to an error on the stack top.
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
Lexer context. Same context is used for Ecmascript and Regexp parsing.
comment: XXX: spilling
label: code-design
Note: rely on index ordering
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
NB: duk_lexer_getpoint() is a macro only
dangerous: must only lower (temp_max not updated)
x <- x + y, use t as temp
* Init argument related properties
add BC*2^16
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
char format: use int
Clamping only necessary for 32-bit ints.
maximum size check is handled by callee
-> [ ... val root val ]
Note: start_offset/end_offset can still be < 0 here.
cat_idx catcher is kept, even for finally
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
'fatal'
* Plain, boring reachable object.
value of re_ctx->captures at start of atom
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
pc_label
'configurable'
* Object prototype
'this' binding exists
XXX: direct manipulation, or duk_replace_tval()
fill window
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
* Logging support
[key result]
unchanged by Duktape.Thread.resume()
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
Return 1: got EOM
include removed: duk_internal.h
NOTE: length may be zero
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
Alignment guarantee
!DUK_USE_PREFER_SIZE
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* Mark the heap.
silence scan-build warning
varname is popped by above code
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
Decode failed.
* Init stringcache
[... constructor arg1 ... argN final_cons]
comment: XXX: lithuanian, explicit dot rules
label: code-design
XXX: similar coercion issue as in DUK_TOK_PERIOD
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
source out-of-bounds (but positive)
'with' binding has no catch clause, so can't be here unless a normal try-catch
second incref for the entry reference
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
Get.
DUK_TOK_PRIVATE
randomized pivot selection
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
These are not needed when only Duktape.Buffer is supported.
duk_hobject specific fields.
[val] -> []
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
* Shared exit path
force_exponential
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
DUK_INVALID_INDEX won't be accepted as a valid index.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
DUK_USE_BUFFEROBJECT_SUPPORT
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
string hash
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
0 = no update
regexp opcodes
'function'
recursion limit
utf-8 validation ensures these
count, not including sep
string data is external (duk_hstring_external)
currently paused: talk with debug client until step/resume
duk_concat() coerces arguments with ToString() in correct order
2 to 11
guaranteed to finish
const flag for B
one i_step added at top of loop
'res' may be NULL if new allocation size is 0.
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
thread
assume PC is at most 32 bits and non-negative
1 0 <2 bits>
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
NULL obj->p is OK
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
Assume that thr->valstack_bottom has been set-up before getting here.
len: 9
* E5 Section 11.4.9
deal with weak references first
duk_push_sprintf constants
negative: dst info not available
topmost element is the result array already
Fast path, handle units with just actual encoding characters.
out of spec, must be configurable
* Debug logging after adjustment.
* Pushers
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
implicit_return_value
XXX: direct valstack write
[ ... source? filename ]
No resize has occurred so temp_desc->e_idx is still OK
lookup for 0x000a above assumes shortest encoding now
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
true, despite side effect resizes
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
[ start end str ]
source is eval code (not global)
switch initial byte
Note: pc is unsigned and cannot be negative
* Casting
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
Longjmp handling has restored jmpbuf_ptr.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
-> [ ... varname val this ]
processed one or more messages
[ ... v1(filename) v2(line+flags) ]
must have been, since in array part
slower but more compact variant
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
comment: parameter passing, not thread safe
label: requirement
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
Note: decimal number may start with a period, but must be followed by a digit
main reachability roots
DUK_HBUFFER_H_INCLUDED
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
placed in duk_heaphdr_string
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
'private'
toJSON() can also be a lightfunc
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
move pivot out of the way
final configuration
-1 == not set, -2 == pending (next statement list)
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
NB: 'length' property is automatically updated by the array setup loop
index for next new key ([0,e_next[ are gc reachable)
idx is unsigned, < 0 check is not necessary
indirect opcode follows direct
* toFixed(), toExponential(), toPrecision()
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
follow prototype chain
[ value ]
XXX: incref by count (here 2 times)
equals
true even with reattach
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
numeric value of a hex digit (also covers octal and decimal digits)
DUK_TOK_MUL_EQ
DUK_USE_DEBUG
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
0x00: finish (non-white)
* 0x01: continue
%lu
[ ... arg1 ... argN ]
executor interrupt running (used to avoid nested interrupts)
[ ... func this ]
Constants: variable size encoding.
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
no res->strs[]
* Debug dumping of duk_heap.
Detach a debugger if attached (can be called multiple times)
* safely.
if 1, doing a string-to-number; else doing a number-to-string
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
* duk_hbuffer allocation and freeing.
stash to bottom of value stack to keep new_env reachable for duration of eval
step 4.a
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
exports
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
comment: XXX: use duk_is_valid_index() instead?
label: code-design
eat closing bracket
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* The switch statement is pretty messy to compile.
* See the helper for details.
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
first value: comma must not precede the value
actually used, non-NULL keys
r <- (2 * b) * f
[ ... re_obj input bc saved_buf res_obj ]
* Create wrapper object and serialize
t1 <- t1 - s
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
112.5%, i.e. new size less than 12.5% higher -> fast resize
* URI handling
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
32-bit value
string intern table (weak refs)
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
Convert indices to byte offsets.
'l'
Fast path: source is a TypedArray (or any bufferobject).
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
'var'
[ args(n) [crud] formals arguments map mappednames ]
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
'pointer'
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
DUK_UNICODE_H_INCLUDED
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
end of valstack allocation (exclusive)
previous value is assumed to be garbage, so don't touch it
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
comment: suppress warning, not used
label: code-design
Buffer/string -> compare contents.
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
finished jump
string is ASCII, clen == blen
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
* Copy array elements to new array part.
For strings, special form for short lengths.
Setup function properties.
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
* Utilities
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
comment: XXX: 'copy properties' API call?
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
'{_func:true}'
prediction: portable variant using doubles if 64-bit values not available
[ ... arr val ]
Casting convenience.
The stack has a variable shape here, so force it to the
* desired one explicitly.
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
Object.getOwnPropertyNames
'undefined'
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
Overestimate required size; debug code so not critical to be tight.
comment: no special formatting
label: code-design
proplist is very rare
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
DUK_USE_JC
function refers to 'arguments' identifier
don't want an intermediate exposed state with invalid pc
Use loop to minimize code size of relookup after bound function case
'Undefined'
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
if abandon_array, new_a_size must be 0
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
pointer is aligned, guaranteed for fixed buffer
See MPUTOBJ comments above.
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
'\xffPc2line'
comment: XXX: better coercion
label: code-design
guaranteed to finish, as hash is never full
shared flags for a subset of types
nothing to incref
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
unpack args
hash lookup
* Cleanup: restore original function, restore valstack state.
don't touch property attributes or hash part
Note: duk_uint8_t type yields larger code
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
return arg as-is
NULL accepted
Lightfunc, not blamed now.
0 = no throw
comment: XXX: macros
label: code-design
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
maximum recursion depth for loop detection stacks
us
[ ... holder name val ]
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
* Init arguments properties, map, etc.
comment: NUL terminator handling doesn't matter here
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
keep in on valstack, use borrowed ref below
[ ... Logger clog logfunc clog(=this) msg ]
-> [ ... func this arg1 ... argN _Args ]
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
compiler's responsibility
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
func is NULL for lightfuncs
shared exit path now
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
-> [ O toIsoString O ]
* Finish
-> [ timeval this timeval ]
cached: valstack_end - valstack (in entries, not bytes)
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
* Bitstream encoder.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
IdentifierStart production with ASCII and non-BMP excluded
temp object for tracking / detecting duplicate keys
negative
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
DUK_BUFOBJ_INT8ARRAY
DUK_USE_ROM_STRINGS
get pointer offsets for tweaking below
Note: not normalized, but duk_push_number() will normalize
NULL if not an object
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
XXX: could add fast path for u8 compatible views
Note2
'resume'
should never happen for a strict callee
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
[... env]
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
'export'
DUK_ERR_URI_ERROR: no macros needed
array case is handled comprehensively above
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
force_no_namebind
DUK_TOK_NEW
* Breakpoint and step state checks
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
global object doesn't have array part
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
comment: XXX: specific getter
label: code-design
[ ... escape_source bytecode ]
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
lastIndex is initialized to zero by new RegExp()
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
>>>
[ ... closure template formals ]
inherit
filename being compiled (ends up in functions' '_filename' property)
filter out flags from exprtop rbp_flags here to save space
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
prop index in 'array part', < 0 if not there
caller handles sign change
comment: load factor too low or high, count actually used entries and resize
label: code-design
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
make the new thread reachable
XXX: print built-ins array?
temp reg
* Externs and prototypes
no incref
Test signaling NaN and alias assignment in all endianness combinations.
1 GB
XXX: fast path for array arguments?
-> [ ... new_global new_globalenv new_global new_global ]
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
DUK_USE_PACKED_TVAL
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
values for the state field
How large a loop detection stack to use
pop enum
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
<
[ ... closure template undefined ]
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
dynamic buffer ops
not found in 'curr', next in prototype chain; impose max depth
13: getUTCDate
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
[ ... this name ]
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
comment: XXX: check flags
label: requirement
ASCII (and EOF) fast path -- quick accept and reject
0xc0...0xcf
'-' as a range indicator
-> [ ... enum_target res handler undefined target ]
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
"123.456"
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
'false'
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
data property or accessor without getter
* Args validation
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
* String built-ins
* Clear (reachable) flags of refzero work list.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
catchstack
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
Call sites don't need the result length so it's not accumulated.
non-zero: make copy
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
fromPresent = false
Check that there's room to push one value.
comma check
backtrack to last output slash (dups already eliminated)
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Flags for call handling.
jump to end
* RegExp built-ins
allocation size
no -> decref members, then free
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
XXX: C recursion limit if proxies are allowed as handler/target values
try part
'caller' must only take on 'null' or function value
sign doesn't matter when writing
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
comment: unused
label: code-design
* Other file level defines
Fast path for numbers (one of which may be a fastint)
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
[enum_target enum res]
orig value
comment: XXX use get tval ptr, more efficient
label: code-design
See comments in duk_pcall().
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
A bit tricky overflow test, see doc/code-issues.rst.
key must not already exist in entry part
Digit generation
reset function state (prepare for pass 2)
+0 = catch
avoid side effects!
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
duk_small_uint_fast_t c = DUK_DEC_C(ins);
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
comment: No coercions or other side effects, so safe
label: requirement
0x20-0x2f
may become sparse...
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
XXXXXX--
lightfuncs are treated like objects and not coerced
jump to end or else part
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
for duk_error_augment.c
just one 'int' for C++ exceptions
'~'
reset voluntary gc trigger count
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
* Defines for JSON, especially duk_bi_json.c.
* Fast path tables
-> [ ... handler trap ]
DUK_TOK_ALSHIFT_EQ
Note: assumes 'data' is always a fixed buffer
* Stringtable entry for fixed size stringtable
sometimes stack and array indices need to go on the stack
hash size ratio goal, must match genhashsizes.py
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
Require a lot of stack to force a value stack grow/shrink.
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
DUK_DEBUG_H_INCLUDED
input size is good output starting point
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: Should never happen but avoid infinite loop just in case.
label: code-design
unchanged from Duktape.Thread.yield()
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
Negative offsets cause a RangeError.
side effect free
main expression parser function
may happen if size is very close to 2^32-1
fail: restore saves
DUK_USE_DATE_PRS_GETDATE
needed for stepping
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
clen == blen -> pure ascii
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
current setjmp() catchpoint
Result is undefined.
[ ... proplist ]
This may throw an error though not for valid E5 strings.
* Marking functions for heap types: mark children recursively
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
XXX: set with duk_hobject_set_length() when tracedata is filled directly
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
Slow path.
'compile'
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
DUK_TOK_RCURLY
comment: XXX: check .caller writability?
label: code-design
replacement handler
2**31-1 ~= 2G properties
part of string
Bytecode instructions: endian conversion needed unless
* platform is big endian.
DUK_TOK_EXTENDS
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
fastint downgrade check for return values
comment: bytes of indent still needed
label: code-design
DUK_JS_COMPILER_H_INCLUDED
nop
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
Double error
* Valstack spare check
This would be pointless: unexpected type and lightfunc would both return NULL
For internal use: get non-accessor entry value
trailing comma followed by rcurly
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
[... value this_binding]
DUK_TOK_INCREMENT
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
insert code for matching the remainder - infinite or finite
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
* Fast paths
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
truncate towards zero
37: setUTCFullYear
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
* Assert helpers
resume lookup from target
comment: XXX: assume these?
label: code-design
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
standard prototype
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
flags: "gm"
no need to decref, as previous value is 'undefined'
may need unwind
catch part will catch
-> [ ... name index ]
* Node.js Buffer: toString([encoding], [start], [end])
* Ecmascript compiler.
Allow fraction part
explicit 'this' binding, see GH-164
Initial bytecode size allocation.
XXX: patch initial size afterwards?
already zero
late lookup, avoid side effects
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
match against rule part/sep bits
'd' and 'res' agree here
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
Eval code doesn't need an automatic .prototype object.
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
never here
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
Note that 'l' and 'r' may cross, i.e. r < l
For internal use: get non-accessor entry value and attributes
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
DUK_USE_JSON_EATWHITE_FASTPATH
valstack top, should match before interpreting each op (no leftovers)
may be NULL if alloc_size == 0
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
110x xxxx; 2 bytes
if num_values > 0, MPUTARR emitted by outer loop after break
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
Not enough data.
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
DUK_TOK_STRING
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ ... env ]
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
* Reallocate memory with garbage collection
comment: XXX: unnecessary translation of flags
label: code-design
Explicit check for fastint downgrade.
default attrs ok
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
comment: There may be whitespace between the equal signs.
label: code-design
comment: Note: first argument not really used
label: code-design
* Function declarations
reg_res should be smallest possible
Slot B
* Unreachable object, free
Specific assumptions for opcode numbering.
comment: copied so that 'ap' can be reused
label: code-design
exponents 1023 to 1069
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
(?!
name
Restart bytecode execution, possibly with a changed thread.
-> [ ... func name ]
top of current frame (exclusive)
if thisArg not supplied, behave as if undefined was supplied
for side effects
comment: XXX: match flag is awkward, rework
label: code-design
fall through and continue for-loop
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
assume 0 <=> NULL
skip leading digit
B -> object register
* C -> C+0 contains key, C+1 closure (value)
caller guarantees
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
at least this function exists
hash part is a 'weak reference' and does not contribute
'pc'
'errThrow'
DUK_TOK_SUPER
This is guaranteed by debugger code.
[... (sep) str1 str2 ... strN buf]
0: no change
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
reg(ignored)
undefined coerces to zero which is correct
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
returned after EOF (infinite amount)
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
Unwind catchstack entries referring to the callstack entry we're reusing
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
e.g. DUK_OP_POSTINCR
'Uint8ClampedArray'
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
no typedef
[ ... func_template ]
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
[ arg1 ... argN obj length ]
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
comment: unused with some debug level combinations
label: code-design
Line number range for function. Needed during debugging to
* determine active breakpoints.
comment: slow init, do only for slow path cases
label: code-design
DUK_BUFOBJ_DUKTAPE_BUFFER
positive
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
e.g. DUK_OP_PREINCP
DUK_JS_H_INCLUDED
DUK_USE_DATE_NOW_WINDOWS
!DUK_SINGLE_FILE
this is added to checks to allow for Duktape
* API calls in addition to function's own use
[ ... key_obj key ]
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
is_setget
flags always encodes to 1 byte
Ensure space for 1:1 output plus one escape.
[ ... obj key value ]
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
C array of duk_labelinfo
comment: XXX: double evaluation for 'tv' argument.
label: code-design
with stack depth (affects identifier lookups)
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Detect recursive invocation
comment: known to be 32-bit
label: code-design
* Directive prologue tracking.
Handle lightfuncs through object coercion for now.
exponent 0
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
duk_handle_ecma_call_setup: setup for a tail call
match: keep wiped/resaved values
E5 Section 11.7.2, steps 7 and 8
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
heap thread, used internally and for finalization
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
For now all calls except Ecma-to-Ecma calls prevent a yield.
If tv1==tv2 this is a NOP, no check is needed
Dispatch loop.
DUK_TOK_SUB
Shared Windows helpers.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
catches EOF and invalid digits
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
* Call the constructor function (called in "constructor mode").
minimum prime
set by atom case clauses
[ ... error func fileName ]
reset callstack limit
right paren eaten
'['
idx_desc
E5 Section 11.7.1, steps 7 and 8
coerced value is updated to value stack even when RangeError thrown
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
Expression_opt
Exact halfway, round to even.
* Arguments check
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
name is empty -> return message
* Rescue or free.
grow by at most one
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
Note: proxy handling must happen before key is string coerced.
DUK_HBUFFEROBJECT_H_INCLUDED
[... res]
Note: unconditional throw
DUK_ERRMSG_H_INCLUDED
Neutered buffer, zero length seems
* like good behavior here.
no mark-and-sweep gc
* DUK_BSWAP macros
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
loggerName
will result in undefined
DUK_TOK_QUESTION
* Delayed initialization only occurs for 'NEWENV' functions.
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
Load constants onto value stack but don't yet copy to buffer.
[ hobject props enum(props) key desc ]
'Float32Array'
eat comma
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
Commands and notifys initiated by Duktape.
DUK_TOK_GT
* Stringtable
offset is now target of the pending split (right after jump)
U+03A3 = GREEK CAPITAL LETTER SIGMA
always 0 args
exit bytecode executor by rethrowing an error to caller
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
initialize built-ins - either by copying or creating new ones
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
IsAccessorDescriptor(desc) == true
avoid issues with relocation
avoid recursive string table call
res.x1 -> res.x2
-> [ ... x y fn ]
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
LHS is already side effect free
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
object has an array part (a_size may still be 0)
0x20...0x2f
eat dup slashes
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
initial estimate based on format string
enable exotic behaviors last
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
[ obj key desc ]
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
[... env callee varmap key val]
currently required
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
(flags<<32) + (line), flags = 0
insert range count
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
[ ... new_glob new_env ]
Count actually used (non-NULL, non-DELETED) entries.
no refcount check
Parse statements until a closing token (EOF or '}') is found.
duk_hthread_callstack_unwind() will decrease this on unwind
Note: array dump will include elements beyond
* 'length'.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
size stored in duk_heaphdr unused flag bits
genbuiltins.py ensures
-> [ ... val' ]
CR LF again a special case
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
Full, aligned 4-byte reads.
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
* Zero the struct, and start initializing roughly in order
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
duk_unicode_idp_m_ids_noa[]
mark-and-sweep is currently running
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
DUK_API_INTERNAL_H_INCLUDED
'\xffTarget'
FUNCTION EXPRESSIONS
0x50-0x5f
Note: there is no standard formatter for function pointers
default: no change
internal type tag
* Ecmascript bytecode executor.
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
p points to digit part ('%xy', p points to 'x')
the compressed pointer is zeroed which maps to NULL, so nothing to do.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
bottom of current frame
Shared offset/length coercion helper.
E5 Section 15.10.2.11
'writable'
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
internal spare
value (error) is at stack top
input byte length
gap (if empty string, NULL)
[ args [crud] arguments ]
lightfunc
higher value conserves memory; also note that linear scan is cache friendly
comment: XXX: to be implemented?
label: code-design
comment: XXX: convert to fixed buffer?
label: code-design
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Assume arrays are dense in the fast path.
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
* Value stack top handling
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
x <= y --> not (x > y) --> not (y < x)
[key setter this val]
little endian
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
* Misc util stuff
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
Node.js return value for failed writes is offset + #bytes
* that would have been written.
NaN sign bit is platform specific with unpacked, un-normalized NaNs
comment: XXX: union would be more correct
label: code-design
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
'stack'
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
".123"
currently used -> new size
caller is responsible for ensuring this
must be signed
uppercase
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
comment: XXX: optimize this filling behavior later
label: code-design
replaced
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
[ ... regexp input ] -> [ res_obj ]
Mostly API and built-in method related
E5 Sections 15.9.3.1, B.2.4, B.2.5
alloc and init
prediction corrections for prime list (see genhashsizes.py)
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
DUK_USE_REGEXP_SUPPORT
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
* Interrupt counter fixup (for development only).
Note: recursive call
maximum bytecode length in instructions
get const for value at valstack top
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
line tracking
first call
* All done
undefined is accepted
* Wrap up
this case can no longer occur because refcount is unsigned
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
reachable through activation
[ ... filename &comp_stk ]
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
+ 1 for rounding
note: any entries above the callstack top are garbage and not zeroed
must be, since env was created when catcher was created
side effects (currently none though)
DUK_BUILTIN_PROTOS_H_INCLUDED
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
shadowed, ignore
'Uint16Array'
-> [ ... enum_target res ]
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
+1 = one retval
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
[ ... obj key val ]
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
idx_value may be < 0 (no value), set and get may be NULL
numeric value (character, count)
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
assume 'var' has been eaten
empty separator can always match
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
coerce to string
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
no check
comment: XXX: optimize to 16 bytes
label: code-design
* Endian conversion
nrets
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
embed: integer value
0=base, 1=esc, 2=class, 3=class+esc
XXX: proper flags?
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
some assertions
array writes autoincrement length
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
reserved words: keywords
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
[... env callee varmap]
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
[ body formals source template ]
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
num args starting from idx_argbase
caller must change active thread, and set thr->resumer to NULL
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
unary plus
* Shortcut for accessing global object properties
* slice()
may be changed
step 3.e: replace 'Desc.[[Value]]'
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
[ ... varmap ]
* Type checking
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
Grow array part for a new highest array index.
no need to mask idx portion
remove hash entry (no decref)
index
exclusive endpoint
Append bytes from a slice already in the buffer.
this also increases refcount by one
whole, won't clip
[ source template ]
Cannot overlap.
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
apparently no hint?
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
XXX: clumsy sign extend and masking of 16 topmost bits
Note: no key on stack
[... retval]
DUK_USE_JX
num args
end of _Formals
no need to pop, nothing was pushed
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
2 when called by debugger
* Top level wrappers
DUK_INTERNAL_H_INCLUDED
Report next pc/line to be executed.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
fixed offsets in valstack
* Math built-ins
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
check that there is space for at least one new entry
0xa0...0xaf
eval left argument first
-> [ ... closure template ]
1 << 52
must match genhashsizes.py
setter and/or getter may be NULL
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
current thread
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
Duktape.Thread.yield() should prevent
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
LICENSE.txt
[ ... varname val ]
string is 'eval' or 'arguments'
* The default property attributes are correct for all
* function valued properties of built-in objects now.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
IdentifierStart production with ASCII excluded
nothing to mark
comment: XXX: function properties
label: code-design
prepend regexp to valstack 0 index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
convenience
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
[obj key value desc]
stmt has non-empty value
-> [ ... holder name val val ToString(i) ]
stage 2: delete configurable entries above target length
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
keep key reachable for GC etc; guaranteed not to fail
generate mantissa with a single leading whole number digit
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Stored in duk_heaphdr unused flags.
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
terminator
DUK_TOK_EQUALSIGN
* Comparison
DUK_JSON_H_INCLUDED
may have side effects
increases key refcount
on first round, skip
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
comment: XXX: solve into closed form (smaller code)
label: code-design
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
must be signed for loop structure
is_extra
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
Here 'x' is a Unicode codepoint
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
"-123456\0"
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
curr value
These are for rate limiting Status notifications and transport peeking.
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
DUK_USE_LEXER_SLIDING_WINDOW
DUK_TOK_NULL
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
-> [... obj value]
[ key trap_result ] -> []
replace in stack
(maybe) truncated
nothing to process
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
knock back "next temp" to this whenever possible
* Detected a directive
'for'
complete the millisecond field
'lt is true'
Pre/post inc/dec for register variables, important for loops.
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Iteration solution
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Helper tables
'this'
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
approximate
Avoid NaN-to-integer coercion as it is compiler specific.
Reset to zero size, keep current limit.
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
callback for indirect reallocs, request for current pointer
[ ... this ]
* Portable 12-byte representation
avoid multiple computations of flags address; bypasses macros
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
must not truncate
prefix matches, lengths matter now
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
* Replace valstack top with case converted version.
Shuffle decision not changed.
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
numeric value of token
[... constructor arg1 ... argN] -> [retval]
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
temps
'Object'
not strictly necessary
IsDataDescriptor(desc) == true
POSTFIX EXPRESSION
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
'Error'
* Flags for __FILE__ / __LINE__ registered into tracedata
Count actually used entry part entries (non-NULL keys).
DUK_TOK_ARSHIFT
comment: XXX: possibly incorrect handling of empty expression
label: code-design
used entries + approx 100% -> reset load to 50%
'\xffRegbase'
is_decl
but don't allow leading plus
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
[ ... holder name val enum obj_key val obj_key ]
lj.value1 is already set
number of arguments allocated to regs
Optimized for size.
* Default fatal error handler
named "arithmetic" because result is signed
Default implicit return value.
lookup name from current activation record's functions' registers
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
max # of key-value pairs initialized in one MPUTOBJ set
unicode code points, window[0] is always next
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
thread not currently running
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
[... key arg1 ... argN]
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
Chop extra retvals away / extend with undefined.
MPUTARR emitted by outer loop
comment: XXX: fastint?
label: code-design
compact the exports table
Code is not accepted before the first case/default clause
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
-> [ ... key val replacer holder key val ]
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
No debugger support.
'<'
treat like property not found
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
Carry is detected based on wrapping which relies on exact 32-bit
* types.
eat (first) input slash
value resides in a register or constant
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
Overflow, relevant mainly when listlen is 16 bits.
[ ... val ] --> [ ... enum ]
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
case 0: nop
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
Error: try coercing error to string once.
for resizing of array part, use slow path
y == -Infinity
Initialization and finalization (compaction), converting to other types.
must match exactly the number of internal properties inserted to enumerator
required
+ spare
All element accessors are host endian now (driven by TypedArray spec).
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
must "goto restart_execution", e.g. breakpoints changed
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
23: getUTCMilliseconds
no need to normalize
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
'this binding' is just under bottom
Default exports table
comment: XXX: macro smaller than call?
label: code-design
XXX: assert? compiler is responsible for this never happening
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
'require'
* Assertion helpers
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
19: getUTCMinutes
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
duk__get_min_grow_e() is always >= 1
* Reachable object, keep
'eval'
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
resolved id: require(id) must return this same module
We rely on a few object flag / class number relationships here,
* assert for them.
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
DUK_HEAP_H_INCLUDED
note: original, uncoerced base
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
DUK_OP_NONE marks a 'plain' assignment
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
Stack size decreases.
heap->strs: not worth dumping
-> [ ... closure template env funcname closure ]
step 12
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
comment: XXX: duk_ssize_t
label: code-design
DUK_ERR_UNCAUGHT_ERROR: no macros needed
-> [ ToObject(this) item1 ... itemN arr ]
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
* Debug dump type sizes
needed for line number tracking (becomes prev_token.start_line)
don't coerce yet to a plain value (variant 3 needs special handling)
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
Read value pushed on stack.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
'null' enumerator case -> behave as with an empty enumerator
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
Current compiler state (if any), used for augmenting SyntaxErrors.
push to stack
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'catch'
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
curr_pc synced back above
hash size approx. 1.25 times entries size
Write in little endian
source starts after dest ends
comment:
* Debugging macro calls.
label: code-design
DUK_USE_VERBOSE_ERRORS
0xxx xxxx -> fast path
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
unsigned shift
Not a very good provider: only full seconds are available.
110x xxxx 10xx xxxx [11 bits]
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
ensure value is 1 or 0 (not other non-zero)
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Indicate function type in the function body using a dummy
* directive.
'ObjEnv'
lj.value1 already set
millisec -> 100ns units since jan 1, 1970
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
DUK_TOK_SWITCH
class Object, extensible
idx_end
_Source
1 1 0 <8 bits>
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
minimum new length is highest_arr_idx + 1
DUK_TOK_RBRACKET
property is configurable and
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
Caller must ensure 'tv' is indeed a double and not a fastint!
Caller has already eaten the first character ('|') which we don't need.
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
structs from duk_forwdecl.h
assumed to also be PC of "LABEL"
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
'{"_undef":true}'
DUK_TOK_ADD_EQ
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
remove the original 'template' atom
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
* Heap native function representation.
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
'Invalid Date'
dynamic
comment:
* Node.js Buffer.concat()
label: code-design
comment: XXX: substring in-place at idx_place?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
embed: 0 or 1 (false or true)
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
string 2 of token (borrowed, stored to ctx->slot2_idx)
UNARY EXPRESSIONS
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
should actually never happen, but check anyway
input offset for window leading edge (not window[0])
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
continuation byte
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
ASCII fast path
Most input bytes go through here.
-> [ ... holder name val ]
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
useful for debugging
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
We should never exit the loop above.
may have FINALIZED
LAYOUT 3
comment: unused
label: code-design
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
'Int32Array'
an error handler (user callback to augment/replace error) is running
without refcounts
arbitrary marker, outside valid exp range
extra -1 for buffer
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
[ ...val ] -> [ ... ]
allow empty expression
[ ... closure template name ]
# total registers target function wants on entry (< 0 => "as is")
comment: unnecessary shift for last byte
label: code-design
varenv remains reachable through 'obj'
Special coercion for Uint8ClampedArray.
valstack slot for temp buffer
* Node.js Buffer: constructor
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
Nothing worked -> not equal.
E5 Section 11.13.1 (and others for other assignments), step 4.
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
String and buffer enumeration behavior is identical now,
* so use shared handler.
37x32 = 1184 bits
heap->dbg_detached_cb: keep
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
[ ... key ] -> [ ... ]
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
mark range 'direct', bypass canonicalization (see Wiki)
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
return module.exports
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
control props
push value to stack
* shift()
k+argCount-1; note that may be above 32-bit range
* Assert macro: failure causes panic.
comment: Similar workaround for INFINITY.
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
number
Must be element size multiple from
* start offset to end of buffer.
empty ("") is allowed in some formats (e.g. Number(''), as zero
slow path is shared
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
-> [ ... func ]
* Various defines and file specific helper macros
no net exponent
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
11 bits
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
get before side effects
DUK_HSTRING_H_INCLUDED
avoid empty label at the end of a compound statement
no specific action, resume normal execution
for manual torture testing: tight allocation, useful with valgrind
XXX: skip count_free w/o debug?
everything except object stay as is
identifiers and environment handling
back to fast loop
DUK_USE_JX || DUK_USE_JC
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
is resume, not a tail call
* Basic stack manipulation: swap, dup, insert, replace, etc
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
strings may have inner refs (extdata) in some cases
class masks
keep label catcher
state updated, restart bytecode execution
Flags for duk_js_equals_helper().
[ ... func this <some bound args> arg1 ... argN _Args ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
DUK_USE_TAILCALL
comment: should never be called
label: code-design
denormal
-> loop body
note: this updates refcounts
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
t1 <- (+ r m+)
denormal or zero
mark-and-sweep control
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
DUK_TOK_LET
Remove a slice from inside buffer.
valstack slot for 2nd token value
one-based -> zero-based
Set .buffer
terminate
max size: radix=2 + sign
remaining actual steps are carried out if standard DefineOwnProperty succeeds
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
'{"_func":true}'
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
E5 Section 15.5.5.2
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
avoid calling write callback in detach1()
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
-> [ Object res ]
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
IdentifierStart production with Letter and ASCII excluded
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
end switch
DUK_TOK_LE
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
[ ... v1(func) v2(pc+flags) ]
Matches both +0 and -0 on purpose.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
start line of token (first char)
10: getMonth
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
x <- y
eat 'var'
cannot have >4G captures
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
normalize NaN which may not match our canonical internal NaN
Recompute argument count: bound function handling may have shifted.
[ ... key val ] -> [ ... ]
minval
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
DUK_TOK_ARSHIFT_EQ
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
* Pass 1
Use unsigned arithmetic to optimize comparison.
type and control flags, label number
DUK_TOK_RSHIFT_EQ
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
[ ... enum_target res trap_result ]
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
Automatic filename: 'eval' or 'input'.
cumulative opcode execution count (overflows are OK)
Fast path for fastints
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
'input'
countdown state
switch
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Shared exit handling for object/array serialization.
input string scan
as elements
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
no need to unwind
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
Strict functions don't get their 'caller' updated.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
currently nop
[ ... closure template ]
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
'func' on stack (borrowed reference)
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
-> [... val this]
comment: code emission temporary
label: code-design
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
(quotient-remainder (* r B) s) using a dummy subtraction loop
Note: either pointer may be NULL (at entry), so don't assert
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
reuse last emitted atom for remaining 'infinite' quantifier
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
* Dragon4 slow path digit generation.
Rule control flags.
USE_PROP_HASH_PART
don't compact objects; needed during object property allocation resize
r <- (remainder (* r B) s)
[ ... error arr ]
String is an own (virtual) property of a lightfunc.
16: getHours
'debugger'
* String manipulation
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
DUK_USE_DEBUGGER_INSPECT
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
comment: Process debug messages until we are no longer paused.
label: code-design
* Entries part
[in_val in_val]
DUK_TOK_LBRACKET
36 bits
for zero size allocations NULL is allowed
-> [... obj key value]
* Some change(s) need to be made. Steps 7-11.
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
end of diff run
* Buffer
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
XXX: stringtable emergency compaction?
thr->ptr_curr_pc is set by bytecode executor early on entry
Allow leading plus sign
if slice not fully valid, treat as error
Now two entries in the same slot, alloc list
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
thr->heap->lj.value1 is already the value to throw
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
* Because buffer values are often looped over, a number fast path
* is important.
starting line number
x <- x - y, use t as temp
EQUALITY EXPRESSION
* Unicode support tables automatically generated during build.
return thread
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
0x08583b00
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
not a wordchar
XXX: a "first" flag would suffice
reg count
Buffer used for generated digits, values are in the range [0,B-1].
assume memset with zero size is OK
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
Parse a number, other than NaN or +/- Infinity
Must be a "string object", i.e. class "String"
no decref needed for a number
[ ... | (crud) ]
x <- y - z, require x >= y => z >= 0, i.e. y >= z
26 bits
Used to support single-byte stream lookahead.
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
-> [ ToObject(this) ]
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
'\Udeadbeef'
* every(), some(), forEach(), map(), filter()
Test without volatiles
Lexer codepoint with additional info like offset/line number
Low memory options
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
Note: either pointer may be NULL (at entry), so don't assert.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
tail call -> reuse current "frame"
refcount is unsigned, so always true
work list for objects to be finalized (by mark-and-sweep)
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
comment: still in use with verbose messages
label: code-design
stack is unbalanced, but: [ <something> buf ]
parse ranges until character class ends
Note: buffer is dynamic so that we can 'steal' the actual
* allocation later.
'delete'
comment: unused now, not needed until Turkish/Azeri
label: requirement
No platform-specific parsing, this is not an error.
mark finalizable as reachability roots
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
ToUint32() coercion required
'global'
not popped by side effect
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
Check array density and indicate whether or not the array part should be abandoned.
* Duktape.Buffer: toString(), valueOf()
descriptor type specific checks
DUK_USE_ERRTHROW
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
unary minus
ignore non-strings
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
move pivot to its final place
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
comment:
* Global state for working around missing variadic macros
label: code-design
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
tolerates NULL h_buf
forced_reg
DUK_TOK_PACKAGE
B -> target register
* C -> constant index of identifier name
no match, next case
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
NULL if tv_obj is primitive
lj value2: thread
Note: use 'curr' as a temp propdesc
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
* substring(), substr(), slice()
30: setHours
Expression, ']' terminates
* Number checkers
E5 Section 11.2.3, step 6.a.i
-> [ hobject props ]
XXX: shared handling for 'duk__expr_lhs'?
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
eat 'in'
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
zero-based month
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
expect_token
periods
idx of first argument on stack
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
check stack first
mod_id may be NULL
http://en.wikipedia.org/wiki/ANSI_escape_code
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
DUK_TOK_SET
* Lookup variable and update in-place if found.
'Int8Array'
Last component name in resolved path
Must match src/extract_chars.py, generate_match_table3().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Force pause if we were doing "step into" in another activation.
allow fmt==NULL
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
duk_hcompiledfunction flags; quite version specific
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Clamping needed if duk_int_t is 64 bits.
'id'
output bufwriter
-> x in [-2**31,2**31[
DUK_USE_SELF_TESTS
built-in strings
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Error throwing helpers
[ ... new_glob new_env new_glob new_glob ]
For lightfuncs, simply read the virtual property.
0x70-0x7f
stable
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
Duktape.Thread.resume()
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
nothing to NULL
use SameValue instead of non-strict equality
a value is left on stack regardless of rc
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
Note: this must match ToObject() behavior
'new' MemberExpression
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Report it to the debug client
no compact
restricted to regs
dummy so sp won't get updated
* Replace global object.
require a (mutable) temporary as a result (or a const if allowed)
contains value
'%s' and NULL is not portable, so special case
* it for debug printing.
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
Parse formals.
[... key arg1 ... argN func]
exit bytecode execution with return value
* Status message and helpers
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
DUK_SELFTEST_H_INCLUDED
Duktape object
0xb0-0xbf
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
[ ... res ]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
accessor with defined getter
comment: XXX: optimize for packed duk_tval directly?
label: code-design
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
allow source elements
one token before
'filename'
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
-> x in ]-2**32, 2**32[
no need to incref
Ecmascript function
embed: void ptr
Lightfuncs are always native functions and have "newenv".
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: XXX: cover this with the generic >1 case?
label: code-design
* Variant 1 or 3
'enumerable'
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
zero size not an issue: pointers are valid
fromPresent = true
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
assumes that allocated pointers and alloc funcs are valid
* if res exists
DUK_TOK_EQ
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
XXX: add 'language' argument when locale/language sensitive rule
* support added.
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
Infinity
comment: XXX: unoptimal use of temps, resetting
label: code-design
-> [ ... regexp string ] -> [ ... res_obj ]
token type (with reserved words as DUK_TOK_IDENTIFER)
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
# argument registers target function wants (< 0 => "as is")
'magic' constants for Murmurhash2
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
Object built-in methods
Skip fully.
switch (ch2)
type
* Allocate memory with garbage collection
* Main switch for statement / source element type.
Shared entry handling for object/array serialization.
overwrite sep
[ message error message ]
[ ... parent stash stash ] -> [ ... parent stash ]
Non-verbose errors for low memory targets: no file, line, or message.
DUK_BUFOBJ_ARRAYBUFFER
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
seconds, doesn't fit into 16 bits
unreferenced w/o tracebacks
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
must be updated to work properly (e.g. creation of 'arguments')
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
1:1 or special conversions, but not locale/context specific: script generated rules
roughly 0.5 kiB
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
DUK_TOK_WITH
0xa0-0xaf
* Table for base-64 decoding
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
[... buf]
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
Production allows 'DecimalDigits', including leading zeroes
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
[] -> []
key
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
-> [ array totalLength buf ]
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
is valid size
[ O Properties obj ]
extra coercion of strings is OK
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
FAIL
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
* Push result object and init its flags
number of continuation (non-initial) bytes in [0x80,0xbf]
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
comment: Note: we can reuse 'desc' here
label: code-design
empty statement with an explicit semicolon
* Constructor
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
* toString()
shuffle registers if large number of regs/consts
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
[ result ]
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
[ source ]
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
combines steps 2 and 5; -len ensures max() not needed for step 5
for register-bound and declarative env identifiers
bound functions are never in act 'func'
Lightfuncs cannot be bound.
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
Don't allow mixed padding and actual chars.
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
DUK_TOK_CONTINUE
unbalanced stack on purpose
arguments MUST have an initialized lexical environment reference
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
tags
regexp compiler should catch these
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
-> [ ... voidp true ]
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mp <- b^(e+1)
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
at most sizeof(buf) - 1
val
Old solution: don't iterate, incorrect
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
No BC shuffling now.
syntactically left-associative but parsed as right-associative
* Local result type for duk__get_identifier_reference() lookup.
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
' '
* Heap stringtable handling, string interning.
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Creation time error augmentation
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
check that byte has the form 10xx xxxx
* Memory constants
return 'res' (of right part) as our result
-> [ func funcname env ]
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
* Assertion helpers.
is_setget
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
replacer function
[ ... ]
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
+(function(){}) -> NaN
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
Reject attempt to change a read-only object.
final result is already in 'res'
21: getUTCSeconds
Eval is just a wrapper now.
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
22: getMilliseconds
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
combined algorithm matching E5 Sections 9.5 and 9.6
Evaluates to (duk_uint8_t *) pointing to start of area.
module.id = resolved_id
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
Maximum number of characters in formatted value.
Read fully.
* Prototypes
For indirect allocs.
always allow 'in', coerce to 'tr' just in case
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
Pointer object internal value is immutable
Leave 'value' on stack
prev char
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
'extends'
result: hash_prime(floor(1.2 * e_size))
bp is assumed to be even
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
If buffer has been exhausted, truncate bitstream
Can be called multiple times with no harm.
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
error
1:1 conversion
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
not LS/PS
invalid codepoint encoding or codepoint
comment: packed advance/token number macro used by multiple functions
label: code-design
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
DUK_TOK_BAND_EQ
remaining
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
Faster but value stack overruns are memory unsafe.
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
already in correct reg
the next 'if' is guaranteed to match after swap
Encoding state. Heap object references are all borrowed.
-> [ ... repl_value ]
no prototype
Note: 'q' is top-1
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
comment: XXX: incref by count (2) directly
label: code-design
')'
source is a function expression (used for Function constructor)
* Variant 2
Stored in duk_heaphdr h_extra16.
Note: intentionally signed.
'Date'
input linenumber at input_offset (not window[0]), init to 1
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
idx_value
[ ... this_new | arg1 ... argN ]
------XX XXXX----
* Get old and new length
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
38: getYear
initjs data is NUL terminated
this.raw(buffer)
return h_bufres
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
-> [ ... regexp_instance ]
Final result is at stack top.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
right exists, [[Put]] regardless whether or not left exists
* Return target object.
reuse 'res' as 'left'
st_used remains the same, DELETED is counted as used
is_join
binding power must be high enough to NOT allow comma expressions directly
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
_Formals
base of known return values
TimeClip(), which also handles Infinity -> NaN conversion
[ ... obj ]
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
flags used for property attributes in duk_propdesc and packed flags
directly uses slow accesses
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
add AC*2^32
result: updated refcount
Entry level info.
catch depth from current func
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
decoding
inline initializer for coercers[] is not allowed by old compilers like BCC
* Create normalized 'source' property (E5 Section 15.10.3).
variable access
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
comment: XXX: refactor out?
label: code-design
same for both error and each subclass like TypeError
[ ... res_obj re_obj input bc saved_buf ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
entire string is whitespace
'multiline'
'+'
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
'lineNumber'
refer to callstack entries below current
statement parsing
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
ignore retval -> [key]
%ld
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
syntax error
don't push value
'buffer'
inherit initial strictness from parent
module
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
not emergency
* Raw memory calls: relative to heap, but no GC interaction
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Evaluate RHS only when LHS is safe.
debugger detaching; used to avoid calling detach handler recursively
no catchers
* Variant 4
'package'
nothing now
* Reset trigger counter
* Preliminaries
count is already incremented, take into account
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
inline string concatenation
DUK_USE_JX && DUK_USE_JC
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
[key] (coerced)
comment: XXX: no optimized variants yet
label: requirement
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
'base64'
[ sep ToObject(this) len sep ]
comment:
* Various sanity checks for typing
label: code-design
Check whether statement list ends.
invalidates tv1, tv2
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
-> sets 'f' and 'e'
Check for maximum string length
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
accessor
set to 1 if any match exists (needed for empty input special case)
this should never be possible, because the switch-case is
* comprehensive
avoid double coercion
'DataView'
* Sweep stringtable
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
DUK_TOK_IN
jump to false
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
heapobj recursion depth when deep printing is selected
basic types
temp reset is not necessary after duk__parse_stmt(), which already does it
mark-and-sweep: reachable
Error object is augmented at its creation here.
DUK_USE_COMMONJS_MODULES
at least effective 'this'
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
DUK_USE_LIGHTFUNC_BUILTINS
some derived types
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
x == +Infinity
temp_start+0 = key, temp_start+1 = closure
E5.1 Section 15.1.3.2: empty
DUK_TOK_FINALLY
comment: Static call style.
label: code-design
'deleteProperty'
Compiling state of one function, eventually converted to duk_hcompiledfunction
to body
Coerce top into Object.prototype.toString() output.
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
actual update happens once write has been completed without
* error below.
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
Target object must be checked for a conflicting
* non-configurable property.
property exists, either 'desc' is empty, or all values
* match (SameValue)
[ func thisArg argArray ]
p overshoots
prefer direct
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
Must restart in all cases because we NULLed thr->ptr_curr_pc.
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
checked by Duktape.Thread.resume()
* Union aliasing, see misc/clang_aliasing.c.
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
eat closing quote
setup many variables in nc_ctx
comment: XXX: fast int-to-double
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
comment: XXX: shorter version for 12-byte representation?
label: code-design
a fresh require() with require.id = resolved target module id
Constructor
elision - flush
temp reg for key literal
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
[ ... bytecode escaped_source ]
[obj key desc value get set curr_value]
>>
msec
unary plus of a number is identity
equals and strict equals
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
tv points to element just below prev top
* Duktape/C function magic
* Identifier handling
error gets its 'name' from the prototype
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
E5 Sections 11.9.1, 11.9.3
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
current digit
* Extern
* Mark objects on finalize_list.
*
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
'valueOf'
XXX: potential issue with signed pointers, p_end < p.
* Helpers to resize properties allocation on specific needs.
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
shared object part
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
[ ... re_obj input ]
Backpointers.
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
bottom of new func
re_ctx->captures at the start of the atom parsed in this loop
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
refzero_list treated as reachability roots
* Memory calls.
+0.5 is handled by floor, this is on purpose
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
internal temporary value, used for char classes
comment: format is too large, abort
label: code-design
-> [ ... key val' ]
0x40-0x4f
MPUTOBJ emitted by outer loop
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
be_ctx->offset == length of encoded bitstream
'in'
Duktape.modLoaded[resolved_id] = module
Caller must ensure 'tv' is indeed a fastint!
stage 1 guarantees
typed for duk_unicode_decode_xutf8()
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
[ ... varname ]
preinitialize lexer state partially
comment: XXX: slightly awkward
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
require
rnd in [lo,hi]
must have catch and/or finally
V
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
DUK_TOK_BXOR
[ ... re_obj input bc saved_buf res_obj val ]
No arr_idx update or limit check
[... varname]
fresh require (argument)
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
String object internal value is immutable
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
highest capture number emitted so far (used as: ++captures)
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
[ ... name name ]
nargs
each call this helper serves has nargs==2
assertion disabled
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
* A C
* B A
* C <- sce ==> B
* D D
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
* Case conversion
* Helpers for dealing with the input string
const limits
0xc0-0xcf
The issues below can be solved with better flags
curr and desc are data
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
statement is guaranteed to be terminal (control doesn't flow to next statement)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
chain
[ ... closure ]
comment: Calling as a non-constructor is not meaningful.
label: code-design
* Voluntary periodic GC (if enabled)
Step types
'default'
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
E5 Section steps 7-8
result object is created and discarded; wasteful but saves code space
Gather in little endian
'fmt'
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
NUL terminate for convenient C access
'BYTES_PER_ELEMENT'
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* Node.js Buffer.prototype.fill()
* Exposed debug macros: debugging disabled
comment: No NUL term checks in this debug code.
label: code-design
DUK_BUFOBJ_FLOAT64ARRAY
embed: duk_hobject ptr
getters
DUK_TOK_DELETE
DUK_TOK_BOR
comment: pseudotypes, not used in actual longjmps
label: code-design
A -> target reg
* BC -> inner function index
refcount code is processing refzero list
[ ... retval ]; popped below
0x80...0x8f
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
entry_top + 1
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
* ToBoolean() (E5 Section 9.2)
* Shift to new valstack_bottom.
0 = don't push current value
"." is not accepted in any format
tmp -> res
[ body formals source ]
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
Other initial bytes.
Similar to String comparison.
Finally, blame the innermost callstack entry which has a
* .fileName property.
skip finalizers; queue finalizable objects to heap_allocated
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
fixed top level hashtable size (separate chaining)
not present
end marker
handle negative values
invalidated by pushes, so get out of the way
h is NULL for lightfunc
* Error throwing
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
comment: unused: not accepted in inbound messages
label: code-design
Reuse buffer as is unless buffer has grown large.
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
internal align target for props allocation, must be 2*n for some n
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
target
DUK__FLD_FLOAT
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> x in [0, 2**32[
rethrow original error
'\xffThis'
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
Check if any lookup above had a negative result.
DUK_USE_DEBUGGER_SUPPORT
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
DUK_TOK_SUB_EQ
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
Fixed header info.
nothing to finalize
throw flag irrelevant (false in std alg)
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
name
accept string if next char is NUL (otherwise reject)
* "WhiteSpace" production check.
value1 -> yield value, iserror -> error / normal
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
reachable so pop OK
may be NULL, too
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
* Heap creation and destruction
[ ... regexp_object escaped_source ]
now expected to fit into a 32-bit integer
Duktape.modSearch(resolved_id, fresh_require, exports, module).
bits 0...1: shift
Architecture, OS, and compiler strings
overflow
must fit into duk_small_int_t
'continue'
'value'
Non-critical.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
DUK_USE_DATE_NOW_GETTIMEOFDAY
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
E5 Sections 15.10.2.8, 7.3
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
Important to do a fastint check so that constants are
* properly read back as fastints.
remove artificial bump
important to use normalized NaN with 8-byte tagged types
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
crossed offsets or zero size
[ ... escaped_source bytecode ]
* E5 Section 11.4.8
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
* ToInteger() (E5 Section 9.4)
invalidates tv
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
num_stack_args
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
'\xffVarmap'
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Only allow Duktape.Buffer when support disabled.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
* Heap Buffer object representation. Used for all Buffer variants.
comment: Note: reuse variables
label: code-design
_Varmap
= 1 + arg count
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
'case'
num_pairs and temp_start reset at top of outer loop
Because size > 0, NULL check is correct
17: getUTCHours
[ ... enum ] -> [ ... next_key ]
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
* Finalize stack
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
no need for 'caller' post-check, because 'key' must be an array index
[ arg undefined ]
''
* String-to-number conversion
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
0x10...0x1f
Main operation
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
invalidated
DUK_USE_CPP_EXCEPTIONS
max(incl)
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
comment: XXX: use helper for size optimization
label: code-design
'ignoreCase'
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
frozen and sealed
tv -> value just before prev top value; must relookup
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
initial estimate for ASCII only codepoints
Parser separator masks.
just in case callback is broken and won't write 'x'
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
then to a register
retval to result[i]
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
expect EOF instead of }
resizing parameters
value from target
this is especially critical to avoid another write call in detach1()
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
return the argument object
new buffer of specified size
* Conversion helpers
%x; only 16 bits are guaranteed
mix-in value for computing string hashes; should be reasonably unpredictable
'debug'
keep default instance
Make buffer compact, matching current written size.
explicit semi follows
* Packed 8-byte representation
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
comment: XXX: awkward helpers
label: code-design
advance, expecting current token to be a specific token; parse next token in regexp context
stack prepped for func call: [ ... trap handler ]
'{"_nan":true}'
tagged null pointers should never occur
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
* Finally, longjmp
e.g. DUK_OP_POSTINCP
Allow leading minus sign
copy to buffer with spare to avoid Valgrind gripes from strptime
throw
4: toLocaleDateString
eat 'with'
[ ... this func ]
setters
step 4.c
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
comment: XXX: relocate
label: code-design
match fail
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
DUK_USE_DATE_TZO_GMTIME
Treat like debugger statement: nop
Get valstack index for the func argument or throw if insane stack.
comment: 'd3' is never NaN, so no need to normalize
label: code-design
XXX: push_uint_string / push_u32_string
return value from Duktape.Thread.resume()
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
end of loop (careful with len==0)
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
DUK_TOK_TRY
Optional UTC conversion.
6
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
* Self test main
prototype is lex_env before catcher created
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
tc1 = true, tc2 = false
no need to handle thread state book-keeping here
Not found. Empty string case is handled specially above.
4 low bits
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
[ ... enum ] -> [ ... ]
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
misc constants and helper macros
zero-based day
28: setMinutes
non-object base, no offending virtual property
Fixed seed value used with ROM strings.
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
E5 Sections 11.8.1, 11.8.5; x < y
may be < thr->catchstack initially
complex, multicharacter conversion
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
E5.1 Section 15.1.3.1: uriReserved + '#'
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
'"' was eaten by caller
expression is left-hand-side compatible
string is a reserved word (strict)
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
Step 9: copy elements-to-be-deleted into the result array
0x30-0x3f
2 bits for heap type
setjmp catchpoint setup
comment: not sure whether or not needed; Thursday
label: requirement
emergency mode: try extra hard
Set object 'length'.
byte index limit for element access, exclusive
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
[ ... eval "eval" eval_input level ]
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
!(p < r)
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
num_stack_args
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
complete 'sub atom'
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
round out to 8 bytes
for convenience
buffer limits
Handle TypedArray vs. Node.js Buffer arg differences
DUK_TOK_WHILE
offset/value order different from Node.js
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
* Detach actual buffer from dynamic buffer in valstack, and
* pop it from the stack.
*
* XXX: the buffer object is certainly not reachable at this point,
* so it would be nice to free it forcibly even with only
* mark-and-sweep enabled. Not a big issue though.
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
DUK_TOK_VOID
DUK_USE_PC2LINE
DUK_HOBJECT_FLAG_STRICT varies
[ ... errval errhandler ]
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
serialize the wrapper with empty string key
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
BITWISE EXPRESSIONS
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
Valstack resize flags
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
finish up pending jump and split for last alternative
nop
* Local declarations.
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
x > y --> y < x
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
resumee: [... initial_func] (currently actually: [initial_func])
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
proto can also be NULL here (allowed explicitly)
* split()
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
could also just pop?
Parser part indices.
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Local prototypes
low-level property functions
helpers for defineProperty() and defineProperties()
w/o refcounts
Skip dvalues to EOM.
all native functions have NEWENV
+1, right after inserted jump
only accept lowercase 'utf8' now.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: XXX: block removal API primitive
label: code-design
LOGICAL EXPRESSIONS
%lf, %ld etc
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
8: getFullYear
* Debug connection peek and flush primitives
'do'
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
exponential notation forced
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
Here we'd have the option to normalize -0 to +0.
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
default: false
comment: fill new_h with u32 0xff = UNUSED
label: code-design
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
if direct eval, calling activation must exist
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
Fast check for extending array: check whether or not a slow density check is required.
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
filename may be NULL in which case file/line is not recorded
unsigned
comment: XXX: function flag to make this automatic?
label: requirement
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Breakpoint entries above the used area are left as garbage.
allow_source_elem
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
fall through if overflow etc
inner function numbering
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
function needs shuffle registers
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
invalid padding
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
[ requested_id require require.id resolved_id last_comp ]
advance to get one step of lookup
Write signed 32-bit integer.
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
Needs lookahead
* Churn refzero_list until empty
Note: 'q_instr' is still used below
duk_unicode_caseconv_uc[]
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
failed, resize and try again
extend with undefined
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
Error; error value is in heap->lj.value1.
-> [ ... key val toJSON val key ]
callstack
read 3 bytes into 't', padded by zero
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
* Computed values (e.g. INFINITY)
DUK_TOK_DIV_EQ
already set
input 'd' in Windows UTC, 100ns units
Keep current size
50x heap size
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
[ name this ]
[ ... holder name val enum obj_key new_elem ]
patched later
[ ... regexp_object ]
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
This was the last term, and q_last was
* updated to match this term at loop top.
x <- b^y; use t1 and t2 as temps
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
ref.holder is global object, holder is the object with the
* conflicting property.
essentially tracks digit position of lowest 'f' digit
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
binding power "levels" (see doc/compiler.rst)
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
result reg
strings are only tracked by stringtable
to avoid relookups
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
':'
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
Slice starting point is beyond current length.
... target is extensible
duk_unicode_support.c
comment: XXX: easier check with less code?
label: code-design
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
x <- x * y, use t as temp
[ ... v1 v2 str ] -> [ ... str v2 ]
Zero 'count' is also allowed to make call sites easier.
comment: XXX: size optimize
label: code-design
!= 0 => post-update for array 'length' (used when key is an array index)
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
false
* Built-in strings
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
* Variant 3
* On second pass, skip the function.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
-> [ ... key val toJSON val ]
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
[ obj trap_result res_arr propname ]
split1: prefer direct execution (no jump)
in resumer's context
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
'try'
-> [in_val]
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
Note: 0xff != DUK_BC_B_MAX
* Unions and structs for self tests
Note: masking is done for 'i' to deal with negative numbers correctly
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
don't run finalizers; queue finalizable objects back to heap_allocated
val1 = count
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Get minimum array part growth for a certain size.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
'enumerate'
DUK_TOK_RSHIFT
roughly 256 bytes
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
object is now reachable
flags: "im"
Copy trap result keys into the enumerator object.
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
Success path.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
t1 <- (* r B)
DUK_BUFOBJ_UINT8ARRAY
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
assertions: env must be closed in the same thread as where it runs
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
refzero not running -> must be empty
comment: XXX: differentiate null pointer from empty string?
label: code-design
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
DUK_USE_MARK_AND_SWEEP
* Coercion and fast path processing
y == +Infinity
caller required to know
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
'toLocaleString'
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
buffer is automatically zeroed
num_args
DUK_OP_EXTRA, sub-operation in A
insert the required matches (qmin) by copying the atom
DUK_USE_INTEGER_BE
out_clamped
adv = 2 default OK
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
'-0'
module table remains registered to modLoaded, minimize its size
* Detach handling
write back
[ ... filename (temps) func ]
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
* Second pass parsing.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
DUK_USE_EXEC_TIMEOUT_CHECK
* Misc defines
E5.1 Section 15.1.3.4: uriUnescaped
Combined size of separators already overflows
-> [ ... res ]
[ ... this name message ]
"/" and not in regexp mode
DUK_USE_BYTECODE_DUMP_SUPPORT
comment: may indirectly slow access through a direct eval
label: code-design
no incref needed
variable binding register if register-bound (otherwise < 0)
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
[ ... varname val this ] (because throw_flag == 1, always resolved)
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
embed: duk_hbuffer ptr
t >= 0 always true, unsigned
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
vararg function, careful arg handling (e.g. thisArg may not be present)
implicit this value always undefined for
* declarative environment records.
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
duk_unicode_ids_noabmp[]
Return value of 'sz' or more indicates output was (potentially)
* truncated.
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
Encoding/decoding flags
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
no need to write 'out_bufdata'
new_used / size <= 1 / DIV <=> new_used <= size / DIV
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
label handling
Expression
comment: This is performance critical because it appears in every DECREF.
label: code-design
code_idx = entry_top + 0
-> [ ... lval rval ]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
eat 'throw'
always grow the array, no sparse / abandon support here
leave formals on stack for later use
since index non-negative
tzoffset
duk_has_prop() popped the second 'name'
varname
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
-------- ----XXXX
stack top: new time value, return 1 to allow tail calls
basereg
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
jump for 'catch' case
Module object containing module.exports, etc
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
-> [ ... escaped_source bytecode ]
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
5: toLocaleTimeString
mark-and-sweep: children not processed
Catches EOF of JSON input.
radix
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
no wrapping
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
object or array
no need to check now: both success and error are OK
Note: allow backtracking from p == ptr_end
Relookup if relocated
module.filename for .fileName, default to resolved ID if
* not present.
-> [ ... toLocaleString ToObject(val) ]
DUK_TOK_LBRACKET already eaten, current token is right after that
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
Restore stack top after unbalanced code paths.
position of highest digit changed
* duk_heap allocation and freeing.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
no statement value (unlike function expression)
Three digit octal escape, digits validated.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Quite approximate but should be useful for little and big endian.
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
retval for success path
* Wrapping duk_safe_call() will mangle the stack, just return stack top
* Node.js Buffer.prototype: toJSON()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
'fileName'
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
parse args starting from "next temp"
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
* Mark-and-sweep garbage collection.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
comment: unnecessary div for last byte
label: code-design
buffer values are coerced first to string here
sanity limit for function pointer size
[ sep ToObject(this) len sep str0 ... str(count-1) ]
DUK_TOK_YIELD
comment: XXX: is valstack top best place for argument?
label: code-design
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
duk_hobject_run_finalizer() sets
[ source template closure ]
Successful return: restore jmpbuf and return to caller.
negative -> no atom matched on previous round
[ ... name ]
Note: may be NULL if first call
unresolvable, no stack changes
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
DUK_USE_DATE_NOW_TIME
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
* Reference counting implementation.
use strict equality instead of non-strict equality
This assert depends on the input parts representing time inside
* the Ecmascript range.
controls for minimum array part growth
-> [ ... key ]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
allow basic ASCII whitespace
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
activation is a direct eval call
current lex_env of the activation (created for catcher)
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
start byte offset of token in lexer input
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
curr_token = get/set name
Initial '[' has been checked and eaten by caller.
Thread may have changed, e.g. YIELD converted to THROW.
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
be paranoid for 32-bit time values (even avoiding negative ones)
* Node.js Buffer.byteLength()
emit instruction; could return PC but that's not needed in the majority
* of cases.
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
All the flags fit in 16 bits, so will fit into duk_bool_t.
flags: "g"
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
end of _Varmap
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
[-0x80000000,0x7fffffff]
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
'Arguments'
[key getter this] -> [key retval]
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
only functions can have arguments
E5 Section 9.3.1
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
0xd0...0xdf
tv1 is -below- valstack_bottom
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
[ obj Properties ]
* First attempt
not found
Loop check.
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
reserved words: additional future reserved words in strict mode
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
Sync and NULL early.
12 to 21
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
-> pushes fixed buffer
comment: XXX: improve check; check against nregs, not against top
label: code-design
byte sizes will match
max # of values initialized in one MPUTARR set
not reached
-> [ ... this ]
* Local defines and forward declarations.
comment: prev value must be unused, no decref
label: code-design
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
x >= y --> not (x < y)
yes, must set array length explicitly
* Post resize assertions.
Note: for dstlen=0, dst may be NULL
!DUK_USE_TRACEBACKS
-> [ func funcname env funcname ]
Constants for duk_lexer_ctx.buf.
Difference is in 100ns units, convert to milliseconds w/o fractions
* "IdentifierPart" production check.
prev exists and is not a letter
Note: no recursion issue, we can trust 'map' to behave
if fails, e_size will be zero = not an issue, except performance-wise
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment: workaround: max nbits = 24 now
label: code-design
DUK_USE_HEX_FASTPATH
DUK_UTIL_H_INCLUDED
'Infinity'
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
debugger state, only relevant when attached
highest value of temp_reg (temp_max - 1 is highest used reg)
* Init compiler and lexer contexts
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
pre/post opcode values have constraints,
allocated heap objects
re-read to avoid spill / fetch
LRU: move our entry to first
argument/function declaration shadows 'arguments'
Proxy target
unconditional block
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
* Node.js Buffer.prototype.copy()
DUK_VERBOSE_ERRORS
skip '|'
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
'byteLength'
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
* Detect iteration statements; if encountered, establish an
* empty label.
skip ')'
* Poppers
DUK_HOBJECT_H_INCLUDED
always at least the header
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Fast path, decode as is.
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
'break'
in yielder's context
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
non-leap year: sunday, monday, ...
activation has tail called one or more times
extended types: custom encoding
reg
-> [... enum key val]
EOF
XXX: optimize value stack operation
* Proxy object handling
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
mark as complex (capture handling)
string is a reserved word (non-strict)
s <- b^(1-e) * 2
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Map DUK__FLX_xxx to byte size.
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
* Get/require
key, getter and setter, now reachable through object
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
'Array'
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
extended utf-8 not allowed for URIs
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
bytecode limits
guaranteed to find an empty slot
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Allow trailing garbage (e.g. treat "123foo" as "123)
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
steps 3.h and 3.i
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
module (argument)
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
current paren level allows 'in' token
comment: XXX: fast-int-to-double
label: code-design
* ArrayBuffer.isView()
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
* Debugging enabled
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: XXX: duk_set_length
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
XXXXXX-- --------
* Bitstream decoder.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
retval (sub-atom char length) unused, tainted as complex above
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
should not happen
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
DUK_TOK_REGEXP
* Peephole optimize JUMP chains.
* Execution timeout check
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
type to represent a reg/const reference during compilation
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
DUK_TOK_PUBLIC
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
'get'
comment: function name (borrowed reference), ends up in _name
label: code-design
repl_value
quotes
'undefined' already on stack top
'res' is used for "left", and 'tmp' for "right"
def_value
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
comment: XXX: skip null filename?
label: code-design
avoid multiply
New require() function for module, updated resolution base
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
"-Infinity", '-' has been eaten
make absolute
'act' already set above
DUK_BUFOBJ_UINT8CLAMPEDARRAY
comment: XXX: turkish / azeri, lowercase rules
label: code-design
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
no comma
strict outer context
jump for 'finally' case or end (if no finally)
* Structs
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
from next pc
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
use 'left' as a temp
JSON
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
* Pointer built-ins
Zero length string is not accepted without quotes
[ key ] -> []
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
current function being compiled (embedded instead of pointer for more compact access)
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
Note: 'this' may be bound to any value, not just an object
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
out of spec, don't care
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
used by e.g. duk_regexp_executor.c, string built-ins
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Share yield longjmp handler.
curr_token slot2 (matches 'lex' slot2_idx)
Error message doesn't matter: the error is ignored anyway.
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment: actually used
label: code-design
rule match
* Helper structs
terminating conditions
see below
allow automatic semicolon even without lineterm (compatibility)
Outside any activation -> put to global.
+0 = break, +1 = continue
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
-> [ val arr ]
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
this is needed for regexp mode
jump to next case clause
pop plain buffer, now reachable through h_bufres
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
add AD*2^16
Proxy handler
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
relookup exports from module.exports in case it was changed by modSearch
* Indexed read/write helpers (also used from outside this file)
adv = 2 - 1 default OK
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
comment: XXX: side effect handling is quite awkward here
label: code-design
act->func
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Call setup checks callability.
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
DUK_BUFOBJ_UINT32ARRAY
* Restore 'caller' property for non-strict callee functions.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
0x60...0x6f
>= 0
mimic semantics for strings
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
DUK__FLD_8BIT
[key]
normal key/value
mm <- b^e
steps 4.a and 4.b are tricky
The external string struct is defined even when the feature is inactive.
fixed arg count
A -> flags
* B -> return value reg/const
* C -> currently unused
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
-> [ ... closure template newobj ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
* Size-optimized pc->line mapping.
return as is
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
function: create binding for func name (function templates only, used for named function expressions)
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
comment: XXX: copy from caller?
label: code-design
always for register bindings
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
heap->dbg_udata: keep
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
dummy value used as marker
never here, but fall through
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
must never longjmp
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
stack top contains 'true'
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
'\xffHandler'
Note: string is a terminal heap object, so no depth check here
0x80-0x8f
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
Debug print which visualizes the qsort partitioning process.
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
r <- (2 * f) * b^e
unreferenced with some options
always terminates led()
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
awkward; we assume there is space for this
Peek ahead in the stream one byte.
* Breakpoint management
* Compact an object
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
alias for above
handle comma and closing brace
shrink case; leave some spare
strictness is not inherited, intentional
only Array.prototype matches
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
This seems reasonable overall.
Loop prevention
'throw'
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
Assume that the native representation never contains a closing
* parenthesis.
varargs marker
entry level reached
Current strictness flag: affects API calls.
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
'*'
call is from executor, so we know we have a jmpbuf
Yield/resume book-keeping.
finally part will catch
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
Load inner functions to value stack, but don't yet copy to buffer.
[ start end ]
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
DUK_TOK_THROW
comment: Note: not a typo, "object" is returned for a null value
label: documentation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
Original idiom used, minimal code size.
comment: 'fun' is quite rarely used, so no local for it
label: code-design
comment: XXX: fastint
label: code-design
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
normal
Careful with wrapping (left shifting idx would be unsafe).
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
"+11:22\0"
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
caller
match followed by capture(s)
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
'ptr' is evaluated both as LHS and RHS.
* Ecmascript [[Class]]
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
finalize_list will always be processed completely
comment: XXX: exposed duk_debug_read_pointer
label: code-design
-> [ ... key val replacer holder ]
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
open scope information, for compiled functions only
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
temp reg handling
* Parse function body
x <- y - z
'Pointer'
relookup if changed
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
throw_flag
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
break/continue without label
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
non-global regexp: lastIndex never updated on match
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
exposed because lexer needs these too
empty match (may happen with empty separator) -> bump and continue
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
Set up curr_pc for opcode dispatch.
[ ... pattern flags escaped_source ]
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
Get minimum entry part growth for a certain size.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
thr->heap->lj.value2 is 'thread', will be wiped out at the end
break/continue with label (label cannot be a reserved word, production is 'Identifier'
property access
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
internal property functions
Report thrown value to client coerced to string
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
DUK_USE_USER_INITJS
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
110x xxxx 10xx xxxx
Sanity limits for stack sizes.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
No net refcount change.
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
result array is already at the top of stack
args go here as a comma expression in parens
[ ... source? filename? &comp_args ] (depends on flags)
no extra padding
Start position (inclusive) and end position (exclusive)
tentative, checked later
slot A is a source (default: target)
indexed by recursion_depth
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
Order of unwinding is important
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
tracks maximum initialized index + 1
comment: first register that is a temporary (below: variables)
label: code-design
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
Just skip, leaving zeroes in the result.
[ ... arr ]
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
bytes in source
no voluntary gc
A -> result reg
* B -> object reg
* C -> key reg/const
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
refcount
regexp res_obj is at index 4
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
']'
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
-> [ func funcname env funcname func ]
true, because v[1] has at least one bit set
bp to use when parsing a top level Expression
Caller will finish the marking process if we hit a recursion limit.
y
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
TypeError if fails
* Entries part
* Delayed env creation check
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
guarantees entry_callstack_top - 1 >= 0
no code needs to be emitted, the regs already have values
magic: 0=getter call, 1=Object.getPrototypeOf
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
* Debug connection write primitives
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
module.name for .name, default to last component if
* not present.
* Exposed debug macros: debugging enabled
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
0xe0-0xef
compact the prototype
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
read header
prop index in 'hash part', < 0 if not there
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
object is a native function (duk_hnativefunction)
[ ... error func fileName lineNumber ]
21 bits
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
embed: duk_hstring ptr
enumeration
* Free memory
Maximum value check ensures 'nbytes' won't wrap below.
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
currently, even for Array.prototype
unsigned intentionally
DUK_TOK_SNEQ
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
No need to assert, buffer size maximum is 0xffff.
default is explicit index read/write copy
not enumerable
* Exposed data
avoid problems if p == h->prototype
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
Output shuffle needed after main operation
For native calls must be NULL so we don't sync back
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
omitted
'toGMTString'
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
* ISO 8601 subset parser.
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
[res]
dash is already 0
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
keep val_highest
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
can't get value, may be accessor
Relookup and initialize dispatch loop variables. Debugger check.
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
leave result on stack top
Resolved, normalized absolute module ID
marker; not actual tagged value
re-lookup curr char on first round
[ ... formals arguments map mappedNames ]
borrowed: full duk_tval for function being executed; for lightfuncs
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
Skip dvalue.
comment: XXX: inefficient; block remove primitive
label: code-design
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
[ ... pattern flags ]
custom; implies DUK_HOBJECT_IS_THREAD
[ thisArg arg1 ... argN ]
for array and object literals
validation of the regexp is caller's responsibility
regnum is sane
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
Preinc/predec for var-by-name, slow path.
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
Small variant; roughly 150 bytes smaller than the fast variant.
-> [ ... closure template env funcname ]
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
_Pc2line
Sanity checks for string and token defines
number of escapes and line continuations (for directive prologue)
MakeTime
comment: XXX: this is possible without resorting to the value stack
label: code-design
ignored
NULL for lightfunc
lookup shorthands (note: assume context variable is named 'lex_ctx')
Other callbacks are optional.
truncated in case pass 3 needed
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
Leave 'getter' on stack
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
Q...f
x < y
set exotic behavior only after we're done
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Current size is about 152 bytes.
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
while repl
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
Setup state. Initial ivalue is 'undefined'.
'object'
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
1 1 1 <32 bits>
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
patch in range count later
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
0: toString
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
lowest mantissa for this exponent
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
all we need to know
ASSIGNMENT EXPRESSION
IdentityEscape
Must decrease recursion depth before returning.
note: mixing len into seed improves hashing when skipping
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
Return with final function pushed on stack top.
Note: 'e' and 'E' are also accepted here.
'%c', passed concretely as int
thread resumed another thread (active but not running)
or a non-catching entry
next char
-> [... key val]
add F
comment: return a specific NaN (although not strictly necessary)
label: code-design
* Variant 1
global regexp: lastIndex updated on match
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
Current size (not counting a dynamic buffer's "spare").
+2 = catcher value, catcher lj_type
parsing in "directive prologue", recognize directives
non-strict: non-deletable, writable
DUK_USE_64BIT_OPS
simulate alloc failure on every realloc (except when mark-and-sweep is running)
7
comment: alloc temp just in case, to update max temp
label: code-design
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
exposed, used by e.g. duk_bi_date.c
* Parsing of ints and floats
flags: "gi"
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
* Return target object
side effects
[ ... result ]
only objects have finalizers
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
* Thread support.
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
temp copy, write back for next loop
char loop
basic platform types
we currently assume virtual properties are not configurable (as none of them are)
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
address
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
may be NULL
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
IEEE double is approximately 16 decimal digits; print a couple extra
* Resizing and hash behavior
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
[obj key undefined]
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* isArray()
DUK_USE_HOBJECT_HASH_PART
trailing elisions?
* Simple commands
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
[ ... global val ] -> [ ... global ]
length in codepoints (must be E5 compatible)
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
Decode helper. Return zero on error.
XXX: specify array size, as we know it
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
1111 0xxx; 4 bytes
start array index of current MPUTARR set
cp == -1 (EOF) never matches and causes return value 0
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
DUK_OP_CALL flags in A
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
Must be >= 0 and multiple of element size.
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
note that we can't reliably pop anything here
[... put_value]
5
ref.value and ref.this_binding invalidated here
nret
object is a compiled function (duk_hcompiledfunction)
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
Need a short reg/const, does not have to be a mutable temp.
delete Duktape.modLoaded[resolved_id]
keep current valstack_top
Disabled until fixed, see above.
'message'
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
0x70...0x7f
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
comment: XXX: depend on available temps?
label: code-design
default case
%u; only 16 bits are guaranteed
MultiplicativeExpression
Trim white space (= allow leading and trailing whitespace)
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
does not modify tv_x
26: setSeconds
patch pending jump and split
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
only needed by debugger for now
Compute day number of the first day of a given year.
ignore_loop
* Begin
Output #1: resolved absolute name
and even number
* DELPROP: Ecmascript property deletion.
normal: implicit leading 1-bit
may throw an error
* Encoding constants, must match genbuiltins.py
'RegExp'
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
<<
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
ensure full memcmp() fits in while
unreachable
push operation normalizes NaNs
getter/setter
x == 0x00 (EOF) causes syntax_error
XXX: range assert
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
flags: "i"
* Init stringtable: probe variant
Catches both doubles and cases where only one argument is a fastint
key coercion (unless already coerced above)
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Limit checks for bytecode byte size and line number.
The necessary #includes are in place in duk_config.h.
comment: XXX: this could be optimized
label: code-design
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
comment: Silence a few global unused warnings here.
label: code-design
-> [... arr num]
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
thread has yielded
Lightfuncs are always strict.
'\xffArgs'
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
Further state-dependent pre-checks
E5 Section 8.12.8
is_decl
at least one activation, ours
s <- b^(-e) * 2
use p_src_base from now on
'taint' result as complex
no issues with memcmp() zero size, even if broken
* Disjunction struct: result of parsing a disjunction
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
Previous entry was inside visited[], nothing to do.
comment: XXX: optimize temp reg use
label: code-design
toFixed()
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
duk_unicode_idp_m_ids_noabmp[]
'(?:)'
* Process replacer/proplist (2nd argument to JSON.stringify)
may be a string constant
return total chars written excluding terminator
[ (builtin objects) name ]
new_free / size <= 1 / DIV <=> new_free <= size / DIV
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
[ ... holder name val enum obj_key ]
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
exit() afterwards to satisfy "noreturn"
string compare is the default (a bit oddly)
'%xx%xx...%xx', p points to char after first '%'
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
2^4 -> 1/16 = 6.25% spare
* reduce(), reduceRight()
* Macros for accessing size fields
* Resolve module identifier into canonical absolute form.
leap year: sunday, monday, ...
even after a detach and possible reattach
tval
comment: integer mixed endian not really used now
label: code-design
only advance if not tainted
tail insert: don't disturb head in case refzero is running
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
0.000...
leave stack unbalanced on purpose
[ ... func this <bound args> arg1 ... argN ]
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Table for hex encoding bytes
[ ... buf func ] -> [ ... func ]
build result as: (r << 32) + s: start with (BD + E + F)
We only get here when doing non-standard JSON encoding
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
[target] -> [enum]
Handle both full and partial slice (as long as covered).
envrec: (declarative) record is closed
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
XXX: bump preventcount by one for the duration of this call?
for
15: getUTCDay
need_bytes may be zero
register binding lookup is based on varmap (even in first pass)
prototype: the only internal property lifted outside 'e' as it is so central
3 entries actually needed below
end of input and last char has been processed
[ start length str ]
array
fast paths for space and tab
Significand ('f') padding.
comment: not needed
label: requirement
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
add a new pending match jump for latest finished alternative
exclusive
DUK_USE_BUILTIN_INITJS
* If selftests enabled, run them as early as possible
ivalue/ispec helpers
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
idx_this = idx_func + 1
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
not needed, as we exit right away
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
relookup, may have changed
leading digit + fractions
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
tc1 = true, tc2 = true
See comments below on MakeTime why these are volatile.
-> [ val obj val ]
Store lexer position, restoring if quantifier is invalid.
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
marker; not actual tagged type
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
For NaN/inf, the return value doesn't matter.
curr char
[ regexp string ]
comment: NULL not needed here
label: code-design
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
overflow, more than 32 bits -> not an array index
special result value handling
[ ... Logger clog res ]
[... put_value varname]
intermediate join to avoid valstack overflow
ptr before mark-and-sweep
end-of-input breaks
reserve a jumpslot after instr before target spilling, used for NEXTENUM
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
* Variable access
comment: function: function must not be tail called
label: code-design
third arg: absolute index (to entire valstack) of idx_bottom of new activation
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
!DUK_USE_HSTRING_CLEN
DUK_ERR_EVAL: no macros needed
DUK_USE_PREFER_SIZE
Incref copies, keep originals.
object is a buffer object (duk_hbufferobject) (always exotic)
recheck that the property still exists
jump from true part to end
comment: XXX: fastint fast path would be very useful here
label: code-design
XXX: happens e.g. when evaluating: String(Buffer.prototype).
'name'
eat identifier
* Init stringtable: fixed variant
Copy values through direct validated reads and writes.
break matches always
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
-1 for opcode
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
comment: hash part size or 0 if unused
label: code-design
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
helper to insert a (non-string) heap object into heap allocated list
* Internal API calls which have (stack and other) semantics similar
* to the public API.
retval is directly usable
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
digit count
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
2^3 -> 1/8 = 12.5% min growth
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
'hex'
borrowed label name
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
Longjmp state is kept clean in success path
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
comment: XXX: faster internal way to get this
label: code-design
old value is number: no refcount
Using classification has smaller footprint than direct comparison.
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
leading byte of match string
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
canonicalized by compiler
[ source template closure this ]
initial index
5 heap flags
DUK_TOK_FUNCTION
exponent for 'f'
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
always 1 arg
helpers
ignore result
DUK_JMPBUF_H_INCLUDED
'static'
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
extended types: compatible encoding
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
valstack limit caller has check, prevents wrapping
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
Note: number has no explicit tag (in 8-byte representation)
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
reg/const for case value
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
signed integer encoding needed to work with UTF-8
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
'&'
jump is inserted here (variant 3)
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
resumee: [... initial_func undefined(= this) resume_value ]
ignore reclimit, not constructor
'\xffCallee'
is normalized
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
Coerce like boolean
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
[ (builtin objects) ]
comment: XXX: tv_func is not actually needed
label: requirement
* Source filename (or equivalent), for identifying thrown errors.
'__proto__'
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
parent env is the prototype
get varenv for varname (callee's declarative lexical environment)
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
Note: can be safely scanned as bytes (undecoded)
========================================================================
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
also goes into flags
UnaryExpression
comment: XXX: return something more useful, so that caller can throw?
label: code-design
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
all virtual properties are non-configurable and non-writable
[ obj trap_result res_arr ]
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
depth check is done when printing an actual type
Preinc/predec for object properties.
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
init function state: inits valstack allocations
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK_USE_PARANOID_ERRORS
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Without ROM objects "needs refcount update" == is heap allocated.
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
side effects -> don't use tv_x, tv_y after
[... enum]
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
DUK_TOK_LT
no value
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
hash probe sequence
* Make the C call
DUK_USE_NONSTD_FUNC_STMT
has access to 'this' binding
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
initial size guess
Buffer writes are often integers.
env[funcname] = closure
Safe to call multiple times.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
formatted result limited
[] -> [res]
may be NaN
'undefined', artifact of lookup
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
lj value1: value
pushes function template
Identifier, i.e. don't allow reserved words
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
[ arg toLogString ]
out_token->lineterm set by caller
note: any entries above the catchstack top are garbage and not zeroed
Error code also packs a tracedata related flag.
enumerator must have no keys deleted
Stack size increases or stays the same.
known to be number; in fact an integer
avail_bytes += need_bytes
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
temp variable to pass constants and flags to shared code
char length of the atom parsed in this loop
-> [ ... fn x y ]
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
-> [...]
topmost activation idx_retval is considered garbage, no need to init
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
ref.value, ref.this.binding invalidated here by getprop call
* Field accessor macros
[ ... buf ]
idx_base and idx_base+1 get completion value and type
integer number in range
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
check stack before interning (avoid hanging temp)
The extra (+4) is tight.
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
DUK_TOK_STATIC
No pointer compression because pointer is potentially outside of
* Duktape heap.
'null'
pc2line
always normalized
JUMP L1 omitted
comment: writable, not configurable
label: code-design
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
big endian
entry_top + 3
must match bytecode defines now; build autogenerate?
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
'.'
* Automatically generated by genbuiltins.py, do not edit!
* Debug connection read primitives
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: XXX: optimize with more direct internal access
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
0x00-0x0f
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
DUK_TOK_BOR_EQ
Argument must be a string, e.g. a buffer is not allowed.
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
number of formal arguments
register, constant, or value
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
h_code: held in bw_code
* Forward declarations.
heap pointer comparison suffices
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
Backtrack.
comment: XXX: code duplication
label: code-design
arg count
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
[ ... number ] -> [ ... string ]
'data' (and everything in it) is reachable through h_res now
Fast path.
called as a normal function: return new Date().toString()
------XX
must be computed after realloc
'join'
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
re-lookup first char on first loop
[ ... buf loop (proplist) ]
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
DUK_USE_DATE_FMT_STRFTIME
eat the right paren
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
-1 if disjunction is complex, char length if simple
noblame_fileline
Backtrack to previous slash or start of buffer.
func limits
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
For anything other than an Error instance, we calculate the error
* location directly from the current activation.
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
comment: code_idx: not needed
label: requirement
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
load factor min 25%
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
Assume interrupt init/counter are properly initialized here.
* Parse a case or default clause.
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
maxval
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
* Bitstream encoder
-> [ sep ToObject(this) len str sep ]
Decrement PC if that was requested, this requires a PC sync.
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
no side effects
INACTIVE: no activation, single function value on valstack
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
this cannot initiate a detach
done so that duk__mark_heaphdr() works correctly
if highest bit of a register number is set, it refers to a constant instead
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
byte offset to buf
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
comment: unused now
label: code-design
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
still in prologue
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
fixed-format termination conditions
DUK_TOK_ELSE
* Add line number to a compiler error.
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
Ensure copy is covered by underlying buffers.
longjmp state
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
Expression, terminates at a ')'
can't happen when keeping current stack size
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
Miscellaneous.
-> [ ... retval ]
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
-> [ timeval this ]
comment: Clean up stack
label: code-design
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
unwind to 'yield' caller
How much stack to require on entry to object/array decode
(e.g. k=3, digits=2 -> "12X")
Note: changing from writable to non-writable is OK
unwinds valstack, updating refcounts
For JX, expressing the whole unsigned 32-bit range matters.
r <- 2 * f
currently active breakpoints: NULL term, borrowed pointers
conversions, coercions, comparison, etc
[key val] -> [key]
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
* Misc support functions
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
array of formal argument names (-> _Formals)
[ ... func this arg1 ... argN ]
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
key encountered as a getter
comment: XXX: typing
label: code-design
catches EOF (NUL)
'act' is no longer accessed, scanbuild fix
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
[ ... RegExp ]
DUK_TOK_DECREMENT
[ ... errhandler undefined errval ]
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
no wrap assuming h_bufobj->length is valid
Nominal size check.
register bound variables are non-configurable -> always false
-> [ obj trap handler target ]
reasonable output estimate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
* Character and charcode access
nargs == 2 so we can pass a callstack level to eval().
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
normal valued properties
'\xffLexenv'
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
variable map for pass 2 (identifier -> register number or null (unmapped))
buffer pointer is to an externally allocated buffer
'Uint32Array'
'with'
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
callstack index of related activation
non-standard
may be safe, or non-safe depending on flags
activation prevents yield (native call or "new")
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
DUK__FLD_VARINT; not relevant here
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
eat 'try'
1110 xxxx 10xx xxxx 10xx xxxx
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Expects 'this' at top of stack on entry.
The token in the switch has already been eaten here
currently all labels accept a break, so no explicit check for it now
[ arg result ]
got lineterm preceding non-whitespace, non-lineterm token
intentional overlap with earlier memzero
Allow exponent
'\xffSource'
read-only object, in code section
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Shared object part.
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
DUK_OP_RETURN flags in A
DUK_TOK_ADD
allocate to reg only (not const)
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
requested number of output digits; 0 = free-format
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
DUK_TOK_EOF
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
XXX: duk_dup_unvalidated(ctx, -2) etc.
fill new entries with -unused- (required, gc reachable)
-> [ O toString O ]
accept anything, expect first value (EOF will be
* caught by key parsing below.
unknown, ignore
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
[ ... v1 v2 name filename ]
!DUK_USE_PANIC_HANDLER
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
expected ival
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
no sce, or sce scan not best
caller must have decref'd values above new_a_size (if that is necessary)
[ ... buf loop (proplist) (gap) ]
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
checked by caller
'Int16Array'
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
thread; minimizes argument passing
step 4.d
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
one operator (= assign)
no need to init reg, it will be undefined on entry
string objects must not created without internal value
eat backslash on entry
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
comment: XXX: Rework to use an always-inline function?
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
We're a varargs function because we need to detect whether
* initialValue was given or not.
cannot be strict (never mapped variables)
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
DUK_DEBUGGER_H_INCLUDED
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
0 if no used entries
* Basic double / byte union memory layout.
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
if new_p == NULL, all of these pointers are NULL
-> [... obj retval/error]
[ ... holder key ] -> [ ... holder ]
'this' binding is just before current activation's bottom
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
a
Allow leading zeroes (e.g. "0123" -> "123")
* Default clause.
d <- (quotient (* r B) s) (in range 0...B-1)
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Commands initiated by debug client.
next loop requires a comma
0x40...0x4f
'string'
match == search string, by definition
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
32-bit x 11-bit = 43-bit, fits accurately into a double
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
eat closing brace
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
without finally, the second jump slot is used to jump to end of stmt
slot B is a target (default: source)
fastint constants etc
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
Duktape.modLoaded
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
comment: XXX: call method tail call?
label: code-design
w.../
always provideThis=true
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
* Thread state and calling context checks
token type (with reserved word identification)
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
verified at beginning
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
XXX: duk_push_uint_string()
Built-in providers
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
pop final_cons
comment: When ptr == NULL, the format argument is unused.
label: code-design
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
ANSI C typing
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
1=little endian
* "IdentifierStart" production check.
* Compiler state
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Entries part is a bit more complex
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
nop: insert top to top
h_match is borrowed, remains reachable through match_obj
0 = uppercase, 32 = lowercase (= 'a' - 'A')
catch jump
3: toLocaleString
not reachable
leave 'cat' as top catcher (also works if catchstack exhausted)
+1 for opcode
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
Not halfway, round to nearest.
remove in_val
idx_argbase
Strict by default.
fixed precision and zero padding would be required
Ensuring (reserving) space.
flags: "m"
'setPrototypeOf'
return 1 to allow callers to tail call
* Not found (even in global object)
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
'number'
label id allocation (running counter)
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
comment: XXX: how to figure correct size?
label: code-design
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
op_flags
# argument registers target function wants (< 0 => never for ecma calls)
Different calling convention than above used because the helper
* is shared.
equality not actually possible
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
[ ... func this arg1 ... argN envobj ]
32: setDate
slot C is a target (default: source)
-> [ ... lval rval new_rval ]
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
sanity
deal with negative values
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
create bound function object
maximum bytecode copies for {n,m} quantifiers
[ ... lval rval ]
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
use duk_double_union as duk_tval directly
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't increase 'count'
module.exports = exports
simulate alloc failure on every alloc (except when mark-and-sweep is running)
must relookup act in case of side effects
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
status booleans
identifier handling
duk_unicode_caseconv_lc[]
DUK_TOK_PROTECTED
target
reserved words: future reserved words
Ensure space for maximum multi-character result; estimate is overkill.
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
* Pre resize assertions.
In-place unary operation.
Note: expect that caller has already eaten the left paren
implicit leading one
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
* Internal helpers for managing object 'length'
biased exp == 0 -> denormal, exp -1022
0xdeadbeef in decimal
strings up to the this length are not cached
DUK_HEAPHDR_H_INCLUDED
[ ... key_obj key val ]
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
keep func->h_argnames; it is fixed for all passes
num entries of new func at entry
One digit octal escape, digit validated.
Use result value as is.
step 15.a
formal arg limits
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
[ offset noAssert ], when ftype != DUK__FLD_VARINT
bufwriter for temp accumulation
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
-1 if invalid
convenience helpers
* Use Object.defineProperty() helper for the actual operation.
Ensure compact use of temps.
* Object handling: property access and other support functions.
allocated from valstack (fixed buffer)
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
DUK_TVAL_H_INCLUDED
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
last component
lexing (tokenization) state (contains two valstack slot indices)
* Update an existing property of the base object.
update length (curr points to length, and we assume it's still valid)
in-place setup
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
The lo/hi indices may be crossed and hi < 0 is possible at entry.
* Init compilation context
add E
'\xffThread'
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
* Special name handling
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: XXX: this is a major target for size optimization
label: code-design
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
XXX: check num_args
pop 'name'
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
* All done, switch properties ('p') allocation to new one.
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
decode '%xx' to '%xx' if decoded char in reserved set
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
any other printable -> as is
Called by duk_hstring.h macros
step type: none, step into, step over, step out
comment: XXX: faster implementation
label: code-design
cleared before entering catch part
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
comment: XXX: ignored now
label: code-design
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
* Automatically generated by extract_caseconv.py, do not edit!
* Support functions for duk_heap.
DUK_HCOMPILEDFUNCTION_H_INCLUDED
write_to_array_part:
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
E5 Section 15.5.5.1
own pointer
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
# total registers target function wants on entry (< 0 => never for ecma calls)
bytecode has a stable pointer
* Thread builtins
overwrite str1
comment: XXX: exposed duk_debug_read_buffer
label: code-design
DUK_JS_BYTECODE_H_INCLUDED
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
no need for refcount update
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
compiler ensures this
[... old_result result] -> [... result]
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
* concat()
different memory layout, alloc size, and init
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
default: NULL, length 0
env is closed, should be missing _Callee, _Thread, _Regbase
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
force_flag
Used for minimal 'const': initializer required.
* Table for base-64 encoding
Note: no allocation pressure, no need to check refcounts etc
args incorrect
write on next loop
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
2nd related value (type specific)
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
cannot grow
0=indexOf, 1=lastIndexOf
bump up "allocated" reg count, just in case
Strict standard behavior, ignore trailing elements for
* result 'length'.
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
DUK_TOK_IF
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
Working with the pointer and current size.
object has any exotic behavior(s)
DUK_USE_STRTAB_PROBE
written by a previous RESUME handling
comment:
* Macro support functions (use only macros in calling code)
label: code-design
string 1 of token (borrowed, stored to ctx->slot1_idx)
comment: XXX: more accurate?
label: code-design
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
level string
sufficient for keeping temp reg numbers in check
All other object types.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
mixed endian
min_new_size
length in bytes (not counting NUL term)
No finalizers for ROM objects
last element that was left in the heap
compact; no need to seal because object is internal
0x90...0x9f
const flag for C
[... obj] -> [...]
number of pairs in current MPUTOBJ set
escaped NonEscapeCharacter
Module id requested
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
Never executed if new size is smaller.
'protected'
because arg count is 1
'if'
finally free the struct itself
!DUK_USE_PARANOID_ERRORS
Array or Array-like
coerce towards zero
must not be extensible
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
mark-and-sweep: finalizable (on current pass)
[ ... replacer match [captures] match_char_offset input ]
DUK_OP_TRYCATCH flags in A
single string token
Use byte copy.
Most common cases first.
no point in supporting encodings of 5 or more bytes
'|'
use_prev_pc
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
Return value handling.
Enable DUKFUNC exotic behavior once properties are set up.
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
Assumes that caller has normalized NaNs, otherwise trouble ahead.
0x00: finish (not part of number)
* 0x01: continue
comment: this is relatively expensive
label: code-design
num_values and temp_start reset at top of outer loop
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
specific assert for wrapping
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
bits 2...5: type
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
'toUTCString'
Note: no need to re-lookup tv, conversion is side effect free
require.id of current module
low 32 bits is complete
time when status/peek was last done (Date-based rate limit)
[obj key value desc value]
'caller'
rbp_flags
'data'
'type'
comment: XXX: shared strings
label: code-design
-> [ ... source ]
default value
output 3 bytes from 't'
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
loop iterator init and limit changed from standard algorithm
enum_flags
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
by default, use caller's environment
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
value resides in 'valstack_idx'
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
free inner references (these exist e.g. when external
* strings are enabled)
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
surrogate pairs get encoded here
11: getUTCMonth
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
assert just a few critical flags
correction
default to false
* Stack slice primitives
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> []
DUK_USE_STRHASH_DENSE
* Get old and new length
clipped codepoint
h_new_proto may be NULL
-> [ ... errhandler errval ]
this is the case for normalized numbers
flags: "gim"
Starting from this round, use emergency mode
* for mark-and-sweep.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
* Found existing own or inherited plain property, but original
* base is a primitive value.
optional callstack level
e.g. duk_push_string_file_raw() pushed undefined
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
'error'
don't throw for prototype loop
(< (* r 2) s)
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
Note: not set in template (has no "prototype")
unreferenced w/o asserts
if (is_repl_func)
precision:shortest
don't resize stringtable (but may sweep it); needed during stringtable resize
Write curr_pc back for the debugger.
Note: duk__dec_req_stridx() backtracks one char
'length'
-> [ ... val retval ]
Object property access
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
3
Apply timezone offset to get the main parts in UTC
* Zero sign, see misc/tcc_zerosign2.c.
* Boolean built-ins
LeftHandSideExpression does not allow empty expression
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
Note: escaped characters differentiate directives
defaults, E5 Section 8.6.1, Table 7
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
special RegExp literal handling after IdentifierName
XXX: byte offset?
'switch'
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
avoid side effects
result in csreg
* Other heap related defines
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
strict: non-deletable, non-writable
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
use fallback as 'this' value
Caller has already eaten the first character ('(') which we don't need.
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
C recursion check.
b
Misc
catches EOF (0x00)
comment: XXX: duk_get_length?
label: code-design
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
'defineProperty'
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
marker for detecting internal "double faults", see duk_error_throw.c
three flags
No difference between raw/ensure because the buffer shrinks.
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
Start filling in the activation
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
prevent duk__expr_led() by using a binding power less than anything valid
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
[ ... proplist enum_obj key val ]
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
shrink failure is not fatal
!(l < p)
valstack index of loop detection object
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
yes -> move back to heap allocated
strict flag for putvar comes from our caller (currently: fixed)
catchstack limits
* Manually optimized number-to-double conversion
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
[ ... enum_target res trap_result val true ]
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
important for callers
fail
[ sep ToObject(this) len ]
DUK_TOK_PERIOD
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
idx_reviver
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
signed shift
Impose a string maximum length, need to handle overflow
* correctly.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
bytes left
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
failed
-> [... key]
comment: Tested: not faster on x64
label: code-design
clamp to 10 chars
* "LineTerminator" production check.
A lightfunc might also inherit a .toJSON() so just bail out.
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
comment: XXX: inefficient; block insert primitive
label: code-design
* Exposed helper for setting up heap longjmp state.
in non-packed representation we don't care about which NaN is used
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
zero
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
comment: XXX: tostring?
label: code-design
'func' wants stack "as is"
* Debug message processing
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
* Sweep heap
Object.keys
map is reachable through obj
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
required for rehash to succeed, equality not that useful
DUK_TOK_CLASS
comment: unused for label
label: code-design
'this' binding shouldn't matter here
comment: remove old value
label: code-design
comment: get rid of the strings early to minimize memory use before intern
label: code-design
always in entry part, no need to look up parents etc
* Raw intern and lookup
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
CONDITIONAL EXPRESSION
swap elements; deal with non-existent elements correctly
[ ... closure/error ]
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
ignore
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
vararg function, thisArg needs special handling
Assert for value stack initialization policy.
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
curr_token slot1 (matches 'lex' slot1_idx)
eat 'break' or 'continue'
zero-based -> one-based
roughly 512 bytes
* indexOf() and lastIndexOf()
DUK_USE_HEAPPTR16
regexp literal must not follow this token
qmin and qmax will be 0 or 1
same as during entry
Have a catch variable.
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
Object property allocation layout
Node.js accepts only actual Arrays.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
* Actual Object.defineProperty() default algorithm.
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
'class'
compare: similar to string comparison but for buffer data.
Note: if 'x' is zero, x->n becomes 0 here
Debugger protocol version is defined in the public API header.
not undefined
Endianness indicator
number of activation records in callstack preventing a yield
DUK_TOK_IMPLEMENTS
4'294'967'295
XXX: switch cast?
'trace'
array 'length' is always a number, as we coerce it
NULL is allowed, no output
* Convert duk_compiler_func to a function template
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
eat closing slash
* Regexp range tables
Value stack intentionally mixed size here.
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
hobject property layout
comment: UNUSED, intentionally empty
label: code-design
double quote or backslash
track utf-8 non-continuation bytes
[ hobject props enum(props) ]
22 to 31
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
-> [... enum key enum_target val]
constants arbitrary, chosen for small loads
reset 'allow_in' for parenthesized expression
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
if present, forces 16-byte duk_tval
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
exports (this binding)
disabled
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
read-only values 'lifted' for ease of use
return value
'source'
'clog'
digits
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
is_frozen
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
if duk_uint32_t is exactly 32 bits, this is a NOP
* Not found as a concrete property, check whether a String object
* virtual property matches.
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
off >= step, and step >= 1
zero-width joiner
Rethrow error to calling state.
'"'
next temporary register to allocate
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
relookup after side effects (no side effects currently however)
Note: this order matters (final value before deleting map entry must be done)
'arguments'
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
inline arithmetic check for constant values
pre-incremented, points to first jump slot
* Helpers for duk_compiler_func.
Note: need to re-lookup because ToNumber() may have side effects
expr_flags
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
accept string
unreferenced without assertions
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
'toString'
first character has been matched
0xfff0 is -Infinity
comment: XXX: don't want to shrink allocation here
label: code-design
-> [ ... error ]
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
curr_token follows 'function'
* Update preventcount
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
'toJSON'
function executes as a constructor (called via "new")
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
DUK_ERROR_H_INCLUDED
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
if 1, doing a fixed format output (not free format)
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
borrowed; NULL if no step state (NULLed in unwind)
new buffer with string contents
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
no regexp instance should exist without a non-configurable bytecode property
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
replaces top of stack with new value if necessary
33: setUTCDate
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
eat 'for'
init 'curr_token'
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
implicit attributes
allow a constant to be returned
prop index in 'entry part', < 0 if not there
add_auto_proto
[ ... ToObject(this) ToUint32(length) val ]
Load bytecode instructions.
unsupported: would consume multiple args
DUK_USE_DEBUGGER_THROW_NOTIFY
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
There's intentionally no check for
* current underlying buffer length.
follow parent chain
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
comment: XXX: this should be an assert
label: test
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
No debugger support, just pop values.
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
[ hobject props enum(props) key desc value? getter? setter? ]
start match from beginning
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
DUK_USE_SECTION_B
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
comment: XXX: better to get base and walk forwards?
label: code-design
'ownKeys'
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
restore stack top
DUK_USE_BASE64_FASTPATH
Valstack should suffice here, required on function valstack init
duk_hnativefunction specific fields.
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Insert bytes in the middle of the buffer from an external buffer.
identifier names (E5 Section 7.6)
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
keep heap->dbg_detached_cb
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
During parsing, month and day are one-based; set defaults here.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
token allows automatic semicolon insertion (eof or preceded by newline)
Use special opcodes to load short strings
* Add .fileName and .lineNumber to an error on the stack top.
* CommonJS require() and modules support
* Lexing helpers
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
explicit PropertyList
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
* Create mantissa
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
ToNumber() for a fastint is a no-op.
[key] -> [undefined] (default value)
traceback depth fits into 16 bits
[ thisArg arg1 ... argN func boundFunc argArray ]
* Parser duk__advance() token eating functions
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
Same as above but for unsigned int range.
comma after a value, expected
duplicate key
Given a day number, determine year and day-within-year.
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
Success path handles
comment: XXX: getter with class check, useful in built-ins
label: code-design
already updated
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
match: keep saves
DUK_USE_PARANOID_MATH
'boolean'
* Debugging disabled
fixed offset in valstack
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
* Proxy helpers
* Found; post-processing (Function and arguments objects)
maps to finalizer 2nd argument
DUK_USE_AVOID_PLATFORM_FUNCPTRS
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
key encountered as a plain property
e.g. DUK_OP_POSTINCV
Allow empty string to be interpreted as 0
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
not minimum exponent
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
Because new_size > duk__count_used_probe(heap), guaranteed to work
bump refcount to prevent refzero during finalizer processing
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_string()
pointers for scanning
array part size (entirely gc reachable)
Steps 12 and 13: reorganize elements to make room for itemCount elements
number of tokens parsed
Tear down state.
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
zero handled by caller
Don't accept relative indices now.
[holder name val] -> [holder]
res_obj
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
function declaration
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
'?'
state == 3
Maximum traversal depth for "bound function" chains.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
[ thread value ]
* GETPROP: Ecmascript property read.
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
object is a thread (duk_hthread)
'info'
add a new pending split to the beginning of the entire disjunction
duk_push_this() + CheckObjectCoercible() + duk_to_object()
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
this may have side effects, so re-lookup act
Fall through to handle the rest.
[ ... error lineNumber fileName ]
* Number built-ins
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
-> [ ... closure template env ]
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
6: toUTCString
comment: note: ctx-wide temporary
label: code-design
value popped by call
Note: this may fail, caller should protect the call if necessary
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
4
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
s <- 2 * b
native functions: 149
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
exponent 1070
no need to reset temps, as we're finished emitting code
DUK_ERR_ERROR: no macros needed
comment: XXX: assumed to fit for now
label: code-design
[... fallback retval]
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
Getter might have arbitrary side effects,
* so bail out.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
-> [ ... voidp voidp ]
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
special helper for emitting u16 lists (used for character ranges for built-in char classes)
[ ... re_obj input bc saved_buf ]
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
Parser separator indices.
Regexp
k > 0 -> k was too low, and cannot be too high
'func' in the algorithm
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
Outside any activation -> look up from global.
Decrease by 25% every round
For manual testing only.
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
* Main heap structure
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
E5 Section 9.2
Backtrack utf-8 input and return a (possibly canonicalized) input character.
Cause an interrupt after executing one instruction.
Compiler
at least errobj must be on stack
16 bits
* Default panic handler
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
'modSearch'
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
does not fit into 16 bits
ensures no overflow
[ ... input buffer ]
execution resumes in bytecode executor
Standard JSON omits functions
7 bits
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
* Objects have internal references. Must finalize through
* the "refzero" work list.
different thread
number of values in current MPUTARR set
steps 13-14
Compute result length and validate argument buffers.
DUK_BUILTINS_H_INCLUDED
copy bytecode instructions one at a time
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
[ ... RegExp val ] -> [ ... res ]
load factor max 75%
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
* Resizing
token closes expression, e.g. ')', ']'
fileName
* Get prototype object for an integer error code.
'\xffNext'
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
borrow literal Infinity from builtin string
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
prefer direct execution
comment: Longjmp state is cleaned up by error handling
label: code-design
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
fall-through jump to next code of next case (backpatched)
already one-based
comment: XXX: could use at least one fewer loop counters
label: code-design
Create function 'data' buffer but don't attach it yet.
* Function built-ins
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
comment: hacky helper for String.prototype.split()
label: code-design
[ (builtin objects) name func ]
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
toString() conditions
Write bytecode executor's curr_pc back to topmost activation (if any).
[] -> [val]
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
-> [ sep ToObject(this) len sep str ]
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
[ ... enum_target res handler trap ]
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
x <- (1<<y)
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
Any 'res' will do.
If neutered must return 0; length is zeroed during
* neutering.
XXX: assert idx_base
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
avoid side effect issues
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
SHIFT EXPRESSION
overflow, fall through
restored if ecma-to-ecma setup fails
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
If debugger is paused, garbage collection is disabled by default.
DUK_ERR_REFERENCE_ERROR: no macros needed
XXX: shared helper for duk_push_hobject_or_undefined()?
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
unconditionally
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
resumee
* Parse a function body or a function-like expression, depending
* on flags.
actually used, non-NULL entries
Fast path check.
length check
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
'{"_ninf":true}'
shared checks for all descriptor types
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
* Process space (3rd argument to JSON.stringify)
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
DUK_USE_PANIC_HANDLER
avoid array abandoning which interns strings
traits are separate; in particular, arguments not an array
duk__get_min_grow_a() is always >= 1
9: getUTCFullYear
[key getter this key] -> [key retval]
Source end clamped silently to available length.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
* Proxy built-in (ES6)
Native function, no relevant lineNumber.
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
'res' must be a plain ivalue, and not register-bound variable.
function helpers
'Null'
internal properties
custom
* XXX: shrink array allocation or entries compaction here?
ToInteger(lastIndex)
* Encoding/decoding helpers
default: NaN
covers -Infinity
Error instance, use augmented error data directly
t1 = (+ r m+)
[... func arg1 ... argN]
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
variable value (function, we hope, not checked here)
return 'res_obj'
E5 Section 10.4.2
DUK_FORWDECL_H_INCLUDED
avoid unary minus on unsigned
Just flip the single bit.
unicode code points, window[0] is always next, points to 'buffer'
probe
may be set to 0 by duk_debugger_attach() inside callback
Easy to get wrong, so assert for it.
mask out flags not actually stored
'with' target must be created first, in case we run out of memory
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
Important main primitive.
no throw
[ ... lval rval(func) ]
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
'lastIndex'
0xd0-0xdf
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
pop varname
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
debugger
* Automatically generated by extract_chars.py, do not edit!
* Copy keys and values in the entry part (compacting them at the same time).
expensive init, just want to fill window
'toLogString'
split2: prefer jump execution (not direct)
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
skip line info
heap destruction ongoing, finalizer rescue no longer possible
E5 Section 9.1
value stack indices for tracking objects
two encoding attempts suffices
DUK_ISPEC_XXX
comment: XXX: append primitive
label: code-design
current lexical environment (may be NULL if delayed)
explicit NULL inits
[ ... closure template env ]
use a temp: decref only when valstack reachable values are correct
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
0 or -1
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
Object.defineProperty() equivalent C binding.
skip jump slots
We can directly access value stack here.
DUK_TOK_TYPEOF
mark as complex
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
comment: m+ != m- (very rarely)
label: code-design
* Duktape debugger
Ecmascript activation + Duktape.Thread.resume() activation
'\''
[ ... str ]
-> [ ... value ]
Use temporaries and update lex_ctx only when finished.
mark-and-sweep not running -> must be empty
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_TOK_EXPORT
array of active label names
* Helper for C function call negative return values.
entry_top + 0
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
Shared helper.
x1 must be a string
[ ... value? getter? setter? ]
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
Gather in big endian
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
format is bit packed
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
parse args starting from "next temp", reg_target + 1
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
* Context init
comment: XXX: rework
label: code-design
Call stack. [0,callstack_top[ is GC reachable.
DUK_NUMCONV_H_INCLUDED
is a function declaration (as opposed to function expression)
Precomputed pointers when using 16-bit heap pointer packing.
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
= IsAccessorDescriptor(Desc)
36: setFullYear
comment: not covered, return all zeroes
label: test
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
DUK_HTHREAD_H_INCLUDED
DUK_USE_ES6_PROXY
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Pretend like we got EOM
[ regexp source bytecode ]
catch depth at point of definition
-> [... cons target]
Grow entry part allocation for one additional entry.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
comment: XXX: better multiline
label: code-design
object literal key tracking flags
curr is accessor -> cannot be in array part
stmt has explicit/implicit semicolon terminator
lexing
[ ... result/error ]
catches EOF (NUL) and initial comma
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
currently running thread
temproots
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
vararg
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
Allow NULL 'msg'
borrowed reference
[... s1 s2] -> [... s1+s2]
DUK_TOK_DIV
comment: XXX: lithuanian not implemented
label: requirement
Explicit zero size check to avoid NULL 'tv1'.
* Get holder object
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
lead zero + 'digits' fractions + 1 for rounding
stack discipline consistency check
* Update the interrupt counter
these non-standard properties are copied for convenience
still reachable
* Forward declarations for all Duktape structures.
[ ... obj key ]
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
* Macros for property handling
val2 = min count, val1 = max count
find and remove string from stringtable; caller must free the string itself
Inner functions recursively.
== DUK__MAX_TEMPS is OK
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
use bigint area as a temp
'n'
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
step 4.b
(Number.MAX_VALUE).toString(2).length == 1024, + spare
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
Catch stack. [0,catchstack_top[ is GC reachable.
DUK_USE_DATE_TZO_WINDOWS
-> [ ... res_obj ]
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
flags is unsigned
0
comment: XXX: better place for this
label: code-design
Zero encoded pointer is required to match NULL
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
upper limit, assuming no whitespace etc
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
comment: not necessary to init, disabled for faster parsing
label: code-design
We already ate 'x', so backup one byte.
maximum token count before error (sanity backstop)
* For ASCII strings, the answer is simple.
'super'
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
'JSON'
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
marker: copy t if not changed
thread has terminated
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
* Duktape public API for Duktape 1.5.2.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
* Git branch HEAD.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
internal flag value: throw if mask doesn't match
set getter (given on value stack)
no error if file does not exist
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
* Buffer
maximum size check is handled by callee
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
Load constants onto value stack but don't yet copy to buffer.
-> [ func funcname env ]
_Formals
Setup function properties.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
_Varmap is dense
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
skip line info
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
end of _Formals
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
buffer limits
Inner functions recursively.
known to be number; in fact an integer
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
Bytecode instructions: endian conversion needed unless
* platform is big endian.
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
duk_hcompiledfunction flags; quite version specific
standard prototype
Load bytecode instructions.
string limits
no side effects
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
comment: known to be 32-bit
label: code-design
Fixed header info.
constants are strings or numbers now
Create function 'data' buffer but don't attach it yet.
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
DUK_USE_BYTECODE_DUMP_SUPPORT
ensures no overflow
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
_Varmap
-> [ func funcname env funcname func ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
Constants: variable size encoding.
Return with final function pushed on stack top.
[ ... func buf ] -> [ ... buf ]
[ ... buf func ] -> [ ... func ]
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
may be NULL if no constants or inner funcs
assert just a few critical flags
Load inner functions to value stack, but don't yet copy to buffer.
comment: XXX: awkward
label: code-design
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
Important to do a fastint check so that constants are
* properly read back as fastints.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
Explicit zero size check to avoid NULL 'tv1'.
func.prototype.constructor = func
end of _Varmap
-> [ func funcname env funcname ]
-> [... cons target]
noblame_fileline
[... func this arg1 ... argN]
thread
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
num_stack_res
class Object, extensible
note that we can't reliably pop anything here
[... retval]
Strict by default.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
num_stack_args
nrets
Anything else is not constructable.
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
not protected, respect reclimit, is a constructor call
respect reclimit, not constructor
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
comment: XXX: code duplication
label: code-design
not protected, respect reclimit, not constructor
pop final_cons
[... fallback retval]
-> [... target]
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
make absolute
use fallback as 'this' value
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Lightfuncs cannot be bound.
* Call the constructor function (called in "constructor mode").
[... key arg1 ... argN]
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
[... constructor arg1 ... argN final_cons]
See comments in duk_pcall().
because callstack_top > 0
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
call_flags
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
must work for nargs <= 0
* Duktape/C function magic
fall through
unreachable
awkward; we assume there is space for this
[... key arg1 ... argN func]
func
Note: -nargs alone would fail for nargs == 0, this is OK
[... constructor arg1 ... argN]
also stash it before constructor,
* in case we need it (as the fallback value)
nargs
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
[... func arg1 ... argN]
[... constructor arg1 ... argN final_cons fallback]
duplicate key
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
* Manipulate callstack for the call.
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
-------- ----XXXX
output 3 bytes from 't'
XX==
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Fixed buffer, no zeroing because we'll fill all the data.
allowed ascii whitespace
full 3-byte -> 4-char conversions
allow basic ASCII whitespace
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
XXX=
read 3 bytes into 't', padded by zero
back to fast loop
never here
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
Backtrack.
idx_value
idx_space
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
------XX XXXX----
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
DUK_USE_HEX_FASTPATH
pointer is aligned, guaranteed for fixed buffer
Don't allow actual chars after equal sign.
Continue parsing after padding, allows concatenated,
* padded base64.
case 0: nop
XXXXXX--
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
Handle one slow path unit (or finish if we're done).
idx_reviver
Check if any lookup above had a negative result.
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
two level break
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
Don't allow mixed padding and actual chars.
------XX
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
invalid padding
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
aaaaaabb bbbbcccc ccdddddd
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
upper limit, assuming no whitespace etc
checked by caller
shift in zeroes
idx_replacer
Fast path, handle units with just actual encoding characters.
comment: XXX: convert to fixed buffer?
label: code-design
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment: There may be whitespace between the equal signs.
label: code-design
XXXXXX-- --------
comment: Tested: not faster on x64
label: code-design
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
DUK_USE_BASE64_FASTPATH
flags
Note: for dstlen=0, dst may be NULL
Note: for srclen=0, src may be NULL
* Compilation and evaluation
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
Helper which can be called both directly and with duk_safe_call().
[ ... source? func_template ]
[ ... source? filename? ]
add_auto_proto
[ ... closure/error ]
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
[ ... result/error ]
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
[ ... source? filename? ] (depends on flags)
[ ... func_template ]
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
e.g. duk_push_string_file_raw() pushed undefined
should be first on 64-bit platforms
Automatic filename: 'eval' or 'input'.
[ ... source? filename? &comp_args ] (depends on flags)
explicit 'this' binding, see GH-164
[ ... closure ]
comment: XXX: unnecessary translation of flags
label: code-design
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
Eval is just a wrapper now.
args incorrect
may be safe, or non-safe depending on flags
-> [ ... closure ]
[ ... source? filename ]
Treat like debugger statement: nop
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
idx_value
idx_space
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
Other callbacks are optional.
nop
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
DUK_USE_DEBUGGER_SUPPORT
Start in paused state.
no_block
No debugger support, just pop values.
idx_replacer
unreachable
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Treat like a debugger statement: ignore when not attached.
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Debugging related API calls
flags
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
Can be called multiple times with no harm.
[ ... new_glob new_env ]
side effects, in theory (referenced by global env)
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
* Heap creation and destruction
[ ... new_glob new_env new_glob new_glob ]
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
side effects
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
[ ... ]
* Replace global object.
comment: XXX: better place for this
label: code-design
no prototype, updated below
without refcounts
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
sometimes stack and array indices need to go on the stack
[key val] -> []
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
[val] -> []
comment: XXX: assumed to fit for now
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_object()
only needed by debugger for now
* Internal API calls which have (stack and other) semantics similar
* to the public API.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
[] -> []
duk_push_sprintf constants
comment: XXX: add fastint support?
label: requirement
This would be pointless: unexpected type and lightfunc would both return NULL
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
DUK_API_INTERNAL_H_INCLUDED
Set object 'length'.
duk_push_this() + CheckObjectCoercible() + duk_to_string()
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
[] -> [val]
Valstack resize flags
out_clamped=NULL, RangeError if outside range
comment: unused
label: code-design
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
[ ... Logger clog logfunc clog(=this) msg ]
nargs
[ ... Logger clog logfunc clog ]
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
[ ... Logger clog res ]
* Memory calls.
NULL accepted
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
* Helpers for writing multiple properties
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
remove key and value
[ ... obj ... ]
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
* Object finalizer
proto can also be NULL here (allowed explicitly)
a value is left on stack regardless of rc
pop key
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
Object.defineProperty() equivalent C binding.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
defprop_flags
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
XXX: shared helper for duk_push_hobject_or_undefined()?
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
* Object handling: property access and other support functions.
remove key
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
value popped by call
1 if property found, 0 otherwise
comment: XXX: "read only object"?
label: code-design
[ ... global val ] -> [ ... global ]
Note: this may fail, caller should protect the call if necessary
comment: XXX: direct implementation
label: requirement
comment: Clean up stack
label: code-design
[target] -> [enum]
* Object prototype
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
* Shortcut for accessing global object properties
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Maximum value check ensures 'nbytes' won't wrap below.
DUK_BUFOBJ_UINT32ARRAY
throw_flag
only flag now
DUK_USE_VARIADIC_MACROS
E5 Section 9.1
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
consequence of above
Never executed if new size is smaller.
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
comment:
* Global state for working around missing variadic macros
label: code-design
use a temp: decref only when valstack reachable values are correct
Note: recursive call
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Should match Function.prototype.toString()
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
Assert for value stack initialization policy.
val is unsigned so >= 0
important to do this *after* pushing, to make the thread reachable for gc
!DUK_USE_PARANOID_ERRORS
initial estimate based on format string
no need to incref
coerce towards zero
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
Non-critical.
default: false
success, fixup pointers
Coerce top into Object.prototype.toString() output.
* Misc helpers
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: XXX: several pointer comparison issues here
label: code-design
must be computed after realloc
side effects
number
radix
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
get pointer offsets for tweaking below
zero size not an issue: pointers are valid
DUK_BUFOBJ_INT8ARRAY
advance manually
out_clamped==NULL -> RangeError if outside range
not reached
because of valstack init policy
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
ensure value is 1 or 0 (not other non-zero)
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
object is now reachable
4 low bits
* Pushers
quotes
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
comment: XXX: string not shared because it is conditional
label: code-design
E5 Section 8.12.8
'd' and 'res' agree here
XXX: direct valstack write
Creation time error augmentation
filename may be NULL in which case file/line is not recorded
Check for maximum buffer length.
Incref copies, keep originals.
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
'undefined' already on stack top
unsigned
covers +Infinity
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
avoid warning (unsigned)
default prototype (Note: 'obj' must be reachable)
everything except object stay as is
flags
Enable DUKFUNC exotic behavior once properties are set up.
DUK_BUFOBJ_UINT8ARRAY
may be NULL
comment: No coercions or other side effects, so safe
label: requirement
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_BUFOBJ_DATAVIEW
If tv1==tv2 this is a NOP, no check is needed
* Basic stack manipulation: swap, dup, insert, replace, etc
No net refcount change.
comment: XXX: shorter version for 12-byte representation?
label: code-design
special handling of fmt==NULL
specific assert for wrapping
Clamping only necessary for 32-bit ints.
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
DUK_BUFOBJ_UINT8CLAMPEDARRAY
caller required to know
ANSI C typing
as is
Only allow Duktape.Buffer when support disabled.
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
Explicit length is only needed if it differs from 'nargs'.
DUK_BUFOBJ_FLOAT64ARRAY
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
inline initializer for coercers[] is not allowed by old compilers like BCC
comment: XXX: duk_ssize_t would be useful here
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
no shrink
nop: insert top to top
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
periods
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
Nothing to initialize, strs[] is in ROM.
[ ... parent stash stash ] -> [ ... parent stash ]
if slice not fully valid, treat as error
Note: no need to re-lookup tv, conversion is side effect free
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
DUK_BUFOBJ_ARRAYBUFFER
check stack first
[ ... retval ]; popped below
tv points to element just below prev top
comment: XXX: fastint?
label: code-design
dynamic
DUK_USE_FILE_IO
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
ignore fclose() error
DUK_BUFOBJ_FLOAT32ARRAY
not reachable
coerced value is updated to value stack even when RangeError thrown
error gets its 'name' from the prototype
no side effects
shrink case; leave some spare
'this' binding exists
may be NULL (but only if size is 0)
failed, resize and try again
* Poppers
-> [ ... func this ]
comment: not very useful, used for debugging
label: code-design
* Lightfunc
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
Not halfway, round to nearest.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
make the new thread reachable
comment: copied so that 'ap' can be reused
label: code-design
estimate is valid
* Comparison
DUK_USE_REFERENCE_COUNTING
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
[ ... func ]
nrets
Error code also packs a tracedata related flag.
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
allow fmt==NULL
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
DUK_BUFOBJ_NODEJS_BUFFER
Stack size increases or stays the same.
Exact halfway, round to even.
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
Clamping needed if duk_int_t is 64 bits.
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
!DUK_USE_PREFER_SIZE
Error: try coercing error to string once.
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
DUK_USE_FASTINT
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
sanity limit for function pointer size
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
* Error throwing
can't resize below 'top'
-> [ ... retval ]
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
shared flags for a subset of types
round up roughly to next 'grow step'
Custom coercion for API
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
tv -> value just before prev top value; must relookup
Init newly allocated slots (only).
default: NULL, length 0
* instanceof
Assume value stack sizes (in elements) fits into duk_idx_t.
useful for debugging
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
valstack limit caller has check, prevents wrapping
default: NaN
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
Negative indices are always within allocated stack but
* must not go below zero index.
covers -Infinity
* Get/require
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
Note: number has no explicit tag (in 8-byte representation)
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
Same as above but for unsigned int range.
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
check stack before interning (avoid hanging temp)
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
* Stack slice primitives
comment: unused
label: code-design
normalize NaN which may not match our canonical internal NaN
* Value stack top handling
check_object_coercible
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
Note: this allows creation of internal strings.
Check for maximum string length
E5 Section 9.2
force_exponential
DUK_INVALID_INDEX won't be accepted as a valid index.
only needed by debugger for now
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
DUK_USE_BUFFEROBJECT_SUPPORT
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
* Forward declarations
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
For tv1 == tv2, this is a no-op (no explicit check needed).
require
comment: XXX: typing
label: code-design
Use unsigned arithmetic to optimize comparison.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
Return value of 'sz' or more indicates output was (potentially)
* truncated.
DUK_BUFOBJ_INT32ARRAY
nop
Faster but value stack overruns are memory unsafe.
E5 Section 9.4, ToInteger()
Note: need to re-lookup because ToNumber() may have side effects
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Type checking
Double error
no compact
w/o refcounting
[ ... func/retval ] -> [ ... ]
Special coercion for Uint8ClampedArray.
flags is unsigned
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
comment: XXX: optimize loops
label: code-design
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
tagged null pointers should never occur
no throw
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
initialize built-ins - either by copying or creating new ones
may throw an error
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: XXX: size optimize
label: code-design
comment: NUL terminator handling doesn't matter here
label: code-design
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
Stack size decreases.
format plus something to avoid just missing
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
unreachable
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
comment: XXX: duk_ssize_t
label: code-design
... and its 'message' from an instance property
DUK_BUFOBJ_DUKTAPE_BUFFER
DUK_BUFOBJ_UINT16ARRAY
nargs
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
[ buf? res ]
Avoid NaN-to-integer coercion as it is compiler specific.
no prototype
Check that there's room to push one value.
Note: 'q' is top-1
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
min_new_size
since index non-negative
not popped by side effect
precision:shortest
'this' binding is just before current activation's bottom
[... (sep) str1 str2 ... strN buf]
no size check is necessary
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
overwrite str1
extra -1 for buffer
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Combined size of separators already overflows
[... buf]
always true, arg is unsigned
start (incl) and end (excl) of trimmed part
[... res]
Impose a string maximum length, need to handle overflow
* correctly.
overwrite sep
guaranteed by string limits
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
entire string is whitespace
A bit tricky overflow test, see doc/code-issues.rst.
* String manipulation
pointers for scanning
wrapped
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
is_join
comment: get rid of the strings early to minimize memory use before intern
label: code-design
reasonable output estimate
* Variable access
[ ... val ]
always throw ReferenceError for unresolvable
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
[ ... varname val ]
comment: XXX: tostring?
label: code-design
[ ... ]
[ ... varname val this ] (because throw_flag == 1, always resolved)
-> [ ... varname val this ]
Outside any activation -> put to global.
Outside any activation -> look up from global.
-> [ ... val retval ]
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
stack top contains 'false'
Steps 12 and 13: reorganize elements to make room for itemCount elements
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
swap elements; deal with non-existent elements correctly
move pivot to its final place
return ToObject(this)
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
-> [ sep ToObject(this) len str ]
end of loop (careful with len==0)
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
for lastIndexOf, result may be -1 (mark immediate termination)
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
For now, restrict result array into 32-bit length range.
avoid degenerate cases, so that (len - 1) won't underflow
* shift()
fixed offsets in valstack
k+argCount-1; note that may be above 32-bit range
intermediate join to avoid valstack overflow
orig value
fromPresent = true
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
right exists, [[Put]] regardless whether or not left exists
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
topmost element is the result array already
-> [ sep ToObject(this) len sep str ]
[ ToObject(this) item1 ... itemN arr ]
The lo/hi indices may be crossed and hi < 0 is possible at entry.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
[ sep ToObject(this) len sep result ]
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
comment: XXX: best behavior for real world compatibility?
label: code-design
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
-> [ ... toLocaleString ToObject(val) ]
Note that 'l' and 'r' may cross, i.e. r < l
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
-> [ ... ToObject(this) ToUint32(length) ]
trivial cases
find elements to swap
args start at index 2
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
[ ... ToObject(this) ToUint32(length) val ]
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
stack top contains 'true'
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
Step 9: copy elements-to-be-deleted into the result array
retval is directly usable
result array is already at the top of stack
has access to 'this' binding
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
* splice()
* isArray()
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
Debug print which visualizes the qsort partitioning process.
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
-> [ sep ToObject(this) len str sep ]
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
* indexOf(), lastIndexOf()
move pivot out of the way
comment: XXX: must be able to represent -len
label: code-design
* reverse()
!(l < p)
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
result index for filter()
loop iterator init and limit changed from standard algorithm
[ ... val callback thisArg val i obj ]
!(p < r)
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
Perform an intermediate join when this many elements have been pushed
* on the value stack.
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
string compare is the default (a bit oddly)
* pop(), push()
[ arg1 ... argN obj length new_length ]
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
no need to check callable; duk_call() will do that
if thisArg not supplied, behave as if undefined was supplied
* reduce(), reduceRight()
[ sep ToObject(this) len ]
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
-> [ ... fn x y ]
-> [ ... res ]
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
idx_step is +1 for indexOf, -1 for lastIndexOf
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
* concat()
[ sep ToObject(this) len sep str0 ... str(count-1) ]
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
[ ... func this ]
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
idx_step is +1 for reduce, -1 for reduceRight
The extra (+4) is tight.
-> [ ToObject(this) ]
[ sep ToObject(this) len sep ]
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
randomized pivot selection
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
* slice()
* unshift()
retval to result[i]
* Constructor
if true, the stack already contains the final result
* every(), some(), forEach(), map(), filter()
* toString()
Strict standard behavior, ignore trailing elements for
* result 'length'.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
fixed offset in valstack
rnd in [lo,hi]
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
nop
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
We're a varargs function because we need to detect whether
* initialValue was given or not.
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
[ arg1 ... argN obj length ]
throw flag irrelevant (false in std alg)
Step 15: insert itemCount elements into the hole made above
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
i >= 0 would always be true
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
fromPresent = false
-> [ ... x y fn ]
[ ... this func ]
each call this helper serves has nargs==2
-> [ ToObject(this) item1 ... itemN arr ]
[ ToObject(this) item1 ... itemN arr item(i) ]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
XXX: proper flags?
* Boolean built-ins
unbalanced stack
-> [ val obj val ]
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
* Duktape.Buffer: toString(), valueOf()
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
reachable so pop OK
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
throw_flag
comment: XXX: encoding is ignored now.
label: code-design
This behavior mostly mimics Node.js now.
nargs
Fast path: source is a TypedArray (or any bufferobject).
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
Don't accept relative indices now.
bits 0...1: shift
default is explicit index read/write copy
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
[ offset noAssert ], when ftype != DUK__FLD_VARINT
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
Push the resulting view object and attach the ArrayBuffer.
DUK__FLD_32BIT
>= 0
arg count
DUK__FLD_8BIT
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
Array or Array-like
comment: Static call style.
label: code-design
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
sign doesn't matter when writing
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
Write in little endian
[ targetBuffer targetStart sourceStart sourceEnd ]
source starts after dest ends
* Misc helpers
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
Check that value is a duk_hbufferobject and return a pointer to it.
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
byte sizes will match
return h_bufres
Must be element size multiple from
* start offset to end of buffer.
* Node.js Buffer: toString([encoding], [start], [end])
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
new buffer with string contents
XXX: could add fast path for u8 compatible views
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
bytes in dest
Use byte copy.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK__FLD_16BIT
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
avoid side effects!
Node.js accepts only actual Arrays.
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
crossed offsets or zero size
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
Gather in little endian
unsigned
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
comment: XXX: function flag to make this automatic?
label: requirement
XXX: happens e.g. when evaluating: String(Buffer.prototype).
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
DUK__FLD_VARINT; not relevant here
Shared helper.
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
idx_end
may be NULL
-> [ buffer ]
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
Copy values through direct validated reads and writes.
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
Gather in big endian
compare: similar to string comparison but for buffer data.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
use p_src_base from now on
ignore encoding for now
* Node.js Buffer.isBuffer()
* Node.js Buffer.prototype.fill()
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
* Node.js Buffer.isEncoding()
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
1=little endian
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
Not enough data.
Note: start_offset/end_offset can still be < 0 here.
bits 2...5: type
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
Push a new ArrayBuffer (becomes view .buffer)
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
idx_start
should never happen but default here
Now we can check offset validity.
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
inherit
* Node.js Buffer.prototype.copy()
comment: not covered, return all zeroes
label: test
[ value offset end ]
comment:
* Node.js Buffer.concat()
label: code-design
Value stack intentionally mixed size here.
[ array totalLength ]
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
not reachable
* Node.js Buffer.prototype: toJSON()
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
length check
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
Must be >= 0 and multiple of element size.
* Duktape.Buffer: constructor
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
Just skip, leaving zeroes in the result.
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
Byte length would overflow.
Set .buffer
equals
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
Shared offset/length coercion helper.
bytes in source
Source end clamped silently to available length.
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
elems in source and dest
XXX: fast path for array arguments?
either nonzero value is ok
Handle TypedArray vs. Node.js Buffer arg differences
Negative offsets cause a RangeError.
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
offset/value order different from Node.js
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
one i_step added at top of loop
comment: unnecessary div for last byte
label: code-design
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
Ensure copy is covered by underlying buffers.
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
* ArrayBuffer, DataView, and TypedArray constructors
guaranteed by duk_to_string()
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
-> [ array totalLength buf ]
source ends before dest starts
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
source out-of-bounds (but positive)
Map DUK__FLX_xxx to byte size.
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
[ start end ]
[ array totalLength bufres buf ]
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
one i_step over
default to false
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
These are not needed when only Duktape.Buffer is supported.
DUK__FLD_FLOAT
undefined coerces to zero which is correct
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
DUK__FLD_DOUBLE
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
even for zero-length string
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
new buffer of specified size
pop plain buffer, now reachable through h_bufres
Node.js return value for failed writes is offset + #bytes
* that would have been written.
DUK_USE_BUFFEROBJECT_SUPPORT
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
ignore_loop
Shift to sign extend.
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
stack is unbalanced, but: [ <something> buf ]
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
Set .buffer to the argument ArrayBuffer.
comment: unnecessary shift for last byte
label: code-design
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
* ArrayBuffer.isView()
comment: XXX: easier check with less code?
label: code-design
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
* Indexed read/write helpers (also used from outside this file)
* Node.js Buffer: constructor
Write in big endian
replaced
* Node.js Buffer.byteLength()
non-zero: make copy
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
Note: unbalanced stack on purpose
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
Nominal size check.
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Check that 'this' is a duk_hbufferobject and return a pointer to it.
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
as elements
Argument must be a string, e.g. a buffer is not allowed.
target out-of-bounds (but positive)
unbalanced stack on purpose
Compute result length and validate argument buffers.
only accept lowercase 'utf8' now.
Cannot overlap.
Convert indices to byte offsets.
no need to decref
[ ... this ]
stack top: new time value, return 1 to allow tail calls
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
3
Apply timezone offset to get the main parts in UTC
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
8: getFullYear
now expected to fit into a 32-bit integer
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
MakeDate
37: setUTCFullYear
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
Integer division which floors also negative values correctly.
-""-
invalid value which never matches
7
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
Here we'd have the option to normalize -0 to +0.
-> [ O toIsoString O ]
-> [ timeval this timeval ]
Optional UTC conversion.
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
Internal timevalue is already NaN, so don't touch it.
5: toLocaleTimeString
Old solution: don't iterate, incorrect
38: getYear
6
* Other file level defines
zero-based -> one-based
called as a normal function: return new Date().toString()
* ISO 8601 subset parser.
39: setYear
Rule control flags.
1: toDateString
E5.1 Section 15.9.1.6
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
if-digit-else-ctrl
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
Parts are in local time, convert when setting.
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
-> [ ... this ]
16: getHours
Note2
char loop
33: setUTCDate
25: setUTCMilliseconds
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
match against rule part/sep bits
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
Rule table: first matching rule is used to determine what to do next.
flags
fits into duk_small_int_t
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
formatters always get one-based month/day-of-month
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
2: toTimeString
comment: TimeClip() should never be necessary
label: code-design
continue matching, set neg_tzoffset flag
-> [ ... this timeval_new ]
30: setHours
TimeClip(), which also handles Infinity -> NaN conversion
unsigned
zero-based day
34: setMonth
Note: rely on index ordering
Parser part masks.
20: getSeconds
Expects 'this' at top of stack on entry.
28: setMinutes
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
1
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
zero-based month
Parser part count.
6: toUTCString
no argument given -> leave components untouched
msec
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
Matching separator index is used in the control table
don't care value, year is mandatory
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
27: setUTCSeconds
unreferenced with some options
36: setFullYear
-> [ this ]
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
4
21: getUTCSeconds
seconds, doesn't fit into 16 bits
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
may be NaN
3: toLocaleString
17: getUTCHours
22: getMilliseconds
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
12: getDate
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
35: setUTCMonth
Special handling for year sign.
caller checks
24: setMilliseconds
MakeTime
0x08583b00
5
If 'day' is NaN, returns NaN.
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
9: getUTCFullYear
During parsing, month and day are one-based; set defaults here.
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
Different calling convention than above used because the helper
* is shared.
non-leap year: sunday, monday, ...
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* API oriented helpers
11: getUTCMonth
leap year: sunday, monday, ...
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
Note: DST adjustment is determined using UTC time.
handle negative values
32: setDate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
7: toISOString
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
13: getUTCDate
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
2
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
23: getUTCMilliseconds
-> [ timeval this ]
We should never exit the loop above.
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
Parser separator indices.
-> [ ... this timeval_new timeval_new ]
"-123456\0"
rule match
deal with negative values
10: getMonth
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
unpack args
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
Given a day number, determine year and day-within-year.
Parser separator masks.
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
* Constructor calls
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
ignore millisecond fractions after 3
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
15: getUTCDay
This assert depends on the input parts representing time inside
* the Ecmascript range.
comment: XXX: getter with class check, useful in built-ins
label: code-design
get as double to handle huge numbers correctly
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
if no NaN handling flag, may still be NaN here, but not Inf
0: toString
26: setSeconds
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
19: getUTCMinutes
14: getDay
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
* Forward declarations
conservative
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
Compute day number of the first day of a given year.
29: setUTCMinutes
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
"+11:22\0"
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
complete the millisecond field
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
day number for Jan 1 since epoch
-> [ ... this timeval ]
Parser part indices.
no fractions in internal time
no need to mask idx portion
does not fit into 16 bits
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
0
Iteration solution
accept string if next char is NUL (otherwise reject)
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
31: setUTCHours
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
Note1
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
accept string
No platform-specific parsing, this is not an error.
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
4: toLocaleDateString
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
See comments below on MakeTime why these are volatile.
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
E5 Sections 15.9.3.1, B.2.4, B.2.5
tzoffset
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
seconds
18: getMinutes
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
DUK_USE_DATE_TZO_GMTIME
one-based -> zero-based
DUK_USE_DATE_PRS_STRPTIME
comment: XXX: return something more useful, so that caller can throw?
label: code-design
For NaN/inf, the return value doesn't matter.
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
no fractions
The necessary #includes are in place in duk_config.h.
already one-based
DUK_USE_DATE_PRS_GETDATE
DUK_USE_DATE_NOW_GETTIMEOFDAY
be paranoid for 32-bit time values (even avoiding negative ones)
unsigned 31-bit range
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
negative: dst info not available
Not a very good provider: only full seconds are available.
copy to buffer with spare to avoid Valgrind gripes from strptime
valgrind whine without this
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
DUK_USE_DATE_NOW_TIME
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
UTC
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
local
DUK_USE_DATE_FMT_STRFTIME
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
flags
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
DUK_USE_DATE_NOW_WINDOWS
input 'd' in Windows UTC, 100ns units
Difference is in 100ns units, convert to milliseconds w/o fractions
millisec -> 100ns units since jan 1, 1970
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
The necessary #includes are in place in duk_config.h.
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
Shared Windows helpers.
Positive if local time ahead of UTC.
comment: not sure whether or not needed; Thursday
label: requirement
seconds
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
DUK_USE_DATE_TZO_WINDOWS
address
-> [ val arr ]
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
type tag (public)
return the argument object
result array
idx_value
idx_space
comment: XXX: primitive to make array from valstack slice
label: code-design
XXX: version specific array format instead?
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
refcount
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
because arg count is 1
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
set values into ret array
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
[ level obj func pc line ]
idx_replacer
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
* Compact an object
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
flags
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
internal type tag
Get.
[ ... this ]
fixed arg count: value
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
noblame_fileline
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
[ ... this tracedata sep this str1 ... strN ]
may be NULL
constants arbitrary, chosen for small loads
* Ecmascript/native function call or lightfunc call
not enumerable
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: XXX: skip null filename?
label: code-design
NULL for lightfunc
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
unknown, ignore
[ ... v1 v2 name filename ]
traceback depth ensures fits into 16 bits
[ ... obj key value ]
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
fixed arg count
[ ... this name message ]
name is empty -> return message
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
[ ... v1(filename) v2(line+flags) ]
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
-> [ ... str ]
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
[ ... v1 v2 str ] -> [ ... str v2 ]
DUK_USE_TRACEBACKS
traceback depth fits into 16 bits
[ message error message ]
same for both error and each subclass like TypeError
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
[ ... v1(func) v2(pc+flags) ]
... name ': ' message
comment: XXX: optimize with more direct internal access
label: code-design
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
[ ... this name ]
message is empty -> return name
[ ... this tracedata sep this ]
* Error built-ins
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
count, not including sep
stack type fits into 16 bits
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Current tracedata contains 2 entries per callstack entry.
vararg function, careful arg handling (e.g. thisArg may not be present)
create bound function object
not a vararg function
these non-standard properties are copied for convenience
step 15.a
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
[ body formals source template closure ]
add_auto_proto
[ body formals source ]
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
[ body formals ], formals is comma separated list that needs to be parsed
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
attrs in E5 Section 15.3.5.1
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
bound function 'length' property is interesting
caller and arguments must use the same thrower, [[ThrowTypeError]]
[ func thisArg arg1 ... argN ]
thisArg
vararg function, thisArg needs special handling
comment: XXX: 'copy properties' API call?
label: code-design
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Function built-ins
comment: XXX: cover this with the generic >1 case?
label: code-design
comment: XXX: make this an internal helper
label: code-design
= 1 + arg count
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
[ thisArg arg1 ... argN ]
lightfunc
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
[ thisArg arg1 ... argN func boundFunc argArray ]
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
[ thisArg arg1 ... argN func boundFunc ]
Lightfuncs are always strict.
[ body formals source template ]
ignore arguments, return undefined (E5 Section 15.3.4)
comment: XXX: ignored now
label: code-design
func
For lightfuncs, simply read the virtual property.
comment: XXX: faster internal way to get this
label: code-design
'func' in the algorithm
[ func thisArg argArray ]
ToUint32() coercion required
comment: XXX: copy from caller?
label: code-design
normal and constructor calls have identical semantics
Indicate function type in the function body using a dummy
* directive.
strictness is not inherited, intentional
Duktape object
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
ignore non-strings
Duktape.modSearch(resolved_id, fresh_require, exports, module).
Module id requested
DUK_USE_COMMONJS_MODULES
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
Module object containing module.exports, etc
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
2 when called by debugger
return module.exports
eat dup slashes
at most sizeof(buf) - 1
requested identifier
E5.1 Section 15.1.3.2: empty
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
spaces (nargs - 1) + newline
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Parsing of ints and floats
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
Duktape.modLoaded[] module cache
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
1110 xxxx; 3 bytes
[ source template result ]
if direct eval, calling activation must exist
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
last component
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
Duktape.modLoaded
p overshoots
comment: XXX: copy from caller?
label: code-design
output is never longer than input during resolution
DUK_USE_PREFER_SIZE
fall through
0x10-0x1f
Output #2: last component name
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
print provider
Eval code doesn't need an automatic .prototype object.
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
E5.1 Section B.2.2, step 7.
Backtrack to previous slash or start of buffer.
* Number checkers
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
Resolved, normalized absolute module ID
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
add_auto_proto
0x20-0x2f
module.filename for .fileName, default to resolved ID if
* not present.
E5.1 Section 15.1.3.1: uriReserved + '#'
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
New require() function for module, updated resolution base
this may have side effects, so re-lookup act
a fresh require() with require.id = resolved target module id
Delete entry in Duktape.modLoaded[] and rethrow.
110x xxxx; 2 bytes
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
0x30-0x3f
initial size guess
decode '%xx' to '%xx' if decoded char in reserved set
The base ID of the current require() function, resolution base
[ requested_id require require.id resolved_id last_comp ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
Current require() function
require.id of current module
mod_id may be NULL
comment: Higher footprint, less churn.
label: code-design
DUK_USE_SECTION_B
compact the exports table
Needs lookahead
'undefined', artifact of lookup
1111 0xxx; 4 bytes
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
not reachable
0x50-0x5f
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
Last component name in resolved path
-> [ ... source ]
module table remains registered to modLoaded, minimize its size
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
this is just beneath bottom
p points to digit part ('%xy', p points to 'x')
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
by default, use caller's environment
eat (first) input slash
module.id = resolved_id
indirect eval
'%xx%xx...%xx', p points to char after first '%'
[ source template closure this ]
module
E5.1 Section 15.1.3.4: uriUnescaped
invalidated
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
this function
exports (this binding)
* Resolve module identifier into canonical absolute form.
continuation byte
* CommonJS require() and modules support
Copy term name until end or '/'.
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
delete Duktape.modLoaded[resolved_id]
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
bytes left
[ source template closure ]
* Encoding/decoding helpers
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
0x40-0x4f
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
This was the last term, and q_last was
* updated to match this term at loop top.
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
e.g. require('/foo'), empty terms not allowed
at least this function exists
0x70-0x7f
comment: XXX: check flags
label: requirement
write on next loop
Default exports table
Duktape.modLoaded[resolved_id] = module
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
stash to bottom of value stack to keep new_env reachable for duration of eval
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
extended utf-8 not allowed for URIs
This is guaranteed by debugger code.
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
E5 Section 10.4.2
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
exports
return arg as-is
* Global object built-ins
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
module.name for .name, default to last component if
* not present.
rethrow original error
module.exports = exports
0x60-0x6f
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
Output #1: resolved absolute name
[ source ]
comment: Stack indices for better readability
label: code-design
comment: XXX: refactor and share with other code
label: code-design
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
Duktape.modSearch
module (argument)
fresh require (argument)
resolved id: require(id) must return this same module
caller
avoid dereference after potential callstack realloc
relookup exports from module.exports in case it was changed by modSearch
must be signed
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
* URI handling
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
utf-8 validation ensures these
0x00-0x0f
nargs
compiler's responsibility
backtrack to last output slash (dups already eliminated)
[ source template ]
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
DUK_USE_JX
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
Note: intentionally signed.
XXX: push_uint_string / push_u32_string
[ ... buf loop ]
idx_value
backtrack (safe)
* Top level wrappers
Loop check.
len: 9
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Final result is at stack top.
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
* Local defines and forward declarations.
already zero
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
flags
Guaranteed by recursion_limit setup so we don't have to
* check twice.
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
[ ... obj ]
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
DUK_USE_JSON_EATWHITE_FASTPATH
'"' was eaten by caller
DUK_USE_HEX_FASTPATH
parse value
-> [ ... key val replacer holder key ]
as is
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
unconditional block
any other printable -> as is
emitted
-> [ ... holder name val val ToString(i) ]
replacer is a mutation risk
skip '|'
toJSON() can also be a lightfunc
parse key and value
default attrs ok
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
0x7F is special
-> [ ... key val val' ]
skip ')'
[ ... val ]
Fast path, decode as is.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
syntax error
-> [ ... proplist enum_obj key ]
avoid attempts to add/remove object keys
XXX: a "first" flag would suffice
avail_bytes += need_bytes
Parse a number, other than NaN or +/- Infinity
0x00: finish (non-white)
* 0x01: continue
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
nothing now
caller guarantees
DUK_USE_JX && DUK_USE_JC
[ ... buf ]
-> [ ... key val replacer ]
serialize the wrapper with empty string key
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
Function values are handled completely above (including
* coercion results):
'\Udeadbeef'
enum_index
eat closing bracket
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
Must decrease recursion depth before returning.
* Create wrapper object and serialize
All other object types.
* Helper tables
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
error message doesn't matter, ignored anyway
must not truncate
negative top-relative indices not allowed now
Encode a fastint from duk_tval ptr, no value stack effects.
avoid attempt to compact any objects
Ensure space for 1:1 output plus one escape.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
[ ... number ] -> [ ... string ]
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
Note: space must cater for both JX and JC.
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
temp copy, write back for next loop
[ ... buf loop (proplist) ]
unsigned
but don't allow leading plus
comment: XXX: Here a "slice copy" would be useful.
label: code-design
0x00: finish (not part of number)
* 0x01: continue
-> [ ... val root "" ]
[ ... holder name val enum obj_key val obj_key ]
"-Infinity", '-' has been eaten
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
original target at entry_top - 1
catches EOF and invalid digits
safe, because matched (NUL causes a break)
not emitted
[ ... arr val ]
maxval
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
Must prevent finalizers which may have arbitrary side effects.
expensive flag
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
The stack has a variable shape here, so force it to the
* desired one explicitly.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
proplist is very rare
DUK_USE_JC
-> [ ... key val replacer holder key val ]
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
-> [ ... ]
-> [ ... key val toJSON val key ]
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
Zero length string is not accepted without quotes
Getter might have arbitrary side effects,
* so bail out.
nret
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
-> [ ... voidp voidp ]
[ ... holder name val enum obj_key new_elem ]
Disabled until fixed, see above.
Error message doesn't matter: the error is ignored anyway.
-> [ ... key val' ]
Value would normally be omitted, replace with 'null'.
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
XXX: array internal?
For JX, expressing the whole unsigned 32-bit range matters.
Caller must ensure 'tv' is indeed a fastint!
safe
will result in undefined
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
typed for duk_unicode_decode_xutf8()
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
catches EOF (NUL)
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
accept comma, expect new value
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
-> [ ... reviver holder name val ]
[ ... holder name val ]
We rely on a few object flag / class number relationships here,
* assert for them.
Standard JSON omits functions
unreachable
nargs
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
x == 0x00 (EOF) causes syntax_error
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
Note: duk__dec_req_stridx() backtracks one char
-> [ ... key val toJSON val ]
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
-> [ ... key val ]
0x00: slow path
* other: as is
value was undefined/unsupported
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
coerce in-place
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
[ ... num ]
* Entry points
Caller has already eaten the first character ('(') which we don't need.
C recursion check.
standard JSON; array gaps
catches EOF (0x00)
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
idx_space
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
-> [ ... val' ]
Caller must ensure 'tv' is indeed a double and not a fastint!
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
Caller has already eaten the first character ('|') which we don't need.
Shared entry handling for object/array serialization.
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
Previous entry was inside visited[], nothing to do.
slow path decode
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
[ ... proplist enum_obj key val ]
comment: XXX: substring in-place at idx_place?
label: code-design
* Process replacer/proplist (2nd argument to JSON.stringify)
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
handle comma and closing brace
'-0'
* Process space (3rd argument to JSON.stringify)
caller checks
[ ... holder name val enum obj_key ]
XXX: duk_dup_unvalidated(ctx, -2) etc.
accept anything, expect first value (EOF will be
* caught by key parsing below.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
Assume that the native representation never contains a closing
* parenthesis.
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
get_value
-> [ ... res ]
Initial '{' has been checked and eaten by caller.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
pop enum
DUK_USE_JSON_STRINGIFY_FASTPATH
leave stack unbalanced on purpose
Most input bytes go through here.
-> [ ... holder name val ]
[ ... buf loop (proplist) (gap) ]
disabled for now
extra coercion of strings is OK
ascii fast path: avoid decoding utf-8
We only get here when doing non-standard JSON encoding
idx_replacer
Handle both full and partial slice (as long as covered).
End of input (NUL) goes through slow path and causes SyntaxError.
Assume arrays are dense in the fast path.
handle comma and closing bracket
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
need_bytes may be zero
clamp to 10 chars
A lightfunc might also inherit a .toJSON() so just bail out.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
-> [ ... key val replacer holder ]
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
[ ... holder key ] -> [ ... holder ]
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Same coercion behavior as for Number.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
DUK_USE_JSON_DECNUMBER_FASTPATH
-> [ ... voidp true ]
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
eat closing brace
Catches EOF of JSON input.
number
radix
end-of-input breaks
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
DUK_USE_JSON_QUOTESTRING_FASTPATH
slow path is shared
comment: bytes of indent available for copying
label: code-design
[ ... target ] -> [ ... target keys ]
[ ... str ]
-> [ ... value ]
object or array
DUK_USE_PREFER_SIZE
overflow not possible, buffer limits
XXX: duk_push_uint_string()
DUK_USE_JX || DUK_USE_JC
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
not undefined
Restore stack top after unbalanced code paths.
comment: When ptr == NULL, the format argument is unused.
label: code-design
* Context init
-> [ ... val root val ]
[ ... obj key val ]
[ ... ]
* Stringify implementation.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
[ ... ptr ]
double quote or backslash
[ ... arr ]
comment: XXX: how to figure correct size?
label: code-design
c recursion check
catches EOF (NUL) and initial comma
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
eat trailing comma
disabled
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
Decode failed.
end switch
Result is undefined.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
[ ... proplist ]
digits
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
[ ... key val ] -> [ ... ]
minval
-> [ ... key ]
[ ... obj key ]
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
Caller has already eaten the first char so backtrack one byte.
comment: bytes of indent still needed
label: code-design
nop
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
Initial '[' has been checked and eaten by caller.
We already ate 'x', so backup one byte.
Convert buffer to result string.
Steps 8-10 have been merged to avoid a "partial" variable.
Shared exit handling for object/array serialization.
first character has been matched
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
[ arg1 ... argN this loggerLevel loggerName buffer ]
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
comment: XXX: better multiline
label: code-design
[ arg undefined ]
* Logging support
[ arg toLogString ]
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
separators: space, space, colon
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
[ arg result ]
time
* Pass 1
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
comment: log level could be popped but that's not necessary
label: code-design
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
Constructor
obj_index
keep default instance
nop
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
* Log level check
don't set 'n' at all, inherited value is used as name
call: this.fmt(arg)
[ name this ]
3-letter log level strings
[ arg1 ... argN this loggerLevel loggerName ]
this.raw(buffer)
* Pass 2
level string
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Line format: <time> <entryLev> <loggerName>: <msg>
comment: Calling as a non-constructor is not meaningful.
label: code-design
[ arg1 ... argN this ]
sep (even before first one)
nargs
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
loggerName
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
Not odd, or y == -Infinity
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
DUK_USE_MATH_BUILTIN
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
order must match constants in genbuiltins.py
DUK_USE_AVOID_PLATFORM_FUNCPTRS
* Math built-ins
+0.5 is handled by floor, this is on purpose
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Note: not normalized, but duk_push_number() will normalize
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
digits
leading digit + fractions
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
* Number built-ins
radix
for side effects
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
comment: XXX: helper
label: code-design
-> [ val obj val ]
flags
no return value -> don't replace created value
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
* toFixed(), toExponential(), toPrecision()
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
target
[ hobject props enum(props) key desc ]
fall thru
Lightfunc, always success.
[ hobject props enum(props) ]
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
-> [ obj trap_result ]
enum_flags
magic: 0=getter call, 1=Object.getPrototypeOf
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
comment: XXX: no need for indirect call
label: code-design
Just call the "original" Object.defineProperties() to
* finish up.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
Loop prevention
-> [ hobject props ]
h_new_proto may be NULL
-> [ O toString O ]
[ obj Properties ]
[ obj trap_result res_arr ]
properties object
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
[ obj trap_result res_arr propname ]
comment: TODO: implement Proxy object support here
label: requirement
ignore_loop
required_desc_flags
get_value
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
* Object built-ins
* Use Object.defineProperty() helper for the actual operation.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
[ obj handler trap ]
h is NULL for lightfunc
* Return target object
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
[[SetPrototypeOf]] standard behavior, E6 9.1.2
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
[ obj key desc ]
[ hobject props enum(props) key desc value? getter? setter? ]
frozen and sealed
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
Object.keys
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
[ O Properties obj ]
* Return target object.
idx_desc
retval for success path
Lightfunc handling by ToObject() coercion.
-> [ obj trap handler target ]
nargs
DUK_USE_ES6_PROXY
is_frozen
Object.getOwnPropertyNames
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
comment: XXX: call method tail call?
label: code-design
Pointer object internal value is immutable
* Constructor
* Pointer built-ins
nop
Must be a "pointer object", i.e. class "Pointer"
Note: unbalanced stack on purpose
* toString(), valueOf()
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
DUK_BUILTIN_PROTOS_H_INCLUDED
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
Helpers exposed for internal use
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
Built-in providers
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
Proxy target
Proxy handler
DUK_USE_ES6_PROXY
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
* Proxy built-in (ES6)
replacement handler
flags: "m"
DUK_USE_REGEXP_SUPPORT
* RegExp built-ins
flags: "gim"
[ result ]
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
[ ... pattern flags ]
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
require to be safe
three flags
prepend regexp to valstack 0 index
comment: XXX: much to improve (code size)
label: code-design
flags: "gi"
[ ... bytecode escaped_source ]
flags: "gm"
[ ... RegExp ]
flags: ""
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
[ regexp input ]
Else functionality is identical for function call and constructor
* call.
flags: "g"
[ regexp ]
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
flags: "im"
flags: "i"
[ regexp source bytecode ]
result object is created and discarded; wasteful but saves code space
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
* Case conversion
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
lastIndex already set up for next match
DUK_USE_REGEXP_SUPPORT
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
[ regexp string ]
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
prefix matches, lengths matter now
min(incl)
not found
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
match == search string, by definition
res_obj
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
empty match (may happen with empty separator) -> bump and continue
* Various
* toString(), valueOf()
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
trailer
don't allow an empty match at the end of the string
[ ... replacer match [captures] match_char_offset input ]
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
* indexOf() and lastIndexOf()
ch1 = (r_increment << 8) + byte
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
return as is
repl_value
Not found. Empty string case is handled specially above.
stack[0] = regexp
* stack[1] = string
* substring(), substr(), slice()
-> [ ... regexp string ] -> [ ... res_obj ]
[ start end str ]
never here, but fall through
at index 1
comment: this is relatively expensive
label: code-design
no issues with memcmp() zero size, even if broken
switch (ch2)
lastIndex is initialized to zero by new RegExp()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
pop regexp res_obj or match string
unconditionally
start match from beginning
h_match is borrowed, remains reachable through match_obj
if (is_regexp)
comment: XXX: faster implementation
label: code-design
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
DUK_USE_SECTION_B
Zero size compare not an issue with DUK_MEMCMP.
out_clamped
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
empty separator can always match
leading byte of match string
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
track utf-8 non-continuation bytes
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
input size is good output starting point
match_caps == 0 without regexps
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
unconditionally; is_global==0
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
string limits
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
regexp res_obj is at index 4
[ ... re_obj input ]
max(incl)
Must be a "string object", i.e. class "String"
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* Character and charcode access
no action
default case
initial estimate for ASCII only codepoints
* replace()
cannot have >4G captures
while repl
return 'res_obj'
never an empty match, so step 13.c.iii can't be triggered
for
no issues with empty memcmp()
* Constructor
Shared helper for match() steps 3-4, search() steps 3-4.
track cpos while scanning
0=indexOf, 1=lastIndexOf
regexp res_obj is at offset 4
[ start length str ]
comment: Global case is more complex.
label: code-design
* String built-ins
return 'res_arr' or 'null'
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
combines steps 2 and 5; -len ensures max() not needed for step 5
force_new
No arr_idx update or limit check
set to 1 if any match exists (needed for empty input special case)
* split()
Combined step 11 (empty string special case) and 14-15.
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
match followed by capture(s)
-> [ ... res_obj ]
empty match -> bump and continue
-> [ res_obj ]
[ regexp string res_arr ]
String object internal value is immutable
index
repl string scan
ditto
Note: unbalanced stack on purpose
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
ensure full memcmp() fits in while
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: combines steps 3, 6; step 7 is not needed
label: requirement
[ ... regexp input ] -> [ res_obj ]
-> [ ... repl_value ]
single match always
constrained by string length
if (is_repl_func)
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
duk_concat() coerces arguments with ToString() in correct order
input string scan
undefined -> skip (replaced with empty)
[ ... RegExp val ] -> [ ... res ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
* Thread state and calling context checks
* Constructor
[ value ]
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
in yielder's context
return thread
* Thread builtins
never here
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
XXX: need a duk_require_func_or_lfunc_coerce()
in resumer's context
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
value (error) is at stack top
us
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
caller
push initial function call to new thread stack; this is
* picked up by resume().
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
call is from executor, so we know we have a jmpbuf
side effects
execution resumes in bytecode executor
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
lj value2: thread
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
lj value1: value
Further state-dependent pre-checks
[ thread value ]
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
* Type error thrower, E5 Section 13.2.3.
DUK_USE_ROM_OBJECTS
* Automatically generated by genbuiltins.py, do not edit!
DUK_USE_ROM_STRINGS
native functions: 149
DUK_USE_BUILTIN_INITJS
'length'
!DUK_SINGLE_FILE
'l'
'Arguments'
'toLogString'
'\xffNext'
'\xffBytecode'
'\xffLexenv'
'Date'
'instanceof'
'has'
'do'
'var'
'exports'
'pointer'
'void'
'string'
'protected'
'filename'
'try'
'continue'
'catch'
'toJSON'
'if'
'index'
'deleteProperty'
'value'
'Object'
'switch'
'toGMTString'
'let'
'[...]'
'enumerable'
'Uint32Array'
DUK_USE_ROM_STRINGS
' '
'enumerate'
'with'
'join'
'resume'
'debugger'
'get'
','
'{"_inf":true}'
'\xffFinalizer'
'\xffArgs'
'Error'
'Float64Array'
'enum'
'default'
'\xffRegbase'
'Thread'
'\xffThread'
'import'
'set'
'export'
'prototype'
'ObjEnv'
'jx'
'fmt'
'typeof'
'Math'
'-Infinity'
'name'
'BYTES_PER_ELEMENT'
'info'
'interface'
'class'
'Boolean'
'Buffer'
'defineProperty'
'\xffVarmap'
'Uint16Array'
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
'Infinity'
'\xffFormals'
'implements'
'\xffHandler'
'{"_undef":true}'
'\xffSource'
'{_func:true}'
'env'
'toLocaleString'
'\n '
'fatal'
'hex'
'trace'
'jc'
'case'
'toUTCString'
'(?:)'
'\xffTarget'
'private'
'Invalid Date'
'multiline'
'errCreate'
'warn'
'finally'
'ownKeys'
'configurable'
'caller'
'undefined'
'byteLength'
'lineNumber'
'Int8Array'
'data'
'type'
'-0'
'{"_ninf":true}'
'modLoaded'
'true'
'fileName'
'Uint8Array'
'break'
'Undefined'
''
'setPrototypeOf'
'\xffVarenv'
'number'
'{"_func":true}'
'return'
'throw'
'valueOf'
'buffer'
'DecEnv'
'writable'
DUK_USE_ROM_OBJECTS
'yield'
'id'
'callee'
'ArrayBuffer'
'Null'
'\xffPc2line'
'\xffMap'
'static'
'package'
'ignoreCase'
'message'
'NaN'
'byteOffset'
'extends'
'source'
'constructor'
'clog'
'raw'
'Int16Array'
'base64'
'in'
'Array'
'pc'
'errThrow'
'while'
'toISOString'
'Float32Array'
'object'
'require'
'compile'
'const'
'false'
'null'
'boolean'
'Int32Array'
'new'
'Function'
'stack'
'\xffThis'
'toString'
'debug'
'\xffCallee'
'Uint8ClampedArray'
'arguments'
'n'
'modSearch'
'for'
DUK_USE_BUILTIN_INITJS
'eval'
'function'
'\xffValue'
'DataView'
'error'
'{"_nan":true}'
'delete'
* Automatically generated by genbuiltins.py, do not edit!
exclusive endpoint
'RegExp'
'this'
'public'
'__proto__'
'\xffTracedata'
'input'
'super'
'lastIndex'
'JSON'
'else'
'Number'
'global'
DUK_BUILTINS_H_INCLUDED
'String'
'Pointer'
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
* Git describe: v1.5.2
* Git branch: HEAD
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment: parameter passing, not thread safe
label: requirement
args go here in parens
* Structs
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
DUK_USE_VARIADIC_MACROS
* Prototypes
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
DUK_DEBUG_H_INCLUDED
omit
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
args go here as a comma expression in parens
* Exposed debug macros: debugging disabled
DUK_USE_DEBUG
args
* Exposed debug macros: debugging enabled
comment: unused
label: code-design
(maybe) truncated
normal
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
actual chars dropped (not just NUL term)
DUK_USE_DEBUG
error
* Debug dumping of duk_heap.
Note: there is no standard formatter for function pointers
DUK_USE_DEBUG
heap->strs: not worth dumping
comment: unused
label: code-design
comment:
* Debugging macro calls.
label: code-design
http://en.wikipedia.org/wiki/ANSI_escape_code
DUK_USE_DPRINT_COLORS
DUK_USE_VARIADIC_MACROS
* Debugging disabled
DUK_USE_DEBUG
* Debugging enabled
%lf, %ld etc
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
XXX: print built-ins array?
%ld
terminal type: no depth check
may be NULL
XXX: use DUK_HSTRING_FLAG_INTERNAL?
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
%p
after this, return paths should 'goto finished' for decrement
%lx
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
%f and %lf both consume a 'long'
%x; only 16 bits are guaranteed
maximum length of standard format tag that we support
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
leave out trailing 'unused' elements
depth check is done when printing an actual type
IEEE double is approximately 16 decimal digits; print a couple extra
ignore
char format: use int
maximum recursion depth for loop detection stacks
unsupported: would consume multiple args
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
DUK_USE_DEBUG
Should not happen.
helpers
%s
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
comment: unused
label: code-design
must match bytecode defines now; build autogenerate?
%lu
Note: string is a terminal heap object, so no depth check here
two special escapes: '\' and '"', other printables as is
from curr pc
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
'%c', passed concretely as int
comment: format is too large, abort
label: code-design
Quite approximate but should be useful for little and big endian.
%d; only 16 bits are guaranteed
'%s' and NULL is not portable, so special case
* it for debug printing.
comment: prototype should be last, for readability
label: code-design
fall through
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
%u; only 16 bits are guaranteed
heapobj recursion depth when deep printing is selected
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
from next pc
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
return total chars written excluding terminator
own pointer
throw_flag
nargs == 2 so we can pass a callstack level to eval().
Write unsigned 32-bit integer.
Use result value as is.
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
* Debug connection peek and flush primitives
Reply with tvals pushed by request callback
Request callback should push values for reply to client onto valstack
* DumpHeap command
comment: NULL not needed here
label: code-design
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
push to stack
Report next pc/line to be executed.
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
tolerates NULL h_buf
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
shared pop
comment: unused
label: code-design
[ ... func varmap enum key value this ]
[ ... result ]
side effects
* Duktape debugger
* Halt execution helper
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
save stack top
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
DUK_USE_DEBUGGER_INSPECT
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
flags
For strings, special form for short lengths.
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
unsigned
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
comment: XXX: comes out as signed now
label: code-design
Report thrown value to client coerced to string
heap->dbg_udata: keep
comment: Process debug messages until we are no longer paused.
label: code-design
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
switch initial byte
may be NULL
For anything other than an Error instance, we calculate the error
* location directly from the current activation.
Note: array dump will include elements beyond
* 'length'.
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
comment: XXX: differentiate null pointer from empty string?
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
To use the shared helper need the virtual index.
Breakpoint entries above the used area are left as garbage.
Skip fully.
Skip dvalue.
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
comment: prevent multiple in-progress detaches
label: requirement
DUK_USE_DEBUGGER_THROW_NOTIFY
processed one or more messages
index
no_block
* Simple commands
Safe to call multiple times.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
tentative, checked later
Write signed 32-bit integer.
Peek ahead in the stream one byte.
* Breakpoint management
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
Decrement PC if that was requested, this requires a PC sync.
comment: For short strings, use a fixed temp buffer.
label: code-design
restore stack top
Pretend like we got EOM
always push some string
* Detach handling
duk_hnativefunction specific fields.
[ ... eval "eval" eval_input level ]
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
For now shared handler is fine.
Signed integers always map to 4 bytes now.
No debugger support.
* Debug connection message write helpers
terminator
enum_flags
this cannot initiate a detach
true even with reattach
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
keep heap->dbg_detached_cb
num_stack_args
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
Return 1: got EOM
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
NOTE: length may be zero
Read fully.
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
get_value
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
even after a detach and possible reattach
avoid calling write callback in detach1()
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
pruned
switch cmd
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
comment: unused: not accepted in inbound messages
label: code-design
Allow NULL 'msg'
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
detached
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
* Debug connection skip primitives
isAccessor
* Helper structs
At least: ... [err]
Error instance, use augmented error data directly
just in case callback is broken and won't write 'x'
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
DUK_USE_DEBUGGER_DUMPHEAP
-> [ ... func varmap enum ]
duk_hobject specific fields.
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
enum_index
this is especially critical to avoid another write call in detach1()
* Debug connection write primitives
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
not an error
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
DUK_USE_STRTAB_PROBE
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
may be set to 0 by duk_debugger_attach() inside callback
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
DUK_USE_DEBUGGER_SUPPORT
Easy to get wrong, so assert for it.
optional callstack level
restore PC
w/o refcounting
Write fully.
* Debug message processing
* Debug connection read primitives
compensate for eval() call
Since we already started writing the reply, just emit nothing.
DUK_USE_STRTAB_CHAIN
Skip dvalues to EOM.
heap->dbg_detached_cb: keep
nargs
'this' binding shouldn't matter here
* Status message and helpers
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
comment: XXX: exposed duk_debug_read_pointer
label: code-design
Error codes.
comment: unused
label: code-design
Initial bytes for markers.
Commands initiated by debug client.
Commands and notifys initiated by Duktape.
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
Debugger protocol version is defined in the public API header.
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
DUK_DEBUGGER_H_INCLUDED
comment: XXX: exposed duk_debug_read_buffer
label: code-design
Other initial bytes.
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
DUK_ERR_URI_ERROR: no macros needed
this is added to checks to allow for Duktape
* API calls in addition to function's own use
assertion omitted
DUK_USE_PANIC_HANDLER
* Assertion helpers
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
no refcount check
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
DUK_ERR_ERROR: no macros needed
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
DUK_USE_ASSERTIONS
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
* Prototypes
nop
already defined, good
DUK_ERR_ASSERTION_ERROR: no macros needed
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
* Assert macro: failure causes panic.
DUK_ERROR_H_INCLUDED
DUK_USE_VERBOSE_ERRORS
DUK_ERR_REFERENCE_ERROR: no macros needed
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
Non-verbose errors for low memory targets: no file, line, or message.
DUK_VERBOSE_ERRORS
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
no valstack space check
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
DUK_ERR_UNCAUGHT_ERROR: no macros needed
assertion disabled
DUK_USE_PARANOID_ERRORS
DUK_ERR_EVAL: no macros needed
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
unsigned
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
[ ... errval ]
3 entries actually needed below
no need to check now: both success and error are OK
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
assume PC is at most 32 bits and non-negative
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
DUK_USE_ERRTHROW
num args
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
Lightfunc, not blamed now.
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
-> [ ... error ]
thr argument only used for thr->heap, so specific thread doesn't matter
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
-> [ ... errhandler errval ]
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
Finally, blame the innermost callstack entry which has a
* .fileName property.
[ ... error ]
ignore reclimit, not constructor
Native function, no relevant lineNumber.
!DUK_USE_TRACEBACKS
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
[ ... error func ]
ignore_loop
callstack limits
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
[ ... error lineNumber fileName ]
* Add line number to a compiler error.
DUK_USE_AUGMENT_ERROR_CREATE
* Add .fileName and .lineNumber to an error on the stack top.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
since no recursive error handler calls
DUK_USE_PC2LINE
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
invalidated by pushes, so get out of the way
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
[ ... errhandler undefined errval ]
[ ... errval errhandler ]
-> [... arr num]
[ ... error func fileName ]
DUK_USE_TRACEBACKS
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
DUK_USE_AUGMENT_ERROR_THROW
[ ... error arr ]
[ ... error func fileName lineNumber ]
call_flags
-> [ ... errhandler undefined(= this) errval ]
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
[... arr]
Add function object.
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Add ._Tracedata to an error on the stack top.
XXX: specify array size, as we know it
(flags<<32) + (line), flags = 0
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
unreferenced w/o tracebacks
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
XXX: set with duk_hobject_set_length() when tracedata is filled directly
unreferenced w/o asserts
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
DUK_USE_CPP_EXCEPTIONS
dummy
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
* Error throwing helpers
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
DUK_USE_VERBOSE_ERRORS
comment: size for formatting buffers
label: code-design
* Default fatal error handler
!DUK_USE_PANIC_HANDLER
omit print
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
SCANBUILD: "Dereference of null pointer", normal
* Default panic handler
* Error, fatal, and panic handling.
exit() afterwards to satisfy "noreturn"
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
Report it to the debug client
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
* Get prototype object for an integer error code.
comment: XXX: more specific error classes?
label: code-design
DUK_USE_DEBUGGER_SUPPORT
side effects
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
all we need to know
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
* Error helpers
* Exposed helper for setting up heap longjmp state.
use_prev_pc
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
reset callstack limit
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
just making sure
* Finally, longjmp
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
comment: XXX: shared strings
label: code-design
Error object is augmented at its creation here.
* Helper for C function call negative return values.
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
intentionally empty
DUK_EXCEPTION_H_INCLUDED
duk_tval intentionally skipped
* Forward declarations
* Forward declarations for all Duktape structures.
DUK_FORWDECL_H_INCLUDED
no typedef
Current size (not counting a dynamic buffer's "spare").
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
No pointer compression because pointer is potentially outside of
* Duktape heap.
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
Stored in duk_heaphdr h_extra16.
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
size stored in duk_heaphdr unused flag bits
* Misc defines
indirect allocs
may be NULL if alloc_size == 0
* Prototypes
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
buffer pointer is to an externally allocated buffer
assume 0 <=> NULL
dynamic buffer ops
DUK_HBUFFER_H_INCLUDED
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
no extra padding
* Field access
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
* Structs
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
Stored in duk_heaphdr unused flags.
Shared prefix for all buffer types.
buffer is behind a pointer, dynamic or external
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
Because size > 0, NULL check is correct
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
alloc external with size zero
the compressed pointer is zeroed which maps to NULL, so nothing to do.
For indirect allocs.
no need to write 'out_bufdata'
zero everything unless requested not to do so
* duk_hbuffer allocation and freeing.
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
no wrapping
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
* Resizing
'res' may be NULL if new allocation size is 0.
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
* Maximum size check
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
All element accessors are host endian now (driven by TypedArray spec).
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
DUK_HBUFFEROBJECT_H_INCLUDED
byte index limit for element access, exclusive
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Shared object part.
element type
Underlying buffer (refcounted), may be NULL.
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
byte offset to buf
* Heap Buffer object representation. Used for all Buffer variants.
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
Slice starting point is beyond current length.
DUK_USE_BUFFEROBJECT_SUPPORT
Line number range for function. Needed during debugging to
* determine active breakpoints.
number of arguments allocated to regs
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
shared object part
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
* Field accessor macros
DUK_HCOMPILEDFUNCTION_H_INCLUDED
regs to allocate
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
Data area, fixed allocation, stable data ptrs.
Note: assumes 'data' is always a fixed buffer
* Main struct
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
* Accessor macros for function specific data areas
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
callback for indirect reallocs, request for current pointer
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
heap destruction ongoing, finalizer rescue no longer possible
resend state next time executor is about to run
No field needed when strings are in ROM.
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
comment: alloc size in elements
label: code-design
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
don't run finalizers; queue finalizable objects back to heap_allocated
comment: unused
label: code-design
DUK_USE_ROM_STRINGS
don't compact objects; needed during object property allocation resize
borrowed; NULL if no step state (NULLed in unwind)
breakpoints: [0,breakpoint_count[ gc reachable
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
* Other heap related defines
Allocator functions.
don't run finalizers; leave finalizable objects in finalize_list for next round
Step types
used entries + approx 100% -> reset load to 50%
current thread
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
* Memory constants
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
required, NULL implies detached
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
heap thread, used internally and for finalization
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
load factor min 25%
helper to insert a (non-string) heap object into heap allocated list
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
used elements (includes DELETED)
marker for detecting internal "double faults", see duk_error_throw.c
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
debugger state, only relevant when attached
allocated heap objects
4'294'967'295
longjmp type
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
Precomputed pointers when using 16-bit heap pointer packing.
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
Milliseconds between status notify and transport peeks.
value1 -> error object
mark-and-sweep is currently running
step type: none, step into, step over, step out
refcount code is processing refzero list
emergency mode: try extra hard
time when status/peek was last done (Date-based rate limit)
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
mark-and-sweep control
if 0, 'str16' used, if > 0, 'strlist16' used
* Stringtable entry for fixed size stringtable
no refcounting
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
probe sequence (open addressing)
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
starting line number
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
if 0, 'str' used, if > 0, 'strlist' used
heap level "stash" object (e.g., various reachability roots)
* Heap flags
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
* Raw memory calls: relative to heap, but no GC interaction
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
* Prototypes
50x heap size
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
currently running thread
fixed top level hashtable size (separate chaining)
longjmp state
debugger detaching; used to avoid calling detach handler recursively
required
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
built-in strings
executor interrupt running (used to avoid nested interrupts)
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
current setjmp() catchpoint
isError flag for yield
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
These are for rate limiting Status notifications and transport peeking.
Used to support single-byte stream lookahead.
duk_handle_call / duk_handle_safe_call recursion depth limiting
comment: unused
label: code-design
* Main heap structure
currently active breakpoints: NULL term, borrowed pointers
2nd related value (type specific)
resizing parameters
1st related value (type specific)
an error handler (user callback to augment/replace error) is running
mix-in value for computing string hashes; should be reasonably unpredictable
Starting from this round, use emergency mode
* for mark-and-sweep.
work list for objects to be finalized (by mark-and-sweep)
value of dbg_exec_counter when we last did a Date-based check
* Stringtable
DUK_USE_DEBUGGER_SUPPORT
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
callstack index
debugger
DUK_HEAP_H_INCLUDED
cumulative opcode execution count (overflows are OK)
comment: alloc function typedefs in duktape.h
label: code-design
value1 -> yield value, iserror -> error / normal
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
strings up to the this length are not cached
* Built-in strings
* Debugger support
1x heap size
currently paused: talk with debug client until step/resume
don't resize stringtable (but may sweep it); needed during stringtable resize
rnd_state for duk_util_tinyrandom.c
string intern table (weak refs)
load factor max 75%
Currently nothing to free
No strs[] pointer.
explicit NULL inits
some derived types
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
comment: suppress warning, not used
label: code-design
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
comment: Similar workaround for INFINITY.
label: code-design
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
* All done
'thr' is now reachable
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
comment: Silence a few global unused warnings here.
label: code-design
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
DUK_USE_ROM_STRINGS
DUK_USE_HEAPPTR16
assumes that allocated pointers and alloc funcs are valid
* if res exists
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
basic platform types
Currently nothing to free; 'data' is a heap object
mark-and-sweep not running -> must be empty
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
* Init the heap object
comment: XXX: zero assumption
label: code-design
unsigned
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
* Init stringtable: fixed variant
Fixed seed value used with ROM strings.
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
refzero not running -> must be empty
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
* Init the heap thread
Constants for built-in string data depacking.
structs from duk_forwdecl.h
* Zero the struct, and start initializing roughly in order
* duk_heap allocation and freeing.
convenience
just one 'int' for C++ exceptions
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
0 = uppercase, 32 = lowercase (= 'a' - 'A')
* Init built-in strings
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
comment: Note: first argument not really used
label: code-design
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
important chosen base types
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
* Computed values (e.g. INFINITY)
skip finalizers; queue finalizable objects to heap_allocated
tval
DUK_USE_DEBUG
basic types from duk_features.h
* Init stringcache
no res->strs[]
DUK_USE_EXPLICIT_NULL_INIT
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
Detach a debugger if attached (can be called multiple times)
* safely.
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
Decrease by 25% every round
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
nothing to NULL
derived types
strings are only tracked by stringtable
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
DUK_USE_STRTAB_PROBE
maps to finalizer 2nd argument
* If selftests enabled, run them as early as possible
zero
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
DUK_USE_STRTAB_CHAIN
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
default prototype (Note: 'thr' must be reachable)
basic types
comment: XXX: this may now fail, and is not handled correctly
label: code-design
* Debug dump type sizes
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Init stringtable: probe variant
comment: XXX: inefficient loop
label: code-design
note: mixing len into seed improves hashing when skipping
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
Bernstein hash init value is normally 5381
Constants for duk_hashstring().
DUK_USE_STRHASH_DENSE
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
off >= step, and step >= 1
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
may be NULL, too
last element that was left in the heap
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
* Finish
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
finally free the struct itself
deal with weak references first
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
XXX: for threads, compact value stack, call stack, catch stack?
only objects have finalizers
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
this case can no longer occur because refcount is unsigned
DUK_USE_HEAPPTR16
free object and all auxiliary (non-heap) allocs
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Strings and ROM objects are never placed on the heap allocated list.
queue back to heap_allocated
* Assertions after
'data' is reachable through every compiled function which
* contains a reference.
XXX: skip count_free w/o debug?
* Object will be kept; queue object back to heap_allocated (to tail)
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
DUK_USE_ASSERTIONS
DUK_USE_MARK_AND_SWEEP
* Assertion helpers.
must never longjmp
* Object compaction.
*
* Compaction is assumed to never throw an error.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
nothing to mark
If debugger is paused, garbage collection is disabled by default.
main reachability roots
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
* Plain, boring reachable object.
XXX: stringtable emergency compaction?
recursion tracking happens here only
reset voluntary gc trigger count
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
* Run (object) finalizers in the "to be finalized" work list.
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
* Assertions before
* Unreachable object, free
OK
done so that duk__mark_heaphdr() works correctly
must also check refzero_list
* Mark objects on finalize_list.
*
DUK_USE_REFERENCE_COUNTING
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
free inner references (these exist e.g. when external
* strings are enabled)
ignored
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
* Mark-and-sweep garbage collection.
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
* Mark the heap.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
mark finalizer work list as reachability roots
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
temproots
refzero_list treated as reachability roots
nothing now
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
flags have been already cleared
* Reset trigger counter
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Caller will finish the marking process if we hit a recursion limit.
no mark-and-sweep gc
may have FINALIZED
log this with a normal debug level because this should be relatively rare
* Marking functions for heap types: mark children recursively
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
hash part is a 'weak reference' and does not contribute
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
nothing to process
* Clear (reachable) flags of refzero work list.
* Begin
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
nop
DUK_USE_STRTAB_PROBE
* Reachable object, keep
May happen in some out-of-memory corner cases.
* Sweep stringtable
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Sweep heap
DUK_USE_STRTAB_CHAIN
finalize_list will always be processed completely
approximate
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
nargs
mark finalizable as reachability roots
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
No finalizers for ROM objects
* Misc
* Memory allocation handling.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
for zero size allocations NULL is allowed
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
simulate alloc failure on every realloc (except when mark-and-sweep is running)
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
no voluntary gc
* First attempt
simulate alloc failure on every alloc (except when mark-and-sweep is running)
DUK_USE_MARK_AND_SWEEP
assume memset with zero size is OK
* Allocate memory with garbage collection
ptr before mark-and-sweep
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
useful for debugging
ptr may be NULL
* Reallocate memory with garbage collection
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
* Free memory
* Voluntary periodic GC (if enabled)
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
DUK_USE_INTERRUPT_COUNTER
* Support functions for duk_heap.
may be NULL
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
yes -> move back to heap allocated
Require a lot of stack to force a value stack grow/shrink.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
DUK_USE_REFERENCE_COUNTING
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
DUK_USE_REFZERO_FINALIZER_TORTURE
no -> decref members, then free
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
ignored
no refcounting
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
refcount is unsigned, so always true
currently, always the case
not emergency
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
must never longjmp
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
* Rescue or free.
May happen in some out-of-memory corner cases.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
tail insert: don't disturb head in case refzero is running
* Detect recursive invocation
nothing to finalize
comment: unused
label: code-design
nothing now
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
not strictly necessary
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
duk_hobject_run_finalizer() sets
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
bump refcount to prevent refzero during finalizer processing
* Objects have internal references. Must finalize through
* the "refzero" work list.
* Pick an object from the head (don't remove yet).
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
approximate
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
comment: XXX: better to get base and walk forwards?
label: code-design
nargs
* Churn refzero_list until empty
remove artificial bump
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
hash part is a 'weak reference' and does not contribute
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
* Reference counting implementation.
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
* Misc
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
update entry, allocating if necessary
may be equal
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
take last entry
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
LRU: move our entry to first
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
no sce, or sce scan not best
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
clen == blen -> pure ascii
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
* For ASCII strings, the answer is simple.
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
initialize for debug prints, needed if sce==NULL
* A C
* B A
* C <- sce ==> B
* D D
may be less, since DELETED entries are NULLed by rehash
comment: load factor too low or high, count actually used entries and resize
label: code-design
Count actually used (non-NULL, non-DELETED) entries.
OK
avoid array abandoning which interns strings
unsigned intentionally
dummy
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
may be NULL
NUL terminate for convenient C access
Undefine local defines
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Overflow, relevant mainly when listlen is 16 bits.
find and remove string from stringtable; caller must free the string itself
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
char: use int cast
guaranteed to succeed
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
fail
new_used / size <= 1 / DIV <=> new_used <= size / DIV
DUK_USE_STRTAB_PROBE
DUK_USE_DEBUG
caller is responsible for ensuring this
strings may have inner refs (extdata) in some cases
grow by at most one
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
looping should never happen
not strictly necessary
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
DUK_USE_ROM_STRINGS
* Heap stringtable handling, string interning.
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
comment: unused with some debug level combinations
label: code-design
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
Because new_size > duk__count_used_probe(heap), guaranteed to work
DUK_USE_HEAPPTR16
failed
avoid recursive string table call
formatted result limited
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
DUK_USE_STRTAB_CHAIN
Now two entries in the same slot, alloc list
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
required for rehash to succeed, equality not that useful
* Exposed calls
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
st_used remains the same, DELETED is counted as used
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
For manual testing only.
comment: unused
label: code-design
Relies on NULL encoding to zero.
FAIL
* Raw intern and lookup
new_free / size <= 1 / DIV <=> new_free <= size / DIV
Without ROM objects "needs refcount update" == is heap allocated.
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
refcount macros not defined without refcounting, caller must #ifdef now
round out to 8 bytes
currently nop
result: updated refcount
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
refcounting requires direct heap frees, which in turn requires a dual linked heap
5 heap flags
mark-and-sweep: finalized (on previous pass)
Original idiom used, minimal code size.
comment: XXX: fast int-to-double
label: code-design
* Assert helpers
Optimized for size.
DUK_USE_ROM_OBJECTS
nop
Optimized for speed.
comment: XXX: double evaluation for 'tv' argument.
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
init pointer fields to null
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
DUK_USE_FASTINT
comment: XXX: fast-int-to-double
label: code-design
read-only object, in code section
2 bits for heap type
side effects
mark-and-sweep: children not processed
mark-and-sweep: finalizable (on current pass)
Casting convenience.
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
get or set a range of flags; m=first bit number, n=number of bits
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
25 user flags
DUK_HEAPHDR_H_INCLUDED
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
comment: XXX: no optimized variants yet
label: requirement
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
mark-and-sweep: reachable
* Heap native function representation.
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
DUK_HNATIVEFUNCTION_H_INCLUDED
shared object part
hobject management functions
!DUK_SINGLE_FILE
LAYOUT 2
misc
* Macros to access the 'props' allocation.
object has an array part (a_size may still be 0)
* Exposed data
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
E5 Section 8.6.1
push value to stack
object is extensible
'Arguments' object and has arguments exotic behavior (non-strict callee)
hash size approx. 1.25 times entries size
* Struct defs
comment: unused
label: code-design
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
finalization
probe sequence
comment: function: function must not be tail called
label: code-design
function: create binding for func name (function templates only, used for named function expressions)
Maximum traversal depth for "bound function" chains.
entry part size
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
* PC-to-line constants
internal property functions
object is a buffer object (duk_hbufferobject) (always exotic)
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
internal define property: skip write silently if exists
flags used for property attributes in duk_propdesc and packed flags
object is a thread (duk_hthread)
prop index in 'entry part', < 0 if not there
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
comment: hash part size or 0 if unused
label: code-design
Object built-in methods
LAYOUT 1
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
implies DUK_HOBJECT_IS_BUFFEROBJECT
* Resizing and hash behavior
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
function: create new environment when called (see duk_hcompiledfunction)
class masks
2^3 -> 1/8 = 12.5% min growth
convenience
custom; implies DUK_HOBJECT_IS_THREAD
for updating (all are set to < 0 for virtual properties)
'Proxy' object
index for next new key ([0,e_next[ are gc reachable)
note: this updates refcounts
alias for above
'Array' object, array length and index exotic behavior
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
25%, i.e. less than 25% used -> abandon
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
hobject property layout
core property functions
DUK_HOBJECT_H_INCLUDED
prop index in 'array part', < 0 if not there
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
flags for duk_hobject_get_own_propdesc() and variants
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Prototypes
* Macros for accessing size fields
object is a compiled function (duk_hcompiledfunction)
macros
Duktape/C (nativefunction) object, exotic 'length'
internal properties
custom
higher value conserves memory; also note that linear scan is cache friendly
read-only values 'lifted' for ease of use
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
envrec: (declarative) record is closed
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
LAYOUT 3
internal align target for props allocation, must be 2*n for some n
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
object is constructable
prototype: the only internal property lifted outside 'e' as it is so central
controls for minimum array part growth
* Macros for property handling
pc2line
ES6 proxy
2**31-1 ~= 2G properties
function: create an arguments object on function call
accessor
controls for minimum entry part growth
range check not necessary because all 4-bit values are mapped
XXX: duk_uarridx_t?
object has any exotic behavior(s)
E5 Section 8.6.2 + custom classes
prop index in 'hash part', < 0 if not there
don't throw for prototype loop
low-level property functions
object established using Function.prototype.bind()
* Ecmascript [[Class]]
112.5%, i.e. new size less than 12.5% higher -> fast resize
helpers for defineProperty() and defineProperties()
object is a native function (duk_hnativefunction)
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
function: function object is strict
enumeration
array part size (entirely gc reachable)
'String' object, array index exotic behavior
alloc and init
* Misc
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
also goes into flags
different memory layout, alloc size, and init
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Zero encoded pointer is required to match NULL
comment: unused now
label: code-design
when nothing is running, API calls are in non-strict mode
NULL pointer is required to encode to zero, so memset is enough.
comment: UNUSED, intentionally empty
label: code-design
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
* Hobject Ecmascript [[Class]].
recheck that the property still exists
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
* Entries part
[... enum]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
still reachable
compact; no need to seal because object is internal
[ ... res ]
-> [... enum key enum_target val]
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
return 1 to allow callers to tail call
used for array, stack, and entry indices
[enum_target res]
enumerator must have no keys deleted
[ ... enum_target res trap_result val true ]
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
string objects must not created without internal value
control props
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
-> [ ... enum_target res ]
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
[enum_target res key true]
-> [... enum key val]
There's intentionally no check for
* current underlying buffer length.
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
[ ... enum_target res trap_result ]
must match exactly the number of internal properties inserted to enumerator
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Initialize index so that we skip internal control keys.
-> [... enum key enum_target key]
-> [...]
* Proxy object handling
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
[enum_target enum res]
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
comment: XXX use get tval ptr, more efficient
label: code-design
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
-> [... key val]
Neutered buffer, zero length seems
* like good behavior here.
String and buffer enumeration behavior is identical now,
* so use shared handler.
[res]
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
-> [... key]
nargs
[ ... enum_target res trap_result val ]
DUK_USE_ES6_PROXY
keep val_highest
-> [ ... enum_target res trap_result ]
we know these because enum objects are internally created
Copy trap result keys into the enumerator object.
no array part
[ ... enum_target res handler trap ]
-> [ ... enum_target res handler undefined target ]
only 'length'
-> [ ... enum_target res trap handler target ]
ensure never re-entered until rescue cycle complete
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
-> [... obj finalizer]
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
[... obj]
nargs
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> [... obj retval/error]
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
nrets
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
this also increases refcount by one
duk_safe_call discipline
-> [...]
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
* Misc support functions
avoid problems if p == h->prototype
* Iterate the bitstream (line diffs) until PC is reached
0: no change
1 0 <2 bits>
1 1 1 <32 bits>
0
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
Note: pc is unsigned and cannot be negative
comment: workaround: max nbits = 24 now
label: code-design
1 1 0 <8 bits>
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Use the index in the header to find the right starting point
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
end of diff run
DUK_USE_PC2LINE
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
end of bytecode
compact
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
be_ctx->offset == length of encoded bitstream
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
valid pc range is [0, length[
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
should never happen
[key getter this] -> [key retval]
Note: no key on stack
avoid attempt to compact the current object
key is now reachable in the valstack
no need to pop, nothing was pushed
NULL obj->p is OK
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
all virtual properties are non-configurable and non-writable
not found
resume lookup from target
comment: Note: reuse 'curr'
label: code-design
* Get old and new length
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
* Check whether we need to abandon an array part (if it exists)
no need to decref, as previous value is 'undefined'
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
USE_PROP_HASH_PART
Get default hash part size for a certain entry part size.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
String is an own (virtual) property of a lightfunc.
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
If neutered must return 0; offset is zeroed during
* neutering.
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
setter and/or getter may be NULL
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
replaces top of stack with new value if necessary
comment: prev value must be unused, no decref
label: code-design
* Update an existing property of the base object.
late lookup, avoid side effects
* Debug logging after adjustment.
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
update length (curr points to length, and we assume it's still valid)
* Post resize assertions.
flags
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
No resize has occurred so temp_desc->e_idx is still OK
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
comment: XXX: this is a major target for size optimization
label: code-design
implicit attributes
[in_val in_val]
leave result on stack top
if fails, e_size will be zero = not an issue, except performance-wise
Note: no recursion issue, we can trust 'map' to behave
non-object base, no offending virtual property
caller ensures; rom objects are never bufferobjects now
* Some change(s) need to be made. Steps 7-11.
For internal use: get non-accessor entry value and attributes
* Write to entry part
* All done, switch properties ('p') allocation to new one.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
hash probe sequence
must have been, since in array part
array entries are all plain values
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Buffer writes are often integers.
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
[obj key value desc]
resume delete to target
stage 2: delete configurable entries above target length
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
success
[] -> [res]
keep key reachable for GC etc; guaranteed not to fail
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
index is above internal buffer length -> property is fully normal
write_to_array_part:
E5 Section 15.5.5.1
ignore retval -> [key]
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
* Because buffer values are often looped over, a number fast path
* is important.
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
don't push value
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
increases key refcount
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
avoid attempts to add/remove object keys
curr is accessor, desc is data
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
* Local defines
E5 Section 15.4.5.1, step 4
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
[... old_result result] -> [... result]
* Detach actual buffer from dynamic buffer in valstack, and
* pop it from the stack.
*
* XXX: the buffer object is certainly not reachable at this point,
* so it would be nice to free it forcibly even with only
* mark-and-sweep enabled. Not a big issue though.
Must avoid duk_pop() in exit path
DUK_USE_FASTINT
no decref needed for a number
Leave 'getter' on stack
[key] -> [undefined] (default value)
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
force_flag
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
curr value
[key] (coerced)
Note: no allocation pressure, no need to check refcounts etc
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
[key setter this val key] -> [key retval]
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
guaranteed to find an empty slot
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
[ key trap_result ] -> []
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
remove value
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
* Not found
* Proxy helpers
steps 3.h and 3.i
* Found; post-processing (Function and arguments objects)
[key val]
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
cannot be arguments exotic
actually used, non-NULL keys
avoid double coercion
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* Local prototypes
Note: buffer is dynamic so that we can 'steal' the actual
* allocation later.
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Check array density and indicate whether or not the array part should be abandoned.
[key value] or [key undefined]
descriptor type specific checks
avoid multiple computations of flags address; bypasses macros
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
not enumerable
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
should not happen
previous value is assumed to be garbage, so don't touch it
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
standard behavior, step 3.f.i
index is above internal string length -> property is fully normal
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
must not be extensible
comment: fill new_h with u32 0xff = UNUSED
label: code-design
* Misc helpers
side effects
NULL if tv_obj is primitive
actual update happens once write has been completed without
* error below.
IsDataDescriptor(desc) == true
Target object must be checked for a conflicting
* non-configurable property.
guaranteed when building arguments
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
* Copy array elements to new array part.
property exists, either 'desc' is empty, or all values
* match (SameValue)
we currently assume virtual properties are not configurable (as none of them are)
* Property lookup
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
Count actually used entry part entries (non-NULL keys).
Note: use 'curr' as a temp propdesc
Fast check for extending array: check whether or not a slow density check is required.
* GETPROP: Ecmascript property read.
* Property not found in prototype chain.
unsigned
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
since new_alloc_size > 0
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
XXX: fast path for arrays?
force the property to 'undefined' to create a slot for it
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
[obj key undefined]
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[obj key desc value get set curr_value]
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
DUK_USE_HOBJECT_HASH_PART
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
coercion order matters
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
Undefine local defines
[obj key value desc value]
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
default value
write to entry part
For internal use: get array part value
treat like property not found
[... put_value]
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
[ key ] -> []
if abandon_array, new_a_size must be 0
* Helpers to resize properties allocation on specific needs.
for resizing of array part, use slow path
-> [ ... trap handler ]
Note: proxy handling must happen before key is string coerced.
guaranteed to finish, as hash is never full
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
Note: unconditional throw
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
comment: actually used
label: code-design
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
* Array part
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
see below
hash lookup
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
success: leave varname in stack
Note: changing from writable to non-writable is OK
don't touch property attributes or hash part
stage 1 guarantees
current assertion is quite strong: decref's and set to unused
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> [key]
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
[ ... key trap handler ]
* Get old and new length
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
* Found existing own or inherited plain property, but original
* base is a primitive value.
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
V
... target is extensible
duk__get_min_grow_e() is always >= 1
* Nice debug log.
* DELPROP: Ecmascript property deletion.
[... varname]
* Ecmascript compliant [[Delete]](P, Throw).
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
note: original, uncoerced base
!= 0 => post-update for array 'length' (used when key is an array index)
only need to guarantee 1 more slot, but allocation growth is in chunks
IsAccessorDescriptor(desc) == true
no wrap assuming h_bufobj->length is valid
avoid issues with relocation
[key] -> []
contains value
Receiver: Proxy object
comment: XXX: inline into a prototype walking loop?
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
nargs
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
happens when hash part dropped
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
no need for decref/incref because value is a number
[key undefined] -> [key]
shared exit path now
attempt to change from accessor to data property
Read value pushed on stack.
curr and desc are data
accessor with defined getter
key coercion (unless already coerced above)
covered by comparison
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
[key]
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
-> [in_val]
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
steps 4.a and 4.b are tricky
defaults, E5 Section 8.6.1, Table 7
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
flag for later write
Get minimum array part growth for a certain size.
arrays MUST have a 'length' property
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
* Helpers for managing property storage size
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
NULL if not an object
Catches >0x100000000 and negative values.
currently required
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
retval indicates delete failed
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
fall through
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
If neutered must return 0; length is zeroed during
* neutering.
array case is handled comprehensively above
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
[key setter this val] -> [key retval]
stage 3: update length (done by caller), decide return code
* Not found as concrete or virtual
minimum new length is highest_arr_idx + 1
property is configurable and
consistency requires this
* Coercion and fast path processing
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
relevant array index is non-configurable, blocks write
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
P
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
index/length check guarantees
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
new value
actually used, non-NULL entries
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
shared checks for all descriptor types
strict flag for putvar comes from our caller (currently: fixed)
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
caller ensures
traits are separate; in particular, arguments not an array
0 = don't push current value
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
fill new entries with -unused- (required, gc reachable)
duk__get_min_grow_a() is always >= 1
[key getter this key] -> [key retval]
* New length not lower than old length => no changes needed
* (not even array allocation).
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
important for callers
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
clear array part flag only after switching
* Writability check
tv1 points to value storage
caller must have decref'd values above new_a_size (if that is necessary)
* XXX: shrink array allocation or entries compaction here?
not found in 'curr', next in prototype chain; impose max depth
FOUND
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
t >= 0 always true, unsigned
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
target
fall thru
[key setter this val]
comment: Note: we can reuse 'desc' here
label: code-design
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
data property or accessor without getter
comment: XXX: fastint
label: code-design
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
Careful with wrapping (left shifting idx would be unsafe).
[ ...val ] -> [ ... ]
currently used -> new size
mask out flags not actually stored
varenv remains reachable through 'obj'
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
comment: XXX: optimize this filling behavior later
label: code-design
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
[key result] -> [result]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
map is reachable through obj
0 if no used entries
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
resume check from proxy target
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
arguments MUST have an initialized lexical environment reference
if new_p == NULL, all of these pointers are NULL
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
automatic length update
always grow the array, no sparse / abandon support here
comment: remove old value
label: code-design
[ ... key ] -> [ ... ]
always in entry part, no need to look up parents etc
* Copy keys and values in the entry part (compacting them at the same time).
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
XXX: C recursion limit if proxies are allowed as handler/target values
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
Arrays never have other exotic behaviors.
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
value from hook
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
[... put_value varname]
number
Get minimum entry part growth for a certain size.
if accessor without getter, return value is undefined
undefined is accepted
[obj key desc value get set curr_value varname]
key must not already exist in entry part
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
* Actual Object.defineProperty() default algorithm.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
[ ... value? getter? setter? ]
may become sparse...
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Entries part is a bit more complex
label: code-design
remove key
array 'length' is always a number, as we coerce it
= IsAccessorDescriptor(Desc)
Reject attempt to change a read-only object.
idx_value may be < 0 (no value), set and get may be NULL
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
-> [ ... handler trap ]
DUK_USE_ES6_PROXY
not reachable
marker values for hash part
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
no need for 'caller' post-check, because 'key' must be an array index
remove in_val
Grow entry part allocation for one additional entry.
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
for zero size, don't push anything on valstack
[key result]
remaining actual steps are carried out if standard DefineOwnProperty succeeds
curr is accessor -> cannot be in array part
E5 Section 15.5.5.2
equality not actually possible
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
ignore result
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
comment: XXX: is valstack top best place for argument?
label: code-design
XXX: sufficient to check 'strict', assert for 'is function'
Leave 'value' on stack
return value
[ ... val key ] -> [ ... key val ]
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
result: hash_prime(floor(1.2 * e_size))
errors out if out of memory
stack contains value (if requested), 'out_desc' is set
curr and desc are accessors
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
* Entries part
second incref for the entry reference
* Not found as a concrete property, check whether a String object
* virtual property matches.
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
prev value can be garbage, no decref
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
step 3.e: replace 'Desc.[[Value]]'
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
[str] -> [substr]
value from target
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
Note: this order matters (final value before deleting map entry must be done)
unconditional
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
0 = no update
Grow array part for a new highest array index.
comment: XXX: awkward helpers
label: code-design
* Pre resize assertions.
curr is data, desc is accessor
stack prepped for func call: [ ... trap handler ]
remove hash entry (no decref)
resume write to target
For internal use: get non-accessor entry value
* Internal helpers for managing object 'length'
All the flags fit in 16 bits, so will fit into duk_bool_t.
throw
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
[... value this_binding]
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Note: 'curr' refers to 'length' propdesc
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
varname is still reachable
get varenv for varname (callee's declarative lexical environment)
guaranteed to finish
Leave 'setter' on stack
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
string is 'eval' or 'arguments'
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
computed live
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
* Prototypes
string hash
The external string struct is defined even when the feature is inactive.
string is a reserved word (strict)
slower but more compact variant
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
string is a reserved word (non-strict)
string is ASCII, clen == blen
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: should never be called
label: code-design
placed in duk_heaphdr_string
length in codepoints (must be E5 compatible)
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
string is a valid array index
string is internal
string data is external (duk_hstring_external)
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
length in bytes (not counting NUL term)
DUK_HSTRING_H_INCLUDED
* Misc
Caller must check character offset to be inside the string.
unsigned
This may throw an error though not for valid E5 strings.
* Misc support functions
!DUK_USE_HSTRING_CLEN
comment: Most practical strings will go here.
label: code-design
comment: Convenience copies from heap/vm for faster access.
label: code-design
allocation size
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
next to use, highest used is top - 1
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
current lexical environment (may be NULL if delayed)
Current compiler state (if any), used for augmenting SyntaxErrors.
No field needed when strings are in ROM.
* Catcher defines
end of valstack allocation (exclusive)
function executes as a constructor (called via "new")
cached: valstack_end - valstack (in entries, not bytes)
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
catch part will catch
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
roughly 512 bytes
DUK_USE_ROM_STRINGS
thread has yielded
roughly 256 bytes
who resumed us (if any)
callstack index of related activation
* Flags for __FILE__ / __LINE__ registered into tracedata
roughly 1 kiB
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
activation prevents yield (native call or "new")
function executes in strict mode
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Sanity limits for stack sizes.
borrowed: full duk_tval for function being executed; for lightfuncs
indirect allocs
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
number of activation records in callstack preventing a yield
activation has active breakpoint(s)
Call stack. [0,callstack_top[ is GC reachable.
thread not currently running
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
roughly 128 bytes
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
DUK_HTHREAD_H_INCLUDED
borrowed reference to catch variable name (or NULL if none)
roughly 0.5 kiB
bottom of current frame
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
thread currently running (only one at a time)
top of current frame (exclusive)
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
* Prototypes
activation has tail called one or more times
Current strictness flag: affects API calls.
Backpointers.
roughly 2 kiB
values for the state field
needed for stepping
Yield/resume book-keeping.
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
finally part will catch
idx_base and idx_base+1 get completion value and type
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
Thread state.
request to create catch binding
nop
start of valstack allocation
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
* Struct defines
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
activation is a direct eval call
Shared object part
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
type and control flags, label number
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
current variable environment (may be NULL if delayed)
Catch stack. [0,catchstack_top[ is GC reachable.
* Stack constants
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
* Activation defines
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
thread resumed another thread (active but not running)
roughly 64 bytes
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
catch or with binding is currently active
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
countdown state
* Thread defines
thread has terminated
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* duk_hthread allocation and freeing.
valstack
callstack
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
For indirect allocs.
catchstack
comment: XXX: relocate
label: code-design
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
currently, even for Array.prototype
normal valued properties
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
Architecture, OS, and compiler strings
DUK_USE_LIGHTFUNC_BUILTINS
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
enable exotic behaviors last
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
initjs data is NUL terminated
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
[ (builtin objects) name func ]
chain
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Cast converts magic to 16-bit signed value
Packed or unpacked tval
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
Object property allocation layout
avoid empty label at the end of a compound statement
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
Inherit from ROM-based global object: less RAM usage, less transparent.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
always provideThis=true
unsigned
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
def_value
DUK_USE_USER_INITJS
* The default property attributes are correct for all
* function valued properties of built-in objects now.
genbuiltins.py ensures
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
Endianness indicator
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
comment: XXX: function properties
label: code-design
* Since built-ins are not often extended, compact them.
convenience
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
only Array.prototype matches
[ (builtin objects) name ]
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
exhaustive
-> [ ... new_global new_globalenv new_global new_global ]
Alignment guarantee
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
DUK_USE_ROM_OBJECTS
some assertions
comment: XXX: compression
label: code-design
side effect free
comment: integer mixed endian not really used now
label: code-design
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
always 1 arg
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
DUK_HOBJECT_FLAG_STRICT varies
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
must hold DUK_VARARGS
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
key, getter and setter, now reachable through object
comment: XXX: compression (as an option)
label: code-design
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
No built-in functions are constructable except the top
* level ones (Number, etc).
Low memory options
accessor flag not encoded explicitly
probe
no prototype or class yet
DUK_USE_BUILTIN_INITJS
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
always 0 args
[ (builtin objects) ]
must be signed
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
* Encoding constants, must match genbuiltins.py
XXX: ARRAY_PART for Array prototype?
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
native function properties
all native functions have NEWENV
push operation normalizes NaNs
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
no prototype
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
no need to decref
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
Write bytecode executor's curr_pc back to topmost activation (if any).
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Order of unwinding is important
ptr_curr_pc != NULL only when bytecode executor is active.
unwinds valstack, updating refcounts
DUK_USE_DEBUGGER_SUPPORT
* Thread support.
side effects, possibly errors
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
avoid warning (unsigned)
unsigned
* Restore 'caller' property for non-strict callee functions.
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
true, despite side effect resizes
note: any entries above the callstack top are garbage and not zeroed
cannot grow
With lightfuncs, act 'func' may be NULL
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
func is NULL for lightfunc
must be, since env was created when catcher was created
note: any entries above the catchstack top are garbage and not zeroed
* Update preventcount
avoid side effect issues
current lex_env of the activation (created for catcher)
Note that multiple catchstack entries may refer to the same
* callstack entry.
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
side effects
no incref needed
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
check that there is space for at least one new entry
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
No need for a NULL/zero-size check because new_size > 0)
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
prototype is lex_env before catcher created
avoid side effects
this is a bit approximate (errors out before max is reached); this is OK
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
shrink failure is not fatal
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
common case, already closed, so skip
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
DUK_INTERNAL_H_INCLUDED
autogenerated: strings and built-in object init data
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
builtins need e.g. duk_tval tag definitions
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
comment: unused
label: code-design
DUK_JMPBUF_H_INCLUDED
use SameValue instead of non-strict equality
conversions, coercions, comparison, etc
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
identifiers and environment handling
Flags for duk_js_compare_helper().
E5 Sections 11.8.1, 11.8.5; x < y
bytecode execution
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
comment: unused
label: code-design
Flags for duk_js_equals_helper().
eval left argument first
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
duk_handle_ecma_call_setup: setup for a tail call
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
call is a direct eval call
call handling
* Ecmascript execution, support primitives.
comment: unused
label: code-design
negate result
DUK_JS_H_INCLUDED
Flags for call handling.
duk_handle_ecma_call_setup: setup for a resume()
use strict equality instead of non-strict equality
pre/post opcode values have constraints,
if B/C is >= this value, refers to a const
misc constants and helper macros
DUK_OP_TRYCATCH flags in A
use 'undefined' for value automatically
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
DUK_OP_RETURN flags in A
DUK_OP_CALL flags in A
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
* Ecmascript bytecode
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
DUK_OP_EXTRA, sub-operation in A
function declaration
DUK_JS_BYTECODE_H_INCLUDED
dummy value used as marker
see duk_js_executor.c
comment: XXX: incref by count (2) directly
label: code-design
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
success/error path both do this
num entries of new func at entry
other call
no need to unwind
* Forward declarations.
Strict functions don't get their 'caller' updated.
comment: XXX: don't want to shrink allocation here
label: code-design
non-strict: non-deletable, writable
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
Get valstack index for the func argument or throw if insane stack.
'i' is the first entry we'll keep
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
tv1 is -below- valstack_bottom
[ args(n) [crud] formals arguments map mappednames ]
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
* Interrupt counter fixup (for development only).
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
'caller' must only take on 'null' or function value
Call handling and success path. Success path exit cleans
* up almost all state.
comment: XXX: avoid this check somehow
label: code-design
'func' on stack (borrowed reference)
at least effective 'this'
[ ... this_new | arg1 ... argN ]
never executed
comment: Longjmp state is cleaned up by error handling
label: code-design
* Thread state check and book-keeping.
bottom of current func
For native calls must be NULL so we don't sync back
comment: XXX: assume these?
label: code-design
Then reuse the unwound activation; callstack was not shrunk so there is always space
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
step 11
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
Note: either pointer may be NULL (at entry), so don't assert
comment: XXX: unify handling with native call.
label: code-design
Lightfuncs are always native functions and have "newenv".
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
XXX: byte offset?
first call
may need unwind
* Helper for updating callee 'caller' property.
side effects
bound chain resolved
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
formals for 'func' (may be NULL if func is a C function)
Normal non-bound function.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
should never happen for a strict callee
Backup 'caller' property and update its value.
* Valstack manipulation for results.
no need to handle thread state book-keeping here
out of spec, must be configurable
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
same as during entry
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
third arg: absolute index (to entire valstack) of idx_bottom of new activation
strict: non-deletable, non-writable
-> [ ... func this arg1 ... argN _Args length ]
1 = num actual 'return values'
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
current thread
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
Duktape/C API guaranteed entries (on top of args)
Success path.
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
bound function chain has already been resolved
base of known return values
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
step 11.c is relevant only if non-strict (checked in 11.c.ii)
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
Return value handling.
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
flags
Unwind the topmost callstack entry before reusing it
borrowed, no refcount
same thread
may be NULL
pop 'name'
Other longjmp types are handled by executor before propagating
* the error here.
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: duk_get_length?
label: code-design
side effects (currently none though)
[ ... formals arguments map mappedNames ]
# argument registers target function wants (< 0 => "as is")
For now all calls except Ecma-to-Ecma calls prevent a yield.
duk_hthread_callstack_unwind() will decrease this on unwind
[ ... formals ]
See: tests/ecmascript/test-spec-bound-constructor.js
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
* Init argument related properties
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
DUK_USE_ASSERTIONS
comment: XXX: inefficient; block remove primitive
label: code-design
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
Lightfuncs are always considered strict.
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
'act' already set above
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
lightfuncs are treated like objects and not coerced
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
* Make the C call
comment: XXX: rework
label: code-design
index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
comment: XXX: this should be an assert
label: test
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
[ ... | (crud) errobj ]
Start filling in the activation
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
assumed to bottom relative
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
[ ... func this <some bound args> arg1 ... argN _Args ]
really 'not applicable' anymore, should not be referenced after this
idx of first argument on stack
thr->ptr_curr_pc is set by bytecode executor early on entry
Chop extra retvals away / extend with undefined.
setjmp catchpoint setup
[ ... errobj ]
Longjmp state is kept clean in success path
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
final configuration
Automatic error throwing, retval check.
no need to decref previous value
Explicit check for fastint downgrade.
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
refer to callstack entries below current
Note: not a valid stack index if num_stack_args == 0
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
must be updated to work properly (e.g. creation of 'arguments')
write back
extend with undefined
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
should actually never happen, but check anyway
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
Use loop to minimize code size of relookup after bound function case
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
don't want an intermediate exposed state with invalid pc
catchstack limits
# total registers target function wants on entry (< 0 => never for ecma calls)
idx_argbase
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
don't want an intermediate exposed state with func == NULL
Error; error value is in heap->lj.value1.
* Store entry state.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
[ ... retval ]
no incref
may have side effects
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
NULL for lightfunc
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
Lightweight function: never bound, so terminate.
# argument registers target function wants (< 0 => never for ecma calls)
compiler ensures this
internal spare
already NULLed (by unwind)
* Misc shared helpers.
out of spec, don't care
[ ... func this arg1 ... argN envobj ]
+ spare
keep current valstack_top
XXX: optimize value stack operation
bottom of new func
can't happen when keeping current stack size
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
XXX: byte offset
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
topmost activation idx_retval is considered garbage, no need to init
[ args [crud] arguments ]
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
comment: XXX: some overlapping code; cleanup
label: code-design
must be signed for loop structure
[ ... func this <bound args> arg1 ... argN ]
vararg
no need to create environment record now; leave as NULL
[ ... arg1 ... argN ]
caller must check
set exotic behavior only after we're done
[ ... name ]
[ ... | (crud) ]
[ ... arg1 ... argN envobj ]
nothing to incref
Note: may be NULL if first call
num args starting from idx_argbase
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
valstack index of 'func' and retval (relative to entry valstack_bottom)
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
Restore entry thread executor curr_pc stack frame pointer.
idx_args = idx_func + 2
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
Success path handles
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
XXX: bump preventcount by one for the duration of this call?
stack discipline consistency check
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
See: test-bug-tailcall-preventyield-assert.c.
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
[ ... func this (crud) retval ]
XXX: assert? compiler is responsible for this never happening
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
* Shift to new valstack_bottom.
comment: XXX: unnecessary, handle in adjust
label: code-design
already updated
to avoid relookups
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
Note: either pointer may be NULL (at entry), so don't assert.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
[ ... func this arg1 ... argN ]
replace in stack
comment: XXX: check .caller writability?
label: code-design
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
duk_tval ptr for 'func' on stack (borrowed reference)
tail call -> reuse current "frame"
Unwind catchstack entries referring to the callstack entry we're reusing
local copy to avoid relookups
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
'arguments'
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
at least errobj must be on stack
comment: XXX: inefficient; block insert primitive
label: code-design
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
Unwind.
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
Error path.
comment: XXX: could be eliminated with valstack adjust
label: code-design
* Ecmascript call
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Argument validation and func/args offset.
# total registers target function wants on entry (< 0 => "as is")
cannot be strict (never mapped variables)
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
no compact
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
* Valstack spare check
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
'func' wants stack "as is"
* Init arguments properties, map, etc.
name
[ ... arg1 ... argN envobj argobj ]
act->func
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
idx_this = idx_func + 1
or a non-catching entry
comment: XXX: tv_func is not actually needed
label: requirement
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
different thread
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
step 12
[ ... name name ]
-> [ ... func this arg1 ... argN _Args ]
steps 13-14
no prototype
leave formals on stack for later use
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
* Native call.
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
duk_has_prop() popped the second 'name'
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
comment: XXX: block removal API primitive
label: code-design
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
only functions can have arguments
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
DUK_TOK_SNEQ
DUK_TOK_TRUE
* Variant 2
UnaryExpression
Buffer length is bounded to 0xffff automatically, avoid compile warning.
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
No need to assert, buffer size maximum is 0xffff.
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
inserted jump
curr_token follows 'function'
Output shuffle needed after main operation
DUK_TOK_TRY
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
push before advancing to keep reachable
DUK_TOK_GET
init function state: inits valstack allocations
for storing/restoring the varmap binding for catch variable
convenience helpers
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
omitted
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
-> pushes fixed buffer
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
Ensure compact use of temps.
default case exists: go there if no case matches
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
eat 'do'
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
-> [ ... name index ]
max # of values initialized in one MPUTARR set
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
e.g. DUK_OP_PREINCV
reuse 'res' as 'left'
Initial bytecode size allocation.
XXX: patch initial size afterwards?
yes, must set array length explicitly
in-place setup
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
binding power must be high enough to NOT allow comma expressions directly
flags
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
implicit_return_value
* Initialize function state for a zero-argument function
* Special name handling
eat 'for'
right associative
init 'curr_token'
allow a constant to be returned
DUK_TOK_LBRACKET
XXX: check num_args
DUK_TOK_LPAREN
directly uses slow accesses
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
DUK_TOK_LT
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
catch depth from current func
eat colon
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
[ ... pattern flags ]
* Init compiler and lexer contexts
DUK_TOK_NEQ
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
if num_values > 0, MPUTARR emitted by outer loop after break
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
DUK_USE_NONSTD_FUNC_STMT
DUK_TOK_STRING
stmt has non-empty value
for array and object literals
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-1 == not set, -2 == pending (next statement list)
Explicit check for fastint downgrade.
DUK_TOK_RETURN
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
* Detect iteration statements; if encountered, establish an
* empty label.
comment: Should never happen but avoid infinite loop just in case.
label: code-design
indirect opcode follows direct
statement parsing
* Function declarations
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
Valstack should suffice here, required on function valstack init
reg_res should be smallest possible
pushes function template
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
Identifier, i.e. don't allow reserved words
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
Slot B
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
XXX: to util
Specific assumptions for opcode numbering.
_Pc2line
EQUALITY EXPRESSION
register declarations in first pass
DUK_TOK_EQUALSIGN
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
useful for patching jumps later
name
-> [ ... func name ]
inherit initial strictness from parent
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
DUK_TOK_WHILE
Use special opcodes to load short strings
temp variable to pass constants and flags to shared code
truncated in case pass 3 needed
reg
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
DUK_TOK_MUL_EQ
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
DUK_TOK_DO
comment: XXX: match flag is awkward, rework
label: code-design
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Evaluate RHS only when LHS is safe.
DUK_TOK_VOID
DUK_USE_PC2LINE
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
no catchers
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
* Variant 4
* Preliminaries
is_extra
Slot A
terminates expression; e.g. post-increment/-decrement
* Parser duk__advance() token eating functions
inline string concatenation
no operators
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
Strict: never allow function declarations outside top level.
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
BITWISE EXPRESSIONS
Used for minimal 'const': initializer required.
DUK_TOK_CONST
DUK_TOK_RPAREN
Slot C
true
comma after a value, expected
general temp register
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
DUK_TOK_SUPER
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
DUK_TOK_NULL
step 4.a
Check whether statement list ends.
Setup state. Initial ivalue is 'undefined'.
DUK_TOK_STATIC
first coerce to a plain value
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
'res' contains expression value
invalidates tv1, tv2
rc_varname and reg_varbind are ignored here
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
reg(ignored)
bytecode limits
DUK_TOK_SEQ
XXX: clarify on when and where DUK__CONST_MARKER is allowed
bump up "allocated" reg count, just in case
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
DUK_TOK_INSTANCEOF
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
DUK_TOK_IF
evaluate to plain value, no forced register (temp/bound reg both ok)
JUMP L1 omitted
e.g. DUK_OP_POSTINCR
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
* Debug dumping
* The switch statement is pretty messy to compile.
* See the helper for details.
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
knock back "next temp" to this whenever possible
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Detected a directive
entry_top + 3
ASSIGNMENT EXPRESSION
if a site already exists, nop: max one label site per statement
first value: comma must not precede the value
DUK_TOK_CATCH
rethrow
key encountered as a plain property
e.g. DUK_OP_POSTINCV
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
sufficient for keeping temp reg numbers in check
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
pass2 allocation handles this
DUK_TOK_IN
jump to false
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
comment: XXX: duk_set_length
label: code-design
DUK_TOK_BOR_EQ
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
NB: must accept reserved words as property name
+1, right after inserted jump
* After arguments, allocate special registers (like shuffling temps)
* Variant 1
DUK_TOK_DEFAULT
temp reset is not necessary after duk__parse_stmt(), which already does it
same handling for identifiers and strings
e.g. DUK_OP_PREINCP
decl name
LOGICAL EXPRESSIONS
jump is inserted here
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
const flag for C
unary minus
number of pairs in current MPUTOBJ set
Tear down state.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
expression parsing helpers
[ ... key_obj key ]
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
one token
DUK_TOK_BNOT
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
comment: alloc temp just in case, to update max temp
label: code-design
is_setget
DUK_TOK_COMMA
Shuffle decision not changed.
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
temp_start+0 = key, temp_start+1 = closure
forced_reg
DUK_TOK_FINALLY
'data' (and everything in it) is reachable through h_res now
arg2 would be clobbered so reassign it to a temp.
DUK_TOK_REGEXP
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
DUK_TOK_PACKAGE
* Peephole optimize JUMP chains.
temps
to body
no match, next case
* Directive prologue tracking.
DUK_TOK_IDENTIFIER
* Misc helpers
finished jump
POSTFIX EXPRESSION
base
DUK_TOK_PUBLIC
variable name reg/const, if variable not register-bound
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
NEXTENUM jump slot: executed when enum finished
single string token
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
DUK_TOK_ARSHIFT
eat the right paren
comment: XXX: possibly incorrect handling of empty expression
label: code-design
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
is_decl
unsigned
Expression, ']' terminates
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
no need to coerce
func limits
'res' is used for "left", and 'tmp' for "right"
[ ... template ]
end switch (tok)
XXX: shared handling for 'duk__expr_lhs'?
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
num_values and temp_start reset at top of outer loop
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
allow_source_elem
duplicate/invalid key checks; returns 1 if syntax error
eat 'in'
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
* Detected label
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
DUK_TOK_SUB
Default implicit return value.
elision - flush
temp reg for key literal
* Parse a case or default clause.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
DUK_TOK_THIS
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
max # of key-value pairs initialized in one MPUTOBJ set
expect_token
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
>>
trailing elisions?
unary plus of a number is identity
no comma
advance to get one step of lookup
right paren eaten
MPUTARR emitted by outer loop
DUK_TOK_NUMBER
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
jump for 'finally' case or end (if no finally)
* Identifier handling
DUK_TOK_SET
Code is not accepted before the first case/default clause
Note: 'q_instr' is still used below
start array index of current MPUTARR set
expect_eof
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
rbp_flags
use 'left' as a temp
don't allow const
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
DUK_TOK_BAND
if highest bit of a register number is set, it refers to a constant instead
no need to reset temps, as we're finished emitting code
-> [ ... ]
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
Expression_opt
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
still in prologue
DUK_TOK_DIV_EQ
* Arguments check
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
bc
parse new token
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
numargs
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
DUK_TOK_ELSE
nret
See MPUTOBJ comments above.
preincrement and predecrement
Need a short reg/const, does not have to be a mutable temp.
Expression, terminates at a ')'
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
DUK_TOK_DEBUGGER
patched later
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
comment: XXX: depend on available temps?
label: code-design
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
last array index explicitly initialized, +1
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
MPUTOBJ emitted by outer loop
MultiplicativeExpression
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
need side effects, not value
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
allow automatic semicolon even without lineterm (compatibility)
binding power "levels" (see doc/compiler.rst)
* Cleanup: restore original function, restore valstack state.
DUK_TOK_QUESTION
comment: XXX: macro smaller than call?
label: code-design
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
result reg
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
eat comma
comment: XXX: source code property
label: code-design
this is needed for regexp mode
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
[ ... varname ]
preinitialize lexer state partially
jump to next case clause
const
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
eat 'if'
key encountered as a getter
comment: XXX: macros
label: code-design
must have catch and/or finally
DUK_TOK_GT
'new' MemberExpression
DUK_TOK_BXOR
* Store lexer position for a later rewind
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
DUK_TOK_DECREMENT
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
require a (mutable) temporary as a result (or a const if allowed)
DUK_OP_NONE marks a 'plain' assignment
keep in on valstack, use borrowed ref below
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
res.x1 -> res.x2
number of values in current MPUTARR set
<<
to exit
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
Parse formals.
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
getter/setter
false
register bound variables are non-configurable -> always false
nargs
XXX: init or assert catch depth etc -- all values
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
copy bytecode instructions one at a time
LHS is already side effect free
* Variant 3
DUK_TOK_IMPORT
XXX: range assert
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
* On second pass, skip the function.
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
token closes expression, e.g. ')', ']'
fileName
chain jumps for case
* evaluation and checking
needed for line number tracking (becomes prev_token.start_line)
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
function call
DUK_TOK_MUL
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
const limits
don't coerce yet to a plain value (variant 3 needs special handling)
The issues below can be solved with better flags
[ ... res ]
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
continue jump
LeftHandSideExpression does not allow empty expression
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
First evaluate LHS fully to ensure all side effects are out.
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
allow source elements
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
eat 'function'
one token before
keep in valstack
Limit checks for bytecode byte size and line number.
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
normal key/value
Note: escaped characters differentiate directives
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
reject 'in' token (used for for-in)
Note: 0xff != DUK_BC_B_MAX
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
special RegExp literal handling after IdentifierName
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
statement is guaranteed to be terminal (control doesn't flow to next statement)
fall-through jump to next code of next case (backpatched)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
directive prologue status at entry
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
* Variant 1 or 3
temp object for tracking / detecting duplicate keys
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
DUK_TOK_SEMICOLON
DUK_TOK_RSHIFT
* Size-optimized pc->line mapping.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
DUK_TOK_EQ
code emission
strict mode restrictions (E5 Section 12.2.1)
result in csreg
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
top-down expression parser
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
E5 Section steps 7-8
comment: XXX: unoptimal use of temps, resetting
label: code-design
Any 'res' will do.
is_decl
varmap is already in comp_ctx->curr_func.varmap_idx
DUK_TOK_SWITCH
eat 'try'
b
Note: 0xff != DUK_BC_C_MAX
_Source
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
COMMA
Parse statements until a closing token (EOF or '}') is found.
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
The token in the switch has already been eaten here
DUK_TOK_LAND
currently all labels accept a break, so no explicit check for it now
DUK_TOK_NEW
force_no_namebind
DUK_TOK_RBRACKET
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
statement does not terminate directive prologue
SHIFT EXPRESSION
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
DUK_TOK_LOR
comment: XXX: specific getter
label: code-design
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
intentional overlap with earlier memzero
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
chain jumps for 'fall-through'
* after a case matches.
assumed to also be PC of "LABEL"
* Main switch for statement / source element type.
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
DUK_TOK_DELETE
DUK_TOK_BOR
DUK_TOK_CASE
DUK_TOK_ADD_EQ
comment: XXX: optimize temp reg use
label: code-design
* Compact the function template.
>>>
PRIMARY EXPRESSIONS
left.x1 -> res.x1
num_args
DUK_TOK_ADD
always terminates led()
allocate to reg only (not const)
skip jump conditionally
prevent duk__expr_led() by using a binding power less than anything valid
default clause matches next statement list (if any)
filter out flags from exprtop rbp_flags here to save space
eat 'return'
* Parse a function body or a function-like expression, depending
* on flags.
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
FUNCTION EXPRESSIONS
MULTIPLICATIVE EXPRESSION
may be a string constant
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
entry_top + 1
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
UNARY EXPRESSIONS
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
a statement following a label cannot be a source element
* (a function declaration).
Note: Identifier rejects reserved words
[ ... filename (temps) func ]
DUK_TOK_EOF
temp reg
* Second pass parsing.
spare
tmp -> res
DUK_TOK_LCURLY
DUK_TOK_BREAK
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
DUK_TOK_MOD_EQ
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
DUK_TOK_WITH
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
DUK_TOK_PERIOD
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
'res' must be a plain ivalue, and not register-bound variable.
not present
ADDITIVE EXPRESSION
function helpers
default case does not exist, or no statements present
* after default case: finish case evaluation
expected ival
use temp_next for tracking register allocations
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
comment: may indirectly slow access through a direct eval
label: code-design
Update all labels with matching label_id.
<
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
variable binding register if register-bound (otherwise < 0)
key
comment: XXX: to be implemented?
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
just in case
entry_top + 4
key encountered as a setter
continue jump not patched, an INVALID opcode remains there
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
comment: unused
label: code-design
current (next) array index
* Push result object and init its flags
step 4.d
duk_hobject_set_length_zero(thr, func->h_funcs);
register binding lookup is based on varmap (even in first pass)
empty statement with an explicit semicolon
one operator (= assign)
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
see above
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
[ ... name reg/null ] -> [ ... ]
no need to init reg, it will be undefined on entry
must restore reliably before returning
DUK_TOK_THROW
Just flip the single bit.
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
break jump
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
[ ... key_obj key key ]
allow empty expression
expect_eof
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
label handling
DUK_TOK_SUB_EQ
Expression
allow negative PCs, behave as a no-op
Important main primitive.
ivalue/ispec helpers
DUK_TOK_BXOR_EQ
code_idx = entry_top + 0
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
name
c
E5 Section 11.13.1 (and others for other assignments), step 4.
DUK_TOK_CONTINUE
eat 'throw'
DUK_TOK_CLASS
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
comment: XXX: spare handling, slow now
label: code-design
comma check
pop varname
* Parse function body
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
the outer loop will recheck and exit
allow caller to give a const number with the DUK__CONST_MARKER
varname
jump to end
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
basereg
a
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
* Default clause.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
DUK_USE_REGEXP_SUPPORT
CONDITIONAL EXPRESSION
break/continue without label
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
jump for 'catch' case
comment: XXX: append primitive
label: code-design
[ ... name reg_bind ]
e.g. DUK_OP_PREINCR
eat 'while'
try part
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
next loop requires a comma
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
get const for value at valstack top
eat 'break' or 'continue'
DUK_TOK_TYPEOF
* Parse inner function
comment: unused
label: code-design
No BC shuffling now.
number
syntactically left-associative but parsed as right-associative
reserve a jumpslot after instr before target spilling, used for NEXTENUM
* Wrap up
at least one opcode emitted
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
relookup after possible realloc
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
regexp literal must not follow this token
-> [ ... func ]
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
slot B is a target (default: source)
without finally, the second jump slot is used to jump to end of stmt
forget temp
[ ... filename &comp_stk ]
break/continue with label (label cannot be a reserved word, production is 'Identifier'
Have a catch variable.
* Intermediate value helpers
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
reset function state (prepare for pass 2)
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
DUK_TOK_EXPORT
entry_top + 0
* Variant 2 or 4
[ ... escaped_source bytecode ]
return 'res' (of right part) as our result
jump from true part to end
comment: XXX: spilling
label: code-design
eat identifier
x1 must be a string
break matches always
dangerous: must only lower (temp_max not updated)
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
format is bit packed
DUK_TOK_LBRACKET already eaten, current token is right after that
parse args starting from "next temp", reg_target + 1
is_setget
enable manually for dumping
shadowed, ignore
DUK_TOK_COLON
DUK_TOK_IMPLEMENTS
jump to end or else part
for side effects, result ignored
for duk_error_augment.c
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
non-Reference deletion is always 'true', even in strict mode
no statement value (unlike function expression)
jump to next loop, using reg_v34_iter as iterated value
DUK_USE_TAILCALL
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
* Convert duk_compiler_func to a function template
final result is already in 'res'
-> loop body
catch jump
num_pairs and temp_start reset at top of outer loop
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
* Wrapping duk_safe_call() will mangle the stack, just return stack top
pc_label
slot A is a source (default: target)
assume 'var' has been eaten
old value is number: no refcount
empty expressions can be detected conveniently with nud/led counts
DUK_TOK_ALSHIFT_EQ
label limits
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
DUK_TOK_GE
DUK_TOK_LET
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
else an array initializer element
tracks maximum initialized index + 1
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
object literal key tracking flags
reset 'allow_in' for parenthesized expression
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
parse args starting from "next temp"
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
lexing
Main operation
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
initial index
'new' MemberExpression Arguments
stmt has explicit/implicit semicolon terminator
op_flags
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
DUK_TOK_FUNCTION
array writes autoincrement length
* Prototypes
main expression parser function
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
statements go here (if any) on next loop
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
silence scan-build warning
varname is popped by above code
always allow 'in', coerce to 'tr' just in case
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
DUK_TOK_YIELD
DUK_TOK_LNOT
slot C is a target (default: source)
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
end switch
DUK_TOK_LE
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
XXX: similar coercion issue as in DUK_TOK_PERIOD
borrowed reference
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
bp to use when parsing a top level Expression
Matches both +0 and -0 on purpose.
bp is assumed to be even
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
transfer flags
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
eat 'var'
DUK_TOK_INTERFACE
DUK_TOK_DIV
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
iteration statements allow continue
reg/const for switch value
unary plus
may be undefined
reg/const for case value
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
DUK_TOK_PRIVATE
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
then to a register
expect EOF instead of }
DUK_TOK_ARSHIFT_EQ
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
no code needs to be emitted, the regs already have values
DUK_TOK_RCURLY
fills window
DUK_TOK_BAND_EQ
jump is inserted here (variant 3)
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't allow continue
valstack will be unbalanced, which is OK
== DUK__MAX_TEMPS is OK
DUK_TOK_EXTENDS
[ ... varmap ]
inline arithmetic check for constant values
identifier handling
* Helpers for duk_compiler_func.
DUK_TOK_RSHIFT_EQ
step 4.b
explicit semi follows
shadowed; update value
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
advance, whatever the current token is; parse next token in regexp context
DUK_TOK_PROTECTED
curr_token = get/set name
target
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
expr_flags
Note: expect that caller has already eaten the left paren
advance, expecting current token to be a specific token; parse next token in regexp context
already in correct reg
RELATIONAL EXPRESSION
* Source filename (or equivalent), for identifying thrown errors.
e.g. DUK_OP_POSTINCP
preallocated temporaries (2) for variants 3 and 4
emit instruction; could return PC but that's not needed in the majority
* of cases.
DUK_TOK_ALSHIFT
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
trailing comma followed by rcurly
eat 'with'
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
step 4.c
[ ... key_obj key val ]
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
DUK_TOK_INCREMENT
const flag for B
keep func->h_argnames; it is fixed for all passes
misc
source is a function expression (used for Function constructor)
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
parsing in "directive prologue", recognize directives
value stack indices for tracking objects
DUK_ISPEC_XXX
comment: code emission temporary
label: code-design
maximum bytecode length in instructions
bufwriter for code
C array of duk_labelinfo
Compiling state of one function, eventually converted to duk_hcompiledfunction
with stack depth (affects identifier lookups)
variable map for pass 2 (identifier -> register number or null (unmapped))
curr_token slot1 (matches 'lex' slot1_idx)
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
type to represent a reg/const reference during compilation
function is strict
* Ecmascript compiler.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
bytecode opcode (or extraop) for binary ops
current and previous token for parsing
comment: function name (borrowed reference), ends up in _name
label: code-design
lexing (tokenization) state (contains two valstack slot indices)
property access
array of active label names
is eval code
1e8: protects against deeply nested inner functions
source is eval code (not global)
comment: function must not be tail called
label: code-design
comment: code_idx: not needed
label: requirement
no value
inner function numbering
always set; points to a reserved valstack slot
expression is left-hand-side compatible
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
highest value of temp_reg (temp_max - 1 is highest used reg)
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* Compiler state
argument/function declaration shadows 'arguments'
is a function declaration (as opposed to function expression)
variable access
function needs shuffle registers
borrowed label name
is global code
strict outer context
filename being compiled (ends up in functions' '_filename' property)
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
function may call direct eval
catch depth at point of definition
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
comment: XXX: optimize to 16 bytes
label: code-design
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
function refers to 'arguments' identifier
comment: first register that is a temporary (below: variables)
label: code-design
catch stack depth
maximum loopcount for peephole optimization
value resides in 'valstack_idx'
value resides in a register or constant
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
label id allocation (running counter)
1 GB
current function being compiled (embedded instead of pointer for more compact access)
stats for current expression being parsed
* Prototypes
DUK_IVAL_XXX
comment: function makes one or more slow path accesses
label: code-design
is an actual function (not global/eval code)
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
is a setter/getter
ecmascript compiler limits
curr_token slot2 (matches 'lex' slot2_idx)
borrowed reference
type to represent a straight register reference, with <0 indicating none
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
next temporary register to allocate
parsing in "scanning" phase (first pass)
shuffle registers if large number of regs/consts
array
array of formal argument names (-> _Formals)
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
prev_token slot2
DUK_JS_COMPILER_H_INCLUDED
status booleans
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
current paren level allows 'in' token
numeric label_id (-1 reserved as marker)
prev_token slot1
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
statement id allocation (running counter)
recursion limit
parenthesis count, 0 = top level
number of formal arguments
register, constant, or value
temp reg handling
h_code: held in bw_code
* Fast paths
comment: 'd3' is never NaN, so no need to normalize
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
return value from Duktape.Thread.resume()
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
-> [... val this]
Preinc/predec for object properties.
Assume that thr->valstack_bottom has been set-up before getting here.
Sync and NULL early.
* E5 Section 11.4.9
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
an Ecmascript function
comment: XXX: improve check; check against nregs, not against top
label: code-design
-> [ ... regexp_instance ]
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
x >= y --> not (x < y)
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
Unary plus is used to force a fastint check, so must include
* downgrade check.
Duktape.Thread.yield() should prevent
comment: should never happen, but be robust
label: code-design
[ ... enum ] -> [ ... ]
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
side effects -> don't use tv_x, tv_y after
flags
Relookup and initialize dispatch loop variables. Debugger check.
never here
add_auto_proto
don't re-enter e.g. during Eval
-> [... obj key value]
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
may be < thr->catchstack initially
Longjmp handling has restored jmpbuf_ptr.
valstack top, should match before interpreting each op (no leftovers)
Entry level info.
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
XXX: assert 'c' is an enumerator
-> [val]
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
comment: XXX: refactor out?
label: code-design
[ ... env ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
cleared before entering catch part
-> [... obj]
no need to unwind catchstack
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
thr->heap->lj.value1 is already the value to throw
if boolean matches A, skip next inst
Preinc/predec for var-by-name, slow path.
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
bytecode has a stable pointer
cleared before entering finally
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
Overflow of the execution counter is fine and doesn't break
* anything here.
Restart bytecode execution, possibly with a changed thread.
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
no need for refcount update
reg count
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
* Slow path: potentially requires function calls for coercion
-> [ Object defineProperty undefined obj key desc ]
DUK_USE_FASTINT
ToNumber() for a fastint is a no-op.
B -> object register
* C -> C+0 contains key, C+1 closure (value)
x < y
call_flags
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
* Local declarations.
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
x > y --> y < x
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
curr_pc synced by duk_handle_ecma_call_setup()
resumee: [... initial_func] (currently actually: [initial_func])
comment: XXX: use duk_is_valid_index() instead?
label: code-design
-> [... obj value]
always normalized
DUK_USE_INTERRUPT_COUNTER
comment: writable, not configurable
label: code-design
written by a previous RESUME handling
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
comment: this is not strictly necessary, but helps debugging
label: code-design
this should never be possible, because the switch-case is
* comprehensive
Pre/post inc/dec for register variables, important for loops.
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
w/o refcounts
fast path
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
stable; precalculated for faster lookups
comment: 'val' is never NaN, so no need to normalize
label: code-design
may be reg or const
+2 = catcher value, catcher lj_type
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
[... obj] -> [...]
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
should not happen
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
[... constructor arg1 ... argN] -> [retval]
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
B -> target register
* C -> constant index of identifier name
* Execution timeout check
side effects
E5 Section 11.7.2, steps 7 and 8
updates thread state, minimizes its allocations
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
use_prev_pc
Must restart in all cases because we NULLed thr->ptr_curr_pc.
checked by Duktape.Thread.resume()
unsigned
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
E5 Section 11.2.3, step 6.a.i
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
lj.value1 is already set
Dispatch loop.
fall through if overflow etc
this may have side effects, so re-lookup act
Assume interrupt init/counter are properly initialized here.
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
allocate catcher and populate it (should be atomic)
E5 Section 11.7.1, steps 7 and 8
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
INACTIVE: no activation, single function value on valstack
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
enum_flags
E5 Sections 11.9.1, 11.9.3
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
Force pause if we were doing "step into" in another activation.
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
already set
[ ... val ] --> [ ... enum ]
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
Note: 'this' may be bound to any value, not just an object
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
+ spare
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
must "goto restart_execution", e.g. breakpoints changed
Share yield longjmp handler.
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
no need to unwind callstack
unwind to 'yield' caller
'this binding' is just under bottom
stable
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
Duktape.Thread.resume()
+0 = break, +1 = continue
Outer executor with setjmp/longjmp handling.
if debugging disabled
E5 Section 10.4.3
does not modify tv_x
[ ... func this arg1 ... argN ]
Cause an interrupt after executing one instruction.
side effects, perform in-place
'act' is no longer accessed, scanbuild fix
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
reg
no compact
restricted to regs
exit bytecode executor by rethrowing an error to caller
comment: XXX: side effect handling is quite awkward here
label: code-design
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
Call setup checks callability.
exit bytecode execution with return value
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
Write curr_pc back for the debugger.
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
no refcount changes
'null' enumerator case -> behave as with an empty enumerator
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment: XXX: could use at least one fewer loop counters
label: code-design
A -> flags
* B -> return value reg/const
* C -> currently unused
Note: left shift, should mask
Ecmascript function
curr_pc synced back above
relookup (side effects)
GH-303
return value from Duktape.Thread.yield()
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
unsigned shift
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
comment: Inner executor, performance critical.
label: code-design
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
x
lj.value1 already set
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
at least one activation, ours
XXX: assert idx_base
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
* Breakpoint and step state checks
[ ... env target target ]
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
overflow, fall through
restored if ecma-to-ecma setup fails
type
reset longjmp
comment: pseudotypes, not used in actual longjmps
label: code-design
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
A -> target reg
* BC -> inner function index
resumee
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
Fast path for the case where the register
* is a number (e.g. loop counter).
* Ecmascript bytecode executor.
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
comment: 'this' binding is not needed here
label: requirement
DUK_USE_EXEC_TIMEOUT_CHECK
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
entry level reached
get_value
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
signed shift
already declared, must update binding value
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
ensures callstack_top - 1 >= 0
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
variable value (function, we hope, not checked here)
x <= y --> not (x > y) --> not (y < x)
mandatory if du.d is a NaN
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
comment: not needed
label: requirement
comment: 'fun' is quite rarely used, so no local for it
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
idx_retval unsigned
DUK_USE_DEBUGGER_SUPPORT
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
'with' target must be created first, in case we run out of memory
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
not needed, as we exit right away
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
relookup, may have changed
comment: unused for label
label: code-design
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
relookup if changed
Shouldn't happen but check anyway.
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
-> [ ... escaped_source bytecode ]
result
not protected, respect reclimit, not constructor
[ ... env target ]
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
ignore
special result value handling
skip jump slots
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
We can directly access value stack here.
Set up curr_pc for opcode dispatch.
val
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: unused
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
Ecmascript activation + Duktape.Thread.resume() activation
always in executor
reachable through activation
thr->heap->lj.value2 is 'thread', will be wiped out at the end
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
important to use normalized NaN with 8-byte tagged types
+0 = catch
get before side effects
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
* E5 Section 11.4.8
always provideThis=true
duk_small_uint_fast_t c = DUK_DEC_C(ins);
comment: XXX: fastint fast path would be very useful here
label: code-design
no specific action, resume normal execution
Execute bytecode until returned or longjmp().
Relookup if relocated
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
num_stack_args
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
is resume, not a tail call
avoid referencing, invalidated
+1 = one retval
B -> target register for next key
* C -> enum register
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
cat_idx catcher is kept, even for finally
XXX: switch cast?
keep label catcher
state updated, restart bytecode execution
Must be restored here to handle e.g. yields properly.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
ToNumber() for a double is a no-op.
[ ... enum ] -> [ ... next_key ]
leave 'cat' as top catcher (also works if catchstack exhausted)
XXX: direct manipulation, or duk_replace_tval()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
terminate
unchanged by Duktape.Thread.resume()
unchanged from Duktape.Thread.yield()
A -> result reg
* B -> object reg
* C -> key reg/const
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
invalidated
[ ... val obj ]
env created above to stack top
-> [ Object res ]
Trigger at zero or below
'this' binding
end switch
Successful return: restore jmpbuf and return to caller.
resume caller must be an ecmascript func
y
'with' binding has no catch clause, so can't be here unless a normal try-catch
caller must change active thread, and set thr->resumer to NULL
unresolvable, no stack changes
[... s1 s2] -> [... s1+s2]
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
Recompute argument count: bound function handling may have shifted.
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
no prototype, updated below
unwind to 'resume' caller
guarantees entry_callstack_top - 1 >= 0
may be changed
Rethrow error to calling state.
* Update the interrupt counter
Stepped? Step out is handled by callstack unwind.
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
relookup after side effects (no side effects currently however)
resumee: [... initial_func undefined(= this) resume_value ]
must relookup act in case of side effects
fastint downgrade check for return values
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
pre-incremented, points to first jump slot
nop
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
In-place unary operation.
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
Thread may have changed, e.g. YIELD converted to THROW.
throw
unreferenced without assertions
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
[-0x80000000,0x7fffffff]
Catches both doubles and cases where only one argument is a fastint
x == -Infinity
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
heap pointer comparison suffices
E5 Section 9.3.1
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
truncate towards zero
func support for [[HasInstance]] checked in the beginning of the loop
prefix matches, lengths matter now
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
mimic semantics for strings
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
implementation specific
x == +Infinity
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
overflow, more than 32 bits -> not an array index
-> x in ]-2**32, 2**32[
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
exposed, used by e.g. duk_bi_date.c
Buffer/string -> compare contents.
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
Handle lightfuncs through object coercion for now.
comment: unused
label: code-design
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
Fast path for numbers (one of which may be a fastint)
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
number
radix
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: direct implementation
label: requirement
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
* ToInteger() (E5 Section 9.4)
invalidates tv
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
never here
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
y == +Infinity
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
comment: Note: reuse variables
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
equals and strict equals
non-strict equality for buffers compares contents
+(function(){}) -> NaN
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
Called by duk_hstring.h macros
non-strict equality from here on
+0.0
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
-> [ ... lval new_rval ]
Using classification has smaller footprint than direct comparison.
coerce lval with ToString()
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
* ToBoolean() (E5 Section 9.2)
follow prototype chain
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
combined algorithm matching E5 Sections 9.5 and 9.6
comment: XXX: this is possible without resorting to the value stack
label: code-design
Similar to String comparison.
Slow path
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
comment: 'tv' becomes invalid
label: code-design
y == -Infinity
buffer values are coerced first to string here
DUK_USE_FASTINT
-> x in [-2**31,2**31[
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
-> [ ... lval rval new_rval ]
* instanceof
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
[ ... lval rval ]
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
DUK_USE_PARANOID_MATH
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
-> x in [0, 2**32[
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
[0x00000000, 0xffffffff]
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
comment: Note: not a typo, "object" is returned for a null value
label: documentation
comment: XXX: fastint
label: code-design
should be a safe way to compute this
x in [2**31, 2**32[
Note: this must match ToObject() behavior
Coerce like boolean
e.g. "x" < "xx"
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
'lt is true'
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
SameValue
Nothing worked -> not equal.
-> [ ... lval rval ]
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
the next 'if' is guaranteed to match after swap
flags:nonstrict
[ ... lval rval(func) ]
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
Fast path for fastints
comment: return a specific NaN (although not strictly necessary)
label: code-design
whole, won't clip
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
* in
-> [ ... lval rval rval.prototype ]
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
apparently no hint?
-> [ ... closure template newobj closure ]
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
func is NULL for lightfuncs
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
formal arg limits
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
[ ... closure template ]
[ ... closure template env ]
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
[holder name val] -> [holder]
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
* Finish
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
lookup name from an open declarative record's registers
env and act may be NULL
[... env callee]
registers are mutable, non-deletable
side effects
-> [ ... closure template newobj ]
* Local result type for duk__get_identifier_reference() lookup.
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
[... env callee varmap key val]
-> [ ... closure template ]
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
must be found: was found earlier, and cannot be inherited
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
[ ... closure ]
[... env]
[this value] -> [value this]
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
non-standard
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
always for register bindings
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
can't get value, may be accessor
unsigned
writable but not deletable
may be NULL
assertions: env must be closed in the same thread as where it runs
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
1 -> needs a PUTVAR
just check 'env'
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
global object doesn't have array part
* Define new property
*
* Note: this may fail if the holder is not extensible.
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
lookup name from current activation record's functions' registers
already closed
-> [ ... closure template env ]
follow parent chain
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
required if NAMEBINDING set
[ ... closure template formals ]
env[funcname] = closure
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
regnum is sane
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
* Lookup variable and update in-place if found.
-> [ ... closure template env funcname ]
[ ... closure template val ]
comment: order: most frequent to least frequent
label: code-design
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
XXX: incref by count (here 2 times)
* Not found (in registers or record objects). Declare
* to current variable environment.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
implicit this value always undefined for
* declarative environment records.
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
* Not found (even in global object)
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
assume plain values
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
* Some assertions (E5 Section 13.2).
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
ref.value and ref.this_binding invalidated here
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment: XXX: use helper for size optimization
label: code-design
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
[ ... closure template undefined ]
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
ref.value, ref.this.binding invalidated here by getprop call
lookup results is ignored
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
[... env callee varmap]
env is closed, should be missing _Callee, _Thread, _Regbase
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
ref.holder is global object, holder is the object with the
* conflicting property.
* Get holder object
for object-bound identifiers
DUK_HOBJECT_FLAG_NEWENV: handled below
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
comment: unused
label: code-design
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
* Delayed env creation check
* Delayed initialization only occurs for 'NEWENV' functions.
no prototype, updated below
[ ... closure template len_value ]
[this value]
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
comment: XXX: slightly awkward
label: code-design
implicit this value always undefined for
* declarative environment records.
property attributes for identifier (relevant if value != NULL)
0 = no throw
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
compact the prototype
assume keys are compacted
* Try registers
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
for register-bound and declarative env identifiers
[ ... closure template name ]
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
bound functions are never in act 'func'
comment: XXX: copy flags using a mask
label: code-design
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
comment: XXX: more accurate?
label: code-design
irrelevant when out->value == NULL
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Note: not set in template (has no "prototype")
-> [ ... closure template env funcname closure ]
assume value is a number
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
if property already exists, overwrites silently
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
parent env is the prototype
open scope information, for compiled functions only
shared helper
explicit PropertyList
How large a loop detection stack to use
gap (if empty string, NULL)
* Defines for JSON, especially duk_bi_json.c.
How much stack to require on entry to object/array decode
indexed by recursion_depth
type bit mask: types which certainly produce 'undefined'
escape any non-ASCII characters
Encoding/decoding flags
extended types: compatible encoding
extended types: custom encoding
Encoding state. Heap object references are all borrowed.
valstack index of loop detection object
avoid key quotes when key is an ASCII Identifier
DUK_JSON_H_INCLUDED
replacer function
How much stack to require on entry to object/array encode
output bufwriter
'='
Store lexer position, restoring if quantifier is invalid.
* Set lexer input position and reinitialize lookup window.
')'
'-' verbatim
One digit octal escape, digit validated.
(
DUK_USE_REGEXP_SUPPORT
escaped NonEscapeCharacter
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mark range 'direct', bypass canonicalization (see Wiki)
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
"/=" and not in regexp mode
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'('
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
Fast path.
'/'
LF line terminator; CR LF and Unicode lineterms are handled in slow path
line tracking
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
val1 = count
'{'
0xxx xxxx -> fast path
radix
having this as a separate function provided a size benefit
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
second, parse flags
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
dash is already 0
* Various defines and file specific helper macros
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
'?'
re-lookup first char on first loop
'\''
state == 3
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
','
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
no point in supporting encodings of 5 or more bytes
line continuation
Use temporaries and update lex_ctx only when finished.
'|'
check that byte has the form 10xx xxxx
lookup for 0x000a above assumes shortest encoding now
unsigned
form: { DecimalDigits , }, val1 = min count
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
note: long live range
1110 xxxx 10xx xxxx 10xx xxxx
110x xxxx 10xx xxxx
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
re-lookup curr char on first round
NB: duk_lexer_getpoint() is a macro only
lexer character window helpers
eat closing quote
avoid multiply
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
got lineterm preceding non-whitespace, non-lineterm token
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
comment: XXX: shared parsing?
label: code-design
CR LF again a special case
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
Track number of escapes: necessary for proper keyword
* detection.
(?=
re-read to avoid spill / fetch
Note: decimal number may start with a period, but must be followed by a digit
(?:
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Three digit octal escape, digits validated.
validation performed by duk__hexval
validation of the regexp is caller's responsibility
character represents itself
'~'
'['
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
'%'
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
eat closing slash
not strictly necessary because of lookahead '}' above
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
'+'
default: char escape (two chars)
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
adv = 2 default OK
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
fill window
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
lookup should prevent this
'<'
10xx xxxx -> invalid
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
out_token->lineterm set by caller
(?!
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
E5 Section 15.10.2.11
Keep current size
0=base, 1=esc, 2=class, 3=class+esc
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
XXX: potential issue with signed pointers, p_end < p.
lookup shorthands (note: assume context variable is named 'lex_ctx')
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
numeric value of a hex digit (also covers octal and decimal digits)
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
';'
"/" and not in regexp mode
* Lexing helpers
EOF
whether to use macros or helper function depends on call count
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Production allows 'DecimalDigits', including leading zeroes
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
'*'
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
']'
comment: XXX: better coercion
label: code-design
'!'
check final character validity
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
* Init lexer context
Here 'x' is a Unicode codepoint
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
'>'
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
PatternCharacter, all excluded characters are matched by cases above
skip opening slash on first loop
Reuse buffer as is unless buffer has grown large.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
Note: duk_uint8_t type yields larger code
DUK_USE_LEXER_SLIDING_WINDOW
'-' as a range indicator
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
not LS/PS
'"'
Slow path.
No other escape beginning with a digit in strict mode
invalid codepoint encoding or codepoint
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
'&'
comment: packed advance/token number macro used by multiple functions
label: code-design
fast paths for space and tab
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
clipped codepoint
fall through to error
* Shared exit path
val2 = min count, val1 = max count
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
line terminator will be handled on next round
part of string
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
':'
'^'
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
eat backslash on entry
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
IdentityEscape
could also just pop?
'.'
adv = 2 - 1 default OK
eat '{' on entry
Zero 'count' is also allowed to make call sites easier.
Note: 'e' and 'E' are also accepted here.
Zero escape (also allowed in non-strict mode)
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: not necessary to init, disabled for faster parsing
label: code-design
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
unreachable
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
switch
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
free some memory
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
marker: copy t if not changed
eat opening quote on first loop
'-'
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
input offset tracking
Constants for duk_lexer_ctx.buf.
token type (with reserved word identification)
valstack slot for 2nd token value
Lexer context. Same context is used for Ecmascript and Regexp parsing.
identifier names (E5 Section 7.6)
token was preceded by a lineterm
token type (with reserved words as DUK_TOK_IDENTIFER)
number of tokens parsed
Regexp tokens
Sanity checks for string and token defines
A regexp token value.
number of escapes and line continuations (for directive prologue)
* Lexer defines.
Lexer codepoint with additional info like offset/line number
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
input linenumber at input_offset (not window[0]), init to 1
DUK_USE_REGEXP_SUPPORT
returned after EOF (infinite amount)
unicode code points, window[0] is always next, points to 'buffer'
bufwriter for temp accumulation
input offset for window leading edge (not window[0])
Convert heap string index to a token (reserved words)
token allows automatic semicolon insertion (eof or preceded by newline)
named "arithmetic" because result is signed
start byte offset of token in lexer input
A structure for 'snapshotting' a point for rewinding
temp accumulation buffer
* Prototypes
reserved words: additional future reserved words in strict mode
valstack slot for 1st token value
numeric value of token
exclusive
reserved words: keywords
string 1 of token (borrowed, stored to ctx->slot1_idx)
reserved words: future reserved words
input byte length
unicode code points, window[0] is always next
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
DUK_LEXER_H_INCLUDED
valstack slot for temp buffer
currently 6 characters of lookup are actually needed (duk_lexer.c)
token type
numeric value (character, count)
punctuators (unlike the spec, also includes "/" and "/=")
inclusive
maximum token count before error (sanity backstop)
start line of token (first char)
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
input string (may be a user pointer)
Sanity check
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
string 2 of token (borrowed, stored to ctx->slot2_idx)
thread; minimizes argument passing
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
need to normalize, may even cancel to 0
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
DUK_USE_64BIT_OPS
zero handled by caller
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
borrow literal Infinity from builtin string
d <- (quotient (* r B) s) (in range 0...B-1)
exponential notation forced
mp <- b^(e+1)
input radix
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
0 or -1
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
x <- y + z
exponent digit
comment: XXX: this could be optimized
label: code-design
* Convert and push final string.
mm <- b^e
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
s <- 2
(quotient-remainder (* r B) s) using a dummy subtraction loop
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
12 to 21
r <- (2 * f) * b^(e+1)
31 to 36
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: unused
label: code-design
x <- y * z
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
comment: m+ != m- (very rarely)
label: code-design
* Dragon4 slow path digit generation.
free-form
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
Maximum number of digits generated.
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
empty ("") is allowed in some formats (e.g. Number(''), as zero
r <- (remainder (* r B) s)
if 1, doing a fixed format output (not free format)
tc1 = true, tc2 = false
Leading zero.
m+ <- (* m+ B)
toString() conditions
Digit generation
significant from precision perspective
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
Most common cases first.
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
no net exponent
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
carry
add E
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Fast path the binary case
Infinity
low to high
x <- (1<<y)
absolute position for digit considered for rounding
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
tc1 = false, tc2 = false
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
+ 1 for rounding
t1 <- (* r B)
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
allow e.g. '0x0009' and '00077'
tc1 = false, tc2 = true
add AC*2^32
large context; around 2kB now
mp <- b^e
s <- b^(-e) * 2
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
x <- x + y, use t as temp
setup many variables in nc_ctx
add BC*2^16
Note: if 'x' is zero, x->n becomes 0 here
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
position of highest digit changed
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: No NUL term checks in this debug code.
label: code-design
triggers garbage digit check below
digit count
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
interpret e.g. '09' as '0', not NaN
toFixed()
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
r <- (2 * f) * b^e
-Infinity
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Start position (inclusive) and end position (exclusive)
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
denormal
max possible
fixed-format
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
IEEE exp without bias
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
low 32 bits is complete
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
generate mantissa with a single leading whole number digit
requested number of output digits; 0 = free-format
s <- 2 * b
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
Overestimate required size; debug code so not critical to be tight.
see algorithm
t1 <- (+ r m+)
denormal or zero
comment: no special formatting
label: code-design
Fast path check.
caller handles sign change
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
22 to 31
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
x <- x - y, use t as temp
Carry is detected based on wrapping which relies on exact 32-bit
* types.
current digit
fixed precision and zero padding would be required
t has high mantissa
max size: radix=2 + sign
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
"." is not accepted in any format
Maximum number of characters in formatted value.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
fixed-format termination conditions
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
exponent for 'f'
32-bit value
Buffer used for generated digits, values are in the range [0,B-1].
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
fall through and continue for-loop
* Create mantissa
0.000...
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
skip leading digit
count is already incremented, take into account
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
true, because v[1] has at least one bit set
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
s <- b^(1-e) * 2
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
is valid size
integer number in range
no need to normalize
Current size is about 152 bytes.
build result as: (r << 32) + s: start with (BD + E + F)
x <- b^y; use t1 and t2 as temps
k > 0 -> k was too low, and cannot be too high
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
x <- y - z, require x >= y => z >= 0, i.e. y >= z
m- <- (* m- B)
Exponent
x <- y
terminating conditions
t1 = (+ r m+)
if 1, doing a string-to-number; else doing a number-to-string
(e.g. k=3, digits=2 -> "12X")
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
whole or fraction digit
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
essentially tracks digit position of lowest 'f' digit
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
r <- 2 * f
lead zero + 'digits' fractions + 1 for rounding
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
"123.456"
for
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
distinct bignums, easy mistake to make
-> sets 'f' and 'e'
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
NB: use 's' as temp on purpose
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
Significand ('f') padding.
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
don't increase 'count'
this is the case for normalized numbers
arbitrary marker, outside valid exp range
comment: XXX: union would be more correct
label: code-design
NaN sign bit is platform specific with unpacked, un-normalized NaNs
* Conversion helpers
add AD*2^16
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
normal
use bigint area as a temp
"123"
is normalized
lowest mantissa for this exponent
mm <- mp
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
".123"
no negative sign for zero
(Number.MAX_VALUE).toString(2).length == 1024, + spare
normal: implicit leading 1-bit
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
r <- (2 * b) * f
digit position is absolute, not relative
x <- x * y, use t as temp
t1 <- t1 - s
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
(< (* r 2) s)
not minimum exponent
add F
output radix
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
biased exp == 0 -> denormal, exp -1022
37x32 = 1184 bits
comment: slow init, do only for slow path cases
label: code-design
"123." is allowed in some formats
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
tc1 = true, tc2 = true
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
2 to 11
x <- y - z
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
Force exponential format. Used for toExponential().
Allow naked fraction (e.g. ".123")
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
Allow leading zeroes (e.g. "0123" -> "123")
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
* String-to-number conversion
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
Allow trailing garbage (e.g. treat "123foo" as "123)
* Prototypes
Allow exponent
DUK_NUMCONV_H_INCLUDED
Allow empty string to be interpreted as 0
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
Allow 'Infinity'
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
Allow leading plus sign
Allow leading minus sign
Allow fraction part
Trim white space (= allow leading and trailing whitespace)
Allow empty fraction (e.g. "123.")
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
regexp opcodes
maximum bytecode copies for {n,m} quantifiers
* Regular expression structs, constants, and bytecode defines.
1e8
regexp execution limits
flags
DUK_REGEXP_H_INCLUDED
internal temporary value, used for char classes
1e9
* Prototypes
regexp compilation limits
comment: hacky helper for String.prototype.split()
label: code-design
allocated from valstack (fixed buffer)
highest capture number emitted so far (used as: ++captures)
insert code for matching the remainder - infinite or finite
expensive init, just want to fill window
[ ... regexp_object escaped_source ]
record previous atom info in case next token is a quantifier
DUK_USE_REGEXP_SUPPORT
retval (sub-atom char length) unused, tainted as complex above
return '(?:)'
two encoding attempts suffices
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
-> [ ... escaped_source bytecode ]
prefer direct execution
flags always encodes to 1 byte
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
mark as complex
comment: unused
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
reuse last emitted atom for remaining 'infinite' quantifier
[ ... pattern flags escaped_source ]
[ ... pattern flags escaped_source bytecode ]
qmin and qmax will be 0 or 1
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
[ ... regexp_object escaped_source bytecode ]
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
insert range count
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
prefer direct
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
* Init compilation context
[ ... escaped_source bytecode ]
-1 if disjunction is complex, char length if simple
insert ranges instruction, range count patched in later
add a new pending split to the beginning of the entire disjunction
never here
wipe the capture range made by the atom (if any)
negative -> complex atom
-1 for opcode
no change
'taint' result as complex
* Helper macros
* Disjunction struct: result of parsing a disjunction
[ ... escape_source bytecode ]
[ ... pattern flags ]
-> [ ... flags escaped_source bytecode ]
comment: note: ctx-wide temporary
label: code-design
* Create normalized 'source' property (E5 Section 15.10.3).
* Compilation
set by atom case clauses
value of re_ctx->captures at start of atom
remove the original 'template' atom
* Flags parsing (see E5 Section 15.10.4.1).
* Init lexer
-> [ ... escaped_source ]
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
insert the required matches (qmin) by copying the atom
expect_eof
coerce to string
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
+1 for opcode
* Finalize stack
always at least the header
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
complete 'sub atom'
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
char length of the atom parsed in this loop
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
silence scan-build warning
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
only advance if not tainted
comment: XXX: solve into closed form (smaller code)
label: code-design
re_ctx->captures at the start of the atom parsed in this loop
special helper for emitting u16 lists (used for character ranges for built-in char classes)
mark as complex (capture handling)
[ ... regexp_object ]
negative -> no atom matched on previous round
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
TypeError if fails
a complex (new) atom taints the result
finish up pending jump and split for last alternative
duplicate zeroing, expect for (possible) NULL inits
patch in range count later
patch pending jump and split
* Args validation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
regexp support disabled
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
offset is now target of the pending split (right after jump)
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
add a new pending match jump for latest finished alternative
[ ... pattern flags escaped_source buffer ]
parse ranges until character class ends
Call sites don't need the result length so it's not accumulated.
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
prefer jump
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Note: can be safely scanned as bytes (undecoded)
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
match fail
* Helpers for dealing with the input string
split2: prefer jump execution (not direct)
DUK_USE_REGEXP_SUPPORT
non-global regexp: lastIndex never updated on match
split1: prefer direct execution (no jump)
[ ... re_obj input bc ]
must fit into duk_small_int_t
note: caller 'sp' is intentionally not updated here
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
must have start and end
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: not really necessary
label: code-design
E5 Sections 15.10.2.8, 7.3
match: keep wiped/resaved values
no regexp instance should exist without a non-configurable bytecode property
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
advance by one character (code point) and one char_offset
TypeError if wrong; class check, see E5 Section 15.10.6
fall through
Note: allow backtracking from p == ptr_end
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
never here
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
backref n -> saved indices [n*2, n*2+1]
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
buffer is automatically zeroed
[ ... res_obj re_obj input bc saved_buf ]
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
NB: 'length' property is automatically updated by the array setup loop
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
[ ... re_obj input ] -> [ ... re_obj input bc ]
idx is unsigned, < 0 check is not necessary
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
[ ... res_obj ]
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
canonicalized by compiler
not a wordchar
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
-> [ ... re_obj input bc saved_buf lastIndex ]
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
fail: restore saves
[ ... re_obj input bc saved_buf ]
ToInteger(lastIndex)
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
capture is 'undefined', always matches!
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
signed integer encoding needed to work with UTF-8
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
force_global
match: keep saves
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
regexp support disabled
Backtrack utf-8 input and return a (possibly canonicalized) input character.
[ ... re_obj input bc saved_buf res_obj val ]
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
and even number
read header
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
[ ... re_obj input bc saved_buf res_obj ]
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
dummy so sp won't get updated
utf-8 continuation bytes have the form 10xx xxxx
regexp compiler should catch these
global regexp: lastIndex updated on match
expt 0xfff is infinite/nan
expt 0x000 is zero/subnormal
expt values [0x001,0x7fe] = normal
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
!DUK_SINGLE_FILE
DUK_REPLACEMENTS_H_INCLUDED
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Test without volatiles
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
* Zero sign, see misc/tcc_zerosign2.c.
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
* Union aliasing, see misc/clang_aliasing.c.
little endian
Test signaling NaN and alias assignment in all endianness combinations.
Catch a double-to-int64 cast issue encountered in practice.
* Casting
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
* Unions and structs for self tests
big endian
nop
* Packed tval sanity
DUK_USE_SELF_TESTS
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
comment: Same test with volatiles
label: test
* Self test main
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
* Basic double / byte union memory layout.
mixed endian
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
0xdeadbeef in decimal
* Two's complement arithmetic.
* DUK_BSWAP macros
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
no check
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment:
* Various sanity checks for typing
label: code-design
* Selftest code
DUK_SELFTEST_H_INCLUDED
Object property access
Compiler
Misc
Limits
Mostly API and built-in method related
comment: still in use with verbose messages
label: code-design
Regexp
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
JSON
DUK_ERRMSG_H_INCLUDED
comment: still in use with verbose messages
label: code-design
!DUK_SINGLE_FILE
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
DUK_USE_FASTINT
zero
exponent 1070
comment: unused
label: code-design
exponent 0
positive
* Manually optimized number-to-double conversion
0
negative
exponents 1023 to 1069
Note: reject negative zero.
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
comment: XXX: optimize for packed duk_tval directly?
label: code-design
implicit leading one
avoid unary minus on unsigned
1 << 52
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Portable 12-byte representation
XXX: clumsy sign extend and masking of 16 topmost bits
marker; not actual tagged type
marker; not actual tagged value
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
DUK_USE_64BIT_OPS
Assumes that caller has normalized NaNs, otherwise trouble ahead.
use duk_double_union as duk_tval directly
This seems reasonable overall.
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
for convenience
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
embed: integer value
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
comment: XXX: fast int-to-double
label: code-design
max, excl. varargs marker
DUK_USE_PACKED_TVAL
if present, forces 16-byte duk_tval
varargs marker
Note: masking is done for 'i' to deal with negative numbers correctly
* Packed 8-byte representation
in non-packed representation we don't care about which NaN is used
embed: void ptr
decoding
0xfff0 is -Infinity
embed: duk_hobject ptr
DUK_USE_FASTINT
getters
comment: This is performance critical because it appears in every DECREF.
label: code-design
comment: the NaN variant we use
label: code-design
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
DUK_TVAL_H_INCLUDED
embed: func ptr
sanity
fastint constants etc
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
embed: duk_hstring ptr
Lightfunc flags packing and unpacking.
first heap allocated, match bit boundary
embed: 0 or 1 (false or true)
setters
not exposed
embed: duk_hbuffer ptr
tags
embed: nothing
* Convenience (independent of representation)
========================================================================
* Unicode helpers
zero-width joiner
* Automatically generated by extract_chars.py, do not edit!
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
up to 36 bit codepoints
* Unicode tables
duk_unicode_support.c
!DUK_SINGLE_FILE
all codepoints up to U+10FFFF
DUK_UNICODE_H_INCLUDED
* Automatically generated by extract_caseconv.py, do not edit!
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
* Prototypes
all codepoints up to U+FFFF
* Extern
zero-width non-joiner
* UTF-8 / XUTF-8 / CESU-8 constants
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
does not fit into an uchar
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
DUK_USE_REGEXP_SUPPORT
curr char
0x20...0x2f
* Unicode letter check.
* Replace valstack top with case converted version.
0x60...0x6f
0xxx xxxx [7 bits]
0x40...0x4f
exposed because lexer needs these too
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
110x xxxx 10xx xxxx [11 bits]
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
XXX: add 'language' argument when locale/language sensitive rule
* support added.
next does not exist or next is not a letter
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
11 bits
0x50...0x5f
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_USE_PREFER_SIZE
fall through
* "IdentifierPart" production check.
fast path for ASCII
prev exists and is not a letter
36 bits
verified at beginning
complex, multicharacter conversion
DUK_USE_ASSERTIONS
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Fall through to handle the rest.
check pointer at end
Full, aligned 4-byte reads.
* "IdentifierStart" production check.
comment: XXX: turkish / azeri, lowercase rules
label: code-design
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
0x00...0x0f
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
NULL is allowed, no output
invalidates h_buf pointer
Decode helper. Return zero on error.
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
31 bits
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
* Fast path tables
* Regexp range tables
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
Small variant; roughly 150 bytes smaller than the fast variant.
cp == -1 (EOF) never matches and causes return value 0
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
default: no change
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
Must match src/extract_chars.py, generate_match_table3().
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
1:1 or special conversions, but not locale/context specific: script generated rules
10xx xxxx -> invalid
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
0x10...0x1f
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
on first round, skip
surrogate pairs get encoded here
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
end marker
used by e.g. duk_regexp_executor.c, string built-ins
prev char
ASCII fast path
0x70...0x7f
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
comment: XXX: lithuanian, explicit dot rules
label: code-design
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
0x30...0x3f
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
26 bits
64-bit OK because always >= 0
comment: XXX: lithuanian not implemented
label: requirement
[r1,r2] is the range
ASCII (and EOF) fast path -- quick accept and reject
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
always >= 0
number of continuation (non-initial) bytes in [0x80,0xbf]
1:1 conversion
* "LineTerminator" production check.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
end of input and last char has been processed
16 bits
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: turkish / azeri
label: code-design
U+03A3 = GREEK CAPITAL LETTER SIGMA
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
Ensure space for maximum multi-character result; estimate is overkill.
[ ... input buffer ]
uppercase
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
range conversion with a "skip"
next char
7 bits
* "WhiteSpace" production check.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
21 bits
comment: unused now, not needed until Turkish/Azeri
label: requirement
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
* Automatically generated by extract_chars.py, do not edit!
* Unicode support tables automatically generated during build.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
duk_unicode_ids_m_let_noabmp[]
duk_unicode_ids_m_let_noa[]
duk_unicode_ids_noabmp[]
IdentifierStart production with ASCII excluded
duk_unicode_caseconv_lc[]
IdentifierPart production with IdentifierStart and ASCII excluded
duk_unicode_ids_noa[]
IdentifierStart production with ASCII and non-BMP excluded
IdentifierStart production with Letter and ASCII excluded
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
duk_unicode_idp_m_ids_noa[]
* Case conversion tables generated using src/extract_caseconv.py.
duk_unicode_idp_m_ids_noabmp[]
* Automatically generated by extract_caseconv.py, do not edit!
duk_unicode_caseconv_uc[]
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
!DUK_SINGLE_FILE
Insert bytes in the middle of the buffer from an external buffer.
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
* Utilities
* Endian conversion
Ensuring (reserving) space.
Evaluates to (duk_uint8_t *) pointing to start of area.
* Externs and prototypes
NOTE: Multiple evaluation of 'ptr' in this macro.
For now only needed by the debugger.
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
2^4 -> 1/16 = 6.25% spare
Working with the pointer and current size.
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
DUK_UTIL_H_INCLUDED
comment: XXX: Rework to use an always-inline function?
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
No difference between raw/ensure because the buffer shrinks.
Initialization and finalization (compaction), converting to other types.
Miscellaneous.
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
'ptr' is evaluated both as LHS and RHS.
Safe write calls which will ensure space first.
must match genhashsizes.py
* Bitstream decoder
Append bytes from a slice already in the buffer.
Note: assumes that duk_util_probe_steps size is 32
* Bitstream encoder
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
Make underlying buffer compact to match DUK_BW_GET_SIZE().
No duk_bw_remove_ensure_slice(), functionality would be identical.
Reset to zero size, keep current limit.
Remove a slice from inside buffer.
remaining
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
* Bitstream decoder.
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
If buffer has been exhausted, truncate bitstream
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
* Bitstream encoder.
buffer size is >= 1
* Fast buffer writer with spare management.
overflow
for manual torture testing: tight allocation, useful with valgrind
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
point to start of 'reserved area'
not reachable
Don't support "straddled" source now.
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
Make buffer compact, matching current written size.
comment:
* Macro support functions (use only macros in calling code)
label: code-design
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
DUK_USE_STRHASH_DENSE
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
'magic' constants for Murmurhash2
prediction corrections for prime list (see genhashsizes.py)
hash size ratio goal, must match genhashsizes.py
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
prediction: portable variant using doubles if 64-bit values not available
minimum prime
correction
floor(1.15 * (1 << 10))
32-bit x 11-bit = 43-bit, fits accurately into a double
may happen if size is very close to 2^32-1
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
0x10-0x1f
0xf0-0xff
0xb0-0xbf
0xc0-0xcf
0x90...0x9f
0x90-0x9f
0x10...0x1f
0xd0...0xdf
0x20-0x2f
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
* Misc util stuff
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
For now only needed by the debugger.
0x60-0x6f
0x20...0x2f
0xa0-0xaf
0x60...0x6f
0x40...0x4f
0xe0-0xef
* Table for base-64 decoding
DUK_USE_HEX_FASTPATH
A...P
-1 if invalid
* Table for hex decoding ASCII hex digits
0x30-0x3f
0xc0...0xcf
0x00...0x0f
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
0x80-0x8f
0xb0...0xbf
Q...f
0xa0...0xaf
0x70...0x7f
* Table for hex encoding bytes
0x40-0x4f
* Table for base-64 encoding
0x30...0x3f
0x00-0x0f
0x80...0x8f
DUK_USE_INTEGER_BE
g...v
0xf0...0xff
0x70-0x7f
0xd0-0xdf
0x50-0x5f
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
DUK_USE_BASE64_FASTPATH
0x50...0x5f
0xe0...0xef
w.../
enough to cover the whole mantissa
if duk_uint32_t is exactly 32 bits, this is a NOP
only use the highest bit
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
* Duktape public API for Duktape 1.5.2.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
* Git branch HEAD.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
internal flag value: throw if mask doesn't match
set getter (given on value stack)
no error if file does not exist
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
* Git describe: v1.5.2
* Git branch: HEAD
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
alloc external with size zero
'i' is the first entry we'll keep
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
resend state next time executor is about to run
comment: XXX: avoid this check somehow
label: code-design
Should match Function.prototype.toString()
* Main struct
'/'
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Duktape.modLoaded[] module cache
[ obj handler trap ]
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
comment: size for formatting buffers
label: code-design
default case exists: go there if no case matches
registers are mutable, non-deletable
'{'
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
get or set a range of flags; m=first bit number, n=number of bits
[ level obj func pc line ]
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
[ arg1 ... argN this ]
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
Allocator functions.
next does not exist or next is not a letter
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
'enum'
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
just making sure
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
comment: XXX: string not shared because it is conditional
label: code-design
carry
Initial bytes for markers.
queue back to heap_allocated
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
print provider
form: { DecimalDigits , }, val1 = min count
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
DUK_TOK_LPAREN
caller ensures; rom objects are never bufferobjects now
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
1 -> needs a PUTVAR
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
leave out trailing 'unused' elements
comment: TODO: implement Proxy object support here
label: requirement
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
args start at index 2
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
eat colon
always set; points to a reserved valstack slot
Track number of escapes: necessary for proper keyword
* detection.
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
should never happen but default here
'env'
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
-> [val]
emitted
resume delete to target
-> [... obj]
success
+0.0
replacer is a mutation risk
parse key and value
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
No duk_bw_remove_ensure_slice(), functionality would be identical.
if boolean matches A, skip next inst
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
[ ... val ]
'true'
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
For now shared handler is fine.
may be less, since DELETED entries are NULLed by rehash
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
OK
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
maximum loopcount for peephole optimization
cleared before entering finally
flags for duk_hobject_get_own_propdesc() and variants
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
useful for patching jumps later
avoid attempts to add/remove object keys
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Local defines
comment: XXX: compression
label: code-design
already NULLed (by unwind)
Don't allow actual chars after equal sign.
-> [ Object defineProperty undefined obj key desc ]
whether to use macros or helper function depends on call count
DUK_USE_FASTINT
7: toISOString
comment: XXX: "read only object"?
label: code-design
no action
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
must hold DUK_VARARGS
capture is 'undefined', always matches!
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
'raw'
DUK_TOK_RPAREN
request to create catch binding
for object-bound identifiers
comment: XXX: compression (as an option)
label: code-design
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
first coerce to a plain value
-> [ ... func varmap enum ]
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
force_global
NB: use 's' as temp on purpose
Not odd, or y == -Infinity
* Global object built-ins
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
[ body formals ], formals is comma separated list that needs to be parsed
bytecode execution
thisArg
* Not found
XXX: duk_uarridx_t?
E5 Section 9.4, ToInteger()
force_new
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
avoid dereference after potential callstack realloc
* Pass 2
compensate for eval() call
set values into ret array
* Pick an object from the head (don't remove yet).
fast path
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
[ ... this tracedata sep this ]
* After arguments, allocate special registers (like shuffling temps)
[ ToObject(this) item1 ... itemN arr item(i) ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
This behavior mostly mimics Node.js now.
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
Encode a fastint from duk_tval ptr, no value stack effects.
'has'
DUK_TOK_COMMA
'void'
bufwriter for code
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
* UTF-8 / XUTF-8 / CESU-8 constants
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
DUK_TOK_IDENTIFIER
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
[ ... func varmap enum key value this ]
1: toDateString
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
Positive if local time ahead of UTC.
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
save stack top
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
Treat like a debugger statement: ignore when not attached.
'import'
Duktape/C API guaranteed entries (on top of args)
avoid warning (unsigned)
Helper which can be called both directly and with duk_safe_call().
[ ... template ]
-> [ buffer ]
comment: XXX: Here a "slice copy" would be useful.
label: code-design
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
duk_unicode_ids_m_let_noa[]
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
indirect allocs
Lightfuncs are always considered strict.
implies DUK_HOBJECT_IS_BUFFEROBJECT
safe, because matched (NUL causes a break)
* Packed tval sanity
longjmp type
should be first on 64-bit platforms
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[ ... | (crud) errobj ]
expensive flag
validation performed by duk__hexval
non-strict equality from here on
allocate catcher and populate it (should be atomic)
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
if 0, 'str16' used, if > 0, 'strlist16' used
probe sequence (open addressing)
token was preceded by a lineterm
-> [ ... ]
* Store entry state.
Perform an intermediate join when this many elements have been pushed
* on the value stack.
duk_unicode_ids_m_let_noabmp[]
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
'return'
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
comment: log level could be popped but that's not necessary
label: code-design
thread currently running (only one at a time)
numargs
already defined, good
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
Copy term name until end or '/'.
-> [ ... trap handler ]
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
DUK_TOK_DEBUGGER
Init newly allocated slots (only).
a complex (new) atom taints the result
[this value]
See: test-bug-tailcall-preventyield-assert.c.
check_object_coercible
comment: XXX: source code property
label: code-design
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
comment: XXX: unnecessary, handle in adjust
label: code-design
[ ... key trap handler ]
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
const
even for zero-length string
eat 'if'
14: getDay
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
function: create an arguments object on function call
-> [... target]
* Nice debug log.
comment: XXX: copy flags using a mask
label: code-design
[ ... func/retval ] -> [ ... ]
comment: XXX: optimize loops
label: code-design
up to 36 bit codepoints
no fractions in internal time
ditto
[key] -> []
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
[ buf? res ]
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
undefined -> skip (replaced with empty)
eat opening quote on first loop
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
no need to decref
18: getMinutes
'exports'
* Unicode letter check.
DUK_USE_MATH_BUILTIN
No field needed when strings are in ROM.
value was undefined/unsupported
eat 'function'
keep in valstack
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
step 11
IdentifierPart production with IdentifierStart and ASCII excluded
Internal timevalue is already NaN, so don't touch it.
flag for later write
GH-303
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
DUK_TOK_SEMICOLON
return value from Duktape.Thread.yield()
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Parts are in local time, convert when setting.
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
Backup 'caller' property and update its value.
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
Add function object.
finalization
[ ToObject(this) item1 ... itemN arr ]
0x50...0x5f
Rule table: first matching rule is used to determine what to do next.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* Init the heap object
Inherit from ROM-based global object: less RAM usage, less transparent.
Note: 0xff != DUK_BC_C_MAX
COMMA
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
comment: function must not be tail called
label: code-design
stage 3: update length (done by caller), decide return code
idx_space
statement does not terminate directive prologue
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
* Table for hex decoding ASCII hex digits
function: create new environment when called (see duk_hcompiledfunction)
pop regexp res_obj or match string
P
required if NAMEBINDING set
slow path decode
don't care value, year is mandatory
really 'not applicable' anymore, should not be referenced after this
skip jump conditionally
* Flags parsing (see E5 Section 15.10.4.1).
for updating (all are set to < 0 for virtual properties)
* Run (object) finalizers in the "to be finalized" work list.
'warn'
DUK_USE_FILE_IO
[... constructor arg1 ... argN final_cons fallback]
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
'Array' object, array length and index exotic behavior
a statement following a label cannot be a source element
* (a function declaration).
24: setMilliseconds
'\xffVarenv'
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
DUK_TOK_BREAK
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
DUK_TOK_MOD_EQ
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
Note: DST adjustment is determined using UTC time.
caller must check
2
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
log this with a normal debug level because this should be relatively rare
* Ecmascript execution, support primitives.
* replace()
out_clamped=NULL, RangeError if outside range
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
idx_args = idx_func + 2
handle comma and closing bracket
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
Note: this allows creation of internal strings.
DUK__FLD_DOUBLE
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
caller and arguments must use the same thrower, [[ThrowTypeError]]
bound function 'length' property is interesting
DUK_REPLACEMENTS_H_INCLUDED
[ ... error func ]
expt 0x000 is zero/subnormal
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
restore PC
allow negative PCs, behave as a no-op
'\xffValue'
* Activation defines
Step 15: insert itemCount elements into the hole made above
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
XXX: ARRAY_PART for Array prototype?
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
string is a valid array index
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
'Number'
buffer is behind a pointer, dynamic or external
* in
allow caller to give a const number with the DUK__CONST_MARKER
DUK_USE_JSON_DECNUMBER_FASTPATH
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
XXX: use DUK_HSTRING_FLAG_INTERNAL?
func support for [[HasInstance]] checked in the beginning of the loop
%p
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
pop key
implementation specific
* Log level check
comment: XXX: unify handling with native call.
label: code-design
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
39: setYear
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
E5.1 Section 15.9.1.6
DUK_USE_JSON_QUOTESTRING_FASTPATH
always in executor
because of valstack init policy
embed: func ptr
local
Sanity check
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
* Manipulate callstack for the call.
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
'typeof'
Execute bytecode until returned or longjmp().
overflow not possible, buffer limits
'interface'
zero everything unless requested not to do so
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
* Node.js Buffer.isBuffer()
DUK_TOK_COLON
B -> target register for next key
* C -> enum register
-> [ ... flags escaped_source bytecode ]
backref n -> saved indices [n*2, n*2+1]
value1 -> error object
remove key
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
comment: For short strings, use a fixed temp buffer.
label: code-design
label limits
marker values for hash part
DUK_TOK_GE
-> [ ... closure ]
NULL pointer is required to encode to zero, so memset is enough.
else an array initializer element
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
35: setUTCMonth
[ ... retval ]
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
'new' MemberExpression Arguments
assume plain values
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
[ ... val obj ]
-> [ ... re_obj input bc saved_buf lastIndex ]
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Duktape/C (nativefunction) object, exotic 'length'
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
'this' binding
[ ... val key ] -> [ ... key val ]
isAccessor
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
skip opening slash on first loop
transfer flags
DUK_TOK_INTERFACE
may be undefined
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
iteration statements allow continue
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
'while'
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
object is constructable
regexp support disabled
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
assume keys are compacted
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
advance, whatever the current token is; parse next token in regexp context
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
regs to allocate
preallocated temporaries (2) for variants 3 and 4
[ regexp input ]
function: function object is strict
DUK_TOK_ALSHIFT
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
call is a direct eval call
varname is still reachable
Leave 'setter' on stack
seconds
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
DUK_USE_VARIADIC_MACROS
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
key is now reachable in the valstack
MakeDate
Request callback should push values for reply to client onto valstack
inserted jump
[enum_target res]
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
Then reuse the unwound activation; callstack was not shrunk so there is always space
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
for storing/restoring the varmap binding for catch variable
r <- (2 * f) * b^(e+1)
'[...]'
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
function is strict
must work for nargs <= 0
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
don't run finalizers; leave finalizable objects in finalize_list for next round
[this value] -> [value this]
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
2: toTimeString
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
* Initialize function state for a zero-argument function
Guaranteed by recursion_limit setup so we don't have to
* check twice.
line continuation
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
'-Infinity'
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
type tag (public)
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
don't re-enter e.g. during Eval
mp <- b^e
special handling of fmt==NULL
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
parse value
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
function may call direct eval
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
[ array totalLength ]
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
-> [ ... key val val' ]
[ ... re_obj input ] -> [ ... re_obj input bc ]
valstack slot for 1st token value
side effects, possibly errors
NOTE: Multiple evaluation of 'ptr' in this macro.
Overflow of the execution counter is fine and doesn't break
* anything here.
mark-and-sweep: finalized (on previous pass)
curr is accessor, desc is data
[ func thisArg arg1 ... argN ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
this function
comment: 'tv' becomes invalid
label: code-design
is an actual function (not global/eval code)
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
'callee'
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
'byteOffset'
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
no operators
Strict: never allow function declarations outside top level.
[ ... arg1 ... argN envobj ]
* Field access
0x30...0x3f
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
true
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
only use the highest bit
Function values are handled completely above (including
* coercion results):
distinct bignums, easy mistake to make
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
DUK_TOK_INSTANCEOF
time
update entry, allocating if necessary
A structure for 'snapshotting' a point for rewinding
* Ecmascript call
cannot be arguments exotic
comment: this is not strictly necessary, but helps debugging
label: code-design
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
push initial function call to new thread stack; this is
* picked up by resume().
31: setUTCHours
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
format plus something to avoid just missing
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
if property already exists, overwrites silently
comment: 'val' is never NaN, so no need to normalize
label: code-design
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
may be reg or const
decl name
rnd_state for duk_util_tinyrandom.c
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
jump is inserted here
misc
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
only flag now
[... func this arg1 ... argN]
record previous atom info in case next token is a quantifier
-""-
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
not enumerable
%f and %lf both consume a 'long'
* Catcher defines
never executed
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
'('
important to do this *after* pushing, to make the thread reachable for gc
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
Should not happen.
init pointer fields to null
* toString(), valueOf()
success, fixup pointers
comment: XXX: several pointer comparison issues here
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
Check that value is a duk_hbufferobject and return a pointer to it.
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
Note: assumes that duk_util_probe_steps size is 32
guaranteed when building arguments
updates thread state, minimizes its allocations
'{"_inf":true}'
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
comment: TimeClip() should never be necessary
label: code-design
0x10-0x1f
E5.1 Section B.2.2, step 7.
Parser part masks.
end switch (tok)
negative -> complex atom
-> [ ... val root "" ]
result array
XXX: fast path for arrays?
-> [ ... ToObject(this) ToUint32(length) ]
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
0x00...0x0f
coercion order matters
'jc'
1 if property found, 0 otherwise
fixed-format
not strictly necessary because of lookahead '}' above
comment: XXX: must be able to represent -len
label: code-design
DUK_USE_DPRINT_COLORS
expect_eof
borrowed reference to catch variable name (or NULL if none)
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
lookup should prevent this
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
result index for filter()
either nonzero value is ok
bc
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
can't resize below 'top'
round up roughly to next 'grow step'
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
last array index explicitly initialized, +1
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
need side effects, not value
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
Note: for srclen=0, src may be NULL
never an empty match, so step 13.c.iii can't be triggered
Outer executor with setjmp/longjmp handling.
if B/C is >= this value, refers to a const
if debugging disabled
if true, the stack already contains the final result
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
when nothing is running, API calls are in non-strict mode
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
see duk_js_executor.c
Convert heap string index to a token (reserved words)
comment: XXX: refactor and share with other code
label: code-design
order must match constants in genbuiltins.py
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Ecmascript compliant [[Delete]](P, Throw).
-> [ ... str ]
args go here in parens
0xb0...0xbf
Write in big endian
only need to guarantee 1 more slot, but allocation growth is in chunks
comment: alloc function typedefs in duktape.h
label: code-design
i >= 0 would always be true
comment: XXX: inline into a prototype walking loop?
label: code-design
Lightfunc handling by ToObject() coercion.
DUK_BUFOBJ_UINT16ARRAY
'else'
'String' object, array index exotic behavior
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
Write unsigned 32-bit integer.
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
[ body formals source template closure ]
no refcount changes
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
First evaluate LHS fully to ensure all side effects are out.
properties object
Call handling and success path. Success path exit cleans
* up almost all state.
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
object is extensible
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
lookup name from an open declarative record's registers
relookup (side effects)
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
x <- y * z
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Catches >0x100000000 and negative values.
* Entry points
* Error built-ins
Packed or unpacked tval
* PC-to-line constants
top-down expression parser
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
fall through
x
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
fast path for ASCII
num_stack_res
%lx
* Not found as concrete or virtual
'Buffer'
[ ... env target target ]
DUK_TOK_LOR
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
triggers garbage digit check below
relevant array index is non-configurable, blocks write
comment: the NaN variant we use
label: code-design
* Compact the function template.
PRIMARY EXPRESSIONS
* indexOf(), lastIndexOf()
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
Automatic error throwing, retval check.
Fast path for the case where the register
* is a number (e.g. loop counter).
always push some string
spare
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
* Heap flags
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
get_value
clear array part flag only after switching
'!'
tv1 points to value storage
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
ascii fast path: avoid decoding utf-8
just in case
entry_top + 4
m- <- (* m- B)
UTC
no valstack space check
End of input (NUL) goes through slow path and causes SyntaxError.
[ ... enum_target res trap_result val ]
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
ptr_curr_pc != NULL only when bytecode executor is active.
Restore entry thread executor curr_pc stack frame pointer.
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
duk_hobject_set_length_zero(thr, func->h_funcs);
fall thru
see above
* Struct defines
[ ... name reg/null ] -> [ ... ]
mandatory if du.d is a NaN
duk_tval ptr for 'func' on stack (borrowed reference)
For tv1 == tv2, this is a no-op (no explicit check needed).
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
local copy to avoid relookups
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
* Hobject Ecmascript [[Class]].
Handle one slow path unit (or finish if we're done).
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
enough to cover the whole mantissa
DUK_TOK_BXOR_EQ
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
repl string scan
[key result] -> [result]
'\xffTracedata'
... and its 'message' from an instance property
AUTHORS.rst
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
prefer jump
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
automatic length update
args
'String'
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
not a vararg function
Shouldn't happen but check anyway.
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
No strs[] pointer.
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
e.g. DUK_OP_PREINCR
eat 'while'
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
input radix
char: use int cast
result
exponent digit
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
defprop_flags
s <- 2
spaces (nargs - 1) + newline
* Parse inner function
if accessor without getter, return value is undefined
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
who resumed us (if any)
out_clamped==NULL -> RangeError if outside range
relookup after possible realloc
[ ... regexp_object escaped_source bytecode ]
m+ <- (* m+ B)
bytecode opcode (or extraop) for binary ops
forget temp
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
absolute position for digit considered for rounding
-> [ ... this timeval_new ]
TypeError if wrong; class check, see E5 Section 15.10.6
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
same thread
'Boolean'
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
* Init the heap thread
XXX: need a duk_require_func_or_lfunc_coerce()
avoid referencing, invalidated
Don't support "straddled" source now.
* Object compaction.
*
* Compaction is assumed to never throw an error.
[ arg1 ... argN this loggerLevel loggerName ]
duk_tval intentionally skipped
* Since built-ins are not often extended, compact them.
* Compilation
Push a new ArrayBuffer (becomes view .buffer)
idx_start
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
may be NULL if no constants or inner funcs
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
empty expressions can be detected conveniently with nud/led counts
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
[ ... val callback thisArg val i obj ]
[ ... this tracedata sep this str1 ... strN ]
important chosen base types
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
must also check refzero_list
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
[ ... func ]
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Trigger at zero or below
Custom coercion for API
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
source ends before dest starts
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
64-bit OK because always >= 0
reg/const for switch value
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
no prototype, updated below
unwind to 'resume' caller
0xf0-0xff
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
1st related value (type specific)
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
Shared object part
always throw ReferenceError for unresolvable
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Shift to sign extend.
'^'
required_desc_flags
comment: Stack indices for better readability
label: code-design
* Try registers
no prototype or class yet
shadowed; update value
E5 Section 8.6.2 + custom classes
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
RELATIONAL EXPRESSION
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
Zero escape (also allowed in non-strict mode)
roughly 64 bytes
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
this is a bit approximate (errors out before max is reached); this is OK
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Convert buffer to result string.
default prototype (Note: 'thr' must be reachable)
we know these because enum objects are internally created
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
1 = num actual 'return values'
should never happen
'-' verbatim
Regexp tokens
avoid attempt to compact the current object
DUK_TOK_TRUE
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
min(incl)
may be equal
traceback depth ensures fits into 16 bits
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
DUK_TOK_GET
* Various
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
trailer
* Check whether we need to abandon an array part (if it exists)
[... env callee]
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
an Ecmascript function
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
end of bytecode
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
must be found: was found earlier, and cannot be inherited
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
shift in zeroes
free object and all auxiliary (non-heap) allocs
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
bytes in dest
stack[0] = regexp
* stack[1] = string
flags
Check for maximum buffer length.
'Thread'
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
Output #2: last component name
tc1 = false, tc2 = false
0
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
0x90-0x9f
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Write to entry part
To use the shared helper need the virtual index.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
LAYOUT 1
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
* Node.js Buffer.isEncoding()
array entries are all plain values
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
XXX: assert 'c' is an enumerator
two special escapes: '\' and '"', other printables as is
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
DUK_USE_AUGMENT_ERROR_THROW
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
comment: Most practical strings will go here.
label: code-design
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-> [ ... lval new_rval ]
sep (even before first one)
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
0x7F is special
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
Signed integers always map to 4 bytes now.
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
estimate is valid
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
always true, arg is unsigned
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
DUK_TOK_DO
* Slow path: potentially requires function calls for coercion
'ArrayBuffer'
Initialize index so that we skip internal control keys.
flags have been already cleared
* ArrayBuffer, DataView, and TypedArray constructors
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
-> [ ... this timeval_new timeval_new ]
DUK_TOK_CONST
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Slot C
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
At least: ... [err]
wrapped
whole or fraction digit
* Constructor calls
only 'length'
DUK_USE_DEBUGGER_DUMPHEAP
'toISOString'
'res' contains expression value
No other escape beginning with a digit in strict mode
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
[key setter this val key] -> [key retval]
point to start of 'reserved area'
Shared helper for match() steps 3-4, search() steps 3-4.
dummy
Just call the "original" Object.defineProperties() to
* finish up.
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
line terminator will be handled on next round
* Debug dumping
x in [2**31, 2**32[
Error path.
if a site already exists, nop: max one label site per statement
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
Start in paused state.
comment: XXX: much to improve (code size)
label: code-design
[ regexp string res_arr ]
range conversion with a "skip"
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
* Regular expression structs, constants, and bytecode defines.
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
DUK_TOK_DEFAULT
[key value] or [key undefined]
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
* Set lexer input position and reinitialize lookup window.
nargs
With lightfuncs, act 'func' may be NULL
return '(?:)'
DUK_USE_REFZERO_FINALIZER_TORTURE
next to use, highest used is top - 1
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
arg2 would be clobbered so reassign it to a temp.
standard behavior, step 3.f.i
avoid degenerate cases, so that (len - 1) won't underflow
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
'let'
* Halt execution helper
1110 xxxx; 3 bytes
ch1 = (r_increment << 8) + byte
variable name reg/const, if variable not register-bound
Cast converts magic to 16-bit signed value
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
entry part size
* Property not found in prototype chain.
function executes in strict mode
'data' is reachable through every compiled function which
* contains a reference.
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
note: long live range
* Object will be kept; queue object back to heap_allocated (to tail)
no change
DUK_USE_ASSERTIONS
force the property to 'undefined' to create a slot for it
Optimized for speed.
comment: prevent multiple in-progress detaches
label: requirement
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
DUK_TOK_THIS
index
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
3-letter log level strings
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
Must prevent finalizers which may have arbitrary side effects.
DUK_EXCEPTION_H_INCLUDED
invalidates h_buf pointer
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
comment: Higher footprint, less churn.
label: code-design
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
core property functions
25%, i.e. less than 25% used -> abandon
Allow empty fraction (e.g. "123.")
0xf0...0xff
don't allow const
this is just beneath bottom
* Duktape.Buffer: constructor
'Uint8Array'
* Helpers for writing multiple properties
exhaustive
refcounting requires direct heap frees, which in turn requires a dual linked heap
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
[ ... error ]
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
parse new token
1e9
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
* Misc shared helpers.
don't set 'n' at all, inherited value is used as name
';'
switch cmd
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
comment: XXX: some overlapping code; cleanup
label: code-design
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
from curr pc
* Maximum size check
isError flag for yield
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
no need to unwind callstack
* Array part
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
[ array totalLength bufres buf ]
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
[r1,r2] is the range
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
duk_handle_call / duk_handle_safe_call recursion depth limiting
DUK_HOBJECT_FLAG_NEWENV: handled below
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
common case, already closed, so skip
ignore millisecond fractions after 3
* unshift()
E5 Section 10.4.3
No built-in functions are constructable except the top
* level ones (Number, etc).
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
Bernstein hash init value is normally 5381
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
expt 0xfff is infinite/nan
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
%s
e.g. "x" < "xx"
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
SameValue
How much stack to require on entry to object/array encode
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
... name ': ' message
to exit
parenthesis count, 0 = top level
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
input string (may be a user pointer)
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
shared helper
* Fast buffer writer with spare management.
success/error path both do this
DUK_TOK_MUL
attempt to change from accessor to data property
allowed ascii whitespace
[ ... source? filename? ]
continue jump
-> [ ... key val ]
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
no need to create environment record now; leave as NULL
* Thread state check and book-keeping.
"/=" and not in regexp mode
for lastIndexOf, result may be -1 (mark immediate termination)
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
requested identifier
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
no return value -> don't replace created value
'Arguments' object and has arguments exotic behavior (non-strict callee)
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
Note: left shift, should mask
31 to 36
two level break
don't allow an empty match at the end of the string
'thr' is now reachable
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
Allow 'Infinity'
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
* Helpers for managing property storage size
if-digit-else-ctrl
Safe write calls which will ensure space first.
having this as a separate function provided a size benefit
code emission
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Debugging related API calls
-> [ ... func this arg1 ... argN _Args length ]
'Float64Array'
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
-> [ this ]
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
retval indicates delete failed
formatters always get one-based month/day-of-month
continue matching, set neg_tzoffset flag
bound function chain has already been resolved
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
standard JSON; array gaps
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
just check 'env'
comment: XXX: primitive to make array from valstack slice
label: code-design
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
consistency requires this
DUK_TOK_CASE
Nothing to initialize, strs[] is in ROM.
currently 6 characters of lookup are actually needed (duk_lexer.c)
index/length check guarantees
left.x1 -> res.x1
* Case conversion tables generated using src/extract_caseconv.py.
is global code
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
Note: not a valid stack index if num_stack_args == 0
* Convenience (independent of representation)
no refcounting
duk_handle_ecma_call_setup: setup for a resume()
escape any non-ASCII characters
if 0, 'str' used, if > 0, 'strlist' used
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
* pop(), push()
'DecEnv'
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
* Writability check
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
DUK_USE_JSON_STRINGIFY_FASTPATH
Update all labels with matching label_id.
guaranteed by duk_to_string()
already declared, must update binding value
DUK_USE_TRACEBACKS
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
ensures callstack_top - 1 >= 0
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
detached
'constructor'
disabled for now
idx_replacer
type to represent a straight register reference, with <0 indicating none
continue jump not patched, an INVALID opcode remains there
-> [ ... enum_target res trap_result ]
current (next) array index
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
'const'
all codepoints up to U+10FFFF
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
if no NaN handling flag, may still be NaN here, but not Inf
thr argument only used for thr->heap, so specific thread doesn't matter
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
[0x00000000, 0xffffffff]
fall through to error
[ ... key_obj key key ]
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
since no recursive error handler calls
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
numeric label_id (-1 reserved as marker)
irrelevant when out->value == NULL
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
DUK_USE_STRTAB_CHAIN
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
assume value is a number
comment: combines steps 3, 6; step 7 is not needed
label: requirement
* Debugger support
comment: XXX: spare handling, slow now
label: code-design
normal and constructor calls have identical semantics
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
Same coercion behavior as for Number.
the outer loop will recheck and exit
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
x == -Infinity
[ ... source? func_template ]
other call
lastIndex already set up for next match
* Macros to access the 'props' allocation.
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
[ ... source? filename? ] (depends on flags)
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
[ targetBuffer targetStart sourceStart sourceEnd ]
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
at least one opcode emitted
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
side effects, in theory (referenced by global env)
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
Allow naked fraction (e.g. ".123")
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
Other longjmp types are handled by executor before propagating
* the error here.
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
* Ecmascript/native function call or lightfunc call
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
computed live
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
callstack limits
A...P
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
Explicit length is only needed if it differs from 'nargs'.
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
(?:
Must be restored here to handle e.g. yields properly.
The base ID of the current require() function, resolution base
non-Reference deletion is always 'true', even in strict mode
jump to next loop, using reg_v34_iter as iterated value
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
max possible
punctuators (unlike the spec, also includes "/" and "/=")
DUK_BUFOBJ_FLOAT32ARRAY
[ ... ptr ]
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
12: getDate
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
'modLoaded'
* Assertions before
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
for zero size, don't push anything on valstack
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
heap level "stash" object (e.g., various reachability roots)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
c recursion check
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
Continue parsing after padding, allows concatenated,
* padded base64.
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
idx_step is +1 for indexOf, -1 for lastIndexOf
is a setter/getter
env created above to stack top
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
DUK_TOK_LNOT
XXX: sufficient to check 'strict', assert for 'is function'
check final character validity
* Init lexer context
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
idx_step is +1 for reduce, -1 for reduceRight
PatternCharacter, all excluded characters are matched by cases above
Note: -nargs alone would fail for nargs == 0, this is OK
curr and desc are accessors
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
func.prototype.constructor = func
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
prev value can be garbage, no decref
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
Stepped? Step out is handled by callstack unwind.
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
fills window
Caller must check character offset to be inside the string.
valstack will be unbalanced, which is OK
conservative
unconditional
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Duktape.modSearch
Set .buffer to the argument ArrayBuffer.
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
flags: ""
-> [ res_obj ]
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
eat '{' on entry
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
resume write to target
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
Else functionality is identical for function call and constructor
* call.
inclusive
Check that 'this' is a duk_hbufferobject and return a pointer to it.
utf-8 continuation bytes have the form 10xx xxxx
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
'-'
hobject management functions
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
'\xffBytecode'
Catch a double-to-int64 cast issue encountered in practice.
* DumpHeap command
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
[ ... buf loop ]
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
x <- y + z
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
[ ... re_obj input bc ]
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
push before advancing to keep reachable
* duk_hthread allocation and freeing.
[ ... pattern flags escaped_source bytecode ]
* Helper for updating callee 'caller' property.
eat 'do'
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
[ source template result ]
25 user flags
also stash it before constructor,
* in case we need it (as the fallback value)
omit print
Unary plus is used to force a fastint check, so must include
* downgrade check.
DUK__FLD_16BIT
comment: should never happen, but be robust
label: code-design
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
comment: XXX: comes out as signed now
label: code-design
flags
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
writable but not deletable
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
[ ... formals ]
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
See: tests/ecmascript/test-spec-bound-constructor.js
guaranteed to succeed
* Define new property
*
* Note: this may fail if the holder is not extensible.
used elements (includes DELETED)
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
-> [ ... key val replacer holder key ]
as is
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
comment: XXX: make this an internal helper
label: code-design
assumed to bottom relative
intentionally empty
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
aaaaaabb bbbbcccc ccdddddd
[[SetPrototypeOf]] standard behavior, E6 9.1.2
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
27: setUTCSeconds
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
no need to unwind catchstack
'Proxy' object
'errCreate'
coerce lval with ToString()
see algorithm
* reverse()
index is above internal buffer length -> property is fully normal
ensure never re-entered until rescue cycle complete
comment: order: most frequent to least frequent
label: code-design
comment: not very useful, used for debugging
label: code-design
catch stack depth
[ ... res_obj ]
* Lexer defines.
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
DUK_BUFOBJ_NODEJS_BUFFER
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
XXX: version specific array format instead?
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
roughly 2 kiB
Must avoid duk_pop() in exit path
basic types from duk_features.h
XXX: byte offset
* instanceof
ecmascript compiler limits
token type
-> [ ... key val replacer ]
call_flags
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Negative indices are always within allocated stack but
* must not go below zero index.
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
Exponent
general temp register
0xe0...0xef
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
[ arg1 ... argN this loggerLevel loggerName buffer ]
duplicate zeroing, expect for (possible) NULL inits
rc_varname and reg_varbind are ignored here
get as double to handle huge numbers correctly
enum_index
XXX: clarify on when and where DUK__CONST_MARKER is allowed
* Error helpers
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
'new'
evaluate to plain value, no forced register (temp/bound reg both ok)
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
DUK_USE_INTERRUPT_COUNTER
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
comment: XXX: could be eliminated with valstack adjust
label: code-design
[key val]
DUK_TOK_CATCH
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
[ ... arg1 ... argN envobj argobj ]
flags:nonstrict
pass2 allocation handles this
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
advance manually
comment: XXX: awkward
label: code-design
target out-of-bounds (but positive)
free some memory
constrained by string length
stable; precalculated for faster lookups
* Thread defines
same handling for identifiers and strings
-> [ ... lval rval rval.prototype ]
'implements'
'='
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
negative top-relative indices not allowed now
'instanceof'
avoid attempt to compact any objects
expression parsing helpers
return ToObject(this)
one token
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
not protected, respect reclimit, is a constructor call
DUK_TOK_BNOT
E5 Section 8.6.1
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
val is unsigned so >= 0
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
must have start and end
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
env and act may be NULL
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
-> [... enum key enum_target key]
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
* Unicode tables
[... obj]
Note: space must cater for both JX and JC.
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
Normal non-bound function.
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
current and previous token for parsing
probe sequence
message is empty -> return name
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
Currently nothing to free; 'data' is a heap object
'prototype'
'jx'
default prototype (Note: 'obj' must be reachable)
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
Unwind the topmost callstack entry before reusing it
internal define property: skip write silently if exists
since new_alloc_size > 0
borrowed, no refcount
allow e.g. '0x0009' and '00077'
DUK_BUFOBJ_DATAVIEW
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
find elements to swap
currently, always the case
* Detected label
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
* Helper macros
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
constants are strings or numbers now
'\n '
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
if (is_regexp)
[ thisArg arg1 ... argN func boundFunc ]
-Infinity
Undefine local defines
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Init built-in strings
* Two's complement arithmetic.
[... constructor arg1 ... argN]
no need to decref previous value
'finally'
Zero size compare not an issue with DUK_MEMCMP.
[ ... closure template val ]
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
may be NULL (but only if size is 0)
write to entry part
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
* Debug connection message write helpers
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
don't want an intermediate exposed state with func == NULL
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
XXX=
separators: space, space, colon
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
Slow path
Lightweight function: never bound, so terminate.
unconditionally; is_global==0
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
string limits
comment: function makes one or more slow path accesses
label: code-design
DUK_USE_AUGMENT_ERROR_CREATE
No need for a NULL/zero-size check because new_size > 0)
Assume value stack sizes (in elements) fits into duk_idx_t.
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
'>'
* Debug connection skip primitives
valstack index of 'func' and retval (relative to entry valstack_bottom)
XXX: array internal?
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
avoid key quotes when key is an ASCII Identifier
embed: nothing
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
* Memory allocation handling.
current assertion is quite strong: decref's and set to unused
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
element type
parsing in "scanning" phase (first pass)
regexp res_obj is at offset 4
Flags for duk_js_compare_helper().
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
no fractions
'Function'
29: setUTCMinutes
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
accept comma, expect new value
-> [ ... reviver holder name val ]
[ ... pattern flags escaped_source buffer ]
reg
empty match -> bump and continue
regexp execution limits
* Single source autogenerated distributable for Duktape 1.5.2.
*
* Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
* Git branch HEAD.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
SCANBUILD: "Dereference of null pointer", normal
catch or with binding is currently active
Note: unbalanced stack on purpose
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
expt values [0x001,0x7fe] = normal
Receiver: Proxy object
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
* Type error thrower, E5 Section 13.2.3.
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
XXX: init or assert catch depth etc -- all values
happens when hash part dropped
1x heap size
no need for decref/incref because value is a number
comment: XXX: this may now fail, and is not handled correctly
label: code-design
[key undefined] -> [key]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
stack top contains 'false'
LAYOUT 2
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
(
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
-> [ sep ToObject(this) len str ]
covered by comparison
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
For now, restrict result array into 32-bit length range.
coerce in-place
DUK_ERR_ASSERTION_ERROR: no macros needed
directive prologue status at entry
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
[ ... num ]
arrays MUST have a 'length' property
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
comment: Inner executor, performance critical.
label: code-design
significant from precision perspective
[ ... Logger clog logfunc clog ]
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
fits into duk_small_int_t
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
is eval code
* Iterate the bitstream (line diffs) until PC is reached
varmap is already in comp_ctx->curr_func.varmap_idx
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
[key setter this val] -> [key retval]
DUK_TOK_LAND
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
Note that multiple catchstack entries may refer to the same
* callstack entry.
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
DUK_HNATIVEFUNCTION_H_INCLUDED
check pointer at end
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
chain jumps for 'fall-through'
* after a case matches.
duk_unicode_ids_noa[]
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
reset longjmp
non-strict equality for buffers compares contents
all codepoints up to U+FFFF
recursion tracking happens here only
roughly 128 bytes
default clause matches next statement list (if any)
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
new value
MULTIPLICATIVE EXPRESSION
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
-> [ ... func this ]
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
caller checks
t has high mantissa
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
DUK_TOK_LCURLY
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
If 'day' is NaN, returns NaN.
* New length not lower than old length => no changes needed
* (not even array allocation).
* API oriented helpers
[enum_target res key true]
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
ADDITIVE EXPRESSION
macros
default case does not exist, or no statements present
* after default case: finish case evaluation
use temp_next for tracking register allocations
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
DUK_REGEXP_H_INCLUDED
comment: XXX: add fastint support?
label: requirement
FOUND
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
initialize for debug prints, needed if sce==NULL
start of valstack allocation
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
-> [ ... enum_target res trap handler target ]
derived types
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Must be a "pointer object", i.e. class "Pointer"
ES6 proxy
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
value of dbg_exec_counter when we last did a Date-based check
idx_retval unsigned
no negative sign for zero
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
looping should never happen
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
digit position is absolute, not relative
c
comment: Same test with volatiles
label: test
because callstack_top > 0
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
%d; only 16 bits are guaranteed
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Since we already started writing the reply, just emit nothing.
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
-> [ ... errhandler undefined(= this) errval ]
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
valid pc range is [0, length[
Current tracedata contains 2 entries per callstack entry.
[ ... errval ]
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
comment: XXX: no need for indirect call
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
valstack
not protected, respect reclimit, not constructor
Push the resulting view object and attach the ArrayBuffer.
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
unbalanced stack
value from hook
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
shared pop
* Struct defs
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: not really necessary
label: code-design
[ ... target ] -> [ ... target keys ]
Leading zero.
','
Make underlying buffer compact to match DUK_BW_GET_SIZE().
first heap allocated, match bit boundary
comment: XXX: more specific error classes?
label: code-design
25: setUTCMilliseconds
* Intermediate value helpers
Limits
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
[ sep ToObject(this) len sep result ]
* Variant 2 or 4
Lightfunc, always success.
step 11.c is relevant only if non-strict (checked in 11.c.ii)
XX==
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
Force exponential format. Used for toExponential().
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
wipe the capture range made by the atom (if any)
Anything else is not constructable.
attrs in E5 Section 15.3.5.1
* Use the index in the header to find the right starting point
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
maximum length of standard format tag that we support
buffer size is >= 1
ignore encoding for now
enable manually for dumping
(?=
require to be safe
Parser part count.
for side effects, result ignored
Now we can check offset validity.
Milliseconds between status notify and transport peeks.
Matching separator index is used in the control table
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
* Stringify implementation.
ToNumber() for a double is a no-op.
default: char escape (two chars)
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
negate result
* Lightfunc
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
Special handling for year sign.
[ arg1 ... argN obj length new_length ]
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
statements go here (if any) on next loop
'yield'
eat trailing comma
pruned
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
lookup results is ignored
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
resume caller must be an ecmascript func
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
errors out if out of memory
stack contains value (if requested), 'out_desc' is set
no issues with empty memcmp()
[str] -> [substr]
func is NULL for lightfunc
property attributes for identifier (relevant if value != NULL)
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
don't allow continue
respect reclimit, not constructor
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
0x60-0x6f
DUK_BUFOBJ_INT32ARRAY
Caller has already eaten the first char so backtrack one byte.
controls for minimum entry part growth
temp accumulation buffer
Unwind.
* Object built-ins
callstack index
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
take last entry
curr is data, desc is accessor
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
* Bitstream decoder
statement id allocation (running counter)
'public'
single match always
Note: 'curr' refers to 'length' propdesc
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
Steps 8-10 have been merged to avoid a "partial" variable.
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
duk_safe_call discipline
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
comment: XXX: encoding is ignored now.
label: code-design
use 'undefined' for value automatically
[ ... obj ... ]
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
Buffer length is bounded to 0xffff automatically, avoid compile warning.
Integer division which floors also negative values correctly.
consequence of above
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
backtrack (safe)
DUK__FLD_32BIT
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
comment: Note: reuse 'curr'
label: code-design
* Convert and push final string.
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
* Selftest code
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Get default hash part size for a certain entry part size.
Maximum number of digits generated.
[ ... func buf ] -> [ ... buf ]
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
e.g. DUK_OP_PREINCV
If neutered must return 0; offset is zeroed during
* neutering.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
breakpoints: [0,breakpoint_count[ gc reachable
comment: XXX: inefficient loop
label: code-design
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
Strings and ROM objects are never placed on the heap allocated list.
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
stack type fits into 16 bits
'set'
low to high
required, NULL implies detached
right associative
covers +Infinity
no size check is necessary
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
comment: XXX: best behavior for real world compatibility?
label: code-design
34: setMonth
20: getSeconds
refcount macros not defined without refcounting, caller must #ifdef now
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
comment: XXX: shared parsing?
label: code-design
Note: reject negative zero.
Delete entry in Duktape.modLoaded[] and rethrow.
already closed
'\xffFormals'
1
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
DUK_TOK_NEQ
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
no shrink
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
* Ecmascript bytecode
Current require() function
[ ... errobj ]
[... arr]
-> [ ... escaped_source ]
func
ignore fclose() error
DUK_TOK_RETURN
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
XXX: to util
Byte length would overflow.
register declarations in first pass
implicit this value always undefined for
* declarative environment records.
match_caps == 0 without regexps
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
* Object finalizer
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
-> [ ... proplist enum_obj key ]
elems in source and dest
E5 Section 15.4.5.1, step 4
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
DUK_USE_ROM_OBJECTS
stats for current expression being parsed
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
DUK_IVAL_XXX
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
* Error, fatal, and panic handling.
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
guaranteed by string limits
Slot A
terminates expression; e.g. post-increment/-decrement
ignore arguments, return undefined (E5 Section 15.3.4)
Thread state.
g...v
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
omit
always >= 0
Fixed buffer, no zeroing because we'll fill all the data.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
terminal type: no depth check
track cpos while scanning
DUK_TOK_SEQ
curr_pc synced by duk_handle_ecma_call_setup()
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
accessor flag not encoded explicitly
For now only needed by the debugger.
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
remove value
* Forward declarations
mm <- mp
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
rethrow
* Accessor macros for function specific data areas
Argument validation and func/args offset.
day number for Jan 1 since epoch
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
compact
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
"123." is allowed in some formats
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
NB: must accept reserved words as property name
no array part
* Misc
error message doesn't matter, ignored anyway
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
Currently nothing to free
comment: Convenience copies from heap/vm for faster access.
label: code-design
Reply with tvals pushed by request callback
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
'index'
index is above internal string length -> property is fully normal
LF line terminator; CR LF and Unicode lineterms are handled in slow path
* Misc helpers
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
bound chain resolved
base
Line format: <time> <entryLev> <loggerName>: <msg>
NEXTENUM jump slot: executed when enum finished
comment: prototype should be last, for readability
label: code-design
comment: XXX: direct implementation
label: requirement
Error codes.
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
* Property lookup
Constants for duk_hashstring().
roughly 1 kiB
advance by one character (code point) and one char_offset
no need to coerce
remove key and value
A regexp token value.
large context; around 2kB now
lexer character window helpers
at index 1
trivial cases
duplicate/invalid key checks; returns 1 if syntax error
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
original target at entry_top - 1
not emitted
comment: XXX: duk_ssize_t would be useful here
label: code-design
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
* Init lexer
'%'
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
DUK_TOK_NUMBER
IEEE exp without bias
31 bits
call handling
not exposed
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
For internal use: get array part value
10xx xxxx -> invalid
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
_Varmap is dense
DUK_TOK_BAND
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
indirect eval
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
* Some assertions (E5 Section 13.2).
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
preincrement and predecrement
Value would normally be omitted, replace with 'null'.
e.g. require('/foo'), empty terms not allowed
string is internal
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
success: leave varname in stack
safe
[ ... closure template len_value ]
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
[ ... func this (crud) retval ]
DUK_USE_DATE_PRS_STRPTIME
comment: Global case is more complex.
label: code-design
max, excl. varargs marker
should be a safe way to compute this
not an error
prev_token slot2
side effects, perform in-place
comment: XXX: turkish / azeri
label: code-design
current variable environment (may be NULL if delayed)
May happen in some out-of-memory corner cases.
* Store lexer position for a later rewind
-> [ ... this timeval ]
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
prev_token slot1
Note1
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
DUK_TOK_IMPORT
* Native call.
input offset tracking
-> [ ... closure template newobj closure ]
fixed arg count: value
chain jumps for case
* evaluation and checking
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
function call
full 3-byte -> 4-char conversions
regexp compilation limits
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
0x00: slow path
* other: as is
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
reject 'in' token (used for for-in)
Data area, fixed allocation, stable data ptrs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
DUK_LEXER_H_INCLUDED
type bit mask: types which certainly produce 'undefined'
XXX: for threads, compact value stack, call stack, catch stack?
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
second, parse flags
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
strict mode restrictions (E5 Section 12.2.1)
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
[ regexp ]
'\xffFinalizer'
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
output is never longer than input during resolution
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Fast path the binary case
* Unicode helpers
comment: XXX: zero assumption
label: code-design
* Assertions after
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
'Math'
1e8: protects against deeply nested inner functions
insert ranges instruction, range count patched in later
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
tc1 = false, tc2 = true
after this, return paths should 'goto finished' for decrement
obj_index
zero-width non-joiner
activation has active breakpoint(s)
Constants for built-in string data depacking.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
start (incl) and end (excl) of trimmed part
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
interpret e.g. '09' as '0', not NaN
* splice()
no argument given -> leave components untouched
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
character represents itself
eat 'return'
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
[ value offset end ]
Relies on NULL encoding to zero.
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
* Compilation and evaluation
Note: Identifier rejects reserved words
-> [ obj trap_result ]
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
caller ensures
* Not found (in registers or record objects). Declare
* to current variable environment.
comment: 'this' binding is not needed here
label: requirement
no need to check callable; duk_call() will do that
mark finalizer work list as reachability roots
Initial '{' has been checked and eaten by caller.
'\xffMap'
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
'NaN'
unsigned 31-bit range
DUK_USE_EXPLICIT_NULL_INIT
valgrind whine without this
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Exposed calls
key encountered as a setter
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
one i_step over
Shared prefix for all buffer types.
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
must restore reliably before returning
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
return 'res_arr' or 'null'
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
break jump
"123"
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
range check not necessary because all 4-bit values are mapped
floor(1.15 * (1 << 10))
expect_eof
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
* Stack constants
call: this.fmt(arg)
Combined step 11 (empty string special case) and 14-15.
w/o refcounting
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
Write fully.
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
object established using Function.prototype.bind()
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
output radix
resume check from proxy target
native function properties
1e8
Lightfunc flags packing and unpacking.
Helpers exposed for internal use
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
assertion omitted
-> [... obj finalizer]
does not fit into an uchar
need to normalize, may even cancel to 0
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
used for array, stack, and entry indices
[ ... name reg_bind ]
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
invalid value which never matches
Arrays never have other exotic behaviors.
0xxx xxxx [7 bits]
[ ... env target ]
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: alloc size in elements
label: code-design
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
note: caller 'sp' is intentionally not updated here
Underlying buffer (refcounted), may be NULL.
actual chars dropped (not just NUL term)
free-form
formals for 'func' (may be NULL if func is a C function)
comment: bytes of indent available for copying
label: code-design
* Valstack manipulation for results.
[obj key desc value get set curr_value varname]
* Add ._Tracedata to an error on the stack top.
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
Lexer context. Same context is used for Ecmascript and Regexp parsing.
comment: XXX: spilling
label: code-design
Note: rely on index ordering
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
NB: duk_lexer_getpoint() is a macro only
dangerous: must only lower (temp_max not updated)
x <- x + y, use t as temp
* Init argument related properties
add BC*2^16
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
char format: use int
Clamping only necessary for 32-bit ints.
maximum size check is handled by callee
-> [ ... val root val ]
Note: start_offset/end_offset can still be < 0 here.
cat_idx catcher is kept, even for finally
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
'fatal'
* Plain, boring reachable object.
value of re_ctx->captures at start of atom
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
pc_label
'configurable'
* Object prototype
'this' binding exists
XXX: direct manipulation, or duk_replace_tval()
fill window
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
* Logging support
[key result]
unchanged by Duktape.Thread.resume()
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
Return 1: got EOM
include removed: duk_internal.h
NOTE: length may be zero
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
Alignment guarantee
!DUK_USE_PREFER_SIZE
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* Mark the heap.
silence scan-build warning
varname is popped by above code
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
Decode failed.
* Init stringcache
[... constructor arg1 ... argN final_cons]
comment: XXX: lithuanian, explicit dot rules
label: code-design
XXX: similar coercion issue as in DUK_TOK_PERIOD
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
source out-of-bounds (but positive)
'with' binding has no catch clause, so can't be here unless a normal try-catch
second incref for the entry reference
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
Get.
DUK_TOK_PRIVATE
randomized pivot selection
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
These are not needed when only Duktape.Buffer is supported.
duk_hobject specific fields.
[val] -> []
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
* Shared exit path
force_exponential
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
DUK_INVALID_INDEX won't be accepted as a valid index.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
DUK_USE_BUFFEROBJECT_SUPPORT
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
string hash
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
0 = no update
regexp opcodes
'function'
recursion limit
utf-8 validation ensures these
count, not including sep
string data is external (duk_hstring_external)
currently paused: talk with debug client until step/resume
duk_concat() coerces arguments with ToString() in correct order
2 to 11
guaranteed to finish
const flag for B
one i_step added at top of loop
'res' may be NULL if new allocation size is 0.
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
thread
assume PC is at most 32 bits and non-negative
1 0 <2 bits>
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
NULL obj->p is OK
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
Assume that thr->valstack_bottom has been set-up before getting here.
len: 9
* E5 Section 11.4.9
deal with weak references first
duk_push_sprintf constants
negative: dst info not available
topmost element is the result array already
Fast path, handle units with just actual encoding characters.
out of spec, must be configurable
* Debug logging after adjustment.
* Pushers
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
implicit_return_value
XXX: direct valstack write
[ ... source? filename ]
No resize has occurred so temp_desc->e_idx is still OK
lookup for 0x000a above assumes shortest encoding now
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
true, despite side effect resizes
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
[ start end str ]
source is eval code (not global)
switch initial byte
Note: pc is unsigned and cannot be negative
* Casting
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
Longjmp handling has restored jmpbuf_ptr.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
-> [ ... varname val this ]
processed one or more messages
[ ... v1(filename) v2(line+flags) ]
must have been, since in array part
slower but more compact variant
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
comment: parameter passing, not thread safe
label: requirement
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
Note: decimal number may start with a period, but must be followed by a digit
main reachability roots
DUK_HBUFFER_H_INCLUDED
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
placed in duk_heaphdr_string
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
'private'
toJSON() can also be a lightfunc
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
move pivot out of the way
final configuration
-1 == not set, -2 == pending (next statement list)
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
NB: 'length' property is automatically updated by the array setup loop
index for next new key ([0,e_next[ are gc reachable)
idx is unsigned, < 0 check is not necessary
indirect opcode follows direct
* toFixed(), toExponential(), toPrecision()
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
follow prototype chain
[ value ]
XXX: incref by count (here 2 times)
equals
true even with reattach
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
numeric value of a hex digit (also covers octal and decimal digits)
DUK_TOK_MUL_EQ
DUK_USE_DEBUG
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
0x00: finish (non-white)
* 0x01: continue
%lu
[ ... arg1 ... argN ]
executor interrupt running (used to avoid nested interrupts)
[ ... func this ]
Constants: variable size encoding.
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
no res->strs[]
* Debug dumping of duk_heap.
Detach a debugger if attached (can be called multiple times)
* safely.
if 1, doing a string-to-number; else doing a number-to-string
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
* duk_hbuffer allocation and freeing.
stash to bottom of value stack to keep new_env reachable for duration of eval
step 4.a
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
exports
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
comment: XXX: use duk_is_valid_index() instead?
label: code-design
eat closing bracket
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* The switch statement is pretty messy to compile.
* See the helper for details.
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
first value: comma must not precede the value
actually used, non-NULL keys
r <- (2 * b) * f
[ ... re_obj input bc saved_buf res_obj ]
* Create wrapper object and serialize
t1 <- t1 - s
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
112.5%, i.e. new size less than 12.5% higher -> fast resize
* URI handling
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
32-bit value
string intern table (weak refs)
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
Convert indices to byte offsets.
'l'
Fast path: source is a TypedArray (or any bufferobject).
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
'var'
[ args(n) [crud] formals arguments map mappednames ]
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
'pointer'
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
DUK_UNICODE_H_INCLUDED
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
end of valstack allocation (exclusive)
previous value is assumed to be garbage, so don't touch it
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
comment: suppress warning, not used
label: code-design
Buffer/string -> compare contents.
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
finished jump
string is ASCII, clen == blen
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
* Copy array elements to new array part.
For strings, special form for short lengths.
Setup function properties.
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
* Utilities
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
comment: XXX: 'copy properties' API call?
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
'{_func:true}'
prediction: portable variant using doubles if 64-bit values not available
[ ... arr val ]
Casting convenience.
The stack has a variable shape here, so force it to the
* desired one explicitly.
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
Object.getOwnPropertyNames
'undefined'
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
Overestimate required size; debug code so not critical to be tight.
comment: no special formatting
label: code-design
proplist is very rare
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
DUK_USE_JC
function refers to 'arguments' identifier
don't want an intermediate exposed state with invalid pc
Use loop to minimize code size of relookup after bound function case
'Undefined'
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
if abandon_array, new_a_size must be 0
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
pointer is aligned, guaranteed for fixed buffer
See MPUTOBJ comments above.
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
'\xffPc2line'
comment: XXX: better coercion
label: code-design
guaranteed to finish, as hash is never full
shared flags for a subset of types
nothing to incref
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
unpack args
hash lookup
* Cleanup: restore original function, restore valstack state.
don't touch property attributes or hash part
Note: duk_uint8_t type yields larger code
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
return arg as-is
NULL accepted
Lightfunc, not blamed now.
0 = no throw
comment: XXX: macros
label: code-design
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
maximum recursion depth for loop detection stacks
us
[ ... holder name val ]
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
* Init arguments properties, map, etc.
comment: NUL terminator handling doesn't matter here
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
keep in on valstack, use borrowed ref below
[ ... Logger clog logfunc clog(=this) msg ]
-> [ ... func this arg1 ... argN _Args ]
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
compiler's responsibility
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
func is NULL for lightfuncs
shared exit path now
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
-> [ O toIsoString O ]
* Finish
-> [ timeval this timeval ]
cached: valstack_end - valstack (in entries, not bytes)
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
* Bitstream encoder.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
IdentifierStart production with ASCII and non-BMP excluded
temp object for tracking / detecting duplicate keys
negative
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
DUK_BUFOBJ_INT8ARRAY
DUK_USE_ROM_STRINGS
get pointer offsets for tweaking below
Note: not normalized, but duk_push_number() will normalize
NULL if not an object
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
XXX: could add fast path for u8 compatible views
Note2
'resume'
should never happen for a strict callee
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
[... env]
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
'export'
DUK_ERR_URI_ERROR: no macros needed
array case is handled comprehensively above
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
force_no_namebind
DUK_TOK_NEW
* Breakpoint and step state checks
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
global object doesn't have array part
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
comment: XXX: specific getter
label: code-design
[ ... escape_source bytecode ]
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
lastIndex is initialized to zero by new RegExp()
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
>>>
[ ... closure template formals ]
inherit
filename being compiled (ends up in functions' '_filename' property)
filter out flags from exprtop rbp_flags here to save space
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
prop index in 'array part', < 0 if not there
caller handles sign change
comment: load factor too low or high, count actually used entries and resize
label: code-design
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
make the new thread reachable
XXX: print built-ins array?
temp reg
* Externs and prototypes
no incref
Test signaling NaN and alias assignment in all endianness combinations.
1 GB
XXX: fast path for array arguments?
-> [ ... new_global new_globalenv new_global new_global ]
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
DUK_USE_PACKED_TVAL
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
values for the state field
How large a loop detection stack to use
pop enum
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
<
[ ... closure template undefined ]
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
dynamic buffer ops
not found in 'curr', next in prototype chain; impose max depth
13: getUTCDate
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
[ ... this name ]
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
comment: XXX: check flags
label: requirement
ASCII (and EOF) fast path -- quick accept and reject
0xc0...0xcf
'-' as a range indicator
-> [ ... enum_target res handler undefined target ]
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
"123.456"
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
'false'
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
data property or accessor without getter
* Args validation
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
* String built-ins
* Clear (reachable) flags of refzero work list.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
catchstack
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
Call sites don't need the result length so it's not accumulated.
non-zero: make copy
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
fromPresent = false
Check that there's room to push one value.
comma check
backtrack to last output slash (dups already eliminated)
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Flags for call handling.
jump to end
* RegExp built-ins
allocation size
no -> decref members, then free
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
XXX: C recursion limit if proxies are allowed as handler/target values
try part
'caller' must only take on 'null' or function value
sign doesn't matter when writing
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
comment: unused
label: code-design
* Other file level defines
Fast path for numbers (one of which may be a fastint)
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
[enum_target enum res]
orig value
comment: XXX use get tval ptr, more efficient
label: code-design
See comments in duk_pcall().
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
A bit tricky overflow test, see doc/code-issues.rst.
key must not already exist in entry part
Digit generation
reset function state (prepare for pass 2)
+0 = catch
avoid side effects!
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
duk_small_uint_fast_t c = DUK_DEC_C(ins);
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
comment: No coercions or other side effects, so safe
label: requirement
0x20-0x2f
may become sparse...
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
XXXXXX--
lightfuncs are treated like objects and not coerced
jump to end or else part
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
for duk_error_augment.c
just one 'int' for C++ exceptions
'~'
reset voluntary gc trigger count
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
* Defines for JSON, especially duk_bi_json.c.
* Fast path tables
-> [ ... handler trap ]
DUK_TOK_ALSHIFT_EQ
Note: assumes 'data' is always a fixed buffer
* Stringtable entry for fixed size stringtable
sometimes stack and array indices need to go on the stack
hash size ratio goal, must match genhashsizes.py
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
Require a lot of stack to force a value stack grow/shrink.
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
DUK_DEBUG_H_INCLUDED
input size is good output starting point
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: Should never happen but avoid infinite loop just in case.
label: code-design
unchanged from Duktape.Thread.yield()
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
Negative offsets cause a RangeError.
side effect free
main expression parser function
may happen if size is very close to 2^32-1
fail: restore saves
DUK_USE_DATE_PRS_GETDATE
needed for stepping
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
clen == blen -> pure ascii
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
current setjmp() catchpoint
Result is undefined.
[ ... proplist ]
This may throw an error though not for valid E5 strings.
* Marking functions for heap types: mark children recursively
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
XXX: set with duk_hobject_set_length() when tracedata is filled directly
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
Slow path.
'compile'
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
DUK_TOK_RCURLY
comment: XXX: check .caller writability?
label: code-design
replacement handler
2**31-1 ~= 2G properties
part of string
Bytecode instructions: endian conversion needed unless
* platform is big endian.
DUK_TOK_EXTENDS
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
fastint downgrade check for return values
comment: bytes of indent still needed
label: code-design
DUK_JS_COMPILER_H_INCLUDED
nop
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
Double error
* Valstack spare check
This would be pointless: unexpected type and lightfunc would both return NULL
For internal use: get non-accessor entry value
trailing comma followed by rcurly
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
[... value this_binding]
DUK_TOK_INCREMENT
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
insert code for matching the remainder - infinite or finite
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
* Fast paths
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
truncate towards zero
37: setUTCFullYear
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
* Assert helpers
resume lookup from target
comment: XXX: assume these?
label: code-design
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
standard prototype
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
flags: "gm"
no need to decref, as previous value is 'undefined'
may need unwind
catch part will catch
-> [ ... name index ]
* Node.js Buffer: toString([encoding], [start], [end])
* Ecmascript compiler.
Allow fraction part
explicit 'this' binding, see GH-164
Initial bytecode size allocation.
XXX: patch initial size afterwards?
already zero
late lookup, avoid side effects
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
match against rule part/sep bits
'd' and 'res' agree here
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
Eval code doesn't need an automatic .prototype object.
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
never here
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
Note that 'l' and 'r' may cross, i.e. r < l
For internal use: get non-accessor entry value and attributes
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
DUK_USE_JSON_EATWHITE_FASTPATH
valstack top, should match before interpreting each op (no leftovers)
may be NULL if alloc_size == 0
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
110x xxxx; 2 bytes
if num_values > 0, MPUTARR emitted by outer loop after break
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
Not enough data.
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
DUK_TOK_STRING
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ ... env ]
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
* Reallocate memory with garbage collection
comment: XXX: unnecessary translation of flags
label: code-design
Explicit check for fastint downgrade.
default attrs ok
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
comment: There may be whitespace between the equal signs.
label: code-design
comment: Note: first argument not really used
label: code-design
* Function declarations
reg_res should be smallest possible
Slot B
* Unreachable object, free
Specific assumptions for opcode numbering.
comment: copied so that 'ap' can be reused
label: code-design
exponents 1023 to 1069
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
(?!
name
Restart bytecode execution, possibly with a changed thread.
-> [ ... func name ]
top of current frame (exclusive)
if thisArg not supplied, behave as if undefined was supplied
for side effects
comment: XXX: match flag is awkward, rework
label: code-design
fall through and continue for-loop
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
assume 0 <=> NULL
skip leading digit
B -> object register
* C -> C+0 contains key, C+1 closure (value)
caller guarantees
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
at least this function exists
hash part is a 'weak reference' and does not contribute
'pc'
'errThrow'
DUK_TOK_SUPER
This is guaranteed by debugger code.
[... (sep) str1 str2 ... strN buf]
0: no change
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
reg(ignored)
undefined coerces to zero which is correct
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
returned after EOF (infinite amount)
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
Unwind catchstack entries referring to the callstack entry we're reusing
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
e.g. DUK_OP_POSTINCR
'Uint8ClampedArray'
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
no typedef
[ ... func_template ]
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
[ arg1 ... argN obj length ]
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
comment: unused with some debug level combinations
label: code-design
Line number range for function. Needed during debugging to
* determine active breakpoints.
comment: slow init, do only for slow path cases
label: code-design
DUK_BUFOBJ_DUKTAPE_BUFFER
positive
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
e.g. DUK_OP_PREINCP
DUK_JS_H_INCLUDED
DUK_USE_DATE_NOW_WINDOWS
!DUK_SINGLE_FILE
this is added to checks to allow for Duktape
* API calls in addition to function's own use
[ ... key_obj key ]
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
is_setget
flags always encodes to 1 byte
Ensure space for 1:1 output plus one escape.
[ ... obj key value ]
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
C array of duk_labelinfo
comment: XXX: double evaluation for 'tv' argument.
label: code-design
with stack depth (affects identifier lookups)
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Detect recursive invocation
comment: known to be 32-bit
label: code-design
* Directive prologue tracking.
Handle lightfuncs through object coercion for now.
exponent 0
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
duk_handle_ecma_call_setup: setup for a tail call
match: keep wiped/resaved values
E5 Section 11.7.2, steps 7 and 8
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
heap thread, used internally and for finalization
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
For now all calls except Ecma-to-Ecma calls prevent a yield.
If tv1==tv2 this is a NOP, no check is needed
Dispatch loop.
DUK_TOK_SUB
Shared Windows helpers.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
catches EOF and invalid digits
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
* Call the constructor function (called in "constructor mode").
minimum prime
set by atom case clauses
[ ... error func fileName ]
reset callstack limit
right paren eaten
'['
idx_desc
E5 Section 11.7.1, steps 7 and 8
coerced value is updated to value stack even when RangeError thrown
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
Expression_opt
Exact halfway, round to even.
* Arguments check
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
name is empty -> return message
* Rescue or free.
grow by at most one
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
Note: proxy handling must happen before key is string coerced.
DUK_HBUFFEROBJECT_H_INCLUDED
[... res]
Note: unconditional throw
DUK_ERRMSG_H_INCLUDED
Neutered buffer, zero length seems
* like good behavior here.
no mark-and-sweep gc
* DUK_BSWAP macros
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
loggerName
will result in undefined
DUK_TOK_QUESTION
* Delayed initialization only occurs for 'NEWENV' functions.
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
Load constants onto value stack but don't yet copy to buffer.
[ hobject props enum(props) key desc ]
'Float32Array'
eat comma
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
Commands and notifys initiated by Duktape.
DUK_TOK_GT
* Stringtable
offset is now target of the pending split (right after jump)
U+03A3 = GREEK CAPITAL LETTER SIGMA
always 0 args
exit bytecode executor by rethrowing an error to caller
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
initialize built-ins - either by copying or creating new ones
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
IsAccessorDescriptor(desc) == true
avoid issues with relocation
avoid recursive string table call
res.x1 -> res.x2
-> [ ... x y fn ]
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
LHS is already side effect free
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
object has an array part (a_size may still be 0)
0x20...0x2f
eat dup slashes
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
initial estimate based on format string
enable exotic behaviors last
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
[ obj key desc ]
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
[... env callee varmap key val]
currently required
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
(flags<<32) + (line), flags = 0
insert range count
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
[ ... new_glob new_env ]
Count actually used (non-NULL, non-DELETED) entries.
no refcount check
Parse statements until a closing token (EOF or '}') is found.
duk_hthread_callstack_unwind() will decrease this on unwind
Note: array dump will include elements beyond
* 'length'.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
size stored in duk_heaphdr unused flag bits
genbuiltins.py ensures
-> [ ... val' ]
CR LF again a special case
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
Full, aligned 4-byte reads.
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
* Zero the struct, and start initializing roughly in order
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
duk_unicode_idp_m_ids_noa[]
mark-and-sweep is currently running
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
DUK_API_INTERNAL_H_INCLUDED
'\xffTarget'
FUNCTION EXPRESSIONS
0x50-0x5f
Note: there is no standard formatter for function pointers
default: no change
internal type tag
* Ecmascript bytecode executor.
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
p points to digit part ('%xy', p points to 'x')
the compressed pointer is zeroed which maps to NULL, so nothing to do.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
bottom of current frame
Shared offset/length coercion helper.
E5 Section 15.10.2.11
'writable'
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
internal spare
value (error) is at stack top
input byte length
gap (if empty string, NULL)
[ args [crud] arguments ]
lightfunc
higher value conserves memory; also note that linear scan is cache friendly
comment: XXX: to be implemented?
label: code-design
comment: XXX: convert to fixed buffer?
label: code-design
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Assume arrays are dense in the fast path.
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
* Value stack top handling
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
x <= y --> not (x > y) --> not (y < x)
[key setter this val]
little endian
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
* Misc util stuff
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
Node.js return value for failed writes is offset + #bytes
* that would have been written.
NaN sign bit is platform specific with unpacked, un-normalized NaNs
comment: XXX: union would be more correct
label: code-design
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
'stack'
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
".123"
currently used -> new size
caller is responsible for ensuring this
must be signed
uppercase
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
comment: XXX: optimize this filling behavior later
label: code-design
replaced
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
[ ... regexp input ] -> [ res_obj ]
Mostly API and built-in method related
E5 Sections 15.9.3.1, B.2.4, B.2.5
alloc and init
prediction corrections for prime list (see genhashsizes.py)
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
DUK_USE_REGEXP_SUPPORT
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
* Interrupt counter fixup (for development only).
Note: recursive call
maximum bytecode length in instructions
get const for value at valstack top
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
line tracking
first call
* All done
undefined is accepted
* Wrap up
this case can no longer occur because refcount is unsigned
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
reachable through activation
[ ... filename &comp_stk ]
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
+ 1 for rounding
note: any entries above the callstack top are garbage and not zeroed
must be, since env was created when catcher was created
side effects (currently none though)
DUK_BUILTIN_PROTOS_H_INCLUDED
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
shadowed, ignore
'Uint16Array'
-> [ ... enum_target res ]
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
+1 = one retval
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
[ ... obj key val ]
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
idx_value may be < 0 (no value), set and get may be NULL
numeric value (character, count)
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
assume 'var' has been eaten
empty separator can always match
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
coerce to string
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
no check
comment: XXX: optimize to 16 bytes
label: code-design
* Endian conversion
nrets
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
embed: integer value
0=base, 1=esc, 2=class, 3=class+esc
XXX: proper flags?
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
some assertions
array writes autoincrement length
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
reserved words: keywords
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
[... env callee varmap]
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
[ body formals source template ]
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
num args starting from idx_argbase
caller must change active thread, and set thr->resumer to NULL
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
unary plus
* Shortcut for accessing global object properties
* slice()
may be changed
step 3.e: replace 'Desc.[[Value]]'
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
[ ... varmap ]
* Type checking
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
Grow array part for a new highest array index.
no need to mask idx portion
remove hash entry (no decref)
index
exclusive endpoint
Append bytes from a slice already in the buffer.
this also increases refcount by one
whole, won't clip
[ source template ]
Cannot overlap.
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
apparently no hint?
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
XXX: clumsy sign extend and masking of 16 topmost bits
Note: no key on stack
[... retval]
DUK_USE_JX
num args
end of _Formals
no need to pop, nothing was pushed
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
2 when called by debugger
* Top level wrappers
DUK_INTERNAL_H_INCLUDED
Report next pc/line to be executed.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
fixed offsets in valstack
* Math built-ins
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
check that there is space for at least one new entry
0xa0...0xaf
eval left argument first
-> [ ... closure template ]
1 << 52
must match genhashsizes.py
setter and/or getter may be NULL
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
current thread
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
Duktape.Thread.yield() should prevent
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
LICENSE.txt
[ ... varname val ]
string is 'eval' or 'arguments'
* The default property attributes are correct for all
* function valued properties of built-in objects now.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
IdentifierStart production with ASCII excluded
nothing to mark
comment: XXX: function properties
label: code-design
prepend regexp to valstack 0 index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
convenience
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
[obj key value desc]
stmt has non-empty value
-> [ ... holder name val val ToString(i) ]
stage 2: delete configurable entries above target length
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
keep key reachable for GC etc; guaranteed not to fail
generate mantissa with a single leading whole number digit
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Stored in duk_heaphdr unused flags.
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
terminator
DUK_TOK_EQUALSIGN
* Comparison
DUK_JSON_H_INCLUDED
may have side effects
increases key refcount
on first round, skip
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
comment: XXX: solve into closed form (smaller code)
label: code-design
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
must be signed for loop structure
is_extra
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
Here 'x' is a Unicode codepoint
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
"-123456\0"
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
curr value
These are for rate limiting Status notifications and transport peeking.
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
DUK_USE_LEXER_SLIDING_WINDOW
DUK_TOK_NULL
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
-> [... obj value]
[ key trap_result ] -> []
replace in stack
(maybe) truncated
nothing to process
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
knock back "next temp" to this whenever possible
* Detected a directive
'for'
complete the millisecond field
'lt is true'
Pre/post inc/dec for register variables, important for loops.
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Iteration solution
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Helper tables
'this'
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
approximate
Avoid NaN-to-integer coercion as it is compiler specific.
Reset to zero size, keep current limit.
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
callback for indirect reallocs, request for current pointer
[ ... this ]
* Portable 12-byte representation
avoid multiple computations of flags address; bypasses macros
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
must not truncate
prefix matches, lengths matter now
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
* Replace valstack top with case converted version.
Shuffle decision not changed.
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
numeric value of token
[... constructor arg1 ... argN] -> [retval]
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
temps
'Object'
not strictly necessary
IsDataDescriptor(desc) == true
POSTFIX EXPRESSION
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
'Error'
* Flags for __FILE__ / __LINE__ registered into tracedata
Count actually used entry part entries (non-NULL keys).
DUK_TOK_ARSHIFT
comment: XXX: possibly incorrect handling of empty expression
label: code-design
used entries + approx 100% -> reset load to 50%
'\xffRegbase'
is_decl
but don't allow leading plus
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
[ ... holder name val enum obj_key val obj_key ]
lj.value1 is already set
number of arguments allocated to regs
Optimized for size.
* Default fatal error handler
named "arithmetic" because result is signed
Default implicit return value.
lookup name from current activation record's functions' registers
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
max # of key-value pairs initialized in one MPUTOBJ set
unicode code points, window[0] is always next
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
thread not currently running
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
[... key arg1 ... argN]
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
Chop extra retvals away / extend with undefined.
MPUTARR emitted by outer loop
comment: XXX: fastint?
label: code-design
compact the exports table
Code is not accepted before the first case/default clause
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
-> [ ... key val replacer holder key val ]
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
No debugger support.
'<'
treat like property not found
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
Carry is detected based on wrapping which relies on exact 32-bit
* types.
eat (first) input slash
value resides in a register or constant
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
Overflow, relevant mainly when listlen is 16 bits.
[ ... val ] --> [ ... enum ]
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
case 0: nop
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
Error: try coercing error to string once.
for resizing of array part, use slow path
y == -Infinity
Initialization and finalization (compaction), converting to other types.
must match exactly the number of internal properties inserted to enumerator
required
+ spare
All element accessors are host endian now (driven by TypedArray spec).
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
must "goto restart_execution", e.g. breakpoints changed
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
23: getUTCMilliseconds
no need to normalize
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
'this binding' is just under bottom
Default exports table
comment: XXX: macro smaller than call?
label: code-design
XXX: assert? compiler is responsible for this never happening
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
'require'
* Assertion helpers
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
19: getUTCMinutes
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
duk__get_min_grow_e() is always >= 1
* Reachable object, keep
'eval'
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
resolved id: require(id) must return this same module
We rely on a few object flag / class number relationships here,
* assert for them.
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
DUK_HEAP_H_INCLUDED
note: original, uncoerced base
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
DUK_OP_NONE marks a 'plain' assignment
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
Stack size decreases.
heap->strs: not worth dumping
-> [ ... closure template env funcname closure ]
step 12
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
comment: XXX: duk_ssize_t
label: code-design
DUK_ERR_UNCAUGHT_ERROR: no macros needed
-> [ ToObject(this) item1 ... itemN arr ]
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
* Debug dump type sizes
needed for line number tracking (becomes prev_token.start_line)
don't coerce yet to a plain value (variant 3 needs special handling)
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
Read value pushed on stack.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
'null' enumerator case -> behave as with an empty enumerator
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
Current compiler state (if any), used for augmenting SyntaxErrors.
push to stack
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'catch'
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
curr_pc synced back above
hash size approx. 1.25 times entries size
Write in little endian
source starts after dest ends
comment:
* Debugging macro calls.
label: code-design
DUK_USE_VERBOSE_ERRORS
0xxx xxxx -> fast path
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
unsigned shift
Not a very good provider: only full seconds are available.
110x xxxx 10xx xxxx [11 bits]
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
ensure value is 1 or 0 (not other non-zero)
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Indicate function type in the function body using a dummy
* directive.
'ObjEnv'
lj.value1 already set
millisec -> 100ns units since jan 1, 1970
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
DUK_TOK_SWITCH
class Object, extensible
idx_end
_Source
1 1 0 <8 bits>
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
minimum new length is highest_arr_idx + 1
DUK_TOK_RBRACKET
property is configurable and
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
Caller must ensure 'tv' is indeed a double and not a fastint!
Caller has already eaten the first character ('|') which we don't need.
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
structs from duk_forwdecl.h
assumed to also be PC of "LABEL"
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
'{"_undef":true}'
DUK_TOK_ADD_EQ
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
remove the original 'template' atom
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
* Heap native function representation.
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
'Invalid Date'
dynamic
comment:
* Node.js Buffer.concat()
label: code-design
comment: XXX: substring in-place at idx_place?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
embed: 0 or 1 (false or true)
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
string 2 of token (borrowed, stored to ctx->slot2_idx)
UNARY EXPRESSIONS
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
should actually never happen, but check anyway
input offset for window leading edge (not window[0])
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
continuation byte
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
ASCII fast path
Most input bytes go through here.
-> [ ... holder name val ]
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
useful for debugging
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
We should never exit the loop above.
may have FINALIZED
LAYOUT 3
comment: unused
label: code-design
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
'Int32Array'
an error handler (user callback to augment/replace error) is running
without refcounts
arbitrary marker, outside valid exp range
extra -1 for buffer
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
[ ...val ] -> [ ... ]
allow empty expression
[ ... closure template name ]
# total registers target function wants on entry (< 0 => "as is")
comment: unnecessary shift for last byte
label: code-design
varenv remains reachable through 'obj'
Special coercion for Uint8ClampedArray.
valstack slot for temp buffer
* Node.js Buffer: constructor
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
Nothing worked -> not equal.
E5 Section 11.13.1 (and others for other assignments), step 4.
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
String and buffer enumeration behavior is identical now,
* so use shared handler.
37x32 = 1184 bits
heap->dbg_detached_cb: keep
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
[ ... key ] -> [ ... ]
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
mark range 'direct', bypass canonicalization (see Wiki)
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
return module.exports
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
control props
push value to stack
* shift()
k+argCount-1; note that may be above 32-bit range
* Assert macro: failure causes panic.
comment: Similar workaround for INFINITY.
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
number
Must be element size multiple from
* start offset to end of buffer.
empty ("") is allowed in some formats (e.g. Number(''), as zero
slow path is shared
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
-> [ ... func ]
* Various defines and file specific helper macros
no net exponent
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
11 bits
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
get before side effects
DUK_HSTRING_H_INCLUDED
avoid empty label at the end of a compound statement
no specific action, resume normal execution
for manual torture testing: tight allocation, useful with valgrind
XXX: skip count_free w/o debug?
everything except object stay as is
identifiers and environment handling
back to fast loop
DUK_USE_JX || DUK_USE_JC
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
is resume, not a tail call
* Basic stack manipulation: swap, dup, insert, replace, etc
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
strings may have inner refs (extdata) in some cases
class masks
keep label catcher
state updated, restart bytecode execution
Flags for duk_js_equals_helper().
[ ... func this <some bound args> arg1 ... argN _Args ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
DUK_USE_TAILCALL
comment: should never be called
label: code-design
denormal
-> loop body
note: this updates refcounts
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
t1 <- (+ r m+)
denormal or zero
mark-and-sweep control
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
DUK_TOK_LET
Remove a slice from inside buffer.
valstack slot for 2nd token value
one-based -> zero-based
Set .buffer
terminate
max size: radix=2 + sign
remaining actual steps are carried out if standard DefineOwnProperty succeeds
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
'{"_func":true}'
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
E5 Section 15.5.5.2
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
avoid calling write callback in detach1()
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
-> [ Object res ]
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
IdentifierStart production with Letter and ASCII excluded
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
end switch
DUK_TOK_LE
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
[ ... v1(func) v2(pc+flags) ]
Matches both +0 and -0 on purpose.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
start line of token (first char)
10: getMonth
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
x <- y
eat 'var'
cannot have >4G captures
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
normalize NaN which may not match our canonical internal NaN
Recompute argument count: bound function handling may have shifted.
[ ... key val ] -> [ ... ]
minval
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
DUK_TOK_ARSHIFT_EQ
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
* Pass 1
Use unsigned arithmetic to optimize comparison.
type and control flags, label number
DUK_TOK_RSHIFT_EQ
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
[ ... enum_target res trap_result ]
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
Automatic filename: 'eval' or 'input'.
cumulative opcode execution count (overflows are OK)
Fast path for fastints
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
'input'
countdown state
switch
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Shared exit handling for object/array serialization.
input string scan
as elements
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
no need to unwind
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
Strict functions don't get their 'caller' updated.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
currently nop
[ ... closure template ]
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
'func' on stack (borrowed reference)
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
-> [... val this]
comment: code emission temporary
label: code-design
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
(quotient-remainder (* r B) s) using a dummy subtraction loop
Note: either pointer may be NULL (at entry), so don't assert
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
reuse last emitted atom for remaining 'infinite' quantifier
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
* Dragon4 slow path digit generation.
Rule control flags.
USE_PROP_HASH_PART
don't compact objects; needed during object property allocation resize
r <- (remainder (* r B) s)
[ ... error arr ]
String is an own (virtual) property of a lightfunc.
16: getHours
'debugger'
* String manipulation
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
DUK_USE_DEBUGGER_INSPECT
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
comment: Process debug messages until we are no longer paused.
label: code-design
* Entries part
[in_val in_val]
DUK_TOK_LBRACKET
36 bits
for zero size allocations NULL is allowed
-> [... obj key value]
* Some change(s) need to be made. Steps 7-11.
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
end of diff run
* Buffer
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
XXX: stringtable emergency compaction?
thr->ptr_curr_pc is set by bytecode executor early on entry
Allow leading plus sign
if slice not fully valid, treat as error
Now two entries in the same slot, alloc list
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
thr->heap->lj.value1 is already the value to throw
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
* Because buffer values are often looped over, a number fast path
* is important.
starting line number
x <- x - y, use t as temp
EQUALITY EXPRESSION
* Unicode support tables automatically generated during build.
return thread
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
0x08583b00
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
not a wordchar
XXX: a "first" flag would suffice
reg count
Buffer used for generated digits, values are in the range [0,B-1].
assume memset with zero size is OK
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
Parse a number, other than NaN or +/- Infinity
Must be a "string object", i.e. class "String"
no decref needed for a number
[ ... | (crud) ]
x <- y - z, require x >= y => z >= 0, i.e. y >= z
26 bits
Used to support single-byte stream lookahead.
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
-> [ ToObject(this) ]
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
'\Udeadbeef'
* every(), some(), forEach(), map(), filter()
Test without volatiles
Lexer codepoint with additional info like offset/line number
Low memory options
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
Note: either pointer may be NULL (at entry), so don't assert.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
tail call -> reuse current "frame"
refcount is unsigned, so always true
work list for objects to be finalized (by mark-and-sweep)
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
comment: still in use with verbose messages
label: code-design
stack is unbalanced, but: [ <something> buf ]
parse ranges until character class ends
Note: buffer is dynamic so that we can 'steal' the actual
* allocation later.
'delete'
comment: unused now, not needed until Turkish/Azeri
label: requirement
No platform-specific parsing, this is not an error.
mark finalizable as reachability roots
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
ToUint32() coercion required
'global'
not popped by side effect
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
Check array density and indicate whether or not the array part should be abandoned.
* Duktape.Buffer: toString(), valueOf()
descriptor type specific checks
DUK_USE_ERRTHROW
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
unary minus
ignore non-strings
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
move pivot to its final place
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
comment:
* Global state for working around missing variadic macros
label: code-design
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
tolerates NULL h_buf
forced_reg
DUK_TOK_PACKAGE
B -> target register
* C -> constant index of identifier name
no match, next case
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
NULL if tv_obj is primitive
lj value2: thread
Note: use 'curr' as a temp propdesc
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
* substring(), substr(), slice()
30: setHours
Expression, ']' terminates
* Number checkers
E5 Section 11.2.3, step 6.a.i
-> [ hobject props ]
XXX: shared handling for 'duk__expr_lhs'?
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
eat 'in'
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
zero-based month
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
expect_token
periods
idx of first argument on stack
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
check stack first
mod_id may be NULL
http://en.wikipedia.org/wiki/ANSI_escape_code
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
DUK_TOK_SET
* Lookup variable and update in-place if found.
'Int8Array'
Last component name in resolved path
Must match src/extract_chars.py, generate_match_table3().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Force pause if we were doing "step into" in another activation.
allow fmt==NULL
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
duk_hcompiledfunction flags; quite version specific
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Clamping needed if duk_int_t is 64 bits.
'id'
output bufwriter
-> x in [-2**31,2**31[
DUK_USE_SELF_TESTS
built-in strings
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Error throwing helpers
[ ... new_glob new_env new_glob new_glob ]
For lightfuncs, simply read the virtual property.
0x70-0x7f
stable
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
Duktape.Thread.resume()
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
nothing to NULL
use SameValue instead of non-strict equality
a value is left on stack regardless of rc
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
Note: this must match ToObject() behavior
'new' MemberExpression
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Report it to the debug client
no compact
restricted to regs
dummy so sp won't get updated
* Replace global object.
require a (mutable) temporary as a result (or a const if allowed)
contains value
'%s' and NULL is not portable, so special case
* it for debug printing.
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
Parse formals.
[... key arg1 ... argN func]
exit bytecode execution with return value
* Status message and helpers
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
DUK_SELFTEST_H_INCLUDED
Duktape object
0xb0-0xbf
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
[ ... res ]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
accessor with defined getter
comment: XXX: optimize for packed duk_tval directly?
label: code-design
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
allow source elements
one token before
'filename'
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
-> x in ]-2**32, 2**32[
no need to incref
Ecmascript function
embed: void ptr
Lightfuncs are always native functions and have "newenv".
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: XXX: cover this with the generic >1 case?
label: code-design
* Variant 1 or 3
'enumerable'
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
zero size not an issue: pointers are valid
fromPresent = true
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
assumes that allocated pointers and alloc funcs are valid
* if res exists
DUK_TOK_EQ
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
XXX: add 'language' argument when locale/language sensitive rule
* support added.
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
Infinity
comment: XXX: unoptimal use of temps, resetting
label: code-design
-> [ ... regexp string ] -> [ ... res_obj ]
token type (with reserved words as DUK_TOK_IDENTIFER)
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
# argument registers target function wants (< 0 => "as is")
'magic' constants for Murmurhash2
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
Object built-in methods
Skip fully.
switch (ch2)
type
* Allocate memory with garbage collection
* Main switch for statement / source element type.
Shared entry handling for object/array serialization.
overwrite sep
[ message error message ]
[ ... parent stash stash ] -> [ ... parent stash ]
Non-verbose errors for low memory targets: no file, line, or message.
DUK_BUFOBJ_ARRAYBUFFER
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
seconds, doesn't fit into 16 bits
unreferenced w/o tracebacks
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
must be updated to work properly (e.g. creation of 'arguments')
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
1:1 or special conversions, but not locale/context specific: script generated rules
roughly 0.5 kiB
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
DUK_TOK_WITH
0xa0-0xaf
* Table for base-64 decoding
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
[... buf]
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
Production allows 'DecimalDigits', including leading zeroes
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
[] -> []
key
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
-> [ array totalLength buf ]
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
is valid size
[ O Properties obj ]
extra coercion of strings is OK
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
FAIL
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
* Push result object and init its flags
number of continuation (non-initial) bytes in [0x80,0xbf]
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
comment: Note: we can reuse 'desc' here
label: code-design
empty statement with an explicit semicolon
* Constructor
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
* toString()
shuffle registers if large number of regs/consts
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
[ result ]
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
[ source ]
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
combines steps 2 and 5; -len ensures max() not needed for step 5
for register-bound and declarative env identifiers
bound functions are never in act 'func'
Lightfuncs cannot be bound.
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
Don't allow mixed padding and actual chars.
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
DUK_TOK_CONTINUE
unbalanced stack on purpose
arguments MUST have an initialized lexical environment reference
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
tags
regexp compiler should catch these
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
-> [ ... voidp true ]
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mp <- b^(e+1)
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
at most sizeof(buf) - 1
val
Old solution: don't iterate, incorrect
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
No BC shuffling now.
syntactically left-associative but parsed as right-associative
* Local result type for duk__get_identifier_reference() lookup.
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
' '
* Heap stringtable handling, string interning.
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Creation time error augmentation
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
check that byte has the form 10xx xxxx
* Memory constants
return 'res' (of right part) as our result
-> [ func funcname env ]
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
* Assertion helpers.
is_setget
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
replacer function
[ ... ]
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
+(function(){}) -> NaN
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
Reject attempt to change a read-only object.
final result is already in 'res'
21: getUTCSeconds
Eval is just a wrapper now.
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
22: getMilliseconds
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
combined algorithm matching E5 Sections 9.5 and 9.6
Evaluates to (duk_uint8_t *) pointing to start of area.
module.id = resolved_id
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
Maximum number of characters in formatted value.
Read fully.
* Prototypes
For indirect allocs.
always allow 'in', coerce to 'tr' just in case
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
Pointer object internal value is immutable
Leave 'value' on stack
prev char
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
'extends'
result: hash_prime(floor(1.2 * e_size))
bp is assumed to be even
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
If buffer has been exhausted, truncate bitstream
Can be called multiple times with no harm.
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
error
1:1 conversion
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
not LS/PS
invalid codepoint encoding or codepoint
comment: packed advance/token number macro used by multiple functions
label: code-design
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
DUK_TOK_BAND_EQ
remaining
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
Faster but value stack overruns are memory unsafe.
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
already in correct reg
the next 'if' is guaranteed to match after swap
Encoding state. Heap object references are all borrowed.
-> [ ... repl_value ]
no prototype
Note: 'q' is top-1
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
comment: XXX: incref by count (2) directly
label: code-design
')'
source is a function expression (used for Function constructor)
* Variant 2
Stored in duk_heaphdr h_extra16.
Note: intentionally signed.
'Date'
input linenumber at input_offset (not window[0]), init to 1
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
idx_value
[ ... this_new | arg1 ... argN ]
------XX XXXX----
* Get old and new length
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
38: getYear
initjs data is NUL terminated
this.raw(buffer)
return h_bufres
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
-> [ ... regexp_instance ]
Final result is at stack top.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
right exists, [[Put]] regardless whether or not left exists
* Return target object.
reuse 'res' as 'left'
st_used remains the same, DELETED is counted as used
is_join
binding power must be high enough to NOT allow comma expressions directly
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
_Formals
base of known return values
TimeClip(), which also handles Infinity -> NaN conversion
[ ... obj ]
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
flags used for property attributes in duk_propdesc and packed flags
directly uses slow accesses
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
add AC*2^32
result: updated refcount
Entry level info.
catch depth from current func
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
decoding
inline initializer for coercers[] is not allowed by old compilers like BCC
* Create normalized 'source' property (E5 Section 15.10.3).
variable access
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
comment: XXX: refactor out?
label: code-design
same for both error and each subclass like TypeError
[ ... res_obj re_obj input bc saved_buf ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
entire string is whitespace
'multiline'
'+'
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
'lineNumber'
refer to callstack entries below current
statement parsing
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
ignore retval -> [key]
%ld
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
syntax error
don't push value
'buffer'
inherit initial strictness from parent
module
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
not emergency
* Raw memory calls: relative to heap, but no GC interaction
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Evaluate RHS only when LHS is safe.
debugger detaching; used to avoid calling detach handler recursively
no catchers
* Variant 4
'package'
nothing now
* Reset trigger counter
* Preliminaries
count is already incremented, take into account
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
inline string concatenation
DUK_USE_JX && DUK_USE_JC
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
[key] (coerced)
comment: XXX: no optimized variants yet
label: requirement
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
'base64'
[ sep ToObject(this) len sep ]
comment:
* Various sanity checks for typing
label: code-design
Check whether statement list ends.
invalidates tv1, tv2
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
-> sets 'f' and 'e'
Check for maximum string length
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
accessor
set to 1 if any match exists (needed for empty input special case)
this should never be possible, because the switch-case is
* comprehensive
avoid double coercion
'DataView'
* Sweep stringtable
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
DUK_TOK_IN
jump to false
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
heapobj recursion depth when deep printing is selected
basic types
temp reset is not necessary after duk__parse_stmt(), which already does it
mark-and-sweep: reachable
Error object is augmented at its creation here.
DUK_USE_COMMONJS_MODULES
at least effective 'this'
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
DUK_USE_LIGHTFUNC_BUILTINS
some derived types
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
x == +Infinity
temp_start+0 = key, temp_start+1 = closure
E5.1 Section 15.1.3.2: empty
DUK_TOK_FINALLY
comment: Static call style.
label: code-design
'deleteProperty'
Compiling state of one function, eventually converted to duk_hcompiledfunction
to body
Coerce top into Object.prototype.toString() output.
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
actual update happens once write has been completed without
* error below.
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
Target object must be checked for a conflicting
* non-configurable property.
property exists, either 'desc' is empty, or all values
* match (SameValue)
[ func thisArg argArray ]
p overshoots
prefer direct
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
Must restart in all cases because we NULLed thr->ptr_curr_pc.
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
checked by Duktape.Thread.resume()
* Union aliasing, see misc/clang_aliasing.c.
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
eat closing quote
setup many variables in nc_ctx
comment: XXX: fast int-to-double
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
comment: XXX: shorter version for 12-byte representation?
label: code-design
a fresh require() with require.id = resolved target module id
Constructor
elision - flush
temp reg for key literal
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
[ ... bytecode escaped_source ]
[obj key desc value get set curr_value]
>>
msec
unary plus of a number is identity
equals and strict equals
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
tv points to element just below prev top
* Duktape/C function magic
* Identifier handling
error gets its 'name' from the prototype
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
E5 Sections 11.9.1, 11.9.3
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
current digit
* Extern
* Mark objects on finalize_list.
*
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
'valueOf'
XXX: potential issue with signed pointers, p_end < p.
* Helpers to resize properties allocation on specific needs.
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
shared object part
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
[ ... re_obj input ]
Backpointers.
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
bottom of new func
re_ctx->captures at the start of the atom parsed in this loop
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
refzero_list treated as reachability roots
* Memory calls.
+0.5 is handled by floor, this is on purpose
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
internal temporary value, used for char classes
comment: format is too large, abort
label: code-design
-> [ ... key val' ]
0x40-0x4f
MPUTOBJ emitted by outer loop
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
be_ctx->offset == length of encoded bitstream
'in'
Duktape.modLoaded[resolved_id] = module
Caller must ensure 'tv' is indeed a fastint!
stage 1 guarantees
typed for duk_unicode_decode_xutf8()
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
[ ... varname ]
preinitialize lexer state partially
comment: XXX: slightly awkward
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
require
rnd in [lo,hi]
must have catch and/or finally
V
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
DUK_TOK_BXOR
[ ... re_obj input bc saved_buf res_obj val ]
No arr_idx update or limit check
[... varname]
fresh require (argument)
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
String object internal value is immutable
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
highest capture number emitted so far (used as: ++captures)
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
[ ... name name ]
nargs
each call this helper serves has nargs==2
assertion disabled
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
* A C
* B A
* C <- sce ==> B
* D D
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
* Case conversion
* Helpers for dealing with the input string
const limits
0xc0-0xcf
The issues below can be solved with better flags
curr and desc are data
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
statement is guaranteed to be terminal (control doesn't flow to next statement)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
chain
[ ... closure ]
comment: Calling as a non-constructor is not meaningful.
label: code-design
* Voluntary periodic GC (if enabled)
Step types
'default'
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
E5 Section steps 7-8
result object is created and discarded; wasteful but saves code space
Gather in little endian
'fmt'
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
NUL terminate for convenient C access
'BYTES_PER_ELEMENT'
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* Node.js Buffer.prototype.fill()
* Exposed debug macros: debugging disabled
comment: No NUL term checks in this debug code.
label: code-design
DUK_BUFOBJ_FLOAT64ARRAY
embed: duk_hobject ptr
getters
DUK_TOK_DELETE
DUK_TOK_BOR
comment: pseudotypes, not used in actual longjmps
label: code-design
A -> target reg
* BC -> inner function index
refcount code is processing refzero list
[ ... retval ]; popped below
0x80...0x8f
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
entry_top + 1
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
* ToBoolean() (E5 Section 9.2)
* Shift to new valstack_bottom.
0 = don't push current value
"." is not accepted in any format
tmp -> res
[ body formals source ]
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
Other initial bytes.
Similar to String comparison.
Finally, blame the innermost callstack entry which has a
* .fileName property.
skip finalizers; queue finalizable objects to heap_allocated
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
fixed top level hashtable size (separate chaining)
not present
end marker
handle negative values
invalidated by pushes, so get out of the way
h is NULL for lightfunc
* Error throwing
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
comment: unused: not accepted in inbound messages
label: code-design
Reuse buffer as is unless buffer has grown large.
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
internal align target for props allocation, must be 2*n for some n
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
target
DUK__FLD_FLOAT
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> x in [0, 2**32[
rethrow original error
'\xffThis'
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
Check if any lookup above had a negative result.
DUK_USE_DEBUGGER_SUPPORT
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
DUK_TOK_SUB_EQ
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
Fixed header info.
nothing to finalize
throw flag irrelevant (false in std alg)
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
name
accept string if next char is NUL (otherwise reject)
* "WhiteSpace" production check.
value1 -> yield value, iserror -> error / normal
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
reachable so pop OK
may be NULL, too
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
* Heap creation and destruction
[ ... regexp_object escaped_source ]
now expected to fit into a 32-bit integer
Duktape.modSearch(resolved_id, fresh_require, exports, module).
bits 0...1: shift
Architecture, OS, and compiler strings
overflow
must fit into duk_small_int_t
'continue'
'value'
Non-critical.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
DUK_USE_DATE_NOW_GETTIMEOFDAY
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
E5 Sections 15.10.2.8, 7.3
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
Important to do a fastint check so that constants are
* properly read back as fastints.
remove artificial bump
important to use normalized NaN with 8-byte tagged types
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
crossed offsets or zero size
[ ... escaped_source bytecode ]
* E5 Section 11.4.8
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
* ToInteger() (E5 Section 9.4)
invalidates tv
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
num_stack_args
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
'\xffVarmap'
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Only allow Duktape.Buffer when support disabled.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
* Heap Buffer object representation. Used for all Buffer variants.
comment: Note: reuse variables
label: code-design
_Varmap
= 1 + arg count
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
'case'
num_pairs and temp_start reset at top of outer loop
Because size > 0, NULL check is correct
17: getUTCHours
[ ... enum ] -> [ ... next_key ]
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
* Finalize stack
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
no need for 'caller' post-check, because 'key' must be an array index
[ arg undefined ]
''
* String-to-number conversion
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
0x10...0x1f
Main operation
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
invalidated
DUK_USE_CPP_EXCEPTIONS
max(incl)
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
comment: XXX: use helper for size optimization
label: code-design
'ignoreCase'
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
frozen and sealed
tv -> value just before prev top value; must relookup
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
initial estimate for ASCII only codepoints
Parser separator masks.
just in case callback is broken and won't write 'x'
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
then to a register
retval to result[i]
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
expect EOF instead of }
resizing parameters
value from target
this is especially critical to avoid another write call in detach1()
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
return the argument object
new buffer of specified size
* Conversion helpers
%x; only 16 bits are guaranteed
mix-in value for computing string hashes; should be reasonably unpredictable
'debug'
keep default instance
Make buffer compact, matching current written size.
explicit semi follows
* Packed 8-byte representation
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
comment: XXX: awkward helpers
label: code-design
advance, expecting current token to be a specific token; parse next token in regexp context
stack prepped for func call: [ ... trap handler ]
'{"_nan":true}'
tagged null pointers should never occur
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
* Finally, longjmp
e.g. DUK_OP_POSTINCP
Allow leading minus sign
copy to buffer with spare to avoid Valgrind gripes from strptime
throw
4: toLocaleDateString
eat 'with'
[ ... this func ]
setters
step 4.c
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
comment: XXX: relocate
label: code-design
match fail
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
DUK_USE_DATE_TZO_GMTIME
Treat like debugger statement: nop
Get valstack index for the func argument or throw if insane stack.
comment: 'd3' is never NaN, so no need to normalize
label: code-design
XXX: push_uint_string / push_u32_string
return value from Duktape.Thread.resume()
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
end of loop (careful with len==0)
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
DUK_TOK_TRY
Optional UTC conversion.
6
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
* Self test main
prototype is lex_env before catcher created
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
tc1 = true, tc2 = false
no need to handle thread state book-keeping here
Not found. Empty string case is handled specially above.
4 low bits
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
[ ... enum ] -> [ ... ]
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
misc constants and helper macros
zero-based day
28: setMinutes
non-object base, no offending virtual property
Fixed seed value used with ROM strings.
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
E5 Sections 11.8.1, 11.8.5; x < y
may be < thr->catchstack initially
complex, multicharacter conversion
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
E5.1 Section 15.1.3.1: uriReserved + '#'
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
'"' was eaten by caller
expression is left-hand-side compatible
string is a reserved word (strict)
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
Step 9: copy elements-to-be-deleted into the result array
0x30-0x3f
2 bits for heap type
setjmp catchpoint setup
comment: not sure whether or not needed; Thursday
label: requirement
emergency mode: try extra hard
Set object 'length'.
byte index limit for element access, exclusive
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
[ ... eval "eval" eval_input level ]
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
!(p < r)
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
num_stack_args
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
complete 'sub atom'
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
round out to 8 bytes
for convenience
buffer limits
Handle TypedArray vs. Node.js Buffer arg differences
DUK_TOK_WHILE
offset/value order different from Node.js
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
* Detach actual buffer from dynamic buffer in valstack, and
* pop it from the stack.
*
* XXX: the buffer object is certainly not reachable at this point,
* so it would be nice to free it forcibly even with only
* mark-and-sweep enabled. Not a big issue though.
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
DUK_TOK_VOID
DUK_USE_PC2LINE
DUK_HOBJECT_FLAG_STRICT varies
[ ... errval errhandler ]
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
serialize the wrapper with empty string key
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
BITWISE EXPRESSIONS
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
Valstack resize flags
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
finish up pending jump and split for last alternative
nop
* Local declarations.
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
x > y --> y < x
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
resumee: [... initial_func] (currently actually: [initial_func])
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
proto can also be NULL here (allowed explicitly)
* split()
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
could also just pop?
Parser part indices.
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Local prototypes
low-level property functions
helpers for defineProperty() and defineProperties()
w/o refcounts
Skip dvalues to EOM.
all native functions have NEWENV
+1, right after inserted jump
only accept lowercase 'utf8' now.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: XXX: block removal API primitive
label: code-design
LOGICAL EXPRESSIONS
%lf, %ld etc
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
8: getFullYear
* Debug connection peek and flush primitives
'do'
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
exponential notation forced
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
Here we'd have the option to normalize -0 to +0.
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
default: false
comment: fill new_h with u32 0xff = UNUSED
label: code-design
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
if direct eval, calling activation must exist
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
Fast check for extending array: check whether or not a slow density check is required.
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
filename may be NULL in which case file/line is not recorded
unsigned
comment: XXX: function flag to make this automatic?
label: requirement
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Breakpoint entries above the used area are left as garbage.
allow_source_elem
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
fall through if overflow etc
inner function numbering
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
function needs shuffle registers
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
invalid padding
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
[ requested_id require require.id resolved_id last_comp ]
advance to get one step of lookup
Write signed 32-bit integer.
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
Needs lookahead
* Churn refzero_list until empty
Note: 'q_instr' is still used below
duk_unicode_caseconv_uc[]
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
failed, resize and try again
extend with undefined
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
Error; error value is in heap->lj.value1.
-> [ ... key val toJSON val key ]
callstack
read 3 bytes into 't', padded by zero
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
* Computed values (e.g. INFINITY)
DUK_TOK_DIV_EQ
already set
input 'd' in Windows UTC, 100ns units
Keep current size
50x heap size
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
[ name this ]
[ ... holder name val enum obj_key new_elem ]
patched later
[ ... regexp_object ]
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
This was the last term, and q_last was
* updated to match this term at loop top.
x <- b^y; use t1 and t2 as temps
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
ref.holder is global object, holder is the object with the
* conflicting property.
essentially tracks digit position of lowest 'f' digit
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
binding power "levels" (see doc/compiler.rst)
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
result reg
strings are only tracked by stringtable
to avoid relookups
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
':'
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
Slice starting point is beyond current length.
... target is extensible
duk_unicode_support.c
comment: XXX: easier check with less code?
label: code-design
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
x <- x * y, use t as temp
[ ... v1 v2 str ] -> [ ... str v2 ]
Zero 'count' is also allowed to make call sites easier.
comment: XXX: size optimize
label: code-design
!= 0 => post-update for array 'length' (used when key is an array index)
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
false
* Built-in strings
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
* Variant 3
* On second pass, skip the function.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
-> [ ... key val toJSON val ]
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
[ obj trap_result res_arr propname ]
split1: prefer direct execution (no jump)
in resumer's context
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
'try'
-> [in_val]
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
Note: 0xff != DUK_BC_B_MAX
* Unions and structs for self tests
Note: masking is done for 'i' to deal with negative numbers correctly
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
don't run finalizers; queue finalizable objects back to heap_allocated
val1 = count
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Get minimum array part growth for a certain size.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
'enumerate'
DUK_TOK_RSHIFT
roughly 256 bytes
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
object is now reachable
flags: "im"
Copy trap result keys into the enumerator object.
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
Success path.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
t1 <- (* r B)
DUK_BUFOBJ_UINT8ARRAY
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
assertions: env must be closed in the same thread as where it runs
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
refzero not running -> must be empty
comment: XXX: differentiate null pointer from empty string?
label: code-design
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
DUK_USE_MARK_AND_SWEEP
* Coercion and fast path processing
y == +Infinity
caller required to know
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
'toLocaleString'
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
buffer is automatically zeroed
num_args
DUK_OP_EXTRA, sub-operation in A
insert the required matches (qmin) by copying the atom
DUK_USE_INTEGER_BE
out_clamped
adv = 2 default OK
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
'-0'
module table remains registered to modLoaded, minimize its size
* Detach handling
write back
[ ... filename (temps) func ]
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
* Second pass parsing.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
DUK_USE_EXEC_TIMEOUT_CHECK
* Misc defines
E5.1 Section 15.1.3.4: uriUnescaped
Combined size of separators already overflows
-> [ ... res ]
[ ... this name message ]
"/" and not in regexp mode
DUK_USE_BYTECODE_DUMP_SUPPORT
comment: may indirectly slow access through a direct eval
label: code-design
no incref needed
variable binding register if register-bound (otherwise < 0)
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
[ ... varname val this ] (because throw_flag == 1, always resolved)
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
embed: duk_hbuffer ptr
t >= 0 always true, unsigned
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
vararg function, careful arg handling (e.g. thisArg may not be present)
implicit this value always undefined for
* declarative environment records.
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
duk_unicode_ids_noabmp[]
Return value of 'sz' or more indicates output was (potentially)
* truncated.
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
Encoding/decoding flags
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
no need to write 'out_bufdata'
new_used / size <= 1 / DIV <=> new_used <= size / DIV
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
label handling
Expression
comment: This is performance critical because it appears in every DECREF.
label: code-design
code_idx = entry_top + 0
-> [ ... lval rval ]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
eat 'throw'
always grow the array, no sparse / abandon support here
leave formals on stack for later use
since index non-negative
tzoffset
duk_has_prop() popped the second 'name'
varname
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
-------- ----XXXX
stack top: new time value, return 1 to allow tail calls
basereg
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
jump for 'catch' case
Module object containing module.exports, etc
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
-> [ ... escaped_source bytecode ]
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
5: toLocaleTimeString
mark-and-sweep: children not processed
Catches EOF of JSON input.
radix
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
no wrapping
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
object or array
no need to check now: both success and error are OK
Note: allow backtracking from p == ptr_end
Relookup if relocated
module.filename for .fileName, default to resolved ID if
* not present.
-> [ ... toLocaleString ToObject(val) ]
DUK_TOK_LBRACKET already eaten, current token is right after that
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
Restore stack top after unbalanced code paths.
position of highest digit changed
* duk_heap allocation and freeing.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
no statement value (unlike function expression)
Three digit octal escape, digits validated.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Quite approximate but should be useful for little and big endian.
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
retval for success path
* Wrapping duk_safe_call() will mangle the stack, just return stack top
* Node.js Buffer.prototype: toJSON()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
'fileName'
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
parse args starting from "next temp"
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
* Mark-and-sweep garbage collection.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
comment: unnecessary div for last byte
label: code-design
buffer values are coerced first to string here
sanity limit for function pointer size
[ sep ToObject(this) len sep str0 ... str(count-1) ]
DUK_TOK_YIELD
comment: XXX: is valstack top best place for argument?
label: code-design
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
duk_hobject_run_finalizer() sets
[ source template closure ]
Successful return: restore jmpbuf and return to caller.
negative -> no atom matched on previous round
[ ... name ]
Note: may be NULL if first call
unresolvable, no stack changes
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
DUK_USE_DATE_NOW_TIME
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
* Reference counting implementation.
use strict equality instead of non-strict equality
This assert depends on the input parts representing time inside
* the Ecmascript range.
controls for minimum array part growth
-> [ ... key ]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
allow basic ASCII whitespace
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
activation is a direct eval call
current lex_env of the activation (created for catcher)
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
start byte offset of token in lexer input
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
curr_token = get/set name
Initial '[' has been checked and eaten by caller.
Thread may have changed, e.g. YIELD converted to THROW.
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
be paranoid for 32-bit time values (even avoiding negative ones)
* Node.js Buffer.byteLength()
emit instruction; could return PC but that's not needed in the majority
* of cases.
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
All the flags fit in 16 bits, so will fit into duk_bool_t.
flags: "g"
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
end of _Varmap
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
[-0x80000000,0x7fffffff]
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
'Arguments'
[key getter this] -> [key retval]
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
only functions can have arguments
E5 Section 9.3.1
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
0xd0...0xdf
tv1 is -below- valstack_bottom
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
[ obj Properties ]
* First attempt
not found
Loop check.
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
reserved words: additional future reserved words in strict mode
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
Sync and NULL early.
12 to 21
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
-> pushes fixed buffer
comment: XXX: improve check; check against nregs, not against top
label: code-design
byte sizes will match
max # of values initialized in one MPUTARR set
not reached
-> [ ... this ]
* Local defines and forward declarations.
comment: prev value must be unused, no decref
label: code-design
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
x >= y --> not (x < y)
yes, must set array length explicitly
* Post resize assertions.
Note: for dstlen=0, dst may be NULL
!DUK_USE_TRACEBACKS
-> [ func funcname env funcname ]
Constants for duk_lexer_ctx.buf.
Difference is in 100ns units, convert to milliseconds w/o fractions
* "IdentifierPart" production check.
prev exists and is not a letter
Note: no recursion issue, we can trust 'map' to behave
if fails, e_size will be zero = not an issue, except performance-wise
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment: workaround: max nbits = 24 now
label: code-design
DUK_USE_HEX_FASTPATH
DUK_UTIL_H_INCLUDED
'Infinity'
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
debugger state, only relevant when attached
highest value of temp_reg (temp_max - 1 is highest used reg)
* Init compiler and lexer contexts
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
pre/post opcode values have constraints,
allocated heap objects
re-read to avoid spill / fetch
LRU: move our entry to first
argument/function declaration shadows 'arguments'
Proxy target
unconditional block
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
* Node.js Buffer.prototype.copy()
DUK_VERBOSE_ERRORS
skip '|'
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
'byteLength'
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
* Detect iteration statements; if encountered, establish an
* empty label.
skip ')'
* Poppers
DUK_HOBJECT_H_INCLUDED
always at least the header
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Fast path, decode as is.
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
'break'
in yielder's context
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
non-leap year: sunday, monday, ...
activation has tail called one or more times
extended types: custom encoding
reg
-> [... enum key val]
EOF
XXX: optimize value stack operation
* Proxy object handling
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
mark as complex (capture handling)
string is a reserved word (non-strict)
s <- b^(1-e) * 2
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Map DUK__FLX_xxx to byte size.
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
* Get/require
key, getter and setter, now reachable through object
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
'Array'
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
extended utf-8 not allowed for URIs
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
bytecode limits
guaranteed to find an empty slot
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Allow trailing garbage (e.g. treat "123foo" as "123)
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
steps 3.h and 3.i
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
module (argument)
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
current paren level allows 'in' token
comment: XXX: fast-int-to-double
label: code-design
* ArrayBuffer.isView()
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
* Debugging enabled
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: XXX: duk_set_length
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
XXXXXX-- --------
* Bitstream decoder.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
retval (sub-atom char length) unused, tainted as complex above
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
should not happen
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
DUK_TOK_REGEXP
* Peephole optimize JUMP chains.
* Execution timeout check
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
type to represent a reg/const reference during compilation
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
DUK_TOK_PUBLIC
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
'get'
comment: function name (borrowed reference), ends up in _name
label: code-design
repl_value
quotes
'undefined' already on stack top
'res' is used for "left", and 'tmp' for "right"
def_value
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
comment: XXX: skip null filename?
label: code-design
avoid multiply
New require() function for module, updated resolution base
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
"-Infinity", '-' has been eaten
make absolute
'act' already set above
DUK_BUFOBJ_UINT8CLAMPEDARRAY
comment: XXX: turkish / azeri, lowercase rules
label: code-design
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
no comma
strict outer context
jump for 'finally' case or end (if no finally)
* Structs
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
from next pc
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
use 'left' as a temp
JSON
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
* Pointer built-ins
Zero length string is not accepted without quotes
[ key ] -> []
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
current function being compiled (embedded instead of pointer for more compact access)
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
Note: 'this' may be bound to any value, not just an object
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
out of spec, don't care
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
used by e.g. duk_regexp_executor.c, string built-ins
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Share yield longjmp handler.
curr_token slot2 (matches 'lex' slot2_idx)
Error message doesn't matter: the error is ignored anyway.
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment: actually used
label: code-design
rule match
* Helper structs
terminating conditions
see below
allow automatic semicolon even without lineterm (compatibility)
Outside any activation -> put to global.
+0 = break, +1 = continue
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
-> [ val arr ]
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
this is needed for regexp mode
jump to next case clause
pop plain buffer, now reachable through h_bufres
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
add AD*2^16
Proxy handler
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
relookup exports from module.exports in case it was changed by modSearch
* Indexed read/write helpers (also used from outside this file)
adv = 2 - 1 default OK
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
comment: XXX: side effect handling is quite awkward here
label: code-design
act->func
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Call setup checks callability.
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
DUK_BUFOBJ_UINT32ARRAY
* Restore 'caller' property for non-strict callee functions.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
0x60...0x6f
>= 0
mimic semantics for strings
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
DUK__FLD_8BIT
[key]
normal key/value
mm <- b^e
steps 4.a and 4.b are tricky
The external string struct is defined even when the feature is inactive.
fixed arg count
A -> flags
* B -> return value reg/const
* C -> currently unused
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
-> [ ... closure template newobj ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
* Size-optimized pc->line mapping.
return as is
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
function: create binding for func name (function templates only, used for named function expressions)
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
comment: XXX: copy from caller?
label: code-design
always for register bindings
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
heap->dbg_udata: keep
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
dummy value used as marker
never here, but fall through
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
must never longjmp
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
stack top contains 'true'
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
'\xffHandler'
Note: string is a terminal heap object, so no depth check here
0x80-0x8f
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
Debug print which visualizes the qsort partitioning process.
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
r <- (2 * f) * b^e
unreferenced with some options
always terminates led()
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
awkward; we assume there is space for this
Peek ahead in the stream one byte.
* Breakpoint management
* Compact an object
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
alias for above
handle comma and closing brace
shrink case; leave some spare
strictness is not inherited, intentional
only Array.prototype matches
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
This seems reasonable overall.
Loop prevention
'throw'
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
Assume that the native representation never contains a closing
* parenthesis.
varargs marker
entry level reached
Current strictness flag: affects API calls.
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
'*'
call is from executor, so we know we have a jmpbuf
Yield/resume book-keeping.
finally part will catch
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
Load inner functions to value stack, but don't yet copy to buffer.
[ start end ]
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
DUK_TOK_THROW
comment: Note: not a typo, "object" is returned for a null value
label: documentation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
Original idiom used, minimal code size.
comment: 'fun' is quite rarely used, so no local for it
label: code-design
comment: XXX: fastint
label: code-design
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
normal
Careful with wrapping (left shifting idx would be unsafe).
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
"+11:22\0"
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
caller
match followed by capture(s)
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
'ptr' is evaluated both as LHS and RHS.
* Ecmascript [[Class]]
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
finalize_list will always be processed completely
comment: XXX: exposed duk_debug_read_pointer
label: code-design
-> [ ... key val replacer holder ]
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
open scope information, for compiled functions only
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
temp reg handling
* Parse function body
x <- y - z
'Pointer'
relookup if changed
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
throw_flag
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
break/continue without label
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
non-global regexp: lastIndex never updated on match
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
exposed because lexer needs these too
empty match (may happen with empty separator) -> bump and continue
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
Set up curr_pc for opcode dispatch.
[ ... pattern flags escaped_source ]
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
Get minimum entry part growth for a certain size.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
thr->heap->lj.value2 is 'thread', will be wiped out at the end
break/continue with label (label cannot be a reserved word, production is 'Identifier'
property access
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
internal property functions
Report thrown value to client coerced to string
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
DUK_USE_USER_INITJS
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
110x xxxx 10xx xxxx
Sanity limits for stack sizes.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
No net refcount change.
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
result array is already at the top of stack
args go here as a comma expression in parens
[ ... source? filename? &comp_args ] (depends on flags)
no extra padding
Start position (inclusive) and end position (exclusive)
tentative, checked later
slot A is a source (default: target)
indexed by recursion_depth
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
Order of unwinding is important
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
tracks maximum initialized index + 1
comment: first register that is a temporary (below: variables)
label: code-design
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
Just skip, leaving zeroes in the result.
[ ... arr ]
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
bytes in source
no voluntary gc
A -> result reg
* B -> object reg
* C -> key reg/const
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
refcount
regexp res_obj is at index 4
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
']'
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
-> [ func funcname env funcname func ]
true, because v[1] has at least one bit set
bp to use when parsing a top level Expression
Caller will finish the marking process if we hit a recursion limit.
y
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
TypeError if fails
* Entries part
* Delayed env creation check
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
guarantees entry_callstack_top - 1 >= 0
no code needs to be emitted, the regs already have values
magic: 0=getter call, 1=Object.getPrototypeOf
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
* Debug connection write primitives
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
module.name for .name, default to last component if
* not present.
* Exposed debug macros: debugging enabled
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
0xe0-0xef
compact the prototype
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
read header
prop index in 'hash part', < 0 if not there
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
object is a native function (duk_hnativefunction)
[ ... error func fileName lineNumber ]
21 bits
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
embed: duk_hstring ptr
enumeration
* Free memory
Maximum value check ensures 'nbytes' won't wrap below.
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
currently, even for Array.prototype
unsigned intentionally
DUK_TOK_SNEQ
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
No need to assert, buffer size maximum is 0xffff.
default is explicit index read/write copy
not enumerable
* Exposed data
avoid problems if p == h->prototype
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
Output shuffle needed after main operation
For native calls must be NULL so we don't sync back
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
omitted
'toGMTString'
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
* ISO 8601 subset parser.
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
[res]
dash is already 0
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
keep val_highest
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
can't get value, may be accessor
Relookup and initialize dispatch loop variables. Debugger check.
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
leave result on stack top
Resolved, normalized absolute module ID
marker; not actual tagged value
re-lookup curr char on first round
[ ... formals arguments map mappedNames ]
borrowed: full duk_tval for function being executed; for lightfuncs
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
Skip dvalue.
comment: XXX: inefficient; block remove primitive
label: code-design
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
[ ... pattern flags ]
custom; implies DUK_HOBJECT_IS_THREAD
[ thisArg arg1 ... argN ]
for array and object literals
validation of the regexp is caller's responsibility
regnum is sane
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
Preinc/predec for var-by-name, slow path.
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
Small variant; roughly 150 bytes smaller than the fast variant.
-> [ ... closure template env funcname ]
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
_Pc2line
Sanity checks for string and token defines
number of escapes and line continuations (for directive prologue)
MakeTime
comment: XXX: this is possible without resorting to the value stack
label: code-design
ignored
NULL for lightfunc
lookup shorthands (note: assume context variable is named 'lex_ctx')
Other callbacks are optional.
truncated in case pass 3 needed
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
Leave 'getter' on stack
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
Q...f
x < y
set exotic behavior only after we're done
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Current size is about 152 bytes.
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
while repl
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
Setup state. Initial ivalue is 'undefined'.
'object'
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
1 1 1 <32 bits>
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
patch in range count later
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
0: toString
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
lowest mantissa for this exponent
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
all we need to know
ASSIGNMENT EXPRESSION
IdentityEscape
Must decrease recursion depth before returning.
note: mixing len into seed improves hashing when skipping
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
Return with final function pushed on stack top.
Note: 'e' and 'E' are also accepted here.
'%c', passed concretely as int
thread resumed another thread (active but not running)
or a non-catching entry
next char
-> [... key val]
add F
comment: return a specific NaN (although not strictly necessary)
label: code-design
* Variant 1
global regexp: lastIndex updated on match
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
Current size (not counting a dynamic buffer's "spare").
+2 = catcher value, catcher lj_type
parsing in "directive prologue", recognize directives
non-strict: non-deletable, writable
DUK_USE_64BIT_OPS
simulate alloc failure on every realloc (except when mark-and-sweep is running)
7
comment: alloc temp just in case, to update max temp
label: code-design
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
exposed, used by e.g. duk_bi_date.c
* Parsing of ints and floats
flags: "gi"
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
* Return target object
side effects
[ ... result ]
only objects have finalizers
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
* Thread support.
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
temp copy, write back for next loop
char loop
basic platform types
we currently assume virtual properties are not configurable (as none of them are)
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
address
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
may be NULL
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
IEEE double is approximately 16 decimal digits; print a couple extra
* Resizing and hash behavior
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
[obj key undefined]
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* isArray()
DUK_USE_HOBJECT_HASH_PART
trailing elisions?
* Simple commands
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
[ ... global val ] -> [ ... global ]
length in codepoints (must be E5 compatible)
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
Decode helper. Return zero on error.
XXX: specify array size, as we know it
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
1111 0xxx; 4 bytes
start array index of current MPUTARR set
cp == -1 (EOF) never matches and causes return value 0
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
DUK_OP_CALL flags in A
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
Must be >= 0 and multiple of element size.
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
note that we can't reliably pop anything here
[... put_value]
5
ref.value and ref.this_binding invalidated here
nret
object is a compiled function (duk_hcompiledfunction)
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
Need a short reg/const, does not have to be a mutable temp.
delete Duktape.modLoaded[resolved_id]
keep current valstack_top
Disabled until fixed, see above.
'message'
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
0x70...0x7f
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
comment: XXX: depend on available temps?
label: code-design
default case
%u; only 16 bits are guaranteed
MultiplicativeExpression
Trim white space (= allow leading and trailing whitespace)
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
does not modify tv_x
26: setSeconds
patch pending jump and split
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
only needed by debugger for now
Compute day number of the first day of a given year.
ignore_loop
* Begin
Output #1: resolved absolute name
and even number
* DELPROP: Ecmascript property deletion.
normal: implicit leading 1-bit
may throw an error
* Encoding constants, must match genbuiltins.py
'RegExp'
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
<<
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
ensure full memcmp() fits in while
unreachable
push operation normalizes NaNs
getter/setter
x == 0x00 (EOF) causes syntax_error
XXX: range assert
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
flags: "i"
* Init stringtable: probe variant
Catches both doubles and cases where only one argument is a fastint
key coercion (unless already coerced above)
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Limit checks for bytecode byte size and line number.
The necessary #includes are in place in duk_config.h.
comment: XXX: this could be optimized
label: code-design
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
comment: Silence a few global unused warnings here.
label: code-design
-> [... arr num]
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
thread has yielded
Lightfuncs are always strict.
'\xffArgs'
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
Further state-dependent pre-checks
E5 Section 8.12.8
is_decl
at least one activation, ours
s <- b^(-e) * 2
use p_src_base from now on
'taint' result as complex
no issues with memcmp() zero size, even if broken
* Disjunction struct: result of parsing a disjunction
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
Previous entry was inside visited[], nothing to do.
comment: XXX: optimize temp reg use
label: code-design
toFixed()
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
duk_unicode_idp_m_ids_noabmp[]
'(?:)'
* Process replacer/proplist (2nd argument to JSON.stringify)
may be a string constant
return total chars written excluding terminator
[ (builtin objects) name ]
new_free / size <= 1 / DIV <=> new_free <= size / DIV
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
[ ... holder name val enum obj_key ]
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
exit() afterwards to satisfy "noreturn"
string compare is the default (a bit oddly)
'%xx%xx...%xx', p points to char after first '%'
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
2^4 -> 1/16 = 6.25% spare
* reduce(), reduceRight()
* Macros for accessing size fields
* Resolve module identifier into canonical absolute form.
leap year: sunday, monday, ...
even after a detach and possible reattach
tval
comment: integer mixed endian not really used now
label: code-design
only advance if not tainted
tail insert: don't disturb head in case refzero is running
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
0.000...
leave stack unbalanced on purpose
[ ... func this <bound args> arg1 ... argN ]
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Table for hex encoding bytes
[ ... buf func ] -> [ ... func ]
build result as: (r << 32) + s: start with (BD + E + F)
We only get here when doing non-standard JSON encoding
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
[target] -> [enum]
Handle both full and partial slice (as long as covered).
envrec: (declarative) record is closed
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
XXX: bump preventcount by one for the duration of this call?
for
15: getUTCDay
need_bytes may be zero
register binding lookup is based on varmap (even in first pass)
prototype: the only internal property lifted outside 'e' as it is so central
3 entries actually needed below
end of input and last char has been processed
[ start length str ]
array
fast paths for space and tab
Significand ('f') padding.
comment: not needed
label: requirement
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
add a new pending match jump for latest finished alternative
exclusive
DUK_USE_BUILTIN_INITJS
* If selftests enabled, run them as early as possible
ivalue/ispec helpers
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
idx_this = idx_func + 1
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
not needed, as we exit right away
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
relookup, may have changed
leading digit + fractions
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
tc1 = true, tc2 = true
See comments below on MakeTime why these are volatile.
-> [ val obj val ]
Store lexer position, restoring if quantifier is invalid.
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
marker; not actual tagged type
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
For NaN/inf, the return value doesn't matter.
curr char
[ regexp string ]
comment: NULL not needed here
label: code-design
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
overflow, more than 32 bits -> not an array index
special result value handling
[ ... Logger clog res ]
[... put_value varname]
intermediate join to avoid valstack overflow
ptr before mark-and-sweep
end-of-input breaks
reserve a jumpslot after instr before target spilling, used for NEXTENUM
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
* Variable access
comment: function: function must not be tail called
label: code-design
third arg: absolute index (to entire valstack) of idx_bottom of new activation
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
!DUK_USE_HSTRING_CLEN
DUK_ERR_EVAL: no macros needed
DUK_USE_PREFER_SIZE
Incref copies, keep originals.
object is a buffer object (duk_hbufferobject) (always exotic)
recheck that the property still exists
jump from true part to end
comment: XXX: fastint fast path would be very useful here
label: code-design
XXX: happens e.g. when evaluating: String(Buffer.prototype).
'name'
eat identifier
* Init stringtable: fixed variant
Copy values through direct validated reads and writes.
break matches always
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
-1 for opcode
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
comment: hash part size or 0 if unused
label: code-design
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
helper to insert a (non-string) heap object into heap allocated list
* Internal API calls which have (stack and other) semantics similar
* to the public API.
retval is directly usable
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
digit count
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
2^3 -> 1/8 = 12.5% min growth
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
'hex'
borrowed label name
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
Longjmp state is kept clean in success path
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
comment: XXX: faster internal way to get this
label: code-design
old value is number: no refcount
Using classification has smaller footprint than direct comparison.
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
leading byte of match string
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
canonicalized by compiler
[ source template closure this ]
initial index
5 heap flags
DUK_TOK_FUNCTION
exponent for 'f'
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
always 1 arg
helpers
ignore result
DUK_JMPBUF_H_INCLUDED
'static'
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
extended types: compatible encoding
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
valstack limit caller has check, prevents wrapping
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
Note: number has no explicit tag (in 8-byte representation)
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
reg/const for case value
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
signed integer encoding needed to work with UTF-8
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
'&'
jump is inserted here (variant 3)
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
resumee: [... initial_func undefined(= this) resume_value ]
ignore reclimit, not constructor
'\xffCallee'
is normalized
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
Coerce like boolean
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
[ (builtin objects) ]
comment: XXX: tv_func is not actually needed
label: requirement
* Source filename (or equivalent), for identifying thrown errors.
'__proto__'
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
parent env is the prototype
get varenv for varname (callee's declarative lexical environment)
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
Note: can be safely scanned as bytes (undecoded)
========================================================================
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
also goes into flags
UnaryExpression
comment: XXX: return something more useful, so that caller can throw?
label: code-design
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
all virtual properties are non-configurable and non-writable
[ obj trap_result res_arr ]
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
depth check is done when printing an actual type
Preinc/predec for object properties.
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
init function state: inits valstack allocations
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK_USE_PARANOID_ERRORS
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Without ROM objects "needs refcount update" == is heap allocated.
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
side effects -> don't use tv_x, tv_y after
[... enum]
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
DUK_TOK_LT
no value
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
hash probe sequence
* Make the C call
DUK_USE_NONSTD_FUNC_STMT
has access to 'this' binding
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
initial size guess
Buffer writes are often integers.
env[funcname] = closure
Safe to call multiple times.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
formatted result limited
[] -> [res]
may be NaN
'undefined', artifact of lookup
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
lj value1: value
pushes function template
Identifier, i.e. don't allow reserved words
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
[ arg toLogString ]
out_token->lineterm set by caller
note: any entries above the catchstack top are garbage and not zeroed
Error code also packs a tracedata related flag.
enumerator must have no keys deleted
Stack size increases or stays the same.
known to be number; in fact an integer
avail_bytes += need_bytes
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
temp variable to pass constants and flags to shared code
char length of the atom parsed in this loop
-> [ ... fn x y ]
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
-> [...]
topmost activation idx_retval is considered garbage, no need to init
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
ref.value, ref.this.binding invalidated here by getprop call
* Field accessor macros
[ ... buf ]
idx_base and idx_base+1 get completion value and type
integer number in range
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
check stack before interning (avoid hanging temp)
The extra (+4) is tight.
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
DUK_TOK_STATIC
No pointer compression because pointer is potentially outside of
* Duktape heap.
'null'
pc2line
always normalized
JUMP L1 omitted
comment: writable, not configurable
label: code-design
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
big endian
entry_top + 3
must match bytecode defines now; build autogenerate?
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
'.'
* Automatically generated by genbuiltins.py, do not edit!
* Debug connection read primitives
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: XXX: optimize with more direct internal access
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
0x00-0x0f
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
DUK_TOK_BOR_EQ
Argument must be a string, e.g. a buffer is not allowed.
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
number of formal arguments
register, constant, or value
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
h_code: held in bw_code
* Forward declarations.
heap pointer comparison suffices
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
Backtrack.
comment: XXX: code duplication
label: code-design
arg count
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
[ ... number ] -> [ ... string ]
'data' (and everything in it) is reachable through h_res now
Fast path.
called as a normal function: return new Date().toString()
------XX
must be computed after realloc
'join'
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
re-lookup first char on first loop
[ ... buf loop (proplist) ]
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
DUK_USE_DATE_FMT_STRFTIME
eat the right paren
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
-1 if disjunction is complex, char length if simple
noblame_fileline
Backtrack to previous slash or start of buffer.
func limits
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
For anything other than an Error instance, we calculate the error
* location directly from the current activation.
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
comment: code_idx: not needed
label: requirement
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
load factor min 25%
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
Assume interrupt init/counter are properly initialized here.
* Parse a case or default clause.
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
maxval
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
* Bitstream encoder
-> [ sep ToObject(this) len str sep ]
Decrement PC if that was requested, this requires a PC sync.
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
no side effects
INACTIVE: no activation, single function value on valstack
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
this cannot initiate a detach
done so that duk__mark_heaphdr() works correctly
if highest bit of a register number is set, it refers to a constant instead
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
byte offset to buf
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
comment: unused now
label: code-design
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
still in prologue
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
fixed-format termination conditions
DUK_TOK_ELSE
* Add line number to a compiler error.
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
Ensure copy is covered by underlying buffers.
longjmp state
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
Expression, terminates at a ')'
can't happen when keeping current stack size
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
Miscellaneous.
-> [ ... retval ]
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
-> [ timeval this ]
comment: Clean up stack
label: code-design
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
unwind to 'yield' caller
How much stack to require on entry to object/array decode
(e.g. k=3, digits=2 -> "12X")
Note: changing from writable to non-writable is OK
unwinds valstack, updating refcounts
For JX, expressing the whole unsigned 32-bit range matters.
r <- 2 * f
currently active breakpoints: NULL term, borrowed pointers
conversions, coercions, comparison, etc
[key val] -> [key]
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
* Misc support functions
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
array of formal argument names (-> _Formals)
[ ... func this arg1 ... argN ]
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
key encountered as a getter
comment: XXX: typing
label: code-design
catches EOF (NUL)
'act' is no longer accessed, scanbuild fix
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
[ ... RegExp ]
DUK_TOK_DECREMENT
[ ... errhandler undefined errval ]
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
no wrap assuming h_bufobj->length is valid
Nominal size check.
register bound variables are non-configurable -> always false
-> [ obj trap handler target ]
reasonable output estimate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
* Character and charcode access
nargs == 2 so we can pass a callstack level to eval().
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
normal valued properties
'\xffLexenv'
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
variable map for pass 2 (identifier -> register number or null (unmapped))
buffer pointer is to an externally allocated buffer
'Uint32Array'
'with'
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
callstack index of related activation
non-standard
may be safe, or non-safe depending on flags
activation prevents yield (native call or "new")
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
DUK__FLD_VARINT; not relevant here
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
eat 'try'
1110 xxxx 10xx xxxx 10xx xxxx
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Expects 'this' at top of stack on entry.
The token in the switch has already been eaten here
currently all labels accept a break, so no explicit check for it now
[ arg result ]
got lineterm preceding non-whitespace, non-lineterm token
intentional overlap with earlier memzero
Allow exponent
'\xffSource'
read-only object, in code section
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Shared object part.
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
DUK_OP_RETURN flags in A
DUK_TOK_ADD
allocate to reg only (not const)
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
requested number of output digits; 0 = free-format
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
DUK_TOK_EOF
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
XXX: duk_dup_unvalidated(ctx, -2) etc.
fill new entries with -unused- (required, gc reachable)
-> [ O toString O ]
accept anything, expect first value (EOF will be
* caught by key parsing below.
unknown, ignore
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
[ ... v1 v2 name filename ]
!DUK_USE_PANIC_HANDLER
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
expected ival
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
no sce, or sce scan not best
caller must have decref'd values above new_a_size (if that is necessary)
[ ... buf loop (proplist) (gap) ]
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
checked by caller
'Int16Array'
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
thread; minimizes argument passing
step 4.d
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
one operator (= assign)
no need to init reg, it will be undefined on entry
string objects must not created without internal value
eat backslash on entry
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
comment: XXX: Rework to use an always-inline function?
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
We're a varargs function because we need to detect whether
* initialValue was given or not.
cannot be strict (never mapped variables)
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
DUK_DEBUGGER_H_INCLUDED
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
0 if no used entries
* Basic double / byte union memory layout.
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
if new_p == NULL, all of these pointers are NULL
-> [... obj retval/error]
[ ... holder key ] -> [ ... holder ]
'this' binding is just before current activation's bottom
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
a
Allow leading zeroes (e.g. "0123" -> "123")
* Default clause.
d <- (quotient (* r B) s) (in range 0...B-1)
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Commands initiated by debug client.
next loop requires a comma
0x40...0x4f
'string'
match == search string, by definition
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
32-bit x 11-bit = 43-bit, fits accurately into a double
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
eat closing brace
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
without finally, the second jump slot is used to jump to end of stmt
slot B is a target (default: source)
fastint constants etc
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
Duktape.modLoaded
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
comment: XXX: call method tail call?
label: code-design
w.../
always provideThis=true
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
* Thread state and calling context checks
token type (with reserved word identification)
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
verified at beginning
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
XXX: duk_push_uint_string()
Built-in providers
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
pop final_cons
comment: When ptr == NULL, the format argument is unused.
label: code-design
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
ANSI C typing
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
1=little endian
* "IdentifierStart" production check.
* Compiler state
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Entries part is a bit more complex
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
nop: insert top to top
h_match is borrowed, remains reachable through match_obj
0 = uppercase, 32 = lowercase (= 'a' - 'A')
catch jump
3: toLocaleString
not reachable
leave 'cat' as top catcher (also works if catchstack exhausted)
+1 for opcode
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
Not halfway, round to nearest.
remove in_val
idx_argbase
Strict by default.
fixed precision and zero padding would be required
Ensuring (reserving) space.
flags: "m"
'setPrototypeOf'
return 1 to allow callers to tail call
* Not found (even in global object)
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
'number'
label id allocation (running counter)
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
comment: XXX: how to figure correct size?
label: code-design
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
op_flags
# argument registers target function wants (< 0 => never for ecma calls)
Different calling convention than above used because the helper
* is shared.
equality not actually possible
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
[ ... func this arg1 ... argN envobj ]
32: setDate
slot C is a target (default: source)
-> [ ... lval rval new_rval ]
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
sanity
deal with negative values
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
create bound function object
maximum bytecode copies for {n,m} quantifiers
[ ... lval rval ]
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
use duk_double_union as duk_tval directly
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't increase 'count'
module.exports = exports
simulate alloc failure on every alloc (except when mark-and-sweep is running)
must relookup act in case of side effects
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
status booleans
identifier handling
duk_unicode_caseconv_lc[]
DUK_TOK_PROTECTED
target
reserved words: future reserved words
Ensure space for maximum multi-character result; estimate is overkill.
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
* Pre resize assertions.
In-place unary operation.
Note: expect that caller has already eaten the left paren
implicit leading one
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
* Internal helpers for managing object 'length'
biased exp == 0 -> denormal, exp -1022
0xdeadbeef in decimal
strings up to the this length are not cached
DUK_HEAPHDR_H_INCLUDED
[ ... key_obj key val ]
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
keep func->h_argnames; it is fixed for all passes
num entries of new func at entry
One digit octal escape, digit validated.
Use result value as is.
step 15.a
formal arg limits
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
[ offset noAssert ], when ftype != DUK__FLD_VARINT
bufwriter for temp accumulation
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
-1 if invalid
convenience helpers
* Use Object.defineProperty() helper for the actual operation.
Ensure compact use of temps.
* Object handling: property access and other support functions.
allocated from valstack (fixed buffer)
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
DUK_TVAL_H_INCLUDED
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
last component
lexing (tokenization) state (contains two valstack slot indices)
* Update an existing property of the base object.
update length (curr points to length, and we assume it's still valid)
in-place setup
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
The lo/hi indices may be crossed and hi < 0 is possible at entry.
* Init compilation context
add E
'\xffThread'
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
* Special name handling
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: XXX: this is a major target for size optimization
label: code-design
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
XXX: check num_args
pop 'name'
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
* All done, switch properties ('p') allocation to new one.
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
decode '%xx' to '%xx' if decoded char in reserved set
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
any other printable -> as is
Called by duk_hstring.h macros
step type: none, step into, step over, step out
comment: XXX: faster implementation
label: code-design
cleared before entering catch part
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
comment: XXX: ignored now
label: code-design
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
* Automatically generated by extract_caseconv.py, do not edit!
* Support functions for duk_heap.
DUK_HCOMPILEDFUNCTION_H_INCLUDED
write_to_array_part:
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
E5 Section 15.5.5.1
own pointer
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
# total registers target function wants on entry (< 0 => never for ecma calls)
bytecode has a stable pointer
* Thread builtins
overwrite str1
comment: XXX: exposed duk_debug_read_buffer
label: code-design
DUK_JS_BYTECODE_H_INCLUDED
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
no need for refcount update
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
compiler ensures this
[... old_result result] -> [... result]
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
* concat()
different memory layout, alloc size, and init
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
default: NULL, length 0
env is closed, should be missing _Callee, _Thread, _Regbase
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
force_flag
Used for minimal 'const': initializer required.
* Table for base-64 encoding
Note: no allocation pressure, no need to check refcounts etc
args incorrect
write on next loop
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
2nd related value (type specific)
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
cannot grow
0=indexOf, 1=lastIndexOf
bump up "allocated" reg count, just in case
Strict standard behavior, ignore trailing elements for
* result 'length'.
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
DUK_TOK_IF
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
Working with the pointer and current size.
object has any exotic behavior(s)
DUK_USE_STRTAB_PROBE
written by a previous RESUME handling
comment:
* Macro support functions (use only macros in calling code)
label: code-design
string 1 of token (borrowed, stored to ctx->slot1_idx)
comment: XXX: more accurate?
label: code-design
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
level string
sufficient for keeping temp reg numbers in check
All other object types.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
mixed endian
min_new_size
length in bytes (not counting NUL term)
No finalizers for ROM objects
last element that was left in the heap
compact; no need to seal because object is internal
0x90...0x9f
const flag for C
[... obj] -> [...]
number of pairs in current MPUTOBJ set
escaped NonEscapeCharacter
Module id requested
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
Never executed if new size is smaller.
'protected'
because arg count is 1
'if'
finally free the struct itself
!DUK_USE_PARANOID_ERRORS
Array or Array-like
coerce towards zero
must not be extensible
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
mark-and-sweep: finalizable (on current pass)
[ ... replacer match [captures] match_char_offset input ]
DUK_OP_TRYCATCH flags in A
single string token
Use byte copy.
Most common cases first.
no point in supporting encodings of 5 or more bytes
'|'
use_prev_pc
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
Return value handling.
Enable DUKFUNC exotic behavior once properties are set up.
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
Assumes that caller has normalized NaNs, otherwise trouble ahead.
0x00: finish (not part of number)
* 0x01: continue
comment: this is relatively expensive
label: code-design
num_values and temp_start reset at top of outer loop
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
specific assert for wrapping
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
bits 2...5: type
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
'toUTCString'
Note: no need to re-lookup tv, conversion is side effect free
require.id of current module
low 32 bits is complete
time when status/peek was last done (Date-based rate limit)
[obj key value desc value]
'caller'
rbp_flags
'data'
'type'
comment: XXX: shared strings
label: code-design
-> [ ... source ]
default value
output 3 bytes from 't'
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
loop iterator init and limit changed from standard algorithm
enum_flags
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
by default, use caller's environment
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
value resides in 'valstack_idx'
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
free inner references (these exist e.g. when external
* strings are enabled)
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
surrogate pairs get encoded here
11: getUTCMonth
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
assert just a few critical flags
correction
default to false
* Stack slice primitives
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> []
DUK_USE_STRHASH_DENSE
* Get old and new length
clipped codepoint
h_new_proto may be NULL
-> [ ... errhandler errval ]
this is the case for normalized numbers
flags: "gim"
Starting from this round, use emergency mode
* for mark-and-sweep.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
* Found existing own or inherited plain property, but original
* base is a primitive value.
optional callstack level
e.g. duk_push_string_file_raw() pushed undefined
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
'error'
don't throw for prototype loop
(< (* r 2) s)
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
Note: not set in template (has no "prototype")
unreferenced w/o asserts
if (is_repl_func)
precision:shortest
don't resize stringtable (but may sweep it); needed during stringtable resize
Write curr_pc back for the debugger.
Note: duk__dec_req_stridx() backtracks one char
'length'
-> [ ... val retval ]
Object property access
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
3
Apply timezone offset to get the main parts in UTC
* Zero sign, see misc/tcc_zerosign2.c.
* Boolean built-ins
LeftHandSideExpression does not allow empty expression
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
Note: escaped characters differentiate directives
defaults, E5 Section 8.6.1, Table 7
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
special RegExp literal handling after IdentifierName
XXX: byte offset?
'switch'
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
avoid side effects
result in csreg
* Other heap related defines
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
strict: non-deletable, non-writable
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
use fallback as 'this' value
Caller has already eaten the first character ('(') which we don't need.
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
C recursion check.
b
Misc
catches EOF (0x00)
comment: XXX: duk_get_length?
label: code-design
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
'defineProperty'
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
marker for detecting internal "double faults", see duk_error_throw.c
three flags
No difference between raw/ensure because the buffer shrinks.
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
Start filling in the activation
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
prevent duk__expr_led() by using a binding power less than anything valid
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
[ ... proplist enum_obj key val ]
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
shrink failure is not fatal
!(l < p)
valstack index of loop detection object
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
yes -> move back to heap allocated
strict flag for putvar comes from our caller (currently: fixed)
catchstack limits
* Manually optimized number-to-double conversion
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
[ ... enum_target res trap_result val true ]
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
important for callers
fail
[ sep ToObject(this) len ]
DUK_TOK_PERIOD
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
idx_reviver
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
signed shift
Impose a string maximum length, need to handle overflow
* correctly.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
bytes left
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
failed
-> [... key]
comment: Tested: not faster on x64
label: code-design
clamp to 10 chars
* "LineTerminator" production check.
A lightfunc might also inherit a .toJSON() so just bail out.
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
comment: XXX: inefficient; block insert primitive
label: code-design
* Exposed helper for setting up heap longjmp state.
in non-packed representation we don't care about which NaN is used
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
zero
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
comment: XXX: tostring?
label: code-design
'func' wants stack "as is"
* Debug message processing
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
* Sweep heap
Object.keys
map is reachable through obj
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
required for rehash to succeed, equality not that useful
DUK_TOK_CLASS
comment: unused for label
label: code-design
'this' binding shouldn't matter here
comment: remove old value
label: code-design
comment: get rid of the strings early to minimize memory use before intern
label: code-design
always in entry part, no need to look up parents etc
* Raw intern and lookup
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
CONDITIONAL EXPRESSION
swap elements; deal with non-existent elements correctly
[ ... closure/error ]
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
ignore
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
vararg function, thisArg needs special handling
Assert for value stack initialization policy.
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
curr_token slot1 (matches 'lex' slot1_idx)
eat 'break' or 'continue'
zero-based -> one-based
roughly 512 bytes
* indexOf() and lastIndexOf()
DUK_USE_HEAPPTR16
regexp literal must not follow this token
qmin and qmax will be 0 or 1
same as during entry
Have a catch variable.
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
Object property allocation layout
Node.js accepts only actual Arrays.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
* Actual Object.defineProperty() default algorithm.
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
'class'
compare: similar to string comparison but for buffer data.
Note: if 'x' is zero, x->n becomes 0 here
Debugger protocol version is defined in the public API header.
not undefined
Endianness indicator
number of activation records in callstack preventing a yield
DUK_TOK_IMPLEMENTS
4'294'967'295
XXX: switch cast?
'trace'
array 'length' is always a number, as we coerce it
NULL is allowed, no output
* Convert duk_compiler_func to a function template
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
eat closing slash
* Regexp range tables
Value stack intentionally mixed size here.
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
hobject property layout
comment: UNUSED, intentionally empty
label: code-design
double quote or backslash
track utf-8 non-continuation bytes
[ hobject props enum(props) ]
22 to 31
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
-> [... enum key enum_target val]
constants arbitrary, chosen for small loads
reset 'allow_in' for parenthesized expression
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
if present, forces 16-byte duk_tval
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
exports (this binding)
disabled
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
read-only values 'lifted' for ease of use
return value
'source'
'clog'
digits
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
is_frozen
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
if duk_uint32_t is exactly 32 bits, this is a NOP
* Not found as a concrete property, check whether a String object
* virtual property matches.
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
off >= step, and step >= 1
zero-width joiner
Rethrow error to calling state.
'"'
next temporary register to allocate
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
relookup after side effects (no side effects currently however)
Note: this order matters (final value before deleting map entry must be done)
'arguments'
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
inline arithmetic check for constant values
pre-incremented, points to first jump slot
* Helpers for duk_compiler_func.
Note: need to re-lookup because ToNumber() may have side effects
expr_flags
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
accept string
unreferenced without assertions
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
'toString'
first character has been matched
0xfff0 is -Infinity
comment: XXX: don't want to shrink allocation here
label: code-design
-> [ ... error ]
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
curr_token follows 'function'
* Update preventcount
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
'toJSON'
function executes as a constructor (called via "new")
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
DUK_ERROR_H_INCLUDED
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
if 1, doing a fixed format output (not free format)
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
borrowed; NULL if no step state (NULLed in unwind)
new buffer with string contents
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
no regexp instance should exist without a non-configurable bytecode property
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
replaces top of stack with new value if necessary
33: setUTCDate
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
eat 'for'
init 'curr_token'
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
implicit attributes
allow a constant to be returned
prop index in 'entry part', < 0 if not there
add_auto_proto
[ ... ToObject(this) ToUint32(length) val ]
Load bytecode instructions.
unsupported: would consume multiple args
DUK_USE_DEBUGGER_THROW_NOTIFY
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
There's intentionally no check for
* current underlying buffer length.
follow parent chain
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
comment: XXX: this should be an assert
label: test
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
No debugger support, just pop values.
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
[ hobject props enum(props) key desc value? getter? setter? ]
start match from beginning
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
DUK_USE_SECTION_B
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
comment: XXX: better to get base and walk forwards?
label: code-design
'ownKeys'
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
restore stack top
DUK_USE_BASE64_FASTPATH
Valstack should suffice here, required on function valstack init
duk_hnativefunction specific fields.
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Insert bytes in the middle of the buffer from an external buffer.
identifier names (E5 Section 7.6)
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
keep heap->dbg_detached_cb
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
During parsing, month and day are one-based; set defaults here.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
token allows automatic semicolon insertion (eof or preceded by newline)
Use special opcodes to load short strings
* Add .fileName and .lineNumber to an error on the stack top.
* CommonJS require() and modules support
* Lexing helpers
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
explicit PropertyList
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
* Create mantissa
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
ToNumber() for a fastint is a no-op.
[key] -> [undefined] (default value)
traceback depth fits into 16 bits
[ thisArg arg1 ... argN func boundFunc argArray ]
* Parser duk__advance() token eating functions
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
Same as above but for unsigned int range.
comma after a value, expected
duplicate key
Given a day number, determine year and day-within-year.
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
Success path handles
comment: XXX: getter with class check, useful in built-ins
label: code-design
already updated
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
match: keep saves
DUK_USE_PARANOID_MATH
'boolean'
* Debugging disabled
fixed offset in valstack
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
* Proxy helpers
* Found; post-processing (Function and arguments objects)
maps to finalizer 2nd argument
DUK_USE_AVOID_PLATFORM_FUNCPTRS
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
key encountered as a plain property
e.g. DUK_OP_POSTINCV
Allow empty string to be interpreted as 0
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
not minimum exponent
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
Because new_size > duk__count_used_probe(heap), guaranteed to work
bump refcount to prevent refzero during finalizer processing
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_string()
pointers for scanning
array part size (entirely gc reachable)
Steps 12 and 13: reorganize elements to make room for itemCount elements
number of tokens parsed
Tear down state.
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
zero handled by caller
Don't accept relative indices now.
[holder name val] -> [holder]
res_obj
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
function declaration
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
'?'
state == 3
Maximum traversal depth for "bound function" chains.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
[ thread value ]
* GETPROP: Ecmascript property read.
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
object is a thread (duk_hthread)
'info'
add a new pending split to the beginning of the entire disjunction
duk_push_this() + CheckObjectCoercible() + duk_to_object()
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
this may have side effects, so re-lookup act
Fall through to handle the rest.
[ ... error lineNumber fileName ]
* Number built-ins
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
-> [ ... closure template env ]
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
6: toUTCString
comment: note: ctx-wide temporary
label: code-design
value popped by call
Note: this may fail, caller should protect the call if necessary
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
4
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
s <- 2 * b
native functions: 149
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
exponent 1070
no need to reset temps, as we're finished emitting code
DUK_ERR_ERROR: no macros needed
comment: XXX: assumed to fit for now
label: code-design
[... fallback retval]
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
Getter might have arbitrary side effects,
* so bail out.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
-> [ ... voidp voidp ]
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
special helper for emitting u16 lists (used for character ranges for built-in char classes)
[ ... re_obj input bc saved_buf ]
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
Parser separator indices.
Regexp
k > 0 -> k was too low, and cannot be too high
'func' in the algorithm
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
Outside any activation -> look up from global.
Decrease by 25% every round
For manual testing only.
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
* Main heap structure
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
E5 Section 9.2
Backtrack utf-8 input and return a (possibly canonicalized) input character.
Cause an interrupt after executing one instruction.
Compiler
at least errobj must be on stack
16 bits
* Default panic handler
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
'modSearch'
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
does not fit into 16 bits
ensures no overflow
[ ... input buffer ]
execution resumes in bytecode executor
Standard JSON omits functions
7 bits
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
* Objects have internal references. Must finalize through
* the "refzero" work list.
different thread
number of values in current MPUTARR set
steps 13-14
Compute result length and validate argument buffers.
DUK_BUILTINS_H_INCLUDED
copy bytecode instructions one at a time
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
[ ... RegExp val ] -> [ ... res ]
load factor max 75%
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
* Resizing
token closes expression, e.g. ')', ']'
fileName
* Get prototype object for an integer error code.
'\xffNext'
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
borrow literal Infinity from builtin string
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
prefer direct execution
comment: Longjmp state is cleaned up by error handling
label: code-design
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
fall-through jump to next code of next case (backpatched)
already one-based
comment: XXX: could use at least one fewer loop counters
label: code-design
Create function 'data' buffer but don't attach it yet.
* Function built-ins
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
comment: hacky helper for String.prototype.split()
label: code-design
[ (builtin objects) name func ]
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
toString() conditions
Write bytecode executor's curr_pc back to topmost activation (if any).
[] -> [val]
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
-> [ sep ToObject(this) len sep str ]
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
[ ... enum_target res handler trap ]
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
x <- (1<<y)
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
Any 'res' will do.
If neutered must return 0; length is zeroed during
* neutering.
XXX: assert idx_base
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
avoid side effect issues
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
SHIFT EXPRESSION
overflow, fall through
restored if ecma-to-ecma setup fails
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
If debugger is paused, garbage collection is disabled by default.
DUK_ERR_REFERENCE_ERROR: no macros needed
XXX: shared helper for duk_push_hobject_or_undefined()?
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
unconditionally
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
resumee
* Parse a function body or a function-like expression, depending
* on flags.
actually used, non-NULL entries
Fast path check.
length check
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
'{"_ninf":true}'
shared checks for all descriptor types
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
* Process space (3rd argument to JSON.stringify)
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
DUK_USE_PANIC_HANDLER
avoid array abandoning which interns strings
traits are separate; in particular, arguments not an array
duk__get_min_grow_a() is always >= 1
9: getUTCFullYear
[key getter this key] -> [key retval]
Source end clamped silently to available length.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
* Proxy built-in (ES6)
Native function, no relevant lineNumber.
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
'res' must be a plain ivalue, and not register-bound variable.
function helpers
'Null'
internal properties
custom
* XXX: shrink array allocation or entries compaction here?
ToInteger(lastIndex)
* Encoding/decoding helpers
default: NaN
covers -Infinity
Error instance, use augmented error data directly
t1 = (+ r m+)
[... func arg1 ... argN]
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
variable value (function, we hope, not checked here)
return 'res_obj'
E5 Section 10.4.2
DUK_FORWDECL_H_INCLUDED
avoid unary minus on unsigned
Just flip the single bit.
unicode code points, window[0] is always next, points to 'buffer'
probe
may be set to 0 by duk_debugger_attach() inside callback
Easy to get wrong, so assert for it.
mask out flags not actually stored
'with' target must be created first, in case we run out of memory
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
Important main primitive.
no throw
[ ... lval rval(func) ]
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
'lastIndex'
0xd0-0xdf
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
pop varname
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
debugger
* Automatically generated by extract_chars.py, do not edit!
* Copy keys and values in the entry part (compacting them at the same time).
expensive init, just want to fill window
'toLogString'
split2: prefer jump execution (not direct)
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
skip line info
heap destruction ongoing, finalizer rescue no longer possible
E5 Section 9.1
value stack indices for tracking objects
two encoding attempts suffices
DUK_ISPEC_XXX
comment: XXX: append primitive
label: code-design
current lexical environment (may be NULL if delayed)
explicit NULL inits
[ ... closure template env ]
use a temp: decref only when valstack reachable values are correct
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
0 or -1
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
Object.defineProperty() equivalent C binding.
skip jump slots
We can directly access value stack here.
DUK_TOK_TYPEOF
mark as complex
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
comment: m+ != m- (very rarely)
label: code-design
* Duktape debugger
Ecmascript activation + Duktape.Thread.resume() activation
'\''
[ ... str ]
-> [ ... value ]
Use temporaries and update lex_ctx only when finished.
mark-and-sweep not running -> must be empty
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_TOK_EXPORT
array of active label names
* Helper for C function call negative return values.
entry_top + 0
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
Shared helper.
x1 must be a string
[ ... value? getter? setter? ]
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
Gather in big endian
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
format is bit packed
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
parse args starting from "next temp", reg_target + 1
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
* Context init
comment: XXX: rework
label: code-design
Call stack. [0,callstack_top[ is GC reachable.
DUK_NUMCONV_H_INCLUDED
is a function declaration (as opposed to function expression)
Precomputed pointers when using 16-bit heap pointer packing.
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
= IsAccessorDescriptor(Desc)
36: setFullYear
comment: not covered, return all zeroes
label: test
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
DUK_HTHREAD_H_INCLUDED
DUK_USE_ES6_PROXY
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Pretend like we got EOM
[ regexp source bytecode ]
catch depth at point of definition
-> [... cons target]
Grow entry part allocation for one additional entry.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
comment: XXX: better multiline
label: code-design
object literal key tracking flags
curr is accessor -> cannot be in array part
stmt has explicit/implicit semicolon terminator
lexing
[ ... result/error ]
catches EOF (NUL) and initial comma
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
currently running thread
temproots
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
vararg
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
Allow NULL 'msg'
borrowed reference
[... s1 s2] -> [... s1+s2]
DUK_TOK_DIV
comment: XXX: lithuanian not implemented
label: requirement
Explicit zero size check to avoid NULL 'tv1'.
* Get holder object
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
lead zero + 'digits' fractions + 1 for rounding
stack discipline consistency check
* Update the interrupt counter
these non-standard properties are copied for convenience
still reachable
* Forward declarations for all Duktape structures.
[ ... obj key ]
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
* Macros for property handling
val2 = min count, val1 = max count
find and remove string from stringtable; caller must free the string itself
Inner functions recursively.
== DUK__MAX_TEMPS is OK
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
use bigint area as a temp
'n'
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
step 4.b
(Number.MAX_VALUE).toString(2).length == 1024, + spare
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
Catch stack. [0,catchstack_top[ is GC reachable.
DUK_USE_DATE_TZO_WINDOWS
-> [ ... res_obj ]
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
flags is unsigned
0
comment: XXX: better place for this
label: code-design
Zero encoded pointer is required to match NULL
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
upper limit, assuming no whitespace etc
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
comment: not necessary to init, disabled for faster parsing
label: code-design
We already ate 'x', so backup one byte.
maximum token count before error (sanity backstop)
* For ASCII strings, the answer is simple.
'super'
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
'JSON'
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
marker: copy t if not changed
thread has terminated
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
* Duktape public API for Duktape 1.5.2.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit cad34ae155acb0846545ca6bf2d29f9463b22bbb (v1.5.2).
* Git branch HEAD.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
internal flag value: throw if mask doesn't match
set getter (given on value stack)
no error if file does not exist
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2016 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
Shared helper to generate DUK_OPT_xxx and DUK_USE_xxx documentation.
XXX: unfinished placeholder
Add a header snippet for detecting presence of DUK_OPT_xxx feature
options which will be removed in Duktape 2.x.
Add a header snippet for providing a __OVERRIDE_DEFINES__ section.
XXX: unsigned constants?
Globals holding scanned metadata, helper snippets, etc
verbatim text for the entire line
comment: Derived defines (DUK_USE_INTEGER_LE, etc) from DUK_USE_BYTEORDER.
Duktape internals currently rely on the derived defines. This is
after sanity checks because the derived defines are marked removed.
label: code-design
Add original snippets. This fills in the required nodes
recursively.
comment: DUK_OPT_xxx always come from outside
label: code-design
print('#snippet ' + sub_fn)
already present
comment: XXX: more checks
label: code-design
Assume these provides come from outside.
Feature selection, system include, Date provider
Most #include statements are here
Remaining tags in alphabetic order
Automatic DUK_OPT_xxx feature option handling
key is known
Byte order and alignment defines are allowed to be missing,
a fill-in will handle them. This is necessary because for
some architecture byte order and/or alignment may vary between
targets and may be software configurable.
integer value
Figure out fill-ins by looking for snippets not in original
list and without any unserialized dependent nodes.
comment:
Autogeneration of option documentation
label: documentation
duk_config.h generation
print(repr(graph))
print(repr(snlist))
print('Resolved helper defines: %r' % resolved)
Detect and reject 'fast math'
comment: XXX: conditional warning, happens in some normal cases
print('WARNING: define %r required, not provided so far' % k)
label: code-design
Helper for building a text file from individual lines, injected files, etc.
Inserted values are converted to Snippets so that their provides/requires
information can be tracked. When non-C outputs are created, these will be
bogus but ignored.
Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
NOTE: careful with Python equality, e.g. "0 == False" is true.
Metadata to scan from config files.
Generate a duk_config.h where platform, architecture, and compiler are
all either autodetected or specified by user.
Autodetection is based on a configured list of supported platforms,
architectures, and compilers. For example, platforms.yaml defines the
supported platforms and provides a helper define (DUK_F_xxx) to use for
detecting that platform, and names the header snippet to provide the
platform-specific definitions. Necessary dependencies (DUK_F_xxx) are
automatically pulled in.
Automatic "fill ins" are used for mandatory platform, architecture, and
compiler defines which have a reasonable portable default. This reduces
e.g. compiler-specific define count because there are a lot compiler
macros which have a good default.
comment: XXX: require automatic detection to be signaled?
e.g. define DUK_USE_ALIGN_BY -1
define DUK_USE_BYTE_ORDER -1
label: code-design
Development time helper: add DUK_ACTIVE which provides a runtime C string
indicating what DUK_USE_xxx config options are active at run time. This
is useful in genconfig development so that one can e.g. diff the active
run time options of two headers. This is intended just for genconfig
development and is not available in normal headers.
Default value is false, and caller has emitted
an unconditional #undef, so don't emit a duplicate
Platform, architecture, compiler fillins. These are after all
detection so that e.g. DUK_SPRINTF() can be provided by platform
or compiler before trying a fill-in.
Main
comment: XXX: indicate feature option support, sanity checks enabled, etc
in general summary of options, perhaps genconfig command line?
label: code-design
sort under primary tag
comment: for line in stripped_lines: print(line)
label: code-design
comment: XXX: better to lookup compilers metadata
label: code-design
Compiler files must provide at least these (additional checks
in validate_compiler_file()). Fill-ins provide missing optionals.
Header snippet representation: lines, provides defines, requires defines.
comment: Find a header snippet which provides the missing define.
Some DUK_F_xxx files provide multiple defines, so we don't
necessarily know the snippet filename here.
label: code-design
signal to fillin
print('Tags: %r' % use_tags_list)
must be #define'd
Compatibility with Duktape 1.3
compiling Duktape from a single source file (duktape.c) version
compiling Duktape (not user application)
artifact, include guard
Forced options from multiple sources are gathered into a shared list
so that the override order remains the same as on the command line.
Avoid ambiguous hex escapes
Snippet provides it's own require; omit
print('config option %s not covered by manual snippets, emitting default automatically' % k)
comment: XXX: rst or other format
label: code-design
C string value
Platform files must provide at least these (additional checks
in validate_platform_file()). Fill-ins provide missing optionals.
shallow copy
Architecture files must provide at least these (additional checks
in validate_architecture_file()). Fill-ins provide missing optionals.
Generate a duk_config.h header with platform, compiler, and
architecture either autodetected (default) or specified by
user. Support for autogenerated DUK_OPT_xxx flags is also
selected by user.
comment: XXX: aware of target version
label: code-design
Preferred tags first
snippet list
comment: XXX: better to lookup architectures metadata
label: code-design
graph[A] = [ B, ... ] <-> B, ... provide something A requires.
x is a Snippet
Helper headers snippets.
lines of text and/or snippets
map from define to 'True' for now
map from define to 'True' for now
comment: Insert missing define dependencies into index 'idx_deps' repeatedly
until no unsatisfied dependencies exist. This is used to pull in
the required DUK_F_xxx helper defines without pulling them all in.
The resolution mechanism also ensures dependencies are pulled in the
correct order, i.e. DUK_F_xxx helpers may depend on each other (as
long as there are no circular dependencies).
XXX: this can be simplified a lot
label: code-design
strip last newline to avoid empty line
comment: DUK_USE_xxx are internal and they should not be 'requirements'
label: code-design
This is a fallback in case config option metadata is wrong.
byteorder provided by all architecture files
alignment provided by all architecture files
packed tval provided by all architecture files
print('Autoscanning snippet: %s' % fn)
for printing only
comment: XXX: detect and handle loops cleanly
label: code-design
Emit a default #define / #undef for an option based on
a config option metadata node (parsed YAML doc).
Object layout
Careful with order, snippet may self-reference its own
defines in which case there's no outward dependency.
(This is not 100% because the order of require/provide
matters and this is not handled now.)
Also, some snippets may #undef/#define another define but
they don't "provide" the define as such. Such redefinitions
are marked "/* redefine */" in the snippets. They're best
avoided (and not currently needed in Duktape 1.4.0).
comment: Add a header snippet for checking consistency of DUK_USE_xxx config
options, e.g. inconsistent options, invalid option values.
label: code-design
Helpers for duk_config.h generation
must be #define'd
may be #undef'd, as long as provided
may be #undef'd, as long as provided
may be #undef'd, as long as provided
Snippet may have further unresolved provides; add recursively
For some options like DUK_OPT_PACKED_TVAL the default comes
from platform definition.
comment: XXX: assume no newlines etc
label: code-design
Date provider snippet is after custom header and overrides, so that
the user may define e.g. DUK_USE_DATE_NOW_GETTIMEOFDAY in their
custom header.
comment: !/usr/bin/env python2
Process Duktape option metadata and produce various useful outputs:
- duk_config.h with specific or autodetected platform, compiler, and
architecture; forced options; sanity checks; etc
- option documentation for Duktape 1.x feature options (DUK_OPT_xxx)
- option documentation for Duktape 1.x/2.x config options (DUK_USE_xxx)
Genconfig tries to build all outputs based on modular metadata, so that
managing a large number of config options (which is hard to avoid given
the wide range of targets Duktape supports) remains maintainable.
Genconfig does *not* try to support all exotic platforms out there.
Instead, the goal is to allow the metadata to be extended, or to provide
a reasonable starting point for manual duk_config.h tweaking.
For Duktape 1.3 release the main goal was to autogenerate a Duktape 1.2
compatible "autodetect" header from legacy snippets, with other outputs
being experimental. For Duktape 1.4 duk_config.h is always created from
modular sources.
label: code-design
comment: Not exact but close enough. Doesn't handle string literals etc,
but these are not a concrete issue for scanning preprocessor
#define references.
Comment contents are stripped of any DUK_ prefixed text to avoid
incorrect requires/provides detection. Other comment text is kept;
in particular a "/* redefine */" comment must remain intact here.
(The 'redefine' hack is not actively needed now.)
Avoid Python 2.6 vs. Python 2.7 argument differences.
label: code-design
If manually-edited snippets don't #define or #undef a certain
config option, emit a default value here. This is useful to
fill-in for new config options not covered by manual snippets
(which is intentional).
position where to emit DUK_F_xxx dependencies
comment: XXX: platform/compiler could provide types; if so, need some signaling
defines like DUK_F_TYPEDEFS_DEFINED
label: code-design
comment: Compilers need a lot of defines; missing defines are automatically
filled in with defaults (which are mostly compiler independent), so
the requires define list is not very large.
label: code-design
comment: C preprocessor '#warning' is often supported
label: code-design
print('Resolving %r' % k)
Miscellaneous helpers
If a related feature option exists, it can be used to force
enable/disable the target feature. If neither feature option
(DUK_OPT_xxx or DUK_OPT_NO_xxx) is given, revert to default.
print('Deleting temporary directory: %r' % dirname)
at least one other node provides 'k'
Preferred tag order for generated C header files.
comment: XXX: better plumbing for lookup path
label: code-design
Add automatic DUK_OPT_XXX and DUK_OPT_NO_XXX handling for backwards
compatibility with Duktape 1.2 and before.
DUK_SETJMP, DUK_LONGJMP, DUK_JMPBUF_TYPE are optional, fill-in
provides if none defined.
for trailing newline
Forced options, last occurrence wins (allows a base config file to be
overridden by a more specific one).
DUK_F_xxx snippets
emit tag heading only if there are subsections
comment: XXX: placeholder, need to decide on markup conventions for YAML files
label: code-design
Number types
print('REQUIRES: %r' % m)
comment: XXX: better to lookup platforms metadata
label: code-design
verbatim value
comment: uppercase only, don't match DUK_USE_xxx for example
label: code-design
comment: XXX: assume no newlines etc
XXX: support compiler specific warning mechanisms
label: code-design
print('Effective tag order: %r' % tags)
comment: Don't allow e.g. DUK_USE_ which results from matching DUK_USE_xxx
print('PROVIDES: %r' % m.group(1))
label: code-design
DUK_F_UCLIBC is special because __UCLIBC__ is provided by an #include
file, so the check must happen after platform includes. It'd be nice
for this to be automatic (e.g. DUK_F_UCLIBC.h.in could indicate the
dependency somehow).
Emit forced options. If a corresponding option is already defined
by a snippet above, #undef it first.
DLL build affects visibility attributes on Windows but unfortunately
cannot be detected automatically from preprocessor defines or such.
DLL build status is hidden behind DUK_F_DLL_BUILD and there are two
ways for that to be set:
- Duktape 1.3 backwards compatible DUK_OPT_DLL_BUILD
- Genconfig --dll option
Preferred tag order for option documentation.
XXX: check that YAML parses
Pretty print a debugger command.
Duktape internal class numbers, must match C headers
Write a string into a buffer interpreting codepoints U+0000...U+00FF
* as bytes. Drop higher bits.
comment: XXX: add constants inline to preformatted output (e.g. for strings,
add a short escaped snippet as a comment on the line after the
compact argument list).
label: code-design
absFn -> true
Errors
true
We shouldn't come here, but if we do, JSON is a reasonable default.
Could emit a 'debug-value' event here, but that's not necessary
because the receiver will just collect statistics which can also
be done using the finished message.
comment: XXX: move this to the web UI so that the UI can control what
locals are listed (or perhaps show locals for all levels with
an expandable tree view).
label: code-design
There is no close() or destroy() for a passthrough stream, so just
close the outputParser which will cancel timers etc.
Raw bytes
Unicode string
Still waiting for version identification to complete.
comment: Pending flags are used to avoid requesting the same thing twice
while a previous request is pending. The flag-based approach is
quite awkward. Rework to use promises.
label: code-design
2-byte string
undefined
* JSON debug proxy
msg.varname is a proper Unicode strings here, and needs to be
converted into a protocol string (U+0000...U+00FF).
new object, old may be in circulation for a while
list of command names, merged client/target
XXX: normalize last newline (i.e. force a newline if contents don't
end with a newline)?
accumulate data
accumulated message until EOM
A PutVar call quite possibly changes the local variables so always
re-read locals afterwards. We don't need to wait for PutVar to
complete here; the requests will pipeline automatically and be
executed in order.
2-byte buffer
'./foo/bar.js' -> 'foo/bar.js'
whole
Commands initiated by Duktape
Not all streams will emit this.
Pretty print a dvalue. Useful for dumping etc.
Could also check for an empty request queue, but that's probably
too strict?
Technically we should wait for each delbreak reply but because
target processes the requests in order, it doesn't matter.
Protocol version handling. When dumping an output stream, the
caller gives a non-null protocolVersion so we don't read one here.
comment: Check if 'msg' would encode to the same JSON which was previously sent
to the web client. The caller then avoid resending unnecessary stuff.
label: code-design
Up-to-date list of breakpoints on target
comment: XXX: do pretty printing in debug client for now
label: code-design
console.log(JSON.stringify(msg));
Duktape heaphdr type constants, must match C headers
* Debugger implementation
*
* A debugger instance communicates with the debug target and maintains
* persistent debug state so that the current state can be resent to the
* socket.io client (web UI) if it reconnects. Whenever the debugger state
* is changed an event is generated. The socket.io handler will listen to
* state change events and push the necessary updates to the web UI, often
* in a rate limited fashion or using a client pull to ensure the web UI
* is not overloaded.
*
* The debugger instance assumes that if the debug protocol connection is
* re-established, it is always to the same target. There is no separate
* abstraction for a debugger session.
error
Decode and normalize source file contents: UTF-8, tabs to 8,
* CR LF to LF.
comment: unused/none
label: code-design
* Command line parsing and initialization
"notify" can be a string or "true"
Shouldn't come here.
4-byte signed integer
For the unquoted version we don't need to escape single or double
quotes.
unsigned
msg.input is a proper Unicode strings here, and needs to be
converted into a protocol string (U+0000...U+00FF).
nop: no callback
https://github.com/ryanmcgrath/wrench-js
varvalue is JSON parsed by the web UI for now, need special string
encoding here.
Command line options (defaults here, overwritten if necessary)
truncate higher bits
No actual requests sent by the target right now (just notifys).
Encode an ordinary Unicode string into a dvalue compatible format, i.e.
* into a byte array represented as codepoints U+0000...U+00FF. Concretely,
* encode with UTF-8 and then represent the bytes with U+0000...U+00FF.
console.log('Received json proxy input line: ' + line.toString('utf8'));
* Miscellaneous helpers
indicate 'v' is actually set
Dump effective options. Also provides a list of option names.
Although the underlying transport may not have a close() or destroy()
method or even a 'close' event, this method is always available and
will generate a 'transport-close'.
The caller is responsible for closing the underlying stream if that
is necessary.
A byline-parser is simple and good enough for now (assume
compact JSON with no newlines).
override
update run state now that we're paused
duk_tval number, any IEEE double
decode into hex
big endian ieee double
just trigger a sync, gets rate limited
comment: Convert a buffer into a string using Unicode codepoints U+0000...U+00FF.
* This is the NodeJS 'binary' encoding, but since it's being deprecated,
* reimplement it here. We need to avoid parsing strings as e.g. UTF-8:
* although Duktape strings are usually UTF-8/CESU-8 that's not always the
* case, e.g. for internal strings. Buffer values are also represented as
* strings in the debug protocol, so we must deal accurately with arbitrary
* byte arrays.
label: code-design
Marker objects for special protocol values
Fetch basic info right away
comment: Pretty print a dvalue for UI usage. Everything comes out as a ready-to-use
* string.
*
* XXX: Currently the debug client formats all values for UI use. A better
* solution would be to pass values in typed form and let the UI format them,
* so that styling etc. could take typing into account.
label: code-design
An eval call quite possibly changes the local variables so always
re-read locals afterwards. We don't need to wait for Eval to
complete here; the requests will pipeline automatically and be
executed in order.
Commands initiated by the debug client (= us)
res.status(200).json(val);
raw identification string
Create debugger and web UI singletons, tie them together and
start them.
* Debug protocol parser
*
* The debug protocol parser is an EventEmitter which parses debug messages
* from an input stream and emits 'debug-message' events for completed
* messages ending in an EOM. The parser also provides debug dumping, stream
* logging functionality, and statistics gathering functionality.
*
* This parser is used to parse both incoming and outgoing messages. For
* outgoing messages the only function is to validate and debug dump the
* messages we're about to send. The downside of dumping at this low level
* is that we can't match request and reply/error messages here.
*
* http://www.sitepoint.com/nodejs-events-and-eventemitter/
Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
* for UI usage without quotes.
Loose matching is tempting but counterproductive: filenames must
match 1:1 between the debug client and the debug target for e.g.
breakpoints to work as expected. Note that a breakpoint may be
assigned by selecting a file from a dropdown populated by scanning
the filesystem for available sources and there's no way of knowing
if the debug target uses the exact same name.
web UI singleton
transport connection to target
dummy passthrough for message dumping
parser for incoming debug messages
parser for outgoing debug messages (stats, dumping)
comment: XXX: make the client do this?
label: code-design
// This fails with "RangeError: Maximum call stack size exceeded" for some
// reason, so use a much slower variant.
for (i = 0, n = buf.length; i < n; i++) {
cp[i] = buf[i];
}
return String.fromCharCode.apply(String, cp);
We require a destroy() method from the actual target stream
Debug protocol integer
shift forces unsigned
Send a status request to trigger a status notify, result is ignored:
target sends a status notify instead of a meaningful reply
See doc/debugger.rst for format description.
Pretty print a dvalue string (bytes represented as U+0000...U+00FF)
* for UI usage. Try UTF-8 decoding to get a nice Unicode string (JSON
* encoded) but if that fails, ensure that bytes are encoded transparently.
* The result is a quoted string with a special quote marker for a "raw"
* string when UTF-8 decoding fails. Very long strings are optionally
* clipped.
console.dir(argv);
Intentional invalid command
When we fall back to representing bytes, indicate that the string
is "raw" with a 'r"' prefix (a somewhat arbitrary convention).
U+0022 = ", U+0027 = '
number (IEEE double), big endian
We want the fileMap to contain the filename relative to
the search dir root.
Initial debugger connection
Represented signed 32-bit integers as plain integers.
Debugger code expects this for all fields that are not
duk_tval representations (e.g. command numbers and such).
Right now bytecode is a string containing a direct dump of the
bytecode in target endianness. Decode here so that the web UI
doesn't need to.
comment: The value key should not be used programmatically,
it is just there to make the dumps more readable.
label: code-design
msg.varname and msg.varvalue are proper Unicode strings here, they
need to be converted into protocol strings (U+0000...U+00FF).
Note: typeof null === 'object', so null special case explicitly
Parse complete dvalues (quite inefficient now) by trial parsing.
Consume a value only when it's fully present in 'buf'.
See doc/debugger.rst for format description.
0x80...0xbf: integers 0-63
pointer
* Source file manager
*
* Scan the list of search directories for Ecmascript source files and
* build an index of them. Provides a mechanism to find a source file
* based on a raw 'fileName' property provided by the debug target, and
* to provide a file list for the web UI.
*
* NOTE: it's tempting to do loose matching for filenames, but this does
* not work in practice. Filenames must match 1:1 with the debug target
* so that e.g. breakpoints assigned based on filenames found from the
* search paths will match 1:1 on the debug target. If this is not the
* case, breakpoints won't work as expected.
not cached, send (cache already updated)
CUSTOMTRANSPORT: to use a custom transport, change this.targetStream to
use your custom transport.
Resend all debugger state for new client
clear client state cache
Parse arguments.
not negative zero
stats and dumping
map from (merged) command name to number
stats for current debug connection
"request" can be a string or "true"
Use a PassThrough stream to debug dump and get stats for output messages.
Simply write outgoing data to both the targetStream and this passthrough
separately.
object
* Debugger output formatting
Read final, effective breakpoints from the target
cached
null
comment: XXX: unprintable characters etc? In some UI cases we'd want to
e.g. escape newlines and in others not.
label: code-design
4-byte string
String map for commands (debug dumping). A single map works (instead of
separate maps for each direction) because command numbers don't currently
overlap. So merge the YAML metadata.
nop
lightfunc
false
stream is closed/broken, don't parse anymore
trailing '"' intentionally missing
heapptr
Explicit rate limiter because this is a source of a lot of traffic.
* Minimal debug web console for Duktape command line tool
*
* See debugger/README.rst.
*
* The web UI socket.io communication can easily become a bottleneck and
* it's important to ensure that the web UI remains responsive. Basic rate
* limiting mechanisms (token buckets, suppressing identical messages, etc)
* are used here now. Ideally the web UI would pull data on its own terms
* which would provide natural rate limiting.
*
* Promises are used to structure callback chains.
*
* https://github.com/petkaantonov/bluebird
* https://github.com/petkaantonov/bluebird/blob/master/API.md
* https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns
Pretty print a debugger message given as an array of parsed dvalues.
* Result should be a pure ASCII one-liner.
Constants
Not possible in practice.
* Express setup and socket.io
Represent non-integers as IEEE double dvalues
UTF-8
comment: console logging is done at a higher level to match request/response
label: code-design
Ignore unknown notify messages
console.log(msg);
0x60...0x7f: strings with length 0-31
Delete matching breakpoints in reverse order so that indices
remain valid. We do this for all operations so that duplicates
are eliminated if present.
0xc0...0xff: integers 0-16383
close previous target connection
4-byte buffer
inform web UI
XXX: signal success to UI?
Bytecode opcode/extraop metadata
Token bucket rate limiter for a given callback. Calling code calls
* trigger() to request 'cb' to be called, and the rate limiter ensures
* that 'cb' is not called too often.
Poll various state items when running
pc is preincremented before adding
cache to avoid resending identical data
Here utf8.decode() is better than decoding using NodeJS buffer
operations because we want strict UTF-8 interpretation.
Right now the implementation is setInterval-based, but could also be
made timerless. There are so few rate limited resources that this
doesn't matter in practice.
Value could be a Node.js buffer directly, but
we prefer all dvalues to be JSON compatible
this.targetStream.destroy();
nop
Don't add a 'value' key to numbers.
preformatted dvalues
used to flag special values like undefined
comment: Pretty print a number for UI usage. Types and values should be easy to
* read and typing should be obvious. For numbers, support Infinity, NaN,
* and signed zeroes properly.
label: code-design
no bias in LDINTX
debugger singleton
current socket (or null)
Try to detach cleanly, timeout if no response
4-byte signed integer
heapptr
plain buffer
* Target binary connection handler
number (IEEE double), big endian
Encode arguments into dvalues.
comment: XXX: write a notify to target?
label: code-design
disconnect JSON client too (if not already disconnected)
* JSON proxy server
*
* Accepts an incoming JSON proxy client and connects to a debug target,
* tying the two connections together. Supports both a single connection
* and a persistent mode.
true
truncate higher bits
* JSON connection handler
Represented signed 32-bit integers as plain integers.
Debugger code expects this for all fields that are not
duk_tval representations (e.g. command numbers and such).
Not possible in practice.
* Main
indicate 'v' is actually set
comment: The value key should not be used programmatically,
it is just there to make the dumps more readable.
label: code-design
2-byte string
Once we're connected to the target, start read both binary and JSON
input. We don't want to read JSON input before this so that we can
always translate incoming messages to dvalues and write them out
without queueing. Any pending JSON messages will be queued by the
OS instead.
Generic handshake format: only relies on initial version field.
undefined
0x80...0xbf: integers 0-63
pointer
0x60...0x7f: strings with length 0-31
Represent non-integers as IEEE double dvalues.
0xc0...0xff: integers 0-16383
Trial parse dvalue(s) and debug messages.
default logger
log.l = 0; // enable debug and trace logging
4-byte buffer
comment: for manual testing of binary/json parsing robustness
label: code-design
2-byte buffer
Parse message type, determine initial marker for binary message.
Note that typeof null === 'object'.
* Config
* Misc helpers
comment:
* JSON debug proxy written in DukLuv
*
* This single file JSON debug proxy implementation is an alternative to the
* Node.js-based proxy in duk_debug.js. DukLuv is a much smaller dependency
* than Node.js so embedding DukLuv in a debug client is easier.
label: code-design
Feed the data one byte at a time when torture testing.
When this is invoked the proxy connection and the target connection
have both been closed.
Add an EOM, and write out the dvalues to the debug target.
* Detect missing 'var' declarations
whole
not negative zero
Receive data into 'incoming', resizing as necessary.
explicit flag for e.g. v === undefined
disconnect target too (if not already disconnected)
comment: XXX: it'd be nice to log remote peer host:port
label: code-design
make a copy, ensuring there's no slice offset
get underlying plain buffer
Trial parse JSON message(s).
This is still pretty awkward in Duktape 1.4.x.
Argument may be a "slice" and we want a copy of the slice
(not the full underlying buffer).
comment: XXX: Code assumes uv.write() will write fully. This is not necessarily
true; should add support for partial writes (or at least failing when
a partial write occurs).
label: code-design
Prevent new bindings on global object. This detects missing 'var'
declarations, e.g. "x = 123;" in a function without declaring it.
object
lightfunc
skip dukluv and script name
null
More detailed v1 handshake line.
comment: unnecessary but just in case
label: code-design
4-byte string
comment: unused/none
label: code-design
don't register any sockets/timers etc to exit
comment: In lenient mode if JSON parse fails just send back an _Error
and ignore the line (useful for initial development).
In non-lenient mode drop the connection here; if the failed line
was a request the client is expecting a reply/error message back
(otherwise it may go out of sync) but we can't send a synthetic
one (as we can't parse the request).
label: code-design
Trial parse handshake unless done.
false
!/usr/bin/env python2
Merge debugger YAML metadata files and output a merged JSON metadata file.
#exec-status
#center-area
#part-middle
#part-footer
<span id="source-filename">?</span>
No source loaded
#about-dialog
#part-header
#left-area
#right-area
comment: XXX: how to minimize the chance we'll further communciate with the
server or reconnect to it? socket.reconnection()?
label: code-design
comment: XXX: prevent retry of no-such-file by negative caching?
label: code-design
Eval may take seconds to complete so indicate it is pending.
Bytecode dialog highlight
If previous update is pending, abort and start a new one.
http://diveintohtml5.info/storage.html
Note: loadedFileName can be either from target or from server, but they
must match exactly. We could do a loose match here, but exact matches
are needed for proper breakpoint handling anyway.
Remove eval button "pulsating" glow when we get a result
may be null
Remove pending highlight once we're no longer running.
Update the "console" output based on lines sent by the server. The server
rate limits these updates to keep the browser load under control. Even
better would be for the client to pull this (and other stuff) on its own.
* Duktape debugger web client
*
* Talks to the NodeJS server using socket.io.
*
* http://unixpapa.com/js/key.html
If we just became paused, check for eval watch
Make copies of the requested file/line so that we have the proper
values in case they've changed.
* UI update handling when exec-status update arrives
Active breakpoints follow
Exact match is required.
comment: XXX: any faster way; elems doesn't have e.g. indexOf()
label: code-design
comment: XXX: ignore issue with last empty line for now
label: code-design
returns a Manager
Update interval for custom source highlighting.
Duktape now restricts execution status updates quite effectively so
there's no need to rate limit UI updates now.
comment: XXX: hacky transition, make source change visible
label: code-design
puff
slide, puff
onclick handler for exec status text
Source is updated periodically. Other code can also call doSourceUpdate()
directly if an immediate update is needed.
* AJAX request handling to fetch source files
comment: XXX: error transition here
label: requirement
If we're executing the file shown, highlight current line
comment: Scroll to requested line. This is not very clean, so a better solution
should be found:
https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollIntoView
http://erraticdev.blogspot.fi/2011/02/jquery-scroll-into-view-plugin-with.html
http://flesler.blogspot.fi/2007/10/jqueryscrollto.html
label: code-design
Make source window grey when running for a longer time, use a small
delay to avoid flashing grey when stepping.
comment: Source view
file that we want to be loaded in source view
scroll to line once file has been loaded
line that we want to highlight (if any)
currently loaded (shown) file
currently loaded file line count
true if currFileName (loosely) matches loadedFileName
if set, scroll loaded file to requested line
highlight line
line numbers which have been modified
(added classes etc, tracked for removing)
timer for updating source view
current AJAX request for fetching a source file (if any)
hack to reset button states
bytecode dialog active
index of currently highlighted line (or null)
index to first line of bytecode instructions
label: code-design
Remove previously added custom classes
Not really interesting in the UI
$('#server-info').text(new Date() + ': ' + JSON.stringify(msg));
Not 100% reliable if callstack has several functions of the same name
If no-one requested us to scroll to a specific line, finish.
Update buttons
http://stackoverflow.com/questions/14918787/jquery-scroll-to-bottom-of-div-even-after-it-updates
Stop queued animations so that we always scroll quickly to bottom
First line is special
AJAX request for the source.
* Initialization
About dialog, shown automatically on first startup.
Enter handling for eval input
https://forum.jquery.com/topic/bind-html-input-to-enter-key-keypress
Eval watch handling
We'd like to window.close() here but can't (not allowed from scripts).
Alert is the next best thing.
float
Bytecode dialog
Force source view to match currFileName only when running or when
just became paused (from running or detached).
nop
Force line update (scrollTop) only when running or just became paused.
Otherwise let user browse and scroll source files freely.
Not worth alerting about because source fetch errors happen
all the time, e.g. for dynamically evaluated code.
Execution state
previous execution state ('paused', 'running', etc)
previous debugger attached state (true, false, null)
current filename being executed
current function name being executed
current line being executed
current bytecode PC being executed
current execution state ('paused', 'running', 'detached', etc)
current debugger attached state (true or false)
current local variables
current callstack (from top to bottom)
current breakpoints
timestamp when last started running (if running)
(used to grey out the source file if running for long enough)
* Source view periodic update handling
If we just started running, store a timestamp so we can grey out the
source view only if we execute long enough (i.e. we're not just
stepping).
comment: The variable value is parsed as JSON right now, but it'd be better to
also be able to parse buffer values etc.
label: code-design
* Init socket.io and add handlers
don't clear eval input
* AJAX request for fetching the source list
This is worth alerting about as the UI is somewhat unusable
if we don't get a source list.
Update current execution state
Add breakpoints
* Helpers
Pause may take seconds to complete so indicate it is pending.
This must fit into the smallest pool entry.
Define to enable some debug printfs.
Use 'st' as udata.
comment: #define DUK_ALLOC_HYBRID_DEBUG
label: code-design
comment:
* Example memory allocator with pool allocation for small sizes and
* fallback into malloc/realloc/free for larger sizes or when the pools
* are exhausted.
*
* Useful to reduce memory churn or work around a platform allocator
* that doesn't handle a lot of small allocations efficiently.
label: code-design
Still fits, no shrink support.
'ptr' cannot be NULL.
DUK_ALLOC_HYBRID_H_INCLUDED
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
comment:
* Example memory allocator with machine parseable logging.
*
* Also sizes for reallocs and frees are logged so that the memory
* behavior can be essentially replayed to accurately determine e.g.
* optimal pool sizes for a pooled allocator.
*
* Allocation structure:
*
* [ alloc_hdr | user area ]
*
* ^ ^
* | `--- pointer returned to Duktape
* `--- underlying malloc ptr
label: code-design
Suppress warning.
comment: DUK_ALLOC_LOGGING_H_INCLUDED
label: code-design
Note: ajduk doesn't log oldsize (uses -1 instead)
comment: !/usr/bin/env python2
Analyze allocator logs and write total-bytes-in-use after every
operation to stdout. The output can be gnuplotted as:
$ python log2gnuplot.py </tmp/duk-alloc-log.txt >/tmp/output.txt
$ gnuplot
> plot "output.txt" with lines
label: code-design
A ptr/NULL/FAIL size
F ptr/NULL size
R ptr/NULL oldsize ptr/NULL/FAIL newsize
comment:
* Example torture memory allocator with memory wiping and check for
* out-of-bounds writes.
*
* Allocation structure:
*
* [ alloc_hdr | red zone before | user area | red zone after ]
*
* ^ ^
* | `--- pointer returned to Duktape
* `--- underlying malloc ptr
label: code-design
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
Suppress warning.
Force address change on every realloc.
DUK_ALLOC_TORTURE_H_INCLUDED
* Enter interactive mode if options indicate it
[ ... bytecode_filename src_data src_len filename ]
* Main
Example of sending an application specific debugger notification.
'p' points to a NUL (p == p_end) or a period.
avoid SIGPIPE killing process
Full completion, add a period, e.g. input 'Math' -> 'Math.'.
Here we know the eval arg exists but check anyway
DUK_CMDLINE_RLIMIT
* Misc helpers
A virtual '/tmp' exists by default:
* https://gist.github.com/evanw/e6be28094f34451bd5bd#file-temp-js-L3806-L3809
DUK_CMDLINE_LINENOISE_COMPLETION
Callback should avoid errors for now, so use
* duk_check_stack() rather than duk_require_stack().
Manual test for bytecode dump/load cycle: dump and load before
* execution. Enable manually, then run "make qecmatest" for a
* reasonably good coverage of different functions and programs.
try {
FS.unmount("/");
} catch (e) {
console.log("Failed to unmount default '/' MEMFS mount: " + e);
}
original, including partial last component
Ensure socket is closed even when detach is initiated by Duktape
* rather than debug client.
* Minimal Linenoise completion support
caller coerces
[ ... bytecode_filename src_data src_len function ]
Optional bytecode dump.
Print error objects with a stack trace specially.
* Note that getting the stack trace may throw an error
* so this also needs to be safe call wrapped.
* Duktape heap lifecycle
Manual test for duk_debugger_cooperate()
'idx_obj' points to the object matching the last
* full component, use [p_curr,p[ as a filter for
* that object.
Running stdin like a full file (reading all lines before
* compiling) is useful with emduk:
* cat test.js | ./emduk --run-stdin
should never happen, but just in case
Catches e.g. 'foo..bar' -> we want 'bar' only.
Print error to stderr and pop error.
* Signal handling setup
~2 GB
comment:
* Cleanup and exit
label: code-design
Partial ends in a period, e.g. 'Math.' -> complete all Math properties.
fatal_handler
comment: Very simplified "is identifier part" check.
label: code-design
Read until EOF, avoid fseek/stat because it won't work with stdin.
global
Defined in duk_cmdline_ajduk.c or alljoyn.js headers.
comment: This is not necessary but should be harmless.
label: code-design
'p' will either be p_start - 1 (ran out of buffer) or point to
* the first offending character.
nrets
comment: XXX: Here it'd be nice to get some stats for the compilation result
* when a suitable command line is given (e.g. code size, constant
* count, function count. These are available internally but not through
* the public API.
label: code-design
In non-interactive mode, success results are not written at all.
* It is important that the result value is not string coerced,
* as the string coercion may cause an error in some cases.
* In interactive mode, write to stdout so output won't
* interleave as easily.
*
* NOTE: the ToString() coercion may fail in some cases;
* for instance, if you evaluate:
*
* ( {valueOf: function() {return {}},
* toString: function() {return {}}});
*
* The error is:
*
* TypeError: failed to coerce with [[DefaultValue]]
* duk_api.c:1420
*
* These are handled now by the caller which also has stack
* trace printing support. User code can print out errors
* safely using duk_safe_to_string().
DUK_CMDLINE_FILEIO
comment: +25% and some extra
label: code-design
* Command line execution tool. Useful for test cases and manual testing.
*
* To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
* It is not the default to maximize portability. You can also compile in
* support for example allocators, grep for DUK_CMDLINE_*.
get_value
nret
for properties of plain strings etc
Not an Error instance, don't read "stack".
'this' binding
Source code.
comment: XXX: handle partial writes
label: code-design
DUK_CMDLINE_SIGNAL
comment: Emscripten specific: stdin EOF doesn't work as expected.
* Instead, when 'emduk' is executed using Node.js, a file
* piped to stdin repeats (!). Detect that repeat and cut off
* the stdin read. Ensure the loop repeats enough times to
* avoid detecting spurious loops.
*
* This only seems to work for inputs up to 256 bytes long.
label: code-design
skip code
* Simple file read/write bindings
* Usage
comment: XXX: There's no key quoting now, it would require replacing the
* last component with a ['foo\nbar'] style lookup when appropriate.
label: code-design
'p' now points to a string of the form 'foo.bar.quux'. Look up
* all the components except the last; treat the last component as
* a partial name which is used as a filter for the previous full
* component. All lookups are from the global object now.
p_curr == p_end allowed on purpose, to handle 'Math.' for example.
For automatic reattach testing.
Not found.
Use duk_compile_lstring_filename() variant which avoids interning
* the source code. This only really matters for low memory environments.
heap_udata: ignored by AjsHeap, use as marker
* Memory limit
fall thru
original, e.g. 'Math.'
DUK_CMDLINE_LINENOISE
* Execute from file handle etc
* Create heap
completion to last component
128 MB
signal(SIGPIPE, SIG_IGN);
EMSCRIPTEN
Bytecode.
in interactive mode, write to stdout
Try to use NODEFS to provide access to local files. Mount the
* CWD as /working, and then prepend "/working/" to relative native
* paths in file calls to get something that works reasonably for
* relative paths. Emscripten doesn't support replacing virtual
* "/" with host "/" (the default MEMFS at "/" can't be unmounted)
* but we can mount "/tmp" as host "/tmp" to allow testcase runs.
*
* https://kripken.github.io/emscripten-site/docs/api_reference/Filesystem-API.html#filesystem-api-nodefs
* https://github.com/kripken/emscripten/blob/master/tests/fs/test_nodefs_rw.c
comment: Suppress warnings about plain fopen() etc.
label: code-design
suppress warning
try {
FS.mkdir("/tmp");
} catch (e) {
console.log("Failed to create virtual /tmp: " + e);
}
Should never happen, just in case.
* Execute any argument file(s)
comment: duk_safe_call() cleans up
label: code-design
* Parse options
an error 'taints' the execution
At the moment it's not possible to replace the default MEMFS mounted at '/':
* https://github.com/kripken/emscripten/issues/2040
* https://github.com/kripken/emscripten/blob/incoming/src/library_fs.js#L1341-L1358
comment: This is useful at the global level; libraries should avoid SIGPIPE though
label: code-design
nargs
Helper define to enable a feature set; can also use separate defines.
Last component is partial, complete.
comment: Workaround for snprintf() missing in older MSVC versions.
* Note that _snprintf() may not NUL terminate the string, but
* this difference does not matter here as a NUL terminator is
* always explicitly added.
label: code-design
Ignore array index keys: usually not desirable, and would
* also require ['0'] quoting.
Scan backwards for a maximal string which looks like a property
* chain (e.g. foo.bar.quux).
skip filename
comment:
* Heap initialization when using AllJoyn.js pool allocator (without any
* other AllJoyn.js integration). This serves as an example of how to
* integrate Duktape with a pool allocator and is useful for low memory
* testing.
*
* The pool sizes are not optimized here. The sizes are chosen so that
* you can look at the high water mark (hwm) and use counts (use) and see
* how much allocations are needed for each pool size. To optimize pool
* sizes more accurately, you can use --alloc-logging and inspect the memory
* allocation log which provides exact byte counts etc.
*
* https://git.allseenalliance.org/cgit/core/alljoyn-js.git
* https://git.allseenalliance.org/cgit/core/alljoyn-js.git/tree/ajs.c
label: code-design
This extern declaration is provided by duktape.h, array provided by duktape.c.
heapConfig
Enable heap dumps
duk_heap, with heap ptr compression, ROM strings+objects
...
Scan ROM pointer range for faster detection of "is 'p' a ROM pointer"
* later on.
heapSz
comment: not needed
label: requirement
numPools
comment:
* Simplified example of an external strings strategy where incoming strings
* are written sequentially into a fixed, memory mapped flash area.
*
* The example first scans if the string is already in the flash (which may
* happen if the same string is interned multiple times), then adds it to
* flash if there is space.
*
* This example is too slow to be used in a real world application: there
* should be e.g. a hash table to quickly check for strings that are already
* present in the string data (similarly to how string interning works in
* Duktape itself).
label: code-design
* Not present yet, check if we have space. Again, be careful to
* ensure there is space for a NUL following the input data.
Linear scan. An actual implementation would need some acceleration
* structure, e.g. select a sublist based on first character.
*
* NOTE: input string (behind 'ptr' with 'len' bytes) DOES NOT have a
* trailing NUL character. Any strings returned from this function
* MUST have a trailing NUL character.
* 'ajduk' specific functionality, examples for low memory techniques
Pointer compression with ROM strings/objects:
*
* For now, use DUK_USE_ROM_OBJECTS to signal the need for compressed ROM
* pointers. DUK_USE_ROM_PTRCOMP_FIRST is provided for the ROM pointer
* compression range minimum to avoid duplication in user code.
to avoid empty source file
Ensure that we always get the heap_udata given in heap creation.
* (Useful for Duktape development, not needed for user programs.)
AjsHeap.dump(), allows Ecmascript code to dump heap status at suitable
* points.
heapNum
protected call not yet running
comment: The if-condition should be the fastest possible check
* for "is 'p' in ROM?". If pointer is in ROM, we'd like
* to compress it quickly. Here we just scan a ~1K array
* which is very bad for performance and for illustration
* only.
label: code-design
Ensure that we always get the heap_udata given in heap creation.
heap
* These strings are from util/duk_meta_to_strarray.py
comment:
* Check if we already have the string. Be careful to compare for
* NUL terminator too, it is NOT present in 'ptr'. This algorithm
* is too simplistic and way too slow for actual use.
label: code-design
duk_heap, with heap ptr compression, RAM strings+objects
This is a blind lookup, could check index validity.
* Duktape should never decompress a pointer which would
* be out-of-bounds here.
comment:
* External strings strategy intended for valgrind testing: external strings
* are allocated using malloc()/free() so that valgrind can be used to ensure
* that strings are e.g. freed exactly once.
label: code-design
* These strings are manually added, and would be gathered in some
* application specific manner.
comment: It's not worth it to make very small strings external, as
* they would take the same space anyway. Also avoids zero
* length degenerate case.
label: code-design
comment: Somewhat portable way of losing a const without warnings.
* Another approach is to cast through intptr_t, but that
* type is not always available.
label: code-design
* Example pointer compression functions.
*
* 'base' is chosen so that no non-NULL pointer results in a zero result
* which is reserved for NULL pointers.
* There is space, add the string to our collection, being careful
* to append the NUL.
DUK_CMDLINE_AJSHEAP
comment:
* Wrapped ajs_heap.c alloc functions
*
* Used to write an alloc log.
label: code-design
until_nul
We should really never be here: Duktape should only be
* compressing pointers which are in the ROM compressed
* pointers list, which are known at 'make dist' time.
* We go on, causing a pointer compression error.
* Simplified example of an external strings strategy where a set of strings
* is gathered during application compile time and baked into the application
* binary.
*
* Duktape built-in strings are available from duk_build_meta.json, see
* util/duk_meta_to_strarray.py. There may also be a lot of application
* specific strings, e.g. those used by application specific APIs. These
* must be gathered through some other means, see e.g. util/scan_strings.py.
* Execution timeout example
See userdata discussion in ajsheap_enc16().
duk_hthread, with heap ptr compression, ROM strings+objects
comment: potentially unused
label: code-design
comment: Userdata is not needed in this case but would be useful if heap
* pointer compression were used for multiple heaps. The userdata
* allows the callback to distinguish between heaps and their base
* pointers.
*
* If not needed, the userdata can be left out during compilation
* by simply ignoring the userdata argument of the pointer encode
* and decode macros. It is kept here so that any bugs in actually
* providing the value inside Duktape are revealed during compilation.
label: code-design
numHeaps
* Helpers
seconds
* Convert an 8-bit input string (e.g. ISO-8859-1) into CESU-8.
* Calling code supplies the "code page" as a 256-entry array of
* codepoints for the conversion.
*
* This is useful when input data is in non-UTF-8 format and must
* be converted at runtime, e.g. when compiling non-UTF-8 source
* code. Another alternative is to use e.g. iconv.
Temporary buffer length wraps.
max expansion is 1 input byte -> 3 output bytes
Decode an 8-bit string using 'codepage' into Unicode codepoints and
* re-encode into CESU-8. Codepage argument must point to a 256-entry
* table. Only supports BMP (codepoints U+0000 to U+FFFF).
[ ... tmp res ]
In CESU-8 all codepoints in [0x0000,0xFFFF] are
* allowed, including surrogates.
DUK_CODEPAGE_CONV_H_INCLUDED
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
Example: compile and run test source encoded in Windows codepage 1252.
undefined
Exercise all 3 byte lengths: any ASCII character is 1 byte, 0xFC maps to
* U+00FC which is 2 bytes, and 0x80 maps to U+20AC which is 3 bytes.
* Same as above, but if the exception inherits from std::exception, it's
* "what()" will be included in the error message.
* If you let your own C++ exceptions propagate out of a Duktape/C function
* it will be caught by Duktape and considered a programming error. Duktape
* will catch the exception and convert it to a Duktape error.
*
* This may be allowed in a later version once all the implications have been
* worked out.
ERROR: exception propagated to Duktape
* Example class with a destructor
suppress warning
* Example of how to use DUK_USE_CPP_EXCEPTIONS to support automatic
* variables (e.g. destructor calls) in Duktape/C functions.
*
* Compile with -DDUK_OPT_CPP_EXCEPTIONS:
*
* $ g++ -otest -DDUK_OPT_CPP_EXCEPTIONS -I<duktape_dist>/src/ \
* <duktape_dist>/src/duktape.c cpp_exceptions.cpp -lm
*
* or ensure duk_config.h has DUK_USE_CPP_EXCEPTIONS enabled using
* genconfig. When executed you should see something like:
*
* $ ./test
* my_class instance created
* my_class instance destroyed <== destructor gets called
* --> rc=1 (SyntaxError: parse error (line 1))
* [...]
*
* Duktape uses a custom exception class (duk_internal_exception) which
* doesn't inherit from any base class, so that catching any base classes
* in user code won't accidentally catch exceptions thrown by Duktape.
* You can use C++ exceptions inside Duktape/C functions for your own
* purposes but you should catch them before they propagate to Duktape.
* SyntaxError caused by eval exits Duktape/C function but destructors
* are executed.
* Same as above, but if the exception inherits from std::exception with
* a NULL what(). Duktape will describe the error as 'unknown' if so.
Handshake line is available for caller for the
* duration of the callback, and must not be freed
* by the caller.
Too small, resize.
just in case, if dvalues changed something
mixed endian (arm)
Define to enable error prints to stderr.
0x80 ... 0xbf
comment: IEEE double byte order, detect at run time (could also use
* preprocessor defines but that's verbose to make portable).
*
* >>> struct.unpack('>d', '1122334455667788'.decode('hex'))
* (3.841412024471731e-226,)
* >>> struct.unpack('>d', '8877665544332211'.decode('hex'))
* (-7.086876636573014e-268,)
* >>> struct.unpack('>d', '4433221188776655'.decode('hex'))
* (3.5294303071877444e+20,)
label: code-design
Handshake line is returned as a dvalue for convenience; it's
* not actually a part of the dvalue phase of the protocol.
Too big, resize so that we reclaim memory if we have just
* received a large string/buffer value.
little endian
0x00 ... 0x1f
comment:
* Example debug transport with a local debug message encoder/decoder.
*
* Provides a "received dvalue" callback for a fully parsed dvalue (user
* code frees dvalue) and a "cooperate" callback for e.g. UI integration.
* There are a few other callbacks. See test.c for usage examples.
*
* This transport implementation is not multithreaded which means that:
*
* - Callbacks to "received dvalue" callback come from the Duktape thread,
* either during normal execution or from duk_debugger_cooperate().
*
* - Calls into duk_trans_dvalue_send() must be made from the callbacks
* provided (e.g. "received dvalue" or "cooperate") which use the active
* Duktape thread.
*
* - The only exception to this is when Duktape is idle: you can then call
* duk_trans_dvalue_send() from any thread (only one thread at a time).
* When you next call into Duktape or call duk_debugger_cooperate(), the
* queued data will be read and processed by Duktape.
*
* There are functions for creating and freeing values; internally they use
* malloc() and free() for memory management. Duktape heap alloc functions
* are not used to minimize disturbances to the Duktape heap under debugging.
*
* Doesn't depend on C99 types; assumes "int" is at least 32 bits, and makes
* a few assumptions about format specifiers.
label: code-design
never here
0x60 ... 0x7f
Caller must provide a buffer at least DUK_DVALUE_TOSTRING_BUFLEN in size.
Harmless warning on some platforms (re: range)
Alloc size is len + 1 so that a NUL terminator is always
* guaranteed which is convenient, e.g. you can printf() the
* value safely.
big endian
Integers are network endian, read back into host format.
Portable IEEE double byteswap. Relies on runtime detection of
* host endianness.
Integers are written in network endian format.
IEEE doubles are network endian, read back into host format.
32 hex encoded or \xXX escaped bytes, possible "...", NUL
* Dvalue transport handling
Integers are network endian, read back into host format in
* a portable manner.
0xc0 ... 0xff
* Dvalue handling
comment: Define to enable debug prints to stderr.
label: code-design
end switch
* Duktape callbacks
Portable sign handling, doesn't assume 'int' is exactly 32 bits
* like a direct cast would.
Trial parse handshake line or dvalue(s).
IEEE doubles are written in network endian format.
Must cooperate until user callback provides data. From
* Duktape's perspective we MUST block until data is received.
mixed endian
0x20 ... 0x5f
comment: some extra to reduce resizes
label: code-design
Append data.
When read_offset is large enough, "rebase" buffer by deleting already
* read data and updating offsets.
big endian: ok as is
Convert argument dvalue into Duktape debug protocol format.
* Literal constants are used here for the debug protocol,
* e.g. initial byte 0x02 is REP, see doc/debugger.rst.
tolerates NULL
d: ieee double
sending towards Duktape (duktape read callback)
Buffer size needed by duk_dvalue_to_string().
buf: buffer data, len: buffer length
DUK_TRANS_DVALUE_H_INCLUDED
struct duk_dvalue 'tag' values, note that these have nothing to do with
* Duktape debug protocol inital byte. Struct fields used with the type
* are noted next to the define.
i: class number, buf: pointer data, len: pointer length
i: 32-bit signed integer
buf: pointer data, len: pointer length
Sending dvalues towards Duktape.
Duktape debug callbacks provided by the transport.
receiving from Duktape (duktape write callback)
buf: string data, len: string length
Could use a union for the value but the gain would be relatively small.
no fields
comment: 0=little endian, 1=big endian, 2=mixed endian
label: code-design
Initializing and freeing the transport context.
Dvalue handling.
i: lightfunc flags, buf: pointer data, len: pointer length
Attach debugger; this will fail with a fatal error here unless
* debugger support is compiled in. To fail more gracefully, call
* this under a duk_safe_call() to catch the error.
DumpHeap
fake ptr len
The Duktape handshake line is given in 'line' (without LF).
* The 'line' argument can be accessed for the duration of the
* callback (read only). Don't free 'line' here, the transport
* handles that.
medium, >= 32 chars
Evaluate simple test code, callbacks will "step over" until end.
*
* The test code here is just for exercising the debug transport.
* The 'evalMe' variable is evaluated (using debugger command Eval)
* before every step to force different dvalues to be carried over
* the transport.
duk_trans_dvalue_send_req_cmd() sends a REQ dvalue followed by
* an integer dvalue (command) for convenience.
classnum
Detached call forwarded as is.
0x14 = StepOver
* Example program using the dvalue debug transport.
long buffer, >= 65536 chars
TriggerStatus
suppress warning
Here a normal debug client would wait for dvalues until an EOM
* dvalue was received (which completes a debug message). The
* debug message would then be handled, possibly causing UI changes
* and/or causing debug commands to be sent to Duktape.
*
* The callback is responsible for eventually freeing the dvalue.
* Here we free it immediately, but an actual client would probably
* gather dvalues into an array or linked list to handle when the
* debug message was complete.
Duktape is not blocked; you can cooperate with e.g. a user
* interface here and send dvalues to Duktape, but don't block.
Also send a dummy TriggerStatus request with trailing dvalues
* ignored by Duktape; Duktape will parse the dvalues to be able to
* skip them, so that the dvalue encoding is exercised.
0x1e = Eval
comment: First time Duktape becomes blocked, send DumpHeap which
* exercises a lot of parsing code.
*
* NOTE: Valgrind may complain about reading uninitialized
* bytes. This is caused by the DumpHeap command writing out
* verbatim duk_tval values which are intentionally not
* always fully initialized for performance reasons.
label: code-design
short, <= 31 chars
Duktape is blocked on a read and won't continue until debug
* command(s) are sent.
*
* Normally you'd enter your own event loop here, and process
* events until something needs to be sent to Duktape. For
* example, the user might press a "Step over" button in the
* UI which would cause dvalues to be sent. You can then
* return from this callback.
*
* The code below sends some example messages for testing the
* dvalue handling of the transport.
*
* If you create dvalues manually and send them using
* duk_trans_dvalue_send(), you must free the dvalues after
* the send call returns using duk_dvalue_free().
lf_flags
DUK_TRANS_SOCKET_H_INCLUDED
comment: XXX: For now, close the listen socket because we won't accept new
* connections anyway. A better implementation would allow multiple
* debug attaches.
label: code-design
Duktape debug transport callback: (possibly partial) read.
This shouldn't happen.
should never happen
This TCP transport requires no write flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
* Example debug transport using a Linux/Unix TCP socket
*
* Provides a TCP server socket which a debug client can connect to.
* After that data is just passed through.
This TCP transport requires no read flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
backlog
In a production quality implementation there would be a sanity
* timeout here to recover from "black hole" disconnects.
Duktape debug transport callback: (possibly partial) write.
Write flush. If the transport combines multiple writes
* before actually sending, a write flush is an indication
* to write out any pending bytes: Duktape may not be doing
* any more writes on this occasion.
* Transport init and finish
* Duktape callbacks
nothing to read
also returns 0, which is correct
Read flush: Duktape may not be making any more read calls at this
* time. If the transport maintains a receive window, it can use a
* read flush as a signal to update the window status to the remote
* peer. A read flush is guaranteed to occur before Duktape stops
* reading for a while; it may occur in other situations as well so
* it's not a 100% reliable indication.
comment: not needed by the example
label: requirement
something to read
comment: XXX: For now, close the listen socket because we won't accept new
* connections anyway. A better implementation would allow multiple
* debug attaches.
label: code-design
Duktape debug transport callback: (possibly partial) read.
comment: MinGW workaround for missing getaddrinfo() etc:
* http://programmingrants.blogspot.fi/2009/09/tips-on-undefined-reference-to.html
label: code-design
This shouldn't happen.
This TCP transport requires no write flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
This TCP transport requires no read flush handling so ignore.
* You can also pass a NULL to duk_debugger_attach() and not
* implement this callback at all.
In a production quality implementation there would be a sanity
* timeout here to recover from "black hole" disconnects.
Duktape debug transport callback: (possibly partial) write.
Write flush. If the transport combines multiple writes
* before actually sending, a write flush is an indication
* to write out any pending bytes: Duktape may not be doing
* any more writes on this occasion.
* Transport init and finish
* Example debug transport using a Windows TCP socket
*
* Provides a TCP server socket which a debug client can connect to.
* After that data is just passed through.
*
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
*
* Compiling 'duk' with debugger support using MSVC (Visual Studio):
*
* > cl /W3 /O2 /Feduk.exe
* /DDUK_OPT_DEBUGGER_SUPPORT /DDUK_OPT_INTERRUPT_COUNTER
* /DDUK_CMDLINE_DEBUGGER_SUPPORT
* /Iexamples\debug-trans-socket /Isrc
* examples\cmdline\duk_cmdline.c
* examples\debug-trans-socket\duk_trans_socket_windows.c
* src\duktape.c
*
* With MinGW:
*
* $ gcc -oduk.exe -Wall -O2 \
* -DDUK_OPT_DEBUGGER_SUPPORT -DDUK_OPT_INTERRUPT_COUNTER \
* -DDUK_CMDLINE_DEBUGGER_SUPPORT \
* -Iexamples/debug-trans-socket -Isrc \
* examples/cmdline/duk_cmdline.c \
* examples/debug-trans-socket/duk_trans_socket_windows.c \
* src/duktape.c -lm -lws2_32
* Duktape callbacks
also returns 0, which is correct
nothing to read
never here
Read flush: Duktape may not be making any more read calls at this
* time. If the transport maintains a receive window, it can use a
* read flush as a signal to update the window status to the remote
* peer. A read flush is guaranteed to occur before Duktape stops
* reading for a while; it may occur in other situations as well so
* it's not a 100% reliable indication.
comment: not needed by the example
label: requirement
something to read
Return a fixed time here as a dummy example.
* Dummy Date provider
*
* There are two minimally required macros which you must provide in
* duk_config.h:
*
* extern duk_double_t dummy_get_now(void);
*
* #define DUK_USE_DATE_GET_NOW(ctx) dummy_get_now()
* #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) 0
*
* Note that since the providers are macros, you don't need to use
* all arguments. Similarly, you can "return" fixed values as
* constants. Above, local timezone offset is always zero i.e.
* we're always in UTC.
*
* You can also provide optional macros to parse and format timestamps
* in a platform specific format. If not provided, Duktape will use
* ISO 8601 only (which is often good enough).
* Very simple example program for evaluating expressions from
* command line
nargs
nrets
* A few basic tests
XXX: or t->target + t->delay?
comment: Active timers. Dense list, terminates to end of list or first unused timer.
* The list is sorted by 'target', with lowest 'target' (earliest expiry) last
* in the list. When a timer's callback is being called, the timer is moved
* to 'timer_expiring' as it needs special handling should the user callback
* delete that particular timer.
label: code-design
ignore errors for now -> [ ... stash eventTimers ]
not found, append to list
Initialize global stash 'eventTimers'.
Update timer_count.
Misc
-> [ ... ]
-> [ ... stash eventTimers retval ]
One-shot timer (always removed) or removed by user callback.
Finally, register the callback to the global stash 'eventTimers' object.
* Determine poll() timeout (as close to poll() as possible as
* the wait is relative).
Interval timer, not removed by user callback. Queue back to
* timer list and bubble to its final sorted position.
deleted, perhaps by previous callback
Timer is now at the last position; use swaps to "bubble" it to its
* correct sorted position.
* If exit has been requested, exit without running further
* callbacks.
comment: mark to-be-deleted, cleaned up by next poll
label: code-design
last timer at timer_count - 1
Zero last element for clarity.
Socket poll state.
[ ... stash eventTimers ]
error
* Compact poll list by removing pollfds with fd == 0.
Set global 'EventLoop'.
eventTimers[timer_id] = callback
comment: zeroize unused entries for sanity
label: code-design
Last timer expires first (list is always kept sorted).
-> [ ... stash eventTimers func ]
delay/interval
oneshot=1 (setTimeout), repeated=0 (setInterval)
The callback associated with the timer is held in the "global stash",
* in <stash>.eventTimers[String(id)]. The references must be deleted
* when a timer struct is deleted.
Get Javascript compatible 'now' timestamp (millisecs since 1970).
events == 0 means stop listening to the FD
-> [ timer_id stash eventTimers ]
* Expire timers.
Shift elements downwards to keep the timer list dense
* (no need if last element).
* If exit requested, bail out as fast as possible.
't' expires later than 't-1', so swap them and repeat.
Timer to bubble is at index i, timer to compare to is
* at i-1 (both guaranteed to exist).
Return timer id.
Bubble last timer on timer list backwards until it has been moved to
* its proper sorted position (based on 'target' time).
next target time
i = input index
* j = output index (initially same as i)
The C state is now up-to-date, but we still need to delete
* the timer callback state from the global 'stash'.
'rc' fds active
clamping ensures that fits
* Expired timer(s) still exist?
timeout
* Move the timer to 'expiring' for the duration of the callback.
* Mark a one-shot timer deleted, compute a new target for an interval.
* Call timer callback. The callback can operate on the timer list:
* add new timers, remove timers. The callback can even remove the
* expired timer whose callback we're calling. However, because the
* timer being expired has been moved to 'timer_expiring', we don't
* need to worry about the timer's offset changing on the timer list.
comment: this is quite excessive for embedded use, but good for testing
label: code-design
if timeout, no need to check pollfd
The Ecmascript poll handler is passed through EventLoop.fdPollHandler
* which c_eventloop.js sets before we come here.
indexes:
* 0 = function (callback)
* 1 = delay
* 2 = boolean: oneshot
-> [ func delay oneshot stash eventTimers ]
comment:
* Unlike insertion, deletion needs a full scan of the timer list
* and an expensive remove. If no match is found, nothing is deleted.
* Caller gets a boolean return code indicating match.
*
* When a timer is being expired and its user callback is running,
* the timer has been moved to 'timer_expiring' and its deletion
* needs special handling: just mark it to-be-deleted and let the
* expiry code remove it.
label: code-design
nargs
* Poll for activity or timeout.
copy only if indices have diverged
timer has been requested for removal
-> [ global EventLoop fdPollHandler ]
Because a user callback can mutate the timer list (by adding or deleting
* a timer), we expire one timer and then rescan from the end again. There
* is a sanity limit on how many times we do this per expiry round.
keep output index the same
comment:
* Check socket activity, handle all sockets. Handling is offloaded to
* Ecmascript code (fd + revents).
*
* If FDs are removed from the poll list while we're processing callbacks,
* the entries are simply marked unused (fd set to 0) without actually
* removing them from the poll list. This ensures indices are not
* disturbed. The poll list is compacted before next poll().
label: code-design
numeric ID (returned from e.g. setTimeout); zero if unused
Should never happen, so return whatever.
delete eventTimers[timer_id]
't' expires earlier than (or same time as) 't-1', so we're done.
indexes:
* 0 = timer id
comment:
* C eventloop example.
*
* Timer management is similar to eventloop.js but implemented in C.
* In particular, timer insertion is an O(n) operation; in a real world
* eventloop based on a heap insertion would be O(log N).
label: code-design
print('unexpected revents, close fd');
no size control now
print('READ', Duktape.enc('jx', data));
* C eventloop example (c_eventloop.c).
*
* Ecmascript code to initialize the exposed API (setTimeout() etc) when
* using the C eventloop.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
This simple example doesn't have support for write blocking / draining
Connected
print('ACCEPT:', Duktape.enc('jx', acc_res));
Special case: callback arguments are provided.
[ arg1, arg2, ... ]
[ global(this), arg1, arg2, ... ]
print('activity on fd', fd, 'revents', revents);
* Timer API
comment:
* Socket handling
*
* Ideally this would be implemented more in C than here for more speed
* and smaller footprint: C code would directly maintain the callback state
* and such.
*
* Also for more optimal I/O, the buffer churn caused by allocating and
* freeing a lot of buffer values could be eliminated by reusing buffers.
* Socket reads would then go into a pre-allocated buffer, for instance.
label: code-design
retval ignored
print('UNKNOWN');
Legacy case: callback is a string.
oneshot
Normal case: callback given as a function without arguments.
Math.exp(0)...Math.exp(8) is an uneven distribution between 1...~2980.
Here the inserts take a lot of time because the underlying timer manager
* data structure has O(n) insertion performance.
* Test using timers and intervals with curses.
* Pure Ecmascript eventloop example.
*
* Timer state handling is inefficient in this trivial example. Timers are
* kept in an array sorted by their expiry time which works well for expiring
* timers, but has O(n) insertion performance. A better implementation would
* use a heap or some other efficient structure for managing timers so that
* all operations (insert, remove, get nearest timer) have good performance.
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Timers
comment: If exit requested, don't call any more callbacks. This allows
a callback to do cleanups and request exit, and can be sure that
no more callbacks are processed.
label: code-design
Remove the timer from the active list and process it. The user
callback may add new timers which is not a problem. The callback
may also delete timers which is not a problem unless the timer
being deleted is the timer whose callback we're running; this is
why the timer is recorded in this.expiring so that clearTimeout()
and clearInterval() can detect this situation.
sockets
fd -> callback
fd -> callback
fd -> callback
If the timer was one-shot, it's marked 'removed'. If the user callback
requested deletion for the timer, it's also marked 'removed'. If the
timer is an interval (and is not marked removed), insert it back into
the timer list.
this.dumpState();
Timer has expired and we're processing its callback. User
callback has requested timer deletion. Mark removed, so
that the timer is not reinserted back into the active list.
This is actually a common case because an interval may very
well cancel itself.
Special case: callback arguments are provided.
[ arg1, arg2, ... ]
[ global(this), arg1, arg2, ... ]
This simple example doesn't have support for write blocking / draining
no such ID, ignore
print('zero read for fd ' + fd + ', closing forcibly');
ignore result
print('UNKNOWN');
Legacy case: callback is a string.
timers
active timers, sorted (nearest expiry last)
set to timer being expired (needs special handling in clearTimeout/clearInterval)
no size control now
print('READ', Duktape.enc('jx', data));
print('revents ' + t.revents + ' for fd ' + fd + ', closing forcibly');
ignore result
misc
print('ACCEPT:', Duktape.enc('jx', acc_res));
* Create poll socket list. This is a very naive approach.
* On Linux, one could use e.g. epoll() and manage socket lists
* incrementally.
start
deleteCount
* Find 'i' such that we want to insert *after* timers[i] at index i+1.
* If no such timer, for-loop terminates with i-1, and we insert at -1+1=0.
print('exit requested, exit');
Remove timer/interval with a timer ID. The timer/interval can reside
either on the active list or it may be an expired timer (this.expiring)
whose user callback we're running when this function gets called.
Get timer with lowest expiry time. Since the active timers list is
sorted, it's always the last timer.
* Wait timeout for timer closest to expiry. Since the poll
* timeout is relative, get this as close to poll() as possible.
print(new Date(), 'poll_set OUT:', Duktape.enc('jx', poll_set));
* Do the actual poll.
* Timer API
*
* These interface with the singleton EventLoop.
print('UNKNOWN POLLOUT');
Timers to expire?
* Exit check (may be requested by a user callback)
comment: Timer on active list: mark removed (not really necessary, but
nice for dumping), and remove from active list.
label: code-design
insert after 't', to index i+1
* Event loop
*
* Timers are sorted by 'target' property which indicates expiry time of
* the timer. The timer expiring next is last in the array, so that
* removals happen at the end, and inserts for timers expiring in the
* near future displace as few elements in the array as possible.
print(new Date(), 'poll_set IN:', Duktape.enc('jx', poll_set));
* Here we must be careful with mutations: user callback may add and
* delete an arbitrary number of timers.
*
* Current solution is simple: check whether the timer at the end of
* the list has expired. If not, we're done. If it has expired,
* remove it from the active list, record it in this.expiring, and call
* the user callback. If user code deletes the this.expiring timer,
* there is special handling which just marks the timer deleted so
* it won't get inserted back into the active list.
*
* This process is repeated at most maxExpirys times to ensure we don't
* get stuck forever; user code could in principle add more and more
* already expired timers.
custom call
* Process expired timers.
* Process all sockets so that nothing is left unhandled for the
* next round.
flag for removal
Timer has not expired, and no other timer could have expired
either because the list is sorted.
Reinsert interval timer to correct sorted position. The timer
must be an interval timer because one-shot timers are marked
'removed' above.
Eat errors silently. When resizing curses window an EINTR
happens now.
Normal case: callback given as a function without arguments.
Set global 'FileIo'.
* File I/O binding example.
comment: XXX: pcall the string coercion
label: code-design
fall thru
comment: This is useful at the global level; libraries should avoid SIGPIPE though
label: code-design
nargs
nrets
[ ... global func ]
Duktape/C function, safe called
nret
Start a zero timer which will call _USERCODE from within
* the event loop.
Finally, launch eventloop. This call only returns after the
* eventloop terminates.
signal(SIGPIPE, SIG_IGN);
Compile input and place it into global _USERCODE
Print error to stderr and pop error.
NO_SIGNAL
comment: XXX: print error objects specially
label: code-design
* Main for evloop command line tool.
*
* Runs a given script from file or stdin inside an eventloop. The
* script can then access setTimeout() etc.
Set global 'Ncurses'.
XXX: no screen management now
comment:
* Ncurses bindings example.
*
* VALGRIND NOTE: when you use ncurses, there seems to be no way to get a
* clean valgrind run. Even if ncurses state is properly shut down, there
* will still be some residual leaks.
*
* Debian: install libncurses5-dev
label: code-design
[retarr]
-> [... retarr key]
Linux 2.6.17 and upwards, requires _GNU_SOURCE etc, not added
* now because we don't use it.
-> [... retarr fd]
enum_flags
leave enum on stack
* C wrapper for poll().
update revents
Set global 'Poll' with functions and constants.
-> [... enum key val events]
-> [... enum key val]
-> [... enum]
-> [... retarr val "revents" fds[i].revents]
[... enum key]
rc = ppoll(fds, n, &ts, NULL);
-> [... enum key key]
-> [... retarr val]
uppercase
ensure we get a plain buffer
Handle socket data carefully: if you convert it to a string,
it may not be valid UTF-8 etc. Here we operate on the data
directly in the buffer.
backlog
Set global 'Socket'.
MSG_NOSIGNAL: avoid SIGPIPE
* TCP sockets binding example.
fib.js
Pure Ecmascript version of low level helper
Check 'val' for primality
prime.js
Select available helper at load time
Find primes below one million ending in '9999'.
primecheck.c
nargs
ignore result
process.js
nargs
index
processlines.c
pop result/error
ignore result
uppercase.c
We're going to need 'sz' additional entries on the stack.
one return value
* Very simple example program
pop global
#args
suppress warning
pop eval result
nargs
comment:
* Pretty print JSON from stdin into indented JX.
label: code-design
comment: suppress warnings
label: code-design
nrets
-1 for filename
comment: The double value in the union is there to ensure alignment is
* good for IEEE doubles too. In many 32-bit environments 4 bytes
* would be sufficiently aligned and the double value is unnecessary.
label: code-design
-> [ ... source filename ]
nrets
* Main
* Setup sandbox
Handle the ptr-NULL vs. size-zero cases explicitly to minimize
* platform assumptions. You can get away with much less in specific
* well-behaving environments.
must not return
256kB sandbox
* Sandboxing example
*
* Uses custom memory allocation functions which keep track of total amount
* of memory allocated, imposing a maximum total allocation size.
-> [ ... filename source ]
* Sandbox setup and test
Should be zero.
Suppress warning.
nargs
flags
Compile as program
* Memory allocator which backs to standard library memory functions but
* keeps a small header to track current allocation size.
*
* Many other sandbox allocation models are useful, e.g. preallocated pools.
* Execute code from specified file
* Mandelbrot example:
*
* $ ./duk mandel.js
* [...]
z -> z^2 + c
* -> (xx+i*yy)^2 + (x0+i*y0)
* -> xx*xx+i*2*xx*yy-yy*yy + x0 + i*y0
* -> (xx*xx - yy*yy + x0) + i*(2*xx*yy + y0)
xx^2 + yy^2 >= 4.0
capture in closure in case changed later
* Minimal console.log() polyfill
nop
* Ensure Error .fileName, .lineNumber, and .stack are not directly writable,
* but can be written using Object.defineProperty(). This matches Duktape
* 1.3.0 and prior.
*
* See: https://github.com/svaarala/duktape/pull/390.
already non-writable
already writable
* Ensure Error .fileName, .lineNumber, and .stack are directly writable
* without having to use Object.defineProperty(). This matches Duktape
* 1.4.0 behavior.
*
* See: https://github.com/svaarala/duktape/pull/390.
tag for unpacked duk_tval
tag for packed duk_tval
internal tag is fastint
public type is DUK_TYPE_NUMBER
* Helper to check if a number is internally represented as a fastint:
*
* if (Duktape.isFastint(x)) {
* print('fastint');
* } else {
* print('not a fastint (or not a number)');
* }
*
* NOTE: This helper depends on the internal tag numbering (defined in
* duk_tval.h) which is both version specific and depends on whether
* duk_tval is packed or not.
Tag number depends on duk_tval packing.
null or undefined
enumerable own keys
* Object.assign(), described in E6 Section 19.1.2.1
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.assign
* Object.prototype.__defineGetter__ polyfill
* Object.prototype.__defineSetter__ polyfill
comment:
* Performance.now() polyfill
*
* http://www.w3.org/TR/hr-time/#sec-high-resolution-time
*
* Dummy implementation which uses the Date built-in and has no higher
* resolution. If/when Duktape has a built-in high resolution timer
* interface, reimplement this.
label: code-design
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: 0a70d7e4c5227c84e3fed5209828973117d02849
* Git describe: v1.8.0
* Git branch: v1.8-maintenance
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
alloc external with size zero
'i' is the first entry we'll keep
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
resend state next time executor is about to run
comment: XXX: avoid this check somehow
label: code-design
Should match Function.prototype.toString()
* Main struct
'/'
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Duktape.modLoaded[] module cache
[ obj handler trap ]
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
comment: size for formatting buffers
label: code-design
default case exists: go there if no case matches
registers are mutable, non-deletable
'{'
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
get or set a range of flags; m=first bit number, n=number of bits
[ level obj func pc line ]
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
[ arg1 ... argN this ]
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
Allocator functions.
next does not exist or next is not a letter
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
'enum'
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
just making sure
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
String table assert check omitted from 1.x branch
* backport.
comment: XXX: string not shared because it is conditional
label: code-design
carry
Initial bytes for markers.
queue back to heap_allocated
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
print provider
form: { DecimalDigits , }, val1 = min count
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
DUK_TOK_LPAREN
caller ensures; rom objects are never bufferobjects now
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
1 -> needs a PUTVAR
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
leave out trailing 'unused' elements
comment: TODO: implement Proxy object support here
label: requirement
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
args start at index 2
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
eat colon
always set; points to a reserved valstack slot
Track number of escapes: necessary for proper keyword
* detection.
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
should never happen but default here
'env'
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
-> [val]
emitted
resume delete to target
-> [... obj]
success
+0.0
replacer is a mutation risk
parse key and value
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
No duk_bw_remove_ensure_slice(), functionality would be identical.
if boolean matches A, skip next inst
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
[ ... val ]
'true'
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
For now shared handler is fine.
may be less, since DELETED entries are NULLed by rehash
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
OK
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
maximum loopcount for peephole optimization
cleared before entering finally
flags for duk_hobject_get_own_propdesc() and variants
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
useful for patching jumps later
avoid attempts to add/remove object keys
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Local defines
comment: XXX: compression
label: code-design
already NULLed (by unwind)
Don't allow actual chars after equal sign.
-> [ Object defineProperty undefined obj key desc ]
whether to use macros or helper function depends on call count
DUK_USE_FASTINT
7: toISOString
comment: XXX: "read only object"?
label: code-design
no action
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
must hold DUK_VARARGS
capture is 'undefined', always matches!
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
'raw'
DUK_TOK_RPAREN
request to create catch binding
for object-bound identifiers
comment: XXX: compression (as an option)
label: code-design
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
first coerce to a plain value
-> [ ... func varmap enum ]
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
force_global
NB: use 's' as temp on purpose
Not odd, or y == -Infinity
* Global object built-ins
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
[ body formals ], formals is comma separated list that needs to be parsed
bytecode execution
thisArg
* Not found
XXX: duk_uarridx_t?
E5 Section 9.4, ToInteger()
force_new
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
avoid dereference after potential callstack realloc
* Pass 2
compensate for eval() call
set values into ret array
* Pick an object from the head (don't remove yet).
fast path
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
[ ... this tracedata sep this ]
* After arguments, allocate special registers (like shuffling temps)
[ ToObject(this) item1 ... itemN arr item(i) ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
This behavior mostly mimics Node.js now.
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
Encode a fastint from duk_tval ptr, no value stack effects.
Already declared, update value.
'has'
DUK_TOK_COMMA
'void'
bufwriter for code
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
* UTF-8 / XUTF-8 / CESU-8 constants
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
DUK_TOK_IDENTIFIER
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
[ ... func varmap enum key value this ]
1: toDateString
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
Positive if local time ahead of UTC.
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
save stack top
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
Treat like a debugger statement: ignore when not attached.
'import'
Duktape/C API guaranteed entries (on top of args)
avoid warning (unsigned)
Helper which can be called both directly and with duk_safe_call().
[ ... template ]
-> [ buffer ]
comment: XXX: Here a "slice copy" would be useful.
label: code-design
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
duk_unicode_ids_m_let_noa[]
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
indirect allocs
Lightfuncs are always considered strict.
implies DUK_HOBJECT_IS_BUFFEROBJECT
safe, because matched (NUL causes a break)
* Packed tval sanity
longjmp type
should be first on 64-bit platforms
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[ ... | (crud) errobj ]
expensive flag
validation performed by duk__hexval
non-strict equality from here on
allocate catcher and populate it (should be atomic)
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
if 0, 'str16' used, if > 0, 'strlist16' used
probe sequence (open addressing)
token was preceded by a lineterm
-> [ ... ]
* Store entry state.
Perform an intermediate join when this many elements have been pushed
* on the value stack.
duk_unicode_ids_m_let_noabmp[]
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
'return'
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
comment: log level could be popped but that's not necessary
label: code-design
thread currently running (only one at a time)
numargs
already defined, good
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
Copy term name until end or '/'.
-> [ ... trap handler ]
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
DUK_TOK_DEBUGGER
Init newly allocated slots (only).
a complex (new) atom taints the result
[this value]
See: test-bug-tailcall-preventyield-assert.c.
check_object_coercible
comment: XXX: source code property
label: code-design
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
comment: XXX: unnecessary, handle in adjust
label: code-design
[ ... key trap handler ]
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
const
even for zero-length string
eat 'if'
14: getDay
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
function: create an arguments object on function call
-> [... target]
* Nice debug log.
comment: XXX: copy flags using a mask
label: code-design
[ ... func/retval ] -> [ ... ]
comment: XXX: optimize loops
label: code-design
up to 36 bit codepoints
no fractions in internal time
ditto
[key] -> []
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
[ buf? res ]
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
undefined -> skip (replaced with empty)
eat opening quote on first loop
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
no need to decref
18: getMinutes
'exports'
* Unicode letter check.
DUK_USE_MATH_BUILTIN
No field needed when strings are in ROM.
value was undefined/unsupported
eat 'function'
keep in valstack
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
step 11
IdentifierPart production with IdentifierStart and ASCII excluded
Internal timevalue is already NaN, so don't touch it.
flag for later write
GH-303
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
DUK_TOK_SEMICOLON
return value from Duktape.Thread.yield()
No need to re-lookup 'act' at present: no side effects.
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Parts are in local time, convert when setting.
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
Backup 'caller' property and update its value.
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
Add function object.
finalization
[ ToObject(this) item1 ... itemN arr ]
0x50...0x5f
Rule table: first matching rule is used to determine what to do next.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* Init the heap object
Inherit from ROM-based global object: less RAM usage, less transparent.
Note: 0xff != DUK_BC_C_MAX
COMMA
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
comment: function must not be tail called
label: code-design
stage 3: update length (done by caller), decide return code
idx_space
statement does not terminate directive prologue
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
* Table for hex decoding ASCII hex digits
function: create new environment when called (see duk_hcompiledfunction)
pop regexp res_obj or match string
P
required if NAMEBINDING set
slow path decode
don't care value, year is mandatory
really 'not applicable' anymore, should not be referenced after this
skip jump conditionally
* Flags parsing (see E5 Section 15.10.4.1).
for updating (all are set to < 0 for virtual properties)
* Run (object) finalizers in the "to be finalized" work list.
'warn'
DUK_USE_FILE_IO
[... constructor arg1 ... argN final_cons fallback]
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
'Array' object, array length and index exotic behavior
a statement following a label cannot be a source element
* (a function declaration).
24: setMilliseconds
'\xffVarenv'
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
DUK_TOK_BREAK
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
DUK_TOK_MOD_EQ
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
Note: DST adjustment is determined using UTC time.
caller must check
2
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
log this with a normal debug level because this should be relatively rare
* Ecmascript execution, support primitives.
* replace()
out_clamped=NULL, RangeError if outside range
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
idx_args = idx_func + 2
handle comma and closing bracket
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
Note: this allows creation of internal strings.
DUK__FLD_DOUBLE
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
caller and arguments must use the same thrower, [[ThrowTypeError]]
bound function 'length' property is interesting
DUK_REPLACEMENTS_H_INCLUDED
[ ... error func ]
expt 0x000 is zero/subnormal
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
restore PC
allow negative PCs, behave as a no-op
'\xffValue'
* Activation defines
Step 15: insert itemCount elements into the hole made above
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
XXX: ARRAY_PART for Array prototype?
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
string is a valid array index
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
'Number'
buffer is behind a pointer, dynamic or external
* in
allow caller to give a const number with the DUK__CONST_MARKER
DUK_USE_JSON_DECNUMBER_FASTPATH
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
XXX: use DUK_HSTRING_FLAG_INTERNAL?
func support for [[HasInstance]] checked in the beginning of the loop
%p
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
pop key
implementation specific
* Log level check
comment: XXX: unify handling with native call.
label: code-design
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
39: setYear
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
E5.1 Section 15.9.1.6
DUK_USE_JSON_QUOTESTRING_FASTPATH
always in executor
because of valstack init policy
embed: func ptr
local
Sanity check
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
* Manipulate callstack for the call.
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
'typeof'
Execute bytecode until returned or longjmp().
overflow not possible, buffer limits
'interface'
zero everything unless requested not to do so
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
* Node.js Buffer.isBuffer()
DUK_TOK_COLON
B -> target register for next key
* C -> enum register
-> [ ... flags escaped_source bytecode ]
backref n -> saved indices [n*2, n*2+1]
value1 -> error object
remove key
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
comment: For short strings, use a fixed temp buffer.
label: code-design
label limits
marker values for hash part
DUK_TOK_GE
-> [ ... closure ]
NULL pointer is required to encode to zero, so memset is enough.
else an array initializer element
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
35: setUTCMonth
[ ... retval ]
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
'new' MemberExpression Arguments
assume plain values
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
[ ... val obj ]
-> [ ... re_obj input bc saved_buf lastIndex ]
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Duktape/C (nativefunction) object, exotic 'length'
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
'this' binding
[ ... val key ] -> [ ... key val ]
isAccessor
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
skip opening slash on first loop
transfer flags
DUK_TOK_INTERFACE
may be undefined
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
iteration statements allow continue
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
'while'
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
object is constructable
regexp support disabled
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
assume keys are compacted
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
advance, whatever the current token is; parse next token in regexp context
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
regs to allocate
preallocated temporaries (2) for variants 3 and 4
[ regexp input ]
function: function object is strict
DUK_TOK_ALSHIFT
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
call is a direct eval call
varname is still reachable
Leave 'setter' on stack
seconds
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
DUK_USE_VARIADIC_MACROS
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
key is now reachable in the valstack
MakeDate
Request callback should push values for reply to client onto valstack
inserted jump
[enum_target res]
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
Then reuse the unwound activation; callstack was not shrunk so there is always space
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
for storing/restoring the varmap binding for catch variable
r <- (2 * f) * b^(e+1)
'[...]'
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
function is strict
must work for nargs <= 0
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
don't run finalizers; leave finalizable objects in finalize_list for next round
[this value] -> [value this]
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
2: toTimeString
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
* Initialize function state for a zero-argument function
Guaranteed by recursion_limit setup so we don't have to
* check twice.
line continuation
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
'-Infinity'
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
type tag (public)
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
don't re-enter e.g. during Eval
mp <- b^e
special handling of fmt==NULL
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
parse value
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
function may call direct eval
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
[ array totalLength ]
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
-> [ ... key val val' ]
[ ... re_obj input ] -> [ ... re_obj input bc ]
valstack slot for 1st token value
side effects, possibly errors
NOTE: Multiple evaluation of 'ptr' in this macro.
Overflow of the execution counter is fine and doesn't break
* anything here.
mark-and-sweep: finalized (on previous pass)
curr is accessor, desc is data
[ func thisArg arg1 ... argN ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
this function
comment: 'tv' becomes invalid
label: code-design
is an actual function (not global/eval code)
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
'callee'
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
'byteOffset'
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
no operators
Strict: never allow function declarations outside top level.
[ ... arg1 ... argN envobj ]
* Field access
0x30...0x3f
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
true
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
only use the highest bit
Function values are handled completely above (including
* coercion results):
distinct bignums, easy mistake to make
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
DUK_TOK_INSTANCEOF
time
update entry, allocating if necessary
A structure for 'snapshotting' a point for rewinding
* Ecmascript call
cannot be arguments exotic
comment: this is not strictly necessary, but helps debugging
label: code-design
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
push initial function call to new thread stack; this is
* picked up by resume().
31: setUTCHours
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
format plus something to avoid just missing
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
if property already exists, overwrites silently
comment: 'val' is never NaN, so no need to normalize
label: code-design
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
may be reg or const
decl name
rnd_state for duk_util_tinyrandom.c
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
jump is inserted here
misc
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
only flag now
[... func this arg1 ... argN]
record previous atom info in case next token is a quantifier
-""-
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
not enumerable
%f and %lf both consume a 'long'
* Catcher defines
never executed
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
'('
important to do this *after* pushing, to make the thread reachable for gc
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
Should not happen.
init pointer fields to null
* toString(), valueOf()
success, fixup pointers
comment: XXX: several pointer comparison issues here
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
Check that value is a duk_hbufferobject and return a pointer to it.
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
Note: assumes that duk_util_probe_steps size is 32
guaranteed when building arguments
updates thread state, minimizes its allocations
'{"_inf":true}'
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
comment: TimeClip() should never be necessary
label: code-design
0x10-0x1f
E5.1 Section B.2.2, step 7.
Parser part masks.
end switch (tok)
negative -> complex atom
-> [ ... val root "" ]
result array
XXX: fast path for arrays?
-> [ ... ToObject(this) ToUint32(length) ]
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
0x00...0x0f
coercion order matters
'jc'
1 if property found, 0 otherwise
fixed-format
not strictly necessary because of lookahead '}' above
comment: XXX: must be able to represent -len
label: code-design
DUK_USE_DPRINT_COLORS
expect_eof
borrowed reference to catch variable name (or NULL if none)
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
result index for filter()
either nonzero value is ok
bc
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
can't resize below 'top'
round up roughly to next 'grow step'
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
last array index explicitly initialized, +1
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
need side effects, not value
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
Note: for srclen=0, src may be NULL
never an empty match, so step 13.c.iii can't be triggered
Outer executor with setjmp/longjmp handling.
if B/C is >= this value, refers to a const
if debugging disabled
if true, the stack already contains the final result
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
when nothing is running, API calls are in non-strict mode
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
see duk_js_executor.c
Convert heap string index to a token (reserved words)
comment: XXX: refactor and share with other code
label: code-design
order must match constants in genbuiltins.py
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Ecmascript compliant [[Delete]](P, Throw).
-> [ ... str ]
args go here in parens
0xb0...0xbf
Write in big endian
only need to guarantee 1 more slot, but allocation growth is in chunks
comment: alloc function typedefs in duktape.h
label: code-design
i >= 0 would always be true
comment: XXX: inline into a prototype walking loop?
label: code-design
Lightfunc handling by ToObject() coercion.
DUK_BUFOBJ_UINT16ARRAY
'else'
'String' object, array index exotic behavior
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
Write unsigned 32-bit integer.
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
[ body formals source template closure ]
no refcount changes
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
First evaluate LHS fully to ensure all side effects are out.
properties object
Call handling and success path. Success path exit cleans
* up almost all state.
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
object is extensible
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
lookup name from an open declarative record's registers
relookup (side effects)
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
x <- y * z
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Catches >0x100000000 and negative values.
* Entry points
* Error built-ins
Packed or unpacked tval
* PC-to-line constants
top-down expression parser
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
fall through
x
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
fast path for ASCII
num_stack_res
%lx
* Not found as concrete or virtual
'Buffer'
[ ... env target target ]
DUK_TOK_LOR
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
triggers garbage digit check below
relevant array index is non-configurable, blocks write
comment: the NaN variant we use
label: code-design
* Compact the function template.
PRIMARY EXPRESSIONS
* indexOf(), lastIndexOf()
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
Automatic error throwing, retval check.
Fast path for the case where the register
* is a number (e.g. loop counter).
always push some string
spare
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
* Heap flags
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
get_value
clear array part flag only after switching
'!'
tv1 points to value storage
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
ascii fast path: avoid decoding utf-8
just in case
entry_top + 4
m- <- (* m- B)
UTC
no valstack space check
End of input (NUL) goes through slow path and causes SyntaxError.
[ ... enum_target res trap_result val ]
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
ptr_curr_pc != NULL only when bytecode executor is active.
Restore entry thread executor curr_pc stack frame pointer.
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
duk_hobject_set_length_zero(thr, func->h_funcs);
fall thru
see above
* Struct defines
[ ... name reg/null ] -> [ ... ]
mandatory if du.d is a NaN
duk_tval ptr for 'func' on stack (borrowed reference)
For tv1 == tv2, this is a no-op (no explicit check needed).
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
local copy to avoid relookups
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
* Hobject Ecmascript [[Class]].
Handle one slow path unit (or finish if we're done).
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
DUK_HEAPHDR_HAS_FINALIZED may or may not be set.
enough to cover the whole mantissa
DUK_TOK_BXOR_EQ
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
repl string scan
[key result] -> [result]
'\xffTracedata'
... and its 'message' from an instance property
AUTHORS.rst
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
prefer jump
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
automatic length update
args
'String'
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
not a vararg function
Shouldn't happen but check anyway.
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
No strs[] pointer.
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
e.g. DUK_OP_PREINCR
eat 'while'
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
input radix
char: use int cast
result
exponent digit
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
defprop_flags
s <- 2
spaces (nargs - 1) + newline
* Parse inner function
if accessor without getter, return value is undefined
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
who resumed us (if any)
out_clamped==NULL -> RangeError if outside range
relookup after possible realloc
[ ... regexp_object escaped_source bytecode ]
m+ <- (* m+ B)
bytecode opcode (or extraop) for binary ops
forget temp
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
absolute position for digit considered for rounding
-> [ ... this timeval_new ]
TypeError if wrong; class check, see E5 Section 15.10.6
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
same thread
'Boolean'
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
* Init the heap thread
XXX: need a duk_require_func_or_lfunc_coerce()
avoid referencing, invalidated
Don't support "straddled" source now.
* Object compaction.
*
* Compaction is assumed to never throw an error.
[ arg1 ... argN this loggerLevel loggerName ]
duk_tval intentionally skipped
* Since built-ins are not often extended, compact them.
* Compilation
Push a new ArrayBuffer (becomes view .buffer)
idx_start
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
may be NULL if no constants or inner funcs
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
empty expressions can be detected conveniently with nud/led counts
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
[ ... val callback thisArg val i obj ]
[ ... this tracedata sep this str1 ... strN ]
important chosen base types
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
must also check refzero_list
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
[ ... func ]
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Trigger at zero or below
Custom coercion for API
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
source ends before dest starts
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
64-bit OK because always >= 0
reg/const for switch value
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
no prototype, updated below
unwind to 'resume' caller
0xf0-0xff
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
1st related value (type specific)
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
Shared object part
always throw ReferenceError for unresolvable
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Shift to sign extend.
'^'
required_desc_flags
comment: Stack indices for better readability
label: code-design
* Try registers
no prototype or class yet
shadowed; update value
E5 Section 8.6.2 + custom classes
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
RELATIONAL EXPRESSION
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
Zero escape (also allowed in non-strict mode)
roughly 64 bytes
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
this is a bit approximate (errors out before max is reached); this is OK
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Convert buffer to result string.
default prototype (Note: 'thr' must be reachable)
we know these because enum objects are internally created
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
1 = num actual 'return values'
should never happen
'-' verbatim
Regexp tokens
avoid attempt to compact the current object
DUK_TOK_TRUE
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
min(incl)
may be equal
traceback depth ensures fits into 16 bits
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
DUK_TOK_GET
* Various
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
trailer
* Check whether we need to abandon an array part (if it exists)
[... env callee]
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
an Ecmascript function
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
end of bytecode
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
must be found: was found earlier, and cannot be inherited
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
shift in zeroes
free object and all auxiliary (non-heap) allocs
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
bytes in dest
stack[0] = regexp
* stack[1] = string
flags
Check for maximum buffer length.
'Thread'
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
Output #2: last component name
tc1 = false, tc2 = false
0
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
0x90-0x9f
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Write to entry part
To use the shared helper need the virtual index.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
LAYOUT 1
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
* Node.js Buffer.isEncoding()
array entries are all plain values
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
XXX: assert 'c' is an enumerator
two special escapes: '\' and '"', other printables as is
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
DUK_USE_AUGMENT_ERROR_THROW
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
comment: Most practical strings will go here.
label: code-design
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-> [ ... lval new_rval ]
sep (even before first one)
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
0x7F is special
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
Signed integers always map to 4 bytes now.
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
estimate is valid
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
always true, arg is unsigned
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
DUK_TOK_DO
* Slow path: potentially requires function calls for coercion
'ArrayBuffer'
Initialize index so that we skip internal control keys.
flags have been already cleared
* ArrayBuffer, DataView, and TypedArray constructors
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
-> [ ... this timeval_new timeval_new ]
DUK_TOK_CONST
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Slot C
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
At least: ... [err]
wrapped
whole or fraction digit
* Constructor calls
only 'length'
DUK_USE_DEBUGGER_DUMPHEAP
'toISOString'
'res' contains expression value
No other escape beginning with a digit in strict mode
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
[key setter this val key] -> [key retval]
point to start of 'reserved area'
Shared helper for match() steps 3-4, search() steps 3-4.
dummy
Just call the "original" Object.defineProperties() to
* finish up.
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
line terminator will be handled on next round
* Debug dumping
x in [2**31, 2**32[
Error path.
if a site already exists, nop: max one label site per statement
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
Start in paused state.
comment: XXX: much to improve (code size)
label: code-design
[ regexp string res_arr ]
range conversion with a "skip"
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
* Regular expression structs, constants, and bytecode defines.
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
DUK_TOK_DEFAULT
[key value] or [key undefined]
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
* Set lexer input position and reinitialize lookup window.
nargs
With lightfuncs, act 'func' may be NULL
return '(?:)'
DUK_USE_REFZERO_FINALIZER_TORTURE
next to use, highest used is top - 1
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
arg2 would be clobbered so reassign it to a temp.
standard behavior, step 3.f.i
avoid degenerate cases, so that (len - 1) won't underflow
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
'let'
* Halt execution helper
1110 xxxx; 3 bytes
ch1 = (r_increment << 8) + byte
variable name reg/const, if variable not register-bound
Cast converts magic to 16-bit signed value
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
entry part size
* Property not found in prototype chain.
function executes in strict mode
'data' is reachable through every compiled function which
* contains a reference.
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
note: long live range
* Object will be kept; queue object back to heap_allocated (to tail)
no change
DUK_USE_ASSERTIONS
force the property to 'undefined' to create a slot for it
Optimized for speed.
comment: prevent multiple in-progress detaches
label: requirement
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
DUK_TOK_THIS
index
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
3-letter log level strings
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
Must prevent finalizers which may have arbitrary side effects.
DUK_EXCEPTION_H_INCLUDED
invalidates h_buf pointer
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
comment: Higher footprint, less churn.
label: code-design
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
core property functions
25%, i.e. less than 25% used -> abandon
Allow empty fraction (e.g. "123.")
0xf0...0xff
don't allow const
this is just beneath bottom
* Duktape.Buffer: constructor
'Uint8Array'
* Helpers for writing multiple properties
exhaustive
refcounting requires direct heap frees, which in turn requires a dual linked heap
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
[ ... error ]
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
parse new token
1e9
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
* Misc shared helpers.
don't set 'n' at all, inherited value is used as name
';'
switch cmd
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
comment: XXX: some overlapping code; cleanup
label: code-design
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
from curr pc
* Maximum size check
isError flag for yield
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
no need to unwind callstack
* Array part
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
[ array totalLength bufres buf ]
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
[r1,r2] is the range
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
duk_handle_call / duk_handle_safe_call recursion depth limiting
DUK_HOBJECT_FLAG_NEWENV: handled below
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
common case, already closed, so skip
ignore millisecond fractions after 3
* unshift()
E5 Section 10.4.3
No built-in functions are constructable except the top
* level ones (Number, etc).
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
Bernstein hash init value is normally 5381
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
expt 0xfff is infinite/nan
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
%s
e.g. "x" < "xx"
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
SameValue
How much stack to require on entry to object/array encode
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
... name ': ' message
to exit
parenthesis count, 0 = top level
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
input string (may be a user pointer)
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
shared helper
* Fast buffer writer with spare management.
success/error path both do this
DUK_TOK_MUL
attempt to change from accessor to data property
allowed ascii whitespace
[ ... source? filename? ]
continue jump
-> [ ... key val ]
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
no need to create environment record now; leave as NULL
* Thread state check and book-keeping.
"/=" and not in regexp mode
for lastIndexOf, result may be -1 (mark immediate termination)
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
requested identifier
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
no return value -> don't replace created value
'Arguments' object and has arguments exotic behavior (non-strict callee)
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
Note: left shift, should mask
31 to 36
two level break
don't allow an empty match at the end of the string
'thr' is now reachable
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
Allow 'Infinity'
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
* Helpers for managing property storage size
if-digit-else-ctrl
Safe write calls which will ensure space first.
having this as a separate function provided a size benefit
code emission
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Debugging related API calls
-> [ ... func this arg1 ... argN _Args length ]
'Float64Array'
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
-> [ this ]
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
retval indicates delete failed
formatters always get one-based month/day-of-month
continue matching, set neg_tzoffset flag
bound function chain has already been resolved
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
standard JSON; array gaps
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
just check 'env'
comment: XXX: primitive to make array from valstack slice
label: code-design
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
consistency requires this
DUK_TOK_CASE
Nothing to initialize, strs[] is in ROM.
currently 6 characters of lookup are actually needed (duk_lexer.c)
index/length check guarantees
left.x1 -> res.x1
* Case conversion tables generated using src/extract_caseconv.py.
is global code
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
Note: not a valid stack index if num_stack_args == 0
* Convenience (independent of representation)
no refcounting
duk_handle_ecma_call_setup: setup for a resume()
escape any non-ASCII characters
if 0, 'str' used, if > 0, 'strlist' used
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
* pop(), push()
'DecEnv'
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
* Writability check
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
DUK_USE_JSON_STRINGIFY_FASTPATH
Update all labels with matching label_id.
guaranteed by duk_to_string()
DUK_USE_TRACEBACKS
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
ensures callstack_top - 1 >= 0
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
detached
'constructor'
disabled for now
idx_replacer
type to represent a straight register reference, with <0 indicating none
continue jump not patched, an INVALID opcode remains there
-> [ ... enum_target res trap_result ]
current (next) array index
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
'const'
all codepoints up to U+10FFFF
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
if no NaN handling flag, may still be NaN here, but not Inf
thr argument only used for thr->heap, so specific thread doesn't matter
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
[0x00000000, 0xffffffff]
fall through to error
[ ... key_obj key key ]
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
since no recursive error handler calls
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
numeric label_id (-1 reserved as marker)
irrelevant when out->value == NULL
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
DUK_USE_STRTAB_CHAIN
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
assume value is a number
comment: combines steps 3, 6; step 7 is not needed
label: requirement
* Debugger support
comment: XXX: spare handling, slow now
label: code-design
normal and constructor calls have identical semantics
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
Same coercion behavior as for Number.
the outer loop will recheck and exit
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
x == -Infinity
[ ... source? func_template ]
other call
lastIndex already set up for next match
* Macros to access the 'props' allocation.
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
[ ... source? filename? ] (depends on flags)
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
[ targetBuffer targetStart sourceStart sourceEnd ]
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
at least one opcode emitted
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
side effects, in theory (referenced by global env)
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
Allow naked fraction (e.g. ".123")
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
Other longjmp types are handled by executor before propagating
* the error here.
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
* Ecmascript/native function call or lightfunc call
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
computed live
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
callstack limits
A...P
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
Explicit length is only needed if it differs from 'nargs'.
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
(?:
Must be restored here to handle e.g. yields properly.
The base ID of the current require() function, resolution base
non-Reference deletion is always 'true', even in strict mode
jump to next loop, using reg_v34_iter as iterated value
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
max possible
punctuators (unlike the spec, also includes "/" and "/=")
DUK_BUFOBJ_FLOAT32ARRAY
[ ... ptr ]
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
12: getDate
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
'modLoaded'
* Assertions before
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
for zero size, don't push anything on valstack
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
heap level "stash" object (e.g., various reachability roots)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
c recursion check
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
Continue parsing after padding, allows concatenated,
* padded base64.
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
idx_step is +1 for indexOf, -1 for lastIndexOf
is a setter/getter
env created above to stack top
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
DUK_TOK_LNOT
XXX: sufficient to check 'strict', assert for 'is function'
check final character validity
* Init lexer context
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
idx_step is +1 for reduce, -1 for reduceRight
PatternCharacter, all excluded characters are matched by cases above
Note: -nargs alone would fail for nargs == 0, this is OK
curr and desc are accessors
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
func.prototype.constructor = func
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
prev value can be garbage, no decref
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
Stepped? Step out is handled by callstack unwind.
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
fills window
Caller must check character offset to be inside the string.
valstack will be unbalanced, which is OK
conservative
unconditional
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Duktape.modSearch
Set .buffer to the argument ArrayBuffer.
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
flags: ""
-> [ res_obj ]
unvalidated
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
eat '{' on entry
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
resume write to target
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
Else functionality is identical for function call and constructor
* call.
inclusive
Check that 'this' is a duk_hbufferobject and return a pointer to it.
utf-8 continuation bytes have the form 10xx xxxx
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
'-'
hobject management functions
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
'\xffBytecode'
Catch a double-to-int64 cast issue encountered in practice.
* DumpHeap command
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
[ ... buf loop ]
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
x <- y + z
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
[ ... re_obj input bc ]
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
push before advancing to keep reachable
* duk_hthread allocation and freeing.
[ ... pattern flags escaped_source bytecode ]
* Helper for updating callee 'caller' property.
eat 'do'
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
[ source template result ]
25 user flags
also stash it before constructor,
* in case we need it (as the fallback value)
omit print
Unary plus is used to force a fastint check, so must include
* downgrade check.
DUK__FLD_16BIT
comment: should never happen, but be robust
label: code-design
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
comment: XXX: comes out as signed now
label: code-design
flags
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
writable but not deletable
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
[ ... formals ]
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
See: tests/ecmascript/test-spec-bound-constructor.js
guaranteed to succeed
* Define new property
*
* Note: this may fail if the holder is not extensible.
used elements (includes DELETED)
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
-> [ ... key val replacer holder key ]
as is
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
comment: XXX: make this an internal helper
label: code-design
assumed to bottom relative
intentionally empty
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
aaaaaabb bbbbcccc ccdddddd
[[SetPrototypeOf]] standard behavior, E6 9.1.2
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
27: setUTCSeconds
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
no need to unwind catchstack
'Proxy' object
'errCreate'
coerce lval with ToString()
see algorithm
* reverse()
index is above internal buffer length -> property is fully normal
ensure never re-entered until rescue cycle complete
comment: order: most frequent to least frequent
label: code-design
comment: not very useful, used for debugging
label: code-design
catch stack depth
[ ... res_obj ]
* Lexer defines.
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
DUK_BUFOBJ_NODEJS_BUFFER
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
XXX: version specific array format instead?
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
roughly 2 kiB
Must avoid duk_pop() in exit path
basic types from duk_features.h
XXX: byte offset
* instanceof
ecmascript compiler limits
token type
-> [ ... key val replacer ]
call_flags
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Negative indices are always within allocated stack but
* must not go below zero index.
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
Exponent
general temp register
0xe0...0xef
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
[ arg1 ... argN this loggerLevel loggerName buffer ]
If not present in finalize_list or refzero_list, the pointer
* must be either in heap_allocated or the string table.
rc_varname and reg_varbind are ignored here
duplicate zeroing, expect for (possible) NULL inits
get as double to handle huge numbers correctly
enum_index
XXX: clarify on when and where DUK__CONST_MARKER is allowed
* Error helpers
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
'new'
evaluate to plain value, no forced register (temp/bound reg both ok)
Keep heap->finalize_list up-to-date during the list walk.
* This has no functional impact, but does matter e.g. for
* duk_push_heapptr() asserts when assertions are enabled.
DUK_USE_INTERRUPT_COUNTER
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
comment: XXX: could be eliminated with valstack adjust
label: code-design
[key val]
DUK_TOK_CATCH
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
[ ... arg1 ... argN envobj argobj ]
flags:nonstrict
pass2 allocation handles this
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
advance manually
comment: XXX: awkward
label: code-design
target out-of-bounds (but positive)
free some memory
constrained by string length
stable; precalculated for faster lookups
* Thread defines
same handling for identifiers and strings
-> [ ... lval rval rval.prototype ]
'implements'
'='
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
negative top-relative indices not allowed now
'instanceof'
avoid attempt to compact any objects
expression parsing helpers
return ToObject(this)
one token
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
not protected, respect reclimit, is a constructor call
DUK_TOK_BNOT
E5 Section 8.6.1
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
val is unsigned so >= 0
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
must have start and end
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
env and act may be NULL
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
-> [... enum key enum_target key]
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
* Unicode tables
[... obj]
Note: space must cater for both JX and JC.
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
Normal non-bound function.
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
current and previous token for parsing
probe sequence
message is empty -> return name
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
Currently nothing to free; 'data' is a heap object
'prototype'
'jx'
default prototype (Note: 'obj' must be reachable)
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
Unwind the topmost callstack entry before reusing it
internal define property: skip write silently if exists
borrowed, no refcount
allow e.g. '0x0009' and '00077'
DUK_BUFOBJ_DATAVIEW
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
find elements to swap
currently, always the case
* Detected label
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
* Helper macros
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
constants are strings or numbers now
'\n '
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
if (is_regexp)
[ thisArg arg1 ... argN func boundFunc ]
-Infinity
Undefine local defines
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Init built-in strings
* Two's complement arithmetic.
[... constructor arg1 ... argN]
no need to decref previous value
'finally'
Zero size compare not an issue with DUK_MEMCMP.
[ ... closure template val ]
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
may be NULL (but only if size is 0)
write to entry part
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
* Debug connection message write helpers
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
don't want an intermediate exposed state with func == NULL
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
XXX=
separators: space, space, colon
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
Slow path
Lightweight function: never bound, so terminate.
unconditionally; is_global==0
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
string limits
comment: function makes one or more slow path accesses
label: code-design
DUK_USE_AUGMENT_ERROR_CREATE
No need for a NULL/zero-size check because new_size > 0)
Assume value stack sizes (in elements) fits into duk_idx_t.
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
'>'
* Debug connection skip primitives
valstack index of 'func' and retval (relative to entry valstack_bottom)
XXX: array internal?
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
avoid key quotes when key is an ASCII Identifier
embed: nothing
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
* Memory allocation handling.
current assertion is quite strong: decref's and set to unused
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
element type
parsing in "scanning" phase (first pass)
regexp res_obj is at offset 4
Flags for duk_js_compare_helper().
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
no fractions
'Function'
29: setUTCMinutes
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
accept comma, expect new value
-> [ ... reviver holder name val ]
[ ... pattern flags escaped_source buffer ]
reg
empty match -> bump and continue
regexp execution limits
SCANBUILD: "Dereference of null pointer", normal
catch or with binding is currently active
Note: unbalanced stack on purpose
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
expt values [0x001,0x7fe] = normal
Receiver: Proxy object
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
* Type error thrower, E5 Section 13.2.3.
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
XXX: init or assert catch depth etc -- all values
happens when hash part dropped
1x heap size
no need for decref/incref because value is a number
comment: XXX: this may now fail, and is not handled correctly
label: code-design
[key undefined] -> [key]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
stack top contains 'false'
LAYOUT 2
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
(
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
-> [ sep ToObject(this) len str ]
covered by comparison
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
For now, restrict result array into 32-bit length range.
coerce in-place
DUK_ERR_ASSERTION_ERROR: no macros needed
directive prologue status at entry
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
[ ... num ]
arrays MUST have a 'length' property
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
comment: Inner executor, performance critical.
label: code-design
significant from precision perspective
[ ... Logger clog logfunc clog ]
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
fits into duk_small_int_t
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
is eval code
* Iterate the bitstream (line diffs) until PC is reached
varmap is already in comp_ctx->curr_func.varmap_idx
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
[key setter this val] -> [key retval]
DUK_TOK_LAND
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
Note that multiple catchstack entries may refer to the same
* callstack entry.
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
DUK_HNATIVEFUNCTION_H_INCLUDED
check pointer at end
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
chain jumps for 'fall-through'
* after a case matches.
duk_unicode_ids_noa[]
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
reset longjmp
non-strict equality for buffers compares contents
all codepoints up to U+FFFF
recursion tracking happens here only
roughly 128 bytes
default clause matches next statement list (if any)
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
new value
MULTIPLICATIVE EXPRESSION
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
-> [ ... func this ]
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
caller checks
t has high mantissa
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
DUK_TOK_LCURLY
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
If 'day' is NaN, returns NaN.
* New length not lower than old length => no changes needed
* (not even array allocation).
* API oriented helpers
[enum_target res key true]
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
ADDITIVE EXPRESSION
macros
default case does not exist, or no statements present
* after default case: finish case evaluation
use temp_next for tracking register allocations
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
DUK_REGEXP_H_INCLUDED
comment: XXX: add fastint support?
label: requirement
FOUND
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
initialize for debug prints, needed if sce==NULL
start of valstack allocation
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
-> [ ... enum_target res trap handler target ]
derived types
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Must be a "pointer object", i.e. class "Pointer"
ES6 proxy
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
value of dbg_exec_counter when we last did a Date-based check
idx_retval unsigned
no negative sign for zero
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
looping should never happen
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
digit position is absolute, not relative
c
comment: Same test with volatiles
label: test
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
%d; only 16 bits are guaranteed
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Since we already started writing the reply, just emit nothing.
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
-> [ ... errhandler undefined(= this) errval ]
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
valid pc range is [0, length[
Current tracedata contains 2 entries per callstack entry.
[ ... errval ]
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
comment: XXX: no need for indirect call
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
valstack
not protected, respect reclimit, not constructor
Push the resulting view object and attach the ArrayBuffer.
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
unbalanced stack
value from hook
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
* Struct defs
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: not really necessary
label: code-design
[ ... target ] -> [ ... target keys ]
Leading zero.
','
Make underlying buffer compact to match DUK_BW_GET_SIZE().
first heap allocated, match bit boundary
comment: XXX: more specific error classes?
label: code-design
25: setUTCMilliseconds
* Intermediate value helpers
Limits
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
[ sep ToObject(this) len sep result ]
* Variant 2 or 4
Lightfunc, always success.
step 11.c is relevant only if non-strict (checked in 11.c.ii)
XX==
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
Force exponential format. Used for toExponential().
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
wipe the capture range made by the atom (if any)
Anything else is not constructable.
attrs in E5 Section 15.3.5.1
* Use the index in the header to find the right starting point
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
maximum length of standard format tag that we support
buffer size is >= 1
ignore encoding for now
enable manually for dumping
(?=
require to be safe
Parser part count.
for side effects, result ignored
Now we can check offset validity.
Milliseconds between status notify and transport peeks.
Matching separator index is used in the control table
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
* Stringify implementation.
ToNumber() for a double is a no-op.
default: char escape (two chars)
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
negate result
* Lightfunc
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
Special handling for year sign.
[ arg1 ... argN obj length new_length ]
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
statements go here (if any) on next loop
'yield'
eat trailing comma
pruned
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
For anything other than an Error instance, we calculate the
* error location directly from the current activation if one
* exists.
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
lookup results is ignored
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
resume caller must be an ecmascript func
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
stack contains value (if requested), 'out_desc' is set
no issues with empty memcmp()
[str] -> [substr]
func is NULL for lightfunc
property attributes for identifier (relevant if value != NULL)
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
don't allow continue
respect reclimit, not constructor
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
0x60-0x6f
DUK_BUFOBJ_INT32ARRAY
Caller has already eaten the first char so backtrack one byte.
controls for minimum entry part growth
temp accumulation buffer
Unwind.
* Object built-ins
callstack index
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
take last entry
curr is data, desc is accessor
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
* Bitstream decoder
statement id allocation (running counter)
'public'
single match always
Note: 'curr' refers to 'length' propdesc
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
Steps 8-10 have been merged to avoid a "partial" variable.
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
duk_safe_call discipline
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
comment: XXX: encoding is ignored now.
label: code-design
use 'undefined' for value automatically
[ ... obj ... ]
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
Buffer length is bounded to 0xffff automatically, avoid compile warning.
Integer division which floors also negative values correctly.
consequence of above
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
backtrack (safe)
DUK__FLD_32BIT
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
comment: Note: reuse 'curr'
label: code-design
* Convert and push final string.
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
* Selftest code
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Get default hash part size for a certain entry part size.
Maximum number of digits generated.
[ ... func buf ] -> [ ... buf ]
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
e.g. DUK_OP_PREINCV
If neutered must return 0; offset is zeroed during
* neutering.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
breakpoints: [0,breakpoint_count[ gc reachable
comment: XXX: inefficient loop
label: code-design
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
Strings and ROM objects are never placed on the heap allocated list.
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
stack type fits into 16 bits
'set'
low to high
required, NULL implies detached
right associative
covers +Infinity
no size check is necessary
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
comment: XXX: best behavior for real world compatibility?
label: code-design
34: setMonth
20: getSeconds
refcount macros not defined without refcounting, caller must #ifdef now
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
comment: XXX: shared parsing?
label: code-design
Note: reject negative zero.
Delete entry in Duktape.modLoaded[] and rethrow.
already closed
'\xffFormals'
1
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
DUK_TOK_NEQ
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
no shrink
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
* Ecmascript bytecode
Current require() function
[ ... errobj ]
[... arr]
-> [ ... escaped_source ]
func
ignore fclose() error
DUK_TOK_RETURN
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
XXX: to util
Byte length would overflow.
register declarations in first pass
implicit this value always undefined for
* declarative environment records.
match_caps == 0 without regexps
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
* Object finalizer
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
-> [ ... proplist enum_obj key ]
elems in source and dest
E5 Section 15.4.5.1, step 4
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
DUK_USE_ROM_OBJECTS
stats for current expression being parsed
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
DUK_IVAL_XXX
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
* Error, fatal, and panic handling.
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
guaranteed by string limits
Slot A
terminates expression; e.g. post-increment/-decrement
ignore arguments, return undefined (E5 Section 15.3.4)
Thread state.
g...v
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
omit
always >= 0
Fixed buffer, no zeroing because we'll fill all the data.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
terminal type: no depth check
track cpos while scanning
DUK_TOK_SEQ
curr_pc synced by duk_handle_ecma_call_setup()
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
accessor flag not encoded explicitly
For now only needed by the debugger.
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
remove value
* Forward declarations
mm <- mp
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
rethrow
* Accessor macros for function specific data areas
Argument validation and func/args offset.
day number for Jan 1 since epoch
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
compact
comment: XXX: could clear FINALIZED already here; now cleared in
* next mark-and-sweep.
label: code-design
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
"123." is allowed in some formats
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
NB: must accept reserved words as property name
no array part
* Misc
error message doesn't matter, ignored anyway
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
Currently nothing to free
comment: Convenience copies from heap/vm for faster access.
label: code-design
Reply with tvals pushed by request callback
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
'index'
index is above internal string length -> property is fully normal
LF line terminator; CR LF and Unicode lineterms are handled in slow path
* Misc helpers
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
bound chain resolved
base
Line format: <time> <entryLev> <loggerName>: <msg>
NEXTENUM jump slot: executed when enum finished
comment: prototype should be last, for readability
label: code-design
comment: XXX: direct implementation
label: requirement
Error codes.
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
* Property lookup
Constants for duk_hashstring().
roughly 1 kiB
advance by one character (code point) and one char_offset
no need to coerce
remove key and value
A regexp token value.
large context; around 2kB now
lexer character window helpers
at index 1
trivial cases
duplicate/invalid key checks; returns 1 if syntax error
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
original target at entry_top - 1
not emitted
comment: XXX: duk_ssize_t would be useful here
label: code-design
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
* Init lexer
'%'
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
DUK_TOK_NUMBER
IEEE exp without bias
31 bits
call handling
not exposed
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
For internal use: get array part value
10xx xxxx -> invalid
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
_Varmap is dense
DUK_TOK_BAND
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
indirect eval
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
* Some assertions (E5 Section 13.2).
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
preincrement and predecrement
Value would normally be omitted, replace with 'null'.
e.g. require('/foo'), empty terms not allowed
string is internal
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
success: leave varname in stack
safe
[ ... closure template len_value ]
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
[ ... func this (crud) retval ]
DUK_USE_DATE_PRS_STRPTIME
comment: Global case is more complex.
label: code-design
max, excl. varargs marker
should be a safe way to compute this
not an error
prev_token slot2
side effects, perform in-place
comment: XXX: turkish / azeri
label: code-design
current variable environment (may be NULL if delayed)
May happen in some out-of-memory corner cases.
* Store lexer position for a later rewind
-> [ ... this timeval ]
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
prev_token slot1
Note1
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
DUK_TOK_IMPORT
* Native call.
input offset tracking
-> [ ... closure template newobj closure ]
fixed arg count: value
chain jumps for case
* evaluation and checking
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
function call
full 3-byte -> 4-char conversions
regexp compilation limits
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
0x00: slow path
* other: as is
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
reject 'in' token (used for for-in)
Data area, fixed allocation, stable data ptrs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
DUK_LEXER_H_INCLUDED
type bit mask: types which certainly produce 'undefined'
XXX: for threads, compact value stack, call stack, catch stack?
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
second, parse flags
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
strict mode restrictions (E5 Section 12.2.1)
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
[ regexp ]
'\xffFinalizer'
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
output is never longer than input during resolution
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Fast path the binary case
* Unicode helpers
comment: XXX: zero assumption
label: code-design
* Assertions after
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
'Math'
1e8: protects against deeply nested inner functions
insert ranges instruction, range count patched in later
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
tc1 = false, tc2 = true
after this, return paths should 'goto finished' for decrement
obj_index
zero-width non-joiner
activation has active breakpoint(s)
Constants for built-in string data depacking.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
start (incl) and end (excl) of trimmed part
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
interpret e.g. '09' as '0', not NaN
* splice()
no argument given -> leave components untouched
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
character represents itself
eat 'return'
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
[ value offset end ]
Relies on NULL encoding to zero.
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
* Compilation and evaluation
Note: Identifier rejects reserved words
-> [ obj trap_result ]
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
caller ensures
* Not found (in registers or record objects). Declare
* to current variable environment.
comment: 'this' binding is not needed here
label: requirement
no need to check callable; duk_call() will do that
mark finalizer work list as reachability roots
Initial '{' has been checked and eaten by caller.
'\xffMap'
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
'NaN'
unsigned 31-bit range
DUK_USE_EXPLICIT_NULL_INIT
valgrind whine without this
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Exposed calls
key encountered as a setter
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
one i_step over
Shared prefix for all buffer types.
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
must restore reliably before returning
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
return 'res_arr' or 'null'
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
break jump
"123"
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
range check not necessary because all 4-bit values are mapped
floor(1.15 * (1 << 10))
expect_eof
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
* Stack constants
call: this.fmt(arg)
Combined step 11 (empty string special case) and 14-15.
w/o refcounting
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
Write fully.
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
object established using Function.prototype.bind()
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
output radix
resume check from proxy target
native function properties
1e8
Lightfunc flags packing and unpacking.
Helpers exposed for internal use
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
comment: NULL always indicates alloc failure because
* new_alloc_size > 0.
label: code-design
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
assertion omitted
-> [... obj finalizer]
does not fit into an uchar
need to normalize, may even cancel to 0
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
used for array, stack, and entry indices
[ ... name reg_bind ]
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
invalid value which never matches
Arrays never have other exotic behaviors.
0xxx xxxx [7 bits]
[ ... env target ]
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: alloc size in elements
label: code-design
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
note: caller 'sp' is intentionally not updated here
Underlying buffer (refcounted), may be NULL.
actual chars dropped (not just NUL term)
free-form
formals for 'func' (may be NULL if func is a C function)
comment: bytes of indent available for copying
label: code-design
* Valstack manipulation for results.
[obj key desc value get set curr_value varname]
* Add ._Tracedata to an error on the stack top.
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
Lexer context. Same context is used for Ecmascript and Regexp parsing.
comment: XXX: spilling
label: code-design
Note: rely on index ordering
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
NB: duk_lexer_getpoint() is a macro only
dangerous: must only lower (temp_max not updated)
x <- x + y, use t as temp
* Init argument related properties
add BC*2^16
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
char format: use int
Clamping only necessary for 32-bit ints.
maximum size check is handled by callee
-> [ ... val root val ]
Note: start_offset/end_offset can still be < 0 here.
cat_idx catcher is kept, even for finally
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
'fatal'
* Plain, boring reachable object.
value of re_ctx->captures at start of atom
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
pc_label
'configurable'
* Object prototype
'this' binding exists
XXX: direct manipulation, or duk_replace_tval()
fill window
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
* Logging support
[key result]
unchanged by Duktape.Thread.resume()
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
Return 1: got EOM
include removed: duk_internal.h
NOTE: length may be zero
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
Alignment guarantee
!DUK_USE_PREFER_SIZE
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* Mark the heap.
silence scan-build warning
varname is popped by above code
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
Decode failed.
* Init stringcache
[... constructor arg1 ... argN final_cons]
comment: XXX: lithuanian, explicit dot rules
label: code-design
XXX: similar coercion issue as in DUK_TOK_PERIOD
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
source out-of-bounds (but positive)
'with' binding has no catch clause, so can't be here unless a normal try-catch
second incref for the entry reference
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
Get.
DUK_TOK_PRIVATE
randomized pivot selection
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
These are not needed when only Duktape.Buffer is supported.
duk_hobject specific fields.
[val] -> []
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
* Shared exit path
force_exponential
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
DUK_INVALID_INDEX won't be accepted as a valid index.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
DUK_USE_BUFFEROBJECT_SUPPORT
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
string hash
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
0 = no update
regexp opcodes
'function'
recursion limit
utf-8 validation ensures these
count, not including sep
string data is external (duk_hstring_external)
currently paused: talk with debug client until step/resume
duk_concat() coerces arguments with ToString() in correct order
2 to 11
guaranteed to finish
const flag for B
one i_step added at top of loop
'res' may be NULL if new allocation size is 0.
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
thread
assume PC is at most 32 bits and non-negative
1 0 <2 bits>
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
NULL obj->p is OK
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
Assume that thr->valstack_bottom has been set-up before getting here.
len: 9
* E5 Section 11.4.9
deal with weak references first
duk_push_sprintf constants
negative: dst info not available
topmost element is the result array already
Fast path, handle units with just actual encoding characters.
out of spec, must be configurable
* Debug logging after adjustment.
* Pushers
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
implicit_return_value
XXX: direct valstack write
[ ... source? filename ]
No resize has occurred so temp_desc->e_idx is still OK
lookup for 0x000a above assumes shortest encoding now
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
true, despite side effect resizes
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
[ start end str ]
source is eval code (not global)
switch initial byte
Note: pc is unsigned and cannot be negative
* Casting
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
Longjmp handling has restored jmpbuf_ptr.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
-> [ ... varname val this ]
processed one or more messages
[ ... v1(filename) v2(line+flags) ]
must have been, since in array part
slower but more compact variant
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
comment: parameter passing, not thread safe
label: requirement
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
Note: decimal number may start with a period, but must be followed by a digit
main reachability roots
DUK_HBUFFER_H_INCLUDED
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
placed in duk_heaphdr_string
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
'private'
toJSON() can also be a lightfunc
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
move pivot out of the way
final configuration
-1 == not set, -2 == pending (next statement list)
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
NB: 'length' property is automatically updated by the array setup loop
index for next new key ([0,e_next[ are gc reachable)
idx is unsigned, < 0 check is not necessary
indirect opcode follows direct
* toFixed(), toExponential(), toPrecision()
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
follow prototype chain
[ value ]
XXX: incref by count (here 2 times)
equals
true even with reattach
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
numeric value of a hex digit (also covers octal and decimal digits)
DUK_TOK_MUL_EQ
DUK_USE_DEBUG
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
0x00: finish (non-white)
* 0x01: continue
%lu
[ ... arg1 ... argN ]
executor interrupt running (used to avoid nested interrupts)
[ ... func this ]
Constants: variable size encoding.
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
no res->strs[]
* Debug dumping of duk_heap.
Detach a debugger if attached (can be called multiple times)
* safely.
if 1, doing a string-to-number; else doing a number-to-string
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
* duk_hbuffer allocation and freeing.
stash to bottom of value stack to keep new_env reachable for duration of eval
step 4.a
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
exports
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
comment: XXX: use duk_is_valid_index() instead?
label: code-design
eat closing bracket
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* The switch statement is pretty messy to compile.
* See the helper for details.
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
first value: comma must not precede the value
actually used, non-NULL keys
r <- (2 * b) * f
[ ... re_obj input bc saved_buf res_obj ]
* Create wrapper object and serialize
t1 <- t1 - s
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
112.5%, i.e. new size less than 12.5% higher -> fast resize
* URI handling
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
32-bit value
string intern table (weak refs)
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
Convert indices to byte offsets.
'l'
Fast path: source is a TypedArray (or any bufferobject).
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
'var'
[ args(n) [crud] formals arguments map mappednames ]
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
'pointer'
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
DUK_UNICODE_H_INCLUDED
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
end of valstack allocation (exclusive)
previous value is assumed to be garbage, so don't touch it
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
comment: suppress warning, not used
label: code-design
Buffer/string -> compare contents.
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
finished jump
string is ASCII, clen == blen
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
* Copy array elements to new array part.
For strings, special form for short lengths.
Setup function properties.
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
* Utilities
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
comment: XXX: 'copy properties' API call?
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
'{_func:true}'
prediction: portable variant using doubles if 64-bit values not available
[ ... arr val ]
Casting convenience.
The stack has a variable shape here, so force it to the
* desired one explicitly.
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
Object.getOwnPropertyNames
'undefined'
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
Overestimate required size; debug code so not critical to be tight.
comment: no special formatting
label: code-design
proplist is very rare
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
DUK_USE_JC
function refers to 'arguments' identifier
don't want an intermediate exposed state with invalid pc
Use loop to minimize code size of relookup after bound function case
'Undefined'
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
if abandon_array, new_a_size must be 0
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
pointer is aligned, guaranteed for fixed buffer
See MPUTOBJ comments above.
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
'\xffPc2line'
comment: XXX: better coercion
label: code-design
guaranteed to finish, as hash is never full
shared flags for a subset of types
nothing to incref
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
unpack args
hash lookup
* Cleanup: restore original function, restore valstack state.
don't touch property attributes or hash part
Note: duk_uint8_t type yields larger code
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
return arg as-is
NULL accepted
Lightfunc, not blamed now.
0 = no throw
comment: XXX: macros
label: code-design
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
maximum recursion depth for loop detection stacks
us
[ ... holder name val ]
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
* Init arguments properties, map, etc.
comment: NUL terminator handling doesn't matter here
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
keep in on valstack, use borrowed ref below
[ ... Logger clog logfunc clog(=this) msg ]
-> [ ... func this arg1 ... argN _Args ]
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
compiler's responsibility
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
func is NULL for lightfuncs
shared exit path now
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
-> [ O toIsoString O ]
* Finish
-> [ timeval this timeval ]
cached: valstack_end - valstack (in entries, not bytes)
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
* Bitstream encoder.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
IdentifierStart production with ASCII and non-BMP excluded
temp object for tracking / detecting duplicate keys
negative
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
DUK_BUFOBJ_INT8ARRAY
DUK_USE_ROM_STRINGS
get pointer offsets for tweaking below
Note: not normalized, but duk_push_number() will normalize
NULL if not an object
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
XXX: could add fast path for u8 compatible views
Note2
'resume'
should never happen for a strict callee
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
[... env]
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
'export'
DUK_ERR_URI_ERROR: no macros needed
array case is handled comprehensively above
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
force_no_namebind
DUK_TOK_NEW
* Breakpoint and step state checks
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
global object doesn't have array part
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
comment: XXX: specific getter
label: code-design
[ ... escape_source bytecode ]
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
lastIndex is initialized to zero by new RegExp()
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
>>>
[ ... closure template formals ]
inherit
filename being compiled (ends up in functions' '_filename' property)
filter out flags from exprtop rbp_flags here to save space
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
prop index in 'array part', < 0 if not there
caller handles sign change
comment: load factor too low or high, count actually used entries and resize
label: code-design
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
make the new thread reachable
XXX: print built-ins array?
temp reg
* Externs and prototypes
no incref
Test signaling NaN and alias assignment in all endianness combinations.
1 GB
XXX: fast path for array arguments?
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
DUK_USE_PACKED_TVAL
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
values for the state field
How large a loop detection stack to use
pop enum
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
<
[ ... closure template undefined ]
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
dynamic buffer ops
not found in 'curr', next in prototype chain; impose max depth
13: getUTCDate
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
[ ... this name ]
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
comment: XXX: check flags
label: requirement
ASCII (and EOF) fast path -- quick accept and reject
0xc0...0xcf
'-' as a range indicator
-> [ ... enum_target res handler undefined target ]
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
"123.456"
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
'false'
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
data property or accessor without getter
* Args validation
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
* String built-ins
* Clear (reachable) flags of refzero work list.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
-> [ ... obj key trap handler ]
catchstack
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
Call sites don't need the result length so it's not accumulated.
non-zero: make copy
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
fromPresent = false
Check that there's room to push one value.
comma check
backtrack to last output slash (dups already eliminated)
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Flags for call handling.
jump to end
* RegExp built-ins
allocation size
no -> decref members, then free
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
XXX: C recursion limit if proxies are allowed as handler/target values
try part
'caller' must only take on 'null' or function value
sign doesn't matter when writing
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
comment: unused
label: code-design
* Other file level defines
Fast path for numbers (one of which may be a fastint)
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
[enum_target enum res]
orig value
comment: XXX use get tval ptr, more efficient
label: code-design
See comments in duk_pcall().
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
A bit tricky overflow test, see doc/code-issues.rst.
key must not already exist in entry part
Digit generation
reset function state (prepare for pass 2)
+0 = catch
avoid side effects!
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
duk_small_uint_fast_t c = DUK_DEC_C(ins);
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
comment: No coercions or other side effects, so safe
label: requirement
0x20-0x2f
may become sparse...
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
XXXXXX--
lightfuncs are treated like objects and not coerced
jump to end or else part
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
for duk_error_augment.c
just one 'int' for C++ exceptions
'~'
reset voluntary gc trigger count
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
* Defines for JSON, especially duk_bi_json.c.
* Fast path tables
-> [ ... handler trap ]
DUK_TOK_ALSHIFT_EQ
Note: assumes 'data' is always a fixed buffer
* Stringtable entry for fixed size stringtable
sometimes stack and array indices need to go on the stack
hash size ratio goal, must match genhashsizes.py
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
Require a lot of stack to force a value stack grow/shrink.
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
DUK_DEBUG_H_INCLUDED
input size is good output starting point
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: Should never happen but avoid infinite loop just in case.
label: code-design
unchanged from Duktape.Thread.yield()
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
Negative offsets cause a RangeError.
side effect free
main expression parser function
Always overflow.
may happen if size is very close to 2^32-1
fail: restore saves
DUK_USE_DATE_PRS_GETDATE
needed for stepping
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
clen == blen -> pure ascii
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
current setjmp() catchpoint
Result is undefined.
[ ... proplist ]
This may throw an error though not for valid E5 strings.
* Marking functions for heap types: mark children recursively
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
XXX: set with duk_hobject_set_length() when tracedata is filled directly
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
Slow path.
'compile'
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
DUK_TOK_RCURLY
comment: XXX: check .caller writability?
label: code-design
replacement handler
2**31-1 ~= 2G properties
part of string
Bytecode instructions: endian conversion needed unless
* platform is big endian.
DUK_TOK_EXTENDS
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
fastint downgrade check for return values
comment: bytes of indent still needed
label: code-design
DUK_JS_COMPILER_H_INCLUDED
nop
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
Double error
* Valstack spare check
This would be pointless: unexpected type and lightfunc would both return NULL
For internal use: get non-accessor entry value
trailing comma followed by rcurly
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
[... value this_binding]
DUK_TOK_INCREMENT
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
insert code for matching the remainder - infinite or finite
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
* Fast paths
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
truncate towards zero
37: setUTCFullYear
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
* Assert helpers
resume lookup from target
comment: XXX: assume these?
label: code-design
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
standard prototype
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
flags: "gm"
no need to decref, as previous value is 'undefined'
may need unwind
catch part will catch
-> [ ... name index ]
* Node.js Buffer: toString([encoding], [start], [end])
* Ecmascript compiler.
Allow fraction part
explicit 'this' binding, see GH-164
Initial bytecode size allocation.
XXX: patch initial size afterwards?
already zero
late lookup, avoid side effects
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
match against rule part/sep bits
'd' and 'res' agree here
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
Eval code doesn't need an automatic .prototype object.
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
never here
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
Note that 'l' and 'r' may cross, i.e. r < l
For internal use: get non-accessor entry value and attributes
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
DUK_USE_JSON_EATWHITE_FASTPATH
valstack top, should match before interpreting each op (no leftovers)
may be NULL if alloc_size == 0
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
110x xxxx; 2 bytes
if num_values > 0, MPUTARR emitted by outer loop after break
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
Not enough data.
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
DUK_TOK_STRING
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ ... env ]
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
* Reallocate memory with garbage collection
comment: XXX: unnecessary translation of flags
label: code-design
Explicit check for fastint downgrade.
default attrs ok
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
comment: There may be whitespace between the equal signs.
label: code-design
comment: Note: first argument not really used
label: code-design
* Function declarations
reg_res should be smallest possible
Slot B
* Unreachable object, free
Specific assumptions for opcode numbering.
comment: copied so that 'ap' can be reused
label: code-design
exponents 1023 to 1069
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
(?!
name
Restart bytecode execution, possibly with a changed thread.
-> [ ... func name ]
top of current frame (exclusive)
if thisArg not supplied, behave as if undefined was supplied
for side effects
comment: XXX: match flag is awkward, rework
label: code-design
fall through and continue for-loop
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
assume 0 <=> NULL
skip leading digit
B -> object register
* C -> C+0 contains key, C+1 closure (value)
caller guarantees
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
at least this function exists
hash part is a 'weak reference' and does not contribute
'pc'
'errThrow'
DUK_TOK_SUPER
This is guaranteed by debugger code.
[... (sep) str1 str2 ... strN buf]
0: no change
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
reg(ignored)
undefined coerces to zero which is correct
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
returned after EOF (infinite amount)
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
Unwind catchstack entries referring to the callstack entry we're reusing
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
e.g. DUK_OP_POSTINCR
'Uint8ClampedArray'
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
no typedef
[ ... func_template ]
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
[ arg1 ... argN obj length ]
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
comment: unused with some debug level combinations
label: code-design
Line number range for function. Needed during debugging to
* determine active breakpoints.
comment: slow init, do only for slow path cases
label: code-design
DUK_BUFOBJ_DUKTAPE_BUFFER
positive
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
e.g. DUK_OP_PREINCP
DUK_JS_H_INCLUDED
DUK_USE_DATE_NOW_WINDOWS
!DUK_SINGLE_FILE
this is added to checks to allow for Duktape
* API calls in addition to function's own use
[ ... key_obj key ]
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
is_setget
flags always encodes to 1 byte
Ensure space for 1:1 output plus one escape.
[ ... obj key value ]
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
C array of duk_labelinfo
comment: XXX: double evaluation for 'tv' argument.
label: code-design
with stack depth (affects identifier lookups)
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Detect recursive invocation
comment: known to be 32-bit
label: code-design
* Directive prologue tracking.
Handle lightfuncs through object coercion for now.
exponent 0
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
duk_handle_ecma_call_setup: setup for a tail call
match: keep wiped/resaved values
E5 Section 11.7.2, steps 7 and 8
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
heap thread, used internally and for finalization
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
For now all calls except Ecma-to-Ecma calls prevent a yield.
If tv1==tv2 this is a NOP, no check is needed
Dispatch loop.
DUK_TOK_SUB
Shared Windows helpers.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
catches EOF and invalid digits
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
* Call the constructor function (called in "constructor mode").
minimum prime
set by atom case clauses
[ ... error func fileName ]
reset callstack limit
right paren eaten
'['
idx_desc
E5 Section 11.7.1, steps 7 and 8
coerced value is updated to value stack even when RangeError thrown
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
Expression_opt
Exact halfway, round to even.
* Arguments check
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
name is empty -> return message
* Rescue or free.
grow by at most one
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
Note: proxy handling must happen before key is string coerced.
DUK_HBUFFEROBJECT_H_INCLUDED
[... res]
Note: unconditional throw
DUK_ERRMSG_H_INCLUDED
Neutered buffer, zero length seems
* like good behavior here.
no mark-and-sweep gc
* DUK_BSWAP macros
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
loggerName
will result in undefined
DUK_TOK_QUESTION
* Delayed initialization only occurs for 'NEWENV' functions.
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
Load constants onto value stack but don't yet copy to buffer.
[ hobject props enum(props) key desc ]
'Float32Array'
eat comma
range
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
Commands and notifys initiated by Duktape.
DUK_TOK_GT
* Stringtable
offset is now target of the pending split (right after jump)
U+03A3 = GREEK CAPITAL LETTER SIGMA
always 0 args
exit bytecode executor by rethrowing an error to caller
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
initialize built-ins - either by copying or creating new ones
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
IsAccessorDescriptor(desc) == true
avoid issues with relocation
avoid recursive string table call
res.x1 -> res.x2
-> [ ... x y fn ]
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
LHS is already side effect free
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
object has an array part (a_size may still be 0)
0x20...0x2f
eat dup slashes
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
initial estimate based on format string
enable exotic behaviors last
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
[ obj key desc ]
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
[... env callee varmap key val]
currently required
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
(flags<<32) + (line), flags = 0
insert range count
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
[ ... new_glob new_env ]
Count actually used (non-NULL, non-DELETED) entries.
no refcount check
Parse statements until a closing token (EOF or '}') is found.
duk_hthread_callstack_unwind() will decrease this on unwind
Note: array dump will include elements beyond
* 'length'.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
size stored in duk_heaphdr unused flag bits
genbuiltins.py ensures
-> [ ... val' ]
CR LF again a special case
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
Full, aligned 4-byte reads.
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
* Zero the struct, and start initializing roughly in order
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
duk_unicode_idp_m_ids_noa[]
mark-and-sweep is currently running
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
DUK_API_INTERNAL_H_INCLUDED
'\xffTarget'
FUNCTION EXPRESSIONS
0x50-0x5f
Note: there is no standard formatter for function pointers
default: no change
internal type tag
* Ecmascript bytecode executor.
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
p points to digit part ('%xy', p points to 'x')
the compressed pointer is zeroed which maps to NULL, so nothing to do.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
bottom of current frame
Shared offset/length coercion helper.
E5 Section 15.10.2.11
'writable'
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
internal spare
value (error) is at stack top
input byte length
gap (if empty string, NULL)
[ args [crud] arguments ]
lightfunc
higher value conserves memory; also note that linear scan is cache friendly
comment: XXX: to be implemented?
label: code-design
comment: XXX: convert to fixed buffer?
label: code-design
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Assume arrays are dense in the fast path.
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
* Value stack top handling
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
x <= y --> not (x > y) --> not (y < x)
[key setter this val]
little endian
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
* Misc util stuff
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
Node.js return value for failed writes is offset + #bytes
* that would have been written.
NaN sign bit is platform specific with unpacked, un-normalized NaNs
comment: XXX: union would be more correct
label: code-design
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
'stack'
Also check for the refzero_list; must not be there unless it is
* being finalized when duk_push_heapptr() is called.
*
* Corner case: similar to finalize_list.
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
".123"
currently used -> new size
caller is responsible for ensuring this
must be signed
uppercase
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
comment: XXX: optimize this filling behavior later
label: code-design
replaced
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
[ ... regexp input ] -> [ res_obj ]
Mostly API and built-in method related
E5 Sections 15.9.3.1, B.2.4, B.2.5
alloc and init
prediction corrections for prime list (see genhashsizes.py)
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
DUK_USE_REGEXP_SUPPORT
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
* Interrupt counter fixup (for development only).
Note: recursive call
maximum bytecode length in instructions
get const for value at valstack top
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
line tracking
first call
* All done
undefined is accepted
* Wrap up
this case can no longer occur because refcount is unsigned
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
reachable through activation
[ ... filename &comp_stk ]
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
+ 1 for rounding
note: any entries above the callstack top are garbage and not zeroed
must be, since env was created when catcher was created
side effects (currently none though)
DUK_BUILTIN_PROTOS_H_INCLUDED
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
shadowed, ignore
'Uint16Array'
-> [ ... enum_target res ]
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
+1 = one retval
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
[ ... obj key val ]
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
idx_value may be < 0 (no value), set and get may be NULL
numeric value (character, count)
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
assume 'var' has been eaten
empty separator can always match
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
coerce to string
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
no check
comment: XXX: optimize to 16 bytes
label: code-design
* Endian conversion
nrets
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
embed: integer value
0=base, 1=esc, 2=class, 3=class+esc
XXX: proper flags?
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
some assertions
array writes autoincrement length
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
reserved words: keywords
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
[... env callee varmap]
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
[ body formals source template ]
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
num args starting from idx_argbase
caller must change active thread, and set thr->resumer to NULL
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
unary plus
* Shortcut for accessing global object properties
* slice()
may be changed
step 3.e: replace 'Desc.[[Value]]'
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
[ ... varmap ]
* Type checking
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
Grow array part for a new highest array index.
no need to mask idx portion
remove hash entry (no decref)
index
exclusive endpoint
Append bytes from a slice already in the buffer.
this also increases refcount by one
whole, won't clip
[ source template ]
Cannot overlap.
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
apparently no hint?
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
XXX: clumsy sign extend and masking of 16 topmost bits
Note: no key on stack
[... retval]
DUK_USE_JX
num args
end of _Formals
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
2 when called by debugger
* Top level wrappers
DUK_INTERNAL_H_INCLUDED
Report next pc/line to be executed.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
fixed offsets in valstack
* Math built-ins
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
check that there is space for at least one new entry
0xa0...0xaf
eval left argument first
-> [ ... closure template ]
1 << 52
must match genhashsizes.py
setter and/or getter may be NULL
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
current thread
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
Duktape.Thread.yield() should prevent
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
LICENSE.txt
[ ... varname val ]
string is 'eval' or 'arguments'
* The default property attributes are correct for all
* function valued properties of built-in objects now.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
IdentifierStart production with ASCII excluded
nothing to mark
comment: XXX: function properties
label: code-design
prepend regexp to valstack 0 index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
convenience
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
[obj key value desc]
stmt has non-empty value
-> [ ... holder name val val ToString(i) ]
stage 2: delete configurable entries above target length
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
keep key reachable for GC etc; guaranteed not to fail
generate mantissa with a single leading whole number digit
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Stored in duk_heaphdr unused flags.
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
terminator
DUK_TOK_EQUALSIGN
* Comparison
DUK_JSON_H_INCLUDED
may have side effects
increases key refcount
on first round, skip
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
comment: XXX: solve into closed form (smaller code)
label: code-design
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
must be signed for loop structure
is_extra
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
Here 'x' is a Unicode codepoint
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
"-123456\0"
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
curr value
These are for rate limiting Status notifications and transport peeking.
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
DUK_USE_LEXER_SLIDING_WINDOW
DUK_TOK_NULL
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
-> [... obj value]
[ key trap_result ] -> []
replace in stack
(maybe) truncated
nothing to process
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
knock back "next temp" to this whenever possible
* Detected a directive
'for'
complete the millisecond field
'lt is true'
Pre/post inc/dec for register variables, important for loops.
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Iteration solution
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Helper tables
'this'
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
approximate
Avoid NaN-to-integer coercion as it is compiler specific.
Reset to zero size, keep current limit.
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
callback for indirect reallocs, request for current pointer
[ ... this ]
* Portable 12-byte representation
avoid multiple computations of flags address; bypasses macros
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
must not truncate
prefix matches, lengths matter now
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
* Replace valstack top with case converted version.
Shuffle decision not changed.
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
numeric value of token
[... constructor arg1 ... argN] -> [retval]
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
temps
'Object'
not strictly necessary
IsDataDescriptor(desc) == true
POSTFIX EXPRESSION
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
'Error'
* Flags for __FILE__ / __LINE__ registered into tracedata
Count actually used entry part entries (non-NULL keys).
DUK_TOK_ARSHIFT
comment: XXX: possibly incorrect handling of empty expression
label: code-design
used entries + approx 100% -> reset load to 50%
'\xffRegbase'
is_decl
but don't allow leading plus
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
[ ... holder name val enum obj_key val obj_key ]
lj.value1 is already set
number of arguments allocated to regs
Optimized for size.
* Default fatal error handler
named "arithmetic" because result is signed
Default implicit return value.
lookup name from current activation record's functions' registers
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
max # of key-value pairs initialized in one MPUTOBJ set
unicode code points, window[0] is always next
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
thread not currently running
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
[... key arg1 ... argN]
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
Chop extra retvals away / extend with undefined.
MPUTARR emitted by outer loop
comment: XXX: fastint?
label: code-design
compact the exports table
Code is not accepted before the first case/default clause
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
-> [ ... key val replacer holder key val ]
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
No debugger support.
'<'
treat like property not found
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
Carry is detected based on wrapping which relies on exact 32-bit
* types.
eat (first) input slash
value resides in a register or constant
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
Overflow, relevant mainly when listlen is 16 bits.
[ ... val ] --> [ ... enum ]
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
case 0: nop
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
Error: try coercing error to string once.
for resizing of array part, use slow path
y == -Infinity
Initialization and finalization (compaction), converting to other types.
must match exactly the number of internal properties inserted to enumerator
required
+ spare
All element accessors are host endian now (driven by TypedArray spec).
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
must "goto restart_execution", e.g. breakpoints changed
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
23: getUTCMilliseconds
no need to normalize
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
'this binding' is just under bottom
Default exports table
comment: XXX: macro smaller than call?
label: code-design
XXX: assert? compiler is responsible for this never happening
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
'require'
* Assertion helpers
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
19: getUTCMinutes
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
duk__get_min_grow_e() is always >= 1
* Reachable object, keep
'eval'
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
resolved id: require(id) must return this same module
We rely on a few object flag / class number relationships here,
* assert for them.
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
DUK_HEAP_H_INCLUDED
note: original, uncoerced base
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
DUK_OP_NONE marks a 'plain' assignment
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
Stack size decreases.
heap->strs: not worth dumping
-> [ ... closure template env funcname closure ]
step 12
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
comment: XXX: duk_ssize_t
label: code-design
DUK_ERR_UNCAUGHT_ERROR: no macros needed
-> [ ToObject(this) item1 ... itemN arr ]
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
* Debug dump type sizes
needed for line number tracking (becomes prev_token.start_line)
don't coerce yet to a plain value (variant 3 needs special handling)
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
Read value pushed on stack.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
'null' enumerator case -> behave as with an empty enumerator
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
Current compiler state (if any), used for augmenting SyntaxErrors.
push to stack
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'catch'
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
curr_pc synced back above
hash size approx. 1.25 times entries size
Write in little endian
source starts after dest ends
comment:
* Debugging macro calls.
label: code-design
DUK_USE_VERBOSE_ERRORS
0xxx xxxx -> fast path
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
unsigned shift
Not a very good provider: only full seconds are available.
110x xxxx 10xx xxxx [11 bits]
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
ensure value is 1 or 0 (not other non-zero)
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Indicate function type in the function body using a dummy
* directive.
'ObjEnv'
lj.value1 already set
millisec -> 100ns units since jan 1, 1970
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
DUK_TOK_SWITCH
class Object, extensible
idx_end
_Source
1 1 0 <8 bits>
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
minimum new length is highest_arr_idx + 1
DUK_TOK_RBRACKET
property is configurable and
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
Caller must ensure 'tv' is indeed a double and not a fastint!
Caller has already eaten the first character ('|') which we don't need.
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
structs from duk_forwdecl.h
assumed to also be PC of "LABEL"
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
'{"_undef":true}'
DUK_TOK_ADD_EQ
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
remove the original 'template' atom
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
* Heap native function representation.
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
'Invalid Date'
dynamic
comment:
* Node.js Buffer.concat()
label: code-design
comment: XXX: substring in-place at idx_place?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
embed: 0 or 1 (false or true)
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
string 2 of token (borrowed, stored to ctx->slot2_idx)
UNARY EXPRESSIONS
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
should actually never happen, but check anyway
input offset for window leading edge (not window[0])
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
continuation byte
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
ASCII fast path
Most input bytes go through here.
-> [ ... holder name val ]
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
useful for debugging
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
We should never exit the loop above.
may have FINALIZED
LAYOUT 3
comment: unused
label: code-design
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
'Int32Array'
an error handler (user callback to augment/replace error) is running
without refcounts
arbitrary marker, outside valid exp range
extra -1 for buffer
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
[ ...val ] -> [ ... ]
allow empty expression
[ ... closure template name ]
# total registers target function wants on entry (< 0 => "as is")
comment: unnecessary shift for last byte
label: code-design
varenv remains reachable through 'obj'
Special coercion for Uint8ClampedArray.
valstack slot for temp buffer
* Node.js Buffer: constructor
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
Nothing worked -> not equal.
E5 Section 11.13.1 (and others for other assignments), step 4.
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
String and buffer enumeration behavior is identical now,
* so use shared handler.
37x32 = 1184 bits
heap->dbg_detached_cb: keep
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
[ ... key ] -> [ ... ]
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
mark range 'direct', bypass canonicalization (see Wiki)
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
return module.exports
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
control props
push value to stack
* shift()
k+argCount-1; note that may be above 32-bit range
* Assert macro: failure causes panic.
comment: Similar workaround for INFINITY.
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
number
Must be element size multiple from
* start offset to end of buffer.
empty ("") is allowed in some formats (e.g. Number(''), as zero
slow path is shared
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
-> [ ... func ]
* Various defines and file specific helper macros
no net exponent
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
11 bits
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
get before side effects
DUK_HSTRING_H_INCLUDED
avoid empty label at the end of a compound statement
no specific action, resume normal execution
for manual torture testing: tight allocation, useful with valgrind
XXX: skip count_free w/o debug?
everything except object stay as is
identifiers and environment handling
back to fast loop
DUK_USE_JX || DUK_USE_JC
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
is resume, not a tail call
* Basic stack manipulation: swap, dup, insert, replace, etc
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
strings may have inner refs (extdata) in some cases
class masks
keep label catcher
state updated, restart bytecode execution
Flags for duk_js_equals_helper().
[ ... func this <some bound args> arg1 ... argN _Args ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
DUK_USE_TAILCALL
comment: should never be called
label: code-design
denormal
-> loop body
note: this updates refcounts
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
t1 <- (+ r m+)
denormal or zero
mark-and-sweep control
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
DUK_TOK_LET
Remove a slice from inside buffer.
valstack slot for 2nd token value
one-based -> zero-based
Set .buffer
terminate
max size: radix=2 + sign
remaining actual steps are carried out if standard DefineOwnProperty succeeds
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
'{"_func":true}'
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
E5 Section 15.5.5.2
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
avoid calling write callback in detach1()
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
-> [ Object res ]
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
IdentifierStart production with Letter and ASCII excluded
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
end switch
DUK_TOK_LE
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
[ ... v1(func) v2(pc+flags) ]
Matches both +0 and -0 on purpose.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
start line of token (first char)
10: getMonth
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
x <- y
eat 'var'
cannot have >4G captures
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
normalize NaN which may not match our canonical internal NaN
Recompute argument count: bound function handling may have shifted.
[ ... key val ] -> [ ... ]
minval
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
DUK_TOK_ARSHIFT_EQ
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
* Pass 1
Use unsigned arithmetic to optimize comparison.
type and control flags, label number
DUK_TOK_RSHIFT_EQ
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
[ ... enum_target res trap_result ]
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
Automatic filename: 'eval' or 'input'.
cumulative opcode execution count (overflows are OK)
Fast path for fastints
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
'input'
countdown state
switch
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Shared exit handling for object/array serialization.
input string scan
as elements
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
no need to unwind
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
Strict functions don't get their 'caller' updated.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
currently nop
[ ... closure template ]
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
'func' on stack (borrowed reference)
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
-> [... val this]
comment: code emission temporary
label: code-design
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
(quotient-remainder (* r B) s) using a dummy subtraction loop
Note: either pointer may be NULL (at entry), so don't assert
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
reuse last emitted atom for remaining 'infinite' quantifier
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
* Dragon4 slow path digit generation.
Rule control flags.
USE_PROP_HASH_PART
don't compact objects; needed during object property allocation resize
r <- (remainder (* r B) s)
[ ... error arr ]
String is an own (virtual) property of a lightfunc.
16: getHours
'debugger'
* String manipulation
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
DUK_USE_DEBUGGER_INSPECT
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
comment: Process debug messages until we are no longer paused.
label: code-design
* Entries part
[in_val in_val]
DUK_TOK_LBRACKET
36 bits
for zero size allocations NULL is allowed
-> [... obj key value]
* Some change(s) need to be made. Steps 7-11.
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
end of diff run
* Buffer
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
XXX: stringtable emergency compaction?
thr->ptr_curr_pc is set by bytecode executor early on entry
Allow leading plus sign
if slice not fully valid, treat as error
Now two entries in the same slot, alloc list
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
thr->heap->lj.value1 is already the value to throw
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
* Because buffer values are often looped over, a number fast path
* is important.
starting line number
x <- x - y, use t as temp
EQUALITY EXPRESSION
* Unicode support tables automatically generated during build.
return thread
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
0x08583b00
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
not a wordchar
XXX: a "first" flag would suffice
reg count
Buffer used for generated digits, values are in the range [0,B-1].
assume memset with zero size is OK
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
Parse a number, other than NaN or +/- Infinity
Must be a "string object", i.e. class "String"
no decref needed for a number
[ ... | (crud) ]
x <- y - z, require x >= y => z >= 0, i.e. y >= z
26 bits
Used to support single-byte stream lookahead.
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
-> [ ToObject(this) ]
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
'\Udeadbeef'
* every(), some(), forEach(), map(), filter()
Test without volatiles
Lexer codepoint with additional info like offset/line number
Low memory options
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
Note: either pointer may be NULL (at entry), so don't assert.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
tail call -> reuse current "frame"
refcount is unsigned, so always true
work list for objects to be finalized (by mark-and-sweep)
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
comment: still in use with verbose messages
label: code-design
stack is unbalanced, but: [ <something> buf ]
parse ranges until character class ends
'delete'
comment: unused now, not needed until Turkish/Azeri
label: requirement
No platform-specific parsing, this is not an error.
mark finalizable as reachability roots
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
ToUint32() coercion required
'global'
not popped by side effect
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
Check array density and indicate whether or not the array part should be abandoned.
* Duktape.Buffer: toString(), valueOf()
descriptor type specific checks
DUK_USE_ERRTHROW
Can happen if duk_throw() is called on an empty
* callstack.
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
unary minus
ignore non-strings
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
move pivot to its final place
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
comment:
* Global state for working around missing variadic macros
label: code-design
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
tolerates NULL h_buf
forced_reg
DUK_TOK_PACKAGE
B -> target register
* C -> constant index of identifier name
no match, next case
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
NULL if tv_obj is primitive
lj value2: thread
Note: use 'curr' as a temp propdesc
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
* substring(), substr(), slice()
30: setHours
Expression, ']' terminates
* Number checkers
E5 Section 11.2.3, step 6.a.i
-> [ hobject props ]
XXX: shared handling for 'duk__expr_lhs'?
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
eat 'in'
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
zero-based month
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
expect_token
periods
idx of first argument on stack
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
check stack first
mod_id may be NULL
http://en.wikipedia.org/wiki/ANSI_escape_code
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
DUK_TOK_SET
* Lookup variable and update in-place if found.
'Int8Array'
Last component name in resolved path
Must match src/extract_chars.py, generate_match_table3().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Force pause if we were doing "step into" in another activation.
allow fmt==NULL
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
duk_hcompiledfunction flags; quite version specific
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Clamping needed if duk_int_t is 64 bits.
'id'
output bufwriter
-> x in [-2**31,2**31[
DUK_USE_SELF_TESTS
built-in strings
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Error throwing helpers
[ ... new_glob new_env new_glob new_glob ]
For lightfuncs, simply read the virtual property.
0x70-0x7f
stable
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
Duktape.Thread.resume()
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
nothing to NULL
use SameValue instead of non-strict equality
a value is left on stack regardless of rc
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
Note: this must match ToObject() behavior
'new' MemberExpression
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Report it to the debug client
no compact
restricted to regs
dummy so sp won't get updated
* Replace global object.
require a (mutable) temporary as a result (or a const if allowed)
contains value
'%s' and NULL is not portable, so special case
* it for debug printing.
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
Parse formals.
[... key arg1 ... argN func]
exit bytecode execution with return value
* Status message and helpers
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
DUK_SELFTEST_H_INCLUDED
Duktape object
0xb0-0xbf
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
[ ... res ]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
accessor with defined getter
comment: XXX: optimize for packed duk_tval directly?
label: code-design
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
allow source elements
one token before
'filename'
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
Allowed.
-> x in ]-2**32, 2**32[
no need to incref
Ecmascript function
embed: void ptr
Lightfuncs are always native functions and have "newenv".
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: XXX: cover this with the generic >1 case?
label: code-design
* Variant 1 or 3
'enumerable'
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
zero size not an issue: pointers are valid
fromPresent = true
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
assumes that allocated pointers and alloc funcs are valid
* if res exists
DUK_TOK_EQ
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
XXX: add 'language' argument when locale/language sensitive rule
* support added.
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
Infinity
comment: XXX: unoptimal use of temps, resetting
label: code-design
-> [ ... regexp string ] -> [ ... res_obj ]
token type (with reserved words as DUK_TOK_IDENTIFER)
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
# argument registers target function wants (< 0 => "as is")
'magic' constants for Murmurhash2
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
Object built-in methods
Skip fully.
switch (ch2)
type
* Allocate memory with garbage collection
* Main switch for statement / source element type.
Shared entry handling for object/array serialization.
overwrite sep
[ message error message ]
[ ... parent stash stash ] -> [ ... parent stash ]
Non-verbose errors for low memory targets: no file, line, or message.
DUK_BUFOBJ_ARRAYBUFFER
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
seconds, doesn't fit into 16 bits
unreferenced w/o tracebacks
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
must be updated to work properly (e.g. creation of 'arguments')
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
1:1 or special conversions, but not locale/context specific: script generated rules
roughly 0.5 kiB
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
DUK_TOK_WITH
0xa0-0xaf
* Table for base-64 decoding
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
[... buf]
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
Production allows 'DecimalDigits', including leading zeroes
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
[] -> []
key
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
-> [ array totalLength buf ]
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
is valid size
[ O Properties obj ]
extra coercion of strings is OK
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
FAIL
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
* Push result object and init its flags
number of continuation (non-initial) bytes in [0x80,0xbf]
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
comment: Note: we can reuse 'desc' here
label: code-design
empty statement with an explicit semicolon
* Constructor
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
* toString()
shuffle registers if large number of regs/consts
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
[ result ]
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
[ source ]
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
combines steps 2 and 5; -len ensures max() not needed for step 5
for register-bound and declarative env identifiers
bound functions are never in act 'func'
Lightfuncs cannot be bound.
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
Don't allow mixed padding and actual chars.
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
DUK_TOK_CONTINUE
unbalanced stack on purpose
arguments MUST have an initialized lexical environment reference
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
tags
regexp compiler should catch these
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
-> [ ... voidp true ]
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mp <- b^(e+1)
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
at most sizeof(buf) - 1
val
Old solution: don't iterate, incorrect
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
No BC shuffling now.
syntactically left-associative but parsed as right-associative
* Local result type for duk__get_identifier_reference() lookup.
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
' '
* Heap stringtable handling, string interning.
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Creation time error augmentation
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
check that byte has the form 10xx xxxx
* Memory constants
return 'res' (of right part) as our result
-> [ func funcname env ]
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
* Assertion helpers.
is_setget
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
replacer function
[ ... ]
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
+(function(){}) -> NaN
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
Reject attempt to change a read-only object.
final result is already in 'res'
21: getUTCSeconds
Eval is just a wrapper now.
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
22: getMilliseconds
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
combined algorithm matching E5 Sections 9.5 and 9.6
Evaluates to (duk_uint8_t *) pointing to start of area.
module.id = resolved_id
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
Maximum number of characters in formatted value.
Read fully.
* Prototypes
For indirect allocs.
always allow 'in', coerce to 'tr' just in case
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
Pointer object internal value is immutable
Leave 'value' on stack
prev char
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
'extends'
result: hash_prime(floor(1.2 * e_size))
bp is assumed to be even
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
If buffer has been exhausted, truncate bitstream
Can be called multiple times with no harm.
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
error
1:1 conversion
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
not LS/PS
invalid codepoint encoding or codepoint
comment: packed advance/token number macro used by multiple functions
label: code-design
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
DUK_TOK_BAND_EQ
remaining
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
Faster but value stack overruns are memory unsafe.
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
already in correct reg
the next 'if' is guaranteed to match after swap
Encoding state. Heap object references are all borrowed.
-> [ ... repl_value ]
no prototype
Note: 'q' is top-1
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
comment: XXX: incref by count (2) directly
label: code-design
')'
source is a function expression (used for Function constructor)
* Variant 2
Stored in duk_heaphdr h_extra16.
Note: intentionally signed.
'Date'
input linenumber at input_offset (not window[0]), init to 1
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
idx_value
[ ... this_new | arg1 ... argN ]
------XX XXXX----
* Get old and new length
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
38: getYear
initjs data is NUL terminated
this.raw(buffer)
return h_bufres
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
-> [ ... regexp_instance ]
Final result is at stack top.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
right exists, [[Put]] regardless whether or not left exists
* Return target object.
reuse 'res' as 'left'
st_used remains the same, DELETED is counted as used
is_join
binding power must be high enough to NOT allow comma expressions directly
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
_Formals
base of known return values
TimeClip(), which also handles Infinity -> NaN conversion
[ ... obj ]
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
flags used for property attributes in duk_propdesc and packed flags
directly uses slow accesses
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
add AC*2^32
result: updated refcount
Entry level info.
catch depth from current func
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
decoding
inline initializer for coercers[] is not allowed by old compilers like BCC
* Create normalized 'source' property (E5 Section 15.10.3).
variable access
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
comment: XXX: refactor out?
label: code-design
same for both error and each subclass like TypeError
[ ... res_obj re_obj input bc saved_buf ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
entire string is whitespace
'multiline'
'+'
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
'lineNumber'
refer to callstack entries below current
statement parsing
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
ignore retval -> [key]
%ld
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
syntax error
don't push value
'buffer'
inherit initial strictness from parent
module
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
not emergency
* Raw memory calls: relative to heap, but no GC interaction
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Evaluate RHS only when LHS is safe.
debugger detaching; used to avoid calling detach handler recursively
no catchers
* Variant 4
'package'
nothing now
* Reset trigger counter
* Preliminaries
count is already incremented, take into account
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
inline string concatenation
DUK_USE_JX && DUK_USE_JC
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
[key] (coerced)
comment: XXX: no optimized variants yet
label: requirement
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
'base64'
[ sep ToObject(this) len sep ]
comment:
* Various sanity checks for typing
label: code-design
Check whether statement list ends.
invalidates tv1, tv2
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
-> sets 'f' and 'e'
Check for maximum string length
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
accessor
set to 1 if any match exists (needed for empty input special case)
this should never be possible, because the switch-case is
* comprehensive
avoid double coercion
'DataView'
* Sweep stringtable
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
DUK_TOK_IN
jump to false
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
heapobj recursion depth when deep printing is selected
basic types
temp reset is not necessary after duk__parse_stmt(), which already does it
mark-and-sweep: reachable
Error object is augmented at its creation here.
DUK_USE_COMMONJS_MODULES
at least effective 'this'
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
DUK_USE_LIGHTFUNC_BUILTINS
some derived types
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
x == +Infinity
temp_start+0 = key, temp_start+1 = closure
E5.1 Section 15.1.3.2: empty
DUK_TOK_FINALLY
comment: Static call style.
label: code-design
'deleteProperty'
Compiling state of one function, eventually converted to duk_hcompiledfunction
to body
Coerce top into Object.prototype.toString() output.
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
actual update happens once write has been completed without
* error below.
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
Target object must be checked for a conflicting
* non-configurable property.
property exists, either 'desc' is empty, or all values
* match (SameValue)
[ func thisArg argArray ]
p overshoots
prefer direct
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
Must restart in all cases because we NULLed thr->ptr_curr_pc.
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
checked by Duktape.Thread.resume()
* Union aliasing, see misc/clang_aliasing.c.
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
eat closing quote
setup many variables in nc_ctx
comment: XXX: fast int-to-double
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
comment: XXX: shorter version for 12-byte representation?
label: code-design
a fresh require() with require.id = resolved target module id
Constructor
elision - flush
temp reg for key literal
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
[ ... bytecode escaped_source ]
[obj key desc value get set curr_value]
>>
msec
unary plus of a number is identity
equals and strict equals
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
tv points to element just below prev top
* Duktape/C function magic
* Identifier handling
error gets its 'name' from the prototype
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
E5 Sections 11.9.1, 11.9.3
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
current digit
* Extern
* Mark objects on finalize_list.
*
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
'valueOf'
XXX: potential issue with signed pointers, p_end < p.
* Helpers to resize properties allocation on specific needs.
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
shared object part
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
[ ... re_obj input ]
Backpointers.
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
bottom of new func
re_ctx->captures at the start of the atom parsed in this loop
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
refzero_list treated as reachability roots
* Memory calls.
+0.5 is handled by floor, this is on purpose
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
internal temporary value, used for char classes
comment: format is too large, abort
label: code-design
-> [ ... key val' ]
0x40-0x4f
MPUTOBJ emitted by outer loop
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
be_ctx->offset == length of encoded bitstream
'in'
Duktape.modLoaded[resolved_id] = module
Caller must ensure 'tv' is indeed a fastint!
stage 1 guarantees
typed for duk_unicode_decode_xutf8()
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
[ ... varname ]
preinitialize lexer state partially
comment: XXX: slightly awkward
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
require
rnd in [lo,hi]
must have catch and/or finally
V
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
DUK_TOK_BXOR
[ ... re_obj input bc saved_buf res_obj val ]
No arr_idx update or limit check
[... varname]
fresh require (argument)
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
String object internal value is immutable
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
highest capture number emitted so far (used as: ++captures)
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
[ ... name name ]
nargs
each call this helper serves has nargs==2
assertion disabled
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
* A C
* B A
* C <- sce ==> B
* D D
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
* Case conversion
* Helpers for dealing with the input string
const limits
0xc0-0xcf
The issues below can be solved with better flags
curr and desc are data
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
statement is guaranteed to be terminal (control doesn't flow to next statement)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
chain
[ ... closure ]
comment: Calling as a non-constructor is not meaningful.
label: code-design
* Voluntary periodic GC (if enabled)
Step types
'default'
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
E5 Section steps 7-8
result object is created and discarded; wasteful but saves code space
Gather in little endian
'fmt'
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
NUL terminate for convenient C access
'BYTES_PER_ELEMENT'
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* Node.js Buffer.prototype.fill()
* Exposed debug macros: debugging disabled
comment: No NUL term checks in this debug code.
label: code-design
DUK_BUFOBJ_FLOAT64ARRAY
embed: duk_hobject ptr
getters
DUK_TOK_DELETE
DUK_TOK_BOR
comment: pseudotypes, not used in actual longjmps
label: code-design
A -> target reg
* BC -> inner function index
refcount code is processing refzero list
[ ... retval ]; popped below
0x80...0x8f
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
entry_top + 1
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
* ToBoolean() (E5 Section 9.2)
* Shift to new valstack_bottom.
0 = don't push current value
"." is not accepted in any format
tmp -> res
[ body formals source ]
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
Other initial bytes.
Similar to String comparison.
Finally, blame the innermost callstack entry which has a
* .fileName property.
skip finalizers; queue finalizable objects to heap_allocated
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
fixed top level hashtable size (separate chaining)
not present
end marker
handle negative values
invalidated by pushes, so get out of the way
h is NULL for lightfunc
* Error throwing
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
comment: unused: not accepted in inbound messages
label: code-design
Reuse buffer as is unless buffer has grown large.
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
internal align target for props allocation, must be 2*n for some n
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
target
DUK__FLD_FLOAT
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> x in [0, 2**32[
rethrow original error
'\xffThis'
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
Check if any lookup above had a negative result.
DUK_USE_DEBUGGER_SUPPORT
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
DUK_TOK_SUB_EQ
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
Fixed header info.
nothing to finalize
throw flag irrelevant (false in std alg)
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
name
accept string if next char is NUL (otherwise reject)
* "WhiteSpace" production check.
value1 -> yield value, iserror -> error / normal
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
reachable so pop OK
may be NULL, too
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
* Heap creation and destruction
[ ... regexp_object escaped_source ]
now expected to fit into a 32-bit integer
Duktape.modSearch(resolved_id, fresh_require, exports, module).
bits 0...1: shift
Architecture, OS, and compiler strings
overflow
must fit into duk_small_int_t
'continue'
'value'
Non-critical.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
DUK_USE_DATE_NOW_GETTIMEOFDAY
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
E5 Sections 15.10.2.8, 7.3
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
Important to do a fastint check so that constants are
* properly read back as fastints.
remove artificial bump
important to use normalized NaN with 8-byte tagged types
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
crossed offsets or zero size
[ ... escaped_source bytecode ]
* E5 Section 11.4.8
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
* ToInteger() (E5 Section 9.4)
invalidates tv
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
num_stack_args
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
'\xffVarmap'
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Only allow Duktape.Buffer when support disabled.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
* Heap Buffer object representation. Used for all Buffer variants.
comment: Note: reuse variables
label: code-design
_Varmap
= 1 + arg count
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
'case'
num_pairs and temp_start reset at top of outer loop
Because size > 0, NULL check is correct
17: getUTCHours
[ ... enum ] -> [ ... next_key ]
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
* Finalize stack
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
no need for 'caller' post-check, because 'key' must be an array index
[ arg undefined ]
''
* String-to-number conversion
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
0x10...0x1f
Main operation
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
invalidated
DUK_USE_CPP_EXCEPTIONS
max(incl)
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
comment: XXX: use helper for size optimization
label: code-design
'ignoreCase'
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
frozen and sealed
tv -> value just before prev top value; must relookup
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
initial estimate for ASCII only codepoints
Parser separator masks.
just in case callback is broken and won't write 'x'
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
then to a register
retval to result[i]
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
expect EOF instead of }
resizing parameters
value from target
this is especially critical to avoid another write call in detach1()
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
return the argument object
new buffer of specified size
* Conversion helpers
%x; only 16 bits are guaranteed
mix-in value for computing string hashes; should be reasonably unpredictable
'debug'
keep default instance
Make buffer compact, matching current written size.
explicit semi follows
* Packed 8-byte representation
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
comment: XXX: awkward helpers
label: code-design
advance, expecting current token to be a specific token; parse next token in regexp context
stack prepped for func call: [ ... trap handler ]
'{"_nan":true}'
tagged null pointers should never occur
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
* Finally, longjmp
e.g. DUK_OP_POSTINCP
Allow leading minus sign
copy to buffer with spare to avoid Valgrind gripes from strptime
throw
4: toLocaleDateString
eat 'with'
[ ... this func ]
setters
step 4.c
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
comment: XXX: relocate
label: code-design
match fail
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
DUK_USE_DATE_TZO_GMTIME
Treat like debugger statement: nop
Get valstack index for the func argument or throw if insane stack.
comment: 'd3' is never NaN, so no need to normalize
label: code-design
XXX: push_uint_string / push_u32_string
return value from Duktape.Thread.resume()
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
end of loop (careful with len==0)
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
DUK_TOK_TRY
Optional UTC conversion.
6
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
provideThis=false
* Self test main
prototype is lex_env before catcher created
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
tc1 = true, tc2 = false
no need to handle thread state book-keeping here
Not found. Empty string case is handled specially above.
4 low bits
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
[ ... enum ] -> [ ... ]
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
misc constants and helper macros
zero-based day
28: setMinutes
non-object base, no offending virtual property
Fixed seed value used with ROM strings.
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
E5 Sections 11.8.1, 11.8.5; x < y
may be < thr->catchstack initially
complex, multicharacter conversion
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
E5.1 Section 15.1.3.1: uriReserved + '#'
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
'"' was eaten by caller
expression is left-hand-side compatible
string is a reserved word (strict)
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
Step 9: copy elements-to-be-deleted into the result array
0x30-0x3f
2 bits for heap type
setjmp catchpoint setup
comment: not sure whether or not needed; Thursday
label: requirement
emergency mode: try extra hard
Set object 'length'.
byte index limit for element access, exclusive
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
[ ... eval "eval" eval_input level ]
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
!(p < r)
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
num_stack_args
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
complete 'sub atom'
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
round out to 8 bytes
for convenience
buffer limits
Handle TypedArray vs. Node.js Buffer arg differences
DUK_TOK_WHILE
offset/value order different from Node.js
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
DUK_TOK_VOID
DUK_USE_PC2LINE
DUK_HOBJECT_FLAG_STRICT varies
[ ... errval errhandler ]
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
serialize the wrapper with empty string key
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
BITWISE EXPRESSIONS
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
Valstack resize flags
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
finish up pending jump and split for last alternative
nop
* Local declarations.
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
x > y --> y < x
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
resumee: [... initial_func] (currently actually: [initial_func])
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
proto can also be NULL here (allowed explicitly)
* split()
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
could also just pop?
Parser part indices.
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Local prototypes
low-level property functions
helpers for defineProperty() and defineProperties()
w/o refcounts
Skip dvalues to EOM.
all native functions have NEWENV
+1, right after inserted jump
only accept lowercase 'utf8' now.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: XXX: block removal API primitive
label: code-design
LOGICAL EXPRESSIONS
%lf, %ld etc
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
8: getFullYear
* Debug connection peek and flush primitives
'do'
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
exponential notation forced
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
Here we'd have the option to normalize -0 to +0.
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
default: false
comment: fill new_h with u32 0xff = UNUSED
label: code-design
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
if direct eval, calling activation must exist
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
Fast check for extending array: check whether or not a slow density check is required.
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
filename may be NULL in which case file/line is not recorded
unsigned
comment: XXX: function flag to make this automatic?
label: requirement
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Breakpoint entries above the used area are left as garbage.
allow_source_elem
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
fall through if overflow etc
inner function numbering
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
function needs shuffle registers
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
invalid padding
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
[ requested_id require require.id resolved_id last_comp ]
advance to get one step of lookup
Write signed 32-bit integer.
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
Needs lookahead
* Churn refzero_list until empty
Note: 'q_instr' is still used below
duk_unicode_caseconv_uc[]
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
failed, resize and try again
extend with undefined
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
Error; error value is in heap->lj.value1.
-> [ ... key val toJSON val key ]
callstack
read 3 bytes into 't', padded by zero
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
* Computed values (e.g. INFINITY)
DUK_TOK_DIV_EQ
already set
input 'd' in Windows UTC, 100ns units
Keep current size
50x heap size
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
[ name this ]
[ ... holder name val enum obj_key new_elem ]
patched later
[ ... regexp_object ]
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
This was the last term, and q_last was
* updated to match this term at loop top.
x <- b^y; use t1 and t2 as temps
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
ref.holder is global object, holder is the object with the
* conflicting property.
essentially tracks digit position of lowest 'f' digit
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
binding power "levels" (see doc/compiler.rst)
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
result reg
strings are only tracked by stringtable
to avoid relookups
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
Reviving an object using a heap pointer is a dangerous API
* operation: if the application doesn't guarantee that the
* pointer target is always reachable, difficult-to-diagnose
* problems may ensue. Try to validate the 'ptr' argument to
* the extent possible.
':'
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
Slice starting point is beyond current length.
... target is extensible
duk_unicode_support.c
comment: XXX: easier check with less code?
label: code-design
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
x <- x * y, use t as temp
[ ... v1 v2 str ] -> [ ... str v2 ]
Zero 'count' is also allowed to make call sites easier.
comment: XXX: size optimize
label: code-design
!= 0 => post-update for array 'length' (used when key is an array index)
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
false
* Built-in strings
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
* Variant 3
* On second pass, skip the function.
OK for NULL.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
-> [ ... key val toJSON val ]
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
[ obj trap_result res_arr propname ]
split1: prefer direct execution (no jump)
in resumer's context
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
'try'
-> [in_val]
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
Note: 0xff != DUK_BC_B_MAX
* Unions and structs for self tests
Note: masking is done for 'i' to deal with negative numbers correctly
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
don't run finalizers; queue finalizable objects back to heap_allocated
val1 = count
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Get minimum array part growth for a certain size.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
'enumerate'
DUK_TOK_RSHIFT
roughly 256 bytes
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
object is now reachable
flags: "im"
Copy trap result keys into the enumerator object.
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
Success path.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
t1 <- (* r B)
DUK_BUFOBJ_UINT8ARRAY
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
assertions: env must be closed in the same thread as where it runs
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
refzero not running -> must be empty
comment: XXX: differentiate null pointer from empty string?
label: code-design
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
DUK_USE_MARK_AND_SWEEP
* Coercion and fast path processing
y == +Infinity
caller required to know
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
'toLocaleString'
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
buffer is automatically zeroed
num_args
DUK_OP_EXTRA, sub-operation in A
insert the required matches (qmin) by copying the atom
DUK_USE_INTEGER_BE
out_clamped
adv = 2 default OK
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
'-0'
module table remains registered to modLoaded, minimize its size
* Detach handling
write back
[ ... filename (temps) func ]
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
* Second pass parsing.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
DUK_USE_EXEC_TIMEOUT_CHECK
* Misc defines
E5.1 Section 15.1.3.4: uriUnescaped
Combined size of separators already overflows
-> [ ... res ]
[ ... this name message ]
"/" and not in regexp mode
DUK_USE_BYTECODE_DUMP_SUPPORT
comment: may indirectly slow access through a direct eval
label: code-design
no incref needed
variable binding register if register-bound (otherwise < 0)
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
[ ... varname val this ] (because throw_flag == 1, always resolved)
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
embed: duk_hbuffer ptr
t >= 0 always true, unsigned
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
vararg function, careful arg handling (e.g. thisArg may not be present)
implicit this value always undefined for
* declarative environment records.
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
duk_unicode_ids_noabmp[]
Return value of 'sz' or more indicates output was (potentially)
* truncated.
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
Encoding/decoding flags
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
no need to write 'out_bufdata'
new_used / size <= 1 / DIV <=> new_used <= size / DIV
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
label handling
Expression
comment: This is performance critical because it appears in every DECREF.
label: code-design
code_idx = entry_top + 0
-> [ ... lval rval ]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
eat 'throw'
always grow the array, no sparse / abandon support here
leave formals on stack for later use
since index non-negative
tzoffset
duk_has_prop() popped the second 'name'
varname
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
-------- ----XXXX
stack top: new time value, return 1 to allow tail calls
basereg
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
jump for 'catch' case
Module object containing module.exports, etc
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
-> [ ... escaped_source bytecode ]
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
5: toLocaleTimeString
mark-and-sweep: children not processed
Catches EOF of JSON input.
radix
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
no wrapping
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
object or array
no need to check now: both success and error are OK
Note: allow backtracking from p == ptr_end
Relookup if relocated
module.filename for .fileName, default to resolved ID if
* not present.
-> [ ... toLocaleString ToObject(val) ]
DUK_TOK_LBRACKET already eaten, current token is right after that
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
Restore stack top after unbalanced code paths.
position of highest digit changed
* duk_heap allocation and freeing.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
no statement value (unlike function expression)
Three digit octal escape, digits validated.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Quite approximate but should be useful for little and big endian.
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
retval for success path
* Wrapping duk_safe_call() will mangle the stack, just return stack top
* Node.js Buffer.prototype: toJSON()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
'fileName'
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
parse args starting from "next temp"
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
* Mark-and-sweep garbage collection.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
comment: unnecessary div for last byte
label: code-design
buffer values are coerced first to string here
sanity limit for function pointer size
[ sep ToObject(this) len sep str0 ... str(count-1) ]
DUK_TOK_YIELD
comment: XXX: is valstack top best place for argument?
label: code-design
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
duk_hobject_run_finalizer() sets
[ source template closure ]
Successful return: restore jmpbuf and return to caller.
negative -> no atom matched on previous round
[ ... name ]
Note: may be NULL if first call
unresolvable, no stack changes
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
DUK_USE_DATE_NOW_TIME
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
* Reference counting implementation.
use strict equality instead of non-strict equality
This assert depends on the input parts representing time inside
* the Ecmascript range.
controls for minimum array part growth
-> [ ... key ]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
allow basic ASCII whitespace
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
activation is a direct eval call
current lex_env of the activation (created for catcher)
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
start byte offset of token in lexer input
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
curr_token = get/set name
Initial '[' has been checked and eaten by caller.
Thread may have changed, e.g. YIELD converted to THROW.
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
be paranoid for 32-bit time values (even avoiding negative ones)
* Node.js Buffer.byteLength()
emit instruction; could return PC but that's not needed in the majority
* of cases.
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
All the flags fit in 16 bits, so will fit into duk_bool_t.
flags: "g"
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
end of _Varmap
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
[-0x80000000,0x7fffffff]
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
'Arguments'
[key getter this] -> [key retval]
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
only functions can have arguments
E5 Section 9.3.1
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
0xd0...0xdf
tv1 is -below- valstack_bottom
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
[ obj Properties ]
* First attempt
not found
Loop check.
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
reserved words: additional future reserved words in strict mode
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
Sync and NULL early.
12 to 21
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
-> pushes fixed buffer
comment: XXX: improve check; check against nregs, not against top
label: code-design
byte sizes will match
max # of values initialized in one MPUTARR set
not reached
-> [ ... this ]
* Local defines and forward declarations.
comment: prev value must be unused, no decref
label: code-design
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
x >= y --> not (x < y)
yes, must set array length explicitly
* Post resize assertions.
Note: for dstlen=0, dst may be NULL
!DUK_USE_TRACEBACKS
-> [ func funcname env funcname ]
Constants for duk_lexer_ctx.buf.
Difference is in 100ns units, convert to milliseconds w/o fractions
* "IdentifierPart" production check.
prev exists and is not a letter
Note: no recursion issue, we can trust 'map' to behave
if fails, e_size will be zero = not an issue, except performance-wise
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment: workaround: max nbits = 24 now
label: code-design
DUK_USE_HEX_FASTPATH
DUK_UTIL_H_INCLUDED
'Infinity'
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
debugger state, only relevant when attached
highest value of temp_reg (temp_max - 1 is highest used reg)
* Init compiler and lexer contexts
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
pre/post opcode values have constraints,
allocated heap objects
re-read to avoid spill / fetch
LRU: move our entry to first
argument/function declaration shadows 'arguments'
Proxy target
unconditional block
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
* Node.js Buffer.prototype.copy()
DUK_VERBOSE_ERRORS
skip '|'
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
'byteLength'
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
* Detect iteration statements; if encountered, establish an
* empty label.
skip ')'
* Poppers
DUK_HOBJECT_H_INCLUDED
always at least the header
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Fast path, decode as is.
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
'break'
in yielder's context
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
non-leap year: sunday, monday, ...
activation has tail called one or more times
extended types: custom encoding
reg
-> [... enum key val]
EOF
XXX: optimize value stack operation
* Proxy object handling
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
mark as complex (capture handling)
string is a reserved word (non-strict)
s <- b^(1-e) * 2
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Map DUK__FLX_xxx to byte size.
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
* Get/require
key, getter and setter, now reachable through object
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
'Array'
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
extended utf-8 not allowed for URIs
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
bytecode limits
guaranteed to find an empty slot
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Allow trailing garbage (e.g. treat "123foo" as "123)
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
steps 3.h and 3.i
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
module (argument)
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
current paren level allows 'in' token
comment: XXX: fast-int-to-double
label: code-design
* ArrayBuffer.isView()
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
* Debugging enabled
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: XXX: duk_set_length
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
XXXXXX-- --------
* Bitstream decoder.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
retval (sub-atom char length) unused, tainted as complex above
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
should not happen
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
DUK_TOK_REGEXP
* Peephole optimize JUMP chains.
* Execution timeout check
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
type to represent a reg/const reference during compilation
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
*
* The ArrayBuffer offset is always set to zero, so that if one
* accesses the ArrayBuffer at the view's .byteOffset, the value
* matches the view at index 0.
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
DUK_TOK_PUBLIC
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
'get'
comment: function name (borrowed reference), ends up in _name
label: code-design
repl_value
quotes
'undefined' already on stack top
'res' is used for "left", and 'tmp' for "right"
def_value
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
comment: XXX: skip null filename?
label: code-design
avoid multiply
New require() function for module, updated resolution base
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
"-Infinity", '-' has been eaten
make absolute
'act' already set above
DUK_BUFOBJ_UINT8CLAMPEDARRAY
comment: XXX: turkish / azeri, lowercase rules
label: code-design
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
no comma
strict outer context
jump for 'finally' case or end (if no finally)
* Structs
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
from next pc
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
use 'left' as a temp
JSON
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
* Pointer built-ins
Zero length string is not accepted without quotes
[ key ] -> []
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
current function being compiled (embedded instead of pointer for more compact access)
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
Note: 'this' may be bound to any value, not just an object
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
out of spec, don't care
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
used by e.g. duk_regexp_executor.c, string built-ins
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Share yield longjmp handler.
curr_token slot2 (matches 'lex' slot2_idx)
Error message doesn't matter: the error is ignored anyway.
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment: actually used
label: code-design
rule match
* Helper structs
terminating conditions
see below
allow automatic semicolon even without lineterm (compatibility)
Outside any activation -> put to global.
+0 = break, +1 = continue
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
-> [ val arr ]
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
this is needed for regexp mode
jump to next case clause
pop plain buffer, now reachable through h_bufres
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
add AD*2^16
Proxy handler
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
relookup exports from module.exports in case it was changed by modSearch
* Indexed read/write helpers (also used from outside this file)
adv = 2 - 1 default OK
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
comment: XXX: side effect handling is quite awkward here
label: code-design
act->func
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Call setup checks callability.
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
DUK_BUFOBJ_UINT32ARRAY
* Restore 'caller' property for non-strict callee functions.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
0x60...0x6f
>= 0
mimic semantics for strings
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
DUK__FLD_8BIT
[key]
normal key/value
mm <- b^e
steps 4.a and 4.b are tricky
The external string struct is defined even when the feature is inactive.
fixed arg count
A -> flags
* B -> return value reg/const
* C -> currently unused
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
-> [ ... closure template newobj ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
* Size-optimized pc->line mapping.
return as is
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
function: create binding for func name (function templates only, used for named function expressions)
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
comment: XXX: copy from caller?
label: code-design
always for register bindings
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
heap->dbg_udata: keep
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
dummy value used as marker
never here, but fall through
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
must never longjmp
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
stack top contains 'true'
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
'\xffHandler'
Note: string is a terminal heap object, so no depth check here
0x80-0x8f
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
Debug print which visualizes the qsort partitioning process.
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
r <- (2 * f) * b^e
unreferenced with some options
always terminates led()
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
awkward; we assume there is space for this
Peek ahead in the stream one byte.
* Breakpoint management
* Compact an object
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
alias for above
handle comma and closing brace
shrink case; leave some spare
strictness is not inherited, intentional
only Array.prototype matches
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
This seems reasonable overall.
Loop prevention
'throw'
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
Assume that the native representation never contains a closing
* parenthesis.
varargs marker
entry level reached
Current strictness flag: affects API calls.
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
'*'
call is from executor, so we know we have a jmpbuf
Yield/resume book-keeping.
finally part will catch
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
Load inner functions to value stack, but don't yet copy to buffer.
[ start end ]
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
DUK_TOK_THROW
comment: Note: not a typo, "object" is returned for a null value
label: documentation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
Original idiom used, minimal code size.
comment: 'fun' is quite rarely used, so no local for it
label: code-design
comment: XXX: fastint
label: code-design
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
normal
Careful with wrapping (left shifting idx would be unsafe).
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
"+11:22\0"
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
caller
match followed by capture(s)
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
'ptr' is evaluated both as LHS and RHS.
* Ecmascript [[Class]]
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
finalize_list will always be processed completely
comment: XXX: exposed duk_debug_read_pointer
label: code-design
-> [ ... key val replacer holder ]
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
open scope information, for compiled functions only
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
temp reg handling
* Parse function body
x <- y - z
'Pointer'
relookup if changed
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
throw_flag
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
break/continue without label
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
non-global regexp: lastIndex never updated on match
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
exposed because lexer needs these too
empty match (may happen with empty separator) -> bump and continue
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
Set up curr_pc for opcode dispatch.
[ ... pattern flags escaped_source ]
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
Get minimum entry part growth for a certain size.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
thr->heap->lj.value2 is 'thread', will be wiped out at the end
break/continue with label (label cannot be a reserved word, production is 'Identifier'
property access
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
internal property functions
Report thrown value to client coerced to string
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
DUK_USE_USER_INITJS
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
110x xxxx 10xx xxxx
Sanity limits for stack sizes.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
No net refcount change.
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
result array is already at the top of stack
args go here as a comma expression in parens
[ ... source? filename? &comp_args ] (depends on flags)
no extra padding
Start position (inclusive) and end position (exclusive)
tentative, checked later
slot A is a source (default: target)
indexed by recursion_depth
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
Order of unwinding is important
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
tracks maximum initialized index + 1
comment: first register that is a temporary (below: variables)
label: code-design
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
Just skip, leaving zeroes in the result.
[ ... arr ]
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
bytes in source
no voluntary gc
A -> result reg
* B -> object reg
* C -> key reg/const
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
refcount
regexp res_obj is at index 4
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
']'
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
-> [ func funcname env funcname func ]
true, because v[1] has at least one bit set
bp to use when parsing a top level Expression
Caller will finish the marking process if we hit a recursion limit.
y
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
TypeError if fails
* Entries part
* Delayed env creation check
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
guarantees entry_callstack_top - 1 >= 0
no code needs to be emitted, the regs already have values
magic: 0=getter call, 1=Object.getPrototypeOf
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
* Debug connection write primitives
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
module.name for .name, default to last component if
* not present.
* Exposed debug macros: debugging enabled
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
0xe0-0xef
compact the prototype
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
read header
prop index in 'hash part', < 0 if not there
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
object is a native function (duk_hnativefunction)
[ ... error func fileName lineNumber ]
21 bits
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
embed: duk_hstring ptr
enumeration
* Free memory
Maximum value check ensures 'nbytes' won't wrap below.
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
currently, even for Array.prototype
unsigned intentionally
DUK_TOK_SNEQ
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
No need to assert, buffer size maximum is 0xffff.
default is explicit index read/write copy
not enumerable
* Exposed data
avoid problems if p == h->prototype
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
Output shuffle needed after main operation
For native calls must be NULL so we don't sync back
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
omitted
'toGMTString'
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
* ISO 8601 subset parser.
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
[res]
dash is already 0
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
keep val_highest
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
can't get value, may be accessor
Relookup and initialize dispatch loop variables. Debugger check.
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
leave result on stack top
Resolved, normalized absolute module ID
marker; not actual tagged value
re-lookup curr char on first round
[ ... formals arguments map mappedNames ]
borrowed: full duk_tval for function being executed; for lightfuncs
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
Skip dvalue.
comment: XXX: inefficient; block remove primitive
label: code-design
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
[ ... pattern flags ]
custom; implies DUK_HOBJECT_IS_THREAD
[ thisArg arg1 ... argN ]
for array and object literals
validation of the regexp is caller's responsibility
regnum is sane
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
Preinc/predec for var-by-name, slow path.
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
Small variant; roughly 150 bytes smaller than the fast variant.
-> [ ... closure template env funcname ]
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
_Pc2line
Sanity checks for string and token defines
number of escapes and line continuations (for directive prologue)
MakeTime
comment: XXX: this is possible without resorting to the value stack
label: code-design
ignored
NULL for lightfunc
lookup shorthands (note: assume context variable is named 'lex_ctx')
Other callbacks are optional.
truncated in case pass 3 needed
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
Leave 'getter' on stack
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
Q...f
x < y
set exotic behavior only after we're done
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Current size is about 152 bytes.
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
while repl
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
DUK_HEAPHDR_HAS_FINALIZED may be set if we're doing a
* refzero finalization and mark-and-sweep gets triggered
* during the finalizer.
Setup state. Initial ivalue is 'undefined'.
'object'
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
1 1 1 <32 bits>
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
patch in range count later
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
0: toString
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
lowest mantissa for this exponent
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
all we need to know
ASSIGNMENT EXPRESSION
IdentityEscape
Must decrease recursion depth before returning.
note: mixing len into seed improves hashing when skipping
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
Return with final function pushed on stack top.
Note: 'e' and 'E' are also accepted here.
'%c', passed concretely as int
thread resumed another thread (active but not running)
or a non-catching entry
next char
-> [... key val]
add F
comment: return a specific NaN (although not strictly necessary)
label: code-design
* Variant 1
global regexp: lastIndex updated on match
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
Current size (not counting a dynamic buffer's "spare").
+2 = catcher value, catcher lj_type
parsing in "directive prologue", recognize directives
non-strict: non-deletable, writable
DUK_USE_64BIT_OPS
simulate alloc failure on every realloc (except when mark-and-sweep is running)
7
comment: alloc temp just in case, to update max temp
label: code-design
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
exposed, used by e.g. duk_bi_date.c
* Parsing of ints and floats
flags: "gi"
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
* Return target object
side effects
[ ... result ]
only objects have finalizers
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
* Thread support.
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
temp copy, write back for next loop
char loop
basic platform types
we currently assume virtual properties are not configurable (as none of them are)
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
address
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
may be NULL
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
IEEE double is approximately 16 decimal digits; print a couple extra
* Resizing and hash behavior
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
[obj key undefined]
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* isArray()
DUK_USE_HOBJECT_HASH_PART
trailing elisions?
* Simple commands
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
[ ... global val ] -> [ ... global ]
length in codepoints (must be E5 compatible)
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
Decode helper. Return zero on error.
XXX: specify array size, as we know it
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
1111 0xxx; 4 bytes
start array index of current MPUTARR set
cp == -1 (EOF) never matches and causes return value 0
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
DUK_OP_CALL flags in A
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
Must be >= 0 and multiple of element size.
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
note that we can't reliably pop anything here
[... put_value]
5
ref.value and ref.this_binding invalidated here
nret
object is a compiled function (duk_hcompiledfunction)
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
Need a short reg/const, does not have to be a mutable temp.
delete Duktape.modLoaded[resolved_id]
keep current valstack_top
Disabled until fixed, see above.
'message'
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
0x70...0x7f
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
comment: XXX: depend on available temps?
label: code-design
default case
%u; only 16 bits are guaranteed
MultiplicativeExpression
Trim white space (= allow leading and trailing whitespace)
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
One particular problem case is where an object has been
* queued for finalization but the finalizer hasn't yet been
* executed.
*
* Corner case: we're running in a finalizer for object X, and
* user code calls duk_push_heapptr() for X itself. In this
* case X will be in finalize_list, and we can detect the case
* by seeing that X's FINALIZED flag is set (which is done before
* the finalizer starts executing).
does not modify tv_x
26: setSeconds
patch pending jump and split
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
only needed by debugger for now
Compute day number of the first day of a given year.
ignore_loop
* Begin
Output #1: resolved absolute name
and even number
* DELPROP: Ecmascript property deletion.
normal: implicit leading 1-bit
may throw an error
* Encoding constants, must match genbuiltins.py
'RegExp'
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
<<
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
ensure full memcmp() fits in while
unreachable
push operation normalizes NaNs
getter/setter
x == 0x00 (EOF) causes syntax_error
XXX: range assert
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
flags: "i"
* Init stringtable: probe variant
Catches both doubles and cases where only one argument is a fastint
key coercion (unless already coerced above)
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Limit checks for bytecode byte size and line number.
The necessary #includes are in place in duk_config.h.
comment: XXX: this could be optimized
label: code-design
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
comment: Silence a few global unused warnings here.
label: code-design
-> [... arr num]
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
thread has yielded
Lightfuncs are always strict.
'\xffArgs'
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
Further state-dependent pre-checks
E5 Section 8.12.8
is_decl
at least one activation, ours
s <- b^(-e) * 2
use p_src_base from now on
'taint' result as complex
no issues with memcmp() zero size, even if broken
* Disjunction struct: result of parsing a disjunction
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
Previous entry was inside visited[], nothing to do.
comment: XXX: optimize temp reg use
label: code-design
toFixed()
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
duk_unicode_idp_m_ids_noabmp[]
'(?:)'
* Process replacer/proplist (2nd argument to JSON.stringify)
may be a string constant
return total chars written excluding terminator
[ (builtin objects) name ]
new_free / size <= 1 / DIV <=> new_free <= size / DIV
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
[ ... holder name val enum obj_key ]
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
exit() afterwards to satisfy "noreturn"
string compare is the default (a bit oddly)
'%xx%xx...%xx', p points to char after first '%'
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
2^4 -> 1/16 = 6.25% spare
* reduce(), reduceRight()
* Macros for accessing size fields
* Resolve module identifier into canonical absolute form.
leap year: sunday, monday, ...
even after a detach and possible reattach
tval
comment: integer mixed endian not really used now
label: code-design
only advance if not tainted
tail insert: don't disturb head in case refzero is running
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
0.000...
leave stack unbalanced on purpose
[ ... func this <bound args> arg1 ... argN ]
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Table for hex encoding bytes
[ ... buf func ] -> [ ... func ]
build result as: (r << 32) + s: start with (BD + E + F)
We only get here when doing non-standard JSON encoding
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
[target] -> [enum]
Handle both full and partial slice (as long as covered).
envrec: (declarative) record is closed
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
XXX: bump preventcount by one for the duration of this call?
for
15: getUTCDay
need_bytes may be zero
register binding lookup is based on varmap (even in first pass)
prototype: the only internal property lifted outside 'e' as it is so central
3 entries actually needed below
end of input and last char has been processed
[ start length str ]
array
fast paths for space and tab
Significand ('f') padding.
comment: not needed
label: requirement
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
add a new pending match jump for latest finished alternative
exclusive
DUK_USE_BUILTIN_INITJS
* If selftests enabled, run them as early as possible
ivalue/ispec helpers
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
idx_this = idx_func + 1
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
not needed, as we exit right away
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
relookup, may have changed
leading digit + fractions
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
tc1 = true, tc2 = true
See comments below on MakeTime why these are volatile.
-> [ val obj val ]
Store lexer position, restoring if quantifier is invalid.
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
marker; not actual tagged type
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
For NaN/inf, the return value doesn't matter.
curr char
[ regexp string ]
comment: NULL not needed here
label: code-design
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
special result value handling
[ ... Logger clog res ]
[... put_value varname]
intermediate join to avoid valstack overflow
ptr before mark-and-sweep
end-of-input breaks
reserve a jumpslot after instr before target spilling, used for NEXTENUM
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
* Variable access
comment: function: function must not be tail called
label: code-design
third arg: absolute index (to entire valstack) of idx_bottom of new activation
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
!DUK_USE_HSTRING_CLEN
DUK_ERR_EVAL: no macros needed
DUK_USE_PREFER_SIZE
Incref copies, keep originals.
object is a buffer object (duk_hbufferobject) (always exotic)
recheck that the property still exists
jump from true part to end
comment: XXX: fastint fast path would be very useful here
label: code-design
XXX: happens e.g. when evaluating: String(Buffer.prototype).
'name'
eat identifier
* Init stringtable: fixed variant
Copy values through direct validated reads and writes.
break matches always
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
-1 for opcode
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
comment: hash part size or 0 if unused
label: code-design
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
helper to insert a (non-string) heap object into heap allocated list
* Internal API calls which have (stack and other) semantics similar
* to the public API.
retval is directly usable
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
digit count
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
2^3 -> 1/8 = 12.5% min growth
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
'hex'
borrowed label name
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
Longjmp state is kept clean in success path
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
Would indicate corrupted lists.
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
comment: XXX: faster internal way to get this
label: code-design
old value is number: no refcount
Using classification has smaller footprint than direct comparison.
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
leading byte of match string
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
canonicalized by compiler
[ source template closure this ]
initial index
5 heap flags
DUK_TOK_FUNCTION
exponent for 'f'
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
always 1 arg
helpers
* Single source autogenerated distributable for Duktape 1.8.0.
*
* Git commit 0a70d7e4c5227c84e3fed5209828973117d02849 (v1.8.0).
* Git branch v1.8-maintenance.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
ignore result
DUK_JMPBUF_H_INCLUDED
Newline allows module last line to contain a // comment.
'static'
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
extended types: compatible encoding
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
valstack limit caller has check, prevents wrapping
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
Note: number has no explicit tag (in 8-byte representation)
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
reg/const for case value
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
signed integer encoding needed to work with UTF-8
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
'&'
jump is inserted here (variant 3)
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
resumee: [... initial_func undefined(= this) resume_value ]
ignore reclimit, not constructor
'\xffCallee'
is normalized
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
Coerce like boolean
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
[ (builtin objects) ]
comment: XXX: tv_func is not actually needed
label: requirement
* Source filename (or equivalent), for identifying thrown errors.
'__proto__'
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
parent env is the prototype
get varenv for varname (callee's declarative lexical environment)
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
Note: can be safely scanned as bytes (undecoded)
========================================================================
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
also goes into flags
UnaryExpression
comment: XXX: return something more useful, so that caller can throw?
label: code-design
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
all virtual properties are non-configurable and non-writable
[ obj trap_result res_arr ]
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
depth check is done when printing an actual type
Preinc/predec for object properties.
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
init function state: inits valstack allocations
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
comment: XXX: inject test
label: code-design
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK_USE_PARANOID_ERRORS
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Without ROM objects "needs refcount update" == is heap allocated.
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
side effects -> don't use tv_x, tv_y after
[... enum]
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
DUK_TOK_LT
no value
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
hash probe sequence
* Make the C call
DUK_USE_NONSTD_FUNC_STMT
has access to 'this' binding
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
initial size guess
Buffer writes are often integers.
env[funcname] = closure
Safe to call multiple times.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
formatted result limited
[] -> [res]
may be NaN
'undefined', artifact of lookup
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
lj value1: value
pushes function template
Identifier, i.e. don't allow reserved words
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
[ arg toLogString ]
out_token->lineterm set by caller
note: any entries above the catchstack top are garbage and not zeroed
Error code also packs a tracedata related flag.
enumerator must have no keys deleted
Stack size increases or stays the same.
known to be number; in fact an integer
avail_bytes += need_bytes
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
temp variable to pass constants and flags to shared code
char length of the atom parsed in this loop
-> [ ... fn x y ]
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
-> [...]
topmost activation idx_retval is considered garbage, no need to init
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
ref.value, ref.this.binding invalidated here by getprop call
* Field accessor macros
[ ... buf ]
idx_base and idx_base+1 get completion value and type
integer number in range
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
check stack before interning (avoid hanging temp)
The extra (+4) is tight.
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
DUK_TOK_STATIC
No pointer compression because pointer is potentially outside of
* Duktape heap.
'null'
pc2line
always normalized
JUMP L1 omitted
comment: writable, not configurable
label: code-design
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
big endian
entry_top + 3
must match bytecode defines now; build autogenerate?
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
'.'
* Automatically generated by genbuiltins.py, do not edit!
* Debug connection read primitives
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: XXX: optimize with more direct internal access
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
0x00-0x0f
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
DUK_TOK_BOR_EQ
Argument must be a string, e.g. a buffer is not allowed.
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
number of formal arguments
register, constant, or value
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
h_code: held in bw_code
* Forward declarations.
heap pointer comparison suffices
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
Backtrack.
comment: XXX: code duplication
label: code-design
arg count
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
[ ... number ] -> [ ... string ]
'data' (and everything in it) is reachable through h_res now
Fast path.
called as a normal function: return new Date().toString()
------XX
must be computed after realloc
'join'
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
re-lookup first char on first loop
[ ... buf loop (proplist) ]
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
DUK_USE_DATE_FMT_STRFTIME
eat the right paren
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
-1 if disjunction is complex, char length if simple
noblame_fileline
Backtrack to previous slash or start of buffer.
func limits
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
comment: code_idx: not needed
label: requirement
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
load factor min 25%
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
Assume interrupt init/counter are properly initialized here.
* Parse a case or default clause.
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
maxval
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
Careful overflow handling. When multiplying by 10:
* - 0x19999998 x 10 = 0xfffffff0: no overflow, and adding
* 0...9 is safe.
* - 0x19999999 x 10 = 0xfffffffa: no overflow, adding
* 0...5 is safe, 6...9 overflows.
* - 0x1999999a x 10 = 0x100000004: always overflow.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
* Bitstream encoder
-> [ sep ToObject(this) len str sep ]
Decrement PC if that was requested, this requires a PC sync.
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
no side effects
INACTIVE: no activation, single function value on valstack
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
this cannot initiate a detach
done so that duk__mark_heaphdr() works correctly
if highest bit of a register number is set, it refers to a constant instead
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
byte offset to buf
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
comment: unused now
label: code-design
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
still in prologue
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
fixed-format termination conditions
DUK_TOK_ELSE
* Add line number to a compiler error.
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
Ensure copy is covered by underlying buffers.
longjmp state
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
Expression, terminates at a ')'
can't happen when keeping current stack size
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
Miscellaneous.
-> [ ... retval ]
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
-> [ timeval this ]
comment: Clean up stack
label: code-design
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
unwind to 'yield' caller
How much stack to require on entry to object/array decode
(e.g. k=3, digits=2 -> "12X")
Note: changing from writable to non-writable is OK
unwinds valstack, updating refcounts
For JX, expressing the whole unsigned 32-bit range matters.
r <- 2 * f
currently active breakpoints: NULL term, borrowed pointers
conversions, coercions, comparison, etc
[key val] -> [key]
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
* Misc support functions
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
array of formal argument names (-> _Formals)
[ ... func this arg1 ... argN ]
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
key encountered as a getter
comment: XXX: typing
label: code-design
catches EOF (NUL)
'act' is no longer accessed, scanbuild fix
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
[ ... RegExp ]
DUK_TOK_DECREMENT
[ ... errhandler undefined errval ]
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
no wrap assuming h_bufobj->length is valid
Nominal size check.
register bound variables are non-configurable -> always false
-> [ obj trap handler target ]
reasonable output estimate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
* Character and charcode access
nargs == 2 so we can pass a callstack level to eval().
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
normal valued properties
'\xffLexenv'
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
variable map for pass 2 (identifier -> register number or null (unmapped))
buffer pointer is to an externally allocated buffer
'Uint32Array'
'with'
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
callstack index of related activation
non-standard
may be safe, or non-safe depending on flags
activation prevents yield (native call or "new")
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
DUK__FLD_VARINT; not relevant here
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
eat 'try'
1110 xxxx 10xx xxxx 10xx xxxx
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Expects 'this' at top of stack on entry.
The token in the switch has already been eaten here
currently all labels accept a break, so no explicit check for it now
[ arg result ]
got lineterm preceding non-whitespace, non-lineterm token
intentional overlap with earlier memzero
Allow exponent
'\xffSource'
read-only object, in code section
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Shared object part.
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
DUK_OP_RETURN flags in A
DUK_TOK_ADD
allocate to reg only (not const)
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
requested number of output digits; 0 = free-format
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
DUK_TOK_EOF
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
XXX: duk_dup_unvalidated(ctx, -2) etc.
fill new entries with -unused- (required, gc reachable)
-> [ O toString O ]
accept anything, expect first value (EOF will be
* caught by key parsing below.
unknown, ignore
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
[ ... v1 v2 name filename ]
!DUK_USE_PANIC_HANDLER
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
expected ival
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
no sce, or sce scan not best
caller must have decref'd values above new_a_size (if that is necessary)
[ ... buf loop (proplist) (gap) ]
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
checked by caller
'Int16Array'
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
thread; minimizes argument passing
step 4.d
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
one operator (= assign)
no need to init reg, it will be undefined on entry
string objects must not created without internal value
eat backslash on entry
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
comment: XXX: Rework to use an always-inline function?
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
We're a varargs function because we need to detect whether
* initialValue was given or not.
cannot be strict (never mapped variables)
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
DUK_DEBUGGER_H_INCLUDED
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
0 if no used entries
* Basic double / byte union memory layout.
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
if new_p == NULL, all of these pointers are NULL
-> [... obj retval/error]
[ ... holder key ] -> [ ... holder ]
'this' binding is just before current activation's bottom
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
a
Allow leading zeroes (e.g. "0123" -> "123")
* Default clause.
d <- (quotient (* r B) s) (in range 0...B-1)
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Commands initiated by debug client.
next loop requires a comma
0x40...0x4f
'string'
match == search string, by definition
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
32-bit x 11-bit = 43-bit, fits accurately into a double
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
eat closing brace
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
without finally, the second jump slot is used to jump to end of stmt
slot B is a target (default: source)
fastint constants etc
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
Duktape.modLoaded
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
comment: XXX: call method tail call?
label: code-design
w.../
always provideThis=true
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
* Thread state and calling context checks
token type (with reserved word identification)
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
verified at beginning
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
XXX: duk_push_uint_string()
Built-in providers
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
pop final_cons
comment: When ptr == NULL, the format argument is unused.
label: code-design
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
ANSI C typing
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
1=little endian
* "IdentifierStart" production check.
* Compiler state
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Entries part is a bit more complex
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
nop: insert top to top
h_match is borrowed, remains reachable through match_obj
0 = uppercase, 32 = lowercase (= 'a' - 'A')
catch jump
3: toLocaleString
not reachable
leave 'cat' as top catcher (also works if catchstack exhausted)
+1 for opcode
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
Not halfway, round to nearest.
remove in_val
idx_argbase
Strict by default.
fixed precision and zero padding would be required
Ensuring (reserving) space.
flags: "m"
'setPrototypeOf'
return 1 to allow callers to tail call
* Not found (even in global object)
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
'number'
label id allocation (running counter)
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
comment: XXX: how to figure correct size?
label: code-design
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
op_flags
# argument registers target function wants (< 0 => never for ecma calls)
Different calling convention than above used because the helper
* is shared.
equality not actually possible
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
[ ... func this arg1 ... argN envobj ]
32: setDate
slot C is a target (default: source)
-> [ ... lval rval new_rval ]
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
sanity
deal with negative values
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
create bound function object
maximum bytecode copies for {n,m} quantifiers
[ ... lval rval ]
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
use duk_double_union as duk_tval directly
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't increase 'count'
module.exports = exports
simulate alloc failure on every alloc (except when mark-and-sweep is running)
must relookup act in case of side effects
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
status booleans
identifier handling
duk_unicode_caseconv_lc[]
DUK_TOK_PROTECTED
target
reserved words: future reserved words
Ensure space for maximum multi-character result; estimate is overkill.
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
* Pre resize assertions.
In-place unary operation.
Note: expect that caller has already eaten the left paren
implicit leading one
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
* Internal helpers for managing object 'length'
biased exp == 0 -> denormal, exp -1022
0xdeadbeef in decimal
strings up to the this length are not cached
DUK_HEAPHDR_H_INCLUDED
[ ... key_obj key val ]
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
keep func->h_argnames; it is fixed for all passes
num entries of new func at entry
One digit octal escape, digit validated.
Use result value as is.
step 15.a
formal arg limits
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
[ offset noAssert ], when ftype != DUK__FLD_VARINT
bufwriter for temp accumulation
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
-1 if invalid
convenience helpers
* Use Object.defineProperty() helper for the actual operation.
Ensure compact use of temps.
* Object handling: property access and other support functions.
allocated from valstack (fixed buffer)
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
DUK_TVAL_H_INCLUDED
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
last component
lexing (tokenization) state (contains two valstack slot indices)
* Update an existing property of the base object.
update length (curr points to length, and we assume it's still valid)
in-place setup
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
The lo/hi indices may be crossed and hi < 0 is possible at entry.
* Init compilation context
add E
'\xffThread'
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
* Special name handling
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: XXX: this is a major target for size optimization
label: code-design
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
XXX: check num_args
pop 'name'
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
* All done, switch properties ('p') allocation to new one.
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
decode '%xx' to '%xx' if decoded char in reserved set
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
any other printable -> as is
Called by duk_hstring.h macros
step type: none, step into, step over, step out
comment: XXX: faster implementation
label: code-design
cleared before entering catch part
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
comment: XXX: ignored now
label: code-design
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
* Automatically generated by extract_caseconv.py, do not edit!
* Support functions for duk_heap.
DUK_HCOMPILEDFUNCTION_H_INCLUDED
write_to_array_part:
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
E5 Section 15.5.5.1
own pointer
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
# total registers target function wants on entry (< 0 => never for ecma calls)
bytecode has a stable pointer
* Thread builtins
overwrite str1
comment: XXX: exposed duk_debug_read_buffer
label: code-design
DUK_JS_BYTECODE_H_INCLUDED
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
no need for refcount update
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
compiler ensures this
[... old_result result] -> [... result]
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
* concat()
different memory layout, alloc size, and init
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
default: NULL, length 0
env is closed, should be missing _Callee, _Thread, _Regbase
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
force_flag
Used for minimal 'const': initializer required.
* Table for base-64 encoding
Note: no allocation pressure, no need to check refcounts etc
args incorrect
write on next loop
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
2nd related value (type specific)
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
cannot grow
0=indexOf, 1=lastIndexOf
bump up "allocated" reg count, just in case
Strict standard behavior, ignore trailing elements for
* result 'length'.
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
DUK_TOK_IF
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
Working with the pointer and current size.
object has any exotic behavior(s)
DUK_USE_STRTAB_PROBE
written by a previous RESUME handling
comment:
* Macro support functions (use only macros in calling code)
label: code-design
string 1 of token (borrowed, stored to ctx->slot1_idx)
comment: XXX: more accurate?
label: code-design
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
level string
sufficient for keeping temp reg numbers in check
All other object types.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
mixed endian
min_new_size
length in bytes (not counting NUL term)
No finalizers for ROM objects
last element that was left in the heap
compact; no need to seal because object is internal
0x90...0x9f
const flag for C
[... obj] -> [...]
number of pairs in current MPUTOBJ set
escaped NonEscapeCharacter
Module id requested
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
Never executed if new size is smaller.
'protected'
because arg count is 1
'if'
finally free the struct itself
!DUK_USE_PARANOID_ERRORS
Array or Array-like
coerce towards zero
must not be extensible
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
mark-and-sweep: finalizable (on current pass)
[ ... replacer match [captures] match_char_offset input ]
DUK_OP_TRYCATCH flags in A
single string token
Use byte copy.
Most common cases first.
no point in supporting encodings of 5 or more bytes
'|'
use_prev_pc
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
Return value handling.
Enable DUKFUNC exotic behavior once properties are set up.
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
Assumes that caller has normalized NaNs, otherwise trouble ahead.
0x00: finish (not part of number)
* 0x01: continue
comment: this is relatively expensive
label: code-design
num_values and temp_start reset at top of outer loop
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
specific assert for wrapping
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
bits 2...5: type
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
'toUTCString'
Note: no need to re-lookup tv, conversion is side effect free
require.id of current module
low 32 bits is complete
time when status/peek was last done (Date-based rate limit)
[obj key value desc value]
'caller'
rbp_flags
'data'
'type'
comment: XXX: shared strings
label: code-design
-> [ ... source ]
default value
output 3 bytes from 't'
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
loop iterator init and limit changed from standard algorithm
enum_flags
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
by default, use caller's environment
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
value resides in 'valstack_idx'
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
free inner references (these exist e.g. when external
* strings are enabled)
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
surrogate pairs get encoded here
11: getUTCMonth
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
assert just a few critical flags
correction
default to false
* Stack slice primitives
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> []
DUK_USE_STRHASH_DENSE
* Get old and new length
clipped codepoint
h_new_proto may be NULL
-> [ ... errhandler errval ]
this is the case for normalized numbers
flags: "gim"
Starting from this round, use emergency mode
* for mark-and-sweep.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
* Found existing own or inherited plain property, but original
* base is a primitive value.
optional callstack level
e.g. duk_push_string_file_raw() pushed undefined
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
'error'
don't throw for prototype loop
(< (* r 2) s)
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
Note: not set in template (has no "prototype")
unreferenced w/o asserts
if (is_repl_func)
precision:shortest
don't resize stringtable (but may sweep it); needed during stringtable resize
Write curr_pc back for the debugger.
Note: duk__dec_req_stridx() backtracks one char
'length'
-> [ ... val retval ]
Object property access
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
3
Apply timezone offset to get the main parts in UTC
* Zero sign, see misc/tcc_zerosign2.c.
* Boolean built-ins
LeftHandSideExpression does not allow empty expression
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
Note: escaped characters differentiate directives
defaults, E5 Section 8.6.1, Table 7
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
special RegExp literal handling after IdentifierName
XXX: byte offset?
'switch'
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
avoid side effects
result in csreg
* Other heap related defines
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
strict: non-deletable, non-writable
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
use fallback as 'this' value
Caller has already eaten the first character ('(') which we don't need.
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
C recursion check.
b
Misc
catches EOF (0x00)
comment: XXX: duk_get_length?
label: code-design
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
'defineProperty'
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
marker for detecting internal "double faults", see duk_error_throw.c
three flags
No difference between raw/ensure because the buffer shrinks.
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
Start filling in the activation
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
prevent duk__expr_led() by using a binding power less than anything valid
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
[ ... proplist enum_obj key val ]
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
shrink failure is not fatal
!(l < p)
valstack index of loop detection object
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
yes -> move back to heap allocated
strict flag for putvar comes from our caller (currently: fixed)
catchstack limits
* Manually optimized number-to-double conversion
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
[ ... enum_target res trap_result val true ]
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
important for callers
fail
[ sep ToObject(this) len ]
DUK_TOK_PERIOD
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
idx_reviver
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
signed shift
Impose a string maximum length, need to handle overflow
* correctly.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
bytes left
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
failed
-> [... key]
comment: Tested: not faster on x64
label: code-design
clamp to 10 chars
* "LineTerminator" production check.
A lightfunc might also inherit a .toJSON() so just bail out.
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
comment: XXX: inefficient; block insert primitive
label: code-design
* Exposed helper for setting up heap longjmp state.
in non-packed representation we don't care about which NaN is used
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
zero
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
comment: XXX: tostring?
label: code-design
'func' wants stack "as is"
* Debug message processing
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
* Sweep heap
Object.keys
map is reachable through obj
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
required for rehash to succeed, equality not that useful
DUK_TOK_CLASS
comment: unused for label
label: code-design
'this' binding shouldn't matter here
comment: remove old value
label: code-design
comment: get rid of the strings early to minimize memory use before intern
label: code-design
always in entry part, no need to look up parents etc
* Raw intern and lookup
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
CONDITIONAL EXPRESSION
swap elements; deal with non-existent elements correctly
[ ... closure/error ]
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
ignore
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
vararg function, thisArg needs special handling
Assert for value stack initialization policy.
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
curr_token slot1 (matches 'lex' slot1_idx)
eat 'break' or 'continue'
zero-based -> one-based
roughly 512 bytes
* indexOf() and lastIndexOf()
DUK_USE_HEAPPTR16
regexp literal must not follow this token
qmin and qmax will be 0 or 1
same as during entry
Have a catch variable.
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
Object property allocation layout
Node.js accepts only actual Arrays.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
* Actual Object.defineProperty() default algorithm.
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
'class'
compare: similar to string comparison but for buffer data.
Note: if 'x' is zero, x->n becomes 0 here
Debugger protocol version is defined in the public API header.
not undefined
Endianness indicator
number of activation records in callstack preventing a yield
DUK_TOK_IMPLEMENTS
4'294'967'295
XXX: switch cast?
'trace'
array 'length' is always a number, as we coerce it
NULL is allowed, no output
* Convert duk_compiler_func to a function template
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
eat closing slash
* Regexp range tables
Value stack intentionally mixed size here.
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
hobject property layout
comment: UNUSED, intentionally empty
label: code-design
double quote or backslash
track utf-8 non-continuation bytes
[ hobject props enum(props) ]
22 to 31
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
-> [... enum key enum_target val]
constants arbitrary, chosen for small loads
reset 'allow_in' for parenthesized expression
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
if present, forces 16-byte duk_tval
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
exports (this binding)
disabled
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
read-only values 'lifted' for ease of use
return value
'source'
'clog'
digits
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
is_frozen
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
if duk_uint32_t is exactly 32 bits, this is a NOP
* Not found as a concrete property, check whether a String object
* virtual property matches.
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
off >= step, and step >= 1
zero-width joiner
Rethrow error to calling state.
'"'
next temporary register to allocate
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
relookup after side effects (no side effects currently however)
Note: this order matters (final value before deleting map entry must be done)
'arguments'
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
inline arithmetic check for constant values
pre-incremented, points to first jump slot
* Helpers for duk_compiler_func.
Note: need to re-lookup because ToNumber() may have side effects
expr_flags
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
accept string
unreferenced without assertions
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
'toString'
first character has been matched
0xfff0 is -Infinity
comment: XXX: don't want to shrink allocation here
label: code-design
-> [ ... error ]
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
curr_token follows 'function'
* Update preventcount
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
'toJSON'
function executes as a constructor (called via "new")
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
DUK_ERROR_H_INCLUDED
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
if 1, doing a fixed format output (not free format)
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
borrowed; NULL if no step state (NULLed in unwind)
new buffer with string contents
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
no regexp instance should exist without a non-configurable bytecode property
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
replaces top of stack with new value if necessary
33: setUTCDate
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
eat 'for'
init 'curr_token'
-> [ ... new_global new_globalenv new_global ]
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
implicit attributes
allow a constant to be returned
prop index in 'entry part', < 0 if not there
add_auto_proto
[ ... ToObject(this) ToUint32(length) val ]
Load bytecode instructions.
unsupported: would consume multiple args
DUK_USE_DEBUGGER_THROW_NOTIFY
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
There's intentionally no check for
* current underlying buffer length.
follow parent chain
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
comment: XXX: this should be an assert
label: test
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
No debugger support, just pop values.
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
[ hobject props enum(props) key desc value? getter? setter? ]
start match from beginning
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
DUK_USE_SECTION_B
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
comment: XXX: better to get base and walk forwards?
label: code-design
'ownKeys'
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
restore stack top
DUK_USE_BASE64_FASTPATH
Valstack should suffice here, required on function valstack init
duk_hnativefunction specific fields.
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Insert bytes in the middle of the buffer from an external buffer.
identifier names (E5 Section 7.6)
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
keep heap->dbg_detached_cb
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
During parsing, month and day are one-based; set defaults here.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
token allows automatic semicolon insertion (eof or preceded by newline)
Use special opcodes to load short strings
* Add .fileName and .lineNumber to an error on the stack top.
* CommonJS require() and modules support
* Lexing helpers
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
explicit PropertyList
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
* Create mantissa
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
ToNumber() for a fastint is a no-op.
[key] -> [undefined] (default value)
traceback depth fits into 16 bits
[ thisArg arg1 ... argN func boundFunc argArray ]
* Parser duk__advance() token eating functions
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
Same as above but for unsigned int range.
comma after a value, expected
duplicate key
Given a day number, determine year and day-within-year.
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
Success path handles
comment: XXX: getter with class check, useful in built-ins
label: code-design
already updated
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
match: keep saves
DUK_USE_PARANOID_MATH
'boolean'
* Debugging disabled
fixed offset in valstack
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
* Proxy helpers
* Found; post-processing (Function and arguments objects)
maps to finalizer 2nd argument
DUK_USE_AVOID_PLATFORM_FUNCPTRS
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
key encountered as a plain property
e.g. DUK_OP_POSTINCV
Allow empty string to be interpreted as 0
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
not minimum exponent
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
Because new_size > duk__count_used_probe(heap), guaranteed to work
bump refcount to prevent refzero during finalizer processing
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_string()
pointers for scanning
array part size (entirely gc reachable)
Steps 12 and 13: reorganize elements to make room for itemCount elements
number of tokens parsed
Tear down state.
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
zero handled by caller
Don't accept relative indices now.
[holder name val] -> [holder]
res_obj
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
function declaration
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
'?'
state == 3
Maximum traversal depth for "bound function" chains.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
[ thread value ]
* GETPROP: Ecmascript property read.
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
object is a thread (duk_hthread)
'info'
add a new pending split to the beginning of the entire disjunction
duk_push_this() + CheckObjectCoercible() + duk_to_object()
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
this may have side effects, so re-lookup act
Fall through to handle the rest.
[ ... error lineNumber fileName ]
* Number built-ins
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
-> [ ... closure template env ]
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
6: toUTCString
comment: note: ctx-wide temporary
label: code-design
value popped by call
Note: this may fail, caller should protect the call if necessary
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
4
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
s <- 2 * b
native functions: 149
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
exponent 1070
no need to reset temps, as we're finished emitting code
DUK_ERR_ERROR: no macros needed
comment: XXX: assumed to fit for now
label: code-design
[... fallback retval]
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
Getter might have arbitrary side effects,
* so bail out.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
-> [ ... voidp voidp ]
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
special helper for emitting u16 lists (used for character ranges for built-in char classes)
[ ... re_obj input bc saved_buf ]
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
Parser separator indices.
Regexp
k > 0 -> k was too low, and cannot be too high
'func' in the algorithm
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
Outside any activation -> look up from global.
Decrease by 25% every round
For manual testing only.
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
* Main heap structure
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
E5 Section 9.2
Backtrack utf-8 input and return a (possibly canonicalized) input character.
Cause an interrupt after executing one instruction.
Compiler
at least errobj must be on stack
16 bits
* Default panic handler
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
'modSearch'
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
does not fit into 16 bits
ensures no overflow
[ ... input buffer ]
execution resumes in bytecode executor
Standard JSON omits functions
7 bits
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
* Objects have internal references. Must finalize through
* the "refzero" work list.
different thread
number of values in current MPUTARR set
steps 13-14
Compute result length and validate argument buffers.
DUK_BUILTINS_H_INCLUDED
copy bytecode instructions one at a time
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
[ ... RegExp val ] -> [ ... res ]
load factor max 75%
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
* Resizing
token closes expression, e.g. ')', ']'
fileName
* Get prototype object for an integer error code.
'\xffNext'
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
borrow literal Infinity from builtin string
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
prefer direct execution
comment: Longjmp state is cleaned up by error handling
label: code-design
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
fall-through jump to next code of next case (backpatched)
already one-based
comment: XXX: could use at least one fewer loop counters
label: code-design
Wrap checked above.
Create function 'data' buffer but don't attach it yet.
* Function built-ins
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
comment: hacky helper for String.prototype.split()
label: code-design
[ (builtin objects) name func ]
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
toString() conditions
Write bytecode executor's curr_pc back to topmost activation (if any).
[] -> [val]
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
-> [ sep ToObject(this) len sep str ]
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
[ ... enum_target res handler trap ]
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
x <- (1<<y)
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
Any 'res' will do.
If neutered must return 0; length is zeroed during
* neutering.
XXX: assert idx_base
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
avoid side effect issues
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
SHIFT EXPRESSION
overflow, fall through
restored if ecma-to-ecma setup fails
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
If debugger is paused, garbage collection is disabled by default.
DUK_ERR_REFERENCE_ERROR: no macros needed
XXX: shared helper for duk_push_hobject_or_undefined()?
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
unconditionally
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
resumee
* Parse a function body or a function-like expression, depending
* on flags.
actually used, non-NULL entries
Fast path check.
length check
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
'{"_ninf":true}'
shared checks for all descriptor types
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
* Process space (3rd argument to JSON.stringify)
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
DUK_USE_PANIC_HANDLER
avoid array abandoning which interns strings
traits are separate; in particular, arguments not an array
duk__get_min_grow_a() is always >= 1
9: getUTCFullYear
[key getter this key] -> [key retval]
Source end clamped silently to available length.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
* Proxy built-in (ES6)
Native function, no relevant lineNumber.
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
'res' must be a plain ivalue, and not register-bound variable.
function helpers
'Null'
internal properties
custom
* XXX: shrink array allocation or entries compaction here?
ToInteger(lastIndex)
* Encoding/decoding helpers
default: NaN
covers -Infinity
Error instance, use augmented error data directly
t1 = (+ r m+)
[... func arg1 ... argN]
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
variable value (function, we hope, not checked here)
return 'res_obj'
E5 Section 10.4.2
DUK_FORWDECL_H_INCLUDED
avoid unary minus on unsigned
Just flip the single bit.
unicode code points, window[0] is always next, points to 'buffer'
probe
may be set to 0 by duk_debugger_attach() inside callback
Easy to get wrong, so assert for it.
mask out flags not actually stored
'with' target must be created first, in case we run out of memory
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
Important main primitive.
no throw
[ ... lval rval(func) ]
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
'lastIndex'
0xd0-0xdf
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
pop varname
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
debugger
* Automatically generated by extract_chars.py, do not edit!
* Copy keys and values in the entry part (compacting them at the same time).
expensive init, just want to fill window
'toLogString'
split2: prefer jump execution (not direct)
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
skip line info
heap destruction ongoing, finalizer rescue no longer possible
E5 Section 9.1
value stack indices for tracking objects
two encoding attempts suffices
DUK_ISPEC_XXX
comment: XXX: append primitive
label: code-design
current lexical environment (may be NULL if delayed)
explicit NULL inits
[ ... closure template env ]
use a temp: decref only when valstack reachable values are correct
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
0 or -1
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
Object.defineProperty() equivalent C binding.
skip jump slots
We can directly access value stack here.
DUK_TOK_TYPEOF
mark as complex
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
comment: m+ != m- (very rarely)
label: code-design
* Duktape debugger
Ecmascript activation + Duktape.Thread.resume() activation
'\''
[ ... str ]
-> [ ... value ]
Use temporaries and update lex_ctx only when finished.
mark-and-sweep not running -> must be empty
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_TOK_EXPORT
array of active label names
* Helper for C function call negative return values.
entry_top + 0
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
Shared helper.
x1 must be a string
[ ... value? getter? setter? ]
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
Gather in big endian
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
format is bit packed
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
parse args starting from "next temp", reg_target + 1
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
* Context init
comment: XXX: rework
label: code-design
Call stack. [0,callstack_top[ is GC reachable.
DUK_NUMCONV_H_INCLUDED
is a function declaration (as opposed to function expression)
Precomputed pointers when using 16-bit heap pointer packing.
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
= IsAccessorDescriptor(Desc)
36: setFullYear
Object is currently being finalized.
comment: not covered, return all zeroes
label: test
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
DUK_HTHREAD_H_INCLUDED
DUK_USE_ES6_PROXY
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Pretend like we got EOM
[ regexp source bytecode ]
catch depth at point of definition
-> [... cons target]
Grow entry part allocation for one additional entry.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
comment: XXX: better multiline
label: code-design
object literal key tracking flags
curr is accessor -> cannot be in array part
stmt has explicit/implicit semicolon terminator
lexing
[ ... result/error ]
catches EOF (NUL) and initial comma
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
currently running thread
temproots
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
vararg
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
Allow NULL 'msg'
borrowed reference
[... s1 s2] -> [... s1+s2]
DUK_TOK_DIV
comment: XXX: lithuanian not implemented
label: requirement
Explicit zero size check to avoid NULL 'tv1'.
* Get holder object
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
lead zero + 'digits' fractions + 1 for rounding
stack discipline consistency check
* Update the interrupt counter
these non-standard properties are copied for convenience
still reachable
* Forward declarations for all Duktape structures.
[ ... obj key ]
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
* Macros for property handling
val2 = min count, val1 = max count
find and remove string from stringtable; caller must free the string itself
Inner functions recursively.
== DUK__MAX_TEMPS is OK
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
use bigint area as a temp
'n'
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
step 4.b
(Number.MAX_VALUE).toString(2).length == 1024, + spare
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
Catch stack. [0,catchstack_top[ is GC reachable.
DUK_USE_DATE_TZO_WINDOWS
-> [ ... res_obj ]
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
flags is unsigned
Already declared but no initializer value
* (e.g. 'var xyz;'), no-op.
0
comment: XXX: better place for this
label: code-design
Zero encoded pointer is required to match NULL
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
upper limit, assuming no whitespace etc
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
comment: not necessary to init, disabled for faster parsing
label: code-design
We already ate 'x', so backup one byte.
maximum token count before error (sanity backstop)
* For ASCII strings, the answer is simple.
'super'
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
'JSON'
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
marker: copy t if not changed
thread has terminated
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
no error if file does not exist
internal flag value: throw if mask doesn't match
set getter (given on value stack)
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
* Duktape public API for Duktape 1.8.0.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit 0a70d7e4c5227c84e3fed5209828973117d02849 (v1.8.0).
* Git branch v1.8-maintenance.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
comment: XXX: Enough space to hold internal suspend/resume structure.
* This is rather awkward and to be fixed when the internal
* structure is visible for the public API header.
label: code-design
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
* Buffer
maximum size check is handled by callee
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
Load constants onto value stack but don't yet copy to buffer.
-> [ func funcname env ]
_Formals
Setup function properties.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
_Varmap is dense
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
skip line info
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
end of _Formals
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
buffer limits
Inner functions recursively.
known to be number; in fact an integer
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
Bytecode instructions: endian conversion needed unless
* platform is big endian.
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
duk_hcompiledfunction flags; quite version specific
standard prototype
Load bytecode instructions.
string limits
no side effects
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
comment: known to be 32-bit
label: code-design
Fixed header info.
constants are strings or numbers now
Create function 'data' buffer but don't attach it yet.
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
DUK_USE_BYTECODE_DUMP_SUPPORT
ensures no overflow
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
_Varmap
-> [ func funcname env funcname func ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
Constants: variable size encoding.
Return with final function pushed on stack top.
[ ... func buf ] -> [ ... buf ]
[ ... buf func ] -> [ ... func ]
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
may be NULL if no constants or inner funcs
assert just a few critical flags
Load inner functions to value stack, but don't yet copy to buffer.
comment: XXX: awkward
label: code-design
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
Important to do a fastint check so that constants are
* properly read back as fastints.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
Explicit zero size check to avoid NULL 'tv1'.
func.prototype.constructor = func
end of _Varmap
-> [ func funcname env funcname ]
-> [... cons target]
noblame_fileline
[... func this arg1 ... argN]
thread
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
num_stack_res
class Object, extensible
note that we can't reliably pop anything here
[... retval]
Strict by default.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
num_stack_args
nrets
Anything else is not constructable.
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
not protected, respect reclimit, is a constructor call
respect reclimit, not constructor
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
comment: XXX: code duplication
label: code-design
not protected, respect reclimit, not constructor
pop final_cons
[... fallback retval]
-> [... target]
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
make absolute
use fallback as 'this' value
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Lightfuncs cannot be bound.
* Call the constructor function (called in "constructor mode").
[... key arg1 ... argN]
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
[... constructor arg1 ... argN final_cons]
See comments in duk_pcall().
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
call_flags
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
must work for nargs <= 0
* Duktape/C function magic
fall through
unreachable
awkward; we assume there is space for this
[... key arg1 ... argN func]
func
Note: -nargs alone would fail for nargs == 0, this is OK
[... constructor arg1 ... argN]
also stash it before constructor,
* in case we need it (as the fallback value)
nargs
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
[... func arg1 ... argN]
[... constructor arg1 ... argN final_cons fallback]
duplicate key
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
* Manipulate callstack for the call.
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
-------- ----XXXX
output 3 bytes from 't'
XX==
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Fixed buffer, no zeroing because we'll fill all the data.
allowed ascii whitespace
full 3-byte -> 4-char conversions
allow basic ASCII whitespace
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
XXX=
read 3 bytes into 't', padded by zero
back to fast loop
never here
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
Backtrack.
idx_value
idx_space
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
------XX XXXX----
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
DUK_USE_HEX_FASTPATH
pointer is aligned, guaranteed for fixed buffer
Don't allow actual chars after equal sign.
Continue parsing after padding, allows concatenated,
* padded base64.
case 0: nop
XXXXXX--
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
Handle one slow path unit (or finish if we're done).
idx_reviver
Check if any lookup above had a negative result.
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
two level break
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
Don't allow mixed padding and actual chars.
------XX
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
invalid padding
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
aaaaaabb bbbbcccc ccdddddd
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
upper limit, assuming no whitespace etc
checked by caller
shift in zeroes
idx_replacer
Fast path, handle units with just actual encoding characters.
comment: XXX: convert to fixed buffer?
label: code-design
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment: There may be whitespace between the equal signs.
label: code-design
XXXXXX-- --------
comment: Tested: not faster on x64
label: code-design
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
DUK_USE_BASE64_FASTPATH
flags
Note: for dstlen=0, dst may be NULL
Note: for srclen=0, src may be NULL
* Compilation and evaluation
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
Helper which can be called both directly and with duk_safe_call().
[ ... source? func_template ]
[ ... source? filename? ]
add_auto_proto
[ ... closure/error ]
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
[ ... result/error ]
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
[ ... source? filename? ] (depends on flags)
[ ... func_template ]
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
e.g. duk_push_string_file_raw() pushed undefined
should be first on 64-bit platforms
Automatic filename: 'eval' or 'input'.
[ ... source? filename? &comp_args ] (depends on flags)
explicit 'this' binding, see GH-164
[ ... closure ]
comment: XXX: unnecessary translation of flags
label: code-design
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
Eval is just a wrapper now.
args incorrect
may be safe, or non-safe depending on flags
-> [ ... closure ]
[ ... source? filename ]
Treat like debugger statement: nop
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
idx_value
idx_space
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
Other callbacks are optional.
nop
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
DUK_USE_DEBUGGER_SUPPORT
Start in paused state.
no_block
No debugger support, just pop values.
idx_replacer
unreachable
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Treat like a debugger statement: ignore when not attached.
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Debugging related API calls
flags
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
Can be called multiple times with no harm.
[ ... new_glob new_env ]
side effects, in theory (referenced by global env)
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
* Heap creation and destruction
[ ... new_glob new_env new_glob new_glob ]
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
unvalidated
side effects
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
[ ... ]
comment: XXX: better place for this
label: code-design
* Replace global object.
no prototype, updated below
without refcounts
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
sometimes stack and array indices need to go on the stack
[key val] -> []
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
[val] -> []
comment: XXX: assumed to fit for now
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_object()
only needed by debugger for now
* Internal API calls which have (stack and other) semantics similar
* to the public API.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
[] -> []
duk_push_sprintf constants
comment: XXX: add fastint support?
label: requirement
This would be pointless: unexpected type and lightfunc would both return NULL
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
DUK_API_INTERNAL_H_INCLUDED
Set object 'length'.
duk_push_this() + CheckObjectCoercible() + duk_to_string()
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
[] -> [val]
Valstack resize flags
out_clamped=NULL, RangeError if outside range
comment: unused
label: code-design
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
[ ... Logger clog logfunc clog(=this) msg ]
nargs
[ ... Logger clog logfunc clog ]
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
[ ... Logger clog res ]
* Memory calls.
NULL accepted
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
* Helpers for writing multiple properties
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
remove key and value
[ ... obj ... ]
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
* Object finalizer
proto can also be NULL here (allowed explicitly)
a value is left on stack regardless of rc
pop key
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
Object.defineProperty() equivalent C binding.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
defprop_flags
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
XXX: shared helper for duk_push_hobject_or_undefined()?
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
* Object handling: property access and other support functions.
remove key
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
value popped by call
1 if property found, 0 otherwise
comment: XXX: "read only object"?
label: code-design
[ ... global val ] -> [ ... global ]
Note: this may fail, caller should protect the call if necessary
comment: XXX: direct implementation
label: requirement
comment: Clean up stack
label: code-design
[target] -> [enum]
* Object prototype
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
* Shortcut for accessing global object properties
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Maximum value check ensures 'nbytes' won't wrap below.
DUK_BUFOBJ_UINT32ARRAY
throw_flag
only flag now
DUK_USE_VARIADIC_MACROS
E5 Section 9.1
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
consequence of above
Never executed if new size is smaller.
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
comment:
* Global state for working around missing variadic macros
label: code-design
use a temp: decref only when valstack reachable values are correct
Note: recursive call
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Should match Function.prototype.toString()
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
Allowed.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
Assert for value stack initialization policy.
val is unsigned so >= 0
important to do this *after* pushing, to make the thread reachable for gc
!DUK_USE_PARANOID_ERRORS
initial estimate based on format string
no need to incref
coerce towards zero
Wrap checked above.
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
Non-critical.
default: false
success, fixup pointers
Coerce top into Object.prototype.toString() output.
* Misc helpers
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: XXX: several pointer comparison issues here
label: code-design
must be computed after realloc
side effects
number
radix
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
get pointer offsets for tweaking below
zero size not an issue: pointers are valid
DUK_BUFOBJ_INT8ARRAY
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
*
* The ArrayBuffer offset is always set to zero, so that if one
* accesses the ArrayBuffer at the view's .byteOffset, the value
* matches the view at index 0.
advance manually
out_clamped==NULL -> RangeError if outside range
not reached
because of valstack init policy
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
ensure value is 1 or 0 (not other non-zero)
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
object is now reachable
4 low bits
* Pushers
quotes
String table assert check omitted from 1.x branch
* backport.
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
comment: XXX: string not shared because it is conditional
label: code-design
E5 Section 8.12.8
'd' and 'res' agree here
XXX: direct valstack write
Creation time error augmentation
filename may be NULL in which case file/line is not recorded
Check for maximum buffer length.
Incref copies, keep originals.
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
'undefined' already on stack top
unsigned
covers +Infinity
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
avoid warning (unsigned)
default prototype (Note: 'obj' must be reachable)
everything except object stay as is
flags
Enable DUKFUNC exotic behavior once properties are set up.
DUK_BUFOBJ_UINT8ARRAY
may be NULL
comment: No coercions or other side effects, so safe
label: requirement
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_BUFOBJ_DATAVIEW
If tv1==tv2 this is a NOP, no check is needed
DUK_USE_ASSERTIONS
* Basic stack manipulation: swap, dup, insert, replace, etc
No net refcount change.
comment: XXX: shorter version for 12-byte representation?
label: code-design
special handling of fmt==NULL
specific assert for wrapping
Clamping only necessary for 32-bit ints.
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
DUK_BUFOBJ_UINT8CLAMPEDARRAY
caller required to know
ANSI C typing
as is
Only allow Duktape.Buffer when support disabled.
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
Explicit length is only needed if it differs from 'nargs'.
DUK_BUFOBJ_FLOAT64ARRAY
Reviving an object using a heap pointer is a dangerous API
* operation: if the application doesn't guarantee that the
* pointer target is always reachable, difficult-to-diagnose
* problems may ensue. Try to validate the 'ptr' argument to
* the extent possible.
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
inline initializer for coercers[] is not allowed by old compilers like BCC
comment: XXX: duk_ssize_t would be useful here
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
no shrink
nop: insert top to top
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
periods
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
Nothing to initialize, strs[] is in ROM.
[ ... parent stash stash ] -> [ ... parent stash ]
if slice not fully valid, treat as error
Note: no need to re-lookup tv, conversion is side effect free
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
DUK_BUFOBJ_ARRAYBUFFER
check stack first
Object is currently being finalized.
[ ... retval ]; popped below
tv points to element just below prev top
comment: XXX: fastint?
label: code-design
Would indicate corrupted lists.
dynamic
DUK_USE_FILE_IO
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
ignore fclose() error
DUK_BUFOBJ_FLOAT32ARRAY
not reachable
coerced value is updated to value stack even when RangeError thrown
error gets its 'name' from the prototype
no side effects
shrink case; leave some spare
'this' binding exists
may be NULL (but only if size is 0)
failed, resize and try again
* Poppers
-> [ ... func this ]
comment: not very useful, used for debugging
label: code-design
* Lightfunc
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
Not halfway, round to nearest.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
make the new thread reachable
comment: copied so that 'ap' can be reused
label: code-design
estimate is valid
* Comparison
DUK_USE_REFERENCE_COUNTING
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
[ ... func ]
nrets
Error code also packs a tracedata related flag.
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
allow fmt==NULL
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
DUK_BUFOBJ_NODEJS_BUFFER
Stack size increases or stays the same.
Exact halfway, round to even.
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
Clamping needed if duk_int_t is 64 bits.
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
!DUK_USE_PREFER_SIZE
Error: try coercing error to string once.
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
DUK_USE_FASTINT
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
sanity limit for function pointer size
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
* Error throwing
can't resize below 'top'
-> [ ... retval ]
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
shared flags for a subset of types
round up roughly to next 'grow step'
Custom coercion for API
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
tv -> value just before prev top value; must relookup
Init newly allocated slots (only).
default: NULL, length 0
* instanceof
Assume value stack sizes (in elements) fits into duk_idx_t.
useful for debugging
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
valstack limit caller has check, prevents wrapping
default: NaN
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
Negative indices are always within allocated stack but
* must not go below zero index.
covers -Infinity
* Get/require
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
Note: number has no explicit tag (in 8-byte representation)
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
Same as above but for unsigned int range.
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
check stack before interning (avoid hanging temp)
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
* Stack slice primitives
comment: unused
label: code-design
normalize NaN which may not match our canonical internal NaN
* Value stack top handling
check_object_coercible
If not present in finalize_list or refzero_list, the pointer
* must be either in heap_allocated or the string table.
One particular problem case is where an object has been
* queued for finalization but the finalizer hasn't yet been
* executed.
*
* Corner case: we're running in a finalizer for object X, and
* user code calls duk_push_heapptr() for X itself. In this
* case X will be in finalize_list, and we can detect the case
* by seeing that X's FINALIZED flag is set (which is done before
* the finalizer starts executing).
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
Note: this allows creation of internal strings.
Check for maximum string length
E5 Section 9.2
force_exponential
DUK_INVALID_INDEX won't be accepted as a valid index.
only needed by debugger for now
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
DUK_USE_BUFFEROBJECT_SUPPORT
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
* Forward declarations
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
For tv1 == tv2, this is a no-op (no explicit check needed).
require
comment: XXX: typing
label: code-design
Use unsigned arithmetic to optimize comparison.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
Return value of 'sz' or more indicates output was (potentially)
* truncated.
DUK_BUFOBJ_INT32ARRAY
Also check for the refzero_list; must not be there unless it is
* being finalized when duk_push_heapptr() is called.
*
* Corner case: similar to finalize_list.
nop
Faster but value stack overruns are memory unsafe.
E5 Section 9.4, ToInteger()
Note: need to re-lookup because ToNumber() may have side effects
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Type checking
Double error
no compact
w/o refcounting
[ ... func/retval ] -> [ ... ]
Special coercion for Uint8ClampedArray.
flags is unsigned
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
comment: XXX: optimize loops
label: code-design
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
tagged null pointers should never occur
no throw
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
initialize built-ins - either by copying or creating new ones
may throw an error
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: XXX: size optimize
label: code-design
comment: NUL terminator handling doesn't matter here
label: code-design
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
Stack size decreases.
format plus something to avoid just missing
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
unreachable
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
comment: XXX: duk_ssize_t
label: code-design
... and its 'message' from an instance property
DUK_BUFOBJ_DUKTAPE_BUFFER
DUK_BUFOBJ_UINT16ARRAY
nargs
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
[ buf? res ]
Avoid NaN-to-integer coercion as it is compiler specific.
no prototype
Check that there's room to push one value.
Note: 'q' is top-1
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
min_new_size
since index non-negative
not popped by side effect
precision:shortest
'this' binding is just before current activation's bottom
[... (sep) str1 str2 ... strN buf]
no size check is necessary
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
overwrite str1
extra -1 for buffer
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Combined size of separators already overflows
[... buf]
always true, arg is unsigned
start (incl) and end (excl) of trimmed part
[... res]
Impose a string maximum length, need to handle overflow
* correctly.
overwrite sep
guaranteed by string limits
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
entire string is whitespace
A bit tricky overflow test, see doc/code-issues.rst.
* String manipulation
pointers for scanning
wrapped
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
is_join
comment: get rid of the strings early to minimize memory use before intern
label: code-design
reasonable output estimate
* Variable access
[ ... val ]
always throw ReferenceError for unresolvable
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
[ ... varname val ]
comment: XXX: tostring?
label: code-design
[ ... ]
[ ... varname val this ] (because throw_flag == 1, always resolved)
-> [ ... varname val this ]
Outside any activation -> put to global.
Outside any activation -> look up from global.
-> [ ... val retval ]
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
stack top contains 'false'
Steps 12 and 13: reorganize elements to make room for itemCount elements
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
swap elements; deal with non-existent elements correctly
move pivot to its final place
return ToObject(this)
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
-> [ sep ToObject(this) len str ]
end of loop (careful with len==0)
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
for lastIndexOf, result may be -1 (mark immediate termination)
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
For now, restrict result array into 32-bit length range.
avoid degenerate cases, so that (len - 1) won't underflow
* shift()
fixed offsets in valstack
k+argCount-1; note that may be above 32-bit range
intermediate join to avoid valstack overflow
orig value
fromPresent = true
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
right exists, [[Put]] regardless whether or not left exists
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
topmost element is the result array already
-> [ sep ToObject(this) len sep str ]
[ ToObject(this) item1 ... itemN arr ]
The lo/hi indices may be crossed and hi < 0 is possible at entry.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
[ sep ToObject(this) len sep result ]
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
comment: XXX: best behavior for real world compatibility?
label: code-design
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
-> [ ... toLocaleString ToObject(val) ]
Note that 'l' and 'r' may cross, i.e. r < l
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
-> [ ... ToObject(this) ToUint32(length) ]
trivial cases
find elements to swap
args start at index 2
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
[ ... ToObject(this) ToUint32(length) val ]
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
stack top contains 'true'
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
Step 9: copy elements-to-be-deleted into the result array
retval is directly usable
result array is already at the top of stack
has access to 'this' binding
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
* splice()
* isArray()
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
Debug print which visualizes the qsort partitioning process.
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
-> [ sep ToObject(this) len str sep ]
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
* indexOf(), lastIndexOf()
move pivot out of the way
comment: XXX: must be able to represent -len
label: code-design
* reverse()
!(l < p)
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
result index for filter()
loop iterator init and limit changed from standard algorithm
[ ... val callback thisArg val i obj ]
!(p < r)
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
Perform an intermediate join when this many elements have been pushed
* on the value stack.
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
string compare is the default (a bit oddly)
* pop(), push()
[ arg1 ... argN obj length new_length ]
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
no need to check callable; duk_call() will do that
if thisArg not supplied, behave as if undefined was supplied
* reduce(), reduceRight()
[ sep ToObject(this) len ]
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
-> [ ... fn x y ]
-> [ ... res ]
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
idx_step is +1 for indexOf, -1 for lastIndexOf
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
* concat()
[ sep ToObject(this) len sep str0 ... str(count-1) ]
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
[ ... func this ]
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
idx_step is +1 for reduce, -1 for reduceRight
The extra (+4) is tight.
-> [ ToObject(this) ]
[ sep ToObject(this) len sep ]
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
randomized pivot selection
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
* slice()
* unshift()
retval to result[i]
* Constructor
if true, the stack already contains the final result
* every(), some(), forEach(), map(), filter()
* toString()
Strict standard behavior, ignore trailing elements for
* result 'length'.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
fixed offset in valstack
rnd in [lo,hi]
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
nop
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
We're a varargs function because we need to detect whether
* initialValue was given or not.
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
[ arg1 ... argN obj length ]
throw flag irrelevant (false in std alg)
Step 15: insert itemCount elements into the hole made above
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
i >= 0 would always be true
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
fromPresent = false
-> [ ... x y fn ]
[ ... this func ]
each call this helper serves has nargs==2
-> [ ToObject(this) item1 ... itemN arr ]
[ ToObject(this) item1 ... itemN arr item(i) ]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
XXX: proper flags?
* Boolean built-ins
unbalanced stack
-> [ val obj val ]
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
* Duktape.Buffer: toString(), valueOf()
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
reachable so pop OK
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
throw_flag
comment: XXX: encoding is ignored now.
label: code-design
This behavior mostly mimics Node.js now.
nargs
Fast path: source is a TypedArray (or any bufferobject).
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
Don't accept relative indices now.
bits 0...1: shift
default is explicit index read/write copy
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
[ offset noAssert ], when ftype != DUK__FLD_VARINT
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
Push the resulting view object and attach the ArrayBuffer.
DUK__FLD_32BIT
>= 0
arg count
DUK__FLD_8BIT
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
Array or Array-like
comment: Static call style.
label: code-design
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
sign doesn't matter when writing
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
Write in little endian
[ targetBuffer targetStart sourceStart sourceEnd ]
source starts after dest ends
* Misc helpers
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
Check that value is a duk_hbufferobject and return a pointer to it.
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
byte sizes will match
return h_bufres
Must be element size multiple from
* start offset to end of buffer.
* Node.js Buffer: toString([encoding], [start], [end])
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
new buffer with string contents
XXX: could add fast path for u8 compatible views
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
bytes in dest
Use byte copy.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK__FLD_16BIT
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
avoid side effects!
Node.js accepts only actual Arrays.
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
crossed offsets or zero size
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
Gather in little endian
unsigned
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
comment: XXX: function flag to make this automatic?
label: requirement
XXX: happens e.g. when evaluating: String(Buffer.prototype).
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
DUK__FLD_VARINT; not relevant here
Shared helper.
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
idx_end
may be NULL
-> [ buffer ]
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
Copy values through direct validated reads and writes.
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
Gather in big endian
compare: similar to string comparison but for buffer data.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
use p_src_base from now on
ignore encoding for now
* Node.js Buffer.isBuffer()
* Node.js Buffer.prototype.fill()
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
* Node.js Buffer.isEncoding()
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
1=little endian
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
Not enough data.
Note: start_offset/end_offset can still be < 0 here.
bits 2...5: type
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
Push a new ArrayBuffer (becomes view .buffer)
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
idx_start
should never happen but default here
Now we can check offset validity.
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
inherit
* Node.js Buffer.prototype.copy()
comment: not covered, return all zeroes
label: test
[ value offset end ]
comment:
* Node.js Buffer.concat()
label: code-design
Value stack intentionally mixed size here.
[ array totalLength ]
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
not reachable
* Node.js Buffer.prototype: toJSON()
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
length check
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
Must be >= 0 and multiple of element size.
* Duktape.Buffer: constructor
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
Just skip, leaving zeroes in the result.
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
Byte length would overflow.
Set .buffer
equals
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
Shared offset/length coercion helper.
bytes in source
Source end clamped silently to available length.
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
elems in source and dest
XXX: fast path for array arguments?
either nonzero value is ok
Handle TypedArray vs. Node.js Buffer arg differences
Negative offsets cause a RangeError.
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
offset/value order different from Node.js
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
one i_step added at top of loop
comment: unnecessary div for last byte
label: code-design
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
Ensure copy is covered by underlying buffers.
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
* ArrayBuffer, DataView, and TypedArray constructors
guaranteed by duk_to_string()
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
-> [ array totalLength buf ]
source ends before dest starts
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
source out-of-bounds (but positive)
Map DUK__FLX_xxx to byte size.
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
[ start end ]
[ array totalLength bufres buf ]
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
one i_step over
default to false
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
These are not needed when only Duktape.Buffer is supported.
DUK__FLD_FLOAT
undefined coerces to zero which is correct
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
DUK__FLD_DOUBLE
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
even for zero-length string
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
new buffer of specified size
pop plain buffer, now reachable through h_bufres
Node.js return value for failed writes is offset + #bytes
* that would have been written.
DUK_USE_BUFFEROBJECT_SUPPORT
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
ignore_loop
Shift to sign extend.
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
stack is unbalanced, but: [ <something> buf ]
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
Set .buffer to the argument ArrayBuffer.
comment: unnecessary shift for last byte
label: code-design
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
* ArrayBuffer.isView()
comment: XXX: easier check with less code?
label: code-design
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
* Indexed read/write helpers (also used from outside this file)
* Node.js Buffer: constructor
Write in big endian
replaced
* Node.js Buffer.byteLength()
non-zero: make copy
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
Note: unbalanced stack on purpose
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
Nominal size check.
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Check that 'this' is a duk_hbufferobject and return a pointer to it.
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
as elements
Argument must be a string, e.g. a buffer is not allowed.
target out-of-bounds (but positive)
unbalanced stack on purpose
Compute result length and validate argument buffers.
only accept lowercase 'utf8' now.
Cannot overlap.
Convert indices to byte offsets.
no need to decref
[ ... this ]
stack top: new time value, return 1 to allow tail calls
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
3
Apply timezone offset to get the main parts in UTC
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
8: getFullYear
now expected to fit into a 32-bit integer
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
MakeDate
37: setUTCFullYear
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
Integer division which floors also negative values correctly.
-""-
invalid value which never matches
7
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
Here we'd have the option to normalize -0 to +0.
-> [ O toIsoString O ]
-> [ timeval this timeval ]
Optional UTC conversion.
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
Internal timevalue is already NaN, so don't touch it.
5: toLocaleTimeString
Old solution: don't iterate, incorrect
38: getYear
6
* Other file level defines
zero-based -> one-based
called as a normal function: return new Date().toString()
* ISO 8601 subset parser.
39: setYear
Rule control flags.
1: toDateString
E5.1 Section 15.9.1.6
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
if-digit-else-ctrl
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
Parts are in local time, convert when setting.
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
-> [ ... this ]
16: getHours
Note2
char loop
33: setUTCDate
25: setUTCMilliseconds
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
match against rule part/sep bits
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
Rule table: first matching rule is used to determine what to do next.
flags
fits into duk_small_int_t
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
formatters always get one-based month/day-of-month
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
2: toTimeString
comment: TimeClip() should never be necessary
label: code-design
continue matching, set neg_tzoffset flag
-> [ ... this timeval_new ]
30: setHours
TimeClip(), which also handles Infinity -> NaN conversion
unsigned
zero-based day
34: setMonth
Note: rely on index ordering
Parser part masks.
20: getSeconds
Expects 'this' at top of stack on entry.
28: setMinutes
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
1
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
zero-based month
Parser part count.
6: toUTCString
no argument given -> leave components untouched
msec
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
Matching separator index is used in the control table
don't care value, year is mandatory
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
27: setUTCSeconds
unreferenced with some options
36: setFullYear
-> [ this ]
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
4
21: getUTCSeconds
seconds, doesn't fit into 16 bits
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
may be NaN
3: toLocaleString
17: getUTCHours
22: getMilliseconds
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
12: getDate
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
35: setUTCMonth
Special handling for year sign.
caller checks
24: setMilliseconds
MakeTime
0x08583b00
5
If 'day' is NaN, returns NaN.
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
9: getUTCFullYear
During parsing, month and day are one-based; set defaults here.
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
Different calling convention than above used because the helper
* is shared.
non-leap year: sunday, monday, ...
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* API oriented helpers
11: getUTCMonth
leap year: sunday, monday, ...
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
Note: DST adjustment is determined using UTC time.
handle negative values
32: setDate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
7: toISOString
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
13: getUTCDate
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
2
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
23: getUTCMilliseconds
-> [ timeval this ]
We should never exit the loop above.
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
Parser separator indices.
-> [ ... this timeval_new timeval_new ]
"-123456\0"
rule match
deal with negative values
10: getMonth
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
unpack args
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
Given a day number, determine year and day-within-year.
Parser separator masks.
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
* Constructor calls
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
ignore millisecond fractions after 3
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
15: getUTCDay
This assert depends on the input parts representing time inside
* the Ecmascript range.
comment: XXX: getter with class check, useful in built-ins
label: code-design
get as double to handle huge numbers correctly
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
if no NaN handling flag, may still be NaN here, but not Inf
0: toString
26: setSeconds
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
19: getUTCMinutes
14: getDay
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
* Forward declarations
conservative
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
Compute day number of the first day of a given year.
29: setUTCMinutes
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
"+11:22\0"
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
complete the millisecond field
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
day number for Jan 1 since epoch
-> [ ... this timeval ]
Parser part indices.
no fractions in internal time
no need to mask idx portion
does not fit into 16 bits
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
0
Iteration solution
accept string if next char is NUL (otherwise reject)
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
31: setUTCHours
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
Note1
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
accept string
No platform-specific parsing, this is not an error.
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
4: toLocaleDateString
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
See comments below on MakeTime why these are volatile.
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
E5 Sections 15.9.3.1, B.2.4, B.2.5
tzoffset
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
seconds
18: getMinutes
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
DUK_USE_DATE_TZO_GMTIME
one-based -> zero-based
DUK_USE_DATE_PRS_STRPTIME
comment: XXX: return something more useful, so that caller can throw?
label: code-design
For NaN/inf, the return value doesn't matter.
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
no fractions
The necessary #includes are in place in duk_config.h.
already one-based
DUK_USE_DATE_PRS_GETDATE
DUK_USE_DATE_NOW_GETTIMEOFDAY
be paranoid for 32-bit time values (even avoiding negative ones)
unsigned 31-bit range
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
negative: dst info not available
Not a very good provider: only full seconds are available.
copy to buffer with spare to avoid Valgrind gripes from strptime
valgrind whine without this
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
DUK_USE_DATE_NOW_TIME
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
UTC
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
local
DUK_USE_DATE_FMT_STRFTIME
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
flags
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
DUK_USE_DATE_NOW_WINDOWS
input 'd' in Windows UTC, 100ns units
Difference is in 100ns units, convert to milliseconds w/o fractions
millisec -> 100ns units since jan 1, 1970
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
The necessary #includes are in place in duk_config.h.
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
Shared Windows helpers.
Positive if local time ahead of UTC.
comment: not sure whether or not needed; Thursday
label: requirement
seconds
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
DUK_USE_DATE_TZO_WINDOWS
address
-> [ val arr ]
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
type tag (public)
return the argument object
result array
idx_value
idx_space
comment: XXX: primitive to make array from valstack slice
label: code-design
XXX: version specific array format instead?
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
refcount
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
because arg count is 1
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
set values into ret array
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
[ level obj func pc line ]
idx_replacer
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
* Compact an object
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
flags
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
internal type tag
Get.
[ ... this ]
fixed arg count: value
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
noblame_fileline
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
[ ... this tracedata sep this str1 ... strN ]
may be NULL
constants arbitrary, chosen for small loads
* Ecmascript/native function call or lightfunc call
not enumerable
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: XXX: skip null filename?
label: code-design
NULL for lightfunc
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
unknown, ignore
[ ... v1 v2 name filename ]
traceback depth ensures fits into 16 bits
[ ... obj key value ]
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
fixed arg count
[ ... this name message ]
name is empty -> return message
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
[ ... v1(filename) v2(line+flags) ]
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
-> [ ... str ]
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
[ ... v1 v2 str ] -> [ ... str v2 ]
DUK_USE_TRACEBACKS
traceback depth fits into 16 bits
[ message error message ]
same for both error and each subclass like TypeError
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
[ ... v1(func) v2(pc+flags) ]
... name ': ' message
comment: XXX: optimize with more direct internal access
label: code-design
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
[ ... this name ]
message is empty -> return name
[ ... this tracedata sep this ]
* Error built-ins
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
count, not including sep
stack type fits into 16 bits
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Current tracedata contains 2 entries per callstack entry.
vararg function, careful arg handling (e.g. thisArg may not be present)
create bound function object
not a vararg function
these non-standard properties are copied for convenience
step 15.a
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
[ body formals source template closure ]
add_auto_proto
[ body formals source ]
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
[ body formals ], formals is comma separated list that needs to be parsed
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
attrs in E5 Section 15.3.5.1
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
bound function 'length' property is interesting
caller and arguments must use the same thrower, [[ThrowTypeError]]
[ func thisArg arg1 ... argN ]
thisArg
vararg function, thisArg needs special handling
comment: XXX: 'copy properties' API call?
label: code-design
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Function built-ins
comment: XXX: cover this with the generic >1 case?
label: code-design
comment: XXX: make this an internal helper
label: code-design
= 1 + arg count
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
[ thisArg arg1 ... argN ]
lightfunc
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
[ thisArg arg1 ... argN func boundFunc argArray ]
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
[ thisArg arg1 ... argN func boundFunc ]
Lightfuncs are always strict.
[ body formals source template ]
ignore arguments, return undefined (E5 Section 15.3.4)
comment: XXX: ignored now
label: code-design
func
For lightfuncs, simply read the virtual property.
comment: XXX: faster internal way to get this
label: code-design
'func' in the algorithm
[ func thisArg argArray ]
ToUint32() coercion required
comment: XXX: copy from caller?
label: code-design
normal and constructor calls have identical semantics
Indicate function type in the function body using a dummy
* directive.
strictness is not inherited, intentional
Duktape object
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
ignore non-strings
Duktape.modSearch(resolved_id, fresh_require, exports, module).
Module id requested
DUK_USE_COMMONJS_MODULES
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
Module object containing module.exports, etc
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
2 when called by debugger
return module.exports
eat dup slashes
at most sizeof(buf) - 1
requested identifier
E5.1 Section 15.1.3.2: empty
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
spaces (nargs - 1) + newline
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Parsing of ints and floats
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
Duktape.modLoaded[] module cache
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
1110 xxxx; 3 bytes
[ source template result ]
if direct eval, calling activation must exist
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
last component
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
Duktape.modLoaded
p overshoots
comment: XXX: copy from caller?
label: code-design
output is never longer than input during resolution
DUK_USE_PREFER_SIZE
fall through
0x10-0x1f
Output #2: last component name
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
print provider
Eval code doesn't need an automatic .prototype object.
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
E5.1 Section B.2.2, step 7.
Backtrack to previous slash or start of buffer.
* Number checkers
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
Resolved, normalized absolute module ID
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
add_auto_proto
0x20-0x2f
module.filename for .fileName, default to resolved ID if
* not present.
E5.1 Section 15.1.3.1: uriReserved + '#'
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
New require() function for module, updated resolution base
this may have side effects, so re-lookup act
a fresh require() with require.id = resolved target module id
Delete entry in Duktape.modLoaded[] and rethrow.
110x xxxx; 2 bytes
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
0x30-0x3f
initial size guess
decode '%xx' to '%xx' if decoded char in reserved set
The base ID of the current require() function, resolution base
[ requested_id require require.id resolved_id last_comp ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
Current require() function
require.id of current module
mod_id may be NULL
comment: Higher footprint, less churn.
label: code-design
DUK_USE_SECTION_B
compact the exports table
Needs lookahead
'undefined', artifact of lookup
1111 0xxx; 4 bytes
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
not reachable
0x50-0x5f
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
Last component name in resolved path
-> [ ... source ]
module table remains registered to modLoaded, minimize its size
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
this is just beneath bottom
p points to digit part ('%xy', p points to 'x')
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
by default, use caller's environment
eat (first) input slash
module.id = resolved_id
indirect eval
'%xx%xx...%xx', p points to char after first '%'
[ source template closure this ]
module
E5.1 Section 15.1.3.4: uriUnescaped
invalidated
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
this function
exports (this binding)
* Resolve module identifier into canonical absolute form.
continuation byte
* CommonJS require() and modules support
Copy term name until end or '/'.
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
delete Duktape.modLoaded[resolved_id]
Newline allows module last line to contain a // comment.
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
bytes left
[ source template closure ]
* Encoding/decoding helpers
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
0x40-0x4f
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
This was the last term, and q_last was
* updated to match this term at loop top.
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
e.g. require('/foo'), empty terms not allowed
at least this function exists
0x70-0x7f
comment: XXX: check flags
label: requirement
write on next loop
Default exports table
Duktape.modLoaded[resolved_id] = module
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
stash to bottom of value stack to keep new_env reachable for duration of eval
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
extended utf-8 not allowed for URIs
This is guaranteed by debugger code.
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
E5 Section 10.4.2
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
exports
return arg as-is
* Global object built-ins
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
module.name for .name, default to last component if
* not present.
rethrow original error
module.exports = exports
0x60-0x6f
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
Output #1: resolved absolute name
[ source ]
comment: Stack indices for better readability
label: code-design
comment: XXX: refactor and share with other code
label: code-design
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
Duktape.modSearch
module (argument)
fresh require (argument)
resolved id: require(id) must return this same module
caller
avoid dereference after potential callstack realloc
relookup exports from module.exports in case it was changed by modSearch
must be signed
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
* URI handling
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
utf-8 validation ensures these
0x00-0x0f
nargs
compiler's responsibility
backtrack to last output slash (dups already eliminated)
[ source template ]
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
DUK_USE_JX
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
Note: intentionally signed.
XXX: push_uint_string / push_u32_string
[ ... buf loop ]
idx_value
backtrack (safe)
* Top level wrappers
Loop check.
len: 9
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Final result is at stack top.
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
* Local defines and forward declarations.
already zero
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
flags
Guaranteed by recursion_limit setup so we don't have to
* check twice.
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
[ ... obj ]
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
DUK_USE_JSON_EATWHITE_FASTPATH
'"' was eaten by caller
DUK_USE_HEX_FASTPATH
parse value
-> [ ... key val replacer holder key ]
as is
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
unconditional block
any other printable -> as is
emitted
-> [ ... holder name val val ToString(i) ]
replacer is a mutation risk
skip '|'
toJSON() can also be a lightfunc
parse key and value
default attrs ok
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
0x7F is special
-> [ ... key val val' ]
skip ')'
[ ... val ]
Fast path, decode as is.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
syntax error
-> [ ... proplist enum_obj key ]
avoid attempts to add/remove object keys
XXX: a "first" flag would suffice
avail_bytes += need_bytes
Parse a number, other than NaN or +/- Infinity
0x00: finish (non-white)
* 0x01: continue
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
nothing now
caller guarantees
DUK_USE_JX && DUK_USE_JC
[ ... buf ]
-> [ ... key val replacer ]
serialize the wrapper with empty string key
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
Function values are handled completely above (including
* coercion results):
'\Udeadbeef'
enum_index
eat closing bracket
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
Must decrease recursion depth before returning.
* Create wrapper object and serialize
All other object types.
* Helper tables
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
error message doesn't matter, ignored anyway
must not truncate
negative top-relative indices not allowed now
Encode a fastint from duk_tval ptr, no value stack effects.
avoid attempt to compact any objects
Ensure space for 1:1 output plus one escape.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
[ ... number ] -> [ ... string ]
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
Note: space must cater for both JX and JC.
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
temp copy, write back for next loop
[ ... buf loop (proplist) ]
unsigned
but don't allow leading plus
comment: XXX: Here a "slice copy" would be useful.
label: code-design
0x00: finish (not part of number)
* 0x01: continue
-> [ ... val root "" ]
[ ... holder name val enum obj_key val obj_key ]
"-Infinity", '-' has been eaten
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
original target at entry_top - 1
catches EOF and invalid digits
safe, because matched (NUL causes a break)
not emitted
[ ... arr val ]
maxval
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
Must prevent finalizers which may have arbitrary side effects.
expensive flag
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
The stack has a variable shape here, so force it to the
* desired one explicitly.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
proplist is very rare
DUK_USE_JC
-> [ ... key val replacer holder key val ]
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
-> [ ... ]
-> [ ... key val toJSON val key ]
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
Zero length string is not accepted without quotes
Getter might have arbitrary side effects,
* so bail out.
nret
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
-> [ ... voidp voidp ]
[ ... holder name val enum obj_key new_elem ]
Disabled until fixed, see above.
Error message doesn't matter: the error is ignored anyway.
-> [ ... key val' ]
Value would normally be omitted, replace with 'null'.
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
XXX: array internal?
For JX, expressing the whole unsigned 32-bit range matters.
Caller must ensure 'tv' is indeed a fastint!
safe
will result in undefined
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
typed for duk_unicode_decode_xutf8()
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
catches EOF (NUL)
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
accept comma, expect new value
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
-> [ ... reviver holder name val ]
[ ... holder name val ]
We rely on a few object flag / class number relationships here,
* assert for them.
Standard JSON omits functions
unreachable
nargs
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
x == 0x00 (EOF) causes syntax_error
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
Note: duk__dec_req_stridx() backtracks one char
-> [ ... key val toJSON val ]
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
-> [ ... key val ]
0x00: slow path
* other: as is
value was undefined/unsupported
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
coerce in-place
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
[ ... num ]
* Entry points
Caller has already eaten the first character ('(') which we don't need.
C recursion check.
standard JSON; array gaps
catches EOF (0x00)
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
idx_space
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
-> [ ... val' ]
Caller must ensure 'tv' is indeed a double and not a fastint!
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
Caller has already eaten the first character ('|') which we don't need.
Shared entry handling for object/array serialization.
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
Previous entry was inside visited[], nothing to do.
slow path decode
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
[ ... proplist enum_obj key val ]
comment: XXX: substring in-place at idx_place?
label: code-design
* Process replacer/proplist (2nd argument to JSON.stringify)
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
handle comma and closing brace
'-0'
* Process space (3rd argument to JSON.stringify)
caller checks
[ ... holder name val enum obj_key ]
XXX: duk_dup_unvalidated(ctx, -2) etc.
accept anything, expect first value (EOF will be
* caught by key parsing below.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
Assume that the native representation never contains a closing
* parenthesis.
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
get_value
-> [ ... res ]
Initial '{' has been checked and eaten by caller.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
pop enum
DUK_USE_JSON_STRINGIFY_FASTPATH
leave stack unbalanced on purpose
Most input bytes go through here.
-> [ ... holder name val ]
[ ... buf loop (proplist) (gap) ]
disabled for now
extra coercion of strings is OK
ascii fast path: avoid decoding utf-8
We only get here when doing non-standard JSON encoding
idx_replacer
Handle both full and partial slice (as long as covered).
End of input (NUL) goes through slow path and causes SyntaxError.
Assume arrays are dense in the fast path.
handle comma and closing bracket
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
need_bytes may be zero
clamp to 10 chars
A lightfunc might also inherit a .toJSON() so just bail out.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
-> [ ... key val replacer holder ]
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
[ ... holder key ] -> [ ... holder ]
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Same coercion behavior as for Number.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
DUK_USE_JSON_DECNUMBER_FASTPATH
-> [ ... voidp true ]
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
eat closing brace
Catches EOF of JSON input.
number
radix
end-of-input breaks
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
DUK_USE_JSON_QUOTESTRING_FASTPATH
slow path is shared
comment: bytes of indent available for copying
label: code-design
[ ... target ] -> [ ... target keys ]
[ ... str ]
-> [ ... value ]
object or array
DUK_USE_PREFER_SIZE
overflow not possible, buffer limits
XXX: duk_push_uint_string()
DUK_USE_JX || DUK_USE_JC
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
not undefined
Restore stack top after unbalanced code paths.
comment: When ptr == NULL, the format argument is unused.
label: code-design
* Context init
-> [ ... val root val ]
[ ... obj key val ]
[ ... ]
* Stringify implementation.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
[ ... ptr ]
double quote or backslash
[ ... arr ]
comment: XXX: how to figure correct size?
label: code-design
c recursion check
catches EOF (NUL) and initial comma
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
eat trailing comma
disabled
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
Decode failed.
end switch
Result is undefined.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
[ ... proplist ]
digits
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
[ ... key val ] -> [ ... ]
minval
-> [ ... key ]
[ ... obj key ]
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
Caller has already eaten the first char so backtrack one byte.
comment: bytes of indent still needed
label: code-design
nop
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
Initial '[' has been checked and eaten by caller.
We already ate 'x', so backup one byte.
Convert buffer to result string.
Steps 8-10 have been merged to avoid a "partial" variable.
Shared exit handling for object/array serialization.
first character has been matched
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
[ arg1 ... argN this loggerLevel loggerName buffer ]
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
comment: XXX: better multiline
label: code-design
[ arg undefined ]
* Logging support
[ arg toLogString ]
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
separators: space, space, colon
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
[ arg result ]
time
* Pass 1
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
comment: log level could be popped but that's not necessary
label: code-design
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
Constructor
obj_index
keep default instance
nop
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
* Log level check
don't set 'n' at all, inherited value is used as name
call: this.fmt(arg)
[ name this ]
3-letter log level strings
[ arg1 ... argN this loggerLevel loggerName ]
this.raw(buffer)
* Pass 2
level string
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Line format: <time> <entryLev> <loggerName>: <msg>
comment: Calling as a non-constructor is not meaningful.
label: code-design
[ arg1 ... argN this ]
sep (even before first one)
nargs
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
loggerName
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
Not odd, or y == -Infinity
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
DUK_USE_MATH_BUILTIN
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
order must match constants in genbuiltins.py
DUK_USE_AVOID_PLATFORM_FUNCPTRS
* Math built-ins
+0.5 is handled by floor, this is on purpose
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Note: not normalized, but duk_push_number() will normalize
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
digits
leading digit + fractions
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
* Number built-ins
radix
for side effects
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
comment: XXX: helper
label: code-design
-> [ val obj val ]
flags
no return value -> don't replace created value
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
* toFixed(), toExponential(), toPrecision()
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
target
[ hobject props enum(props) key desc ]
fall thru
Lightfunc, always success.
[ hobject props enum(props) ]
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
-> [ obj trap_result ]
enum_flags
magic: 0=getter call, 1=Object.getPrototypeOf
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
comment: XXX: no need for indirect call
label: code-design
Just call the "original" Object.defineProperties() to
* finish up.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
Loop prevention
-> [ hobject props ]
h_new_proto may be NULL
-> [ O toString O ]
[ obj Properties ]
[ obj trap_result res_arr ]
properties object
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
[ obj trap_result res_arr propname ]
comment: TODO: implement Proxy object support here
label: requirement
ignore_loop
required_desc_flags
get_value
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
* Object built-ins
* Use Object.defineProperty() helper for the actual operation.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
[ obj handler trap ]
h is NULL for lightfunc
* Return target object
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
[[SetPrototypeOf]] standard behavior, E6 9.1.2
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
[ obj key desc ]
[ hobject props enum(props) key desc value? getter? setter? ]
frozen and sealed
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
Object.keys
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
[ O Properties obj ]
* Return target object.
idx_desc
retval for success path
Lightfunc handling by ToObject() coercion.
-> [ obj trap handler target ]
nargs
DUK_USE_ES6_PROXY
is_frozen
Object.getOwnPropertyNames
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
comment: XXX: call method tail call?
label: code-design
Pointer object internal value is immutable
* Constructor
* Pointer built-ins
nop
Must be a "pointer object", i.e. class "Pointer"
Note: unbalanced stack on purpose
* toString(), valueOf()
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
DUK_BUILTIN_PROTOS_H_INCLUDED
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
Helpers exposed for internal use
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
Built-in providers
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
Proxy target
Proxy handler
DUK_USE_ES6_PROXY
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
* Proxy built-in (ES6)
replacement handler
flags: "m"
DUK_USE_REGEXP_SUPPORT
* RegExp built-ins
flags: "gim"
[ result ]
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
[ ... pattern flags ]
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
require to be safe
three flags
prepend regexp to valstack 0 index
comment: XXX: much to improve (code size)
label: code-design
flags: "gi"
[ ... bytecode escaped_source ]
flags: "gm"
[ ... RegExp ]
flags: ""
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
[ regexp input ]
Else functionality is identical for function call and constructor
* call.
flags: "g"
[ regexp ]
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
flags: "im"
flags: "i"
[ regexp source bytecode ]
result object is created and discarded; wasteful but saves code space
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
* Case conversion
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
lastIndex already set up for next match
DUK_USE_REGEXP_SUPPORT
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
[ regexp string ]
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
prefix matches, lengths matter now
min(incl)
not found
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
match == search string, by definition
res_obj
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
empty match (may happen with empty separator) -> bump and continue
* Various
* toString(), valueOf()
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
trailer
don't allow an empty match at the end of the string
[ ... replacer match [captures] match_char_offset input ]
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
* indexOf() and lastIndexOf()
ch1 = (r_increment << 8) + byte
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
return as is
repl_value
Not found. Empty string case is handled specially above.
stack[0] = regexp
* stack[1] = string
* substring(), substr(), slice()
-> [ ... regexp string ] -> [ ... res_obj ]
[ start end str ]
never here, but fall through
at index 1
comment: this is relatively expensive
label: code-design
no issues with memcmp() zero size, even if broken
switch (ch2)
lastIndex is initialized to zero by new RegExp()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
pop regexp res_obj or match string
unconditionally
start match from beginning
h_match is borrowed, remains reachable through match_obj
if (is_regexp)
comment: XXX: faster implementation
label: code-design
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
DUK_USE_SECTION_B
Zero size compare not an issue with DUK_MEMCMP.
out_clamped
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
empty separator can always match
leading byte of match string
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
track utf-8 non-continuation bytes
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
input size is good output starting point
match_caps == 0 without regexps
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
unconditionally; is_global==0
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
string limits
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
regexp res_obj is at index 4
[ ... re_obj input ]
max(incl)
Must be a "string object", i.e. class "String"
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* Character and charcode access
no action
default case
initial estimate for ASCII only codepoints
* replace()
cannot have >4G captures
while repl
return 'res_obj'
never an empty match, so step 13.c.iii can't be triggered
for
no issues with empty memcmp()
* Constructor
Shared helper for match() steps 3-4, search() steps 3-4.
track cpos while scanning
0=indexOf, 1=lastIndexOf
regexp res_obj is at offset 4
[ start length str ]
comment: Global case is more complex.
label: code-design
* String built-ins
return 'res_arr' or 'null'
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
combines steps 2 and 5; -len ensures max() not needed for step 5
force_new
No arr_idx update or limit check
set to 1 if any match exists (needed for empty input special case)
* split()
Combined step 11 (empty string special case) and 14-15.
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
match followed by capture(s)
-> [ ... res_obj ]
empty match -> bump and continue
-> [ res_obj ]
[ regexp string res_arr ]
String object internal value is immutable
index
repl string scan
ditto
Note: unbalanced stack on purpose
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
ensure full memcmp() fits in while
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: combines steps 3, 6; step 7 is not needed
label: requirement
[ ... regexp input ] -> [ res_obj ]
-> [ ... repl_value ]
single match always
constrained by string length
if (is_repl_func)
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
duk_concat() coerces arguments with ToString() in correct order
input string scan
undefined -> skip (replaced with empty)
[ ... RegExp val ] -> [ ... res ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
* Thread state and calling context checks
* Constructor
[ value ]
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
in yielder's context
return thread
* Thread builtins
never here
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
XXX: need a duk_require_func_or_lfunc_coerce()
in resumer's context
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
value (error) is at stack top
us
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
caller
push initial function call to new thread stack; this is
* picked up by resume().
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
call is from executor, so we know we have a jmpbuf
side effects
execution resumes in bytecode executor
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
lj value2: thread
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
lj value1: value
Further state-dependent pre-checks
[ thread value ]
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
* Type error thrower, E5 Section 13.2.3.
DUK_USE_ROM_OBJECTS
* Automatically generated by genbuiltins.py, do not edit!
DUK_USE_ROM_STRINGS
native functions: 149
DUK_USE_BUILTIN_INITJS
'length'
!DUK_SINGLE_FILE
'l'
'Arguments'
'toLogString'
'\xffNext'
'\xffBytecode'
'\xffLexenv'
'Date'
'instanceof'
'has'
'do'
'var'
'exports'
'pointer'
'void'
'string'
'protected'
'filename'
'try'
'continue'
'catch'
'toJSON'
'if'
'index'
'deleteProperty'
'value'
'Object'
'switch'
'toGMTString'
'let'
'[...]'
'enumerable'
'Uint32Array'
DUK_USE_ROM_STRINGS
' '
'enumerate'
'with'
'join'
'resume'
'debugger'
'get'
','
'{"_inf":true}'
'\xffFinalizer'
'\xffArgs'
'Error'
'Float64Array'
'enum'
'default'
'\xffRegbase'
'Thread'
'\xffThread'
'import'
'set'
'export'
'prototype'
'ObjEnv'
'jx'
'fmt'
'typeof'
'Math'
'-Infinity'
'name'
'BYTES_PER_ELEMENT'
'info'
'interface'
'class'
'Boolean'
'Buffer'
'defineProperty'
'\xffVarmap'
'Uint16Array'
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
'Infinity'
'\xffFormals'
'implements'
'\xffHandler'
'{"_undef":true}'
'\xffSource'
'{_func:true}'
'env'
'toLocaleString'
'\n '
'fatal'
'hex'
'trace'
'jc'
'case'
'toUTCString'
'(?:)'
'\xffTarget'
'private'
'Invalid Date'
'multiline'
'errCreate'
'warn'
'finally'
'ownKeys'
'configurable'
'caller'
'undefined'
'byteLength'
'lineNumber'
'Int8Array'
'data'
'type'
'-0'
'{"_ninf":true}'
'modLoaded'
'true'
'fileName'
'Uint8Array'
'break'
'Undefined'
''
'setPrototypeOf'
'\xffVarenv'
'number'
'{"_func":true}'
'return'
'throw'
'valueOf'
'buffer'
'DecEnv'
'writable'
DUK_USE_ROM_OBJECTS
'yield'
'id'
'callee'
'ArrayBuffer'
'Null'
'\xffPc2line'
'\xffMap'
'static'
'package'
'ignoreCase'
'message'
'NaN'
'byteOffset'
'extends'
'source'
'constructor'
'clog'
'raw'
'Int16Array'
'base64'
'in'
'Array'
'pc'
'errThrow'
'while'
'toISOString'
'Float32Array'
'object'
'require'
'compile'
'const'
'false'
'null'
'boolean'
'Int32Array'
'new'
'Function'
'stack'
'\xffThis'
'toString'
'debug'
'\xffCallee'
'Uint8ClampedArray'
'arguments'
'n'
'modSearch'
'for'
DUK_USE_BUILTIN_INITJS
'eval'
'function'
'\xffValue'
'DataView'
'error'
'{"_nan":true}'
'delete'
* Automatically generated by genbuiltins.py, do not edit!
exclusive endpoint
'RegExp'
'this'
'public'
'__proto__'
'\xffTracedata'
'input'
'super'
'lastIndex'
'JSON'
'else'
'Number'
'global'
DUK_BUILTINS_H_INCLUDED
'String'
'Pointer'
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: 0a70d7e4c5227c84e3fed5209828973117d02849
* Git describe: v1.8.0
* Git branch: v1.8-maintenance
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment: parameter passing, not thread safe
label: requirement
args go here in parens
* Structs
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
DUK_USE_VARIADIC_MACROS
* Prototypes
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
DUK_DEBUG_H_INCLUDED
omit
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
args go here as a comma expression in parens
* Exposed debug macros: debugging disabled
DUK_USE_DEBUG
args
* Exposed debug macros: debugging enabled
comment: unused
label: code-design
(maybe) truncated
normal
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
actual chars dropped (not just NUL term)
DUK_USE_DEBUG
error
* Debug dumping of duk_heap.
Note: there is no standard formatter for function pointers
DUK_USE_DEBUG
heap->strs: not worth dumping
comment: unused
label: code-design
comment:
* Debugging macro calls.
label: code-design
http://en.wikipedia.org/wiki/ANSI_escape_code
DUK_USE_DPRINT_COLORS
DUK_USE_VARIADIC_MACROS
* Debugging disabled
DUK_USE_DEBUG
* Debugging enabled
%lf, %ld etc
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
XXX: print built-ins array?
%ld
terminal type: no depth check
may be NULL
XXX: use DUK_HSTRING_FLAG_INTERNAL?
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
%p
after this, return paths should 'goto finished' for decrement
%lx
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
%f and %lf both consume a 'long'
%x; only 16 bits are guaranteed
maximum length of standard format tag that we support
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
leave out trailing 'unused' elements
depth check is done when printing an actual type
IEEE double is approximately 16 decimal digits; print a couple extra
ignore
char format: use int
maximum recursion depth for loop detection stacks
unsupported: would consume multiple args
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
DUK_USE_DEBUG
Should not happen.
helpers
%s
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
comment: unused
label: code-design
must match bytecode defines now; build autogenerate?
%lu
Note: string is a terminal heap object, so no depth check here
two special escapes: '\' and '"', other printables as is
from curr pc
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
'%c', passed concretely as int
comment: format is too large, abort
label: code-design
Quite approximate but should be useful for little and big endian.
%d; only 16 bits are guaranteed
'%s' and NULL is not portable, so special case
* it for debug printing.
comment: prototype should be last, for readability
label: code-design
fall through
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
%u; only 16 bits are guaranteed
heapobj recursion depth when deep printing is selected
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
from next pc
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
return total chars written excluding terminator
own pointer
throw_flag
nargs == 2 so we can pass a callstack level to eval().
Write unsigned 32-bit integer.
Can happen if duk_throw() is called on an empty
* callstack.
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
Use result value as is.
* Debug connection peek and flush primitives
Reply with tvals pushed by request callback
Request callback should push values for reply to client onto valstack
* DumpHeap command
comment: NULL not needed here
label: code-design
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
push to stack
Report next pc/line to be executed.
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
tolerates NULL h_buf
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
comment: unused
label: code-design
[ ... func varmap enum key value this ]
[ ... result ]
side effects
* Duktape debugger
* Halt execution helper
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
save stack top
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
DUK_USE_DEBUGGER_INSPECT
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
flags
For strings, special form for short lengths.
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
unsigned
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
comment: XXX: comes out as signed now
label: code-design
Report thrown value to client coerced to string
heap->dbg_udata: keep
comment: Process debug messages until we are no longer paused.
label: code-design
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
switch initial byte
may be NULL
Note: array dump will include elements beyond
* 'length'.
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
comment: XXX: differentiate null pointer from empty string?
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
To use the shared helper need the virtual index.
Breakpoint entries above the used area are left as garbage.
Skip fully.
Skip dvalue.
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
comment: prevent multiple in-progress detaches
label: requirement
DUK_USE_DEBUGGER_THROW_NOTIFY
processed one or more messages
index
no_block
* Simple commands
Safe to call multiple times.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
tentative, checked later
Write signed 32-bit integer.
Peek ahead in the stream one byte.
* Breakpoint management
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
Decrement PC if that was requested, this requires a PC sync.
comment: For short strings, use a fixed temp buffer.
label: code-design
restore stack top
Pretend like we got EOM
always push some string
* Detach handling
duk_hnativefunction specific fields.
[ ... eval "eval" eval_input level ]
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
For now shared handler is fine.
Signed integers always map to 4 bytes now.
No debugger support.
* Debug connection message write helpers
terminator
enum_flags
this cannot initiate a detach
true even with reattach
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
keep heap->dbg_detached_cb
num_stack_args
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
Return 1: got EOM
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
NOTE: length may be zero
Read fully.
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
get_value
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
even after a detach and possible reattach
avoid calling write callback in detach1()
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
pruned
switch cmd
For anything other than an Error instance, we calculate the
* error location directly from the current activation if one
* exists.
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
comment: unused: not accepted in inbound messages
label: code-design
Allow NULL 'msg'
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
detached
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
* Debug connection skip primitives
isAccessor
* Helper structs
At least: ... [err]
Error instance, use augmented error data directly
just in case callback is broken and won't write 'x'
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
DUK_USE_DEBUGGER_DUMPHEAP
-> [ ... func varmap enum ]
duk_hobject specific fields.
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
enum_index
this is especially critical to avoid another write call in detach1()
* Debug connection write primitives
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
not an error
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
DUK_USE_STRTAB_PROBE
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
may be set to 0 by duk_debugger_attach() inside callback
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
DUK_USE_DEBUGGER_SUPPORT
Easy to get wrong, so assert for it.
optional callstack level
restore PC
w/o refcounting
Write fully.
* Debug message processing
* Debug connection read primitives
compensate for eval() call
Since we already started writing the reply, just emit nothing.
DUK_USE_STRTAB_CHAIN
Skip dvalues to EOM.
heap->dbg_detached_cb: keep
nargs
'this' binding shouldn't matter here
* Status message and helpers
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
comment: XXX: exposed duk_debug_read_pointer
label: code-design
Error codes.
comment: unused
label: code-design
Initial bytes for markers.
Commands initiated by debug client.
Commands and notifys initiated by Duktape.
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
Debugger protocol version is defined in the public API header.
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
DUK_DEBUGGER_H_INCLUDED
comment: XXX: exposed duk_debug_read_buffer
label: code-design
Other initial bytes.
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
DUK_ERR_URI_ERROR: no macros needed
this is added to checks to allow for Duktape
* API calls in addition to function's own use
assertion omitted
DUK_USE_PANIC_HANDLER
* Assertion helpers
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
no refcount check
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
DUK_ERR_ERROR: no macros needed
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
DUK_USE_ASSERTIONS
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
* Prototypes
nop
already defined, good
DUK_ERR_ASSERTION_ERROR: no macros needed
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
* Assert macro: failure causes panic.
DUK_ERROR_H_INCLUDED
DUK_USE_VERBOSE_ERRORS
DUK_ERR_REFERENCE_ERROR: no macros needed
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
Non-verbose errors for low memory targets: no file, line, or message.
DUK_VERBOSE_ERRORS
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
no valstack space check
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
DUK_ERR_UNCAUGHT_ERROR: no macros needed
assertion disabled
DUK_USE_PARANOID_ERRORS
DUK_ERR_EVAL: no macros needed
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
unsigned
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
[ ... errval ]
3 entries actually needed below
no need to check now: both success and error are OK
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
assume PC is at most 32 bits and non-negative
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
DUK_USE_ERRTHROW
num args
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
Lightfunc, not blamed now.
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
-> [ ... error ]
thr argument only used for thr->heap, so specific thread doesn't matter
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
-> [ ... errhandler errval ]
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
Finally, blame the innermost callstack entry which has a
* .fileName property.
[ ... error ]
ignore reclimit, not constructor
Native function, no relevant lineNumber.
!DUK_USE_TRACEBACKS
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
[ ... error func ]
ignore_loop
callstack limits
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
[ ... error lineNumber fileName ]
* Add line number to a compiler error.
DUK_USE_AUGMENT_ERROR_CREATE
* Add .fileName and .lineNumber to an error on the stack top.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
since no recursive error handler calls
DUK_USE_PC2LINE
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
invalidated by pushes, so get out of the way
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
[ ... errhandler undefined errval ]
[ ... errval errhandler ]
-> [... arr num]
[ ... error func fileName ]
DUK_USE_TRACEBACKS
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
DUK_USE_AUGMENT_ERROR_THROW
[ ... error arr ]
[ ... error func fileName lineNumber ]
call_flags
-> [ ... errhandler undefined(= this) errval ]
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
[... arr]
Add function object.
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Add ._Tracedata to an error on the stack top.
XXX: specify array size, as we know it
(flags<<32) + (line), flags = 0
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
unreferenced w/o tracebacks
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
XXX: set with duk_hobject_set_length() when tracedata is filled directly
unreferenced w/o asserts
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
DUK_USE_CPP_EXCEPTIONS
dummy
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
* Error throwing helpers
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
DUK_USE_VERBOSE_ERRORS
comment: size for formatting buffers
label: code-design
* Default fatal error handler
!DUK_USE_PANIC_HANDLER
omit print
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
SCANBUILD: "Dereference of null pointer", normal
* Default panic handler
* Error, fatal, and panic handling.
exit() afterwards to satisfy "noreturn"
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
Report it to the debug client
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
* Get prototype object for an integer error code.
comment: XXX: more specific error classes?
label: code-design
DUK_USE_DEBUGGER_SUPPORT
side effects
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
all we need to know
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
* Error helpers
* Exposed helper for setting up heap longjmp state.
use_prev_pc
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
reset callstack limit
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
just making sure
* Finally, longjmp
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
comment: XXX: shared strings
label: code-design
Error object is augmented at its creation here.
* Helper for C function call negative return values.
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
intentionally empty
DUK_EXCEPTION_H_INCLUDED
duk_tval intentionally skipped
* Forward declarations
* Forward declarations for all Duktape structures.
DUK_FORWDECL_H_INCLUDED
no typedef
Current size (not counting a dynamic buffer's "spare").
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
No pointer compression because pointer is potentially outside of
* Duktape heap.
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
Stored in duk_heaphdr h_extra16.
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
size stored in duk_heaphdr unused flag bits
* Misc defines
indirect allocs
may be NULL if alloc_size == 0
* Prototypes
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
buffer pointer is to an externally allocated buffer
assume 0 <=> NULL
dynamic buffer ops
DUK_HBUFFER_H_INCLUDED
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
no extra padding
* Field access
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
* Structs
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
Stored in duk_heaphdr unused flags.
Shared prefix for all buffer types.
buffer is behind a pointer, dynamic or external
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
Because size > 0, NULL check is correct
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
alloc external with size zero
the compressed pointer is zeroed which maps to NULL, so nothing to do.
For indirect allocs.
no need to write 'out_bufdata'
zero everything unless requested not to do so
* duk_hbuffer allocation and freeing.
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
no wrapping
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
* Resizing
'res' may be NULL if new allocation size is 0.
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
* Maximum size check
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
All element accessors are host endian now (driven by TypedArray spec).
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
DUK_HBUFFEROBJECT_H_INCLUDED
byte index limit for element access, exclusive
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Shared object part.
element type
Underlying buffer (refcounted), may be NULL.
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
byte offset to buf
* Heap Buffer object representation. Used for all Buffer variants.
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
Slice starting point is beyond current length.
DUK_USE_BUFFEROBJECT_SUPPORT
Line number range for function. Needed during debugging to
* determine active breakpoints.
number of arguments allocated to regs
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
shared object part
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
* Field accessor macros
DUK_HCOMPILEDFUNCTION_H_INCLUDED
regs to allocate
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
Data area, fixed allocation, stable data ptrs.
Note: assumes 'data' is always a fixed buffer
* Main struct
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
* Accessor macros for function specific data areas
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
callback for indirect reallocs, request for current pointer
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
heap destruction ongoing, finalizer rescue no longer possible
resend state next time executor is about to run
No field needed when strings are in ROM.
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
comment: alloc size in elements
label: code-design
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
don't run finalizers; queue finalizable objects back to heap_allocated
comment: unused
label: code-design
DUK_USE_ROM_STRINGS
don't compact objects; needed during object property allocation resize
borrowed; NULL if no step state (NULLed in unwind)
breakpoints: [0,breakpoint_count[ gc reachable
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
* Other heap related defines
Allocator functions.
don't run finalizers; leave finalizable objects in finalize_list for next round
Step types
used entries + approx 100% -> reset load to 50%
current thread
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
* Memory constants
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
required, NULL implies detached
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
heap thread, used internally and for finalization
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
load factor min 25%
helper to insert a (non-string) heap object into heap allocated list
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
used elements (includes DELETED)
marker for detecting internal "double faults", see duk_error_throw.c
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
debugger state, only relevant when attached
allocated heap objects
4'294'967'295
longjmp type
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
Precomputed pointers when using 16-bit heap pointer packing.
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
Milliseconds between status notify and transport peeks.
value1 -> error object
mark-and-sweep is currently running
step type: none, step into, step over, step out
refcount code is processing refzero list
emergency mode: try extra hard
time when status/peek was last done (Date-based rate limit)
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
mark-and-sweep control
if 0, 'str16' used, if > 0, 'strlist16' used
* Stringtable entry for fixed size stringtable
no refcounting
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
probe sequence (open addressing)
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
starting line number
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
if 0, 'str' used, if > 0, 'strlist' used
heap level "stash" object (e.g., various reachability roots)
* Heap flags
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
* Raw memory calls: relative to heap, but no GC interaction
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
* Prototypes
50x heap size
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
currently running thread
fixed top level hashtable size (separate chaining)
longjmp state
debugger detaching; used to avoid calling detach handler recursively
required
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
built-in strings
executor interrupt running (used to avoid nested interrupts)
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
current setjmp() catchpoint
isError flag for yield
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
These are for rate limiting Status notifications and transport peeking.
Used to support single-byte stream lookahead.
duk_handle_call / duk_handle_safe_call recursion depth limiting
comment: unused
label: code-design
* Main heap structure
currently active breakpoints: NULL term, borrowed pointers
2nd related value (type specific)
resizing parameters
1st related value (type specific)
an error handler (user callback to augment/replace error) is running
mix-in value for computing string hashes; should be reasonably unpredictable
Starting from this round, use emergency mode
* for mark-and-sweep.
work list for objects to be finalized (by mark-and-sweep)
value of dbg_exec_counter when we last did a Date-based check
* Stringtable
DUK_USE_DEBUGGER_SUPPORT
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
callstack index
debugger
DUK_HEAP_H_INCLUDED
cumulative opcode execution count (overflows are OK)
comment: alloc function typedefs in duktape.h
label: code-design
value1 -> yield value, iserror -> error / normal
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
strings up to the this length are not cached
* Built-in strings
* Debugger support
1x heap size
currently paused: talk with debug client until step/resume
don't resize stringtable (but may sweep it); needed during stringtable resize
rnd_state for duk_util_tinyrandom.c
string intern table (weak refs)
load factor max 75%
Currently nothing to free
No strs[] pointer.
explicit NULL inits
some derived types
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
comment: suppress warning, not used
label: code-design
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
comment: Similar workaround for INFINITY.
label: code-design
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
* All done
'thr' is now reachable
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
comment: Silence a few global unused warnings here.
label: code-design
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
DUK_USE_ROM_STRINGS
DUK_USE_HEAPPTR16
assumes that allocated pointers and alloc funcs are valid
* if res exists
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
basic platform types
Currently nothing to free; 'data' is a heap object
mark-and-sweep not running -> must be empty
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
* Init the heap object
comment: XXX: zero assumption
label: code-design
unsigned
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
* Init stringtable: fixed variant
Fixed seed value used with ROM strings.
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
refzero not running -> must be empty
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
* Init the heap thread
Constants for built-in string data depacking.
structs from duk_forwdecl.h
* Zero the struct, and start initializing roughly in order
* duk_heap allocation and freeing.
convenience
just one 'int' for C++ exceptions
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
0 = uppercase, 32 = lowercase (= 'a' - 'A')
* Init built-in strings
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
comment: Note: first argument not really used
label: code-design
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
important chosen base types
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
* Computed values (e.g. INFINITY)
skip finalizers; queue finalizable objects to heap_allocated
tval
DUK_USE_DEBUG
basic types from duk_features.h
* Init stringcache
no res->strs[]
DUK_USE_EXPLICIT_NULL_INIT
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
Detach a debugger if attached (can be called multiple times)
* safely.
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
Decrease by 25% every round
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
nothing to NULL
derived types
strings are only tracked by stringtable
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
DUK_USE_STRTAB_PROBE
maps to finalizer 2nd argument
* If selftests enabled, run them as early as possible
zero
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
DUK_USE_STRTAB_CHAIN
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
default prototype (Note: 'thr' must be reachable)
basic types
comment: XXX: this may now fail, and is not handled correctly
label: code-design
* Debug dump type sizes
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Init stringtable: probe variant
comment: XXX: inefficient loop
label: code-design
note: mixing len into seed improves hashing when skipping
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
Bernstein hash init value is normally 5381
Constants for duk_hashstring().
DUK_USE_STRHASH_DENSE
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
off >= step, and step >= 1
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
may be NULL, too
last element that was left in the heap
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
* Finish
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
finally free the struct itself
deal with weak references first
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
XXX: for threads, compact value stack, call stack, catch stack?
only objects have finalizers
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
this case can no longer occur because refcount is unsigned
DUK_USE_HEAPPTR16
free object and all auxiliary (non-heap) allocs
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Strings and ROM objects are never placed on the heap allocated list.
queue back to heap_allocated
* Assertions after
'data' is reachable through every compiled function which
* contains a reference.
XXX: skip count_free w/o debug?
* Object will be kept; queue object back to heap_allocated (to tail)
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
DUK_USE_ASSERTIONS
DUK_USE_MARK_AND_SWEEP
* Assertion helpers.
must never longjmp
* Object compaction.
*
* Compaction is assumed to never throw an error.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
nothing to mark
If debugger is paused, garbage collection is disabled by default.
main reachability roots
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
* Plain, boring reachable object.
XXX: stringtable emergency compaction?
recursion tracking happens here only
reset voluntary gc trigger count
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
* Run (object) finalizers in the "to be finalized" work list.
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
* Assertions before
* Unreachable object, free
OK
done so that duk__mark_heaphdr() works correctly
must also check refzero_list
* Mark objects on finalize_list.
*
DUK_USE_REFERENCE_COUNTING
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
free inner references (these exist e.g. when external
* strings are enabled)
ignored
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
* Mark-and-sweep garbage collection.
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
* Mark the heap.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
mark finalizer work list as reachability roots
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
temproots
refzero_list treated as reachability roots
nothing now
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
flags have been already cleared
* Reset trigger counter
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Caller will finish the marking process if we hit a recursion limit.
no mark-and-sweep gc
may have FINALIZED
log this with a normal debug level because this should be relatively rare
* Marking functions for heap types: mark children recursively
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
hash part is a 'weak reference' and does not contribute
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
DUK_HEAPHDR_HAS_FINALIZED may be set if we're doing a
* refzero finalization and mark-and-sweep gets triggered
* during the finalizer.
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
nothing to process
* Clear (reachable) flags of refzero work list.
Keep heap->finalize_list up-to-date during the list walk.
* This has no functional impact, but does matter e.g. for
* duk_push_heapptr() asserts when assertions are enabled.
* Begin
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
nop
DUK_USE_STRTAB_PROBE
* Reachable object, keep
May happen in some out-of-memory corner cases.
DUK_HEAPHDR_HAS_FINALIZED may or may not be set.
* Sweep stringtable
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Sweep heap
comment: XXX: could clear FINALIZED already here; now cleared in
* next mark-and-sweep.
label: code-design
DUK_USE_STRTAB_CHAIN
finalize_list will always be processed completely
approximate
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
nargs
mark finalizable as reachability roots
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
No finalizers for ROM objects
* Misc
* Memory allocation handling.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
for zero size allocations NULL is allowed
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
simulate alloc failure on every realloc (except when mark-and-sweep is running)
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
no voluntary gc
* First attempt
simulate alloc failure on every alloc (except when mark-and-sweep is running)
DUK_USE_MARK_AND_SWEEP
assume memset with zero size is OK
* Allocate memory with garbage collection
ptr before mark-and-sweep
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
useful for debugging
ptr may be NULL
* Reallocate memory with garbage collection
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
* Free memory
* Voluntary periodic GC (if enabled)
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
DUK_USE_INTERRUPT_COUNTER
* Support functions for duk_heap.
may be NULL
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
yes -> move back to heap allocated
Require a lot of stack to force a value stack grow/shrink.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
DUK_USE_REFERENCE_COUNTING
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
DUK_USE_REFZERO_FINALIZER_TORTURE
no -> decref members, then free
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
ignored
no refcounting
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
refcount is unsigned, so always true
currently, always the case
not emergency
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
must never longjmp
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
* Rescue or free.
May happen in some out-of-memory corner cases.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
tail insert: don't disturb head in case refzero is running
* Detect recursive invocation
nothing to finalize
comment: unused
label: code-design
nothing now
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
not strictly necessary
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
duk_hobject_run_finalizer() sets
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
bump refcount to prevent refzero during finalizer processing
* Objects have internal references. Must finalize through
* the "refzero" work list.
* Pick an object from the head (don't remove yet).
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
approximate
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
comment: XXX: better to get base and walk forwards?
label: code-design
nargs
* Churn refzero_list until empty
remove artificial bump
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
hash part is a 'weak reference' and does not contribute
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
* Reference counting implementation.
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
* Misc
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
update entry, allocating if necessary
may be equal
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
take last entry
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
LRU: move our entry to first
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
no sce, or sce scan not best
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
clen == blen -> pure ascii
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
* For ASCII strings, the answer is simple.
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
initialize for debug prints, needed if sce==NULL
* A C
* B A
* C <- sce ==> B
* D D
may be less, since DELETED entries are NULLed by rehash
comment: load factor too low or high, count actually used entries and resize
label: code-design
Count actually used (non-NULL, non-DELETED) entries.
OK
avoid array abandoning which interns strings
unsigned intentionally
dummy
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
may be NULL
NUL terminate for convenient C access
Undefine local defines
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Overflow, relevant mainly when listlen is 16 bits.
find and remove string from stringtable; caller must free the string itself
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
char: use int cast
guaranteed to succeed
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
fail
new_used / size <= 1 / DIV <=> new_used <= size / DIV
DUK_USE_STRTAB_PROBE
DUK_USE_DEBUG
caller is responsible for ensuring this
strings may have inner refs (extdata) in some cases
grow by at most one
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
looping should never happen
not strictly necessary
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
DUK_USE_ROM_STRINGS
* Heap stringtable handling, string interning.
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
comment: unused with some debug level combinations
label: code-design
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
Because new_size > duk__count_used_probe(heap), guaranteed to work
DUK_USE_HEAPPTR16
failed
avoid recursive string table call
formatted result limited
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
DUK_USE_STRTAB_CHAIN
Now two entries in the same slot, alloc list
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
required for rehash to succeed, equality not that useful
* Exposed calls
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
st_used remains the same, DELETED is counted as used
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
For manual testing only.
comment: unused
label: code-design
Relies on NULL encoding to zero.
FAIL
* Raw intern and lookup
new_free / size <= 1 / DIV <=> new_free <= size / DIV
Without ROM objects "needs refcount update" == is heap allocated.
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
refcount macros not defined without refcounting, caller must #ifdef now
round out to 8 bytes
currently nop
result: updated refcount
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
refcounting requires direct heap frees, which in turn requires a dual linked heap
5 heap flags
mark-and-sweep: finalized (on previous pass)
Original idiom used, minimal code size.
comment: XXX: fast int-to-double
label: code-design
* Assert helpers
Optimized for size.
DUK_USE_ROM_OBJECTS
nop
Optimized for speed.
comment: XXX: double evaluation for 'tv' argument.
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
init pointer fields to null
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
DUK_USE_FASTINT
comment: XXX: fast-int-to-double
label: code-design
read-only object, in code section
2 bits for heap type
side effects
mark-and-sweep: children not processed
mark-and-sweep: finalizable (on current pass)
Casting convenience.
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
get or set a range of flags; m=first bit number, n=number of bits
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
25 user flags
DUK_HEAPHDR_H_INCLUDED
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
comment: XXX: no optimized variants yet
label: requirement
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
mark-and-sweep: reachable
* Heap native function representation.
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
DUK_HNATIVEFUNCTION_H_INCLUDED
shared object part
hobject management functions
!DUK_SINGLE_FILE
LAYOUT 2
misc
* Macros to access the 'props' allocation.
object has an array part (a_size may still be 0)
* Exposed data
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
E5 Section 8.6.1
push value to stack
object is extensible
'Arguments' object and has arguments exotic behavior (non-strict callee)
hash size approx. 1.25 times entries size
* Struct defs
comment: unused
label: code-design
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
finalization
probe sequence
comment: function: function must not be tail called
label: code-design
function: create binding for func name (function templates only, used for named function expressions)
Maximum traversal depth for "bound function" chains.
entry part size
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
* PC-to-line constants
internal property functions
object is a buffer object (duk_hbufferobject) (always exotic)
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
internal define property: skip write silently if exists
flags used for property attributes in duk_propdesc and packed flags
object is a thread (duk_hthread)
prop index in 'entry part', < 0 if not there
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
comment: hash part size or 0 if unused
label: code-design
Object built-in methods
LAYOUT 1
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
implies DUK_HOBJECT_IS_BUFFEROBJECT
* Resizing and hash behavior
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
function: create new environment when called (see duk_hcompiledfunction)
class masks
2^3 -> 1/8 = 12.5% min growth
convenience
custom; implies DUK_HOBJECT_IS_THREAD
for updating (all are set to < 0 for virtual properties)
'Proxy' object
index for next new key ([0,e_next[ are gc reachable)
note: this updates refcounts
alias for above
'Array' object, array length and index exotic behavior
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
25%, i.e. less than 25% used -> abandon
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
hobject property layout
core property functions
DUK_HOBJECT_H_INCLUDED
prop index in 'array part', < 0 if not there
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
flags for duk_hobject_get_own_propdesc() and variants
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Prototypes
* Macros for accessing size fields
object is a compiled function (duk_hcompiledfunction)
macros
Duktape/C (nativefunction) object, exotic 'length'
internal properties
custom
higher value conserves memory; also note that linear scan is cache friendly
read-only values 'lifted' for ease of use
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
envrec: (declarative) record is closed
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
LAYOUT 3
internal align target for props allocation, must be 2*n for some n
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
object is constructable
prototype: the only internal property lifted outside 'e' as it is so central
controls for minimum array part growth
* Macros for property handling
pc2line
ES6 proxy
2**31-1 ~= 2G properties
function: create an arguments object on function call
accessor
controls for minimum entry part growth
range check not necessary because all 4-bit values are mapped
XXX: duk_uarridx_t?
object has any exotic behavior(s)
E5 Section 8.6.2 + custom classes
prop index in 'hash part', < 0 if not there
don't throw for prototype loop
low-level property functions
object established using Function.prototype.bind()
* Ecmascript [[Class]]
112.5%, i.e. new size less than 12.5% higher -> fast resize
helpers for defineProperty() and defineProperties()
object is a native function (duk_hnativefunction)
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
function: function object is strict
enumeration
array part size (entirely gc reachable)
'String' object, array index exotic behavior
alloc and init
* Misc
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
also goes into flags
different memory layout, alloc size, and init
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Zero encoded pointer is required to match NULL
comment: unused now
label: code-design
when nothing is running, API calls are in non-strict mode
NULL pointer is required to encode to zero, so memset is enough.
comment: UNUSED, intentionally empty
label: code-design
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
* Hobject Ecmascript [[Class]].
recheck that the property still exists
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
* Entries part
[... enum]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
still reachable
compact; no need to seal because object is internal
[ ... res ]
-> [... enum key enum_target val]
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
return 1 to allow callers to tail call
used for array, stack, and entry indices
[enum_target res]
enumerator must have no keys deleted
[ ... enum_target res trap_result val true ]
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
string objects must not created without internal value
control props
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
-> [ ... enum_target res ]
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
[enum_target res key true]
-> [... enum key val]
There's intentionally no check for
* current underlying buffer length.
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
[ ... enum_target res trap_result ]
must match exactly the number of internal properties inserted to enumerator
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Initialize index so that we skip internal control keys.
-> [... enum key enum_target key]
-> [...]
* Proxy object handling
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
[enum_target enum res]
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
comment: XXX use get tval ptr, more efficient
label: code-design
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
-> [... key val]
Neutered buffer, zero length seems
* like good behavior here.
String and buffer enumeration behavior is identical now,
* so use shared handler.
[res]
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
-> [... key]
nargs
[ ... enum_target res trap_result val ]
DUK_USE_ES6_PROXY
keep val_highest
-> [ ... enum_target res trap_result ]
we know these because enum objects are internally created
Copy trap result keys into the enumerator object.
no array part
[ ... enum_target res handler trap ]
-> [ ... enum_target res handler undefined target ]
only 'length'
-> [ ... enum_target res trap handler target ]
ensure never re-entered until rescue cycle complete
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
-> [... obj finalizer]
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
[... obj]
nargs
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> [... obj retval/error]
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
nrets
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
this also increases refcount by one
duk_safe_call discipline
-> [...]
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
* Misc support functions
avoid problems if p == h->prototype
* Iterate the bitstream (line diffs) until PC is reached
0: no change
1 0 <2 bits>
1 1 1 <32 bits>
0
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
Note: pc is unsigned and cannot be negative
comment: workaround: max nbits = 24 now
label: code-design
1 1 0 <8 bits>
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Use the index in the header to find the right starting point
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
end of diff run
DUK_USE_PC2LINE
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
end of bytecode
compact
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
be_ctx->offset == length of encoded bitstream
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
valid pc range is [0, length[
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
should never happen
[key getter this] -> [key retval]
Note: no key on stack
avoid attempt to compact the current object
key is now reachable in the valstack
NULL obj->p is OK
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
all virtual properties are non-configurable and non-writable
not found
resume lookup from target
comment: Note: reuse 'curr'
label: code-design
* Get old and new length
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
* Check whether we need to abandon an array part (if it exists)
no need to decref, as previous value is 'undefined'
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
USE_PROP_HASH_PART
Get default hash part size for a certain entry part size.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
String is an own (virtual) property of a lightfunc.
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
If neutered must return 0; offset is zeroed during
* neutering.
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
comment: XXX: inject test
label: code-design
setter and/or getter may be NULL
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
replaces top of stack with new value if necessary
comment: prev value must be unused, no decref
label: code-design
* Update an existing property of the base object.
late lookup, avoid side effects
* Debug logging after adjustment.
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
update length (curr points to length, and we assume it's still valid)
* Post resize assertions.
flags
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
No resize has occurred so temp_desc->e_idx is still OK
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
comment: XXX: this is a major target for size optimization
label: code-design
implicit attributes
[in_val in_val]
leave result on stack top
if fails, e_size will be zero = not an issue, except performance-wise
Note: no recursion issue, we can trust 'map' to behave
non-object base, no offending virtual property
caller ensures; rom objects are never bufferobjects now
* Some change(s) need to be made. Steps 7-11.
For internal use: get non-accessor entry value and attributes
* Write to entry part
* All done, switch properties ('p') allocation to new one.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
hash probe sequence
must have been, since in array part
array entries are all plain values
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Buffer writes are often integers.
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
[obj key value desc]
resume delete to target
stage 2: delete configurable entries above target length
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
success
[] -> [res]
keep key reachable for GC etc; guaranteed not to fail
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
index is above internal buffer length -> property is fully normal
write_to_array_part:
E5 Section 15.5.5.1
ignore retval -> [key]
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
* Because buffer values are often looped over, a number fast path
* is important.
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
don't push value
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
increases key refcount
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
avoid attempts to add/remove object keys
curr is accessor, desc is data
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
* Local defines
E5 Section 15.4.5.1, step 4
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
[... old_result result] -> [... result]
Must avoid duk_pop() in exit path
DUK_USE_FASTINT
no decref needed for a number
Leave 'getter' on stack
[key] -> [undefined] (default value)
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
force_flag
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
curr value
[key] (coerced)
Note: no allocation pressure, no need to check refcounts etc
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
[key setter this val key] -> [key retval]
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
guaranteed to find an empty slot
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
[ key trap_result ] -> []
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
remove value
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
* Not found
* Proxy helpers
steps 3.h and 3.i
* Found; post-processing (Function and arguments objects)
[key val]
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
cannot be arguments exotic
actually used, non-NULL keys
avoid double coercion
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* Local prototypes
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Check array density and indicate whether or not the array part should be abandoned.
[key value] or [key undefined]
descriptor type specific checks
avoid multiple computations of flags address; bypasses macros
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
not enumerable
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
should not happen
previous value is assumed to be garbage, so don't touch it
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
standard behavior, step 3.f.i
index is above internal string length -> property is fully normal
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
must not be extensible
comment: fill new_h with u32 0xff = UNUSED
label: code-design
* Misc helpers
side effects
NULL if tv_obj is primitive
actual update happens once write has been completed without
* error below.
IsDataDescriptor(desc) == true
Target object must be checked for a conflicting
* non-configurable property.
guaranteed when building arguments
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
* Copy array elements to new array part.
property exists, either 'desc' is empty, or all values
* match (SameValue)
we currently assume virtual properties are not configurable (as none of them are)
* Property lookup
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
Count actually used entry part entries (non-NULL keys).
Note: use 'curr' as a temp propdesc
Fast check for extending array: check whether or not a slow density check is required.
* GETPROP: Ecmascript property read.
* Property not found in prototype chain.
unsigned
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
XXX: fast path for arrays?
force the property to 'undefined' to create a slot for it
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
[obj key undefined]
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[obj key desc value get set curr_value]
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
DUK_USE_HOBJECT_HASH_PART
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
coercion order matters
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
Undefine local defines
[obj key value desc value]
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
default value
write to entry part
For internal use: get array part value
treat like property not found
[... put_value]
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
[ key ] -> []
if abandon_array, new_a_size must be 0
* Helpers to resize properties allocation on specific needs.
for resizing of array part, use slow path
-> [ ... trap handler ]
Note: proxy handling must happen before key is string coerced.
guaranteed to finish, as hash is never full
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
Note: unconditional throw
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
comment: actually used
label: code-design
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
* Array part
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
see below
hash lookup
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
success: leave varname in stack
Note: changing from writable to non-writable is OK
don't touch property attributes or hash part
stage 1 guarantees
current assertion is quite strong: decref's and set to unused
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> [key]
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
[ ... key trap handler ]
* Get old and new length
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
* Found existing own or inherited plain property, but original
* base is a primitive value.
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
V
... target is extensible
duk__get_min_grow_e() is always >= 1
* Nice debug log.
* DELPROP: Ecmascript property deletion.
[... varname]
* Ecmascript compliant [[Delete]](P, Throw).
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
note: original, uncoerced base
!= 0 => post-update for array 'length' (used when key is an array index)
only need to guarantee 1 more slot, but allocation growth is in chunks
IsAccessorDescriptor(desc) == true
no wrap assuming h_bufobj->length is valid
avoid issues with relocation
[key] -> []
contains value
Receiver: Proxy object
comment: XXX: inline into a prototype walking loop?
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
nargs
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
happens when hash part dropped
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
no need for decref/incref because value is a number
[key undefined] -> [key]
OK for NULL.
shared exit path now
attempt to change from accessor to data property
Read value pushed on stack.
curr and desc are data
accessor with defined getter
key coercion (unless already coerced above)
covered by comparison
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
[key]
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
-> [in_val]
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
steps 4.a and 4.b are tricky
defaults, E5 Section 8.6.1, Table 7
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
flag for later write
Get minimum array part growth for a certain size.
arrays MUST have a 'length' property
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
* Helpers for managing property storage size
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
NULL if not an object
Catches >0x100000000 and negative values.
currently required
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
retval indicates delete failed
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
fall through
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
If neutered must return 0; length is zeroed during
* neutering.
array case is handled comprehensively above
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
[key setter this val] -> [key retval]
stage 3: update length (done by caller), decide return code
* Not found as concrete or virtual
minimum new length is highest_arr_idx + 1
property is configurable and
consistency requires this
* Coercion and fast path processing
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
relevant array index is non-configurable, blocks write
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
P
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
index/length check guarantees
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
new value
actually used, non-NULL entries
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
shared checks for all descriptor types
strict flag for putvar comes from our caller (currently: fixed)
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
caller ensures
traits are separate; in particular, arguments not an array
0 = don't push current value
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
fill new entries with -unused- (required, gc reachable)
duk__get_min_grow_a() is always >= 1
[key getter this key] -> [key retval]
* New length not lower than old length => no changes needed
* (not even array allocation).
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
important for callers
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
clear array part flag only after switching
* Writability check
tv1 points to value storage
caller must have decref'd values above new_a_size (if that is necessary)
* XXX: shrink array allocation or entries compaction here?
not found in 'curr', next in prototype chain; impose max depth
FOUND
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
t >= 0 always true, unsigned
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
target
fall thru
[key setter this val]
comment: Note: we can reuse 'desc' here
label: code-design
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
data property or accessor without getter
comment: XXX: fastint
label: code-design
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
Careful with wrapping (left shifting idx would be unsafe).
-> [ ... obj key trap handler ]
[ ...val ] -> [ ... ]
currently used -> new size
mask out flags not actually stored
varenv remains reachable through 'obj'
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
comment: XXX: optimize this filling behavior later
label: code-design
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
[key result] -> [result]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
map is reachable through obj
0 if no used entries
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
resume check from proxy target
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
arguments MUST have an initialized lexical environment reference
if new_p == NULL, all of these pointers are NULL
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
automatic length update
always grow the array, no sparse / abandon support here
comment: remove old value
label: code-design
comment: NULL always indicates alloc failure because
* new_alloc_size > 0.
label: code-design
[ ... key ] -> [ ... ]
always in entry part, no need to look up parents etc
* Copy keys and values in the entry part (compacting them at the same time).
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
XXX: C recursion limit if proxies are allowed as handler/target values
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
Arrays never have other exotic behaviors.
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
value from hook
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
[... put_value varname]
number
Get minimum entry part growth for a certain size.
if accessor without getter, return value is undefined
undefined is accepted
[obj key desc value get set curr_value varname]
key must not already exist in entry part
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
* Actual Object.defineProperty() default algorithm.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
[ ... value? getter? setter? ]
may become sparse...
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Entries part is a bit more complex
label: code-design
remove key
array 'length' is always a number, as we coerce it
= IsAccessorDescriptor(Desc)
Reject attempt to change a read-only object.
idx_value may be < 0 (no value), set and get may be NULL
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
-> [ ... handler trap ]
DUK_USE_ES6_PROXY
not reachable
marker values for hash part
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
no need for 'caller' post-check, because 'key' must be an array index
remove in_val
Grow entry part allocation for one additional entry.
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
for zero size, don't push anything on valstack
[key result]
remaining actual steps are carried out if standard DefineOwnProperty succeeds
curr is accessor -> cannot be in array part
E5 Section 15.5.5.2
equality not actually possible
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
ignore result
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
comment: XXX: is valstack top best place for argument?
label: code-design
XXX: sufficient to check 'strict', assert for 'is function'
Leave 'value' on stack
return value
[ ... val key ] -> [ ... key val ]
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
result: hash_prime(floor(1.2 * e_size))
stack contains value (if requested), 'out_desc' is set
curr and desc are accessors
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
* Entries part
second incref for the entry reference
* Not found as a concrete property, check whether a String object
* virtual property matches.
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
prev value can be garbage, no decref
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
step 3.e: replace 'Desc.[[Value]]'
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
[str] -> [substr]
value from target
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
Note: this order matters (final value before deleting map entry must be done)
unconditional
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
0 = no update
Grow array part for a new highest array index.
comment: XXX: awkward helpers
label: code-design
* Pre resize assertions.
curr is data, desc is accessor
stack prepped for func call: [ ... trap handler ]
remove hash entry (no decref)
resume write to target
For internal use: get non-accessor entry value
* Internal helpers for managing object 'length'
All the flags fit in 16 bits, so will fit into duk_bool_t.
throw
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
[... value this_binding]
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Note: 'curr' refers to 'length' propdesc
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
varname is still reachable
get varenv for varname (callee's declarative lexical environment)
guaranteed to finish
Leave 'setter' on stack
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
string is 'eval' or 'arguments'
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
computed live
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
* Prototypes
string hash
The external string struct is defined even when the feature is inactive.
string is a reserved word (strict)
slower but more compact variant
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
string is a reserved word (non-strict)
string is ASCII, clen == blen
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: should never be called
label: code-design
placed in duk_heaphdr_string
length in codepoints (must be E5 compatible)
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
string is a valid array index
string is internal
string data is external (duk_hstring_external)
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
length in bytes (not counting NUL term)
DUK_HSTRING_H_INCLUDED
* Misc
Caller must check character offset to be inside the string.
unsigned
This may throw an error though not for valid E5 strings.
* Misc support functions
!DUK_USE_HSTRING_CLEN
comment: Most practical strings will go here.
label: code-design
comment: Convenience copies from heap/vm for faster access.
label: code-design
allocation size
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
next to use, highest used is top - 1
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
current lexical environment (may be NULL if delayed)
Current compiler state (if any), used for augmenting SyntaxErrors.
No field needed when strings are in ROM.
* Catcher defines
end of valstack allocation (exclusive)
function executes as a constructor (called via "new")
cached: valstack_end - valstack (in entries, not bytes)
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
catch part will catch
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
roughly 512 bytes
DUK_USE_ROM_STRINGS
thread has yielded
roughly 256 bytes
who resumed us (if any)
callstack index of related activation
* Flags for __FILE__ / __LINE__ registered into tracedata
roughly 1 kiB
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
activation prevents yield (native call or "new")
function executes in strict mode
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Sanity limits for stack sizes.
borrowed: full duk_tval for function being executed; for lightfuncs
indirect allocs
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
number of activation records in callstack preventing a yield
activation has active breakpoint(s)
Call stack. [0,callstack_top[ is GC reachable.
thread not currently running
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
roughly 128 bytes
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
DUK_HTHREAD_H_INCLUDED
borrowed reference to catch variable name (or NULL if none)
roughly 0.5 kiB
bottom of current frame
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
thread currently running (only one at a time)
top of current frame (exclusive)
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
* Prototypes
activation has tail called one or more times
Current strictness flag: affects API calls.
Backpointers.
roughly 2 kiB
values for the state field
needed for stepping
Yield/resume book-keeping.
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
finally part will catch
idx_base and idx_base+1 get completion value and type
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
Thread state.
request to create catch binding
nop
start of valstack allocation
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
* Struct defines
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
activation is a direct eval call
Shared object part
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
type and control flags, label number
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
current variable environment (may be NULL if delayed)
Catch stack. [0,catchstack_top[ is GC reachable.
* Stack constants
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
* Activation defines
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
thread resumed another thread (active but not running)
roughly 64 bytes
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
catch or with binding is currently active
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
countdown state
* Thread defines
thread has terminated
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* duk_hthread allocation and freeing.
valstack
callstack
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
For indirect allocs.
catchstack
comment: XXX: relocate
label: code-design
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
currently, even for Array.prototype
normal valued properties
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
Architecture, OS, and compiler strings
DUK_USE_LIGHTFUNC_BUILTINS
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
enable exotic behaviors last
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
provideThis=false
initjs data is NUL terminated
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
[ (builtin objects) name func ]
chain
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Cast converts magic to 16-bit signed value
Packed or unpacked tval
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
Object property allocation layout
avoid empty label at the end of a compound statement
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
Inherit from ROM-based global object: less RAM usage, less transparent.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
unsigned
-> [ ... new_global new_globalenv new_global ]
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
def_value
DUK_USE_USER_INITJS
* The default property attributes are correct for all
* function valued properties of built-in objects now.
genbuiltins.py ensures
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
Endianness indicator
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
comment: XXX: function properties
label: code-design
* Since built-ins are not often extended, compact them.
convenience
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
only Array.prototype matches
[ (builtin objects) name ]
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
exhaustive
Alignment guarantee
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
DUK_USE_ROM_OBJECTS
some assertions
comment: XXX: compression
label: code-design
side effect free
comment: integer mixed endian not really used now
label: code-design
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
always 1 arg
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
DUK_HOBJECT_FLAG_STRICT varies
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
must hold DUK_VARARGS
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
key, getter and setter, now reachable through object
comment: XXX: compression (as an option)
label: code-design
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
No built-in functions are constructable except the top
* level ones (Number, etc).
Low memory options
accessor flag not encoded explicitly
probe
no prototype or class yet
DUK_USE_BUILTIN_INITJS
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
always 0 args
[ (builtin objects) ]
must be signed
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
* Encoding constants, must match genbuiltins.py
XXX: ARRAY_PART for Array prototype?
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
native function properties
all native functions have NEWENV
push operation normalizes NaNs
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
no prototype
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
no need to decref
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
Write bytecode executor's curr_pc back to topmost activation (if any).
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Order of unwinding is important
ptr_curr_pc != NULL only when bytecode executor is active.
unwinds valstack, updating refcounts
DUK_USE_DEBUGGER_SUPPORT
* Thread support.
side effects, possibly errors
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
avoid warning (unsigned)
unsigned
* Restore 'caller' property for non-strict callee functions.
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
true, despite side effect resizes
note: any entries above the callstack top are garbage and not zeroed
cannot grow
With lightfuncs, act 'func' may be NULL
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
func is NULL for lightfunc
must be, since env was created when catcher was created
note: any entries above the catchstack top are garbage and not zeroed
* Update preventcount
avoid side effect issues
current lex_env of the activation (created for catcher)
Note that multiple catchstack entries may refer to the same
* callstack entry.
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
side effects
no incref needed
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
check that there is space for at least one new entry
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
No need for a NULL/zero-size check because new_size > 0)
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
prototype is lex_env before catcher created
avoid side effects
this is a bit approximate (errors out before max is reached); this is OK
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
shrink failure is not fatal
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
common case, already closed, so skip
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
DUK_INTERNAL_H_INCLUDED
autogenerated: strings and built-in object init data
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
builtins need e.g. duk_tval tag definitions
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
comment: unused
label: code-design
DUK_JMPBUF_H_INCLUDED
use SameValue instead of non-strict equality
conversions, coercions, comparison, etc
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
identifiers and environment handling
Flags for duk_js_compare_helper().
E5 Sections 11.8.1, 11.8.5; x < y
bytecode execution
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
comment: unused
label: code-design
Flags for duk_js_equals_helper().
eval left argument first
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
duk_handle_ecma_call_setup: setup for a tail call
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
call is a direct eval call
call handling
* Ecmascript execution, support primitives.
comment: unused
label: code-design
negate result
DUK_JS_H_INCLUDED
Flags for call handling.
duk_handle_ecma_call_setup: setup for a resume()
use strict equality instead of non-strict equality
pre/post opcode values have constraints,
if B/C is >= this value, refers to a const
misc constants and helper macros
DUK_OP_TRYCATCH flags in A
use 'undefined' for value automatically
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
DUK_OP_RETURN flags in A
DUK_OP_CALL flags in A
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
* Ecmascript bytecode
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
DUK_OP_EXTRA, sub-operation in A
function declaration
DUK_JS_BYTECODE_H_INCLUDED
dummy value used as marker
see duk_js_executor.c
comment: XXX: incref by count (2) directly
label: code-design
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
success/error path both do this
num entries of new func at entry
other call
no need to unwind
* Forward declarations.
Strict functions don't get their 'caller' updated.
comment: XXX: don't want to shrink allocation here
label: code-design
non-strict: non-deletable, writable
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
Get valstack index for the func argument or throw if insane stack.
'i' is the first entry we'll keep
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
tv1 is -below- valstack_bottom
[ args(n) [crud] formals arguments map mappednames ]
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
* Interrupt counter fixup (for development only).
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
'caller' must only take on 'null' or function value
Call handling and success path. Success path exit cleans
* up almost all state.
comment: XXX: avoid this check somehow
label: code-design
'func' on stack (borrowed reference)
at least effective 'this'
[ ... this_new | arg1 ... argN ]
never executed
comment: Longjmp state is cleaned up by error handling
label: code-design
* Thread state check and book-keeping.
bottom of current func
For native calls must be NULL so we don't sync back
comment: XXX: assume these?
label: code-design
Then reuse the unwound activation; callstack was not shrunk so there is always space
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
step 11
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
Note: either pointer may be NULL (at entry), so don't assert
comment: XXX: unify handling with native call.
label: code-design
Lightfuncs are always native functions and have "newenv".
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
XXX: byte offset?
first call
may need unwind
* Helper for updating callee 'caller' property.
side effects
bound chain resolved
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
No need to re-lookup 'act' at present: no side effects.
formals for 'func' (may be NULL if func is a C function)
Normal non-bound function.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
should never happen for a strict callee
Backup 'caller' property and update its value.
* Valstack manipulation for results.
no need to handle thread state book-keeping here
out of spec, must be configurable
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
same as during entry
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
third arg: absolute index (to entire valstack) of idx_bottom of new activation
strict: non-deletable, non-writable
-> [ ... func this arg1 ... argN _Args length ]
1 = num actual 'return values'
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
current thread
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
Duktape/C API guaranteed entries (on top of args)
Success path.
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
bound function chain has already been resolved
base of known return values
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
step 11.c is relevant only if non-strict (checked in 11.c.ii)
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
Return value handling.
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
flags
Unwind the topmost callstack entry before reusing it
borrowed, no refcount
same thread
may be NULL
pop 'name'
Other longjmp types are handled by executor before propagating
* the error here.
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: duk_get_length?
label: code-design
side effects (currently none though)
[ ... formals arguments map mappedNames ]
# argument registers target function wants (< 0 => "as is")
For now all calls except Ecma-to-Ecma calls prevent a yield.
duk_hthread_callstack_unwind() will decrease this on unwind
[ ... formals ]
See: tests/ecmascript/test-spec-bound-constructor.js
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
* Init argument related properties
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
DUK_USE_ASSERTIONS
comment: XXX: inefficient; block remove primitive
label: code-design
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
Lightfuncs are always considered strict.
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
'act' already set above
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
lightfuncs are treated like objects and not coerced
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
* Make the C call
comment: XXX: rework
label: code-design
index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
comment: XXX: this should be an assert
label: test
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
[ ... | (crud) errobj ]
Start filling in the activation
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
assumed to bottom relative
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
[ ... func this <some bound args> arg1 ... argN _Args ]
really 'not applicable' anymore, should not be referenced after this
idx of first argument on stack
thr->ptr_curr_pc is set by bytecode executor early on entry
Chop extra retvals away / extend with undefined.
setjmp catchpoint setup
[ ... errobj ]
Longjmp state is kept clean in success path
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
final configuration
Automatic error throwing, retval check.
no need to decref previous value
Explicit check for fastint downgrade.
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
refer to callstack entries below current
Note: not a valid stack index if num_stack_args == 0
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
must be updated to work properly (e.g. creation of 'arguments')
write back
extend with undefined
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
should actually never happen, but check anyway
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
Use loop to minimize code size of relookup after bound function case
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
don't want an intermediate exposed state with invalid pc
catchstack limits
# total registers target function wants on entry (< 0 => never for ecma calls)
idx_argbase
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
don't want an intermediate exposed state with func == NULL
Error; error value is in heap->lj.value1.
* Store entry state.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
[ ... retval ]
no incref
may have side effects
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
NULL for lightfunc
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
Lightweight function: never bound, so terminate.
# argument registers target function wants (< 0 => never for ecma calls)
compiler ensures this
internal spare
already NULLed (by unwind)
* Misc shared helpers.
out of spec, don't care
[ ... func this arg1 ... argN envobj ]
+ spare
keep current valstack_top
XXX: optimize value stack operation
bottom of new func
can't happen when keeping current stack size
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
XXX: byte offset
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
topmost activation idx_retval is considered garbage, no need to init
[ args [crud] arguments ]
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
comment: XXX: some overlapping code; cleanup
label: code-design
must be signed for loop structure
[ ... func this <bound args> arg1 ... argN ]
vararg
no need to create environment record now; leave as NULL
[ ... arg1 ... argN ]
caller must check
set exotic behavior only after we're done
[ ... name ]
[ ... | (crud) ]
[ ... arg1 ... argN envobj ]
nothing to incref
Note: may be NULL if first call
num args starting from idx_argbase
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
valstack index of 'func' and retval (relative to entry valstack_bottom)
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
Restore entry thread executor curr_pc stack frame pointer.
idx_args = idx_func + 2
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
Success path handles
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
XXX: bump preventcount by one for the duration of this call?
stack discipline consistency check
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
See: test-bug-tailcall-preventyield-assert.c.
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
[ ... func this (crud) retval ]
XXX: assert? compiler is responsible for this never happening
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
* Shift to new valstack_bottom.
comment: XXX: unnecessary, handle in adjust
label: code-design
already updated
to avoid relookups
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
Note: either pointer may be NULL (at entry), so don't assert.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
[ ... func this arg1 ... argN ]
replace in stack
comment: XXX: check .caller writability?
label: code-design
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
duk_tval ptr for 'func' on stack (borrowed reference)
tail call -> reuse current "frame"
Unwind catchstack entries referring to the callstack entry we're reusing
local copy to avoid relookups
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
'arguments'
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
at least errobj must be on stack
comment: XXX: inefficient; block insert primitive
label: code-design
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
Unwind.
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
Error path.
comment: XXX: could be eliminated with valstack adjust
label: code-design
* Ecmascript call
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Argument validation and func/args offset.
# total registers target function wants on entry (< 0 => "as is")
cannot be strict (never mapped variables)
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
no compact
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
* Valstack spare check
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
'func' wants stack "as is"
* Init arguments properties, map, etc.
name
[ ... arg1 ... argN envobj argobj ]
act->func
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
idx_this = idx_func + 1
or a non-catching entry
comment: XXX: tv_func is not actually needed
label: requirement
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
different thread
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
step 12
[ ... name name ]
-> [ ... func this arg1 ... argN _Args ]
steps 13-14
no prototype
leave formals on stack for later use
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
* Native call.
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
duk_has_prop() popped the second 'name'
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
comment: XXX: block removal API primitive
label: code-design
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
only functions can have arguments
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
DUK_TOK_SNEQ
DUK_TOK_TRUE
* Variant 2
UnaryExpression
Buffer length is bounded to 0xffff automatically, avoid compile warning.
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
No need to assert, buffer size maximum is 0xffff.
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
inserted jump
curr_token follows 'function'
Output shuffle needed after main operation
DUK_TOK_TRY
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
push before advancing to keep reachable
DUK_TOK_GET
init function state: inits valstack allocations
for storing/restoring the varmap binding for catch variable
convenience helpers
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
omitted
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
-> pushes fixed buffer
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
Ensure compact use of temps.
default case exists: go there if no case matches
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
eat 'do'
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
-> [ ... name index ]
max # of values initialized in one MPUTARR set
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
e.g. DUK_OP_PREINCV
reuse 'res' as 'left'
Initial bytecode size allocation.
XXX: patch initial size afterwards?
yes, must set array length explicitly
in-place setup
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
binding power must be high enough to NOT allow comma expressions directly
flags
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
implicit_return_value
* Initialize function state for a zero-argument function
* Special name handling
eat 'for'
right associative
init 'curr_token'
allow a constant to be returned
DUK_TOK_LBRACKET
XXX: check num_args
DUK_TOK_LPAREN
directly uses slow accesses
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
DUK_TOK_LT
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
catch depth from current func
eat colon
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
[ ... pattern flags ]
* Init compiler and lexer contexts
DUK_TOK_NEQ
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
if num_values > 0, MPUTARR emitted by outer loop after break
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
DUK_USE_NONSTD_FUNC_STMT
DUK_TOK_STRING
stmt has non-empty value
for array and object literals
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-1 == not set, -2 == pending (next statement list)
Explicit check for fastint downgrade.
DUK_TOK_RETURN
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
* Detect iteration statements; if encountered, establish an
* empty label.
comment: Should never happen but avoid infinite loop just in case.
label: code-design
indirect opcode follows direct
statement parsing
* Function declarations
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
Valstack should suffice here, required on function valstack init
reg_res should be smallest possible
pushes function template
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
Identifier, i.e. don't allow reserved words
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
Slot B
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
XXX: to util
Specific assumptions for opcode numbering.
_Pc2line
EQUALITY EXPRESSION
register declarations in first pass
DUK_TOK_EQUALSIGN
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
useful for patching jumps later
name
-> [ ... func name ]
inherit initial strictness from parent
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
DUK_TOK_WHILE
Use special opcodes to load short strings
temp variable to pass constants and flags to shared code
truncated in case pass 3 needed
reg
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
DUK_TOK_MUL_EQ
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
DUK_TOK_DO
comment: XXX: match flag is awkward, rework
label: code-design
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Evaluate RHS only when LHS is safe.
DUK_TOK_VOID
DUK_USE_PC2LINE
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
no catchers
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
* Variant 4
* Preliminaries
is_extra
Slot A
terminates expression; e.g. post-increment/-decrement
* Parser duk__advance() token eating functions
inline string concatenation
no operators
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
Strict: never allow function declarations outside top level.
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
BITWISE EXPRESSIONS
Used for minimal 'const': initializer required.
DUK_TOK_CONST
DUK_TOK_RPAREN
Slot C
true
comma after a value, expected
general temp register
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
DUK_TOK_SUPER
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
DUK_TOK_NULL
step 4.a
Check whether statement list ends.
Setup state. Initial ivalue is 'undefined'.
DUK_TOK_STATIC
first coerce to a plain value
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
'res' contains expression value
invalidates tv1, tv2
rc_varname and reg_varbind are ignored here
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
reg(ignored)
bytecode limits
DUK_TOK_SEQ
XXX: clarify on when and where DUK__CONST_MARKER is allowed
bump up "allocated" reg count, just in case
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
DUK_TOK_INSTANCEOF
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
DUK_TOK_IF
evaluate to plain value, no forced register (temp/bound reg both ok)
JUMP L1 omitted
e.g. DUK_OP_POSTINCR
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
* Debug dumping
* The switch statement is pretty messy to compile.
* See the helper for details.
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
knock back "next temp" to this whenever possible
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Detected a directive
entry_top + 3
ASSIGNMENT EXPRESSION
if a site already exists, nop: max one label site per statement
first value: comma must not precede the value
DUK_TOK_CATCH
rethrow
key encountered as a plain property
e.g. DUK_OP_POSTINCV
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
sufficient for keeping temp reg numbers in check
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
pass2 allocation handles this
DUK_TOK_IN
jump to false
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
comment: XXX: duk_set_length
label: code-design
DUK_TOK_BOR_EQ
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
NB: must accept reserved words as property name
+1, right after inserted jump
* After arguments, allocate special registers (like shuffling temps)
* Variant 1
DUK_TOK_DEFAULT
temp reset is not necessary after duk__parse_stmt(), which already does it
same handling for identifiers and strings
e.g. DUK_OP_PREINCP
decl name
LOGICAL EXPRESSIONS
jump is inserted here
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
const flag for C
unary minus
number of pairs in current MPUTOBJ set
Tear down state.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
expression parsing helpers
[ ... key_obj key ]
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
one token
DUK_TOK_BNOT
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
comment: alloc temp just in case, to update max temp
label: code-design
is_setget
DUK_TOK_COMMA
Shuffle decision not changed.
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
temp_start+0 = key, temp_start+1 = closure
forced_reg
DUK_TOK_FINALLY
'data' (and everything in it) is reachable through h_res now
arg2 would be clobbered so reassign it to a temp.
DUK_TOK_REGEXP
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
DUK_TOK_PACKAGE
* Peephole optimize JUMP chains.
temps
to body
no match, next case
* Directive prologue tracking.
DUK_TOK_IDENTIFIER
* Misc helpers
finished jump
POSTFIX EXPRESSION
base
DUK_TOK_PUBLIC
variable name reg/const, if variable not register-bound
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
NEXTENUM jump slot: executed when enum finished
single string token
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
DUK_TOK_ARSHIFT
eat the right paren
comment: XXX: possibly incorrect handling of empty expression
label: code-design
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
is_decl
unsigned
Expression, ']' terminates
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
no need to coerce
func limits
'res' is used for "left", and 'tmp' for "right"
[ ... template ]
end switch (tok)
XXX: shared handling for 'duk__expr_lhs'?
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
num_values and temp_start reset at top of outer loop
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
allow_source_elem
duplicate/invalid key checks; returns 1 if syntax error
eat 'in'
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
* Detected label
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
DUK_TOK_SUB
Default implicit return value.
elision - flush
temp reg for key literal
* Parse a case or default clause.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
DUK_TOK_THIS
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
max # of key-value pairs initialized in one MPUTOBJ set
expect_token
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
>>
trailing elisions?
unary plus of a number is identity
no comma
advance to get one step of lookup
right paren eaten
MPUTARR emitted by outer loop
DUK_TOK_NUMBER
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
jump for 'finally' case or end (if no finally)
* Identifier handling
DUK_TOK_SET
Code is not accepted before the first case/default clause
Note: 'q_instr' is still used below
start array index of current MPUTARR set
expect_eof
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
rbp_flags
use 'left' as a temp
don't allow const
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
DUK_TOK_BAND
if highest bit of a register number is set, it refers to a constant instead
no need to reset temps, as we're finished emitting code
-> [ ... ]
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
Expression_opt
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
still in prologue
DUK_TOK_DIV_EQ
* Arguments check
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
bc
parse new token
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
numargs
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
DUK_TOK_ELSE
nret
See MPUTOBJ comments above.
preincrement and predecrement
Need a short reg/const, does not have to be a mutable temp.
Expression, terminates at a ')'
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
DUK_TOK_DEBUGGER
patched later
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
comment: XXX: depend on available temps?
label: code-design
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
last array index explicitly initialized, +1
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
MPUTOBJ emitted by outer loop
MultiplicativeExpression
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
need side effects, not value
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
allow automatic semicolon even without lineterm (compatibility)
binding power "levels" (see doc/compiler.rst)
* Cleanup: restore original function, restore valstack state.
DUK_TOK_QUESTION
comment: XXX: macro smaller than call?
label: code-design
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
result reg
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
eat comma
comment: XXX: source code property
label: code-design
this is needed for regexp mode
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
[ ... varname ]
preinitialize lexer state partially
jump to next case clause
const
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
eat 'if'
key encountered as a getter
comment: XXX: macros
label: code-design
must have catch and/or finally
DUK_TOK_GT
'new' MemberExpression
DUK_TOK_BXOR
* Store lexer position for a later rewind
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
DUK_TOK_DECREMENT
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
require a (mutable) temporary as a result (or a const if allowed)
DUK_OP_NONE marks a 'plain' assignment
keep in on valstack, use borrowed ref below
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
res.x1 -> res.x2
number of values in current MPUTARR set
<<
to exit
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
Parse formals.
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
getter/setter
false
register bound variables are non-configurable -> always false
nargs
XXX: init or assert catch depth etc -- all values
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
copy bytecode instructions one at a time
LHS is already side effect free
* Variant 3
DUK_TOK_IMPORT
XXX: range assert
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
* On second pass, skip the function.
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
token closes expression, e.g. ')', ']'
fileName
chain jumps for case
* evaluation and checking
needed for line number tracking (becomes prev_token.start_line)
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
function call
DUK_TOK_MUL
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
const limits
don't coerce yet to a plain value (variant 3 needs special handling)
The issues below can be solved with better flags
[ ... res ]
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
continue jump
LeftHandSideExpression does not allow empty expression
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
First evaluate LHS fully to ensure all side effects are out.
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
allow source elements
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
eat 'function'
one token before
keep in valstack
Limit checks for bytecode byte size and line number.
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
normal key/value
Note: escaped characters differentiate directives
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
reject 'in' token (used for for-in)
Note: 0xff != DUK_BC_B_MAX
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
special RegExp literal handling after IdentifierName
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
statement is guaranteed to be terminal (control doesn't flow to next statement)
fall-through jump to next code of next case (backpatched)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
directive prologue status at entry
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
* Variant 1 or 3
temp object for tracking / detecting duplicate keys
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
DUK_TOK_SEMICOLON
DUK_TOK_RSHIFT
* Size-optimized pc->line mapping.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
DUK_TOK_EQ
code emission
strict mode restrictions (E5 Section 12.2.1)
result in csreg
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
top-down expression parser
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
E5 Section steps 7-8
comment: XXX: unoptimal use of temps, resetting
label: code-design
Any 'res' will do.
is_decl
varmap is already in comp_ctx->curr_func.varmap_idx
DUK_TOK_SWITCH
eat 'try'
b
Note: 0xff != DUK_BC_C_MAX
_Source
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
COMMA
Parse statements until a closing token (EOF or '}') is found.
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
The token in the switch has already been eaten here
DUK_TOK_LAND
currently all labels accept a break, so no explicit check for it now
DUK_TOK_NEW
force_no_namebind
DUK_TOK_RBRACKET
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
statement does not terminate directive prologue
SHIFT EXPRESSION
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
DUK_TOK_LOR
comment: XXX: specific getter
label: code-design
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
intentional overlap with earlier memzero
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
chain jumps for 'fall-through'
* after a case matches.
assumed to also be PC of "LABEL"
* Main switch for statement / source element type.
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
DUK_TOK_DELETE
DUK_TOK_BOR
DUK_TOK_CASE
DUK_TOK_ADD_EQ
comment: XXX: optimize temp reg use
label: code-design
* Compact the function template.
>>>
PRIMARY EXPRESSIONS
left.x1 -> res.x1
num_args
DUK_TOK_ADD
always terminates led()
allocate to reg only (not const)
skip jump conditionally
prevent duk__expr_led() by using a binding power less than anything valid
default clause matches next statement list (if any)
filter out flags from exprtop rbp_flags here to save space
eat 'return'
* Parse a function body or a function-like expression, depending
* on flags.
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
FUNCTION EXPRESSIONS
MULTIPLICATIVE EXPRESSION
may be a string constant
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
entry_top + 1
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
UNARY EXPRESSIONS
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
a statement following a label cannot be a source element
* (a function declaration).
Note: Identifier rejects reserved words
[ ... filename (temps) func ]
DUK_TOK_EOF
temp reg
* Second pass parsing.
spare
tmp -> res
DUK_TOK_LCURLY
DUK_TOK_BREAK
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
DUK_TOK_MOD_EQ
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
DUK_TOK_WITH
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
DUK_TOK_PERIOD
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
'res' must be a plain ivalue, and not register-bound variable.
not present
ADDITIVE EXPRESSION
function helpers
default case does not exist, or no statements present
* after default case: finish case evaluation
expected ival
use temp_next for tracking register allocations
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
comment: may indirectly slow access through a direct eval
label: code-design
Update all labels with matching label_id.
<
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
variable binding register if register-bound (otherwise < 0)
key
comment: XXX: to be implemented?
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
just in case
entry_top + 4
key encountered as a setter
continue jump not patched, an INVALID opcode remains there
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
comment: unused
label: code-design
current (next) array index
* Push result object and init its flags
step 4.d
duk_hobject_set_length_zero(thr, func->h_funcs);
register binding lookup is based on varmap (even in first pass)
empty statement with an explicit semicolon
one operator (= assign)
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
see above
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
[ ... name reg/null ] -> [ ... ]
no need to init reg, it will be undefined on entry
must restore reliably before returning
DUK_TOK_THROW
Just flip the single bit.
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
break jump
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
[ ... key_obj key key ]
allow empty expression
expect_eof
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
label handling
DUK_TOK_SUB_EQ
Expression
allow negative PCs, behave as a no-op
Important main primitive.
ivalue/ispec helpers
DUK_TOK_BXOR_EQ
code_idx = entry_top + 0
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
name
c
E5 Section 11.13.1 (and others for other assignments), step 4.
DUK_TOK_CONTINUE
eat 'throw'
DUK_TOK_CLASS
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
comment: XXX: spare handling, slow now
label: code-design
comma check
pop varname
* Parse function body
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
the outer loop will recheck and exit
allow caller to give a const number with the DUK__CONST_MARKER
varname
jump to end
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
basereg
a
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
* Default clause.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
DUK_USE_REGEXP_SUPPORT
CONDITIONAL EXPRESSION
break/continue without label
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
jump for 'catch' case
comment: XXX: append primitive
label: code-design
[ ... name reg_bind ]
e.g. DUK_OP_PREINCR
eat 'while'
try part
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
next loop requires a comma
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
get const for value at valstack top
eat 'break' or 'continue'
DUK_TOK_TYPEOF
* Parse inner function
comment: unused
label: code-design
No BC shuffling now.
number
syntactically left-associative but parsed as right-associative
reserve a jumpslot after instr before target spilling, used for NEXTENUM
* Wrap up
at least one opcode emitted
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
relookup after possible realloc
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
regexp literal must not follow this token
-> [ ... func ]
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
slot B is a target (default: source)
without finally, the second jump slot is used to jump to end of stmt
forget temp
[ ... filename &comp_stk ]
break/continue with label (label cannot be a reserved word, production is 'Identifier'
Have a catch variable.
* Intermediate value helpers
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
reset function state (prepare for pass 2)
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
DUK_TOK_EXPORT
entry_top + 0
* Variant 2 or 4
[ ... escaped_source bytecode ]
return 'res' (of right part) as our result
jump from true part to end
comment: XXX: spilling
label: code-design
eat identifier
x1 must be a string
break matches always
dangerous: must only lower (temp_max not updated)
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
format is bit packed
DUK_TOK_LBRACKET already eaten, current token is right after that
parse args starting from "next temp", reg_target + 1
is_setget
enable manually for dumping
shadowed, ignore
DUK_TOK_COLON
DUK_TOK_IMPLEMENTS
jump to end or else part
for side effects, result ignored
for duk_error_augment.c
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
non-Reference deletion is always 'true', even in strict mode
no statement value (unlike function expression)
jump to next loop, using reg_v34_iter as iterated value
DUK_USE_TAILCALL
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
* Convert duk_compiler_func to a function template
final result is already in 'res'
-> loop body
catch jump
num_pairs and temp_start reset at top of outer loop
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
* Wrapping duk_safe_call() will mangle the stack, just return stack top
pc_label
slot A is a source (default: target)
assume 'var' has been eaten
old value is number: no refcount
empty expressions can be detected conveniently with nud/led counts
DUK_TOK_ALSHIFT_EQ
label limits
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
DUK_TOK_GE
DUK_TOK_LET
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
else an array initializer element
tracks maximum initialized index + 1
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
object literal key tracking flags
reset 'allow_in' for parenthesized expression
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
parse args starting from "next temp"
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
lexing
Main operation
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
initial index
'new' MemberExpression Arguments
stmt has explicit/implicit semicolon terminator
op_flags
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
DUK_TOK_FUNCTION
array writes autoincrement length
* Prototypes
main expression parser function
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
statements go here (if any) on next loop
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
silence scan-build warning
varname is popped by above code
always allow 'in', coerce to 'tr' just in case
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
DUK_TOK_YIELD
DUK_TOK_LNOT
slot C is a target (default: source)
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
end switch
DUK_TOK_LE
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
XXX: similar coercion issue as in DUK_TOK_PERIOD
borrowed reference
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
bp to use when parsing a top level Expression
Matches both +0 and -0 on purpose.
bp is assumed to be even
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
transfer flags
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
eat 'var'
DUK_TOK_INTERFACE
DUK_TOK_DIV
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
iteration statements allow continue
reg/const for switch value
unary plus
may be undefined
reg/const for case value
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
DUK_TOK_PRIVATE
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
then to a register
expect EOF instead of }
DUK_TOK_ARSHIFT_EQ
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
no code needs to be emitted, the regs already have values
DUK_TOK_RCURLY
fills window
DUK_TOK_BAND_EQ
jump is inserted here (variant 3)
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't allow continue
valstack will be unbalanced, which is OK
== DUK__MAX_TEMPS is OK
DUK_TOK_EXTENDS
[ ... varmap ]
inline arithmetic check for constant values
identifier handling
* Helpers for duk_compiler_func.
DUK_TOK_RSHIFT_EQ
step 4.b
explicit semi follows
shadowed; update value
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
advance, whatever the current token is; parse next token in regexp context
DUK_TOK_PROTECTED
curr_token = get/set name
target
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
expr_flags
Note: expect that caller has already eaten the left paren
advance, expecting current token to be a specific token; parse next token in regexp context
already in correct reg
RELATIONAL EXPRESSION
* Source filename (or equivalent), for identifying thrown errors.
e.g. DUK_OP_POSTINCP
preallocated temporaries (2) for variants 3 and 4
emit instruction; could return PC but that's not needed in the majority
* of cases.
DUK_TOK_ALSHIFT
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
trailing comma followed by rcurly
eat 'with'
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
step 4.c
[ ... key_obj key val ]
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
DUK_TOK_INCREMENT
const flag for B
keep func->h_argnames; it is fixed for all passes
misc
source is a function expression (used for Function constructor)
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
parsing in "directive prologue", recognize directives
value stack indices for tracking objects
DUK_ISPEC_XXX
comment: code emission temporary
label: code-design
maximum bytecode length in instructions
bufwriter for code
C array of duk_labelinfo
Compiling state of one function, eventually converted to duk_hcompiledfunction
with stack depth (affects identifier lookups)
variable map for pass 2 (identifier -> register number or null (unmapped))
curr_token slot1 (matches 'lex' slot1_idx)
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
type to represent a reg/const reference during compilation
function is strict
* Ecmascript compiler.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
bytecode opcode (or extraop) for binary ops
current and previous token for parsing
comment: function name (borrowed reference), ends up in _name
label: code-design
lexing (tokenization) state (contains two valstack slot indices)
property access
array of active label names
is eval code
1e8: protects against deeply nested inner functions
source is eval code (not global)
comment: function must not be tail called
label: code-design
comment: code_idx: not needed
label: requirement
no value
inner function numbering
always set; points to a reserved valstack slot
expression is left-hand-side compatible
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
highest value of temp_reg (temp_max - 1 is highest used reg)
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* Compiler state
argument/function declaration shadows 'arguments'
is a function declaration (as opposed to function expression)
variable access
function needs shuffle registers
borrowed label name
is global code
strict outer context
filename being compiled (ends up in functions' '_filename' property)
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
function may call direct eval
catch depth at point of definition
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
comment: XXX: optimize to 16 bytes
label: code-design
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
function refers to 'arguments' identifier
comment: first register that is a temporary (below: variables)
label: code-design
catch stack depth
maximum loopcount for peephole optimization
value resides in 'valstack_idx'
value resides in a register or constant
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
label id allocation (running counter)
1 GB
current function being compiled (embedded instead of pointer for more compact access)
stats for current expression being parsed
* Prototypes
DUK_IVAL_XXX
comment: function makes one or more slow path accesses
label: code-design
is an actual function (not global/eval code)
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
is a setter/getter
ecmascript compiler limits
curr_token slot2 (matches 'lex' slot2_idx)
borrowed reference
type to represent a straight register reference, with <0 indicating none
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
next temporary register to allocate
parsing in "scanning" phase (first pass)
shuffle registers if large number of regs/consts
array
array of formal argument names (-> _Formals)
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
prev_token slot2
DUK_JS_COMPILER_H_INCLUDED
status booleans
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
current paren level allows 'in' token
numeric label_id (-1 reserved as marker)
prev_token slot1
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
statement id allocation (running counter)
recursion limit
parenthesis count, 0 = top level
number of formal arguments
register, constant, or value
temp reg handling
h_code: held in bw_code
* Fast paths
comment: 'd3' is never NaN, so no need to normalize
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
return value from Duktape.Thread.resume()
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
-> [... val this]
Preinc/predec for object properties.
Assume that thr->valstack_bottom has been set-up before getting here.
Sync and NULL early.
* E5 Section 11.4.9
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
an Ecmascript function
comment: XXX: improve check; check against nregs, not against top
label: code-design
-> [ ... regexp_instance ]
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
x >= y --> not (x < y)
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
Unary plus is used to force a fastint check, so must include
* downgrade check.
Duktape.Thread.yield() should prevent
comment: should never happen, but be robust
label: code-design
[ ... enum ] -> [ ... ]
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
side effects -> don't use tv_x, tv_y after
flags
Relookup and initialize dispatch loop variables. Debugger check.
never here
add_auto_proto
don't re-enter e.g. during Eval
-> [... obj key value]
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
may be < thr->catchstack initially
Longjmp handling has restored jmpbuf_ptr.
valstack top, should match before interpreting each op (no leftovers)
Entry level info.
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
XXX: assert 'c' is an enumerator
-> [val]
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
comment: XXX: refactor out?
label: code-design
[ ... env ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
cleared before entering catch part
-> [... obj]
no need to unwind catchstack
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
thr->heap->lj.value1 is already the value to throw
if boolean matches A, skip next inst
Preinc/predec for var-by-name, slow path.
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
bytecode has a stable pointer
cleared before entering finally
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
Overflow of the execution counter is fine and doesn't break
* anything here.
Restart bytecode execution, possibly with a changed thread.
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
no need for refcount update
reg count
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
* Slow path: potentially requires function calls for coercion
-> [ Object defineProperty undefined obj key desc ]
DUK_USE_FASTINT
ToNumber() for a fastint is a no-op.
B -> object register
* C -> C+0 contains key, C+1 closure (value)
x < y
call_flags
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
* Local declarations.
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
x > y --> y < x
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
curr_pc synced by duk_handle_ecma_call_setup()
resumee: [... initial_func] (currently actually: [initial_func])
comment: XXX: use duk_is_valid_index() instead?
label: code-design
-> [... obj value]
always normalized
DUK_USE_INTERRUPT_COUNTER
comment: writable, not configurable
label: code-design
written by a previous RESUME handling
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
comment: this is not strictly necessary, but helps debugging
label: code-design
this should never be possible, because the switch-case is
* comprehensive
Pre/post inc/dec for register variables, important for loops.
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
w/o refcounts
fast path
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
stable; precalculated for faster lookups
comment: 'val' is never NaN, so no need to normalize
label: code-design
may be reg or const
+2 = catcher value, catcher lj_type
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
[... obj] -> [...]
Already declared, update value.
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
should not happen
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
[... constructor arg1 ... argN] -> [retval]
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
B -> target register
* C -> constant index of identifier name
* Execution timeout check
side effects
E5 Section 11.7.2, steps 7 and 8
updates thread state, minimizes its allocations
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
use_prev_pc
Must restart in all cases because we NULLed thr->ptr_curr_pc.
checked by Duktape.Thread.resume()
unsigned
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
E5 Section 11.2.3, step 6.a.i
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
lj.value1 is already set
Dispatch loop.
fall through if overflow etc
this may have side effects, so re-lookup act
Assume interrupt init/counter are properly initialized here.
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
allocate catcher and populate it (should be atomic)
E5 Section 11.7.1, steps 7 and 8
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
INACTIVE: no activation, single function value on valstack
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
enum_flags
E5 Sections 11.9.1, 11.9.3
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
Force pause if we were doing "step into" in another activation.
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
already set
[ ... val ] --> [ ... enum ]
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
Note: 'this' may be bound to any value, not just an object
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
+ spare
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
must "goto restart_execution", e.g. breakpoints changed
Share yield longjmp handler.
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
no need to unwind callstack
unwind to 'yield' caller
'this binding' is just under bottom
stable
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
Duktape.Thread.resume()
+0 = break, +1 = continue
Outer executor with setjmp/longjmp handling.
if debugging disabled
E5 Section 10.4.3
does not modify tv_x
[ ... func this arg1 ... argN ]
Cause an interrupt after executing one instruction.
side effects, perform in-place
'act' is no longer accessed, scanbuild fix
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
reg
no compact
restricted to regs
exit bytecode executor by rethrowing an error to caller
comment: XXX: side effect handling is quite awkward here
label: code-design
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
Call setup checks callability.
exit bytecode execution with return value
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
Write curr_pc back for the debugger.
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
no refcount changes
'null' enumerator case -> behave as with an empty enumerator
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment: XXX: could use at least one fewer loop counters
label: code-design
A -> flags
* B -> return value reg/const
* C -> currently unused
Note: left shift, should mask
Ecmascript function
curr_pc synced back above
relookup (side effects)
GH-303
return value from Duktape.Thread.yield()
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
unsigned shift
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
comment: Inner executor, performance critical.
label: code-design
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
x
lj.value1 already set
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
at least one activation, ours
XXX: assert idx_base
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
* Breakpoint and step state checks
[ ... env target target ]
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
overflow, fall through
restored if ecma-to-ecma setup fails
type
reset longjmp
comment: pseudotypes, not used in actual longjmps
label: code-design
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
A -> target reg
* BC -> inner function index
resumee
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
Fast path for the case where the register
* is a number (e.g. loop counter).
* Ecmascript bytecode executor.
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
comment: 'this' binding is not needed here
label: requirement
DUK_USE_EXEC_TIMEOUT_CHECK
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
entry level reached
get_value
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
signed shift
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
ensures callstack_top - 1 >= 0
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
variable value (function, we hope, not checked here)
x <= y --> not (x > y) --> not (y < x)
mandatory if du.d is a NaN
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
comment: not needed
label: requirement
comment: 'fun' is quite rarely used, so no local for it
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
idx_retval unsigned
DUK_USE_DEBUGGER_SUPPORT
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
'with' target must be created first, in case we run out of memory
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
not needed, as we exit right away
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
relookup, may have changed
comment: unused for label
label: code-design
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
relookup if changed
Shouldn't happen but check anyway.
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
-> [ ... escaped_source bytecode ]
result
not protected, respect reclimit, not constructor
[ ... env target ]
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
ignore
special result value handling
skip jump slots
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
We can directly access value stack here.
Set up curr_pc for opcode dispatch.
val
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: unused
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
Ecmascript activation + Duktape.Thread.resume() activation
always in executor
reachable through activation
thr->heap->lj.value2 is 'thread', will be wiped out at the end
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
important to use normalized NaN with 8-byte tagged types
+0 = catch
get before side effects
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
* E5 Section 11.4.8
always provideThis=true
duk_small_uint_fast_t c = DUK_DEC_C(ins);
comment: XXX: fastint fast path would be very useful here
label: code-design
no specific action, resume normal execution
Execute bytecode until returned or longjmp().
Relookup if relocated
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
num_stack_args
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
is resume, not a tail call
avoid referencing, invalidated
+1 = one retval
B -> target register for next key
* C -> enum register
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
cat_idx catcher is kept, even for finally
XXX: switch cast?
keep label catcher
state updated, restart bytecode execution
Must be restored here to handle e.g. yields properly.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
ToNumber() for a double is a no-op.
[ ... enum ] -> [ ... next_key ]
leave 'cat' as top catcher (also works if catchstack exhausted)
XXX: direct manipulation, or duk_replace_tval()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
terminate
unchanged by Duktape.Thread.resume()
unchanged from Duktape.Thread.yield()
A -> result reg
* B -> object reg
* C -> key reg/const
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
invalidated
[ ... val obj ]
env created above to stack top
-> [ Object res ]
Trigger at zero or below
'this' binding
end switch
Successful return: restore jmpbuf and return to caller.
resume caller must be an ecmascript func
y
'with' binding has no catch clause, so can't be here unless a normal try-catch
caller must change active thread, and set thr->resumer to NULL
unresolvable, no stack changes
[... s1 s2] -> [... s1+s2]
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
Recompute argument count: bound function handling may have shifted.
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
no prototype, updated below
unwind to 'resume' caller
guarantees entry_callstack_top - 1 >= 0
may be changed
Rethrow error to calling state.
* Update the interrupt counter
Stepped? Step out is handled by callstack unwind.
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
relookup after side effects (no side effects currently however)
resumee: [... initial_func undefined(= this) resume_value ]
must relookup act in case of side effects
fastint downgrade check for return values
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
pre-incremented, points to first jump slot
nop
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
In-place unary operation.
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
Thread may have changed, e.g. YIELD converted to THROW.
Already declared but no initializer value
* (e.g. 'var xyz;'), no-op.
throw
unreferenced without assertions
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
[-0x80000000,0x7fffffff]
Catches both doubles and cases where only one argument is a fastint
x == -Infinity
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
heap pointer comparison suffices
E5 Section 9.3.1
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
truncate towards zero
func support for [[HasInstance]] checked in the beginning of the loop
prefix matches, lengths matter now
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
mimic semantics for strings
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
implementation specific
x == +Infinity
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
-> x in ]-2**32, 2**32[
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
exposed, used by e.g. duk_bi_date.c
Buffer/string -> compare contents.
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
Handle lightfuncs through object coercion for now.
comment: unused
label: code-design
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
Fast path for numbers (one of which may be a fastint)
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
number
radix
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: direct implementation
label: requirement
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
* ToInteger() (E5 Section 9.4)
invalidates tv
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
never here
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
y == +Infinity
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
comment: Note: reuse variables
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
equals and strict equals
non-strict equality for buffers compares contents
+(function(){}) -> NaN
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
Called by duk_hstring.h macros
Careful overflow handling. When multiplying by 10:
* - 0x19999998 x 10 = 0xfffffff0: no overflow, and adding
* 0...9 is safe.
* - 0x19999999 x 10 = 0xfffffffa: no overflow, adding
* 0...5 is safe, 6...9 overflows.
* - 0x1999999a x 10 = 0x100000004: always overflow.
non-strict equality from here on
+0.0
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
-> [ ... lval new_rval ]
Using classification has smaller footprint than direct comparison.
coerce lval with ToString()
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
* ToBoolean() (E5 Section 9.2)
follow prototype chain
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
combined algorithm matching E5 Sections 9.5 and 9.6
comment: XXX: this is possible without resorting to the value stack
label: code-design
Similar to String comparison.
Slow path
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
comment: 'tv' becomes invalid
label: code-design
y == -Infinity
Always overflow.
buffer values are coerced first to string here
DUK_USE_FASTINT
-> x in [-2**31,2**31[
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
-> [ ... lval rval new_rval ]
* instanceof
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
[ ... lval rval ]
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
range
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
DUK_USE_PARANOID_MATH
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
-> x in [0, 2**32[
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
[0x00000000, 0xffffffff]
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
comment: Note: not a typo, "object" is returned for a null value
label: documentation
comment: XXX: fastint
label: code-design
should be a safe way to compute this
x in [2**31, 2**32[
Note: this must match ToObject() behavior
Coerce like boolean
e.g. "x" < "xx"
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
'lt is true'
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
SameValue
Nothing worked -> not equal.
-> [ ... lval rval ]
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
the next 'if' is guaranteed to match after swap
flags:nonstrict
[ ... lval rval(func) ]
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
Fast path for fastints
comment: return a specific NaN (although not strictly necessary)
label: code-design
whole, won't clip
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
* in
-> [ ... lval rval rval.prototype ]
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
apparently no hint?
-> [ ... closure template newobj closure ]
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
func is NULL for lightfuncs
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
formal arg limits
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
[ ... closure template ]
[ ... closure template env ]
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
[holder name val] -> [holder]
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
* Finish
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
lookup name from an open declarative record's registers
env and act may be NULL
[... env callee]
registers are mutable, non-deletable
side effects
-> [ ... closure template newobj ]
* Local result type for duk__get_identifier_reference() lookup.
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
[... env callee varmap key val]
-> [ ... closure template ]
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
must be found: was found earlier, and cannot be inherited
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
[ ... closure ]
[... env]
[this value] -> [value this]
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
non-standard
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
always for register bindings
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
can't get value, may be accessor
unsigned
writable but not deletable
may be NULL
assertions: env must be closed in the same thread as where it runs
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
1 -> needs a PUTVAR
just check 'env'
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
global object doesn't have array part
* Define new property
*
* Note: this may fail if the holder is not extensible.
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
lookup name from current activation record's functions' registers
already closed
-> [ ... closure template env ]
follow parent chain
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
required if NAMEBINDING set
[ ... closure template formals ]
env[funcname] = closure
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
regnum is sane
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
* Lookup variable and update in-place if found.
-> [ ... closure template env funcname ]
[ ... closure template val ]
comment: order: most frequent to least frequent
label: code-design
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
XXX: incref by count (here 2 times)
* Not found (in registers or record objects). Declare
* to current variable environment.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
implicit this value always undefined for
* declarative environment records.
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
* Not found (even in global object)
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
assume plain values
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
* Some assertions (E5 Section 13.2).
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
ref.value and ref.this_binding invalidated here
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment: XXX: use helper for size optimization
label: code-design
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
[ ... closure template undefined ]
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
ref.value, ref.this.binding invalidated here by getprop call
lookup results is ignored
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
[... env callee varmap]
env is closed, should be missing _Callee, _Thread, _Regbase
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
ref.holder is global object, holder is the object with the
* conflicting property.
* Get holder object
for object-bound identifiers
DUK_HOBJECT_FLAG_NEWENV: handled below
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
comment: unused
label: code-design
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
* Delayed env creation check
* Delayed initialization only occurs for 'NEWENV' functions.
no prototype, updated below
[ ... closure template len_value ]
[this value]
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
comment: XXX: slightly awkward
label: code-design
implicit this value always undefined for
* declarative environment records.
property attributes for identifier (relevant if value != NULL)
0 = no throw
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
compact the prototype
assume keys are compacted
* Try registers
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
for register-bound and declarative env identifiers
[ ... closure template name ]
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
bound functions are never in act 'func'
comment: XXX: copy flags using a mask
label: code-design
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
comment: XXX: more accurate?
label: code-design
irrelevant when out->value == NULL
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Note: not set in template (has no "prototype")
-> [ ... closure template env funcname closure ]
assume value is a number
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
if property already exists, overwrites silently
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
parent env is the prototype
open scope information, for compiled functions only
shared helper
explicit PropertyList
How large a loop detection stack to use
gap (if empty string, NULL)
* Defines for JSON, especially duk_bi_json.c.
How much stack to require on entry to object/array decode
indexed by recursion_depth
type bit mask: types which certainly produce 'undefined'
escape any non-ASCII characters
Encoding/decoding flags
extended types: compatible encoding
extended types: custom encoding
Encoding state. Heap object references are all borrowed.
valstack index of loop detection object
avoid key quotes when key is an ASCII Identifier
DUK_JSON_H_INCLUDED
replacer function
How much stack to require on entry to object/array encode
output bufwriter
'='
Store lexer position, restoring if quantifier is invalid.
* Set lexer input position and reinitialize lookup window.
')'
'-' verbatim
One digit octal escape, digit validated.
(
DUK_USE_REGEXP_SUPPORT
escaped NonEscapeCharacter
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mark range 'direct', bypass canonicalization (see Wiki)
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
"/=" and not in regexp mode
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'('
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
Fast path.
'/'
LF line terminator; CR LF and Unicode lineterms are handled in slow path
line tracking
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
val1 = count
'{'
0xxx xxxx -> fast path
radix
having this as a separate function provided a size benefit
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
second, parse flags
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
dash is already 0
* Various defines and file specific helper macros
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
'?'
re-lookup first char on first loop
'\''
state == 3
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
','
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
no point in supporting encodings of 5 or more bytes
line continuation
Use temporaries and update lex_ctx only when finished.
'|'
check that byte has the form 10xx xxxx
lookup for 0x000a above assumes shortest encoding now
unsigned
form: { DecimalDigits , }, val1 = min count
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
note: long live range
1110 xxxx 10xx xxxx 10xx xxxx
110x xxxx 10xx xxxx
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
re-lookup curr char on first round
NB: duk_lexer_getpoint() is a macro only
lexer character window helpers
eat closing quote
avoid multiply
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
got lineterm preceding non-whitespace, non-lineterm token
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
comment: XXX: shared parsing?
label: code-design
CR LF again a special case
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
Track number of escapes: necessary for proper keyword
* detection.
(?=
re-read to avoid spill / fetch
Note: decimal number may start with a period, but must be followed by a digit
(?:
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Three digit octal escape, digits validated.
validation performed by duk__hexval
validation of the regexp is caller's responsibility
character represents itself
'~'
'['
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
'%'
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
eat closing slash
not strictly necessary because of lookahead '}' above
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
'+'
default: char escape (two chars)
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
adv = 2 default OK
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
fill window
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
'<'
10xx xxxx -> invalid
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
out_token->lineterm set by caller
(?!
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
E5 Section 15.10.2.11
Keep current size
0=base, 1=esc, 2=class, 3=class+esc
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
XXX: potential issue with signed pointers, p_end < p.
lookup shorthands (note: assume context variable is named 'lex_ctx')
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
numeric value of a hex digit (also covers octal and decimal digits)
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
';'
"/" and not in regexp mode
* Lexing helpers
EOF
whether to use macros or helper function depends on call count
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Production allows 'DecimalDigits', including leading zeroes
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
'*'
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
']'
comment: XXX: better coercion
label: code-design
'!'
check final character validity
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
* Init lexer context
Here 'x' is a Unicode codepoint
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
'>'
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
PatternCharacter, all excluded characters are matched by cases above
skip opening slash on first loop
Reuse buffer as is unless buffer has grown large.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
Note: duk_uint8_t type yields larger code
DUK_USE_LEXER_SLIDING_WINDOW
'-' as a range indicator
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
not LS/PS
'"'
Slow path.
No other escape beginning with a digit in strict mode
invalid codepoint encoding or codepoint
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
'&'
comment: packed advance/token number macro used by multiple functions
label: code-design
fast paths for space and tab
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
clipped codepoint
fall through to error
* Shared exit path
val2 = min count, val1 = max count
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
line terminator will be handled on next round
part of string
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
':'
'^'
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
eat backslash on entry
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
IdentityEscape
could also just pop?
'.'
adv = 2 - 1 default OK
eat '{' on entry
Zero 'count' is also allowed to make call sites easier.
Note: 'e' and 'E' are also accepted here.
Zero escape (also allowed in non-strict mode)
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: not necessary to init, disabled for faster parsing
label: code-design
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
unreachable
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
switch
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
free some memory
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
marker: copy t if not changed
eat opening quote on first loop
'-'
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
input offset tracking
Constants for duk_lexer_ctx.buf.
token type (with reserved word identification)
valstack slot for 2nd token value
Lexer context. Same context is used for Ecmascript and Regexp parsing.
identifier names (E5 Section 7.6)
token was preceded by a lineterm
token type (with reserved words as DUK_TOK_IDENTIFER)
number of tokens parsed
Regexp tokens
Sanity checks for string and token defines
A regexp token value.
number of escapes and line continuations (for directive prologue)
* Lexer defines.
Lexer codepoint with additional info like offset/line number
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
input linenumber at input_offset (not window[0]), init to 1
DUK_USE_REGEXP_SUPPORT
returned after EOF (infinite amount)
unicode code points, window[0] is always next, points to 'buffer'
bufwriter for temp accumulation
input offset for window leading edge (not window[0])
Convert heap string index to a token (reserved words)
token allows automatic semicolon insertion (eof or preceded by newline)
named "arithmetic" because result is signed
start byte offset of token in lexer input
A structure for 'snapshotting' a point for rewinding
temp accumulation buffer
* Prototypes
reserved words: additional future reserved words in strict mode
valstack slot for 1st token value
numeric value of token
exclusive
reserved words: keywords
string 1 of token (borrowed, stored to ctx->slot1_idx)
reserved words: future reserved words
input byte length
unicode code points, window[0] is always next
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
DUK_LEXER_H_INCLUDED
valstack slot for temp buffer
currently 6 characters of lookup are actually needed (duk_lexer.c)
token type
numeric value (character, count)
punctuators (unlike the spec, also includes "/" and "/=")
inclusive
maximum token count before error (sanity backstop)
start line of token (first char)
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
input string (may be a user pointer)
Sanity check
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
string 2 of token (borrowed, stored to ctx->slot2_idx)
thread; minimizes argument passing
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
need to normalize, may even cancel to 0
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
DUK_USE_64BIT_OPS
zero handled by caller
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
borrow literal Infinity from builtin string
d <- (quotient (* r B) s) (in range 0...B-1)
exponential notation forced
mp <- b^(e+1)
input radix
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
0 or -1
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
x <- y + z
exponent digit
comment: XXX: this could be optimized
label: code-design
* Convert and push final string.
mm <- b^e
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
s <- 2
(quotient-remainder (* r B) s) using a dummy subtraction loop
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
12 to 21
r <- (2 * f) * b^(e+1)
31 to 36
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: unused
label: code-design
x <- y * z
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
comment: m+ != m- (very rarely)
label: code-design
* Dragon4 slow path digit generation.
free-form
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
Maximum number of digits generated.
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
empty ("") is allowed in some formats (e.g. Number(''), as zero
r <- (remainder (* r B) s)
if 1, doing a fixed format output (not free format)
tc1 = true, tc2 = false
Leading zero.
m+ <- (* m+ B)
toString() conditions
Digit generation
significant from precision perspective
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
Most common cases first.
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
no net exponent
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
carry
add E
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Fast path the binary case
Infinity
low to high
x <- (1<<y)
absolute position for digit considered for rounding
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
tc1 = false, tc2 = false
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
+ 1 for rounding
t1 <- (* r B)
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
allow e.g. '0x0009' and '00077'
tc1 = false, tc2 = true
add AC*2^32
large context; around 2kB now
mp <- b^e
s <- b^(-e) * 2
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
x <- x + y, use t as temp
setup many variables in nc_ctx
add BC*2^16
Note: if 'x' is zero, x->n becomes 0 here
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
position of highest digit changed
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: No NUL term checks in this debug code.
label: code-design
triggers garbage digit check below
digit count
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
interpret e.g. '09' as '0', not NaN
toFixed()
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
r <- (2 * f) * b^e
-Infinity
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Start position (inclusive) and end position (exclusive)
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
denormal
max possible
fixed-format
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
IEEE exp without bias
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
low 32 bits is complete
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
generate mantissa with a single leading whole number digit
requested number of output digits; 0 = free-format
s <- 2 * b
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
Overestimate required size; debug code so not critical to be tight.
see algorithm
t1 <- (+ r m+)
denormal or zero
comment: no special formatting
label: code-design
Fast path check.
caller handles sign change
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
22 to 31
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
x <- x - y, use t as temp
Carry is detected based on wrapping which relies on exact 32-bit
* types.
current digit
fixed precision and zero padding would be required
t has high mantissa
max size: radix=2 + sign
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
"." is not accepted in any format
Maximum number of characters in formatted value.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
fixed-format termination conditions
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
exponent for 'f'
32-bit value
Buffer used for generated digits, values are in the range [0,B-1].
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
fall through and continue for-loop
* Create mantissa
0.000...
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
skip leading digit
count is already incremented, take into account
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
true, because v[1] has at least one bit set
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
s <- b^(1-e) * 2
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
is valid size
integer number in range
no need to normalize
Current size is about 152 bytes.
build result as: (r << 32) + s: start with (BD + E + F)
x <- b^y; use t1 and t2 as temps
k > 0 -> k was too low, and cannot be too high
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
x <- y - z, require x >= y => z >= 0, i.e. y >= z
m- <- (* m- B)
Exponent
x <- y
terminating conditions
t1 = (+ r m+)
if 1, doing a string-to-number; else doing a number-to-string
(e.g. k=3, digits=2 -> "12X")
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
whole or fraction digit
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
essentially tracks digit position of lowest 'f' digit
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
r <- 2 * f
lead zero + 'digits' fractions + 1 for rounding
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
"123.456"
for
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
distinct bignums, easy mistake to make
-> sets 'f' and 'e'
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
NB: use 's' as temp on purpose
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
Significand ('f') padding.
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
don't increase 'count'
this is the case for normalized numbers
arbitrary marker, outside valid exp range
comment: XXX: union would be more correct
label: code-design
NaN sign bit is platform specific with unpacked, un-normalized NaNs
* Conversion helpers
add AD*2^16
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
normal
use bigint area as a temp
"123"
is normalized
lowest mantissa for this exponent
mm <- mp
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
".123"
no negative sign for zero
(Number.MAX_VALUE).toString(2).length == 1024, + spare
normal: implicit leading 1-bit
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
r <- (2 * b) * f
digit position is absolute, not relative
x <- x * y, use t as temp
t1 <- t1 - s
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
(< (* r 2) s)
not minimum exponent
add F
output radix
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
biased exp == 0 -> denormal, exp -1022
37x32 = 1184 bits
comment: slow init, do only for slow path cases
label: code-design
"123." is allowed in some formats
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
tc1 = true, tc2 = true
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
2 to 11
x <- y - z
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
Force exponential format. Used for toExponential().
Allow naked fraction (e.g. ".123")
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
Allow leading zeroes (e.g. "0123" -> "123")
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
* String-to-number conversion
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
Allow trailing garbage (e.g. treat "123foo" as "123)
* Prototypes
Allow exponent
DUK_NUMCONV_H_INCLUDED
Allow empty string to be interpreted as 0
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
Allow 'Infinity'
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
Allow leading plus sign
Allow leading minus sign
Allow fraction part
Trim white space (= allow leading and trailing whitespace)
Allow empty fraction (e.g. "123.")
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
regexp opcodes
maximum bytecode copies for {n,m} quantifiers
* Regular expression structs, constants, and bytecode defines.
1e8
regexp execution limits
flags
DUK_REGEXP_H_INCLUDED
internal temporary value, used for char classes
1e9
* Prototypes
regexp compilation limits
comment: hacky helper for String.prototype.split()
label: code-design
allocated from valstack (fixed buffer)
highest capture number emitted so far (used as: ++captures)
insert code for matching the remainder - infinite or finite
expensive init, just want to fill window
[ ... regexp_object escaped_source ]
record previous atom info in case next token is a quantifier
DUK_USE_REGEXP_SUPPORT
retval (sub-atom char length) unused, tainted as complex above
return '(?:)'
two encoding attempts suffices
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
-> [ ... escaped_source bytecode ]
prefer direct execution
flags always encodes to 1 byte
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
mark as complex
comment: unused
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
reuse last emitted atom for remaining 'infinite' quantifier
[ ... pattern flags escaped_source ]
[ ... pattern flags escaped_source bytecode ]
qmin and qmax will be 0 or 1
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
[ ... regexp_object escaped_source bytecode ]
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
insert range count
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
prefer direct
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
* Init compilation context
[ ... escaped_source bytecode ]
-1 if disjunction is complex, char length if simple
insert ranges instruction, range count patched in later
add a new pending split to the beginning of the entire disjunction
never here
wipe the capture range made by the atom (if any)
negative -> complex atom
-1 for opcode
no change
'taint' result as complex
* Helper macros
* Disjunction struct: result of parsing a disjunction
[ ... escape_source bytecode ]
[ ... pattern flags ]
-> [ ... flags escaped_source bytecode ]
comment: note: ctx-wide temporary
label: code-design
* Create normalized 'source' property (E5 Section 15.10.3).
* Compilation
set by atom case clauses
value of re_ctx->captures at start of atom
remove the original 'template' atom
* Flags parsing (see E5 Section 15.10.4.1).
* Init lexer
-> [ ... escaped_source ]
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
insert the required matches (qmin) by copying the atom
expect_eof
coerce to string
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
+1 for opcode
* Finalize stack
always at least the header
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
complete 'sub atom'
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
char length of the atom parsed in this loop
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
silence scan-build warning
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
only advance if not tainted
comment: XXX: solve into closed form (smaller code)
label: code-design
re_ctx->captures at the start of the atom parsed in this loop
special helper for emitting u16 lists (used for character ranges for built-in char classes)
mark as complex (capture handling)
[ ... regexp_object ]
negative -> no atom matched on previous round
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
TypeError if fails
a complex (new) atom taints the result
finish up pending jump and split for last alternative
duplicate zeroing, expect for (possible) NULL inits
patch in range count later
patch pending jump and split
* Args validation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
regexp support disabled
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
offset is now target of the pending split (right after jump)
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
add a new pending match jump for latest finished alternative
[ ... pattern flags escaped_source buffer ]
parse ranges until character class ends
Call sites don't need the result length so it's not accumulated.
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
prefer jump
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Note: can be safely scanned as bytes (undecoded)
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
match fail
* Helpers for dealing with the input string
split2: prefer jump execution (not direct)
DUK_USE_REGEXP_SUPPORT
non-global regexp: lastIndex never updated on match
split1: prefer direct execution (no jump)
[ ... re_obj input bc ]
must fit into duk_small_int_t
note: caller 'sp' is intentionally not updated here
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
must have start and end
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: not really necessary
label: code-design
E5 Sections 15.10.2.8, 7.3
match: keep wiped/resaved values
no regexp instance should exist without a non-configurable bytecode property
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
advance by one character (code point) and one char_offset
TypeError if wrong; class check, see E5 Section 15.10.6
fall through
Note: allow backtracking from p == ptr_end
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
never here
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
backref n -> saved indices [n*2, n*2+1]
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
buffer is automatically zeroed
[ ... res_obj re_obj input bc saved_buf ]
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
NB: 'length' property is automatically updated by the array setup loop
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
[ ... re_obj input ] -> [ ... re_obj input bc ]
idx is unsigned, < 0 check is not necessary
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
[ ... res_obj ]
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
canonicalized by compiler
not a wordchar
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
-> [ ... re_obj input bc saved_buf lastIndex ]
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
fail: restore saves
[ ... re_obj input bc saved_buf ]
ToInteger(lastIndex)
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
capture is 'undefined', always matches!
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
signed integer encoding needed to work with UTF-8
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
force_global
match: keep saves
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
regexp support disabled
Backtrack utf-8 input and return a (possibly canonicalized) input character.
[ ... re_obj input bc saved_buf res_obj val ]
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
and even number
read header
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
[ ... re_obj input bc saved_buf res_obj ]
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
dummy so sp won't get updated
utf-8 continuation bytes have the form 10xx xxxx
regexp compiler should catch these
global regexp: lastIndex updated on match
expt 0xfff is infinite/nan
expt 0x000 is zero/subnormal
expt values [0x001,0x7fe] = normal
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
!DUK_SINGLE_FILE
DUK_REPLACEMENTS_H_INCLUDED
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Test without volatiles
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
* Zero sign, see misc/tcc_zerosign2.c.
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
* Union aliasing, see misc/clang_aliasing.c.
little endian
Test signaling NaN and alias assignment in all endianness combinations.
Catch a double-to-int64 cast issue encountered in practice.
* Casting
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
* Unions and structs for self tests
big endian
nop
* Packed tval sanity
DUK_USE_SELF_TESTS
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
comment: Same test with volatiles
label: test
* Self test main
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
* Basic double / byte union memory layout.
mixed endian
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
0xdeadbeef in decimal
* Two's complement arithmetic.
* DUK_BSWAP macros
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
no check
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment:
* Various sanity checks for typing
label: code-design
* Selftest code
DUK_SELFTEST_H_INCLUDED
Object property access
Compiler
Misc
Limits
Mostly API and built-in method related
comment: still in use with verbose messages
label: code-design
Regexp
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
JSON
DUK_ERRMSG_H_INCLUDED
comment: still in use with verbose messages
label: code-design
!DUK_SINGLE_FILE
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
DUK_USE_FASTINT
zero
exponent 1070
comment: unused
label: code-design
exponent 0
positive
* Manually optimized number-to-double conversion
0
negative
exponents 1023 to 1069
Note: reject negative zero.
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
comment: XXX: optimize for packed duk_tval directly?
label: code-design
implicit leading one
avoid unary minus on unsigned
1 << 52
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Portable 12-byte representation
XXX: clumsy sign extend and masking of 16 topmost bits
marker; not actual tagged type
marker; not actual tagged value
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
DUK_USE_64BIT_OPS
Assumes that caller has normalized NaNs, otherwise trouble ahead.
use duk_double_union as duk_tval directly
This seems reasonable overall.
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
for convenience
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
embed: integer value
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
comment: XXX: fast int-to-double
label: code-design
max, excl. varargs marker
DUK_USE_PACKED_TVAL
if present, forces 16-byte duk_tval
varargs marker
Note: masking is done for 'i' to deal with negative numbers correctly
* Packed 8-byte representation
in non-packed representation we don't care about which NaN is used
embed: void ptr
decoding
0xfff0 is -Infinity
embed: duk_hobject ptr
DUK_USE_FASTINT
getters
comment: This is performance critical because it appears in every DECREF.
label: code-design
comment: the NaN variant we use
label: code-design
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
DUK_TVAL_H_INCLUDED
embed: func ptr
sanity
fastint constants etc
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
embed: duk_hstring ptr
Lightfunc flags packing and unpacking.
first heap allocated, match bit boundary
embed: 0 or 1 (false or true)
setters
not exposed
embed: duk_hbuffer ptr
tags
embed: nothing
* Convenience (independent of representation)
========================================================================
* Unicode helpers
zero-width joiner
* Automatically generated by extract_chars.py, do not edit!
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
up to 36 bit codepoints
* Unicode tables
duk_unicode_support.c
!DUK_SINGLE_FILE
all codepoints up to U+10FFFF
DUK_UNICODE_H_INCLUDED
* Automatically generated by extract_caseconv.py, do not edit!
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
* Prototypes
all codepoints up to U+FFFF
* Extern
zero-width non-joiner
* UTF-8 / XUTF-8 / CESU-8 constants
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
does not fit into an uchar
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
DUK_USE_REGEXP_SUPPORT
curr char
0x20...0x2f
* Unicode letter check.
* Replace valstack top with case converted version.
0x60...0x6f
0xxx xxxx [7 bits]
0x40...0x4f
exposed because lexer needs these too
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
110x xxxx 10xx xxxx [11 bits]
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
XXX: add 'language' argument when locale/language sensitive rule
* support added.
next does not exist or next is not a letter
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
11 bits
0x50...0x5f
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_USE_PREFER_SIZE
fall through
* "IdentifierPart" production check.
fast path for ASCII
prev exists and is not a letter
36 bits
verified at beginning
complex, multicharacter conversion
DUK_USE_ASSERTIONS
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Fall through to handle the rest.
check pointer at end
Full, aligned 4-byte reads.
* "IdentifierStart" production check.
comment: XXX: turkish / azeri, lowercase rules
label: code-design
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
0x00...0x0f
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
NULL is allowed, no output
invalidates h_buf pointer
Decode helper. Return zero on error.
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
31 bits
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
* Fast path tables
* Regexp range tables
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
Small variant; roughly 150 bytes smaller than the fast variant.
cp == -1 (EOF) never matches and causes return value 0
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
default: no change
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
Must match src/extract_chars.py, generate_match_table3().
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
1:1 or special conversions, but not locale/context specific: script generated rules
10xx xxxx -> invalid
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
0x10...0x1f
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
on first round, skip
surrogate pairs get encoded here
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
end marker
used by e.g. duk_regexp_executor.c, string built-ins
prev char
ASCII fast path
0x70...0x7f
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
comment: XXX: lithuanian, explicit dot rules
label: code-design
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
0x30...0x3f
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
26 bits
64-bit OK because always >= 0
comment: XXX: lithuanian not implemented
label: requirement
[r1,r2] is the range
ASCII (and EOF) fast path -- quick accept and reject
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
always >= 0
number of continuation (non-initial) bytes in [0x80,0xbf]
1:1 conversion
* "LineTerminator" production check.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
end of input and last char has been processed
16 bits
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: turkish / azeri
label: code-design
U+03A3 = GREEK CAPITAL LETTER SIGMA
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
Ensure space for maximum multi-character result; estimate is overkill.
[ ... input buffer ]
uppercase
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
range conversion with a "skip"
next char
7 bits
* "WhiteSpace" production check.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
21 bits
comment: unused now, not needed until Turkish/Azeri
label: requirement
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
* Automatically generated by extract_chars.py, do not edit!
* Unicode support tables automatically generated during build.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
duk_unicode_ids_m_let_noabmp[]
duk_unicode_ids_m_let_noa[]
duk_unicode_ids_noabmp[]
IdentifierStart production with ASCII excluded
duk_unicode_caseconv_lc[]
IdentifierPart production with IdentifierStart and ASCII excluded
duk_unicode_ids_noa[]
IdentifierStart production with ASCII and non-BMP excluded
IdentifierStart production with Letter and ASCII excluded
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
duk_unicode_idp_m_ids_noa[]
* Case conversion tables generated using src/extract_caseconv.py.
duk_unicode_idp_m_ids_noabmp[]
* Automatically generated by extract_caseconv.py, do not edit!
duk_unicode_caseconv_uc[]
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
!DUK_SINGLE_FILE
Insert bytes in the middle of the buffer from an external buffer.
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
* Utilities
* Endian conversion
Ensuring (reserving) space.
Evaluates to (duk_uint8_t *) pointing to start of area.
* Externs and prototypes
NOTE: Multiple evaluation of 'ptr' in this macro.
For now only needed by the debugger.
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
2^4 -> 1/16 = 6.25% spare
Working with the pointer and current size.
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
DUK_UTIL_H_INCLUDED
comment: XXX: Rework to use an always-inline function?
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
No difference between raw/ensure because the buffer shrinks.
Initialization and finalization (compaction), converting to other types.
Miscellaneous.
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
'ptr' is evaluated both as LHS and RHS.
Safe write calls which will ensure space first.
must match genhashsizes.py
* Bitstream decoder
Append bytes from a slice already in the buffer.
Note: assumes that duk_util_probe_steps size is 32
* Bitstream encoder
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
Make underlying buffer compact to match DUK_BW_GET_SIZE().
No duk_bw_remove_ensure_slice(), functionality would be identical.
Reset to zero size, keep current limit.
Remove a slice from inside buffer.
remaining
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
* Bitstream decoder.
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
If buffer has been exhausted, truncate bitstream
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
* Bitstream encoder.
buffer size is >= 1
* Fast buffer writer with spare management.
overflow
for manual torture testing: tight allocation, useful with valgrind
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
point to start of 'reserved area'
not reachable
Don't support "straddled" source now.
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
Make buffer compact, matching current written size.
comment:
* Macro support functions (use only macros in calling code)
label: code-design
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
DUK_USE_STRHASH_DENSE
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
'magic' constants for Murmurhash2
prediction corrections for prime list (see genhashsizes.py)
hash size ratio goal, must match genhashsizes.py
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
prediction: portable variant using doubles if 64-bit values not available
minimum prime
correction
floor(1.15 * (1 << 10))
32-bit x 11-bit = 43-bit, fits accurately into a double
may happen if size is very close to 2^32-1
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
0x10-0x1f
0xf0-0xff
0xb0-0xbf
0xc0-0xcf
0x90...0x9f
0x90-0x9f
0x10...0x1f
0xd0...0xdf
0x20-0x2f
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
* Misc util stuff
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
For now only needed by the debugger.
0x60-0x6f
0x20...0x2f
0xa0-0xaf
0x60...0x6f
0x40...0x4f
0xe0-0xef
* Table for base-64 decoding
DUK_USE_HEX_FASTPATH
A...P
-1 if invalid
* Table for hex decoding ASCII hex digits
0x30-0x3f
0xc0...0xcf
0x00...0x0f
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
0x80-0x8f
0xb0...0xbf
Q...f
0xa0...0xaf
0x70...0x7f
* Table for hex encoding bytes
0x40-0x4f
* Table for base-64 encoding
0x30...0x3f
0x00-0x0f
0x80...0x8f
DUK_USE_INTEGER_BE
g...v
0xf0...0xff
0x70-0x7f
0xd0-0xdf
0x50-0x5f
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
DUK_USE_BASE64_FASTPATH
0x50...0x5f
0xe0...0xef
w.../
enough to cover the whole mantissa
if duk_uint32_t is exactly 32 bits, this is a NOP
only use the highest bit
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
no error if file does not exist
internal flag value: throw if mask doesn't match
set getter (given on value stack)
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
* Duktape public API for Duktape 1.8.0.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit 0a70d7e4c5227c84e3fed5209828973117d02849 (v1.8.0).
* Git branch v1.8-maintenance.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
comment: XXX: Enough space to hold internal suspend/resume structure.
* This is rather awkward and to be fixed when the internal
* structure is visible for the public API header.
label: code-design
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
This should not really happen, but would indicate x64.
comment: Minimize warnings for unused internal functions with GCC >= 3.1.1 and
* Clang. Based on documentation it should suffice to have the attribute
* in the declaration only, but in practice some warnings are generated unless
* the attribute is also applied to the definition.
label: code-design
Emscripten (provided explicitly by user), improve if possible
Both MinGW and MSVC have a 64-bit type.
* Platform autodetection
--- TinyC ---
mint clib is missing these
SuperH
--- x64 ---
MSVC does not have sys/param.h
--- Motorola 68k ---
since gcc-2.5
--- MIPS 64-bit ---
comment: XXX: DUK_UNREACHABLE for msvc?
label: code-design
OpenBSD
NetBSD
Apple OSX, iOS
Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
* integer ordering and is not relevant.
Type for public API calls.
comment: Rely as little as possible on compiler behavior for NaN comparison,
* signed zero handling, etc. Currently never activated but may be needed
* for broken compilers.
label: code-design
--- Generic BSD ---
uclibc may be missing these
FreeBSD
not defined by default
comment: Windows, both 32-bit and 64-bit
label: code-design
--- OpenBSD ---
comment:
* Alternative customization header
*
* If you want to modify the final DUK_USE_xxx flags directly (without
* using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
* and tweak the final flags there.
label: code-design
Cygwin
integer endianness is little on purpose
e.g. getdate_r
* Autogenerated defaults
Atari Mint
comment: GCC older than 4.6: avoid overflow warnings related to using INFINITY
label: code-design
Most portable, wastes space
GCC/clang inaccurate math would break compliance and probably duk_tval,
* so refuse to compile. Relax this if -ffast-math is tested to work.
--- Generic ---
VS2012+ has stdint.h, < VS2012 does not (but it's available for download).
comment:
* Alignment requirement and support for unaligned accesses
*
* Assume unaligned accesses are not supported unless specifically allowed
* in the target platform. Some platforms may support unaligned accesses
* but alignment to 4 or 8 may still be desirable.
label: requirement
Clang
AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
* define 'AMIGA' manually when using VBCC.
* duk_config.h configuration header generated by genconfig.py.
*
* Git commit: 0a70d7e4c5227c84e3fed5209828973117d02849
* Git describe: v1.8.0
* Git branch: v1.8-maintenance
*
* Supported platforms:
* - Mac OSX, iPhone, Darwin
* - OpenBSD
* - Generic BSD
* - Atari ST TOS
* - AmigaOS
* - Windows
* - Flashplayer (Crossbridge)
* - QNX
* - TI-Nspire
* - Emscripten
* - Linux
* - Solaris
* - Generic POSIX
* - Cygwin
* - Generic UNIX
* - Generic fallback
*
* Supported architectures:
* - x86
* - x64
* - x32
* - ARM 32-bit
* - ARM 64-bit
* - MIPS 32-bit
* - MIPS 64-bit
* - PowerPC 32-bit
* - PowerPC 64-bit
* - SPARC 32-bit
* - SPARC 64-bit
* - SuperH
* - Motorola 68k
* - Emscripten
* - Generic
*
* Supported compilers:
* - Clang
* - GCC
* - MSVC
* - Emscripten
* - TinyC
* - VBCC
* - Bruce's C compiler
* - Generic
*
--- GCC ---
Duktape/C function return value, platform int is enough for now to
* represent 0, 1, or negative error code. Must be compatible with
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
Low memory algorithm: separate chaining using arrays, fixed size hash
__OVERRIDE_DEFINES__
http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
vbcc + AmigaOS has C99 but no inttypes.h
MSVC
* Check whether or not a packed duk_tval representation is possible.
* What's basically required is that pointers are 32-bit values
* (sizeof(void *) == 4). Best effort check, not always accurate.
* If guess goes wrong, crashes may result; self tests also verify
* the guess.
--- Linux ---
--- AmigaOS ---
BCC, assume we're on x86.
Pointer size determination based on __WORDSIZE or architecture when
* that's not available.
Unsigned index variant.
External provider already defined.
Byte order varies, so rely on autodetect.
DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in.
comment: Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
* (which is unfortunately named). May sometimes need replacement, e.g.
* some compilers don't handle zero length or NULL correctly in realloc().
label: code-design
empty
--- MSVC ---
We're generally assuming that we're working on a platform with a 32-bit
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary
* if SIZE_MAX is missing), the check must be avoided because the
* preprocessor can't do a comparison.
64-bit constants. Since LL / ULL constants are not always available,
* use computed values. These values can't be used in preprocessor
* comparisons; flag them as such.
--- x86 ---
--- MIPS 32-bit ---
XXX: add feature options to force basic types from outside?
Array index values, could be exact 32 bits.
* Currently no need for signed duk_arridx_t.
SIZE_MAX may be missing so use an approximate value for it.
DUK_F_BCC
Complex condition broken into separate parts.
POSIX
If not provided, use safe default for alignment.
* Date provider selection
*
* User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
* rely on an external provider. If this is not done, revert to previous
* behavior and use Unix/Windows built-in provider.
Cannot determine byte order.
--- Cygwin ---
!defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
More or less standard endianness predefines provided by header files.
* The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
* will be big endian, see: http://lists.mysql.com/internals/443.
* On some platforms some defines may be present with an empty value which
* causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
!defined(DUK_USE_BYTEORDER)
comment: For custom platforms allow user to define byteorder explicitly.
* Since endianness headers are not standardized, this is a useful
* workaround for custom platforms for which endianness detection
* is not directly supported. Perhaps custom hardware is used and
* user cannot submit upstream patches.
label: code-design
comment: Don't know how to declare unreachable point, so don't do it; this
* may cause some spurious compilation warnings (e.g. "variable used
* uninitialized").
label: code-design
Good default is a bit arbitrary because alignment requirements
* depend on target. See https://github.com/svaarala/duktape/issues/102.
--- Windows ---
User provided InitJS.
These have been tested from VS2008 onwards; may work in older VS versions
* too but not enabled by default.
Error codes are represented with platform int. High bits are used
* for flags and such, so 32 bits are needed.
Intermediate define for 'have inttypes.h'
build is not C99 or C++11, play it safe
GCC: test not very accurate; enable only in relatively recent builds
* because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
* define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
* https://sites.google.com/site/x32abi/
Enabled with debug/assertions just so that any issues can be caught.
C99 or compatible
--- Mac OSX, iPhone, Darwin ---
C99 or above
MinGW. Also GCC flags (DUK_F_GCC) are enabled now.
This detection is not very reliable.
Support for 48-bit signed integer duk_tval with transparent semantics.
GCC and Clang provide endianness defines as built-in predefines, with
* leading and trailing double underscores (e.g. __BYTE_ORDER__). See
* output of "make gccpredefs" and "make clangpredefs". Clang doesn't
* seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
* http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
64-bit type detection is a bit tricky.
*
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
* are used by at least GCC (even if system headers don't provide ULLONG_MAX).
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
*
* ULL / LL constants are rejected / warned about by some compilers, even if
* the compiler has a 64-bit type and the compiler/system headers provide an
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32
* bits but can't be sure it is exactly 64 bits. Self tests will catch such
* cases.
Convert any input pointer into a "void *", losing a const qualifier.
* This is not fully portable because casting through duk_uintptr_t may
* not work on all architectures (e.g. those with long, segmented pointers).
Small integers (16 bits or more) can fall back to the 'int' type, but
* have a typedef so they are marked "small" explicitly.
comment: Most portable, potentially wastes space
label: code-design
PowerPC
--- Solaris ---
comment: Technically C99 (C++11) but found in many systems. On some systems
* __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
* including stdint.h (see above).
label: code-design
Missing some obvious constants.
No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only.
no endian.h or stdint.h
--- Atari ST TOS ---
GCC: assume we have __va_copy() in non-C99 mode.
User forced alignment to 4 or 8.
C99 / C++11 and above: rely on va_copy() which is required.
http://bellard.org/tcc/tcc-doc.html#SEC9
Check that architecture is two's complement, standard C allows e.g.
* INT_MIN to be -2**31+1 (instead of -2**31).
Based on 'make checkalign' there are no alignment requirements on
* Linux MIPS except for doubles, which need align by 4. Alignment
* requirements vary based on target though.
AmigaOS on M68k
not configured for DLL build
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
* anything; these require direct changes above.
comment: cannot detect 64-bit type, not always needed so don't error
label: code-design
--- Generic UNIX ---
std::exception
A few types are assumed to always exist.
Float word order not known, assume not a hybrid.
--- Generic fallback ---
comment: --- Generic POSIX ---
label: code-design
no parsing (not an error)
comment: ANSI C (various versions) and some implementations require that the
* pointer arguments to memset(), memcpy(), and memmove() be valid values
* even when byte size is 0 (even a NULL pointer is considered invalid in
* this context). Zero-size operations as such are allowed, as long as their
* pointer arguments point to a valid memory area. The DUK_MEMSET(),
* DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
* (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
* allowed. If these are not fulfilled, a macro wrapper is needed.
*
* http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
* http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
*
* Not sure what's the required behavior when a pointer points just past the
* end of a buffer, which often happens in practice (e.g. zero size memmoves).
* For example, if allocation size is 3, the following pointer would not
* technically point to a valid memory byte:
*
* <-- alloc -->
* | 0 | 1 | 2 | .....
* ^-- p=3, points after last valid byte (2)
label: code-design
C++11 or above
SPARC byte order varies so rely on autodetection.
DUK_F_PACKED_TVAL_PROVIDED
http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html
VBCC
sigsetjmp() alternative
GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang.
--- SuperH ---
Pre-C99: va_list type is implementation dependent. This replacement
* assumes it is a plain value so that a simple assignment will work.
* This is not the case on all platforms (it may be a single-array element,
* for instance).
comment: The best type for an "all around int" in Duktape internals is "at least
* 32 bit signed integer" which is most convenient. Same for unsigned type.
* Prefer 'int' when large enough, as it is almost always a convenient type.
label: code-design
uclibc
Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'.
No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only.
comment: Many platforms are missing fpclassify() and friends, so use replacements
* if necessary. The replacement constants (FP_NAN etc) can be anything but
* match Linux constants now.
label: code-design
* Checks for config option consistency (DUK_USE_xxx)
autodetect compiler
Rely on C89 headers only; time.h must be here.
These functions don't currently need replacement but are wrapped for
* completeness. Because these are used as function pointers, they need
* to be defined as concrete C functions (not macros).
--- TI-Nspire ---
comment: We need va_copy() which is defined in C99 / C++11, so an awkward
* replacement is needed for pre-C99 / pre-C++11 environments. This
* will quite likely need portability hacks for some non-C99
* environments.
label: code-design
AmigaOS on M68K or PPC is always big endian.
Feature option forcing.
--- ARM 64-bit ---
* Feature option handling
comment:
* Wrapper typedefs and constants for integer types, also sanity check types.
*
* C99 typedefs are quite good but not always available, and we want to avoid
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
* all C99 typedefs and Duktape code should only use these typedefs. Type
* detection when C99 is not supported is best effort and may end up detecting
* some types incorrectly.
*
* Pointer sizes are a portability problem: pointers to different types may
* have a different size and function pointers are very difficult to manage
* portably.
*
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
*
* Note: there's an interesting corner case when trying to define minimum
* signed integer value constants which leads to the current workaround of
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
* for a longer discussion.
*
* Note: avoid typecasts and computations in macro integer constants as they
* can then no longer be used in macro relational expressions (such as
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
* being able to compare DUK_SIZE_MAX against a limit.
label: code-design
Not standard but common enough
--- QNX ---
comment: Object property allocation layout has implications for memory and code
* footprint and generated code size/speed. The best layout also depends
* on whether the platform has alignment requirements or benefits from
* having mostly aligned accesses.
label: code-design
(v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
* NOT NUL terminate on truncation, but Duktape code never assumes that.
* http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
Motorola 68K. Not defined by VBCC, so user must define one of these
* manually when using VBCC.
http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx
Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value
http://bellard.org/tcc/tcc-doc.html#SEC7
* Intermediate helper defines
comment: Macro hackery to convert e.g. __LINE__ to a string without formatting,
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
label: code-design
Flash player (e.g. Crossbridge)
no endian.h
Shared includes: C89
integer byte order
float word order
* Convert DUK_USE_BYTEORDER, from whatever source, into currently used
* internal defines. If detection failed, #error out.
e.g. ptrdiff_t
comment: XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc?
label: code-design
SPARC
VBCC supports C99 so check only for C99 for union initializer support.
* Designated union initializers would possibly work even without a C99 check.
C++11 apparently ratified stdint.h
QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
* $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 67:#define __LITTLEENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 81:#define __BIGENDIAN__ 1
* $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
* 70:#define __LITTLEENDIAN__ 1
At least some uclibc versions have broken floating point math. For
* example, fpclassify() can incorrectly classify certain NaN formats.
* To be safe, use replacements.
Placeholder fix for (detection is wider than necessary):
* http://llvm.org/bugs/show_bug.cgi?id=17788
snprintf() is technically not part of C89 but usually available.
--- x32 ---
Basic integer typedefs and limits, preferably from inttypes.h, otherwise
* through automatic detection.
comment: Only include when compiling Duktape to avoid polluting application build
* with a lot of unnecessary defines.
label: code-design
--- VBCC ---
On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
* which seems incorrect if size_t is (at least) an unsigned 32-bit type.
* However, it doesn't seem useful to error out compilation if this is the
* case.
comment: On other platforms use layout 2, which requires some padding but
* is a bit more natural than layout 3 in ordering the entries. Layout
* 3 is currently not used.
label: code-design
VS2005+ should have variadic macros even when they're not C99.
illumos / Solaris
DUK_COMPILING_DUKTAPE
DUK_OPT_FORCE_BYTEORDER
QNX
since gcc-4.5
comment: Windows 32-bit and 64-bit are currently the same.
label: code-design
This is optionally used by panic handling to cause the program to segfault
* (instead of e.g. abort()) on panic. Valgrind will then indicate the C
* call stack leading to the panic.
IEEE float/double typedef.
--- ARM 32-bit ---
comment: XXX: This is technically not guaranteed because it's possible to configure
* an x86 to require aligned accesses with Alignment Check (AC) flag.
label: code-design
TinyC
comment: Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
* -not- portable. See code-issues.txt for a detailed discussion.
label: code-design
These are necessary wild guesses.
Already provided above
Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
* apparently, so to use with VBCC user must define __TOS__ manually.
Byte order is big endian but cannot determine IEEE double word order.
--- Flashplayer (Crossbridge) ---
MIPS byte order varies so rely on autodetection.
stdint.h not available
comment: The most portable way to figure out local time offset is gmtime(),
* but it's not thread safe so use with caution.
label: requirement
Codepoint type. Must be 32 bits or more because it is used also for
* internal codepoints. The type is signed because negative codepoints
* are used as internal markers (e.g. to mark EOF or missing argument).
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
* ensure duk_uint32_t casts back and forth nicely. Almost everything
* else uses the signed one.
DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in.
TOS on M68K is always big endian.
don't use strptime() for now
comment: not sure, not needed with C99 anyway
label: requirement
C++ doesn't have standard designated union initializers ({ .foo = 1 }).
--- Emscripten ---
nop
DLL build detection
comment: Avoid custom date parsing and formatting for portability.
label: code-design
Workaround for older C++ compilers before including <inttypes.h>,
* see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
* Compiler autodetection
--- SPARC 32-bit ---
--- Clang ---
On some platforms int is 16-bit but long is 32-bit (e.g. PureC)
comment:
* Byte order and double memory layout detection
*
* Endianness detection is a major portability hassle because the macros
* and headers are not standardized. There's even variance across UNIX
* platforms. Even with "standard" headers, details like underscore count
* varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
* (Crossbridge has a single underscore, for instance).
*
* The checks below are structured with this in mind: several approaches are
* used, and at the end we check if any of them worked. This allows generic
* approaches to be tried first, and platform/compiler specific hacks tried
* last. As a last resort, the user can force a specific endianness, as it's
* not likely that automatic detection will work on the most exotic platforms.
*
* Duktape supports little and big endian machines. There's also support
* for a hybrid used by some ARM machines where integers are little endian
* but IEEE double values use a mixed order (12345678 -> 43218765). This
* byte order for doubles is referred to as "mixed endian".
label: code-design
comment: Check whether we should use 64-bit integers or not.
*
* Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
* unless they are known to be unreliable. For instance, 64-bit types are
* available on VBCC but seem to misbehave.
label: code-design
VS2013+ supports union initializers but there's a bug involving union-inside-struct:
* https://connect.microsoft.com/VisualStudio/feedback/details/805981
* The bug was fixed (at least) in VS2015 so check for VS2015 for now:
* https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
* Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
no user declarations
DUK_CONFIG_H_INCLUDED
BCC (Bruce's C compiler): this is a "torture target" for compilation
Generic Unix (includes Cygwin)
There was a curious bug where test-bi-date-canceling.js would fail e.g.
* on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
* using doubles would be optimized which then broke some corner case tests.
* The problem goes away by adding 'volatile' to the datetime computations.
* Not sure what the actual triggering conditions are, but using this on
* non-C99 systems solves the known issues and has relatively little cost
* on other platforms.
C99 / C++11 and above: rely on va_copy() which is required.
* Omit parenthesis on macro right side on purpose to minimize differences
* to direct use.
C99 types
DUK_SIZE_MAX (= SIZE_MAX) is often reliable
--- PowerPC 64-bit ---
See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h
--- SPARC 64-bit ---
On platforms without any alignment issues, layout 1 is preferable
* because it compiles to slightly less code and provides direct access
* to property keys.
Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable
autodetect platform
comment: NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
* see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
* (This might be a wider problem; if so, generalize the define name.)
label: code-design
autodetect architecture
In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
* In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
* Use a computed NaN (initialized when a heap is created at the
* latest).
Clang: assume we have __va_copy() in non-C99 mode.
--- Bruce's C compiler ---
Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
* distinction matters for the CPU. These types are used mainly in the
* executor where it might really matter.
vbcc + AmigaOS may be missing these
C99 or C++11, no known issues
comment: XXX: DUK_LIKELY, DUK_UNLIKELY for msvc?
label: code-design
Initial fix: disable secure CRT related warnings when compiling Duktape
* itself (must be defined before including Windows headers). Don't define
* for user code including duktape.h.
varargs
* Fill-ins for platform, architecture, and compiler
e.g. strptime
comment: Note: PRS and FMT are intentionally left undefined for now. This means
* there is no platform specific date parsing/formatting but there is still
* the ISO 8601 standard format.
label: code-design
vsnprintf() is technically not part of C89 but usually available.
Rely on autodetection for byte order, alignment, and packed tval.
AmigaOS + M68K seems to have math issues even when using GCC cross
* compilation. Use replacements for all AmigaOS versions on M68K
* regardless of compiler.
Byte order is little endian but cannot determine IEEE double word order.
C++
MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__
VBCC is missing the built-ins even in C99 mode (perhaps a header issue).
_MSC_VER
comment: Macro for suppressing warnings for potentially unreferenced variables.
* The variables can be actually unreferenced or unreferenced in some
* specific cases only; for instance, if a variable is only debug printed,
* it is unreferenced when debug printing is disabled.
label: code-design
Byte order varies, rely on autodetection.
Use _setjmp() on Apple by default, see GH-55.
TI-Nspire (using Ndless)
--- PowerPC 32-bit ---
Some math functions are C99 only. This is also an issue with some
* embedded environments using uclibc where uclibc has been configured
* not to provide some functions. For now, use replacements whenever
* using uclibc.
Most portable
Boolean values are represented with the platform 'int'.
Shared includes: stdint.h is C99
BSD variant
Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
* now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
date.h is omitted, and included per platform
* Architecture autodetection
The most portable current time provider is time(), but it only has a
* one second resolution.
Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable
defined(DUK_USE_BYTEORDER)
In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
* Use a computed infinity (initialized when a heap is created at the
* latest).
For now, hash part is dropped if and only if 16-bit object fields are used.
MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
* compiling Duktape or the application.
comment: On Windows, assume we're little endian. Even Itanium which has a
* configurable endianness runs little endian in Windows.
label: code-design
comment: Compiler specific hackery needed to force struct size to match aligment,
* see e.g. duk_hbuffer.h.
*
* http://stackoverflow.com/questions/11130109/c-struct-size-alignment
* http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
label: code-design
Index values must have at least 32-bit signed range.
comment: Workaround for GH-323: avoid inlining control when compiling from
* multiple sources, as it causes compiler portability trouble.
label: code-design
byte order
Linux
Based on 'make checkalign' there are no alignment requirements on
* Linux SH4, but align by 4 is probably a good basic default.
MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
* _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
* BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
ARM
Fast variants of small integers, again for really fast paths like the
* executor.
comment: When C99 types are not available, we use heuristic detection to get
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
* types are then assumed to be exactly the same for now: these could
* be improved per platform but C99 types are very often now available.
* 64-bit types are not available on all platforms; this is OK at least
* on 32-bit platforms.
*
* This detection code is necessarily a bit hacky and can provide typedefs
* and defines that won't work correctly on some exotic platform.
label: code-design
comment:
* Cleanups (all statement parsing flows through here).
*
* Pop label site and reset labels. Reset 'next temp' to value at
* entry to reuse temps.
label: code-design
comment:
* Reference counting helper macros. The macros take a thread argument
* and must thus always be executed in a specific thread context. The
* thread argument is needed for features like finalization. Currently
* it is not required for INCREF, but it is included just in case.
*
* Note that 'raw' macros such as DUK_HEAPHDR_GET_REFCOUNT() are not
* defined without DUK_USE_REFERENCE_COUNTING, so caller must #ifdef
* around them.
label: code-design
alloc external with size zero
'i' is the first entry we'll keep
If blen <= 0xffffUL, clen is also guaranteed to be <= 0xffffUL.
Set catcher regs: idx_base+0 = value, idx_base+1 = lj_type.
resend state next time executor is about to run
comment: XXX: avoid this check somehow
label: code-design
Should match Function.prototype.toString()
* Main struct
'/'
* Unwind debugger state. If we unwind while stepping
* (either step over or step into), pause execution.
Duktape.modLoaded[] module cache
[ obj handler trap ]
Not safe to use 'reg_varbind' as assignment expression
* value, so go through a temp.
comment: size for formatting buffers
label: code-design
default case exists: go there if no case matches
registers are mutable, non-deletable
'{'
If the debugger is active we need to force an interrupt so that
* debugger breakpoints are rechecked. This is important for function
* calls caused by side effects (e.g. when doing a DUK_OP_GETPROP), see
* GH-303. Only needed for success path, error path always causes a
* breakpoint recheck in the executor. It would be enough to set this
* only when returning to an Ecmascript activation, but setting the flag
* on every return should have no ill effect.
get or set a range of flags; m=first bit number, n=number of bits
[ level obj func pc line ]
* Ecmascript compliant [[GetProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* May cause arbitrary side effects and invalidate (most) duk_tval
* pointers.
[ arg1 ... argN this ]
* Matching order:
*
* Punctuator first chars, also covers comments, regexps
* LineTerminator
* Identifier or reserved word, also covers null/true/false literals
* NumericLiteral
* StringLiteral
* EOF
*
* The order does not matter as long as the longest match is
* always correctly identified. There are order dependencies
* in the clauses, so it's not trivial to convert to a switch.
Allocator functions.
next does not exist or next is not a letter
* Create and push an error object onto the top of stack.
* If a "double error" occurs, use a fixed error instance
* to avoid further trouble.
'enum'
SameValue(NaN, NaN) = true, regardless of NaN sign or extra bits
just making sure
needed for inf: causes mantissa to become zero,
* and rounding to be skipped.
String table assert check omitted from 1.x branch
* backport.
comment: XXX: string not shared because it is conditional
label: code-design
carry
Initial bytes for markers.
queue back to heap_allocated
XXX: We can't resize the value stack to a size smaller than the
* current top, so the order of the resize and adjusting the stack
* top depends on the current vs. final size of the value stack.
* The operations could be combined to avoid this, but the proper
* fix is to only grow the value stack on a function call, and only
* shrink it (without throwing if the shrink fails) on function
* return.
print provider
form: { DecimalDigits , }, val1 = min count
* Figure out the final, non-bound constructor, to get "prototype"
* property.
comment:
* Note:
*
* - duk__match_regexp() is required not to longjmp() in ordinary "non-match"
* conditions; a longjmp() will terminate the entire matching process.
*
* - Clearing saved[] is not necessary because backtracking does it
*
* - Backtracking also rewinds ctx.recursion back to zero, unless an
* internal/limit error occurs (which causes a longjmp())
*
* - If we supported anchored matches, we would break out here
* unconditionally; however, Ecmascript regexps don't have anchored
* matches. It might make sense to implement a fast bail-out if
* the regexp begins with '^' and sp is not 0: currently we'll just
* run through the entire input string, trivially failing the match
* at every non-zero offset.
label: code-design
DUK_TOK_LPAREN
caller ensures; rom objects are never bufferobjects now
Would be nice to bulk clear the allocation, but the context
* is 1-2 kilobytes and nothing should rely on it being zeroed.
1 -> needs a PUTVAR
* Post-increment/decrement will return the original value as its
* result value. However, even that value will be coerced using
* ToNumber() which is quite awkward. Specific bytecode opcodes
* are used to handle these semantics.
*
* Note that post increment/decrement has a "no LineTerminator here"
* restriction. This is handled by duk__expr_lbp(), which forcibly terminates
* the previous expression if a LineTerminator occurs before '++'/'--'.
leave out trailing 'unused' elements
comment: TODO: implement Proxy object support here
label: requirement
* Multiply + add + carry for 32-bit components using only 16x16->32
* multiplies and carry detection based on unsigned overflow.
*
* 1st mult, 32-bit: (A*2^16 + B)
* 2nd mult, 32-bit: (C*2^16 + D)
* 3rd add, 32-bit: E
* 4th add, 32-bit: F
*
* (AC*2^16 + B) * (C*2^16 + D) + E + F
* = AC*2^32 + AD*2^16 + BC*2^16 + BD + E + F
* = AC*2^32 + (AD + BC)*2^16 + (BD + E + F)
* = AC*2^32 + AD*2^16 + BC*2^16 + (BD + E + F)
args start at index 2
* Various Unicode help functions for character classification predicates,
* case conversion, decoding, etc.
eat colon
always set; points to a reserved valstack slot
Track number of escapes: necessary for proper keyword
* detection.
* Node.js Buffer.prototype.write(string, [offset], [length], [encoding])
IdentifierPart production with IdentifierStart, ASCII, and non-BMP excluded
should never happen but default here
'env'
Preliminaries, required by setjmp() handler. Must be careful not
* to throw an unintended error here.
-> [val]
emitted
resume delete to target
-> [... obj]
success
+0.0
replacer is a mutation risk
parse key and value
comment:
* Arithmetic operations other than '+' have number-only semantics
* and are implemented here. The separate switch-case here means a
* "double dispatch" of the arithmetic opcode, but saves code space.
*
* E5 Sections 11.5, 11.5.1, 11.5.2, 11.5.3, 11.6, 11.6.1, 11.6.2, 11.6.3.
label: code-design
No duk_bw_remove_ensure_slice(), functionality would be identical.
if boolean matches A, skip next inst
(>= e 0) AND (= f (expt b (- p 1)))
*
* be <- (expt b e) == b^e
* be1 <- (* be b) == (expt b (+ e 1)) == b^(e+1)
* r <- (* f be1 2) == 2 * f * b^(e+1) [if b==2 -> f * b^(e+2)]
* s <- (* b 2) [if b==2 -> 4]
* m+ <- be1 == b^(e+1)
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Perform fixed-format rounding.
If not within Ecmascript range, some integer time calculations
* won't work correctly (and some asserts will fail), so bail out
* if so. This fixes test-bug-date-insane-setyear.js. There is
* a +/- 24h leeway in this range check to avoid a test262 corner
* case documented in test-bug-date-timeval-edges.js.
Failed to match the quantifier, restore lexer and parse
* opening brace as a literal.
[ ... val ]
'true'
comment: If we don't have a jmpbuf_ptr, there is little we can do
* except panic. The caller's expectation is that we never
* return.
*
* With C++ exceptions we now just propagate an uncaught error
* instead of invoking the fatal error handler. Because there's
* a dummy jmpbuf for C++ exceptions now, this could be changed.
label: code-design
For now shared handler is fine.
may be less, since DELETED entries are NULLed by rehash
Handle single character fills as memset() even when
* the fill data comes from a one-char argument.
OK
comment:
* Bytecode dump/load
*
* The bytecode load primitive is more important performance-wise than the
* dump primitive.
*
* Unlike most Duktape API calls, bytecode dump/load is not guaranteed to be
* memory safe for invalid arguments - caller beware! There's little point
* in trying to achieve memory safety unless bytecode instructions are also
* validated which is not easy to do with indirect register references etc.
label: code-design
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
maximum loopcount for peephole optimization
cleared before entering finally
flags for duk_hobject_get_own_propdesc() and variants
comment: Execute finalizers before freeing the heap, even for reachable
* objects, and regardless of whether or not mark-and-sweep is
* enabled. This gives finalizers the chance to free any native
* resources like file handles, allocations made outside Duktape,
* etc. This is quite tricky to get right, so that all finalizer
* guarantees are honored.
*
* XXX: this perhaps requires an execution time limit.
label: code-design
useful for patching jumps later
avoid attempts to add/remove object keys
The get/set pointers could be 16-bit pointer compressed but it
* would make no difference on 32-bit platforms because duk_tval is
* 8 bytes or more anyway.
* Local defines
comment: XXX: compression
label: code-design
already NULLed (by unwind)
Don't allow actual chars after equal sign.
-> [ Object defineProperty undefined obj key desc ]
whether to use macros or helper function depends on call count
DUK_USE_FASTINT
7: toISOString
comment: XXX: "read only object"?
label: code-design
no action
comment: XXX: There is currently no support for writing buffer object
* indexed elements here. Attempt to do so will succeed and
* write a concrete property into the buffer object. This should
* be fixed at some point but because buffers are a custom feature
* anyway, this is relatively unimportant.
label: code-design
must hold DUK_VARARGS
capture is 'undefined', always matches!
comment:
* XXX: could make this a lot faster if we create the double memory
* representation directly. Feasible easily (must be uniform random).
label: code-design
'raw'
DUK_TOK_RPAREN
request to create catch binding
for object-bound identifiers
comment: XXX: compression (as an option)
label: code-design
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* This handling is now identical for C and Ecmascript functions.
* C functions always have the 'NEWENV' flag set, so their
* environment record initialization is delayed (which is good).
*
* Delayed creation (on demand) is handled in duk_js_var.c.
comment:
* Declaration binding instantiation conceptually happens when calling a
* function; for us it essentially means that function prologue. The
* conceptual process is described in E5 Section 10.5.
*
* We need to keep track of all encountered identifiers to (1) create an
* identifier-to-register map ("varmap"); and (2) detect duplicate
* declarations. Identifiers which are not bound to registers still need
* to be tracked for detecting duplicates. Currently such identifiers
* are put into the varmap with a 'null' value, which is later cleaned up.
*
* To support functions with a large number of variable and function
* declarations, registers are not allocated beyond a certain limit;
* after that limit, variables and functions need slow path access.
* Arguments are currently always register bound, which imposes a hard
* (and relatively small) argument count limit.
*
* Some bindings in E5 are not configurable (= deletable) and almost all
* are mutable (writable). Exceptions are:
*
* - The 'arguments' binding, established only if no shadowing argument
* or function declaration exists. We handle 'arguments' creation
* and binding through an explicit slow path environment record.
*
* - The "name" binding for a named function expression. This is also
* handled through an explicit slow path environment record.
label: code-design
first coerce to a plain value
-> [ ... func varmap enum ]
* Replace lexical environment for global scope
*
* Create a new object environment for the global lexical scope.
* We can't just reset the _Target property of the current one,
* because the lexical scope is shared by other threads with the
* same (initial) built-ins.
force_global
NB: use 's' as temp on purpose
Not odd, or y == -Infinity
* Global object built-ins
A bunch of helpers (for size optimization) that combine duk__expr()/duk__exprtop()
* and result conversions.
*
* Each helper needs at least 2-3 calls to make it worth while to wrap.
Value stack: these are expressed as pointers for faster stack manipulation.
* [valstack,valstack_top[ is GC-reachable, [valstack_top,valstack_end[ is
* not GC-reachable but kept initialized as 'undefined'.
Output a specified number of digits instead of using the shortest
* form. Used for toPrecision() and toFixed().
[ body formals ], formals is comma separated list that needs to be parsed
bytecode execution
thisArg
* Not found
XXX: duk_uarridx_t?
E5 Section 9.4, ToInteger()
force_new
duk_js_call.c is required to restore the stack reserve
* so we only need to reset the top.
* __FILE__ / __LINE__ entry, here 'pc' is line number directly.
* Sometimes __FILE__ / __LINE__ is reported as the source for
* the error (fileName, lineNumber), sometimes not.
avoid dereference after potential callstack realloc
* Pass 2
compensate for eval() call
set values into ret array
* Pick an object from the head (don't remove yet).
fast path
comment: Fast exit if indices are identical. This is valid for a non-existent property,
* for an undefined value, and almost always for ToString() coerced comparison of
* arbitrary values (corner cases where this is not the case include e.g. a an
* object with varying ToString() coercion).
*
* The specification does not prohibit "caching" of values read from the array, so
* assuming equality for comparing an index with itself falls into the category of
* "caching".
*
* Also, compareFn may be inconsistent, so skipping a call to compareFn here may
* have an effect on the final result. The specification does not require any
* specific behavior for inconsistent compare functions, so again, this fast path
* is OK.
label: code-design
comment: XXX: this could be a DUK__CONSTP instead
label: code-design
[ ... this tracedata sep this ]
* After arguments, allocate special registers (like shuffling temps)
[ ToObject(this) item1 ... itemN arr item(i) ]
The implementation for computing of start_pos and end_pos differs
* from the standard algorithm, but is intended to result in the exactly
* same behavior. This is not always obvious.
This behavior mostly mimics Node.js now.
comment: XXX: typing (duk_hcompiledfunction has duk_uint32_t)
label: code-design
comment: XXX: because we're dealing with 'own' properties of a fresh array,
* the array initializer should just ensure that the array has a large
* enough array part and write the values directly into array part,
* and finally set 'length' manually in the end (as already happens now).
label: code-design
This may happen even after the fast path check, if exponent is
* not balanced (e.g. "0e1"). Remember to respect zero sign.
Encode a fastint from duk_tval ptr, no value stack effects.
Already declared, update value.
'has'
DUK_TOK_COMMA
'void'
bufwriter for code
* Abandon array failed, need to decref keys already inserted
* into the beginning of new_e_k before unwinding valstack.
* UTF-8 / XUTF-8 / CESU-8 constants
when going backwards, we decrement cpos 'early';
* 'p' may point to a continuation byte of the char
* at offset 'cpos', but that's OK because we'll
* backtrack all the way to the initial byte.
DUK_TOK_IDENTIFIER
* Regexp recursive matching function.
*
* Returns 'sp' on successful match (points to character after last matched one),
* NULL otherwise.
*
* The C recursion depth limit check is only performed in this function, this
* suffices because the function is present in all true recursion required by
* regexp execution.
comment: Use recursion_limit to ensure we don't overwrite js_ctx->visiting[]
* array so we don't need two counter checks in the fast path. The
* slow path has a much larger recursion limit which we'll use if
* necessary.
label: code-design
[ ... func varmap enum key value this ]
1: toDateString
comment: Fill offset handling is more lenient than in Node.js.
label: code-design
Positive if local time ahead of UTC.
With this check in place fast paths won't need read-only
* object checks. This is technically incorrect if there are
* setters that cause no writes to ROM objects, but current
* built-ins don't have such setters.
save stack top
Insert an empty jump in the middle of code emitted earlier. This is
* currently needed for compiling for-in.
Treat like a debugger statement: ignore when not attached.
'import'
Duktape/C API guaranteed entries (on top of args)
avoid warning (unsigned)
Helper which can be called both directly and with duk_safe_call().
[ ... template ]
-> [ buffer ]
comment: XXX: Here a "slice copy" would be useful.
label: code-design
Must ensure result is 64-bit (no overflow); a
* simple and sufficient fast path is to allow only
* 32-bit inputs. Avoid zero inputs to avoid
* negative zero issues (-1 * 0 = -0, for instance).
duk_unicode_ids_m_let_noa[]
Don't intercept a DoubleError, we may have caused the initial double
* fault and attempting to intercept it will cause us to be called
* recursively and exhaust the C stack.
comment:
* Node.js Buffer.prototype.equals()
* Node.js Buffer.prototype.compare()
* Node.js Buffer.compare()
label: requirement
indirect allocs
Lightfuncs are always considered strict.
implies DUK_HOBJECT_IS_BUFFEROBJECT
safe, because matched (NUL causes a break)
* Packed tval sanity
longjmp type
should be first on 64-bit platforms
comment:
* XXX: duk_uint_fast32_t should probably be used in many places here.
label: code-design
[ ... | (crud) errobj ]
expensive flag
validation performed by duk__hexval
non-strict equality from here on
allocate catcher and populate it (should be atomic)
since duk__abandon_array_checked() causes a resize, there should be no gaps in keys
comment: DUK_TVAL_SET_TVAL_UPDREF() is used a lot in executor, property lookups,
* etc, so it's very important for performance. Measure when changing.
*
* NOTE: the source and destination duk_tval pointers may be the same, and
* the macros MUST deal with that correctly.
label: code-design
if 0, 'str16' used, if > 0, 'strlist16' used
probe sequence (open addressing)
token was preceded by a lineterm
-> [ ... ]
* Store entry state.
Perform an intermediate join when this many elements have been pushed
* on the value stack.
duk_unicode_ids_m_let_noabmp[]
* Parse variant 3 or 4.
*
* For variant 3 (e.g. "for (A in C) D;") the code for A (except the
* final property/variable write) has already been emitted. The first
* instruction of that code is at pc_v34_lhs; a JUMP needs to be inserted
* there to satisfy control flow needs.
*
* For variant 4, if the variable declaration had an initializer
* (e.g. "for (var A = B in C) D;") the code for the assignment
* (B) has already been emitted.
*
* Variables set before entering here:
*
* pc_v34_lhs: insert a "JUMP L2" here (see doc/compiler.rst example).
* reg_temps + 0: iteration target value (written to LHS)
* reg_temps + 1: enumerator object
'return'
comment:
* String table algorithm: fixed size string table with array chaining
*
* The top level string table has a fixed size, with each slot holding
* either NULL, string pointer, or pointer to a separately allocated
* string pointer list.
*
* This is good for low memory environments using a pool allocator: the
* top level allocation has a fixed size and the pointer lists have quite
* small allocation size, which further matches the typical pool sizes
* needed by objects, strings, property tables, etc.
label: code-design
comment: XXX: remove this native function and map 'stack' accessor
* to the toString() implementation directly.
label: code-design
* Create a RegExp instance (E5 Section 15.10.7).
*
* Note: the output stack left by duk_regexp_compile() is directly compatible
* with the input here.
*
* Input stack: [ escaped_source bytecode ] (both as strings)
* Output stack: [ RegExp ]
comment: log level could be popped but that's not necessary
label: code-design
thread currently running (only one at a time)
numargs
already defined, good
* Currently only allowed only if yielding thread has only
* Ecmascript activations (except for the Duktape.Thread.yield()
* call at the callstack top) and none of them constructor
* calls.
*
* This excludes the 'entry' thread which will always have
* a preventcount > 0.
Copy term name until end or '/'.
-> [ ... trap handler ]
Non-BMP characters within valid UTF-8 range: encode as is.
* They'll decode back into surrogate pairs if the escaped
* output is decoded.
[ ... v1 v2 name filename str ] -> [ ... str v2 name filename ]
DUK_TOK_DEBUGGER
Init newly allocated slots (only).
a complex (new) atom taints the result
[this value]
See: test-bug-tailcall-preventyield-assert.c.
check_object_coercible
comment: XXX: source code property
label: code-design
comment: XXX: Would be nice to share the fast path loop from duk_hex_decode()
* and avoid creating a temporary buffer. However, there are some
* differences which prevent trivial sharing:
*
* - Pipe char detection
* - EOF detection
* - Unknown length of input and output
*
* The best approach here would be a bufwriter and a reasonaly sized
* safe inner loop (e.g. 64 output bytes at a time).
label: code-design
comment: XXX: unnecessary, handle in adjust
label: code-design
[ ... key trap handler ]
comment:
* XXX: As noted above, a protected API call won't be counted as a
* catcher. This is usually convenient, e.g. in the case of a top-
* level duk_pcall(), but may not always be desirable. Perhaps add an
* argument to treat them as catchers?
label: code-design
const
even for zero-length string
eat 'if'
14: getDay
Custom behavior: plain buffer is used as internal buffer
* without making a copy (matches Duktape.Buffer).
function: create an arguments object on function call
-> [... target]
* Nice debug log.
comment: XXX: copy flags using a mask
label: code-design
[ ... func/retval ] -> [ ... ]
comment: XXX: optimize loops
label: code-design
up to 36 bit codepoints
no fractions in internal time
ditto
[key] -> []
Track number of escapes; count not really needed but directive
* prologues need to detect whether there were any escapes or line
* continuations or not.
[ buf? res ]
comment: Duktape 0.11.0 and prior tried to optimize the resize by not
* counting the number of actually used keys prior to the resize.
* This worked mostly well but also caused weird leak-like behavior
* as in: test-bug-object-prop-alloc-unbounded.js. So, now we count
* the keys explicitly to compute the new entry part size.
label: code-design
undefined -> skip (replaced with empty)
eat opening quote on first loop
comment:
* Array built-ins
*
* Note that most Array built-ins are intentionally generic and work even
* when the 'this' binding is not an Array instance. To ensure this,
* Array algorithms do not assume "magical" Array behavior for the "length"
* property, for instance.
*
* XXX: the "Throw" flag should be set for (almost?) all [[Put]] and
* [[Delete]] operations, but it's currently false throughout. Go through
* all put/delete cases and check throw flag use. Need a new API primitive
* which allows throws flag to be specified.
*
* XXX: array lengths above 2G won't work reliably. There are many places
* where one needs a full signed 32-bit range ([-0xffffffff, 0xffffffff],
* i.e. -33- bits). Although array 'length' cannot be written to be outside
* the unsigned 32-bit range (E5.1 Section 15.4.5.1 throws a RangeError if so)
* some intermediate values may be above 0xffffffff and this may not be always
* correctly handled now (duk_uint32_t is not enough for all algorithms).
*
* For instance, push() can legitimately write entries beyond length 0xffffffff
* and cause a RangeError only at the end. To do this properly, the current
* push() implementation tracks the array index using a 'double' instead of a
* duk_uint32_t (which is somewhat awkward). See test-bi-array-push-maxlen.js.
*
* On using "put" vs. "def" prop
* =============================
*
* Code below must be careful to use the appropriate primitive as it matters
* for compliance. When using "put" there may be inherited properties in
* Array.prototype which cause side effects when values are written. When
* using "define" there are no such side effects, and many test262 test cases
* check for this (for real world code, such side effects are very rare).
* Both "put" and "define" are used in the E5.1 specification; as a rule,
* "put" is used when modifying an existing array (or a non-array 'this'
* binding) and "define" for setting values into a fresh result array.
*
* Also note that Array instance 'length' should be writable, but not
* enumerable and definitely not configurable: even Duktape code internally
* assumes that an Array instance will always have a 'length' property.
* Preventing deletion of the property is critical.
label: code-design
no need to decref
18: getMinutes
'exports'
* Unicode letter check.
DUK_USE_MATH_BUILTIN
No field needed when strings are in ROM.
value was undefined/unsupported
eat 'function'
keep in valstack
* Must guarantee all actually used array entries will fit into
* new entry part. Add one growth step to ensure we don't run out
* of space right away.
step 11
IdentifierPart production with IdentifierStart and ASCII excluded
Internal timevalue is already NaN, so don't touch it.
flag for later write
GH-303
Popping one element is called so often that when footprint is not an issue,
* compile a specialized function for it.
DUK_TOK_SEMICOLON
return value from Duktape.Thread.yield()
No need to re-lookup 'act' at present: no side effects.
Causes a ToNumber() coercion, but doesn't break coercion order since
* year is coerced first anyway.
Parts are in local time, convert when setting.
* E5 Section 7.4. If the multi-line comment contains a newline,
* it is treated like a single line terminator for automatic
* semicolon insertion.
Note: if target_pc1 == i, we'll optimize a jump to itself.
* This does not need to be checked for explicitly; the case
* is rare and max iter breaks us out.
Backup 'caller' property and update its value.
assume exactly 1 arg, which is why '*' is forbidden; arg size still
* depends on type though.
Add function object.
finalization
[ ToObject(this) item1 ... itemN arr ]
0x50...0x5f
Rule table: first matching rule is used to determine what to do next.
CATCH flag may be enabled or disabled here; it may be enabled if
* the statement has a catch block but the try block does not throw
* an error.
* Init the heap object
Inherit from ROM-based global object: less RAM usage, less transparent.
Note: 0xff != DUK_BC_C_MAX
COMMA
Node.js return value for noAssert out-of-bounds reads is
* usually (but not always) NaN. Return NaN consistently.
comment: function must not be tail called
label: code-design
stage 3: update length (done by caller), decide return code
idx_space
statement does not terminate directive prologue
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func exports fresh_require exports module ]
comment: XXX: optimize for buffer inputs: no need to coerce to a string
* which causes an unnecessary interning.
label: code-design
* Table for hex decoding ASCII hex digits
function: create new environment when called (see duk_hcompiledfunction)
pop regexp res_obj or match string
P
required if NAMEBINDING set
slow path decode
don't care value, year is mandatory
really 'not applicable' anymore, should not be referenced after this
skip jump conditionally
* Flags parsing (see E5 Section 15.10.4.1).
for updating (all are set to < 0 for virtual properties)
* Run (object) finalizers in the "to be finalized" work list.
'warn'
DUK_USE_FILE_IO
[... constructor arg1 ... argN final_cons fallback]
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur.
'Array' object, array length and index exotic behavior
a statement following a label cannot be a source element
* (a function declaration).
24: setMilliseconds
'\xffVarenv'
comment: DUK_USE_DATE_GET_LOCAL_TZOFFSET() needs to be called with a
* time value computed from UTC parts. At this point we only
* have 'd' which is a time value computed from local parts, so
* it is off by the UTC-to-local time offset which we don't know
* yet. The current solution for computing the UTC-to-local
* time offset is to iterate a few times and detect a fixed
* point or a two-cycle loop (or a sanity iteration limit),
* see test-bi-date-local-parts.js and test-bi-date-tzoffset-basic-fi.js.
*
* E5.1 Section 15.9.1.9:
* UTC(t) = t - LocalTZA - DaylightSavingTA(t - LocalTZA)
*
* For NaN/inf, DUK_USE_DATE_GET_LOCAL_TZOFFSET() returns 0.
label: code-design
DUK_TOK_BREAK
We're conceptually between two opcodes; act->pc indicates the next
* instruction to be executed. This is usually the correct pc/line to
* indicate in Status. (For the 'debugger' statement this now reports
* the pc/line after the debugger statement because the debugger opcode
* has already been executed.)
DUK_TOK_MOD_EQ
comment:
* Write to 'length' of an array is a very complex case
* handled in a helper which updates both the array elements
* and writes the new 'length'. The write may result in an
* unconditional RangeError or a partial write (indicated
* by a return code).
*
* Note: the helper has an unnecessary writability check
* for 'length', we already know it is writable.
label: code-design
comment:
* Allocation size for 'curr_alloc' is alloc_size. There is no
* automatic NUL terminator for buffers (see above for rationale).
*
* 'curr_alloc' is explicitly allocated with heap allocation
* primitives and will thus always have alignment suitable for
* e.g. duk_tval and an IEEE double.
label: code-design
* ctx->prev_token token to process with duk__expr_led()
* ctx->curr_token updated by caller
Note: target registers a and a+1 may overlap with DUK__REGP(b).
* Careful here.
* Mark unreachable, finalizable objects.
*
* Such objects will be moved aside and their finalizers run later. They have
* to be treated as reachability roots for their properties etc to remain
* allocated. This marking is only done for unreachable values which would
* be swept later (refzero_list is thus excluded).
*
* Objects are first marked FINALIZABLE and only then marked as reachability
* roots; otherwise circular references might be handled inconsistently.
comment: XXX: accept any duk_hbufferobject type as an input also?
label: code-design
Note: DST adjustment is determined using UTC time.
caller must check
2
comment: Fresh require: require.id is left configurable (but not writable)
* so that is not easy to accidentally tweak it, but it can still be
* done with Object.defineProperty().
*
* XXX: require.id could also be just made non-configurable, as there
* is no practical reason to touch it.
label: code-design
log this with a normal debug level because this should be relatively rare
* Ecmascript execution, support primitives.
* replace()
out_clamped=NULL, RangeError if outside range
DUK_USE_MARK_AND_SWEEP && DUK_USE_VOLUNTARY_GC
idx_args = idx_func + 2
handle comma and closing bracket
* Avoid a GC if GC is already running. See duk_heap_mem_alloc().
Note: this allows creation of internal strings.
DUK__FLD_DOUBLE
comment:
* Logging
*
* Current logging primitive is a sprintf-style log which is convenient
* for most C code. Another useful primitive would be to log N arguments
* from value stack (like the Ecmascript binding does).
label: code-design
caller and arguments must use the same thrower, [[ThrowTypeError]]
bound function 'length' property is interesting
DUK_REPLACEMENTS_H_INCLUDED
[ ... error func ]
expt 0x000 is zero/subnormal
There is a caller; it MUST be an Ecmascript caller (otherwise it would
* match entry level check)
restore PC
allow negative PCs, behave as a no-op
'\xffValue'
* Activation defines
Step 15: insert itemCount elements into the hole made above
No need to replace the 'enum_target' value in stack, only the
* enum_target reference. This also ensures that the original
* enum target is reachable, which keeps the proxy and the proxy
* target reachable. We do need to replace the internal _Target.
XXX: ARRAY_PART for Array prototype?
Coerce value to a number before computing check_length, so that
* the field type specific coercion below can't have side effects
* that would invalidate check_length.
string is a valid array index
* Fast path: assume no mutation, iterate object property tables
* directly; bail out if that assumption doesn't hold.
'Number'
buffer is behind a pointer, dynamic or external
* in
allow caller to give a const number with the DUK__CONST_MARKER
DUK_USE_JSON_DECNUMBER_FASTPATH
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack (e.g. if
* lval is already a string).
XXX: use DUK_HSTRING_FLAG_INTERNAL?
func support for [[HasInstance]] checked in the beginning of the loop
%p
weak refs should be handled here, but no weak refs for
* any non-string objects exist right now.
pop key
implementation specific
* Log level check
comment: XXX: unify handling with native call.
label: code-design
internal extra elements assumed on function entry,
* always added to user-defined 'extra' for e.g. the
* duk_check_stack() call.
* Complex atom
*
* The original code is used as a template, and removed at the end
* (this differs from the handling of simple quantifiers).
*
* NOTE: there is no current solution for empty atoms in complex
* quantifiers. This would need some sort of a 'progress' instruction.
*
* XXX: impose limit on maximum result size, i.e. atom_code_len * atom_copies?
Leading zero is not counted towards precision digits; not
* in the integer part, nor in the fraction part.
39: setYear
comment:
* ToString() (E5 Section 9.8)
*
* ==> implemented in the API.
label: requirement
E5.1 Section 15.9.1.6
DUK_USE_JSON_QUOTESTRING_FASTPATH
always in executor
because of valstack init policy
embed: func ptr
local
Sanity check
* Object environment record.
*
* Binding (target) object is an external, uncontrolled object.
* Identifier may be bound in an ancestor property, and may be
* an accessor. Target can also be a Proxy which we must support
* here.
* Manipulate callstack for the call.
Currently the bytecode executor and executor interrupt
* instruction counts are off because we don't execute the
* interrupt handler when we're about to exit from the initial
* user call into Duktape.
*
* If we were to execute the interrupt handler here, the counts
* would match. You can enable this block manually to check
* that this is the case.
comment: Note: combining comparison ops must be done carefully because
* of uncomparable values (NaN): it's not necessarily true that
* (x >= y) === !(x < y). Also, evaluation order matters, and
* although it would only seem to affect the compiler this is
* actually not the case, because there are also run-time coercions
* of the arguments (with potential side effects).
*
* XXX: can be combined; check code size.
label: code-design
'typeof'
Execute bytecode until returned or longjmp().
overflow not possible, buffer limits
'interface'
zero everything unless requested not to do so
E5 Section 15.12.3, main algorithm, step 4.b.ii steps 1-4.
* Node.js Buffer.isBuffer()
DUK_TOK_COLON
B -> target register for next key
* C -> enum register
-> [ ... flags escaped_source bytecode ]
backref n -> saved indices [n*2, n*2+1]
value1 -> error object
remove key
comment:
* String hash computation (interning).
*
* String hashing is performance critical because a string hash is computed
* for all new strings which are candidates to be added to the string table.
* However, strings actually added to the string table go through a codepoint
* length calculation which dominates performance because it goes through
* every byte of the input string (but only for strings added).
*
* The string hash algorithm should be fast, but on the other hand provide
* good enough hashes to ensure both string table and object property table
* hash tables work reasonably well (i.e., there aren't too many collisions
* with real world inputs). Unless the hash is cryptographic, it's always
* possible to craft inputs with maximal hash collisions.
*
* NOTE: The hash algorithms must match src/dukutil.py:duk_heap_hashstring()
* for ROM string support!
label: code-design
comment: XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
label: code-design
comment: For short strings, use a fixed temp buffer.
label: code-design
label limits
marker values for hash part
DUK_TOK_GE
-> [ ... closure ]
NULL pointer is required to encode to zero, so memset is enough.
else an array initializer element
* E5 Section 7.3
*
* A LineTerminatorSequence essentially merges <CR> <LF> sequences
* into a single line terminator. This must be handled by the caller.
35: setUTCMonth
[ ... retval ]
Input shuffling happens before the actual operation, while output
* shuffling happens afterwards. Output shuffling decisions are still
* made at the same time to reduce branch clutter; output shuffle decisions
* are recorded into X_out variables.
'new' MemberExpression Arguments
assume plain values
duk_regconst_t is unsigned, so use 0 as dummy value (ignored by caller)
[ ... val obj ]
-> [ ... re_obj input bc saved_buf lastIndex ]
comment: (advance << 8) + token_type, updated at function end,
* init is unnecessary but suppresses "may be used uninitialized" warnings.
label: code-design
first, parse regexp body roughly
Duktape/C (nativefunction) object, exotic 'length'
DUK_HOBJECT_FLAG_EXOTIC_ARRAY varies
'this' binding
[ ... val key ] -> [ ... key val ]
isAccessor
Cannot be compressed as a heap pointer because may point to
* an arbitrary address.
skip opening slash on first loop
transfer flags
DUK_TOK_INTERFACE
may be undefined
accept anything, expect first value (EOF will be
* caught by duk__dec_value() below.
iteration statements allow continue
Clamp so that values at 'clamp_top' and above are wiped and won't
* retain reachable garbage. Then extend to 'nregs' because we're
* returning to an Ecmascript function.
'while'
comment: Checking this here rather that in memory alloc primitives
* reduces checking code there but means a failed allocation
* will go through a few retries before giving up. That's
* fine because this only happens during debugging.
label: code-design
comment:
* Array abandon check; abandon if:
*
* new_used / new_size < limit
* new_used < limit * new_size || limit is 3 bits fixed point
* new_used < limit' / 8 * new_size || *8
* 8*new_used < limit' * new_size || :8
* new_used < limit' * (new_size / 8)
*
* Here, new_used = a_used, new_size = a_size.
*
* Note: some callers use approximate values for a_used and/or a_size
* (e.g. dropping a '+1' term). This doesn't affect the usefulness
* of the check, but may confuse debugging.
label: code-design
Target is before source. Source offset is expressed as
* a "before change" offset. Account for the memmove.
object is constructable
regexp support disabled
This should be equivalent to match() algorithm step 8.f.iii.2:
* detect an empty match and allow it, but don't allow it twice.
assume keys are compacted
currently implicitly also DUK_USE_DOUBLE_LINKED_HEAP
advance, whatever the current token is; parse next token in regexp context
* ToInt32(), ToUint32(), ToUint16() (E5 Sections 9.5, 9.6, 9.7)
regs to allocate
preallocated temporaries (2) for variants 3 and 4
[ regexp input ]
function: function object is strict
DUK_TOK_ALSHIFT
comment: XXX: what to do if _Formals is not empty but compiler has
* optimized it away -- read length from an explicit property
* then?
label: code-design
work list for objects whose refcounts are zero but which have not been
* "finalized"; avoids recursive C calls when refcounts go to zero in a
* chain of objects.
comment: context and locale specific rules which cannot currently be represented
* in the caseconv bitstream: hardcoded rules in C
label: code-design
* Heap string representation.
*
* Strings are byte sequences ordinarily stored in extended UTF-8 format,
* allowing values larger than the official UTF-8 range (used internally)
* and also allowing UTF-8 encoding of surrogate pairs (CESU-8 format).
* Strings may also be invalid UTF-8 altogether which is the case e.g. with
* strings used as internal property names and raw buffers converted to
* strings. In such cases the 'clen' field contains an inaccurate value.
*
* Ecmascript requires support for 32-bit long strings. However, since each
* 16-bit codepoint can take 3 bytes in CESU-8, this representation can only
* support about 1.4G codepoint long strings in extreme cases. This is not
* really a practical issue.
call is a direct eval call
varname is still reachable
Leave 'setter' on stack
seconds
comment:
* Ecmascript compiler.
*
* Parses an input string and generates a function template result.
* Compilation may happen in multiple contexts (global code, eval
* code, function code).
*
* The parser uses a traditional top-down recursive parsing for the
* statement level, and an operator precedence based top-down approach
* for the expression level. The attempt is to minimize the C stack
* depth. Bytecode is generated directly without an intermediate
* representation (tree), at the cost of needing two passes over each
* function.
*
* The top-down recursive parser functions are named "duk__parse_XXX".
*
* Recursion limits are in key functions to prevent arbitrary C recursion:
* function body parsing, statement parsing, and expression parsing.
*
* See doc/compiler.rst for discussion on the design.
*
* A few typing notes:
*
* - duk_regconst_t: unsigned, no marker value for "none"
* - duk_reg_t: signed, < 0 = none
* - PC values: duk_int_t, negative values used as markers
label: code-design
Append a "(line NNN)" to the "message" property of any error
* thrown during compilation. Usually compilation errors are
* SyntaxErrors but they can also be out-of-memory errors and
* the like.
comment: XXX: any way to detect faster whether something needs to be closed?
* We now look up _Callee and then skip the rest.
label: requirement
DUK_USE_VARIADIC_MACROS
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* ieee value = 1.ffff... * 2^(e - 1023) (normal)
* = 0.ffff... * 2^(-1022) (denormal)
*
* algorithm v = f * b^e
key is now reachable in the valstack
MakeDate
Request callback should push values for reply to client onto valstack
inserted jump
[enum_target res]
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize or a forced relocating realloc?
label: code-design
For Ecmascript strings, this check can only match for
* initial UTF-8 bytes (not continuation bytes). For other
* strings all bets are off.
Then reuse the unwound activation; callstack was not shrunk so there is always space
DUK_USE_DEBUGGER_DUMPHEAP || DUK_USE_DEBUGGER_INSPECT
for storing/restoring the varmap binding for catch variable
r <- (2 * f) * b^(e+1)
'[...]'
comment: Careful here and with other duk_put_prop_xxx() helpers: the
* target object and the property value may be in the same value
* stack slot (unusual, but still conceptually clear).
label: code-design
function is strict
must work for nargs <= 0
Ignore digits beyond a radix-specific limit, but note them
* in expt_adj.
don't run finalizers; leave finalizable objects in finalize_list for next round
[this value] -> [value this]
Update 'buffer_length' to be the effective, safe limit which
* takes into account the underlying buffer. This value will be
* potentially invalidated by any side effect.
2: toTimeString
comment: No need for constants pointer (= same as data).
*
* When using 16-bit packing alignment to 4 is nice. 'funcs' will be
* 4-byte aligned because 'constants' are duk_tvals. For now the
* inner function pointers are not compressed, so that 'bytecode' will
* also be 4-byte aligned.
label: code-design
* Initialize function state for a zero-argument function
Guaranteed by recursion_limit setup so we don't have to
* check twice.
line continuation
IsGenericDescriptor(desc) == true; this means in practice that 'desc'
* only has [[Enumerable]] or [[Configurable]] flag updates, which are
* allowed at this point.
'-Infinity'
* Resume a thread.
*
* The thread must be in resumable state, either (a) new thread which hasn't
* yet started, or (b) a thread which has previously yielded. This method
* must be called from an Ecmascript function.
*
* Args:
* - thread
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
type tag (public)
comment: It'd be nice to do something like this - but it doesn't
* work for closures created inside the catch clause.
label: code-design
don't re-enter e.g. during Eval
mp <- b^e
special handling of fmt==NULL
Ensure space for final configuration (idx_retbase + num_stack_rets)
* and intermediate configurations.
parse value
comment: Note: not honoring round-to-even should work but now generates incorrect
* results. For instance, 1e23 serializes to "a000...", i.e. the first digit
* equals the radix (10). Scaling stops one step too early in this case.
* Don't know why this is the case, but since this code path is unused, it
* doesn't matter.
label: code-design
comment: The 'strict' flag is copied to get the special [[Get]] of E5.1
* Section 15.3.5.4 to apply when a 'caller' value is a strict bound
* function. Not sure if this is correct, because the specification
* is a bit ambiguous on this point but it would make sense.
label: code-design
function may call direct eval
comment: _Varmap: omitted if function is guaranteed not to do slow path identifier
* accesses or if it would turn out to be empty of actual register mappings
* after a cleanup. When debugging is enabled, we always need the varmap to
* be able to lookup variables at any point.
label: code-design
[ array totalLength ]
Opcode interval for a Date-based status/peek rate limit check. Only
* relevant when debugger is attached. Requesting a timestamp may be a
* slow operation on some platforms so this shouldn't be too low. On the
* other hand a high value makes Duktape react to a pause request slowly.
-> [ ... key val val' ]
[ ... re_obj input ] -> [ ... re_obj input bc ]
valstack slot for 1st token value
side effects, possibly errors
NOTE: Multiple evaluation of 'ptr' in this macro.
Overflow of the execution counter is fine and doesn't break
* anything here.
mark-and-sweep: finalized (on previous pass)
curr is accessor, desc is data
[ func thisArg arg1 ... argN ]
XXX: the insert helpers should ensure that the bytecode result is not
* larger than expected (or at least assert for it). Many things in the
* bytecode, like skip offsets, won't work correctly if the bytecode is
* larger than say 2G.
this function
comment: 'tv' becomes invalid
label: code-design
is an actual function (not global/eval code)
Catch attempts to use out-of-range reg/const. Without this
* check Duktape 0.12.0 could generate invalid code which caused
* an assert failure on execution. This error is triggered e.g.
* for functions with a lot of constants and a try-catch statement.
* Shuffling or opcode semantics change is needed to fix the issue.
* See: test-bug-trycatch-many-constants.js.
'callee'
Initial stack size satisfies the stack spare constraints so there
* is no need to require stack here.
'byteOffset'
comment: duk_handle_call_xxx: constructor call (i.e. called as 'new Foo()')
label: code-design
no operators
Strict: never allow function declarations outside top level.
[ ... arg1 ... argN envobj ]
* Field access
0x30...0x3f
value1 -> label number, pseudo-type to indicate a continue continuation (for ENDFIN)
true
comment: XXX: common reg allocation need is to reuse a sub-expression's temp reg,
* but only if it really is a temp. Nothing fancy here now.
label: code-design
only use the highest bit
Function values are handled completely above (including
* coercion results):
distinct bignums, easy mistake to make
comment: XXX: this is now a very unoptimal implementation -- this can be
* made very simple by direct manipulation of the object internals,
* given the guarantees above.
label: code-design
Split time value into parts. The time value is assumed to be an internal
* one, i.e. finite, no fractions. Possible local time adjustment has already
* been applied when reading the time value.
If flags != 0 (strict or SameValue), thr can be NULL. For loose
* equals comparison it must be != NULL.
DUK_TOK_INSTANCEOF
time
update entry, allocating if necessary
A structure for 'snapshotting' a point for rewinding
* Ecmascript call
cannot be arguments exotic
comment: this is not strictly necessary, but helps debugging
label: code-design
* Prototypes for built-in functions not automatically covered by the
* header declarations emitted by genbuiltins.py.
push initial function call to new thread stack; this is
* picked up by resume().
31: setUTCHours
Decode a one-bit flag, and if set, decode a value of 'bits', otherwise return
* default value. Return value is signed so that negative marker value can be
* used by caller as a "not present" value.
format plus something to avoid just missing
comment: XXX: post-checks (such as no duplicate keys)
label: code-design
if property already exists, overwrites silently
comment: 'val' is never NaN, so no need to normalize
label: code-design
* Lowercase digits for radix values 2 to 36. Also doubles as lowercase
* hex nybble table.
may be reg or const
decl name
rnd_state for duk_util_tinyrandom.c
Note: heap->heap_thread, heap->curr_thread, and heap->heap_object
* are on the heap allocated list.
jump is inserted here
misc
'length' and other virtual properties are not
* enumerable, but are included if non-enumerable
* properties are requested.
only flag now
[... func this arg1 ... argN]
record previous atom info in case next token is a quantifier
-""-
* Ecmascript compliant [[GetOwnProperty]](P), for internal use only.
*
* If property is found:
* - Fills descriptor fields to 'out_desc'
* - If DUK_GETDESC_FLAG_PUSH_VALUE is set, pushes a value related to the
* property onto the stack ('undefined' for accessor properties).
* - Returns non-zero
*
* If property is not found:
* - 'out_desc' is left in untouched state (possibly garbage)
* - Nothing is pushed onto the stack (not even with DUK_GETDESC_FLAG_PUSH_VALUE
* set)
* - Returns zero
*
* Notes:
*
* - Getting a property descriptor may cause an allocation (and hence
* GC) to take place, hence reachability and refcount of all related
* values matter. Reallocation of value stack, properties, etc may
* invalidate many duk_tval pointers (concretely, those which reside
* in memory areas subject to reallocation). However, heap object
* pointers are never affected (heap objects have stable pointers).
*
* - The value of a plain property is always reachable and has a non-zero
* reference count.
*
* - The value of a virtual property is not necessarily reachable from
* elsewhere and may have a refcount of zero. Hence we push it onto
* the valstack for the caller, which ensures it remains reachable
* while it is needed.
*
* - There are no virtual accessor properties. Hence, all getters and
* setters are always related to concretely stored properties, which
* ensures that the get/set functions in the resulting descriptor are
* reachable and have non-zero refcounts. Should there be virtual
* accessor properties later, this would need to change.
not enumerable
%f and %lf both consume a 'long'
* Catcher defines
never executed
comment: At least 'magic' has a significant impact on function
* identity.
label: code-design
'('
important to do this *after* pushing, to make the thread reachable for gc
[ offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
Should not happen.
init pointer fields to null
* toString(), valueOf()
success, fixup pointers
comment: XXX: several pointer comparison issues here
label: code-design
insert (DUK_REOP_WIPERANGE, start, count) in reverse order so the order ends up right
Check that value is a duk_hbufferobject and return a pointer to it.
Note: DUK_VALSTACK_INITIAL_SIZE must be >= DUK_VALSTACK_API_ENTRY_MINIMUM
* + DUK_VALSTACK_INTERNAL_EXTRA so that the initial stack conforms to spare
* requirements.
comment: XXX: may need a 'length' filter for forEach()
label: code-design
Note: assumes that duk_util_probe_steps size is 32
guaranteed when building arguments
updates thread state, minimizes its allocations
'{"_inf":true}'
comment: Without variadic macros resort to comma expression trickery to handle debug
* prints. This generates a lot of harmless warnings. These hacks are not
* needed normally because DUK_D() and friends will hide the entire debug log
* statement from the compiler.
label: code-design
comment: TimeClip() should never be necessary
label: code-design
0x10-0x1f
E5.1 Section B.2.2, step 7.
Parser part masks.
end switch (tok)
negative -> complex atom
-> [ ... val root "" ]
result array
XXX: fast path for arrays?
-> [ ... ToObject(this) ToUint32(length) ]
Continue checked execution if there are breakpoints or we're stepping.
* Also use checked execution if paused flag is active - it shouldn't be
* because the debug message loop shouldn't terminate if it was. Step out
* is handled by callstack unwind and doesn't need checked execution.
* Note that debugger may have detached due to error or explicit request
* above, so we must recheck attach status.
0x00...0x0f
coercion order matters
'jc'
1 if property found, 0 otherwise
fixed-format
not strictly necessary because of lookahead '}' above
comment: XXX: must be able to represent -len
label: code-design
DUK_USE_DPRINT_COLORS
expect_eof
borrowed reference to catch variable name (or NULL if none)
comment: XXX: these could be implemented as macros calling an internal function
* directly.
* XXX: same issue as with Duktape.fin: there's no way to delete the property
* now (just set it to undefined).
label: code-design
comment: XXX: set magic directly here? (it could share the c_nargs arg)
label: code-design
* Preliminary activation record and valstack manipulation.
* The concrete actions depend on whether the we're dealing
* with a tail call (reuse an existing activation), a resume,
* or a normal call.
*
* The basic actions, in varying order, are:
*
* - Check stack size for call handling
* - Grow call stack if necessary (non-tail-calls)
* - Update current activation (idx_retval) if necessary
* (non-tail, non-resume calls)
* - Move start of args (idx_args) to valstack bottom
* (tail calls)
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
result index for filter()
either nonzero value is ok
bc
* DELVAR
*
* See E5 Sections:
* 11.4.1 The delete operator
* 10.2.1.1.5 DeleteBinding (N) [declarative environment record]
* 10.2.1.2.5 DeleteBinding (N) [object environment record]
*
* Variable bindings established inside eval() are deletable (configurable),
* other bindings are not, including variables declared in global level.
* Registers are always non-deletable, and the deletion of other bindings
* is controlled by the configurable flag.
*
* For strict mode code, the 'delete' operator should fail with a compile
* time SyntaxError if applied to identifiers. Hence, no strict mode
* run-time deletion of identifiers should ever happen. This function
* should never be called from strict mode code!
* Mark refzero_list objects.
*
* Objects on the refzero_list have no inbound references. They might have
* outbound references to objects that we might free, which would invalidate
* any references held by the refzero objects. A refzero object might also
* be rescued by refcount finalization. Refzero objects are treated as
* reachability roots to ensure they (or anything they point to) are not
* freed in mark-and-sweep.
Negative zero needs special handling in JX/JC because
* it would otherwise serialize to '0', not '-0'.
can't resize below 'top'
round up roughly to next 'grow step'
comment:
* E5 Section 7.6:
*
* IdentifierPart:
* IdentifierStart
* UnicodeCombiningMark
* UnicodeDigit
* UnicodeConnectorPunctuation
* <ZWNJ> [U+200C]
* <ZWJ> [U+200D]
*
* IdentifierPart production has one multi-character production
* as part of its IdentifierStart alternative. The '\' character
* of an escape sequence is not matched here, see discussion in
* duk_unicode_is_identifier_start().
*
* To match non-ASCII characters (codepoints >= 0x80), a very slow
* linear range-by-range scan is used. The codepoint is first compared
* to the IdentifierStart ranges, and if it doesn't match, then to a
* set consisting of code points in IdentifierPart but not in
* IdentifierStart. This is done to keep the unicode range data small,
* at the expense of speed.
*
* The ASCII fast path consists of:
*
* 0x0030 ... 0x0039 ['0' ... '9', UnicodeDigit]
* 0x0041 ... 0x005a ['A' ... 'Z', IdentifierStart]
* 0x0061 ... 0x007a ['a' ... 'z', IdentifierStart]
* 0x0024 ['$', IdentifierStart]
* 0x005f ['_', IdentifierStart and
* UnicodeConnectorPunctuation]
*
* UnicodeCombiningMark has no code points <= 0x7f.
*
* The matching code reuses the "identifier start" tables, and then
* consults a separate range set for characters in "identifier part"
* but not in "identifier start". These can be extracted with the
* "src/extract_chars.py" script.
*
* UnicodeCombiningMark -> categories Mn, Mc
* UnicodeDigit -> categories Nd
* UnicodeConnectorPunctuation -> categories Pc
label: code-design
last array index explicitly initialized, +1
Value would yield 'undefined', so skip key altogether.
* Side effects have already happened.
need side effects, not value
* Check function name validity now that we know strictness.
* This only applies to function declarations and expressions,
* not setter/getter name.
*
* See: test-dev-strict-mode-boundary.js
Target may be a Proxy or property may be an accessor, so we must
* use an actual, Proxy-aware hasprop check here.
*
* out->holder is NOT set to the actual duk_hobject where the
* property is found, but rather the object binding target object.
Note: for srclen=0, src may be NULL
never an empty match, so step 13.c.iii can't be triggered
Outer executor with setjmp/longjmp handling.
if B/C is >= this value, refers to a const
if debugging disabled
if true, the stack already contains the final result
* E5 Section 7.2 specifies six characters specifically as
* white space:
*
* 0009;<control>;Cc;0;S;;;;;N;CHARACTER TABULATION;;;;
* 000B;<control>;Cc;0;S;;;;;N;LINE TABULATION;;;;
* 000C;<control>;Cc;0;WS;;;;;N;FORM FEED (FF);;;;
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* FEFF;ZERO WIDTH NO-BREAK SPACE;Cf;0;BN;;;;;N;BYTE ORDER MARK;;;;
*
* It also specifies any Unicode category 'Zs' characters as white
* space. These can be extracted with the "src/extract_chars.py" script.
* Current result:
*
* RAW OUTPUT:
* ===========
* 0020;SPACE;Zs;0;WS;;;;;N;;;;;
* 00A0;NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;NON-BREAKING SPACE;;;;
* 1680;OGHAM SPACE MARK;Zs;0;WS;;;;;N;;;;;
* 180E;MONGOLIAN VOWEL SEPARATOR;Zs;0;WS;;;;;N;;;;;
* 2000;EN QUAD;Zs;0;WS;2002;;;;N;;;;;
* 2001;EM QUAD;Zs;0;WS;2003;;;;N;;;;;
* 2002;EN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2003;EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2004;THREE-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2005;FOUR-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2006;SIX-PER-EM SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2007;FIGURE SPACE;Zs;0;WS;<noBreak> 0020;;;;N;;;;;
* 2008;PUNCTUATION SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 2009;THIN SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 200A;HAIR SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 202F;NARROW NO-BREAK SPACE;Zs;0;CS;<noBreak> 0020;;;;N;;;;;
* 205F;MEDIUM MATHEMATICAL SPACE;Zs;0;WS;<compat> 0020;;;;N;;;;;
* 3000;IDEOGRAPHIC SPACE;Zs;0;WS;<wide> 0020;;;;N;;;;;
*
* RANGES:
* =======
* 0x0020
* 0x00a0
* 0x1680
* 0x180e
* 0x2000 ... 0x200a
* 0x202f
* 0x205f
* 0x3000
*
* A manual decoder (below) is probably most compact for this.
ToNumber(bool) is +1.0 or 0.0. Tagged boolean value is always 0 or 1.
when nothing is running, API calls are in non-strict mode
comment: String length is computed here to avoid multiple evaluation
* of a macro argument in the calling side.
label: code-design
see duk_js_executor.c
Convert heap string index to a token (reserved words)
comment: XXX: refactor and share with other code
label: code-design
order must match constants in genbuiltins.py
Buffer is kept as is, with the fixed/dynamic nature of the
* buffer only changed if requested. An external buffer
* is converted into a non-external dynamic buffer in a
* duk_to_dynamic_buffer() call.
* Ecmascript compliant [[Delete]](P, Throw).
-> [ ... str ]
args go here in parens
0xb0...0xbf
Write in big endian
only need to guarantee 1 more slot, but allocation growth is in chunks
comment: alloc function typedefs in duktape.h
label: code-design
i >= 0 would always be true
comment: XXX: inline into a prototype walking loop?
label: code-design
Lightfunc handling by ToObject() coercion.
DUK_BUFOBJ_UINT16ARRAY
'else'
'String' object, array index exotic behavior
A -> target reg
* B -> object reg/const (may be const e.g. in "'foo'[1]")
* C -> key reg/const
There is no eval() special handling here: eval() is never
* automatically converted to a lightfunc.
comment: XXX: identify enumeration target with an object index (not top of stack)
label: code-design
Write unsigned 32-bit integer.
The underlying types for offset/length in duk_hbufferobject is
* duk_uint_t; make sure argument values fit and that offset + length
* does not wrap.
[ body formals source template closure ]
no refcount changes
[ arg1 ... argN-1 body] -> [body arg1 ... argN-1]
First evaluate LHS fully to ensure all side effects are out.
properties object
Call handling and success path. Success path exit cleans
* up almost all state.
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
* stack[4] = regexp match OR match string
object is extensible
* The length comparisons are present to handle
* strings like "use strict\u0000foo" as required.
lookup name from an open declarative record's registers
relookup (side effects)
comment: XXX: make a common DUK_USE_ option, and allow custom fixed seed?
label: code-design
x <- y * z
* Note: assuming new_a_size == 0, and that entry part contains
* no conflicting keys, refcounts do not need to be adjusted for
* the values, as they remain exactly the same.
*
* The keys, however, need to be interned, incref'd, and be
* reachable for GC. Any intern attempt may trigger a GC and
* claim any non-reachable strings, so every key must be reachable
* at all times.
*
* A longjmp must not occur here, as the new_p allocation would
* be freed without these keys being decref'd, hence the messy
* decref handling if intern fails.
comment:
* 'props' contains {key,value,flags} entries, optional array entries, and
* an optional hash lookup table for non-array entries in a single 'sliced'
* allocation. There are several layout options, which differ slightly in
* generated code size/speed and alignment/padding; duk_features.h selects
* the layout used.
*
* Layout 1 (DUK_USE_HOBJECT_LAYOUT_1):
*
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 2 (DUK_USE_HOBJECT_LAYOUT_2):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* e_size * sizeof(duk_uint8_t) + pad bytes of entry flags (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
*
* Layout 3 (DUK_USE_HOBJECT_LAYOUT_3):
*
* e_size * sizeof(duk_propvalue) bytes of entry values (e_next gc reachable)
* a_size * sizeof(duk_tval) bytes of (opt) array values (plain only) (all gc reachable)
* e_size * sizeof(duk_hstring *) bytes of entry keys (e_next gc reachable)
* h_size * sizeof(duk_uint32_t) bytes of (opt) hash indexes to entries (e_size),
* 0xffffffffUL = unused, 0xfffffffeUL = deleted
* e_size * sizeof(duk_uint8_t) bytes of entry flags (e_next gc reachable)
*
* In layout 1, the 'e_next' count is rounded to 4 or 8 on platforms
* requiring 4 or 8 byte alignment. This ensures proper alignment
* for the entries, at the cost of memory footprint. However, it's
* probably preferable to use another layout on such platforms instead.
*
* In layout 2, the key and value parts are swapped to avoid padding
* the key array on platforms requiring alignment by 8. The flags part
* is padded to get alignment for array entries. The 'e_next' count does
* not need to be rounded as in layout 1.
*
* In layout 3, entry values and array values are always aligned properly,
* and assuming pointers are at most 8 bytes, so are the entry keys. Hash
* indices will be properly aligned (assuming pointers are at least 4 bytes).
* Finally, flags don't need additional alignment. This layout provides
* compact allocations without padding (even on platforms with alignment
* requirements) at the cost of a bit slower lookups.
*
* Objects with few keys don't have a hash index; keys are looked up linearly,
* which is cache efficient because the keys are consecutive. Larger objects
* have a hash index part which contains integer indexes to the entries part.
*
* A single allocation reduces memory allocation overhead but requires more
* work when any part needs to be resized. A sliced allocation for entries
* makes linear key matching faster on most platforms (more locality) and
* skimps on flags size (which would be followed by 3 bytes of padding in
* most architectures if entries were placed in a struct).
*
* 'props' also contains internal properties distinguished with a non-BMP
* prefix. Often used properties should be placed early in 'props' whenever
* possible to make accessing them as fast a possible.
label: code-design
Catches >0x100000000 and negative values.
* Entry points
* Error built-ins
Packed or unpacked tval
* PC-to-line constants
top-down expression parser
E5 Section 15.4.5.1, steps 4.e.i - 4.e.ii
fall through
x
comment: XXX: write protect after flag? -> any chance of handling it here?
label: code-design
Term was '.' and is eaten entirely (including dup slashes).
fast path for ASCII
num_stack_res
%lx
* Not found as concrete or virtual
'Buffer'
[ ... env target target ]
DUK_TOK_LOR
DUK_OP_DECLVAR flags in A; bottom bits are reserved for propdesc flags (DUK_PROPDESC_FLAG_XXX)
Day-of-month is one-based in the API, but zero-based
* internally, so fix here. Note that month is zero-based
* both in the API and internally.
The coercion order must match the ToPropertyDescriptor() algorithm
* so that side effects in coercion happen in the correct order.
* (This order also happens to be compatible with duk_def_prop(),
* although it doesn't matter in practice.)
triggers garbage digit check below
relevant array index is non-configurable, blocks write
comment: the NaN variant we use
label: code-design
* Compact the function template.
PRIMARY EXPRESSIONS
* indexOf(), lastIndexOf()
Sometimes this assert is not true right now; it will be true after
* rounding. See: test-bug-numconv-mantissa-assert.js.
Automatic error throwing, retval check.
Fast path for the case where the register
* is a number (e.g. loop counter).
always push some string
spare
Note: new_e_next matches pushed temp key count, and nothing can
* fail above between the push and this point.
* Heap flags
Object extra properties.
*
* There are some difference between function templates and functions.
* For example, function templates don't have .length and nargs is
* normally used to instantiate the functions.
We intentionally ignore the duk_safe_call() return value and only
* check the output type. This way we don't also need to check that
* the returned value is indeed a string in the success case.
* Arguments exotic behavior not possible for new properties: all
* magically bound properties are initially present in the arguments
* object, and if they are deleted, the binding is also removed from
* parameter map.
get_value
clear array part flag only after switching
'!'
tv1 points to value storage
Map DUK_HBUFFEROBJECT_ELEM_xxx to prototype object built-in index.
* Sync with duk_hbufferobject.h.
* Create "fallback" object to be used as the object instance,
* unless the constructor returns a replacement value.
* Its internal prototype needs to be set based on "prototype"
* property of the constructor.
Slightly modified "Bernstein hash" from:
*
* http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
*
* Modifications: string skipping and reverse direction similar to
* Lua 5.1.5, and different hash initializer.
*
* The reverse direction ensures last byte it always included in the
* hash which is a good default as changing parts of the string are
* more often in the suffix than in the prefix.
ascii fast path: avoid decoding utf-8
just in case
entry_top + 4
m- <- (* m- B)
UTC
no valstack space check
End of input (NUL) goes through slow path and causes SyntaxError.
[ ... enum_target res trap_result val ]
comment: XXX: unnecessary '%s' formatting here, but cannot use
* 'msg' as a format string directly.
label: code-design
ptr_curr_pc != NULL only when bytecode executor is active.
Restore entry thread executor curr_pc stack frame pointer.
Storing the entry top is cheaper here to ensure stack is correct at exit,
* as there are several paths out.
duk_hobject_set_length_zero(thr, func->h_funcs);
fall thru
see above
* Struct defines
[ ... name reg/null ] -> [ ... ]
mandatory if du.d is a NaN
duk_tval ptr for 'func' on stack (borrowed reference)
For tv1 == tv2, this is a no-op (no explicit check needed).
Use b[] to access the size of the union, which is strictly not
* correct. Can't use fixed size unless there's feature detection
* for pointer byte size.
local copy to avoid relookups
comment: XXX: this has some overlap with object inspection; remove this and make
* DumpHeap return lists of heapptrs instead?
label: code-design
Return to the bytecode executor caller which will unwind stacks.
* Return value is already on the stack top: [ ... retval ].
* Hobject Ecmascript [[Class]].
Handle one slow path unit (or finish if we're done).
comment: Copy the .buffer property, needed for TypedArray.prototype.subarray().
*
* XXX: limit copy only for TypedArray classes specifically?
label: code-design
DUK_HEAPHDR_HAS_FINALIZED may or may not be set.
enough to cover the whole mantissa
DUK_TOK_BXOR_EQ
comment:
* Hobject enumeration support.
*
* Creates an internal enumeration state object to be used e.g. with for-in
* enumeration. The state object contains a snapshot of target object keys
* and internal control state for enumeration. Enumerator flags allow caller
* to e.g. request internal/non-enumerable properties, and to enumerate only
* "own" properties.
*
* Also creates the result value for e.g. Object.keys() based on the same
* internal structure.
*
* This snapshot-based enumeration approach is used to simplify enumeration:
* non-snapshot-based approaches are difficult to reconcile with mutating
* the enumeration target, running multiple long-lived enumerators at the
* same time, garbage collection details, etc. The downside is that the
* enumerator object is memory inefficient especially for iterating arrays.
label: code-design
repl string scan
[key result] -> [result]
'\xffTracedata'
... and its 'message' from an instance property
AUTHORS.rst
Potential direct eval call detected, flag the CALL
* so that a run-time "direct eval" check is made and
* special behavior may be triggered. Note that this
* does not prevent 'eval' from being register bound.
prefer jump
comment:
* Arithmetic, binary, and logical helpers.
*
* Note: there is no opcode for logical AND or logical OR; this is on
* purpose, because the evalution order semantics for them make such
* opcodes pretty pointless: short circuiting means they are most
* comfortably implemented as jumps. However, a logical NOT opcode
* is useful.
*
* Note: careful with duk_tval pointers here: they are potentially
* invalidated by any DECREF and almost any API call. It's still
* preferable to work without making a copy but that's not always
* possible.
label: code-design
automatic length update
args
'String'
With ROM-based strings, heap->strs[] and thr->strs[] are omitted
* so nothing to initialize for strs[].
* Note: prototype chain is followed BEFORE first comparison. This
* means that the instanceof lval is never itself compared to the
* rval.prototype property. This is apparently intentional, see E5
* Section 15.3.5.3, step 4.a.
*
* Also note:
*
* js> (function() {}) instanceof Function
* true
* js> Function instanceof Function
* true
*
* For the latter, h_proto will be Function.prototype, which is the
* built-in Function prototype. Because Function.[[Prototype]] is
* also the built-in Function prototype, the result is true.
not a vararg function
Shouldn't happen but check anyway.
E5 Sections 11.8.3, 11.8.5; x <= y --> not (x > y) --> not (y < x)
Used by duk__emit*() calls so that we don't shuffle the loadints that
* are needed to handle indirect opcodes.
No strs[] pointer.
comment: XXX: assertion that entries >= old_len are already unused
label: code-design
e.g. DUK_OP_PREINCR
eat 'while'
nuke values at idx_retbase to get the first retval (initially
* at idx_rcbase) to idx_retbase
input radix
char: use int cast
result
exponent digit
comment: This is a cleaner approach and also produces smaller code than
* the other alternative. Use duk_require_string() for format
* safety (although the source property should always exist).
label: code-design
defprop_flags
s <- 2
spaces (nargs - 1) + newline
* Parse inner function
if accessor without getter, return value is undefined
comment:
* For non-ASCII strings, we need to scan forwards or backwards
* from some starting point. The starting point may be the start
* or end of the string, or some cached midpoint in the string
* cache.
*
* For "short" strings we simply scan without checking or updating
* the cache. For longer strings we check and update the cache as
* necessary, inserting a new cache entry if none exists.
label: code-design
XXX: len >= 0x80000000 won't work below because we need to be
* able to represent -len.
who resumed us (if any)
out_clamped==NULL -> RangeError if outside range
relookup after possible realloc
[ ... regexp_object escaped_source bytecode ]
m+ <- (* m+ B)
bytecode opcode (or extraop) for binary ops
forget temp
* Shared assignment expression handling
*
* args = (opcode << 8) + rbp
*
* If 'opcode' is DUK_OP_NONE, plain assignment without arithmetic.
* Syntactically valid left-hand-side forms which are not accepted as
* left-hand-side values (e.g. as in "f() = 1") must NOT cause a
* SyntaxError, but rather a run-time ReferenceError.
*
* When evaluating X <op>= Y, the LHS (X) is conceptually evaluated
* to a temporary first. The RHS is then evaluated. Finally, the
* <op> is applied to the initial value of RHS (not the value after
* RHS evaluation), and written to X. Doing so concretely generates
* inefficient code so we'd like to avoid the temporary when possible.
* See: https://github.com/svaarala/duktape/pull/992.
*
* The expression value (final LHS value, written to RHS) is
* conceptually copied into a fresh temporary so that it won't
* change even if the LHS/RHS values change in outer expressions.
* For example, it'd be generally incorrect for the expression value
* to be the RHS register binding, unless there's a guarantee that it
* won't change during further expression evaluation. Using the
* temporary concretely produces inefficient bytecode, so we try to
* avoid the extra temporary for some known-to-be-safe cases.
* Currently the only safe case we detect is a "top level assignment",
* for example "x = y + z;", where the assignment expression value is
* ignored.
* See: test-dev-assign-expr.js and test-bug-assign-mutate-gh381.js.
TRYCATCH, cannot emit now (not enough info)
Value stack slot limits: these are quite approximate right now, and
* because they overlap in control flow, some could be eliminated.
absolute position for digit considered for rounding
-> [ ... this timeval_new ]
TypeError if wrong; class check, see E5 Section 15.10.6
DUK_HOBJECT_FLAG_EXOTIC_DUKFUNC: omitted here intentionally
* Byte order. Important to self check, because on some exotic platforms
* there is no actual detection but rather assumption based on platform
* defines.
Both inputs are zero; cases where only one is zero can go
* through main algorithm.
same thread
'Boolean'
* Inside one or more 'with' statements fall back to slow path always.
* (See e.g. test-stmt-with.js.)
* Init the heap thread
XXX: need a duk_require_func_or_lfunc_coerce()
avoid referencing, invalidated
Don't support "straddled" source now.
* Object compaction.
*
* Compaction is assumed to never throw an error.
[ arg1 ... argN this loggerLevel loggerName ]
duk_tval intentionally skipped
* Since built-ins are not often extended, compact them.
* Compilation
Push a new ArrayBuffer (becomes view .buffer)
idx_start
Note: we rely on the _Varmap having a bunch of nice properties, like:
* - being compacted and unmodified during this process
* - not containing an array part
* - having correct value types
comment: XXX: return indication of "terminalness" (e.g. a 'throw' is terminal)
label: code-design
may be NULL if no constants or inner funcs
Equivalent year for DST calculations outside [1970,2038[ range, see
* E5 Section 15.9.1.8. Equivalent year has the same leap-year-ness and
* starts with the same weekday on Jan 1.
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
empty expressions can be detected conveniently with nud/led counts
There are at most 7 args, but we use 8 here so that also
* DUK_DATE_IDX_WEEKDAY gets initialized (to zero) to avoid the potential
* for any Valgrind gripes later.
[ ... val callback thisArg val i obj ]
[ ... this tracedata sep this str1 ... strN ]
important chosen base types
Digit count indicates number of fractions (i.e. an absolute
* digit index instead of a relative one). Used together with
* DUK_N2S_FLAG_FIXED_FORMAT for toFixed().
must also check refzero_list
MEMBER/NEW/CALL EXPRESSIONS
comment: XXX: add flag to indicate whether caller cares about return value; this
* affects e.g. handling of assignment expressions. This change needs API
* changes elsewhere too.
label: code-design
Fast jumps (which avoid longjmp) jump directly to the jump sites
* which are always known even while the iteration/switch statement
* is still being parsed. A final peephole pass "straightens out"
* the jumps.
[ ... func ]
* Function gets no new environment when called. This is the
* case for global code, indirect eval code, and non-strict
* direct eval code. There is no direct correspondence to the
* E5 specification, as global/eval code is not exposed as a
* function.
Wrappers for calling standard math library methods. These may be required
* on platforms where one or more of the math built-ins are defined as macros
* or inline functions and are thus not suitable to be used as function pointers.
comment: Throwing an error this deep makes the error rather vague, but
* saves hundreds of bytes of code.
label: code-design
This is not strictly necessary, but avoids compiler warnings; e.g.
* gcc won't reliably detect that no uninitialized data is read below.
Trigger at zero or below
Custom coercion for API
comment: Note: cannot read more than 24 bits without possibly shifting top bits out.
* Fixable, but adds complexity.
label: code-design
Almost all global level Function objects are constructable
* but not all: Function.prototype is a non-constructable,
* callable Function.
source ends before dest starts
* Statement terminator check, including automatic semicolon
* handling. After this step, 'curr_tok' should be the first
* token after a possible statement terminator.
* Exposed string-to-number API
*
* Input: [ string ]
* Output: [ number ]
*
* If number parsing fails, a NaN is pushed as the result. If number parsing
* fails due to an internal error, an InternalError is thrown.
64-bit OK because always >= 0
reg/const for switch value
comment: When formatting an argument to a string, errors may happen from multiple
* causes. In general we want to catch obvious errors like a toLogString()
* throwing an error, but we don't currently try to catch every possible
* error. In particular, internal errors (like out of memory or stack) are
* not caught. Also, we expect Error toString() to not throw an error.
label: code-design
Each round of finalizer execution may spawn new finalizable objects
* which is normal behavior for some applications. Allow multiple
* rounds of finalization, but use a shrinking limit based on the
* first round to detect the case where a runaway finalizer creates
* an unbounded amount of new finalizable objects. Finalizer rescue
* is not supported: the semantics are unclear because most of the
* objects being finalized here are already reachable. The finalizer
* is given a boolean to indicate that rescue is not possible.
*
* See discussion in: https://github.com/svaarala/duktape/pull/473
no prototype, updated below
unwind to 'resume' caller
0xf0-0xff
comment: XXX: missing trap result validation for non-configurable target keys
* (must be present), for non-extensible target all target keys must be
* present and no extra keys can be present.
* http://www.ecma-international.org/ecma-262/6.0/#sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys
label: code-design
comment: NOTE: lightfuncs are coerced to full functions because
* lightfuncs don't fit into a property value slot. This
* has some side effects, see test-dev-lightfunc-accessor.js.
label: code-design
IdentityEscape, with dollar added as a valid additional
* non-standard escape (see test-regexp-identity-escape-dollar.js).
* Careful not to match end-of-buffer (<0) here.
1st related value (type specific)
The caller is responsible for being sure that bytecode being loaded
* is valid and trusted. Invalid bytecode can cause memory unsafe
* behavior directly during loading or later during bytecode execution
* (instruction validation would be quite complex to implement).
*
* This signature check is the only sanity check for detecting
* accidental invalid inputs. The initial 0xFF byte ensures no
* ordinary string will be accepted by accident.
Shared object part
always throw ReferenceError for unresolvable
* Mark roots, hoping that recursion limit is not normally hit.
* If recursion limit is hit, run additional reachability rounds
* starting from "temproots" until marking is complete.
*
* Marking happens in two phases: first we mark actual reachability
* roots (and run "temproots" to complete the process). Then we
* check which objects are unreachable and are finalizable; such
* objects are marked as FINALIZABLE and marked as reachability
* (and "temproots" is run again to complete the process).
*
* The heap finalize_list must also be marked as a reachability root.
* There may be objects on the list from a previous round if the
* previous run had finalizer skip flag.
Shift to sign extend.
'^'
required_desc_flags
comment: Stack indices for better readability
label: code-design
* Try registers
no prototype or class yet
shadowed; update value
E5 Section 8.6.2 + custom classes
comment: Lookup current thread; use the stable 'entry_thread' for this to
* avoid clobber warnings. Any valid, reachable 'thr' value would be
* fine for this, so using 'entry_thread' is just to silence warnings.
label: code-design
RELATIONAL EXPRESSION
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property existence check right now.
These are just convenience "wiping" of state. Side effects should
* not be an issue here: thr->heap and thr->heap->lj have a stable
* pointer. Finalizer runs etc capture even out-of-memory errors so
* nothing should throw here.
Zero escape (also allowed in non-strict mode)
roughly 64 bytes
XXX: this doesn't actually work properly for tail calls, so
* tail calls are disabled when DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
* is in use.
* Dragon4 slow path (binary) digit generation.
* An extra digit is generated for rounding.
this is a bit approximate (errors out before max is reached); this is OK
comment:
* Parse a function-body-like expression (FunctionBody or Program
* in E5 grammar) using a two-pass parse. The productions appear
* in the following contexts:
*
* - function expression
* - function statement
* - function declaration
* - getter in object literal
* - setter in object literal
* - global code
* - eval code
* - Function constructor body
*
* This function only parses the statement list of the body; the argument
* list and possible function name must be initialized by the caller.
* For instance, for Function constructor, the argument names are originally
* on the value stack. The parsing of statements ends either at an EOF or
* a closing brace; this is controlled by an input flag.
*
* Note that there are many differences affecting parsing and even code
* generation:
*
* - Global and eval code have an implicit return value generated
* by the last statement; function code does not
*
* - Global code, eval code, and Function constructor body end in
* an EOF, other bodies in a closing brace ('}')
*
* Upon entry, 'curr_tok' is ignored and the function will pull in the
* first token on its own. Upon exit, 'curr_tok' is the terminating
* token (EOF or closing brace).
label: code-design
When torture not enabled, can just use the same helper because
* 'reg' won't get spilled.
Note: actual update happens once write has been completed
* without error below. The write should always succeed
* from a specification viewpoint, but we may e.g. run out
* of memory. It's safer in this order.
Convert buffer to result string.
default prototype (Note: 'thr' must be reachable)
we know these because enum objects are internally created
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
comment: Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to do an indirect eval instead.
label: code-design
1 = num actual 'return values'
should never happen
'-' verbatim
Regexp tokens
avoid attempt to compact the current object
DUK_TOK_TRUE
idx_bottom and idx_retval are only used for book-keeping of
* Ecmascript-initiated calls, to allow returning to an Ecmascript
* function properly. They are duk_size_t to match the convention
* that value stack sizes are duk_size_t and local frame indices
* are duk_idx_t.
comment: This loop is optimized for size. For speed, there should be
* two separate loops, and we should ensure that memcmp() can be
* used without an extra "will searchstring fit" check. Doing
* the preconditioning for 'p' and 'p_end' is easy but cpos
* must be updated if 'p' is wound back (backward scanning).
label: code-design
min(incl)
may be equal
traceback depth ensures fits into 16 bits
* Get the values onto the stack first. It would be possible to cover
* some normal cases without resorting to the value stack.
*
* The right hand side could be a light function (as they generally
* behave like objects). Light functions never have a 'prototype'
* property so E5.1 Section 15.3.5.3 step 3 always throws a TypeError.
* Using duk_require_hobject() is thus correct (except for error msg).
DUK_TOK_GET
* Various
Module has now evaluated to a wrapped module function. Force its
* .name to match module.name (defaults to last component of resolved
* ID) so that it is shown in stack traces too. Note that we must not
* introduce an actual name binding into the function scope (which is
* usually the case with a named function) because it would affect the
* scope seen by the module and shadow accesses to globals of the same name.
* This is now done by compiling the function as anonymous and then forcing
* its .name without setting a "has name binding" flag.
Characters outside BMP cannot be escape()'d. We could
* encode them as surrogate pairs (for codepoints inside
* valid UTF-8 range, but not extended UTF-8). Because
* escape() and unescape() are legacy functions, we don't.
trailer
* Check whether we need to abandon an array part (if it exists)
[... env callee]
comment: These is not 100% because format would need to be non-portable "long long".
* Also print out as doubles to catch cases where the "long" type is not wide
* enough; the limits will then not be printed accurately but the magnitude
* will be correct.
label: code-design
an Ecmascript function
comment: avoid pressure to add/remove strings, invalidation of call data argument, etc.
label: code-design
end of bytecode
key is 'length', cannot match argument exotic behavior
* First check whether property exists; if not, simple case. This covers
* steps 1-4.
* Do-while statement is mostly trivial, but there is special
* handling for automatic semicolon handling (triggered by the
* DUK__ALLOW_AUTO_SEMI_ALWAYS) flag related to a bug filed at:
*
* https://bugs.ecmascript.org/show_bug.cgi?id=8
*
* See doc/compiler.rst for details.
must be found: was found earlier, and cannot be inherited
Input value should be on stack top and will be coerced and
* popped. Refuse to update an Array's 'length' to a value
* outside the 32-bit range. Negative zero is accepted as zero.
shift in zeroes
free object and all auxiliary (non-heap) allocs
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Returns NULL for a lightfunc.
bytes in dest
stack[0] = regexp
* stack[1] = string
flags
Check for maximum buffer length.
'Thread'
comment: Pointer to bytecode executor's 'curr_pc' variable. Used to copy
* the current PC back into the topmost activation when activation
* state is about to change (or "syncing" is otherwise needed). This
* is rather awkward but important for performance, see execution.rst.
label: code-design
The Quote(value) operation: quote a string.
*
* Stack policy: [ ] -> [ ].
Output #2: last component name
tc1 = false, tc2 = false
0
Exponent without a sign or with a +/- sign is accepted
* by all call sites (even JSON.parse()).
0x90-0x9f
comment: XXX: Shuffling support could be implemented here so that LDINT+LDINTX
* would only shuffle once (instead of twice). The current code works
* though, and has a smaller compiler footprint.
label: code-design
* Write to entry part
To use the shared helper need the virtual index.
* Slow delete, but we don't care as we're already in a very slow path.
* The delete always succeeds: key has no exotic behavior, property
* is configurable, and no resize occurs.
LAYOUT 1
For len == 0, i is initialized to len - 1 which underflows.
* The condition (i < len) will then exit the for-loop on the
* first round which is correct. Similarly, loop termination
* happens by i underflowing.
Raw internal valstack access macros: access is unsafe so call site
* must have a guarantee that the index is valid. When that is the case,
* using these macro results in faster and smaller code than duk_get_tval().
* Both 'ctx' and 'idx' are evaluted multiple times, but only for asserts.
* Node.js Buffer.isEncoding()
array entries are all plain values
comment: Buffer values are encoded in (lowercase) hex to make the
* binary data readable. Base64 or similar would be more
* compact but less readable, and the point of JX/JC
* variants is to be as useful to a programmer as possible.
label: code-design
comment: XXX: the helper currently assumes stack top contains new
* 'length' value and the whole calling convention is not very
* compatible with what we need.
label: code-design
Coerce to number before validating pointers etc so that the
* number coercions in duk_hbufferobject_validated_write() are
* guaranteed to be side effect free and not invalidate the
* pointer checks we do here.
Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is
* decreased by each (re)allocation attempt (regardless of size), and each
* refzero processed object.
*
* 'SKIP' indicates how many (re)allocations to wait until a retry if
* GC is skipped because there is no thread do it with yet (happens
* only during init phases).
XXX: assert 'c' is an enumerator
two special escapes: '\' and '"', other printables as is
for indexOf, ToInteger(undefined) would be 0, i.e. correct, but
* handle both indexOf and lastIndexOf specially here.
DUK_USE_AUGMENT_ERROR_THROW
* Exponent notation for non-base-10 numbers isn't specified in Ecmascript
* specification, as it never explicitly turns up: non-decimal numbers can
* only be formatted with Number.prototype.toString([radix]) and for that,
* behavior is not explicitly specified.
*
* Logical choices include formatting the exponent as decimal (e.g. binary
* 100000 as 1e+5) or in current radix (e.g. binary 100000 as 1e+101).
* The Dragon4 algorithm (in the original paper) prints the exponent value
* in the target radix B. However, for radix values 15 and above, the
* exponent separator 'e' is no longer easily parseable. Consider, for
* instance, the number "1.faecee+1c".
Template functions are not strictly constructable (they don't
* have a "prototype" property for instance), so leave the
* DUK_HOBJECT_FLAG_CONSRUCTABLE flag cleared here.
comment: Most practical strings will go here.
label: code-design
non-strict eval: env is caller's env or global env (direct vs. indirect call)
* global code: env is is global env
comment: XXX: use the exactly same arithmetic function here as in executor
label: code-design
-> [ ... lval new_rval ]
sep (even before first one)
comment: XXX: use advancing pointers instead of index macros -> faster and smaller?
label: code-design
0x7F is special
IEEE requires that zeros compare the same regardless
* of their signed, so if both x and y are zeroes, they
* are caught above.
Signed integers always map to 4 bytes now.
Resolve Proxy targets until Proxy chain ends. No explicit check for
* a Proxy loop: user code cannot create such a loop without tweaking
* internal properties directly.
estimate is valid
Note: it's nice if size is 2^N (not 4x4 = 16 bytes on 32 bit)
always true, arg is unsigned
ArrayBuffer: unlike any other argument variant, create
* a view into the existing buffer.
DUK_TOK_DO
* Slow path: potentially requires function calls for coercion
'ArrayBuffer'
Initialize index so that we skip internal control keys.
flags have been already cleared
* ArrayBuffer, DataView, and TypedArray constructors
comment:
* XXX: for now, indicate that an expensive catch binding
* declarative environment is always needed. If we don't
* need it, we don't need the const_varname either.
label: code-design
-> [ ... this timeval_new timeval_new ]
DUK_TOK_CONST
comment: XXX: unnecessary copying of values? Just set 'top' to
* b + c, and let the return handling fix up the stack frame?
label: code-design
Slot C
comment: Array is dense and contains only strings, but ASIZE may
* be larger than used part and there are UNUSED entries.
label: code-design
At least: ... [err]
wrapped
whole or fraction digit
* Constructor calls
only 'length'
DUK_USE_DEBUGGER_DUMPHEAP
'toISOString'
'res' contains expression value
No other escape beginning with a digit in strict mode
comment: Use Murmurhash2 directly for short strings, and use "block skipping"
* for long strings: hash an initial part and then sample the rest of
* the string with reasonably sized chunks. An initial offset for the
* sampling is computed based on a hash of the initial part of the string;
* this is done to (usually) avoid the case where all long strings have
* certain offset ranges which are never sampled.
*
* Skip should depend on length and bound the total time to roughly
* logarithmic. With current values:
*
* 1M string => 256 * 241 = 61696 bytes (0.06M) of hashing
* 1G string => 256 * 16321 = 4178176 bytes (3.98M) of hashing
*
* XXX: It would be better to compute the skip offset more "smoothly"
* instead of having a few boundary values.
label: code-design
[key setter this val key] -> [key retval]
point to start of 'reserved area'
Shared helper for match() steps 3-4, search() steps 3-4.
dummy
Just call the "original" Object.defineProperties() to
* finish up.
Although these could be parsed as PatternCharacters unambiguously (here),
* E5 Section 15.10.1 grammar explicitly forbids these as PatternCharacters.
line terminator will be handled on next round
* Debug dumping
x in [2**31, 2**32[
Error path.
if a site already exists, nop: max one label site per statement
Flag ORed to err_code to indicate __FILE__ / __LINE__ is not
* blamed as source of error for error fileName / lineNumber.
Start in paused state.
comment: XXX: much to improve (code size)
label: code-design
[ regexp string res_arr ]
range conversion with a "skip"
comment: Update function min/max line from current token. Needed to improve
* function line range information for debugging, so that e.g. opening
* curly brace is covered by line range even when no opcodes are emitted
* for the line containing the brace.
label: code-design
* Regular expression structs, constants, and bytecode defines.
comment: should never be zero, because we (Duktape.Thread.yield) are on the stack
label: code-design
comment: XXX: This will now return false for non-numbers, even though they would
* coerce to NaN (as a general rule). In particular, duk_get_number()
* returns a NaN for non-numbers, so should this function also return
* true for non-numbers?
label: code-design
comment: The handler is looked up with a normal property lookup; it may be an
* accessor or the handler object itself may be a proxy object. If the
* handler is a proxy, we need to extend the valstack as we make a
* recursive proxy check without a function call in between (in fact
* there is no limit to the potential recursion here).
*
* (For sanity, proxy creation rejects another proxy object as either
* the handler or the target at the moment so recursive proxy cases
* are not realized now.)
label: code-design
Flag handling currently assumes that flags are consistent. This is OK
* because the call sites are now strictly controlled.
DUK_TOK_DEFAULT
[key value] or [key undefined]
Pad significand with "virtual" zero digits so that Dragon4 will
* have enough (apparent) precision to work with.
* Set lexer input position and reinitialize lookup window.
nargs
With lightfuncs, act 'func' may be NULL
return '(?:)'
DUK_USE_REFZERO_FINALIZER_TORTURE
next to use, highest used is top - 1
comment: XXX: actually single step levels would work just fine, clean up
label: code-design
* DUK_CALL_FLAG_IGNORE_RECLIMIT causes duk_handle_call() to ignore C
* recursion depth limit (and won't increase it either). This is
* dangerous, but useful because it allows the error handler to run
* even if the original error is caused by C recursion depth limit.
*
* The heap level DUK_HEAP_FLAG_ERRHANDLER_RUNNING is set for the
* duration of the error handler and cleared afterwards. This flag
* prevents the error handler from running recursively. The flag is
* heap level so that the flag properly controls even coroutines
* launched by an error handler. Since the flag is heap level, it is
* critical to restore it correctly.
*
* We ignore errors now: a success return and an error value both
* replace the original error value. (This would be easy to change.)
comment: XXX: remove heap->dbg_exec_counter, use heap->inst_count_interrupt instead?
label: code-design
DUK_USE_JSON_DECSTRING_FASTPATH
The actual detached_cb call is postponed to message loop so
* we don't need any special precautions here (just skip to EOM
* on the already closed connection).
arg2 would be clobbered so reassign it to a temp.
standard behavior, step 3.f.i
avoid degenerate cases, so that (len - 1) won't underflow
Note: %06d for positive value, %07d for negative value to include
* sign and 6 digits.
'let'
* Halt execution helper
1110 xxxx; 3 bytes
ch1 = (r_increment << 8) + byte
variable name reg/const, if variable not register-bound
Cast converts magic to 16-bit signed value
* Remove the object from the refzero list. This cannot be done
* before a possible finalizer has been executed; the finalizer
* may trigger a mark-and-sweep, and mark-and-sweep must be able
* to traverse a complete refzero_list.
Argument variants. When the argument is an ArrayBuffer a view to
* the same buffer is created; otherwise a new ArrayBuffer is always
* created.
entry part size
* Property not found in prototype chain.
function executes in strict mode
'data' is reachable through every compiled function which
* contains a reference.
Caller must trigger recomputation of active breakpoint list. To
* ensure stale values are not used if that doesn't happen, clear the
* active breakpoint list here.
* Longjmp types, also double as identifying continuation type for a rethrow (in 'finally')
note: long live range
* Object will be kept; queue object back to heap_allocated (to tail)
no change
DUK_USE_ASSERTIONS
force the property to 'undefined' to create a slot for it
Optimized for speed.
comment: prevent multiple in-progress detaches
label: requirement
Set a high interrupt counter; the original executor
* interrupt invocation will rewrite before exiting.
DUK_TOK_THIS
index
* Expression parsing: duk__expr_nud(), duk__expr_led(), duk__expr_lbp(), and helpers.
*
* - duk__expr_nud(): ("null denotation"): process prev_token as a "start" of an expression (e.g. literal)
* - duk__expr_led(): ("left denotation"): process prev_token in the "middle" of an expression (e.g. operator)
* - duk__expr_lbp(): ("left-binding power"): return left-binding power of curr_token
3-letter log level strings
comment:
* Convert char offset to byte offset
*
* Avoid using the string cache if possible: for ASCII strings byte and
* char offsets are equal and for short strings direct scanning may be
* better than using the string cache (which may evict a more important
* entry).
*
* Typing now assumes 32-bit string byte/char offsets (duk_uint_fast32_t).
* Better typing might be to use duk_size_t.
label: code-design
Must prevent finalizers which may have arbitrary side effects.
DUK_EXCEPTION_H_INCLUDED
invalidates h_buf pointer
Special case: original qmin was zero so there is nothing
* to repeat. Emit an atom copy but jump over it here.
comment: Higher footprint, less churn.
label: code-design
-> [ ... holder name val new_elem ]
NUL term or -1 (EOF), NUL check would suffice
core property functions
25%, i.e. less than 25% used -> abandon
Allow empty fraction (e.g. "123.")
0xf0...0xff
don't allow const
this is just beneath bottom
* Duktape.Buffer: constructor
'Uint8Array'
* Helpers for writing multiple properties
exhaustive
refcounting requires direct heap frees, which in turn requires a dual linked heap
lastIndexOf() needs to be a vararg function because we must distinguish
* between an undefined fromIndex and a "not given" fromIndex; indexOf() is
* made vararg for symmetry although it doesn't strictly need to be.
[ ... error ]
XXX: share final setting code for value and flags? difficult because
* refcount code is different. Share entry allocation? But can't allocate
* until array index checked.
Terminating conditions. For fixed width output, we just ignore the
* terminating conditions (and pretend that tc1 == tc2 == false). The
* the current shortcut for fixed-format output is to generate a few
* extra digits and use rounding (with carry) to finish the output.
Return value when returning to this activation (points to caller
* reg, not callee reg); index is absolute (only set if activation is
* not topmost).
*
* Note: idx_bottom is always set, while idx_retval is only applicable
* for activations below the topmost one. Currently idx_retval for
* the topmost activation is considered garbage (and it not initialized
* on entry or cleared on return; may contain previous or garbage
* values).
Unlike non-obsolete String calls, substr() algorithm in E5.1
* specification will happily coerce undefined and null to strings
* ("undefined" and "null").
DecimalEscape, only \0 is allowed, no leading zeroes are allowed
parse new token
1e9
Negative value checked so that a "time jump" works
* reasonably.
*
* Same interval is now used for status sending and
* peeking.
* Misc shared helpers.
don't set 'n' at all, inherited value is used as name
';'
switch cmd
comment: XXX: could add a fast path to process chunks of input codepoints,
* but relative benefit would be quite small.
label: code-design
Copy interrupt counter/init value state to new thread (if any).
* It's OK for new_thr to be the same as curr_thr.
User totalLength overrides a computed length, but we'll check
* every copy in the copy loop. Note that duk_to_uint() can
* technically have arbitrary side effects so we need to recheck
* the buffers in the copy loop.
comment: XXX: some overlapping code; cleanup
label: code-design
stack[0] = searchElement
* stack[1] = fromIndex
* stack[2] = object
* stack[3] = length (not needed, but not popped above)
from curr pc
* Maximum size check
isError flag for yield
* callstack_top - 1 --> this function
* callstack_top - 2 --> caller (may not exist)
*
* If called directly from C, callstack_top might be 1. If calling
* activation doesn't exist, call must be indirect.
no need to unwind callstack
* Array part
comment:
* Number should already be in NaN-normalized form,
* but let's normalize anyway.
label: code-design
[ array totalLength bufres buf ]
When src_size == 0, src_data may be NULL (if source
* buffer is dynamic), and dst_data may be NULL (if
* target buffer is dynamic). Avoid zero-size memcpy()
* with an invalid pointer.
[r1,r2] is the range
* NormalizePropertyDescriptor() related helper.
*
* Internal helper which validates and normalizes a property descriptor
* represented as an Ecmascript object (e.g. argument to defineProperty()).
* The output of this conversion is a set of defprop_flags and possibly
* some values pushed on the value stack; some subset of: property value,
* getter, setter. Caller must manage stack top carefully because the
* number of values pushed depends on the input property descriptor.
*
* The original descriptor object must not be altered in the process.
duk_handle_call / duk_handle_safe_call recursion depth limiting
DUK_HOBJECT_FLAG_NEWENV: handled below
A leading digit is not required in some cases, e.g. accept ".123".
* In other cases (JSON.parse()) a leading digit is required. This
* is checked for after the loop.
common case, already closed, so skip
ignore millisecond fractions after 3
* unshift()
E5 Section 10.4.3
No built-in functions are constructable except the top
* level ones (Number, etc).
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed,
* and we're in an infinite loop.
Raw helper for getting a value from the stack, checking its tag.
* The tag cannot be a number because numbers don't have an internal
* tag in the packed representation.
Bernstein hash init value is normally 5381
* DECLVAR
*
* See E5 Sections:
* 10.4.3 Entering Function Code
* 10.5 Declaration Binding Instantion
* 12.2 Variable Statement
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
*
* Variable declaration behavior is mainly discussed in Section 10.5,
* and is not discussed in the execution semantics (Sections 11-13).
*
* Conceptually declarations happen when code (global, eval, function)
* is entered, before any user code is executed. In practice, register-
* bound identifiers are 'declared' automatically (by virtue of being
* allocated to registers with the initial value 'undefined'). Other
* identifiers are declared in the function prologue with this primitive.
*
* Since non-register bindings eventually back to an internal object's
* properties, the 'prop_flags' argument is used to specify binding
* type:
*
* - Immutable binding: set DUK_PROPDESC_FLAG_WRITABLE to false
* - Non-deletable binding: set DUK_PROPDESC_FLAG_CONFIGURABLE to false
* - The flag DUK_PROPDESC_FLAG_ENUMERABLE should be set, although it
* doesn't really matter for internal objects
*
* All bindings are non-deletable mutable bindings except:
*
* - Declarations in eval code (mutable, deletable)
* - 'arguments' binding in strict function code (immutable)
* - Function name binding of a function expression (immutable)
*
* Declarations may go to declarative environment records (always
* so for functions), but may also go to object environment records
* (e.g. global code). The global object environment has special
* behavior when re-declaring a function (but not a variable); see
* E5.1 specification, Section 10.5, step 5.e.
*
* Declarations always go to the 'top-most' environment record, i.e.
* we never check the record chain. It's not an error even if a
* property (even an immutable or non-deletable one) of the same name
* already exists.
*
* If a declared variable already exists, its value needs to be updated
* (if possible). Returns 1 if a PUTVAR needs to be done by the caller;
* otherwise returns 0.
comment: duk_handle_call_xxx: call ignores C recursion limit (for errhandler calls)
label: code-design
expt 0xfff is infinite/nan
Augment the error if called as a normal function. __FILE__ and __LINE__
* are not desirable in this case.
%s
e.g. "x" < "xx"
comment: XXX: for fastints, could use a variant which assumes a double duk_tval
* (and doesn't need to check for fastint again).
label: code-design
SameValue
How much stack to require on entry to object/array encode
* Parse code after the clause. Possible terminators are
* 'case', 'default', and '}'.
*
* Note that there may be no code at all, not even an empty statement,
* between case clauses. This must be handled just like an empty statement
* (omitting seemingly pointless JUMPs), to avoid situations like
* test-bug-case-fallthrough.js.
... name ': ' message
to exit
parenthesis count, 0 = top level
* Useful Unicode codepoints
*
* Integer constants must be signed to avoid unexpected coercions
* in comparisons.
input string (may be a user pointer)
* round_idx points to the digit which is considered for rounding; the
* digit to its left is the final digit of the rounded value. If round_idx
* is zero, rounding will be performed; the result will either be an empty
* rounded value or if carry happens a '1' digit is generated.
Careful with carry condition:
* - If carry not added: 0x12345678 + 0 + 0xffffffff = 0x12345677 (< 0x12345678)
* - If carry added: 0x12345678 + 1 + 0xffffffff = 0x12345678 (== 0x12345678)
shared helper
* Fast buffer writer with spare management.
success/error path both do this
DUK_TOK_MUL
attempt to change from accessor to data property
allowed ascii whitespace
[ ... source? filename? ]
continue jump
-> [ ... key val ]
Prepare value stack for a method call through an object property.
* May currently throw an error e.g. when getting the property.
no need to create environment record now; leave as NULL
* Thread state check and book-keeping.
"/=" and not in regexp mode
for lastIndexOf, result may be -1 (mark immediate termination)
fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently
* done.
requested identifier
Function expression. Note that any statement beginning with 'function'
* is handled by the statement parser as a function declaration, or a
* non-standard function expression/statement (or a SyntaxError). We only
* handle actual function expressions (occurring inside an expression) here.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
* JSON.stringify() fast path
*
* Otherwise supports full JSON, JX, and JC features, but bails out on any
* possible side effect which might change the value being serialized. The
* fast path can take advantage of the fact that the value being serialized
* is unchanged so that we can walk directly through property tables etc.
comment: XXX: helper
label: code-design
no return value -> don't replace created value
'Arguments' object and has arguments exotic behavior (non-strict callee)
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded Duktape.modLoaded[id] ]
Note: left shift, should mask
31 to 36
two level break
don't allow an empty match at the end of the string
'thr' is now reachable
Parse argument list. Arguments are written to temps starting from
* "next temp". Returns number of arguments parsed. Expects left paren
* to be already eaten, and eats the right paren before returning.
Allow 'Infinity'
Opcode slot C is used in a non-standard way, so shuffling
* is not allowed.
* Helpers for managing property storage size
if-digit-else-ctrl
Safe write calls which will ensure space first.
having this as a separate function provided a size benefit
code emission
comment:
* obj->props is intentionally left as NULL, and duk_hobject_props.c must deal
* with this properly. This is intentional: empty objects consume a minimum
* amount of memory. Further, an initial allocation might fail and cause
* 'obj' to "leak" (require a mark-and-sweep) since it is not reachable yet.
label: code-design
Term was '..', backtrack resolved name by one component.
* q[-1] = previous slash (or beyond start of buffer)
* q[-2] = last char of previous component (or beyond start of buffer)
comment: This could also be thrown internally (set the error, goto check_longjmp),
* but it's better for internal errors to bubble outwards so that we won't
* infinite loop in this catchpoint.
label: code-design
* Debugging related API calls
-> [ ... func this arg1 ... argN _Args length ]
'Float64Array'
1 1 1 <32 bits>
* Encode in two parts to avoid bitencode 24-bit limitation
-> [ this ]
comment: Note: array entries are always writable, so the writability check
* above is pointless for them. The check could be avoided with some
* refactoring but is probably not worth it.
label: code-design
retval indicates delete failed
formatters always get one-based month/day-of-month
continue matching, set neg_tzoffset flag
bound function chain has already been resolved
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property get right now.
standard JSON; array gaps
Note: array part values are [[Writable]], [[Enumerable]],
* and [[Configurable]] which matches the required attributes
* here.
0=before period/exp,
* 1=after period, before exp
* 2=after exp, allow '+' or '-'
* 3=after exp and exp sign
just check 'env'
comment: XXX: primitive to make array from valstack slice
label: code-design
comment:
* Dragon4 setup.
*
* Convert double from IEEE representation for conversion;
* normal finite values have an implicit leading 1-bit. The
* slow path algorithm doesn't handle zero, so zero is special
* cased here but still creates a valid nc_ctx, and goes
* through normal formatting in case special formatting has
* been requested (e.g. forced exponential format: 0 -> "0e+0").
label: code-design
consistency requires this
DUK_TOK_CASE
Nothing to initialize, strs[] is in ROM.
currently 6 characters of lookup are actually needed (duk_lexer.c)
index/length check guarantees
left.x1 -> res.x1
* Case conversion tables generated using src/extract_caseconv.py.
is global code
comment:
* Macros to set a duk_tval and update refcount of the target (decref the
* old value and incref the new value if necessary). This is both performance
* and footprint critical; any changes made should be measured for size/speed.
label: code-design
We don't duk_require_stack() here now, but rely on the caller having
* enough space.
* Regexp executor.
*
* Safety: the Ecmascript executor should prevent user from reading and
* replacing regexp bytecode. Even so, the executor must validate all
* memory accesses etc. When an invalid access is detected (e.g. a 'save'
* opcode to invalid, unallocated index) it should fail with an internal
* error but not cause a segmentation fault.
*
* Notes:
*
* - Backtrack counts are limited to unsigned 32 bits but should
* technically be duk_size_t for strings longer than 4G chars.
* This also requires a regexp bytecode change.
Note: not a valid stack index if num_stack_args == 0
* Convenience (independent of representation)
no refcounting
duk_handle_ecma_call_setup: setup for a resume()
escape any non-ASCII characters
if 0, 'str' used, if > 0, 'strlist' used
These limits are based on bytecode limits. Max temps is limited
* by duk_hcompiledfunction nargs/nregs fields being 16 bits.
* pop(), push()
'DecEnv'
number of elements guaranteed to be user accessible
* (in addition to call arguments) on Duktape/C function entry.
NOTE: The Array special behaviors are NOT invoked by duk_xdef_prop_index()
* (which differs from the official algorithm). If no error is thrown, this
* doesn't matter as the length is updated at the end. However, if an error
* is thrown, the length will be unset. That shouldn't matter because the
* caller won't get a reference to the intermediate value.
Torture option to shake out finalizer side effect issues:
* make a bogus function call for every finalizable object,
* essentially simulating the case where everything has a
* finalizer.
[ ... key ]
comment: This seems faster than emitting bytes one at a time and
* then potentially rewinding.
label: code-design
* Writability check
may be changed by call
DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
DUK_USE_JSON_STRINGIFY_FASTPATH
Update all labels with matching label_id.
guaranteed by duk_to_string()
DUK_USE_TRACEBACKS
comment: Formatting function pointers is tricky: there is no standard pointer for
* function pointers and the size of a function pointer may depend on the
* specific pointer type. This helper formats a function pointer based on
* its memory layout to get something useful on most platforms.
label: code-design
ensures callstack_top - 1 >= 0
Count free operations toward triggering a GC but never actually trigger
* a GC from a free. Otherwise code which frees internal structures would
* need to put in NULLs at every turn to ensure the object is always in
* consistent state for a mark-and-sweep.
detached
'constructor'
disabled for now
idx_replacer
type to represent a straight register reference, with <0 indicating none
continue jump not patched, an INVALID opcode remains there
-> [ ... enum_target res trap_result ]
current (next) array index
fmin() with args -0 and +0 is not guaranteed to return
* -0 as Ecmascript requires.
'const'
all codepoints up to U+10FFFF
comment: This is performance critical because it's needed for every DECREF.
* Take advantage of the fact that the first heap allocated tag is 8,
* so that bit 3 is set for all heap allocated tags (and never set for
* non-heap-allocated tags).
label: code-design
if no NaN handling flag, may still be NaN here, but not Inf
thr argument only used for thr->heap, so specific thread doesn't matter
Preshifted << 4. Must use 16-bit entry to allow negative value signaling.
[0x00000000, 0xffffffff]
fall through to error
[ ... key_obj key key ]
Specification stripPrefix maps to DUK_S2N_FLAG_ALLOW_AUTO_HEX_INT.
*
* Don't autodetect octals (from leading zeroes), require user code to
* provide an explicit radix 8 for parsing octal. See write-up from Mozilla:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation
Process messages until we're no longer paused or we peek
* and see there's nothing to read right now.
XXX: callstack unwind may now throw an error when closing
* scopes; this is a sandboxing issue, described in:
* https://github.com/svaarala/duktape/issues/476
since no recursive error handler calls
comment: XXX: other properties of function instances; 'arguments', 'caller'.
label: code-design
numeric label_id (-1 reserved as marker)
irrelevant when out->value == NULL
Avoid fake finalization when callstack limit has been reached.
* Otherwise a callstack limit error will be created, then refzero'ed.
comment:
* Helper to sort array index keys. The keys are in the enumeration object
* entry part, starting from DUK__ENUM_START_INDEX, and the entry part is dense.
*
* We use insertion sort because it is simple (leading to compact code,)
* works nicely in-place, and minimizes operations if data is already sorted
* or nearly sorted (which is a very common case here). It also minimizes
* the use of element comparisons in general. This is nice because element
* comparisons here involve re-parsing the string keys into numbers each
* time, which is naturally very expensive.
*
* Note that the entry part values are all "true", e.g.
*
* "1" -> true, "3" -> true, "2" -> true
*
* so it suffices to only work in the key part without exchanging any keys,
* simplifying the sort.
*
* http://en.wikipedia.org/wiki/Insertion_sort
*
* (Compiles to about 160 bytes now as a stand-alone function.)
label: code-design
The function object is now reachable and refcounts are fine,
* so we can pop off all the temporaries.
Care must be taken to avoid pointer wrapping in the index
* validation. For instance, on a 32-bit platform with 8-byte
* duk_tval the index 0x20000000UL would wrap the memory space
* once.
Convert a duk_tval fastint (caller checks) to a 32-bit index.
Insert bytes in the middle of the buffer from a slice already
* in the buffer. Source offset is interpreted "before" the operation.
DUK_USE_STRTAB_CHAIN
Original function instance/template had NAMEBINDING.
* Must create a lexical environment on loading to allow
* recursive functions like 'function foo() { foo(); }'.
comment: the message should be a compile time constant without formatting (less risk);
* we don't care about assertion text size because they're not used in production
* builds.
label: code-design
assume value is a number
comment: combines steps 3, 6; step 7 is not needed
label: requirement
* Debugger support
comment: XXX: spare handling, slow now
label: code-design
normal and constructor calls have identical semantics
* A token is interpreted as any possible production of InputElementDiv
* and InputElementRegExp, see E5 Section 7 in its entirety. Note that
* the E5 "Token" production does not cover all actual tokens of the
* language (which is explicitly stated in the specification, Section 7.5).
* Null and boolean literals are defined as part of both ReservedWord
* (E5 Section 7.6.1) and Literal (E5 Section 7.8) productions. Here,
* null and boolean values have literal tokens, and are not reserved
* words.
*
* Decimal literal negative/positive sign is -not- part of DUK_TOK_NUMBER.
* The number tokens always have a non-negative value. The unary minus
* operator in "-1.0" is optimized during compilation to yield a single
* negative constant.
*
* Token numbering is free except that reserved words are required to be
* in a continuous range and in a particular order. See genstrings.py.
Same coercion behavior as for Number.
the outer loop will recheck and exit
comment: These are macros for now, but could be separate functions to reduce code
* footprint (check call site count before refactoring).
label: code-design
x == -Infinity
[ ... source? func_template ]
other call
lastIndex already set up for next match
* Macros to access the 'props' allocation.
comment:
* Struct size/alignment if platform requires it
*
* There are some compiler specific struct padding pragmas etc in use, this
* selftest ensures they're correctly detected and used.
label: code-design
[ ... source? filename? ] (depends on flags)
ToUint16() coercion is mandatory in the E5.1 specification, but
* this non-compliant behavior makes more sense because we support
* non-BMP codepoints. Don't use CESU-8 because that'd create
* surrogate pairs.
match string
[ targetBuffer targetStart sourceStart sourceEnd ]
x = sign(x) * floor(abs(x)), i.e. truncate towards zero, keep sign
comment: XXX: here again finalizer thread is the heap_thread which needs
* to be coordinated with finalizer thread fixes.
label: code-design
at least one opcode emitted
Slice offsets are element (not byte) offsets, which only matters
* for TypedArray views, Node.js Buffer and ArrayBuffer have shift
* zero so byte and element offsets are the same. Negative indices
* are counted from end of slice, crossed indices are allowed (and
* result in zero length result), and final values are clamped
* against the current slice. There's intentionally no check
* against the underlying buffer here.
side effects, in theory (referenced by global env)
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
additional flags which are passed in the same flags argument as property
* flags but are not stored in object properties.
comment: XXX: Is this INCREF necessary? 'func' is always a borrowed
* reference reachable through the value stack? If changed, stack
* unwind code also needs to be fixed to match.
label: code-design
comment: XXX: shared decoding of 'b' and 'c'?
label: code-design
comment: The fast path for array property put is not fully compliant:
* If one places conflicting number-indexed properties into
* Array.prototype (for example, a non-writable Array.prototype[7])
* the fast path will incorrectly ignore them.
*
* This fast path could be made compliant by falling through
* to the slow path if the previous value was UNUSED. This would
* also remove the need to check for extensibility. Right now a
* non-extensible array is slower than an extensible one as far
* as writes are concerned.
*
* The fast path behavior is documented in more detail here:
* tests/ecmascript/test-misc-array-fast-write.js
label: code-design
comment: XXX: because we unwind stacks above, thr->heap->curr_thread is at
* risk of pointing to an already freed thread. This was indeed the
* case in test-bug-multithread-valgrind.c, until duk_handle_call()
* was fixed to restore thr->heap->curr_thread before rethrowing an
* uncaught error.
label: code-design
Allow naked fraction (e.g. ".123")
* Rate limit check for sending status update or peeking into
* the debug transport. Both can be expensive operations that
* we don't want to do on every opcode.
*
* Making sure the interval remains reasonable on a wide variety
* of targets and bytecode is difficult without a timestamp, so
* we use a Date-provided timestamp for the rate limit check.
* But since it's also expensive to get a timestamp, a bytecode
* counter is used to rate limit getting timestamps.
>>> struct.unpack('>d', '4000112233445566'.decode('hex'))
* (2.008366013071895,)
Other longjmp types are handled by executor before propagating
* the error here.
* E5 Section 11.8.6 describes the main algorithm, which uses
* [[HasInstance]]. [[HasInstance]] is defined for only
* function objects:
*
* - Normal functions:
* E5 Section 15.3.5.3
* - Functions established with Function.prototype.bind():
* E5 Section 15.3.4.5.3
*
* For other objects, a TypeError is thrown.
*
* Limited Proxy support: don't support 'getPrototypeOf' trap but
* continue lookup in Proxy target if the value is a Proxy.
* Ecmascript/native function call or lightfunc call
Halt execution and enter a debugger message loop until execution is resumed
* by the client. PC for the current activation may be temporarily decremented
* so that the "current" instruction will be shown by the client. This helper
* is callable from anywhere, also outside bytecode executor.
computed live
comment: Load a function from bytecode. The function object returned here must
* match what is created by duk_js_push_closure() with respect to its flags,
* properties, etc.
*
* NOTE: there are intentionally no input buffer length / bound checks.
* Adding them would be easy but wouldn't ensure memory safety as untrusted
* or broken bytecode is unsafe during execution unless the opcodes themselves
* are validated (which is quite complex, especially for indirect opcodes).
label: code-design
* For an external string, the NUL-terminated string data is stored
* externally. The user must guarantee that data behind this pointer
* doesn't change while it's used.
Note: masking of 'x' is not necessary because of
* range check and shifting -> no bits overlapping
* the marker should be set.
comment:
* Object.defineProperty() related helper (E5 Section 15.2.3.6)
*
* Inlines all [[DefineOwnProperty]] exotic behaviors.
*
* Note: Ecmascript compliant [[DefineOwnProperty]](P, Desc, Throw) is not
* implemented directly, but Object.defineProperty() serves its purpose.
* We don't need the [[DefineOwnProperty]] internally and we don't have a
* property descriptor with 'missing values' so it's easier to avoid it
* entirely.
*
* Note: this is only called for actual objects, not primitive values.
* This must support virtual properties for full objects (e.g. Strings)
* but not for plain values (e.g. strings). Lightfuncs, even though
* primitive in a sense, are treated like objects and accepted as target
* values.
label: code-design
callstack limits
A...P
Module table:
* - module.exports: initial exports table (may be replaced by user)
* - module.id is non-writable and non-configurable, as the CommonJS
* spec suggests this if possible
* - module.filename: not set, defaults to resolved ID if not explicitly
* set by modSearch() (note capitalization, not .fileName, matches Node.js)
* - module.name: not set, defaults to last component of resolved ID if
* not explicitly set by modSearch()
String constructor needs to distinguish between an argument not given at all
* vs. given as 'undefined'. We're a vararg function to handle this properly.
Explicit length is only needed if it differs from 'nargs'.
Force restart caused by a function return; must recheck
* debugger breakpoints before checking line transitions,
* see GH-303. Restart and then handle interrupt_counter
* zero again.
Decode 'bits' bits from the input stream (bits must be 1...24).
* When reading past bitstream end, zeroes are shifted in. The result
* is signed to match duk_bd_decode_flagged.
(?:
Must be restored here to handle e.g. yields properly.
The base ID of the current require() function, resolution base
non-Reference deletion is always 'true', even in strict mode
jump to next loop, using reg_v34_iter as iterated value
Scan error: this shouldn't normally happen; it could happen if
* string is not valid UTF-8 data, and clen/blen are not consistent
* with the scanning algorithm.
max possible
punctuators (unlike the spec, also includes "/" and "/=")
DUK_BUFOBJ_FLOAT32ARRAY
[ ... ptr ]
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property delete right now.
12: getDate
* Helper for valstack space
*
* Caller of DUK_ASSERT_VALSTACK_SPACE() estimates the number of free stack entries
* required for its own use, and any child calls which are not (a) Duktape API calls
* or (b) Duktape calls which involve extending the valstack (e.g. getter call).
'modLoaded'
* Assertions before
comment:
* Buffer writer (dynamic buffer only)
*
* Helper for writing to a dynamic buffer with a concept of a "spare" area
* to reduce resizes. You can ensure there is enough space beforehand and
* then write for a while without further checks, relying on a stable data
* pointer. Spare handling is automatic so call sites only indicate how
* much data they need right now.
*
* There are several ways to write using bufwriter. The best approach
* depends mainly on how much performance matters over code footprint.
* The key issues are (1) ensuring there is space and (2) keeping the
* pointers consistent. Fast code should ensure space for multiple writes
* with one ensure call. Fastest inner loop code can temporarily borrow
* the 'p' pointer but must write it back eventually.
*
* Be careful to ensure all macro arguments (other than static pointers like
* 'thr' and 'bw_ctx') are evaluated exactly once, using temporaries if
* necessary (if that's not possible, there should be a note near the macro).
* Buffer write arguments often contain arithmetic etc so this is
* particularly important here.
label: code-design
Ordering should not matter (E5 Section 11.8.5, step 3.a) but
* preserve it just in case.
for zero size, don't push anything on valstack
Here we'd have the option of decoding unpadded base64
* (e.g. "xxxxyy" instead of "xxxxyy==". Currently not
* accepted.
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
* Conceptually, we look for the identifier binding by starting from
* 'env' and following to chain of environment records (represented
* by the prototype chain).
*
* If 'env' is NULL, the current activation does not yet have an
* allocated declarative environment record; this should be treated
* exactly as if the environment record existed but had no bindings
* other than register bindings.
*
* Note: we assume that with the DUK_HOBJECT_FLAG_NEWENV cleared
* the environment will always be initialized immediately; hence
* a NULL 'env' should only happen with the flag set. This is the
* case for: (1) function calls, and (2) strict, direct eval calls.
heap level "stash" object (e.g., various reachability roots)
* For global or eval code this is straightforward. For functions
* created with the Function constructor we only get the source for
* the body and must manufacture the "function ..." part.
*
* For instance, for constructed functions (v8):
*
* > a = new Function("foo", "bar", "print(foo)");
* [Function]
* > a.toString()
* 'function anonymous(foo,bar) {\nprint(foo)\n}'
*
* Similarly for e.g. getters (v8):
*
* > x = { get a(foo,bar) { print(foo); } }
* { a: [Getter] }
* > Object.getOwnPropertyDescriptor(x, 'a').get.toString()
* 'function a(foo,bar) { print(foo); }'
c recursion check
XXX: optimize by adding the token numbers directly into the
* always interned duk_hstring objects (there should be enough
* flag bits free for that)?
Continue parsing after padding, allows concatenated,
* padded base64.
Check that 'this' is a duk_hbufferobject and return a pointer to it
* (NULL if not).
idx_step is +1 for indexOf, -1 for lastIndexOf
is a setter/getter
env created above to stack top
cannot be e.g. arguments exotic, since exotic 'traits' are mutually exclusive
DUK_TOK_LNOT
XXX: sufficient to check 'strict', assert for 'is function'
check final character validity
* Init lexer context
* Incref and decref functions.
*
* Decref may trigger immediate refzero handling, which may free and finalize
* an arbitrary number of objects.
*
Generate pc2line data for an instruction sequence, leaving a buffer on stack top.
a dummy undefined value is pushed to make valstack
* behavior uniform for caller
idx_step is +1 for reduce, -1 for reduceRight
PatternCharacter, all excluded characters are matched by cases above
Note: -nargs alone would fail for nargs == 0, this is OK
curr and desc are accessors
* Throw the error in the resumed thread's context; the
* error value is pushed onto the resumee valstack.
*
* Note: the callstack of the target may empty in this case
* too (i.e. the target thread has never been resumed). The
* value stack will contain the initial function in that case,
* which we simply ignore.
For string-to-number, pretend we never have the lowest mantissa as there
* is no natural "precision" for inputs. Having lowest_mantissa == 0, we'll
* fall into the base cases for both e >= 0 and e < 0.
Number built-in accepts a plain number or a Number object (whose
* internal value is operated on). Other types cause TypeError.
Encode to extended UTF-8; 'out' must have space for at least
* DUK_UNICODE_MAX_XUTF8_LENGTH bytes. Allows encoding of any
* 32-bit (unsigned) codepoint.
func.prototype.constructor = func
Accept any pointer-like value; for 'object' dvalue, read
* and ignore the class number.
comment: Clone the properties of the ROM-based global object to create a
* fully RAM-based global object. Uses more memory than the inherit
* model but more compliant.
label: code-design
prev value can be garbage, no decref
comment:
* For/for-in statement is complicated to parse because
* determining the statement type (three-part for vs. a
* for-in) requires potential backtracking.
*
* See the helper for the messy stuff.
label: code-design
Stepped? Step out is handled by callstack unwind.
Copy values, the copy method depends on the arguments.
*
* Copy mode decision may depend on the validity of the underlying
* buffer of the source argument; there must be no harmful side effects
* from there to here for copy_mode to still be valid.
fills window
Caller must check character offset to be inside the string.
valstack will be unbalanced, which is OK
conservative
unconditional
DUK_USE_FASTINT && DUK_USE_PACKED_TVAL
* NEXTENUM checks whether the enumerator still has unenumerated
* keys. If so, the next key is loaded to the target register
* and the next instruction is skipped. Otherwise the next instruction
* will be executed, jumping out of the enumeration loop.
comment: Providing access to e.g. act->lex_env would be dangerous: these
* internal structures must never be accessible to the application.
* Duktape relies on them having consistent data, and this consistency
* is only asserted for, not checked for.
label: code-design
Duktape.modSearch
Set .buffer to the argument ArrayBuffer.
* Parse a function-like expression:
*
* - function expression
* - function declaration
* - function statement (non-standard)
* - setter/getter
*
* Adds the function to comp_ctx->curr_func function table and returns the
* function number.
*
* On entry, curr_token points to:
*
* - the token after 'function' for function expression/declaration/statement
* - the token after 'set' or 'get' for setter/getter
* Match loop.
*
* Try matching at different offsets until match found or input exhausted.
flags: ""
-> [ res_obj ]
unvalidated
nbytes
* <--------->
* [ ... | p | x | x | q ]
* => [ ... | q | p | x | x ]
eat '{' on entry
This native function is also used for Date.prototype.getTime()
* as their behavior is identical.
resume write to target
if new_size < L * old_size, resize without abandon check; L = 3-bit fixed point, e.g. 9 -> 9/8 = 112.5%
Note: we could try to stuff a partial hash (e.g. 16 bits) into the
* shared heap header. Good hashing needs more hash bits though.
Else functionality is identical for function call and constructor
* call.
inclusive
Check that 'this' is a duk_hbufferobject and return a pointer to it.
utf-8 continuation bytes have the form 10xx xxxx
This is based on V8 EquivalentYear() algorithm (see src/genequivyear.py):
* http://code.google.com/p/v8/source/browse/trunk/src/date.h#146
'buf' contains the string to write, 'sz_buf' contains the length
* (which may be zero).
'-'
hobject management functions
Convert day from one-based to zero-based (internal). This may
* cause the day part to be negative, which is OK.
1111 10xx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [26 bits]
There is no need to check the first character specially here
* (i.e. reject digits): the caller only accepts valid initial
* characters and won't call us if the first character is a digit.
* This also ensures that the plain string won't be empty.
'\xffBytecode'
Catch a double-to-int64 cast issue encountered in practice.
* DumpHeap command
comment:
* Lexer for source files, ToNumber() string conversions, RegExp expressions,
* and JSON.
*
* Provides a stream of Ecmascript tokens from an UTF-8/CESU-8 buffer. The
* caller can also rewind the token stream into a certain position which is
* needed by the compiler part for multi-pass scanning. Tokens are
* represented as duk_token structures, and contain line number information.
* Token types are identified with DUK_TOK_* defines.
*
* Characters are decoded into a fixed size lookup window consisting of
* decoded Unicode code points, with window positions past the end of the
* input filled with an invalid codepoint (-1). The tokenizer can thus
* perform multiple character lookups efficiently and with few sanity
* checks (such as access outside the end of the input), which keeps the
* tokenization code small at the cost of performance.
*
* Character data in tokens, such as identifier names and string literals,
* is encoded into CESU-8 format on-the-fly while parsing the token in
* question. The string data is made reachable to garbage collection by
* placing the token-related values in value stack entries allocated for
* this purpose by the caller. The characters exist in Unicode code point
* form only in the fixed size lookup window, which keeps character data
* expansion (of especially ASCII data) low.
*
* Token parsing supports the full range of Unicode characters as described
* in the E5 specification. Parsing has been optimized for ASCII characters
* because ordinary Ecmascript code consists almost entirely of ASCII
* characters. Matching of complex Unicode codepoint sets (such as in the
* IdentifierStart and IdentifierPart productions) is optimized for size,
* and is done using a linear scan of a bit-packed list of ranges. This is
* very slow, but should never be entered unless the source code actually
* contains Unicode characters.
*
* Ecmascript tokenization is partially context sensitive. First,
* additional future reserved words are recognized in strict mode (see E5
* Section 7.6.1.2). Second, a forward slash character ('/') can be
* recognized either as starting a RegExp literal or as a division operator,
* depending on context. The caller must provide necessary context flags
* when requesting a new token.
*
* Future work:
*
* * Make line number tracking optional, as it consumes space.
*
* * Add a feature flag for disabling UTF-8 decoding of input, as most
* source code is ASCII. Because of Unicode escapes written in ASCII,
* this does not allow Unicode support to be removed from e.g.
* duk_unicode_is_identifier_start() nor does it allow removal of CESU-8
* encoding of e.g. string literals.
*
* * Add a feature flag for disabling Unicode compliance of e.g. identifier
* names. This allows for a build more than a kilobyte smaller, because
* Unicode ranges needed by duk_unicode_is_identifier_start() and
* duk_unicode_is_identifier_part() can be dropped. String literals
* should still be allowed to contain escaped Unicode, so this still does
* not allow removal of CESU-8 encoding of e.g. string literals.
*
* * Character lookup tables for codepoints above BMP could be stripped.
*
* * Strictly speaking, E5 specification requires that source code consists
* of 16-bit code units, and if not, must be conceptually converted to
* that format first. The current lexer processes Unicode code points
* and allows characters outside the BMP. These should be converted to
* surrogate pairs while reading the source characters into the window,
* not after tokens have been formed (as is done now). However, the fix
* is not trivial because two characters are decoded from one codepoint.
*
* * Optimize for speed as well as size. Large if-else ladders are (at
* least potentially) slow.
label: code-design
[ ... buf loop ]
comment:
* Heap object representation.
*
* Heap objects are used for Ecmascript objects, arrays, and functions,
* but also for internal control like declarative and object environment
* records. Compiled functions, native functions, and threads are also
* objects but with an extended C struct.
*
* Objects provide the required Ecmascript semantics and exotic behaviors
* especially for property access.
*
* Properties are stored in three conceptual parts:
*
* 1. A linear 'entry part' contains ordered key-value-attributes triples
* and is the main method of string properties.
*
* 2. An optional linear 'array part' is used for array objects to store a
* (dense) range of [0,N[ array indexed entries with default attributes
* (writable, enumerable, configurable). If the array part would become
* sparse or non-default attributes are required, the array part is
* abandoned and moved to the 'entry part'.
*
* 3. An optional 'hash part' is used to optimize lookups of the entry
* part; it is used only for objects with sufficiently many properties
* and can be abandoned without loss of information.
*
* These three conceptual parts are stored in a single memory allocated area.
* This minimizes memory allocation overhead but also means that all three
* parts are resized together, and makes property access a bit complicated.
label: code-design
x <- y + z
get array index related to string (or return DUK_HSTRING_NO_ARRAY_INDEX);
* avoids helper call if string has no array index value.
[ ... re_obj input bc ]
Keep the error as the result (coercing it might fail below,
* but we don't catch that now).
* Note: although arguments object variable mappings are only established
* for non-strict functions (and a call to a non-strict function created
* the arguments object in question), an inner strict function may be doing
* the actual property write. Hence the throw_flag applied here comes from
* the property write call.
push before advancing to keep reachable
* duk_hthread allocation and freeing.
[ ... pattern flags escaped_source bytecode ]
* Helper for updating callee 'caller' property.
eat 'do'
saves a few instructions to have this wrapper (see comment on duk_heap_mem_alloc)
[ source template result ]
25 user flags
also stash it before constructor,
* in case we need it (as the fallback value)
omit print
Unary plus is used to force a fastint check, so must include
* downgrade check.
DUK__FLD_16BIT
comment: should never happen, but be robust
label: code-design
_Formals: omitted if function is guaranteed not to need a (non-strict) arguments object
comment: XXX: comes out as signed now
label: code-design
flags
comment: If message is undefined, the own property 'message' is not set at
* all to save property space. An empty message is inherited anyway.
label: code-design
writable but not deletable
Decode UTF-8 codepoint from a sequence of hex escapes. The
* first byte of the sequence has been decoded to 't'.
*
* Note that UTF-8 validation must be strict according to the
* specification: E5.1 Section 15.1.3, decode algorithm step
* 4.d.vii.8. URIError from non-shortest encodings is also
* specifically noted in the spec.
[ ... formals ]
comment: avoid tag 0xfff0, no risk of confusion with negative infinity
label: code-design
See: tests/ecmascript/test-spec-bound-constructor.js
guaranteed to succeed
* Define new property
*
* Note: this may fail if the holder is not extensible.
used elements (includes DELETED)
comment: XXX: since the enumerator may be a memory expensive object,
* perhaps clear it explicitly here? If so, break jump must
* go through this clearing operation.
label: code-design
-> [ ... key val replacer holder key ]
as is
Step 1 is not necessary because duk_call_method() will take
* care of it.
* Code emission helpers
*
* Some emission helpers understand the range of target and source reg/const
* values and automatically emit shuffling code if necessary. This is the
* case when the slot in question (A, B, C) is used in the standard way and
* for opcodes the emission helpers explicitly understand (like DUK_OP_CALL).
*
* The standard way is that:
* - slot A is a target register
* - slot B is a source register/constant
* - slot C is a source register/constant
*
* If a slot is used in a non-standard way the caller must indicate this
* somehow. If a slot is used as a target instead of a source (or vice
* versa), this can be indicated with a flag to trigger proper shuffling
* (e.g. DUK__EMIT_FLAG_B_IS_TARGET). If the value in the slot is not
* register/const related at all, the caller must ensure that the raw value
* fits into the corresponding slot so as to not trigger shuffling. The
* caller must set a "no shuffle" flag to ensure compilation fails if
* shuffling were to be triggered because of an internal error.
*
* For slots B and C the raw slot size is 9 bits but one bit is reserved for
* the reg/const indicator. To use the full 9-bit range for a raw value,
* shuffling must be disabled with the DUK__EMIT_FLAG_NO_SHUFFLE_{B,C} flag.
* Shuffling is only done for A, B, and C slots, not the larger BC or ABC slots.
*
* There is call handling specific understanding in the A-B-C emitter to
* convert call setup and call instructions into indirect ones if necessary.
comment: XXX: make this an internal helper
label: code-design
assumed to bottom relative
intentionally empty
Compute time value from (double) parts. The parts can be either UTC
* or local time; if local, they need to be (conceptually) converted into
* UTC time. The parts may represent valid or invalid time, and may be
* wildly out of range (but may cancel each other and still come out in
* the valid Date range).
aaaaaabb bbbbcccc ccdddddd
[[SetPrototypeOf]] standard behavior, E6 9.1.2
comment: XXX: could unwind catchstack here, so that call handling
* didn't need to do that?
label: code-design
27: setUTCSeconds
Lightfunc virtual properties are non-configurable, so
* reject if match any of them.
comment: init is unnecessary but suppresses "may be used uninitialized" warnings
label: code-design
no need to unwind catchstack
'Proxy' object
'errCreate'
coerce lval with ToString()
see algorithm
* reverse()
index is above internal buffer length -> property is fully normal
ensure never re-entered until rescue cycle complete
comment: order: most frequent to least frequent
label: code-design
comment: not very useful, used for debugging
label: code-design
catch stack depth
[ ... res_obj ]
* Lexer defines.
A token value. Can be memcpy()'d, but note that slot1/slot2 values are on the valstack.
* Some fields (like num, str1, str2) are only valid for specific token types and may have
* stale values otherwise.
DUK_BUFOBJ_NODEJS_BUFFER
XXX: if 'len' is low, may want to ensure array part is kept:
* the caller is likely to want a dense array.
XXX: version specific array format instead?
* Process incoming debug requests
*
* Individual request handlers can push temporaries on the value stack and
* rely on duk__debug_process_message() to restore the value stack top
* automatically.
roughly 2 kiB
Must avoid duk_pop() in exit path
basic types from duk_features.h
XXX: byte offset
* instanceof
ecmascript compiler limits
token type
-> [ ... key val replacer ]
call_flags
* Comparisons (x >= y, x > y, x <= y, x < y)
*
* E5 Section 11.8.5: implement 'x < y' and then use negate and eval_left_first
* flags to get the rest.
Negative indices are always within allocated stack but
* must not go below zero index.
Executor interrupt default interval when nothing else requires a
* smaller value. The default interval must be small enough to allow
* for reasonable execution timeout checking but large enough to keep
* impact on execution performance low.
* Object internal value
*
* Returned value is guaranteed to be reachable / incref'd, caller does not need
* to incref OR decref. No proxies or accessors are invoked, no prototype walk.
Exponent
general temp register
0xe0...0xef
Maximum write size: XUTF8 path writes max DUK_UNICODE_MAX_XUTF8_LENGTH,
* percent escape path writes max two times CESU-8 encoded BMP length.
[ arg1 ... argN this loggerLevel loggerName buffer ]
If not present in finalize_list or refzero_list, the pointer
* must be either in heap_allocated or the string table.
rc_varname and reg_varbind are ignored here
duplicate zeroing, expect for (possible) NULL inits
get as double to handle huge numbers correctly
enum_index
XXX: clarify on when and where DUK__CONST_MARKER is allowed
* Error helpers
* Data following the header depends on the DUK_HBUFFER_FLAG_DYNAMIC
* flag.
*
* If the flag is clear (the buffer is a fixed size one), the buffer
* data follows the header directly, consisting of 'size' bytes.
*
* If the flag is set, the actual buffer is allocated separately, and
* a few control fields follow the header. Specifically:
*
* - a "void *" pointing to the current allocation
* - a duk_size_t indicating the full allocated size (always >= 'size')
*
* If DUK_HBUFFER_FLAG_EXTERNAL is set, the buffer has been allocated
* by user code, so that Duktape won't be able to resize it and won't
* free it. This allows buffers to point to e.g. an externally
* allocated structure such as a frame buffer.
*
* Unlike strings, no terminator byte (NUL) is guaranteed after the
* data. This would be convenient, but would pad aligned user buffers
* unnecessarily upwards in size. For instance, if user code requested
* a 64-byte dynamic buffer, 65 bytes would actually be allocated which
* would then potentially round upwards to perhaps 68 or 72 bytes.
'new'
evaluate to plain value, no forced register (temp/bound reg both ok)
Keep heap->finalize_list up-to-date during the list walk.
* This has no functional impact, but does matter e.g. for
* duk_push_heapptr() asserts when assertions are enabled.
DUK_USE_INTERRUPT_COUNTER
Fast path is triggered for no exponent and also for balanced exponent
* and fraction parts, e.g. for "1.23e2" == "123". Remember to respect
* zero sign.
Note: copying tv_obj and tv_key to locals to shield against a valstack
* resize is not necessary for a property put right now (putprop protects
* against it internally).
comment:
* Parser control values for tokens. The token table is ordered by the
* DUK_TOK_XXX defines.
*
* The binding powers are for lbp() use (i.e. for use in led() context).
* Binding powers are positive for typing convenience, and bits at the
* top should be reserved for flags. Binding power step must be higher
* than 1 so that binding power "lbp - 1" can be used for right associative
* operators. Currently a step of 2 is used (which frees one more bit for
* flags).
label: code-design
* Array part
*
* Note: ordering between array and entry part must match 'abandon array'
* behavior in duk_hobject_props.c: key order after an array is abandoned
* must be the same.
comment: XXX: could be eliminated with valstack adjust
label: code-design
[key val]
DUK_TOK_CATCH
Note: we rely on duk_safe_call() to fix up the stack for the caller,
* so we don't need to pop stuff here. There is no return value;
* caller determines rescued status based on object refcount.
* Case conversion helper, with context/local sensitivity.
* For proper case conversion, one needs to know the character
* and the preceding and following characters, as well as
* locale/language.
[ ... arg1 ... argN envobj argobj ]
flags:nonstrict
pass2 allocation handles this
* Call the wrapped module function.
*
* Use a protected call so that we can update Duktape.modLoaded[resolved_id]
* even if the module throws an error.
advance manually
comment: XXX: awkward
label: code-design
target out-of-bounds (but positive)
free some memory
constrained by string length
stable; precalculated for faster lookups
* Thread defines
same handling for identifiers and strings
-> [ ... lval rval rval.prototype ]
'implements'
'='
XXX: Not sure what the best return value would be in the API.
* Return a boolean for now. Note that rc == 0 is success (true).
Current convention is to use duk_size_t for value stack sizes and global indices,
* and duk_idx_t for local frame indices.
comment: XXX: where to release temp regs in intermediate expressions?
* e.g. 1+2+3 -> don't inflate temp register count when parsing this.
* that particular expression temp regs can be forced here.
label: code-design
negative top-relative indices not allowed now
'instanceof'
avoid attempt to compact any objects
expression parsing helpers
return ToObject(this)
one token
flags field: LLLLLLFT, L = label (24 bits), F = flags (4 bits), T = type (4 bits)
not protected, respect reclimit, is a constructor call
DUK_TOK_BNOT
E5 Section 8.6.1
indicates a deleted string; any fixed non-NULL, non-hstring pointer works
val is unsigned so >= 0
comment: NOTE: we try to minimize code size by avoiding unnecessary pops,
* so the stack looks a bit cluttered in this function. DUK_ASSERT_TOP()
* assertions are used to ensure stack configuration is correct at each
* step.
label: code-design
must have start and end
Check for breakpoints only on line transition.
* Breakpoint is triggered when we enter the target
* line from a different line, and the previous line
* was within the same function.
*
* This condition is tricky: the condition used to be
* that transition to -or across- the breakpoint line
* triggered the breakpoint. This seems intuitively
* better because it handles breakpoints on lines with
* no emitted opcodes; but this leads to the issue
* described in: https://github.com/svaarala/duktape/issues/263.
env and act may be NULL
* Process yield
*
* After longjmp(), processing continues in bytecode executor longjmp
* handler, which will e.g. update thr->resumer to NULL.
-> [... enum key enum_target key]
comment: XXX: store 'bcode' pointer to activation for faster lookup?
label: code-design
* Unicode tables
[... obj]
Note: space must cater for both JX and JC.
Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
Normal non-bound function.
Eating a left curly; regexp mode is allowed by left curly
* based on duk__token_lbp[] automatically.
A validated read() is always a number, so it's write coercion
* is always side effect free an won't invalidate pointers etc.
current and previous token for parsing
probe sequence
message is empty -> return name
NaN timevalue: we need to coerce the arguments, but
* the resulting internal timestamp needs to remain NaN.
* This works but is not pretty: parts and dparts will
* be partially uninitialized, but we only write to them.
comment: It might seem that replacing 'thr->heap' with just 'heap' below
* might be a good idea, but it increases code size slightly
* (probably due to unnecessary spilling) at least on x64.
label: code-design
Currently nothing to free; 'data' is a heap object
'prototype'
'jx'
default prototype (Note: 'obj' must be reachable)
comment: XXX: currently NULL allocations are not supported; remove if later allowed
label: code-design
Unwind the topmost callstack entry before reusing it
internal define property: skip write silently if exists
borrowed, no refcount
allow e.g. '0x0009' and '00077'
DUK_BUFOBJ_DATAVIEW
* Compact an object. Minimizes allocation size for objects which are
* not likely to be extended. This is useful for internal and non-
* extensible objects, but can also be called for non-extensible objects.
* May abandon the array part if it is computed to be too sparse.
*
* This call is relatively expensive, as it needs to scan both the
* entries and the array part.
*
* The call may fail due to allocation error.
find elements to swap
currently, always the case
* Detected label
comment: XXX: an array can have length higher than 32 bits; this is not handled
* correctly now.
label: code-design
* Helper macros
comment: XXX: Simplify this algorithm, should be possible to come up with
* a shorter and faster algorithm by inspecting IEEE representation
* directly.
label: code-design
* CheckObjectCoercible() (E5 Section 9.10)
*
* Note: no API equivalent now.
constants are strings or numbers now
'\n '
Must behave like a no-op with NULL and any pointer returned from
* malloc/realloc with zero size.
if (is_regexp)
[ thisArg arg1 ... argN func boundFunc ]
-Infinity
Undefine local defines
* Top-level include file to be used for all (internal) source files.
*
* Source files should not include individual header files, as they
* have not been designed to be individually included.
* Init built-in strings
* Two's complement arithmetic.
[... constructor arg1 ... argN]
no need to decref previous value
'finally'
Zero size compare not an issue with DUK_MEMCMP.
[ ... closure template val ]
YIELDED: Ecmascript activation + Duktape.Thread.yield() activation
may be NULL (but only if size is 0)
write to entry part
* Ecmascript bytecode executor.
*
* Resume execution for the current thread from its current activation.
* Returns when execution would return from the entry level activation,
* leaving a single return value on top of the stack. Function calls
* and thread resumptions are handled internally. If an error occurs,
* a longjmp() with type DUK_LJ_TYPE_THROW is called on the entry level
* setjmp() jmpbuf.
*
* Ecmascript function calls and coroutine resumptions are handled
* internally (by the outer executor function) without recursive C calls.
* Other function calls are handled using duk_handle_call(), increasing
* C recursion depth.
*
* Abrupt completions (= long control tranfers) are handled either
* directly by reconfiguring relevant stacks and restarting execution,
* or via a longjmp. Longjmp-free handling is preferable for performance
* (especially Emscripten performance), and is used for: break, continue,
* and return.
*
* For more detailed notes, see doc/execution.rst.
*
* Also see doc/code-issues.rst for discussion of setjmp(), longjmp(),
* and volatile.
* Debug connection message write helpers
We know _Formals is dense and all entries will be in the
* array part. GC and finalizers shouldn't affect _Formals
* so side effects should be fine.
don't want an intermediate exposed state with func == NULL
comment:
* (Re)try handling the longjmp.
*
* A longjmp handler may convert the longjmp to a different type and
* "virtually" rethrow by goto'ing to 'check_longjmp'. Before the goto,
* the following must be updated:
* - the heap 'lj' state
* - 'thr' must reflect the "throwing" thread
label: code-design
XXX=
separators: space, space, colon
comment: Format of magic, bits:
* 0...1: field type; 0=uint8, 1=uint16, 2=uint32, 3=float, 4=double, 5=unused, 6=unused, 7=unused
* 3: endianness: 0=little, 1=big
* 4: signed: 1=yes, 0=no
* 5: typedarray: 1=yes, 0=no
label: code-design
comment: Note: reuse 'curr' as a temp propdesc
label: code-design
Slow path
Lightweight function: never bound, so terminate.
unconditionally; is_global==0
Node.js Buffer: return offset + #bytes written (i.e. next
* write offset).
string limits
comment: function makes one or more slow path accesses
label: code-design
DUK_USE_AUGMENT_ERROR_CREATE
No need for a NULL/zero-size check because new_size > 0)
Assume value stack sizes (in elements) fits into duk_idx_t.
comment: Relookup in case duk_js_tointeger() ends up e.g. coercing an object.
label: code-design
'>'
* Debug connection skip primitives
valstack index of 'func' and retval (relative to entry valstack_bottom)
XXX: array internal?
Assertion compatible inside a comma expression, evaluates to void.
* Currently not compatible with DUK_USE_PANIC_HANDLER() which may have
* a statement block.
avoid key quotes when key is an ASCII Identifier
embed: nothing
comment: bit mask which indicates that a regconst is a constant instead of a register
label: code-design
* Memory allocation handling.
current assertion is quite strong: decref's and set to unused
Coerce an duk_ivalue to a 'plain' value by generating the necessary
* arithmetic operations, property access, or variable access bytecode.
* The duk_ivalue argument ('x') is converted into a plain value as a
* side effect.
element type
parsing in "scanning" phase (first pass)
regexp res_obj is at offset 4
Flags for duk_js_compare_helper().
comment:
* Eval
*
* Eval needs to handle both a "direct eval" and an "indirect eval".
* Direct eval handling needs access to the caller's activation so that its
* lexical environment can be accessed. A direct eval is only possible from
* Ecmascript code; an indirect eval call is possible also from C code.
* When an indirect eval call is made from C code, there may not be a
* calling activation at all which needs careful handling.
label: code-design
no fractions
'Function'
29: setUTCMinutes
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
accept comma, expect new value
-> [ ... reviver holder name val ]
[ ... pattern flags escaped_source buffer ]
reg
empty match -> bump and continue
regexp execution limits
SCANBUILD: "Dereference of null pointer", normal
catch or with binding is currently active
Note: unbalanced stack on purpose
Get a borrowed duk_tval pointer to the current 'this' binding. Caller must
* make sure there's an active callstack entry. Note that the returned pointer
* is unstable with regards to side effects.
expt values [0x001,0x7fe] = normal
Receiver: Proxy object
comment:
* Dump/load helpers, xxx_raw() helpers do no buffer checks
label: code-design
comment:
* Push readable string summarizing duk_tval. The operation is side effect
* free and will only throw from internal errors (e.g. out of memory).
* This is used by e.g. property access code to summarize a key/base safely,
* and is not intended to be fast (but small and safe).
label: code-design
* Type error thrower, E5 Section 13.2.3.
comment: Corner case: see test-numconv-parse-mant-carry.js. We could
* just bump the exponent and update bitstart, but it's more robust
* to recompute (but avoid rounding twice).
label: code-design
The JA(value) operation: encode array.
*
* Stack policy: [ array ] -> [ array ].
XXX: init or assert catch depth etc -- all values
happens when hash part dropped
1x heap size
no need for decref/incref because value is a number
comment: XXX: this may now fail, and is not handled correctly
label: code-design
[key undefined] -> [key]
* join(), toLocaleString()
*
* Note: checking valstack is necessary, but only in the per-element loop.
*
* Note: the trivial approach of pushing all the elements on the value stack
* and then calling duk_join() fails when the array contains a large number
* of elements. This problem can't be offloaded to duk_join() because the
* elements to join must be handled here and have special handling. Current
* approach is to do intermediate joins with very large number of elements.
* There is no fancy handling; the prefix gets re-joined multiple times.
stack top contains 'false'
LAYOUT 2
If 16-bit hash is in use, stuff it into duk_heaphdr_string flags.
* Other cases, use C recursion.
*
* If a tail call was requested we ignore it and execute a normal call.
* Since Duktape 0.11.0 the compiler emits a RETURN opcode even after
* a tail call to avoid test-bug-tailcall-thread-yield-resume.js.
*
* Direct eval call: (1) call target (before following bound function
* chain) is the built-in eval() function, and (2) call was made with
* the identifier 'eval'.
(
NOTE! Caller must ensure that any side effects from the
* coercions below are safe. If that cannot be guaranteed
* (which is normally the case), caller must coerce the
* argument using duk_to_number() before any pointer
* validations; the result of duk_to_number() always coerces
* without side effects here.
comment: Compared to duk_handle_call():
* - protected call: never
* - ignore recursion limit: never
label: code-design
Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
-> [ sep ToObject(this) len str ]
covered by comparison
Setting "no shuffle A" is covered by the assert, but it's needed
* with DUK_USE_SHUFFLE_TORTURE.
comment: XXX: .code = err_code disabled, not sure if useful
label: code-design
For now, restrict result array into 32-bit length range.
coerce in-place
DUK_ERR_ASSERTION_ERROR: no macros needed
directive prologue status at entry
* ToNumber() (E5 Section 9.3)
*
* Value to convert must be on stack top, and is popped before exit.
*
* See: http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
* http://www.cs.indiana.edu/~burger/fp/index.html
*
* Notes on the conversion:
*
* - There are specific requirements on the accuracy of the conversion
* through a "Mathematical Value" (MV), so this conversion is not
* trivial.
*
* - Quick rejects (e.g. based on first char) are difficult because
* the grammar allows leading and trailing white space.
*
* - Quick reject based on string length is difficult even after
* accounting for white space; there may be arbitrarily many
* decimal digits.
*
* - Standard grammar allows decimal values ("123"), hex values
* ("0x123") and infinities
*
* - Unlike source code literals, ToNumber() coerces empty strings
* and strings with only whitespace to zero (not NaN).
[ ... num ]
arrays MUST have a 'length' property
Using an explicit 'ASCII' flag has larger footprint (one call site
* only) but is quite useful for the case when there's no explicit
* 'clen' in duk_hstring.
comment: XXX: try to optimize to 8 (would now be possible, <200 used)
label: code-design
* Arguments handling helpers (argument map mainly).
*
* An arguments object has exotic behavior for some numeric indices.
* Accesses may translate to identifier operations which may have
* arbitrary side effects (potentially invalidating any duk_tval
* pointers).
Undefined/null are considered equal (e.g. "null == undefined" -> true).
* String value of 'blen+1' bytes follows (+1 for NUL termination
* convenience for C API). No alignment needs to be guaranteed
* for strings, but fields above should guarantee alignment-by-4
* (but not alignment-by-8).
comment: XXX: Could be improved by coercing to a readable duk_tval (especially string escaping)
label: code-design
comment: Inner executor, performance critical.
label: code-design
significant from precision perspective
[ ... Logger clog logfunc clog ]
No assertions for offset or length; in particular, \
* it's OK for length to be longer than underlying \
* buffer. Just ensure they don't wrap when added. \
fits into duk_small_int_t
Caller doesn't need to check exotic proxy behavior (but does so for
* some fast paths).
is eval code
* Iterate the bitstream (line diffs) until PC is reached
varmap is already in comp_ctx->curr_func.varmap_idx
* Convert binary digits into an IEEE double. Need to handle
* denormals and rounding correctly.
[key setter this val] -> [key retval]
DUK_TOK_LAND
comment:
* E5 Section 15.3.4.2 places few requirements on the output of
* this function:
*
* - The result is an implementation dependent representation
* of the function; in particular
*
* - The result must follow the syntax of a FunctionDeclaration.
* In particular, the function must have a name (even in the
* case of an anonymous function or a function with an empty
* name).
*
* - Note in particular that the output does NOT need to compile
* into anything useful.
label: code-design
Note that multiple catchstack entries may refer to the same
* callstack entry.
(-Number.MAX_VALUE).toString(2).length == 1025, + spare
DUK_HNATIVEFUNCTION_H_INCLUDED
check pointer at end
comment: XXX: any way to avoid decoding magic bit; there are quite
* many function properties and relatively few with magic values.
label: code-design
chain jumps for 'fall-through'
* after a case matches.
duk_unicode_ids_noa[]
comment: XXX: error message is a bit misleading: we reached a recursion
* limit which is also essentially the same as a C callstack limit
* (except perhaps with some relaxed threading assumptions).
label: code-design
reset longjmp
non-strict equality for buffers compares contents
all codepoints up to U+FFFF
recursion tracking happens here only
roughly 128 bytes
default clause matches next statement list (if any)
* E5 Sections 11.8.7, 8.12.6.
*
* Basically just a property existence check using [[HasProperty]].
new value
MULTIPLICATIVE EXPRESSION
comment:
* typeof
*
* E5 Section 11.4.3.
*
* Very straightforward. The only question is what to return for our
* non-standard tag / object types.
*
* There is an unfortunate string constant define naming problem with
* typeof return values for e.g. "Object" and "object"; careful with
* the built-in string defines. The LC_XXX defines are used for the
* lowercase variants now.
label: code-design
-> [ ... func this ]
comment: XXX: should this happen in the callee's activation or after unwinding?
label: code-design
comment:
* Four possible outcomes:
*
* 1. A 'finally' in the same function catches the 'return'.
* It may continue to propagate when 'finally' is finished,
* or it may be neutralized by 'finally' (both handled by
* ENDFIN).
*
* 2. The return happens at the entry level of the bytecode
* executor, so return from the executor (in C stack).
*
* 3. There is a calling (Ecmascript) activation in the call
* stack => return to it, in the same executor instance.
*
* 4. There is no calling activation, and the thread is
* terminated. There is always a resumer in this case,
* which gets the return value similarly to a 'yield'
* (except that the current thread can no longer be
* resumed).
label: code-design
caller checks
t has high mantissa
* Flags
*
* Fixed buffer: 0
* Dynamic buffer: DUK_HBUFFER_FLAG_DYNAMIC
* External buffer: DUK_HBUFFER_FLAG_DYNAMIC | DUK_HBUFFER_FLAG_EXTERNAL
DUK_TOK_LCURLY
comment:
* Identifier access and function closure handling.
*
* Provides the primitives for slow path identifier accesses: GETVAR,
* PUTVAR, DELVAR, etc. The fast path, direct register accesses, should
* be used for most identifier accesses. Consequently, these slow path
* primitives should be optimized for maximum compactness.
*
* Ecmascript environment records (declarative and object) are represented
* as internal objects with control keys. Environment records have a
* parent record ("outer environment reference") which is represented by
* the implicit prototype for technical reasons (in other words, it is a
* convenient field). The prototype chain is not followed in the ordinary
* sense for variable lookups.
*
* See identifier-handling.rst for more details on the identifier algorithms
* and the internal representation. See function-objects.rst for details on
* what function templates and instances are expected to look like.
*
* Care must be taken to avoid duk_tval pointer invalidation caused by
* e.g. value stack or object resizing.
*
* TODO: properties for function instances could be initialized much more
* efficiently by creating a property allocation for a certain size and
* filling in keys and values directly (and INCREFing both with "bulk incref"
* primitives.
*
* XXX: duk_hobject_getprop() and duk_hobject_putprop() calls are a bit
* awkward (especially because they follow the prototype chain); rework
* if "raw" own property helpers are added.
label: code-design
If 'day' is NaN, returns NaN.
* New length not lower than old length => no changes needed
* (not even array allocation).
* API oriented helpers
[enum_target res key true]
comment: XXX: we could save space by using _Target OR _This. If _Target, assume
* this binding is undefined. If _This, assumes this binding is _This, and
* target is also _This. One property would then be enough.
label: code-design
ADDITIVE EXPRESSION
macros
default case does not exist, or no statements present
* after default case: finish case evaluation
use temp_next for tracking register allocations
stack[0] = search value
* stack[1] = replace value
* stack[2] = input string
* stack[3] = result buffer
DUK_REGEXP_H_INCLUDED
comment: XXX: add fastint support?
label: requirement
FOUND
* Additional control information is placed into the object itself
* as internal properties to avoid unnecessary fields for the
* majority of functions. The compiler tries to omit internal
* control fields when possible.
*
* Function templates:
*
* {
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* }
*
* Function instances:
*
* {
* length: 2,
* prototype: { constructor: <func> },
* caller: <thrower>,
* arguments: <thrower>,
* name: "func", // declaration, named function expressions
* fileName: <debug info for creating nice errors>
* _Varmap: { "arg1": 0, "arg2": 1, "varname": 2 },
* _Formals: [ "arg1", "arg2" ],
* _Source: "function func(arg1, arg2) { ... }",
* _Pc2line: <debug info for pc-to-line mapping>,
* _Varenv: <variable environment of closure>,
* _Lexenv: <lexical environment of closure (if differs from _Varenv)>
* }
*
* More detailed description of these properties can be found
* in the documentation.
initialize for debug prints, needed if sce==NULL
start of valstack allocation
Allocate a new duk_hbuffer of a certain type and return a pointer to it
* (NULL on error). Write buffer data pointer to 'out_bufdata' (only if
* allocation successful).
Lookup 'key' from arguments internal 'map', delete mapping if found.
* Used in E5 Section 10.6 algorithm for [[Delete]]. Note that the
* variable/argument itself (where the map points) is not deleted.
-> [ ... enum_target res trap handler target ]
derived types
Awkward inclusion condition: drop out of compilation if not needed by any
* call site: object hash part or probing stringtable.
next instruction to execute (points to 'func' bytecode, stable pointer), NULL for native calls
[ offset littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
Must be a "pointer object", i.e. class "Pointer"
ES6 proxy
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
* stack[4] = regexp res_obj (if is_regexp)
value of dbg_exec_counter when we last did a Date-based check
idx_retval unsigned
no negative sign for zero
comment: Two value cycle, see e.g. test-bi-date-tzoffset-basic-fi.js.
* In these cases, favor a higher tzoffset to get a consistent
* result which is independent of iteration count. Not sure if
* this is a generically correct solution.
label: code-design
'thr' is the current thread, as no-one resumes except us and we
* switch 'thr' in that case.
lastIndex must be ignored for non-global regexps, but get the
* value for (theoretical) side effects. No side effects can
* really occur, because lastIndex is a normal property and is
* always non-configurable for RegExp instances.
clamp anything above nargs
comment: XXX: this could be more compact by accessing the internal properties
* directly as own properties (they cannot be inherited, and are not
* externally visible).
label: code-design
Get/set the current user visible size, without accounting for a dynamic
* buffer's "spare" (= usable size).
looping should never happen
Validate byte read/write for virtual 'offset', i.e. check that the
* offset, taking into account h->offset, is within the underlying
* buffer size. This is a safety check which is needed to ensure
* that even a misconfigured duk_hbufferobject never causes memory
* unsafe behavior (e.g. if an underlying dynamic buffer changes
* after being setup). Caller must ensure 'buf' != NULL.
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
digit position is absolute, not relative
c
comment: Same test with volatiles
label: test
There's overlap: the desired end result is that
* conceptually a copy is made to avoid "trampling"
* of source data by destination writes. We make
* an actual temporary copy to handle this case.
comment: XXX: just use toString() for now; permitted although not recommended.
* nargs==1, so radix is passed to toString().
label: code-design
%d; only 16 bits are guaranteed
'this' value:
* E5 Section 6.b.i
*
* The only (standard) case where the 'this' binding is non-null is when
* (1) the variable is found in an object environment record, and
* (2) that object environment record is a 'with' block.
*
This is important to ensure dynamic buffer data pointer is not
* NULL (which is possible if buffer size is zero), which in turn
* causes portability issues with e.g. memmove() and memcpy().
Since we already started writing the reply, just emit nothing.
* For top-level objects, 'length' property has the following
* default attributes: non-writable, non-enumerable, non-configurable
* (E5 Section 15).
*
* However, 'length' property for Array.prototype has attributes
* expected of an Array instance which are different: writable,
* non-enumerable, non-configurable (E5 Section 15.4.5.2).
*
* This is currently determined implicitly based on class; there are
* no attribute flags in the init data.
-> [ ... errhandler undefined(= this) errval ]
Reconfigure value stack for return to an Ecmascript function at 'act_idx'.
* First pass.
*
* Gather variable/function declarations needed for second pass.
* Code generated is dummy and discarded.
valid pc range is [0, length[
Current tracedata contains 2 entries per callstack entry.
[ ... errval ]
comment: XXX: there is a small risk here: because the ISO 8601 parser is
* very loose, it may end up parsing some datetime values which
* would be better parsed with a platform specific parser.
label: code-design
* Return (t - LocalTime(t)) in minutes:
*
* t - LocalTime(t) = t - (t + LocalTZA + DaylightSavingTA(t))
* = -(LocalTZA + DaylightSavingTA(t))
*
* where DaylightSavingTA() is checked for time 't'.
*
* Note that the sign of the result is opposite to common usage,
* e.g. for EE(S)T which normally is +2h or +3h from UTC, this
* function returns -120 or -180.
*
comment: XXX: no need for indirect call
label: code-design
XXX: the implementation now assumes "chained" bound functions,
* whereas "collapsed" bound functions (where there is ever only
* one bound function which directly points to a non-bound, final
* function) would require a "collapsing" implementation which
* merges argument lists etc here.
The current implementation of localeCompare() is simply a codepoint
* by codepoint comparison, implemented with a simple string compare
* because UTF-8 should preserve codepoint ordering (assuming valid
* shortest UTF-8 encoding).
*
* The specification requires that the return value must be related
* to the sort order: e.g. negative means that 'this' comes before
* 'that' in sort order. We assume an ascending sort order.
valstack
not protected, respect reclimit, not constructor
Push the resulting view object and attach the ArrayBuffer.
comment: XXX: this should be optimized to be a raw query and avoid valstack
* operations if possible.
label: code-design
unbalanced stack
value from hook
* If object has been marked finalizable, move it to the
* "to be finalized" work list. It will be collected on
* the next mark-and-sweep if it is still unreachable
* after running the finalizer.
* Struct defs
nbytes zero size case
* <--------->
* [ ... | p | x | x | q ] [ ... | p==q ]
* => [ ... | x | x | q ] [ ... ]
comment: not really necessary
label: code-design
[ ... target ] -> [ ... target keys ]
Leading zero.
','
Make underlying buffer compact to match DUK_BW_GET_SIZE().
first heap allocated, match bit boundary
comment: XXX: more specific error classes?
label: code-design
25: setUTCMilliseconds
* Intermediate value helpers
Limits
Encoded as surrogate pair, each encoding to 3 bytes for
* 6 bytes total. Codepoints above U+10FFFF encode as 6 bytes
* too, see duk_unicode_encode_cesu8().
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
*
* Value stack may either grow or shrink, depending on the
* number of func registers and the number of actual arguments.
* If nregs >= 0, func wants args clamped to 'nargs'; else it
* wants all args (= 'num_stack_args').
[ sep ToObject(this) len sep result ]
* Variant 2 or 4
Lightfunc, always success.
step 11.c is relevant only if non-strict (checked in 11.c.ii)
XX==
comment: A plain buffer coerces to a Duktape.Buffer because it's the
* object counterpart of the plain buffer value. But it might
* still make more sense to produce an ArrayBuffer here?
label: code-design
Force exponential format. Used for toExponential().
Cannot wrap: each object is at least 8 bytes so count is
* at most 1/8 of that.
wipe the capture range made by the atom (if any)
Anything else is not constructable.
attrs in E5 Section 15.3.5.1
* Use the index in the header to find the right starting point
Tolerate act_caller->func == NULL which happens in
* some finalization cases; treat like unknown caller.
comment: XXX: remove DUK_CALL_FLAG_IGNORE_RECLIMIT flag: there's now the
* reclimit bump?
label: code-design
maximum length of standard format tag that we support
buffer size is >= 1
ignore encoding for now
enable manually for dumping
(?=
require to be safe
Parser part count.
for side effects, result ignored
Now we can check offset validity.
Milliseconds between status notify and transport peeks.
Matching separator index is used in the control table
rehash even if old and new sizes are the same to get rid of
* DELETED entries.
* Two pass approach to processing the property descriptors.
* On first pass validate and normalize all descriptors before
* any changes are made to the target object. On second pass
* make the actual modifications to the target object.
*
* Right now we'll just use the same normalize/validate helper
* on both passes, ignoring its outputs on the first pass.
* Stringify implementation.
ToNumber() for a double is a no-op.
default: char escape (two chars)
* Hobject allocation.
*
* Provides primitive allocation functions for all object types (plain object,
* compiled function, native function, thread). The object return is not yet
* in "heap allocated" list and has a refcount of zero, so caller must careful.
Check actual underlying buffers for validity and that they
* cover the copy. No side effects are allowed after the check
* so that the validity status doesn't change.
* Special parser for character classes; calls callback for every
* range parsed and returns the number of ranges present.
negate result
* Lightfunc
comment:
* Refzero handling is skipped entirely if (1) mark-and-sweep is
* running or (2) execution is paused in the debugger. The objects
* are left in the heap, and will be freed by mark-and-sweep or
* eventual heap destruction.
*
* This is necessary during mark-and-sweep because refcounts are also
* updated during the sweep phase (otherwise objects referenced by a
* swept object would have incorrect refcounts) which then calls here.
* This could be avoided by using separate decref macros in
* mark-and-sweep; however, mark-and-sweep also calls finalizers which
* would use the ordinary decref macros anyway and still call this
* function.
*
* This check must be enabled also when mark-and-sweep support has been
* disabled: the flag is also used in heap destruction when running
* finalizers for remaining objects, and the flag prevents objects from
* being moved around in heap linked lists.
label: code-design
XXX: len >= 0x80000000 won't work below because a signed type
* is needed by qsort.
Special handling for year sign.
[ arg1 ... argN obj length new_length ]
The algorithm in E5.1 Section 15.9.1.12 normalizes month, but
* does not normalize the day-of-month (nor check whether or not
* it is finite) because it's not necessary for finding the day
* number which matches the (year,month) pair.
*
* We assume that duk__day_from_year() is exact here.
*
* Without an explicit infinity / NaN check in the beginning,
* day_num would be a bogus integer here.
*
* It's possible for 'year' to be out of integer range here.
* If so, we need to return NaN without integer overflow.
* This fixes test-bug-setyear-overflow.js.
* Node.js Buffer.prototype.slice([start], [end])
* ArrayBuffer.prototype.slice(begin, [end])
* TypedArray.prototype.slice(begin, [end])
*
* The API calls are almost identical; negative indices are counted from end
* of buffer, and final indices are clamped (allowing crossed indices). Main
* differences:
*
* - Copy/view behavior; Node.js .slice() and TypedArray .subarray() create
* views, ArrayBuffer .slice() creates a copy
*
* - Resulting object has a different class and prototype depending on the
* call (or 'this' argument)
*
* - TypedArray .subarray() arguments are element indices, not byte offsets
comment: When alloc_size == 0 the second allocation may not
* actually exist.
label: code-design
statements go here (if any) on next loop
'yield'
eat trailing comma
pruned
* Declarative environment record.
*
* Identifiers can never be stored in ancestors and are
* always plain values, so we can use an internal helper
* and access the value directly with an duk_tval ptr.
*
* A closed environment is only indicated by it missing
* the "book-keeping" properties required for accessing
* register-bound variables.
For anything other than an Error instance, we calculate the
* error location directly from the current activation if one
* exists.
Note: there is no requirement that: 'thr->callstack_preventcount == 1'
* like for yield.
lookup results is ignored
comment:
* ToPrimitive() (E5 Section 9.1)
*
* ==> implemented in the API.
label: requirement
resume caller must be an ecmascript func
e.g. a = -4, b = 5 --> -4 - 5 + 1 / 5 --> -8 / 5 --> -1
* a = -5, b = 5 --> -5 - 5 + 1 / 5 --> -9 / 5 --> -1
* a = -6, b = 5 --> -6 - 5 + 1 / 5 --> -10 / 5 --> -2
stack contains value (if requested), 'out_desc' is set
no issues with empty memcmp()
[str] -> [substr]
func is NULL for lightfunc
property attributes for identifier (relevant if value != NULL)
Default function to format objects. Tries to use toLogString() but falls
* back to toString(). Any errors are propagated out without catching.
don't allow continue
respect reclimit, not constructor
* Notation: double underscore used for internal properties which are not
* stored in the property allocation (e.g. '__valstack').
0x60-0x6f
DUK_BUFOBJ_INT32ARRAY
Caller has already eaten the first char so backtrack one byte.
controls for minimum entry part growth
temp accumulation buffer
Unwind.
* Object built-ins
callstack index
comment: XXX: The ES5/5.1/6 specifications require that the key in 'key in obj'
* must be string coerced before the internal HasProperty() algorithm is
* invoked. A fast path skipping coercion could be safely implemented for
* numbers (as number-to-string coercion has no side effects). For ES6
* proxy behavior, the trap 'key' argument must be in a string coerced
* form (which is a shame).
label: code-design
take last entry
curr is data, desc is accessor
comment: XXX: The incref macro takes a thread pointer but doesn't
* use it right now.
label: code-design
An object may be in heap_allocated list with a zero
* refcount also if it is a temporary object created by
* a finalizer; because finalization now runs inside
* mark-and-sweep, such objects will not be queued to
* refzero_list and will thus appear here with refcount
* zero.
Accept 32-bit decimal integers, no leading zeroes, signs, etc.
* Leading zeroes are not accepted (zero index "0" is an exception
* handled above).
comment: Set: currently a finalizer is disabled by setting it to
* undefined; this does not remove the property at the moment.
* The value could be type checked to be either a function
* or something else; if something else, the property could
* be deleted.
label: code-design
* Bitstream decoder
statement id allocation (running counter)
'public'
single match always
Note: 'curr' refers to 'length' propdesc
Use double parts, they tolerate unnormalized time.
*
* Note: DUK_DATE_IDX_WEEKDAY is initialized with a bogus value (DUK__PI_TZHOUR)
* on purpose. It won't be actually used by duk_bi_date_get_timeval_from_dparts(),
* but will make the value initialized just in case, and avoid any
* potential for Valgrind issues.
Steps 8-10 have been merged to avoid a "partial" variable.
Used during heap destruction: don't actually run finalizers
* because we're heading into forced finalization. Instead,
* queue finalizable objects back to the heap_allocated list.
duk_safe_call discipline
comment:
* Unicode tables containing ranges of Unicode characters in a
* packed format. These tables are used to match non-ASCII
* characters of complex productions by resorting to a linear
* range-by-range comparison. This is very slow, but is expected
* to be very rare in practical Ecmascript source code, and thus
* compactness is most important.
*
* The tables are matched using uni_range_match() and the format
* is described in src/extract_chars.py.
label: code-design
comment: XXX: encoding is ignored now.
label: code-design
use 'undefined' for value automatically
[ ... obj ... ]
comment: Function pointers do not always cast correctly to void *
* (depends on memory and segmentation model for instance),
* so they coerce to NULL.
label: code-design
Buffer length is bounded to 0xffff automatically, avoid compile warning.
Integer division which floors also negative values correctly.
consequence of above
* Self tests to ensure execution environment is sane. Intended to catch
* compiler/platform problems which cannot be detected at compile time.
DUK_TAG_NUMBER would logically go here, but it has multiple 'tags'
backtrack (safe)
DUK__FLD_32BIT
* Parse a RegExp token. The grammar is described in E5 Section 15.10.
* Terminal constructions (such as quantifiers) are parsed directly here.
*
* 0xffffffffU is used as a marker for "infinity" in quantifiers. Further,
* DUK__MAX_RE_QUANT_DIGITS limits the maximum number of digits that
* will be accepted for a quantifier.
comment: Note: reuse 'curr'
label: code-design
* Convert and push final string.
evaluate to final form (e.g. coerce GETPROP to code), throw away temp
* Selftest code
use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to the existing one)
duk_tval ptr for 'func' on stack (borrowed reference) or tv_func_copy
* Encoding and decoding basic formats: hex, base64.
*
* These are in-place operations which may allow an optimized implementation.
*
* Base-64: https://tools.ietf.org/html/rfc4648#section-4
Run mark-and-sweep a few times just in case (unreachable object
* finalizers run already here). The last round must rescue objects
* from the previous round without running any more finalizers. This
* ensures rescued objects get their FINALIZED flag cleared so that
* their finalizer is called once more in forced finalization to
* satisfy finalizer guarantees. However, we don't want to run any
* more finalizer because that'd required one more loop, and so on.
required to keep recursion depth correct
[ ... buf loop (proplist) (gap) holder "" ]
Get default hash part size for a certain entry part size.
Maximum number of digits generated.
[ ... func buf ] -> [ ... buf ]
comment: XXX: could share code with duk_js_ops.c, duk_js_compare_helper
label: code-design
Math.pow(+0,y) should be Infinity when y<0. NetBSD pow()
* returns -Infinity instead when y is <0 and finite. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
Free strings in the stringtable and any allocations needed
* by the stringtable itself.
e.g. DUK_OP_PREINCV
If neutered must return 0; offset is zeroed during
* neutering.
array of declarations: [ name1, val1, name2, val2, ... ]
* valN = (typeN) | (fnum << 8), where fnum is inner func number (0 for vars)
* record function and variable declarations in pass 1
breakpoints: [0,breakpoint_count[ gc reachable
comment: XXX: inefficient loop
label: code-design
* Insert a jump offset at 'offset' to complete an instruction
* (the jump offset is always the last component of an instruction).
* The 'skip' argument must be computed relative to 'offset',
* -without- taking into account the skip field being inserted.
*
* ... A B C ins X Y Z ... (ins may be a JUMP, SPLIT1/SPLIT2, etc)
* => ... A B C ins SKIP X Y Z
*
* Computing the final (adjusted) skip value, which is relative to the
* first byte of the next instruction, is a bit tricky because of the
* variable length UTF-8 encoding. See doc/regexp.rst for discussion.
* NFY <int: 5> <int: fatal> <str: msg> <str: filename> <int: linenumber> EOM
Note: not necessary to check p against re_ctx->input_end:
* the memory access is checked by duk__inp_get_cp(), while
* valid compiled regexps cannot write a saved[] entry
* which points to outside the string.
Strings and ROM objects are never placed on the heap allocated list.
[ ... val root "" ] -> [ ... val val' ]
comment:
* JSON built-ins.
*
* See doc/json.rst.
*
* Codepoints are handled as duk_uint_fast32_t to ensure that the full
* unsigned 32-bit range is supported. This matters to e.g. JX.
*
* Input parsing doesn't do an explicit end-of-input check at all. This is
* safe: input string data is always NUL-terminated (0x00) and valid JSON
* inputs never contain plain NUL characters, so that as long as syntax checks
* are correct, we'll never read past the NUL. This approach reduces code size
* and improves parsing performance, but it's critical that syntax checks are
* indeed correct!
label: code-design
stack type fits into 16 bits
'set'
low to high
required, NULL implies detached
right associative
covers +Infinity
no size check is necessary
r <- (* f 2)
* s <- (* (expt b (- e)) 2) == b^(-e) * 2 [if b==2 -> b^(1-e)]
* m+ <- 1
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
comment: XXX: best behavior for real world compatibility?
label: code-design
34: setMonth
20: getSeconds
refcount macros not defined without refcounting, caller must #ifdef now
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is never NULL.
DUK_MEMCMP() is guaranteed to return zero (equal) for zero length
* inputs so no zero length check is needed.
comment: XXX: shared parsing?
label: code-design
Note: reject negative zero.
Delete entry in Duktape.modLoaded[] and rethrow.
already closed
'\xffFormals'
1
XXX: Multiple tv_func lookups are now avoided by making a local
* copy of tv_func. Another approach would be to compute an offset
* for tv_func from valstack bottom and recomputing the tv_func
* pointer quickly as valstack + offset instead of calling duk_get_tval().
DUK_TOK_NEQ
comment: XXX: would be nice to omit this jump when the jump is not
* reachable, at least in the obvious cases (such as the case
* ending with a 'break'.
*
* Perhaps duk__parse_stmt() could provide some info on whether
* the statement is a "dead end"?
*
* If implemented, just set pc_prevstmt to -1 when not needed.
label: code-design
no shrink
XXX: duk_to_int() ensures we'll get 8 lowest bits as
* as input is within duk_int_t range (capped outside it).
* Ecmascript bytecode
Current require() function
[ ... errobj ]
[... arr]
-> [ ... escaped_source ]
func
ignore fclose() error
DUK_TOK_RETURN
* https://github.com/svaarala/duktape/issues/127#issuecomment-77863473
comment: Note: not initializing all bytes is normally not an issue: Duktape won't
* read or use the uninitialized bytes so valgrind won't issue warnings.
* In some special cases a harmless valgrind warning may be issued though.
* For example, the DumpHeap debugger command writes out a compiled function's
* 'data' area as is, including any uninitialized bytes, which causes a
* valgrind warning.
label: code-design
XXX: to util
Byte length would overflow.
register declarations in first pass
implicit this value always undefined for
* declarative environment records.
match_caps == 0 without regexps
Value coercion (in stack): ToInteger(), E5 Section 9.4
* API return value coercion: custom
thr->heap->lj.jmpbuf_ptr is checked by duk_err_longjmp() so we don't
* need to check that here. If the value is NULL, a panic occurs because
* we can't return.
* Object finalizer
comment: never shrinks; auto-adds DUK_VALSTACK_INTERNAL_EXTRA, which is generous
label: code-design
-> [ ... proplist enum_obj key ]
elems in source and dest
E5 Section 15.4.5.1, step 4
comment:
* Handle special cases (NaN, infinity, zero).
label: code-design
DUK_USE_ROM_OBJECTS
stats for current expression being parsed
comment: maintain highest 'used' temporary, needed to figure out nregs of function
label: code-design
DUK_IVAL_XXX
comment: Serialize uncovered backing buffer as a null; doesn't
* really matter as long we're memory safe.
label: code-design
* Error, fatal, and panic handling.
A number can be loaded either through a constant, using
* LDINT, or using LDINT+LDINTX. LDINT is always a size win,
* LDINT+LDINTX is not if the constant is used multiple times.
* Currently always prefer LDINT+LDINTX over a double constant.
guaranteed by string limits
Slot A
terminates expression; e.g. post-increment/-decrement
ignore arguments, return undefined (E5 Section 15.3.4)
Thread state.
g...v
[ ... | ] or [ ... | errobj (M * undefined)] where M = num_stack_rets - 1
omit
always >= 0
Fixed buffer, no zeroing because we'll fill all the data.
Ecma-to-ecma call possible, may or may not be a tail call.
* Avoid C recursion by being clever.
terminal type: no depth check
track cpos while scanning
DUK_TOK_SEQ
curr_pc synced by duk_handle_ecma_call_setup()
comment: XXX: could accept numbers larger than 32 bits, e.g. up to 53 bits?
label: code-design
accessor flag not encoded explicitly
For now only needed by the debugger.
* Bytecode instruction representation during compilation
*
* Contains the actual instruction and (optionally) debug info.
remove value
* Forward declarations
mm <- mp
comment: LDINTX is not necessarily in FASTINT range, so
* no fast path for now.
*
* XXX: perhaps restrict LDINTX to fastint range, wider
* range very rarely needed.
label: code-design
the entries [new_e_next, new_e_size_adjusted[ are left uninitialized on purpose (ok, not gc reachable)
rethrow
* Accessor macros for function specific data areas
Argument validation and func/args offset.
day number for Jan 1 since epoch
DUK_HOBJECT_FLAG_NATIVEFUNCTION varies
compact
comment: XXX: could clear FINALIZED already here; now cleared in
* next mark-and-sweep.
label: code-design
comment: XXX: this generates quite large code - perhaps select the error
* class based on the code and then just use the error 'name'?
label: code-design
require a short (8-bit) reg/const which fits into bytecode B/C slot
comment: Function.prototype.bind() should never let this happen,
* ugly error message is enough.
label: code-design
"123." is allowed in some formats
Apply ToNumber() to specified index; if ToInteger(val) in [0,99], add
* 1900 and replace value at idx_val.
NB: must accept reserved words as property name
no array part
* Misc
error message doesn't matter, ignored anyway
Resolve 'res' directly into the LHS binding, and use
* that as the expression value if safe. If not safe,
* resolve to a temp/const and copy to LHS.
* Found existing own (non-inherited) plain property.
* Do an access control check and update in place.
Currently nothing to free
comment: Convenience copies from heap/vm for faster access.
label: code-design
Reply with tvals pushed by request callback
If out of catchstack, cat = thr->catchstack - 1;
* new_cat_top will be 0 in that case.
comment: XXX: Could just lookup .toJSON() and continue in fast path,
* as it would almost never be defined.
label: code-design
comment:
* Raw write/read macros for big endian, unaligned basic values.
* Caller ensures there's enough space. The macros update the pointer
* argument automatically on resizes. The idiom seems a bit odd, but
* leads to compact code.
label: code-design
comment:
* "arguments" and "caller" must be mapped to throwers for strict
* mode and bound functions (E5 Section 15.3.5).
*
* XXX: This is expensive to have for every strict function instance.
* Try to implement as virtual properties or on-demand created properties.
label: code-design
'index'
index is above internal string length -> property is fully normal
LF line terminator; CR LF and Unicode lineterms are handled in slow path
* Misc helpers
expt==-1023 -> bitstart=0 (leading 1);
* expt==-1024 -> bitstart=-1 (one left of leading 1), etc
bound chain resolved
base
Line format: <time> <entryLev> <loggerName>: <msg>
NEXTENUM jump slot: executed when enum finished
comment: prototype should be last, for readability
label: code-design
comment: XXX: direct implementation
label: requirement
Error codes.
multi-character sets not allowed as part of ranges, see
* E5 Section 15.10.2.15, abstract operation CharacterRange.
* Property lookup
Constants for duk_hashstring().
roughly 1 kiB
advance by one character (code point) and one char_offset
no need to coerce
remove key and value
A regexp token value.
large context; around 2kB now
lexer character window helpers
at index 1
trivial cases
duplicate/invalid key checks; returns 1 if syntax error
Here we could remove references to built-ins, but it may not be
* worth the effort because built-ins are quite likely to be shared
* with another (unterminated) thread, and terminated threads are also
* usually garbage collected quite quickly. Also, doing DECREFs
* could trigger finalization, which would run on the current thread
* and have access to only some of the built-ins. Garbage collection
* deals with this correctly already.
Name will be filled from function expression, not by caller.
* This case is used by Function constructor and duk_compile()
* API with the DUK_COMPILE_FUNCTION option.
original target at entry_top - 1
not emitted
comment: XXX: duk_ssize_t would be useful here
label: code-design
comp_ctx->lex.input and comp_ctx->lex.input_length filled by caller
comment: XXX: pre-checks (such as no duplicate keys)
label: code-design
To handle deeper indents efficiently, make use of copies we've
* already emitted. In effect we can emit a sequence of 1, 2, 4,
* 8, etc copies, and then finish the last run. Byte counters
* avoid multiply with gap_len on every loop.
comment: XXX: TRYCATCH handling should be reworked to avoid creating
* an explicit scope unless it is actually needed (e.g. function
* instances or eval is executed inside the catch block). This
* rework is not trivial because the compiler doesn't have an
* intermediate representation. When the rework is done, the
* opcode format can also be made more straightforward.
label: code-design
Because new_size != 0, if condition doesn't need to be
* (p != NULL || new_size == 0).
* Init lexer
'%'
* This test fails on an exotic ARM target; double-to-uint
* cast is incorrectly clamped to -signed- int highest value.
*
* https://github.com/svaarala/duktape/issues/336
DUK_TOK_NUMBER
IEEE exp without bias
31 bits
call handling
not exposed
No need to check for size of bp_active list,
* it's always larger than maximum number of
* breakpoints.
comment:
* Restart execution by reloading thread state.
*
* Note that 'thr' and any thread configuration may have changed,
* so all local variables are suspect and we need to reinitialize.
*
* The number of local variables should be kept to a minimum: if
* the variables are spilled, they will need to be loaded from
* memory anyway.
*
* Any 'goto restart_execution;' code path in opcode dispatch must
* ensure 'curr_pc' is synced back to act->curr_pc before the goto
* takes place.
*
* The interpreter must be very careful with memory pointers, as
* many pointers are not guaranteed to be 'stable' and may be
* reallocated and relocated on-the-fly quite easily (e.g. by a
* memory allocation or a property access).
*
* The following are assumed to have stable pointers:
* - the current thread
* - the current function
* - the bytecode, constant table, inner function table of the
* current function (as they are a part of the function allocation)
*
* The following are assumed to have semi-stable pointers:
* - the current activation entry: stable as long as callstack
* is not changed (reallocated by growing or shrinking), or
* by any garbage collection invocation (through finalizers)
* - Note in particular that ANY DECREF can invalidate the
* activation pointer, so for the most part a fresh lookup
* is required
*
* The following are not assumed to have stable pointers at all:
* - the value stack (registers) of the current thread
* - the catch stack of the current thread
*
* See execution.rst for discussion.
label: code-design
For internal use: get array part value
10xx xxxx -> invalid
Compiler is responsible for selecting property flags (configurability,
* writability, etc).
_Varmap is dense
DUK_TOK_BAND
comment: 0x00 ... 0x7f: as is
* 0x80: escape generically
* 0x81: slow path
* 0xa0 ... 0xff: backslash + one char
label: code-design
* Exposed matcher function which provides the semantics of RegExp.prototype.exec().
*
* RegExp.prototype.test() has the same semantics as exec() but does not return the
* result object (which contains the matching string and capture groups). Currently
* there is no separate test() helper, so a temporary result object is created and
* discarded if test() is needed. This is intentional, to save code space.
*
* Input stack: [ ... re_obj input ]
* Output stack: [ ... result ]
* Buffers have no internal references. However, a dynamic
* buffer has a separate allocation for the buffer. This is
* freed by duk_heap_free_heaphdr_raw().
indirect eval
Numbers half-way between integers must be rounded towards +Infinity,
* e.g. -3.5 must be rounded to -3 (not -4). When rounded to zero, zero
* sign must be set appropriately. E5.1 Section 15.8.2.15.
*
* Note that ANSI C round() is "round to nearest integer, away from zero",
* which is incorrect for negative values. Here we make do with floor().
* Some assertions (E5 Section 13.2).
Shared lenient buffer length clamping helper. No negative indices, no
* element/byte shifting.
comment: XXX: some code might benefit from DUK__SETTEMP_IFTEMP(ctx,x)
label: code-design
preincrement and predecrement
Value would normally be omitted, replace with 'null'.
e.g. require('/foo'), empty terms not allowed
string is internal
* Parse regexp Disjunction. Most of regexp compilation happens here.
*
* Handles Disjunction, Alternative, and Term productions directly without
* recursion. The only constructs requiring recursion are positive/negative
* lookaheads, capturing parentheses, and non-capturing parentheses.
*
* The function determines whether the entire disjunction is a 'simple atom'
* (see doc/regexp.rst discussion on 'simple quantifiers') and if so,
* returns the atom character length which is needed by the caller to keep
* track of its own atom character length. A disjunction with more than one
* alternative is never considered a simple atom (although in some cases
* that might be the case).
*
* Return value: simple atom character length or < 0 if not a simple atom.
* Appends the bytecode for the disjunction matcher to the end of the temp
* buffer.
*
* Regexp top level structure is:
*
* Disjunction = Term*
* | Term* | Disjunction
*
* Term = Assertion
* | Atom
* | Atom Quantifier
*
* An empty Term sequence is a valid disjunction alternative (e.g. /|||c||/).
*
* Notes:
*
* * Tracking of the 'simple-ness' of the current atom vs. the entire
* disjunction are separate matters. For instance, the disjunction
* may be complex, but individual atoms may be simple. Furthermore,
* simple quantifiers are used whenever possible, even if the
* disjunction as a whole is complex.
*
* * The estimate of whether an atom is simple is conservative now,
* and it would be possible to expand it. For instance, captures
* cause the disjunction to be marked complex, even though captures
* -can- be handled by simple quantifiers with some minor modifications.
*
* * Disjunction 'tainting' as 'complex' is handled at the end of the
* main for loop collectively for atoms. Assertions, quantifiers,
* and '|' tokens need to taint the result manually if necessary.
* Assertions cannot add to result char length, only atoms (and
* quantifiers) can; currently quantifiers will taint the result
* as complex though.
Get a pointer to the current buffer contents (matching current allocation
* size). May be NULL for zero size dynamic/external buffer.
success: leave varname in stack
safe
[ ... closure template len_value ]
Note: negative pc values are ignored when patching jumps, so no explicit checks needed
[ ... func this (crud) retval ]
DUK_USE_DATE_PRS_STRPTIME
comment: Global case is more complex.
label: code-design
max, excl. varargs marker
should be a safe way to compute this
not an error
prev_token slot2
side effects, perform in-place
comment: XXX: turkish / azeri
label: code-design
current variable environment (may be NULL if delayed)
May happen in some out-of-memory corner cases.
* Store lexer position for a later rewind
-> [ ... this timeval ]
Avoid using RegExp.prototype methods, as they're writable and
* configurable and may have been changed.
Index validation is strict, which differs from duk_equals().
* The strict behavior mimics how instanceof itself works, e.g.
* it is a TypeError if rval is not a -callable- object. It would
* be somewhat inconsistent if rval would be allowed to be
* non-existent without a TypeError.
prev_token slot1
Note1
comment: When DUK_USE_HEAPPTR16 (and DUK_USE_REFCOUNT16) is in use, the
* struct won't align nicely to 4 bytes. This 16-bit extra field
* is added to make the alignment clean; the field can be used by
* heap objects when 16-bit packing is used. This field is now
* conditional to DUK_USE_HEAPPTR16 only, but it is intended to be
* used with DUK_USE_REFCOUNT16 and DUK_USE_DOUBLE_LINKED_HEAP;
* this only matter to low memory environments anyway.
label: code-design
DUK_TOK_IMPORT
* Native call.
input offset tracking
-> [ ... closure template newobj closure ]
fixed arg count: value
chain jumps for case
* evaluation and checking
Called for handling both a longjmp() with type DUK_LJ_TYPE_YIELD and
* when a RETURN opcode terminates a thread and yields to the resumer.
function call
full 3-byte -> 4-char conversions
regexp compilation limits
comment: Current PC, accessed by other functions through thr->ptr_to_curr_pc.
* Critical for performance. It would be safest to make this volatile,
* but that eliminates performance benefits; aliasing guarantees
* should be enough though.
label: code-design
0x00: slow path
* other: as is
comment: XXX: this could be optimized; there is only one call site now though
label: code-design
reject 'in' token (used for for-in)
Data area, fixed allocation, stable data ptrs.
list of conversion specifiers that terminate a format tag;
* this is unfortunately guesswork.
Preliminaries for __proto__ and setPrototypeOf (E6 19.1.2.18 steps 1-4);
* magic: 0=setter call, 1=Object.setPrototypeOf
DUK_LEXER_H_INCLUDED
type bit mask: types which certainly produce 'undefined'
XXX: for threads, compact value stack, call stack, catch stack?
comment: Lightfuncs are currently supported by coercing to a temporary
* Function object; changes will be allowed (the coerced value is
* extensible) but will be lost.
label: code-design
second, parse flags
* Not found: write to global object (non-strict) or ReferenceError
* (strict); see E5 Section 8.7.2, step 3.
strict mode restrictions (E5 Section 12.2.1)
comment: Forget the previous allocation, setting size to 0 and alloc to
* NULL. Caller is responsible for freeing the previous allocation.
* Getting the allocation and clearing it is done in the same API
* call to avoid any chance of a realloc.
label: code-design
[ regexp ]
'\xffFinalizer'
comment: The entries can either be register numbers or 'null' values.
* Thus, no need to DECREF them and get side effects. DECREF'ing
* the keys (strings) can cause memory to be freed but no side
* effects as strings don't have finalizers. This is why we can
* rely on the object properties not changing from underneath us.
label: code-design
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
For all combinations: +0 < +0, +0 < -0, -0 < +0, -0 < -0,
* steps e, f, and g.
output is never longer than input during resolution
comment: XXX: make fast paths optional for size minimization?
label: code-design
comment: XXX: handling for array part missing now; this doesn't affect
* compliance but causes array entry writes using defineProperty()
* to always abandon array part.
label: code-design
Fast path the binary case
* Unicode helpers
comment: XXX: zero assumption
label: code-design
* Assertions after
r <- r
* s <- (* s B)
* m+ <- m+
* m- <- m-
* k <- (+ k 1)
'Math'
1e8: protects against deeply nested inner functions
insert ranges instruction, range count patched in later
* Validate and convert argument property descriptor (an Ecmascript
* object) into a set of defprop_flags and possibly property value,
* getter, and/or setter values on the value stack.
*
* Lightfunc set/get values are coerced to full Functions.
tc1 = false, tc2 = true
after this, return paths should 'goto finished' for decrement
obj_index
zero-width non-joiner
activation has active breakpoint(s)
Constants for built-in string data depacking.
Need to set curr_token.t because lexing regexp mode depends on current
* token type. Zero value causes "allow regexp" mode.
start (incl) and end (excl) of trimmed part
Careful with wrapping: arr_idx upshift may easily wrap, whereas
* length downshift won't.
interpret e.g. '09' as '0', not NaN
* splice()
no argument given -> leave components untouched
comment: This fast path is pretty marginal in practice.
* XXX: candidate for removal.
label: code-design
character represents itself
eat 'return'
comment: If thr != NULL, the thr may still be in the middle of
* initialization.
* XXX: Improve the thread viability test.
label: code-design
[ value offset end ]
Relies on NULL encoding to zero.
comment: XXX: the current implementation works but is quite clunky; it compiles
* to almost 1,4kB of x86 code so it needs to be simplified (better approach,
* shared helpers, etc). Some ideas for refactoring:
*
* - a primitive to convert a string into a regexp matcher (reduces matching
* code at the cost of making matching much slower)
* - use replace() as a basic helper for match() and split(), which are both
* much simpler
* - API call to get_prop and to_boolean
label: code-design
* Compilation and evaluation
Note: Identifier rejects reserved words
-> [ obj trap_result ]
* Unicode letter is now taken to be the categories:
*
* Lu, Ll, Lt, Lm, Lo
*
* (Not sure if this is exactly correct.)
*
* The ASCII fast path consists of:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
caller ensures
* Not found (in registers or record objects). Declare
* to current variable environment.
comment: 'this' binding is not needed here
label: requirement
no need to check callable; duk_call() will do that
mark finalizer work list as reachability roots
Initial '{' has been checked and eaten by caller.
'\xffMap'
The directive prologue flag is cleared by default so that it is
* unset for any recursive statement parsing. It is only "revived"
* if a directive is detected. (We could also make directives only
* allowed if 'allow_source_elem' was true.)
'NaN'
unsigned 31-bit range
DUK_USE_EXPLICIT_NULL_INIT
valgrind whine without this
comment:
* Helper for calling a user error handler.
*
* 'thr' must be the currently active thread; the error handler is called
* in its context. The valstack of 'thr' must have the error value on
* top, and will be replaced by another error value based on the return
* value of the error handler.
*
* The helper calls duk_handle_call() recursively in protected mode.
* Before that call happens, no longjmps should happen; as a consequence,
* we must assume that the valstack contains enough temporary space for
* arguments and such.
*
* While the error handler runs, any errors thrown will not trigger a
* recursive error handler call (this is implemented using a heap level
* flag which will "follow" through any coroutines resumed inside the
* error handler). If the error handler is not callable or throws an
* error, the resulting error replaces the original error (for Duktape
* internal errors, duk_error_throw.c further substitutes this error with
* a DoubleError which is not ideal). This would be easy to change and
* even signal to the caller.
*
* The user error handler is stored in 'Duktape.errCreate' or
* 'Duktape.errThrow' depending on whether we're augmenting the error at
* creation or throw time. There are several alternatives to this approach,
* see doc/error-objects.rst for discussion.
*
* Note: since further longjmp()s may occur while calling the error handler
* (for many reasons, e.g. a labeled 'break' inside the handler), the
* caller can make no assumptions on the thr->heap->lj state after the
* call (this affects especially duk_error_throw.c). This is not an issue
* as long as the caller writes to the lj state only after the error handler
* finishes.
label: code-design
* Exposed calls
key encountered as a setter
Don't need to sync curr_pc here; duk_new() will do that
* when it augments the created error.
one i_step over
Shared prefix for all buffer types.
* Environment record creation and 'arguments' object creation.
* Named function expression name binding is handled by the
* compiler; the compiled function's parent env will contain
* the (immutable) binding already.
*
* Delayed creation (on demand) is handled in duk_js_var.c.
Reject a proxy object as the target because it would need
* special handler in property lookups. (ES6 has no such restriction)
must restore reliably before returning
* Basic context initialization.
*
* Some init values are read from the bytecode header
* whose format is (UTF-8 codepoints):
*
* uint flags
* uint nsaved (even, 2n+2 where n = num captures)
return 'res_arr' or 'null'
comment: This would be nice, but parsing is faster without resetting the
* value slots. The only side effect is that references to temporary
* string values may linger until lexing is finished; they're then
* freed normally.
label: code-design
break jump
"123"
Note: the only yield-preventing call is Duktape.Thread.yield(), hence check for 1, not 0
range check not necessary because all 4-bit values are mapped
floor(1.15 * (1 << 10))
expect_eof
.-- p_insert .-- p_curr
* v v
* | ... | insert | ... | curr
* Stack constants
call: this.fmt(arg)
Combined step 11 (empty string special case) and 14-15.
w/o refcounting
Example: d=3.5, t=0.5 -> ret = (3 + 1) & 0xfe = 4 & 0xfe = 4
* Example: d=4.5, t=0.5 -> ret = (4 + 1) & 0xfe = 5 & 0xfe = 4
Write fully.
Assume IEEE round-to-even, so that shorter encoding can be used
* when round-to-even would produce correct result. By removing
* this check (and having low_ok == high_ok == 0) the results would
* still be accurate but in some cases longer than necessary.
object established using Function.prototype.bind()
* Heap object refcount finalization.
*
* When an object is about to be freed, all other objects it refers to must
* be decref'd. Refcount finalization does NOT free the object or its inner
* allocations (mark-and-sweep shares these helpers), it just manipulates
* the refcounts.
*
* Note that any of the decref's may cause a refcount to drop to zero, BUT
* it will not be processed inline; instead, because refzero is already
* running, the objects will just be queued to refzero list and processed
* later. This eliminates C recursion.
output radix
resume check from proxy target
native function properties
1e8
Lightfunc flags packing and unpacking.
Helpers exposed for internal use
* Hash function duk_util_hashbytes().
*
* Currently, 32-bit MurmurHash2.
*
* Don't rely on specific hash values; hash function may be endianness
* dependent, for instance.
comment: NULL always indicates alloc failure because
* new_alloc_size > 0.
label: code-design
The final object may be a normal function or a lightfunc.
* We need to re-lookup tv_func because it may have changed
* (also value stack may have been resized). Loop again to
* do that; we're guaranteed not to come here again.
comment: For objects JSON.stringify() only looks for own, enumerable
* properties which is nice for the fast path here.
*
* For arrays JSON.stringify() uses [[Get]] so it will actually
* inherit properties during serialization! This fast path
* supports gappy arrays as long as there's no actual inherited
* property (which might be a getter etc).
*
* Since recursion only happens for objects, we can have both
* recursion and loop checks here. We use a simple, depth-limited
* loop check in the fast path because the object-based tracking
* is very slow (when tested, it accounted for 50% of fast path
* execution time for input data with a lot of small objects!).
label: code-design
assertion omitted
-> [... obj finalizer]
does not fit into an uchar
need to normalize, may even cancel to 0
Callee/caller are throwers and are not deletable etc. They
* could be implemented as virtual properties, but currently
* there is no support for virtual properties which are accessors
* (only plain virtual properties). This would not be difficult
* to change in duk_hobject_props, but we can make the throwers
* normal, concrete properties just as easily.
*
* Note that the specification requires that the *same* thrower
* built-in object is used here! See E5 Section 10.6 main
* algoritm, step 14, and Section 13.2.3 which describes the
* thrower. See test case test-arguments-throwers.js.
used for array, stack, and entry indices
[ ... name reg_bind ]
Select copy mode. Must take into account element
* compatibility and validity of the underlying source
* buffer.
invalid value which never matches
Arrays never have other exotic behaviors.
0xxx xxxx [7 bits]
[ ... env target ]
Setup builtins from ROM objects. All heaps/threads will share
* the same readonly objects.
comment: alloc size in elements
label: code-design
* Init remaining result fields
*
* 'nregs' controls how large a register frame is allocated.
*
* 'nargs' controls how many formal arguments are written to registers:
* r0, ... r(nargs-1). The remaining registers are initialized to
* undefined.
note: caller 'sp' is intentionally not updated here
Underlying buffer (refcounted), may be NULL.
actual chars dropped (not just NUL term)
free-form
formals for 'func' (may be NULL if func is a C function)
comment: bytes of indent available for copying
label: code-design
* Valstack manipulation for results.
[obj key desc value get set curr_value varname]
* Add ._Tracedata to an error on the stack top.
force executor restart to recheck breakpoints; used to handle function returns (see GH-303)
Lexer context. Same context is used for Ecmascript and Regexp parsing.
comment: XXX: spilling
label: code-design
Note: rely on index ordering
* Get enumerated keys in an Ecmascript array. Matches Object.keys() behavior
* described in E5 Section 15.2.3.14.
NB: duk_lexer_getpoint() is a macro only
dangerous: must only lower (temp_max not updated)
x <- x + y, use t as temp
* Init argument related properties
add BC*2^16
initial stringtable size, must be prime and higher than DUK_UTIL_MIN_HASH_PRIME
char format: use int
Clamping only necessary for 32-bit ints.
maximum size check is handled by callee
-> [ ... val root val ]
Note: start_offset/end_offset can still be < 0 here.
cat_idx catcher is kept, even for finally
"null", "true", and "false" are always reserved words.
* Note that "get" and "set" are not!
AssignmentExpression
DUK_TOK_MOD
comment: XXX: this is pointless here because pass 1 is throw-away
label: code-design
Possibly truncated; there is no explicit truncation
* marker so this is the best we can do.
'fatal'
* Plain, boring reachable object.
value of re_ctx->captures at start of atom
* Find an existing key from entry part either by linear scan or by
* using the hash index (if it exists).
*
* Sets entry index (and possibly the hash index) to output variables,
* which allows the caller to update the entry and hash entries in-place.
* If entry is not found, both values are set to -1. If entry is found
* but there is no hash part, h_idx is set to -1.
pc_label
'configurable'
* Object prototype
'this' binding exists
XXX: direct manipulation, or duk_replace_tval()
fill window
comment:
* Helper for handling a "bound function" chain when a call is being made.
*
* Follows the bound function chain until a non-bound function is found.
* Prepends the bound arguments to the value stack (at idx_func + 2),
* updating 'num_stack_args' in the process. The 'this' binding is also
* updated if necessary (at idx_func + 1). Note that for constructor calls
* the 'this' binding is never updated by [[BoundThis]].
*
* XXX: bound function chains could be collapsed at bound function creation
* time so that each bound function would point directly to a non-bound
* function. This would make call time handling much easier.
label: code-design
* Constructor arguments are currently somewhat compatible with
* (keep it that way if possible):
*
* http://nodejs.org/api/buffer.html
*
* Note that the ToBuffer() coercion (duk_to_buffer()) does NOT match
* the constructor behavior.
* Emit compiled regexp header: flags, ncaptures
* (insertion order inverted on purpose)
* Logging support
[key result]
unchanged by Duktape.Thread.resume()
arguments object would be accessible; note that shadowing
* bindings are arguments or function declarations, neither
* of which are deletable, so this is safe.
Return 1: got EOM
include removed: duk_internal.h
NOTE: length may be zero
SCANBUILD: NULL pointer dereference, doesn't actually trigger,
* asserted above.
Alignment guarantee
!DUK_USE_PREFER_SIZE
Note1: the specification doesn't require matching a time form with
* just hours ("HH"), but we accept it here, e.g. "2012-01-02T12Z".
*
* Note2: the specification doesn't require matching a timezone offset
* with just hours ("HH"), but accept it here, e.g. "2012-01-02T03:04:05+02"
* Mark the heap.
silence scan-build warning
varname is popped by above code
Estimating the result size beforehand would be costly, so
* start with a reasonable size and extend as needed.
Decode failed.
* Init stringcache
[... constructor arg1 ... argN final_cons]
comment: XXX: lithuanian, explicit dot rules
label: code-design
XXX: similar coercion issue as in DUK_TOK_PERIOD
comment: Wipe capture range and save old values for backtracking.
*
* XXX: this typically happens with a relatively small idx_count.
* It might be useful to handle cases where the count is small
* (say <= 8) by saving the values in stack instead. This would
* reduce memory churn and improve performance, at the cost of a
* slightly higher code footprint.
label: code-design
source out-of-bounds (but positive)
'with' binding has no catch clause, so can't be here unless a normal try-catch
second incref for the entry reference
comment: XXX: declvar takes an duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
Get.
DUK_TOK_PRIVATE
randomized pivot selection
* Check whether the property already exists in the prototype chain.
* Note that the actual write goes into the original base object
* (except if an accessor property captures the write).
These are not needed when only Duktape.Buffer is supported.
duk_hobject specific fields.
[val] -> []
Map DUK_HBUFFEROBJECT_ELEM_xxx to duk_hobject class number.
* Sync with duk_hbufferobject.h and duk_hobject.h.
* Shared exit path
force_exponential
As an initial implementation, write flush after every EOM (and the
* version identifier). A better implementation would flush only when
* Duktape is finished processing messages so that a flush only happens
* after all outbound messages are finished on that occasion.
DUK_INVALID_INDEX won't be accepted as a valid index.
* Heap thread object representation.
*
* duk_hthread is also the 'context' (duk_context) for exposed APIs
* which mostly operate on the topmost frame of the value stack.
DUK_USE_BUFFEROBJECT_SUPPORT
As an initial implementation, read flush after exiting the message
* loop. If transport is broken, this is a no-op (with debug logs).
* Figure out how generated digits match up with the mantissa,
* and then perform rounding. If mantissa overflows, need to
* recompute the exponent (it is bumped and may overflow to
* infinity).
*
* For normal numbers the leading '1' is hidden and ignored,
* and the last bit is used for rounding:
*
* rounding pt
* <--------52------->|
* 1 x x x x ... x x x x|y ==> x x x x ... x x x x
*
* For denormals, the leading '1' is included in the number,
* and the rounding point is different:
*
* rounding pt
* <--52 or less--->|
* 1 x x x x ... x x|x x y ==> 0 0 ... 1 x x ... x x
*
* The largest denormals will have a mantissa beginning with
* a '1' (the explicit leading bit); smaller denormals will
* have leading zero bits.
*
* If the exponent would become too high, the result becomes
* Infinity. If the exponent is so small that the entire
* mantissa becomes zero, the result becomes zero.
*
* Note: the Dragon4 'k' is off-by-one with respect to the IEEE
* exponent. For instance, k==0 indicates that the leading '1'
* digit is at the first binary fraction position (0.1xxx...);
* the corresponding IEEE exponent would be -1.
string hash
Relookup in case coerce_func() has side effects, e.g. ends up coercing an object
0 = no update
regexp opcodes
'function'
recursion limit
utf-8 validation ensures these
count, not including sep
string data is external (duk_hstring_external)
currently paused: talk with debug client until step/resume
duk_concat() coerces arguments with ToString() in correct order
2 to 11
guaranteed to finish
const flag for B
one i_step added at top of loop
'res' may be NULL if new allocation size is 0.
comment: Shared entry code for many Array built-ins. Note that length is left
* on stack (it could be popped, but that's not necessary).
label: code-design
thread
assume PC is at most 32 bits and non-negative
1 0 <2 bits>
comment:
* Shared handling for logical AND and logical OR.
*
* args = (truthval << 8) + rbp
*
* Truthval determines when to skip right-hand-side.
* For logical AND truthval=1, for logical OR truthval=0.
*
* See doc/compiler.rst for discussion on compiling logical
* AND and OR expressions. The approach here is very simplistic,
* generating extra jumps and multiple evaluations of truth values,
* but generates code on-the-fly with only local back-patching.
*
* Both logical AND and OR are syntactically left-associated.
* However, logical ANDs are compiled as right associative
* expressions, i.e. "A && B && C" as "A && (B && C)", to allow
* skip jumps to skip over the entire tail. Similarly for logical OR.
label: code-design
NULL obj->p is OK
* In strict mode E5 protects 'eval' and 'arguments' from being
* assigned to (or even declared anywhere). Attempt to do so
* should result in a compile time SyntaxError. See the internal
* design documentation for details.
*
* Thus, we should never come here, run-time, for strict code,
* and name 'eval' or 'arguments'.
Assume that thr->valstack_bottom has been set-up before getting here.
len: 9
* E5 Section 11.4.9
deal with weak references first
duk_push_sprintf constants
negative: dst info not available
topmost element is the result array already
Fast path, handle units with just actual encoding characters.
out of spec, must be configurable
* Debug logging after adjustment.
* Pushers
comment:
* Note: each API operation potentially resizes the callstack,
* so be careful to re-lookup after every operation. Currently
* these is no issue because we don't store a temporary 'act'
* pointer at all. (This would be a non-issue if we operated
* directly on the array part.)
label: code-design
implicit_return_value
XXX: direct valstack write
[ ... source? filename ]
No resize has occurred so temp_desc->e_idx is still OK
lookup for 0x000a above assumes shortest encoding now
XXX: E5.1 Section 11.1.4 coerces the final length through
* ToUint32() which is odd but happens now as a side effect of
* 'arr_idx' type.
Read tvals from the message and push them onto the valstack,
* then call the request callback to process the request.
true, despite side effect resizes
the stack is unbalanced here on purpose; we only rely on the
* initial two values: [ name this ].
[ start end str ]
source is eval code (not global)
switch initial byte
Note: pc is unsigned and cannot be negative
* Casting
comment:
* User declarations, e.g. prototypes for user functions used by Duktape
* macros. Concretely, if DUK_USE_PANIC_HANDLER is used and the macro
* value calls a user function, it needs to be declared for Duktape
* compilation to avoid warnings.
label: code-design
Longjmp handling has restored jmpbuf_ptr.
* Round a number upwards to a prime (not usually the nearest one).
*
* Uses a table of successive 32-bit primes whose ratio is roughly
* constant. This keeps the relative upwards 'rounding error' bounded
* and the data size small. A simple 'predict-correct' compression is
* used to compress primes to one byte per prime. See genhashsizes.py
* for details.
*
* The minimum prime returned here must be coordinated with the possible
* probe sequence steps in duk_hobject and duk_heap stringtable.
-> [ ... varname val this ]
processed one or more messages
[ ... v1(filename) v2(line+flags) ]
must have been, since in array part
slower but more compact variant
TypedArray (or other non-ArrayBuffer duk_hbufferobject).
* Conceptually same behavior as for an Array-like argument,
* with a few fast paths.
comment: parameter passing, not thread safe
label: requirement
comment: Two temporaries are preallocated here for variants 3 and 4 which need
* registers which are never clobbered by expressions in the loop
* (concretely: for the enumerator object and the next enumerated value).
* Variants 1 and 2 "release" these temps.
label: code-design
Note: decimal number may start with a period, but must be followed by a digit
main reachability roots
DUK_HBUFFER_H_INCLUDED
Inputs: explicit arguments (nargs), +1 for key, +2 for obj_index/nargs passing.
* If the value stack does not contain enough args, an error is thrown; this matches
* behavior of the other protected call API functions.
[ value offset fieldByteLength noAssert ], when ftype == DUK__FLD_VARINT
placed in duk_heaphdr_string
* Main mark-and-sweep function.
*
* 'flags' represents the features requested by the caller. The current
* heap->mark_and_sweep_base_flags is ORed automatically into the flags;
* the base flags mask typically prevents certain mark-and-sweep operations
* to avoid trouble.
'private'
toJSON() can also be a lightfunc
Special behavior for 'caller' property of (non-bound) function objects
* and non-strict Arguments objects: if 'caller' -value- (!) is a strict
* mode function, throw a TypeError (E5 Sections 15.3.5.4, 10.6).
* Quite interestingly, a non-strict function with no formal arguments
* will get an arguments object -without- special 'caller' behavior!
*
* The E5.1 spec is a bit ambiguous if this special behavior applies when
* a bound function is the base value (not the 'caller' value): Section
* 15.3.4.5 (describing bind()) states that [[Get]] for bound functions
* matches that of Section 15.3.5.4 ([[Get]] for Function instances).
* However, Section 13.3.5.4 has "NOTE: Function objects created using
* Function.prototype.bind use the default [[Get]] internal method."
* The current implementation assumes this means that bound functions
* should not have the special [[Get]] behavior.
*
* The E5.1 spec is also a bit unclear if the TypeError throwing is
* applied if the 'caller' value is a strict bound function. The
* current implementation will throw even for both strict non-bound
* and strict bound functions.
*
* See test-dev-strict-func-as-caller-prop-value.js for quite extensive
* tests.
*
* This exotic behavior is disabled when the non-standard 'caller' property
* is enabled, as it conflicts with the free use of 'caller'.
move pivot out of the way
final configuration
-1 == not set, -2 == pending (next statement list)
comment: temporary, must be signed and 32-bit to hold Unicode code points
label: code-design
NB: 'length' property is automatically updated by the array setup loop
index for next new key ([0,e_next[ are gc reachable)
idx is unsigned, < 0 check is not necessary
indirect opcode follows direct
* toFixed(), toExponential(), toPrecision()
* Helpers for UTF-8 handling
*
* For bytecode readers the duk_uint32_t and duk_int32_t types are correct
* because they're used for more than just codepoints.
follow prototype chain
[ value ]
XXX: incref by count (here 2 times)
equals
true even with reattach
Fatal error handling, called e.g. when a longjmp() is needed but
* lj.jmpbuf_ptr is NULL. fatal_func must never return; it's not
* declared as "noreturn" because doing that for typedefs is a bit
* challenging portability-wise.
comment: XXX: very messy now, but works; clean up, remove unused variables (nomimally
* used so compiler doesn't complain).
label: code-design
* Note: type is treated as a field separate from flags, so some masking is
* involved in the macros below.
Compute final offset in seconds, positive if local time ahead of
* UTC (returned value is UTC-to-local offset).
*
* difftime() returns a double, so coercion to int generates quite
* a lot of code. Direct subtraction is not portable, however.
* XXX: allow direct subtraction on known platforms.
comment: XXX: this is a very narrow check, and doesn't cover
* zeroes, subnormals, infinities, which compare normally.
label: code-design
Don't allow a zero divisor. Fast path check by
* "verifying" with multiplication. Also avoid zero
* dividend to avoid negative zero issues (0 / -1 = -0
* for instance).
numeric value of a hex digit (also covers octal and decimal digits)
DUK_TOK_MUL_EQ
DUK_USE_DEBUG
comment: XXX: optimize to use direct reads, i.e. avoid
* value stack operations.
label: code-design
0x00: finish (non-white)
* 0x01: continue
%lu
[ ... arg1 ... argN ]
executor interrupt running (used to avoid nested interrupts)
[ ... func this ]
Constants: variable size encoding.
* Variable declarations.
*
* Unlike function declarations, variable declaration values don't get
* assigned on entry. If a binding of the same name already exists, just
* ignore it silently.
comment: XXX: duk_small_uint_t would be enough for this loop
label: code-design
no res->strs[]
* Debug dumping of duk_heap.
Detach a debugger if attached (can be called multiple times)
* safely.
if 1, doing a string-to-number; else doing a number-to-string
comment: Faster alternative: avoid making a temporary copy of tvptr_dst and use
* fast incref/decref macros.
label: code-design
* duk_hbuffer allocation and freeing.
stash to bottom of value stack to keep new_env reachable for duration of eval
step 4.a
Handle a RETURN opcode. Avoid using longjmp() for return handling because
* it has a measurable performance impact in ordinary environments and an extreme
* impact in Emscripten (GH-342). Return value is on value stack top.
exports
Note: must behave like a no-op with NULL and any pointer
* returned from malloc/realloc with zero size.
comment: XXX: use duk_is_valid_index() instead?
label: code-design
eat closing bracket
* Object.isSealed() and Object.isFrozen() (E5 Sections 15.2.3.11, 15.2.3.13)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: all virtual (non-concrete) properties are currently non-configurable
* and non-writable (and there are no accessor virtual properties), so they don't
* need to be considered here now.
* The switch statement is pretty messy to compile.
* See the helper for details.
re_ctx->captures at start and end of atom parsing.
* Since 'captures' indicates highest capture number emitted
* so far in a DUK_REOP_SAVE, the captures numbers saved by
* the atom are: ]start_captures,end_captures].
Loop check using a hybrid approach: a fixed-size visited[] array
* with overflow in a loop check object.
first value: comma must not precede the value
actually used, non-NULL keys
r <- (2 * b) * f
[ ... re_obj input bc saved_buf res_obj ]
* Create wrapper object and serialize
t1 <- t1 - s
* Label handling
*
* Labels are initially added with flags prohibiting both break and continue.
* When the statement type is finally uncovered (after potentially multiple
* labels), all the labels are updated to allow/prohibit break and continue.
112.5%, i.e. new size less than 12.5% higher -> fast resize
* URI handling
* ASCII character constants
*
* C character literals like 'x' have a platform specific value and do
* not match ASCII (UTF-8) values on e.g. EBCDIC platforms. So, use
* these (admittedly awkward) constants instead. These constants must
* also have signed values to avoid unexpected coercions in comparisons.
*
* http://en.wikipedia.org/wiki/ASCII
32-bit value
string intern table (weak refs)
comment:
* Shared error message strings
*
* To minimize code footprint, try to share error messages inside Duktape
* code. Modern compilers will do this automatically anyway, this is mostly
* for older compilers.
label: code-design
Convert indices to byte offsets.
'l'
Fast path: source is a TypedArray (or any bufferobject).
Note: object cannot be a finalizable unreachable object, as
* they have been marked temporarily reachable for this round,
* and are handled above.
'var'
[ args(n) [crud] formals arguments map mappednames ]
comment: Note: 'this' is not necessarily an Array object. The push()
* algorithm is supposed to work for other kinds of objects too,
* so the algorithm has e.g. an explicit update for the 'length'
* property which is normally "magical" in arrays.
label: code-design
comment:
* XXX: array indices are mostly typed as duk_uint32_t here; duk_uarridx_t
* might be more appropriate.
label: code-design
'pointer'
Return value would be pointless: because throw_flag==1, we always
* throw if the identifier doesn't resolve.
PC points to next instruction, find offending PC,
* PC == 0 for native code.
DUK_UNICODE_H_INCLUDED
comment: dead code, but ensures portability (see Linux man page notes)
label: code-design
DUK__ALLOW_AUTO_SEMI_ALWAYS workaround
end of valstack allocation (exclusive)
previous value is assumed to be garbage, so don't touch it
* Scan number and setup for Dragon4.
*
* The fast path case is detected during setup: an integer which
* can be converted without rounding, no net exponent. The fast
* path could be implemented as a separate scan, but may not really
* be worth it: the multiplications for building 'f' are not
* expensive when 'f' is small.
*
* The significand ('f') must contain enough bits of (apparent)
* accuracy, so that Dragon4 will generate enough binary output digits.
* For decimal numbers, this means generating a 20-digit significand,
* which should yield enough practical accuracy to parse IEEE doubles.
* In fact, the Ecmascript specification explicitly allows an
* implementation to treat digits beyond 20 as zeroes (and even
* to round the 20th digit upwards). For non-decimal numbers, the
* appropriate number of digits has been precomputed for comparable
* accuracy.
*
* Digit counts:
*
* [ dig_lzero ]
* |
* .+-..---[ dig_prec ]----.
* | || |
* 0000123.456789012345678901234567890e+123456
* | | | | | |
* `--+--' `------[ dig_frac ]-------' `-+--'
* | |
* [ dig_whole ] [ dig_expt ]
*
* dig_frac and dig_expt are -1 if not present
* dig_lzero is only computed for whole number part
*
* Parsing state
*
* Parsing whole part dig_frac < 0 AND dig_expt < 0
* Parsing fraction part dig_frac >= 0 AND dig_expt < 0
* Parsing exponent part dig_expt >= 0 (dig_frac may be < 0 or >= 0)
*
* Note: in case we hit an implementation limit (like exponent range),
* we should throw an error, NOT return NaN or Infinity. Even with
* very large exponent (or significand) values the final result may be
* finite, so NaN/Infinity would be incorrect.
comment: suppress warning, not used
label: code-design
Buffer/string -> compare contents.
* Update cache entry (allocating if necessary), and move the
* cache entry to the first place (in an "LRU" policy).
finished jump
string is ASCII, clen == blen
DUK_USE_HOBJECT_HASH_PART || DUK_USE_STRTAB_PROBE
* Since character data is only generated by decoding the source or by
* the compiler itself, we rely on the input codepoints being correct
* and avoid a check here.
*
* Character data can also come here through decoding of Unicode
* escapes ("\udead\ubeef") so all 16-but unsigned values can be
* present, even when the source file itself is strict UTF-8.
comment: XXX: more emergency behavior, e.g. find smaller hash sizes etc
label: code-design
* Copy array elements to new array part.
For strings, special form for short lengths.
Setup function properties.
comment:
* In a fast check we assume old_size equals old_used (i.e., existing
* array is fully dense).
*
* Slow check if:
*
* (new_size - old_size) / old_size > limit
* new_size - old_size > limit * old_size
* new_size > (1 + limit) * old_size || limit' is 3 bits fixed point
* new_size > (1 + (limit' / 8)) * old_size || * 8
* 8 * new_size > (8 + limit') * old_size || : 8
* new_size > (8 + limit') * (old_size / 8)
* new_size > limit'' * (old_size / 8) || limit'' = 9 -> max 25% increase
* arr_idx + 1 > limit'' * (old_size / 8)
*
* This check doesn't work well for small values, so old_size is rounded
* up for the check (and the '+ 1' of arr_idx can be ignored in practice):
*
* arr_idx > limit'' * ((old_size + 7) / 8)
label: code-design
comment:
* A few notes on the algorithm:
*
* - Terms are not allowed to begin with a period unless the term
* is either '.' or '..'. This simplifies implementation (and
* is within CommonJS modules specification).
*
* - There are few output bound checks here. This is on purpose:
* the resolution input is length checked and the output is never
* longer than the input. The resolved output is written directly
* over the input because it's never longer than the input at any
* point in the algorithm.
*
* - Non-ASCII characters are processed as individual bytes and
* need no special treatment. However, U+0000 terminates the
* algorithm; this is not an issue because U+0000 is not a
* desirable term character anyway.
label: code-design
* Utilities
* Helpers
*
* The fast path checks are done within a macro to ensure "inlining"
* while the slow path actions use a helper (which won't typically be
* inlined in size optimized builds).
comment: If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
label: code-design
comment: XXX: now that pc2line is used by the debugger quite heavily in
* checked execution, this should be optimized to avoid value stack
* and perhaps also implement some form of pc2line caching (see
* future work in debugger.rst).
label: code-design
* Case clause.
*
* Note: cannot use reg_case as a temp register (for SEQ target)
* because it may be a constant.
comment: XXX: not sure what the correct semantic details are here,
* e.g. handling of missing values (gaps), handling of non-array
* trap results, etc.
*
* For keys, we simply skip non-string keys which seems to be
* consistent with how e.g. Object.keys() will process proxy trap
* results (ES6, Section 19.1.2.14).
label: code-design
comment: XXX: 'copy properties' API call?
label: code-design
* Determine whether to use the constructor return value as the created
* object instance or not.
Stack top contains plain value
make current token the previous; need to fiddle with valstack "backing store"
'{_func:true}'
prediction: portable variant using doubles if 64-bit values not available
[ ... arr val ]
Casting convenience.
The stack has a variable shape here, so force it to the
* desired one explicitly.
comment: XXX: does not work if thr->catchstack is NULL
label: code-design
Object.getOwnPropertyNames
'undefined'
comment: XXX: with 'caller' property the callstack would need
* to be unwound to update the 'caller' properties of
* functions in the callstack.
label: code-design
Overestimate required size; debug code so not critical to be tight.
comment: no special formatting
label: code-design
proplist is very rare
* Handling DUK_OP_ADD this way is more compact (experimentally)
* than a separate case with separate argument decoding.
currently processing messages or breakpoints: don't enter message processing recursively (e.g. no breakpoints when processing debugger eval)
DUK_USE_JC
function refers to 'arguments' identifier
don't want an intermediate exposed state with invalid pc
Use loop to minimize code size of relookup after bound function case
'Undefined'
comment:
* Variable already declared, ignore re-declaration.
* The only exception is the updated behavior of E5.1 for
* global function declarations, E5.1 Section 10.5, step 5.e.
* This behavior does not apply to global variable declarations.
label: code-design
comment: Avoid fake finalization for the duk__refcount_fake_finalizer function
* itself, otherwise we're in infinite recursion.
label: code-design
comment: Borrow is detected based on wrapping which relies on exact 32-bit
* types.
label: code-design
if abandon_array, new_a_size must be 0
Parse enumeration target and initialize enumerator. For 'null' and 'undefined',
* INITENUM will creates a 'null' enumerator which works like an empty enumerator
* (E5 Section 12.6.4, step 3). Note that INITENUM requires the value to be in a
* register (constant not allowed).
pointer is aligned, guaranteed for fixed buffer
See MPUTOBJ comments above.
Pause on the next opcode executed. This is always safe to do even
* inside the debugger message loop: the interrupt counter will be reset
* to its proper value when the message loop exits.
Ensure there is internal valstack spare before we exit; this may
* throw an alloc error. The same guaranteed size must be available
* as before the call. This is not optimal now: we store the valstack
* allocated size during entry; this value may be higher than the
* minimal guarantee for an application.
'\xffPc2line'
comment: XXX: better coercion
label: code-design
guaranteed to finish, as hash is never full
shared flags for a subset of types
nothing to incref
The short string/integer initial bytes starting from 0x60 don't have
* defines now.
comment: XXX: use a helper for prototype traversal; no loop check here
label: code-design
FunctionDeclaration: not strictly a statement but handled as such.
*
* O(depth^2) parse count for inner functions is handled by recording a
* lexer offset on the first compilation pass, so that the function can
* be efficiently skipped on the second pass. This is encapsulated into
* duk__parse_func_like_fnum().
unpack args
hash lookup
* Cleanup: restore original function, restore valstack state.
don't touch property attributes or hash part
Note: duk_uint8_t type yields larger code
* The error object has been augmented with a traceback and other
* info from its creation point -- usually another thread. The
* error handler is called here right before throwing, but it also
* runs in the resumer's thread. It might be nice to get a traceback
* from the resumee but this is not the case now.
Push function object, init flags etc. This must match
* duk_js_push_closure() quite carefully.
return arg as-is
NULL accepted
Lightfunc, not blamed now.
0 = no throw
comment: XXX: macros
label: code-design
Interrupt counter for triggering a slow path check for execution
* timeout, debugger interaction such as breakpoints, etc. The value
* is valid for the current running thread, and both the init and
* counter values are copied whenever a thread switch occurs. It's
* important for the counter to be conveniently accessible for the
* bytecode executor inner loop for performance reasons.
start value for current countdown
maximum recursion depth for loop detection stacks
us
[ ... holder name val ]
Allow automatic detection of hex base ("0x" or "0X" prefix),
* overrides radix argument and forces integer mode.
* Init arguments properties, map, etc.
comment: NUL terminator handling doesn't matter here
label: code-design
comment: XXX: error handling is incomplete. It would be cleanest if
* there was a setjmp catchpoint, so that all init code could
* freely throw errors. If that were the case, the return code
* passing here could be removed.
label: code-design
keep in on valstack, use borrowed ref below
[ ... Logger clog logfunc clog(=this) msg ]
-> [ ... func this arg1 ... argN _Args ]
* Found
*
* Arguments object has exotic post-processing, see E5 Section 10.6,
* description of [[GetOwnProperty]] variant for arguments.
compiler's responsibility
[ ... func this arg1 ... argN ] (not tail call)
* [ this | arg1 ... argN ] (tail call)
*
* idx_args updated to match
func is NULL for lightfuncs
shared exit path now
Finish the wrapped module source. Force module.filename as the
* function .fileName so it gets set for functions defined within a
* module. This also ensures loggers created within the module get
* the module ID (or overridden filename) as their default logger name.
* (Note capitalization: .filename matches Node.js while .fileName is
* used elsewhere in Duktape.)
comment: This limitation would be fixable but adds unnecessary complexity.
label: code-design
-> [ O toIsoString O ]
* Finish
-> [ timeval this timeval ]
cached: valstack_end - valstack (in entries, not bytes)
comment: XXX: awkward, especially the bunch of separate output values -> output struct?
label: code-design
According to E5.1 Section 15.4.4.4 nonexistent trailing
* elements do not affect 'length' of the result. Test262
* and other engines disagree, so update idx_last here too.
* Bitstream encoder.
* Once the whole refzero cascade has been freed, check for
* a voluntary mark-and-sweep.
Resolve start/end offset as element indices first; arguments
* at idx_start/idx_end are element offsets. Working with element
* indices first also avoids potential for wrapping.
IdentifierStart production with ASCII and non-BMP excluded
temp object for tracking / detecting duplicate keys
negative
* First create all built-in bare objects on the empty valstack.
*
* Built-ins in the index range [0,DUK_NUM_BUILTINS-1] have value
* stack indices matching their eventual thr->builtins[] index.
*
* Built-ins in the index range [DUK_NUM_BUILTINS,DUK_NUM_ALL_BUILTINS]
* will exist on the value stack during init but won't be placed
* into thr->builtins[]. These are objects referenced in some way
* from thr->builtins[] roots but which don't need to be indexed by
* Duktape through thr->builtins[] (e.g. user custom objects).
DUK_BUFOBJ_INT8ARRAY
DUK_USE_ROM_STRINGS
get pointer offsets for tweaking below
Note: not normalized, but duk_push_number() will normalize
NULL if not an object
* Exposed number-to-string API
*
* Input: [ number ]
* Output: [ string ]
XXX: could add fast path for u8 compatible views
Note2
'resume'
should never happen for a strict callee
comment: XXX: This is VERY inefficient now, and should be e.g. a
* binary search or perfect hash, to be fixed.
label: code-design
[... env]
Lookup an identifier name in the current varmap, indicating whether the
* identifier is register-bound and if not, allocating a constant for the
* identifier name. Returns 1 if register-bound, 0 otherwise. Caller can
* also check (out_reg_varbind >= 0) to check whether or not identifier is
* register bound. The caller must NOT use out_rc_varname at all unless
* return code is 0 or out_reg_varbind is < 0; this is becuase out_rc_varname
* is unsigned and doesn't have a "unused" / none value.
'export'
DUK_ERR_URI_ERROR: no macros needed
array case is handled comprehensively above
* Bytecode executor call.
*
* Execute bytecode, handling any recursive function calls and
* thread resumptions. Returns when execution would return from
* the entry level activation. When the executor returns, a
* single return value is left on the stack top.
*
* The only possible longjmp() is an error (DUK_LJ_TYPE_THROW),
* other types are handled internally by the executor.
comment: XXX: refactor into an internal helper, pretty awkward
label: code-design
Allocate a new valstack.
*
* Note: cannot use a plain DUK_REALLOC() because a mark-and-sweep may
* invalidate the original thr->valstack base pointer inside the realloc
* process. See doc/memory-management.rst.
Note that this is the same operation for strict and loose equality:
* - E5 Section 11.9.3, step 1.c (loose)
* - E5 Section 11.9.6, step 4 (strict)
force_no_namebind
DUK_TOK_NEW
* Breakpoint and step state checks
comment: XXX: this behavior is quite useless now; it would be nice to be able
* to create pointer values from e.g. numbers or strings. Numbers are
* problematic on 64-bit platforms though. Hex encoded strings?
label: code-design
global object doesn't have array part
comment: Then evaluate RHS fully (its value becomes the expression value too).
* Technically we'd need the side effect safety check here too, but because
* we always throw using INVLHS the result doesn't matter.
label: code-design
comment: XXX: specific getter
label: code-design
[ ... escape_source bytecode ]
First we need to insert a jump in the middle of previously
* emitted code to get the control flow right. No jumps can
* cross the position where the jump is inserted. See doc/compiler.rst
* for discussion on the intricacies of control flow and side effects
* for variants 3 and 4.
Cannot simulate individual finalizers because finalize_list only
* contains objects with actual finalizers. But simulate side effects
* from finalization by doing a bogus function call and resizing the
* stacks.
lastIndex is initialized to zero by new RegExp()
comment: Note: we could return the hash index here too, but it's not
* needed right now.
label: code-design
>>>
[ ... closure template formals ]
inherit
filename being compiled (ends up in functions' '_filename' property)
filter out flags from exprtop rbp_flags here to save space
comment:
* Debugging macros, DUK_DPRINT() and its variants in particular.
*
* DUK_DPRINT() allows formatted debug prints, and supports standard
* and Duktape specific formatters. See duk_debug_vsnprintf.c for details.
*
* DUK_D(x), DUK_DD(x), and DUK_DDD(x) are used together with log macros
* for technical reasons. They are concretely used to hide 'x' from the
* compiler when the corresponding log level is disabled. This allows
* clean builds on non-C99 compilers, at the cost of more verbose code.
* Examples:
*
* DUK_D(DUK_DPRINT("foo"));
* DUK_DD(DUK_DDPRINT("foo"));
* DUK_DDD(DUK_DDDPRINT("foo"));
*
* This approach is preferable to the old "double parentheses" hack because
* double parentheses make the C99 solution worse: __FILE__ and __LINE__ can
* no longer be added transparently without going through globals, which
* works poorly with threading.
label: code-design
prop index in 'array part', < 0 if not there
caller handles sign change
comment: load factor too low or high, count actually used entries and resize
label: code-design
* Coercion and fast path processing.
Not strictly necessary because if key == NULL, flag MUST be ignored.
make the new thread reachable
XXX: print built-ins array?
temp reg
* Externs and prototypes
no incref
Test signaling NaN and alias assignment in all endianness combinations.
1 GB
XXX: fast path for array arguments?
E5.1 Section 15.1.3.3: uriReserved + uriUnescaped + '#'
DUK_USE_PACKED_TVAL
comment:
* Enumeration semantics come from for-in statement, E5 Section 12.6.4.
* If called with 'null' or 'undefined', this opcode returns 'null' as
* the enumerator, which is special cased in NEXTENUM. This simplifies
* the compiler part
label: code-design
Insert a reserved area somewhere in the buffer; caller fills it.
* Evaluates to a (duk_uint_t *) pointing to the start of the reserved
* area for convenience.
values for the state field
How large a loop detection stack to use
pop enum
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
<
[ ... closure template undefined ]
comment:
* To determine whether to use an optimized Ecmascript-to-Ecmascript
* call, we need to know whether the final, non-bound function is an
* Ecmascript function.
*
* This is now implemented so that we start to do an ecma-to-ecma call
* setup which will resolve the bound chain as the first thing. If the
* final function is not eligible, the return value indicates that the
* ecma-to-ecma call is not possible. The setup will overwrite the call
* target at DUK__REGP(idx) with the final, non-bound function (which
* may be a lightfunc), and fudge arguments if necessary.
*
* XXX: If an ecma-to-ecma call is not possible, this initial call
* setup will do bound function chain resolution but won't do the
* "effective this binding" resolution which is quite confusing.
* Perhaps add a helper for doing bound function and effective this
* binding resolution - and call that explicitly? Ecma-to-ecma call
* setup and normal function handling can then assume this prestep has
* been done by the caller.
label: code-design
dynamic buffer ops
not found in 'curr', next in prototype chain; impose max depth
13: getUTCDate
comment: Truncate to 16 bits here, so that a computed hash can be compared
* against a hash stored in a 16-bit field.
label: code-design
Buffer has virtual properties similar to string, but indexed values
* are numbers, not 1-byte buffers/strings which would perform badly.
[ ... this name ]
* Date/time parsing helper.
*
* Parse a datetime string into a time value. We must first try to parse
* the input according to the standard format in E5.1 Section 15.9.1.15.
* If that fails, we can try to parse using custom parsing, which can
* either be platform neutral (custom code) or platform specific (using
* existing platform API calls).
*
* Note in particular that we must parse whatever toString(), toUTCString(),
* and toISOString() can produce; see E5.1 Section 15.9.4.2.
*
* Returns 1 to allow tail calling.
*
* There is much room for improvement here with respect to supporting
* alternative datetime formats. For instance, V8 parses '2012-01-01' as
* UTC and '2012/01/01' as local time.
comment: XXX: check flags
label: requirement
ASCII (and EOF) fast path -- quick accept and reject
0xc0...0xcf
'-' as a range indicator
-> [ ... enum_target res handler undefined target ]
[ arg1 ... argN this loggerLevel loggerName 'fmt' arg ]
"123.456"
Helper for creating the arguments object and adding it to the env record
* on top of the value stack. This helper has a very strict dependency on
* the shape of the input stack.
If an implicit return value is needed by caller, it must be
* initialized to 'undefined' because we don't know whether any
* non-empty (where "empty" is a continuation type, and different
* from an empty statement) statements will be executed.
*
* However, since 1st pass is a throwaway one, no need to emit
* it here.
'false'
Some internal code now assumes that all duk_uint_t values
* can be expressed with a duk_size_t.
data property or accessor without getter
* Args validation
DUK__TAG_NUMBER is intentionally first, as it is the default clause in code
* to support the 8-byte representation. Further, it is a non-heap-allocated
* type so it should come before DUK_TAG_STRING. Finally, it should not break
* the tag value ranges covered by case-clauses in a switch-case.
* String built-ins
* Clear (reachable) flags of refzero work list.
comment:
* Number should already be in NaN-normalized form, but let's
* normalize anyway.
label: code-design
-> [ ... obj key trap handler ]
catchstack
* C call recursion depth check, which provides a reasonable upper
* bound on maximum C stack size (arbitrary C stack growth is only
* possible by recursive handle_call / handle_safe_call calls).
Call sites don't need the result length so it's not accumulated.
non-zero: make copy
Return non-zero (true) if we have a good reason to believe
* the notify was delivered; if we're still attached at least
* a transport error was not indicated by the transport write
* callback. This is not a 100% guarantee of course.
fromPresent = false
Check that there's room to push one value.
comma check
backtrack to last output slash (dups already eliminated)
comment: Fastint range is signed 48-bit so longest value is -2^47 = -140737488355328
* (16 chars long), longest signed 64-bit value is -2^63 = -9223372036854775808
* (20 chars long). Alloc space for 64-bit range to be safe.
label: code-design
Flags for call handling.
jump to end
* RegExp built-ins
allocation size
no -> decref members, then free
If any non-Array value had enumerable virtual own
* properties, they should be serialized here. Standard
* types don't.
XXX: C recursion limit if proxies are allowed as handler/target values
try part
'caller' must only take on 'null' or function value
sign doesn't matter when writing
comment: XXX: use macros for the repetitive tval/refcount handling.
label: code-design
comment: Builtin-objects; may or may not be shared with other threads,
* threads existing in different "compartments" will have different
* built-ins. Must be stored on a per-thread basis because there
* is no intermediate structure for a thread group / compartment.
* This takes quite a lot of space, currently 43x4 = 172 bytes on
* 32-bit platforms.
*
* In some cases the builtins array could be ROM based, but it's
* sometimes edited (e.g. for sandboxing) so it's better to keep
* this array in RAM.
label: code-design
comment: unused
label: code-design
* Other file level defines
Fast path for numbers (one of which may be a fastint)
maximum length for a SKIP-1 diffstream: 35 bits per entry, rounded up to bytes
[enum_target enum res]
orig value
comment: XXX use get tval ptr, more efficient
label: code-design
See comments in duk_pcall().
The 'left' value must not be a register bound variable
* because it may be mutated during the rest of the expression
* and E5.1 Section 11.2.1 specifies the order of evaluation
* so that the base value is evaluated first.
* See: test-bug-nested-prop-mutate.js.
A bit tricky overflow test, see doc/code-issues.rst.
key must not already exist in entry part
Digit generation
reset function state (prepare for pass 2)
+0 = catch
avoid side effects!
comment: NOTE: "get" and "set" are not officially ReservedWords and the lexer
* currently treats them always like ordinary identifiers (DUK_TOK_GET
* and DUK_TOK_SET are unused). They need to be detected based on the
* identifier string content.
label: code-design
comment: XXX: regetting the pointer may be overkill - we're writing
* to a side-effect free array here.
label: code-design
* Because buffer values may be looped over and read/written
* from, an array index fast path is important.
duk_small_uint_fast_t c = DUK_DEC_C(ins);
For all duk_hbufferobjects, get the plain buffer inside
* without making a copy. This is compatible with Duktape 1.2
* but means that a slice/view information is ignored and the
* full underlying buffer is returned.
*
* If called as a constructor, a new Duktape.Buffer object
* pointing to the same plain buffer is created below.
Copy values by index reads and writes. Let virtual
* property handling take care of coercion.
comment: No coercions or other side effects, so safe
label: requirement
0x20-0x2f
may become sparse...
Pointers may be NULL for a while when 'buf' size is zero and before any
* ENSURE calls have been made. Once an ENSURE has been made, the pointers
* are required to be non-NULL so that it's always valid to use memcpy() and
* memmove(), even for zero size.
* Create and throw an Ecmascript error object based on a code and a message.
*
* Used when we throw errors internally. Ecmascript generated error objects
* are created by Ecmascript code, and the throwing is handled by the bytecode
* executor.
XXXXXX--
lightfuncs are treated like objects and not coerced
jump to end or else part
comment: Registers 'bc' and 'bc + 1' are written in longjmp handling
* and if their previous values (which are temporaries) become
* unreachable -and- have a finalizer, there'll be a function
* call during error handling which is not supported now (GH-287).
* Ensure that both 'bc' and 'bc + 1' have primitive values to
* guarantee no finalizer calls in error handling. Scrubbing also
* ensures finalizers for the previous values run here rather than
* later. Error handling related values are also written to 'bc'
* and 'bc + 1' but those values never become unreachable during
* error handling, so there's no side effect problem even if the
* error value has a finalizer.
label: code-design
no_block
The original value needs to be preserved for filter(), hence
* this funny order. We can't re-get the value because of side
* effects.
for duk_error_augment.c
just one 'int' for C++ exceptions
'~'
reset voluntary gc trigger count
If the separator is a RegExp, make a "clone" of it. The specification
* algorithm calls [[Match]] directly for specific indices; we emulate this
* by tweaking lastIndex and using a "force global" variant of duk_regexp_match()
* which will use global-style matching even when the RegExp itself is non-global.
* Defines for JSON, especially duk_bi_json.c.
* Fast path tables
-> [ ... handler trap ]
DUK_TOK_ALSHIFT_EQ
Note: assumes 'data' is always a fixed buffer
* Stringtable entry for fixed size stringtable
sometimes stack and array indices need to go on the stack
hash size ratio goal, must match genhashsizes.py
* Heap structure.
*
* Heap contains allocated heap objects, interned strings, and built-in
* strings for one or more threads.
Require a lot of stack to force a value stack grow/shrink.
comment: XXX: lastIndex handling produces a lot of asm
label: code-design
DUK_DEBUG_H_INCLUDED
input size is good output starting point
XXX: Current putvar implementation doesn't have a success flag,
* add one and send to debug client?
comment: must be able to emit code, alloc consts, etc.
label: code-design
comment: Should never happen but avoid infinite loop just in case.
label: code-design
unchanged from Duktape.Thread.yield()
value1 -> return value, pseudo-type to indicate a return continuation (for ENDFIN)
Negative offsets cause a RangeError.
side effect free
main expression parser function
Always overflow.
may happen if size is very close to 2^32-1
fail: restore saves
DUK_USE_DATE_PRS_GETDATE
needed for stepping
comment: XXX: could map/decode be unified with duk_unicode_support.c code?
* Case conversion needs also the character surroundings though.
label: code-design
clen == blen -> pure ascii
* The attempt to allocate may cause a GC. Such a GC must not attempt to resize
* the stringtable (though it can be swept); finalizer execution and object
* compaction must also be postponed to avoid the pressure to add strings to the
* string table. Call site must prevent these.
current setjmp() catchpoint
Result is undefined.
[ ... proplist ]
This may throw an error though not for valid E5 strings.
* Marking functions for heap types: mark children recursively
* Any catch bindings ("catch (e)") also affect identifier binding.
*
* Currently, the varmap is modified for the duration of the catch
* clause to ensure any identifier accesses with the catch variable
* name will use slow path.
XXX: set with duk_hobject_set_length() when tracedata is filled directly
comment: XXX: optimize by creating array into correct size directly, and
* operating on the array part directly; values can be memcpy()'d from
* value stack directly as long as refcounts are increased.
label: code-design
Slow path.
'compile'
comment: XXX: does not work if thr->catchstack is allocated but lowest pointer
label: code-design
DUK_TOK_RCURLY
comment: XXX: check .caller writability?
label: code-design
replacement handler
2**31-1 ~= 2G properties
part of string
Bytecode instructions: endian conversion needed unless
* platform is big endian.
DUK_TOK_EXTENDS
XXX: optimize reconfig valstack operations so that resize, clamp, and setting
* top are combined into one pass.
fastint downgrade check for return values
comment: bytes of indent still needed
label: code-design
DUK_JS_COMPILER_H_INCLUDED
nop
Restore the previous setjmp catcher so that any error in
* error handling will propagate outwards rather than re-enter
* the same handler. However, the error handling path must be
* designed to be error free so that sandboxing guarantees are
* reliable, see e.g. https://github.com/svaarala/duktape/issues/476.
Double error
* Valstack spare check
This would be pointless: unexpected type and lightfunc would both return NULL
For internal use: get non-accessor entry value
trailing comma followed by rcurly
Prevent mark-and-sweep for the pending finalizers, also prevents
* refzero handling from moving objects away from the heap_allocated
* list. (The flag meaning is slightly abused here.)
[... value this_binding]
DUK_TOK_INCREMENT
* Shared handling of binary operations
*
* args = (is_extraop << 16) + (opcode << 8) + rbp
insert code for matching the remainder - infinite or finite
comment: XXX: shared api error strings, and perhaps even throw code for rare cases?
label: code-design
Although there are writable virtual properties (e.g. plain buffer
* and buffer object number indices), they are handled before we come
* here.
* Fast paths
comment: XXX: static alloc is OK until separate chaining stringtable
* resizing is implemented.
label: code-design
truncate towards zero
37: setUTCFullYear
comment: Function name: missing/undefined is mapped to empty string,
* otherwise coerce to string.
label: code-design
* Assert helpers
resume lookup from target
comment: XXX: assume these?
label: code-design
When creating built-ins, some of the built-ins may not be set
* and we want to tolerate that when throwing errors.
standard prototype
comment: XXX: consolidated algorithm step 15.f -> redundant?
label: code-design
flags: "gm"
no need to decref, as previous value is 'undefined'
may need unwind
catch part will catch
-> [ ... name index ]
* Node.js Buffer: toString([encoding], [start], [end])
* Ecmascript compiler.
Allow fraction part
explicit 'this' binding, see GH-164
Initial bytecode size allocation.
XXX: patch initial size afterwards?
already zero
late lookup, avoid side effects
Return value: <0 <=> x < y
* 0 <=> x == y
* >0 <=> x > y
match against rule part/sep bits
'd' and 'res' agree here
no value, pseudo-type to indicate a normal continuation (for ENDFIN)
Eval code doesn't need an automatic .prototype object.
The coercion potentially invokes user .valueOf() and .toString()
* but can't result in a function value because [[DefaultValue]] would
* reject such a result: test-dev-json-stringify-coercion-1.js.
never here
comment: Macro for creating flag initializer from a class number.
* Unsigned type cast is needed to avoid warnings about coercing
* a signed integer to an unsigned one; the largest class values
* have the highest bit (bit 31) set which causes this.
label: code-design
Note that 'l' and 'r' may cross, i.e. r < l
For internal use: get non-accessor entry value and attributes
It's important that duk_xdef_prop() is a 'raw define' so that any
* properties in an ancestor are never an issue (they should never be
* e.g. non-writable, but just in case).
DUK_USE_JSON_EATWHITE_FASTPATH
valstack top, should match before interpreting each op (no leftovers)
may be NULL if alloc_size == 0
comment: XXX: this is a bit awkward because there is no exposed helper
* in the API style, only this internal helper.
label: code-design
110x xxxx; 2 bytes
if num_values > 0, MPUTARR emitted by outer loop after break
Overflow not an issue because subtraction is used on the right
* side and guaranteed to be >= 0.
Intentionally not 0x7fffffffUL; at least JSON code expects that
* 2*len + 2 fits in 32 bits.
Not enough data.
* Helper to walk the thread chain and see if there is an active error
* catcher. Protected calls or finally blocks aren't considered catching.
DUK_TOK_STRING
'}'
comment: initialized to avoid warnings of unused var
label: code-design
Slow path: quite slow, but we save space by using the property code
* to write coerce target values. We don't need to worry about overlap
* here because the source is not a TypedArray.
*
* We could use the bufferobject write coercion helper but since the
* property read may have arbitrary side effects, full validity checks
* would be needed for every element anyway.
[ ... env ]
IdentifierStart is stricter than IdentifierPart, so if the first
* character is escaped, must have a stricter check here.
* Reallocate memory with garbage collection
comment: XXX: unnecessary translation of flags
label: code-design
Explicit check for fastint downgrade.
default attrs ok
comment:
* Logical instruction layout
* ==========================
*
* !3!3!2!2!2!2!2!2!2!2!2!2!1!1!1!1!1!1!1!1!1!1! ! ! ! ! ! ! ! ! ! !
* !1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!9!8!7!6!5!4!3!2!1!0!
* +---------------------------------------------------+-----------+
* ! C ! B ! A ! OP !
* +---------------------------------------------------+-----------+
*
* OP (6 bits): opcode (DUK_OP_*), access should be fastest
* A (8 bits): typically a target register number
* B (9 bits): typically first source register/constant number
* C (9 bits): typically second source register/constant number
*
* Some instructions combine BC or ABC together for larger parameter values.
* Signed integers (e.g. jump offsets) are encoded as unsigned, with an opcode
* specific bias. B and C may denote a register or a constant, see
* DUK_BC_ISREG() and DUK_BC_ISCONST().
*
* Note: macro naming is a bit misleading, e.g. "ABC" in macro name but
* the field layout is logically "CBA".
label: code-design
comment: There may be whitespace between the equal signs.
label: code-design
comment: Note: first argument not really used
label: code-design
* Function declarations
reg_res should be smallest possible
Slot B
* Unreachable object, free
Specific assumptions for opcode numbering.
comment: copied so that 'ap' can be reused
label: code-design
exponents 1023 to 1069
* Allocate a heap.
*
* String table is initialized with built-in strings from genbuiltins.py,
* either by dynamically creating the strings or by referring to ROM strings.
(?!
name
Restart bytecode execution, possibly with a changed thread.
-> [ ... func name ]
top of current frame (exclusive)
if thisArg not supplied, behave as if undefined was supplied
for side effects
comment: XXX: match flag is awkward, rework
label: code-design
fall through and continue for-loop
* Module not loaded (and loading not started previously).
*
* Create a new require() function with 'id' set to resolved ID
* of module being loaded. Also create 'exports' and 'module'
* tables but don't register exports to the loaded table yet.
* We don't want to do that unless the user module search callbacks
* succeeds in finding the module.
Careful here: state must be wiped before the call
* so that we can cleanly handle a re-attach from
* inside the callback.
assume 0 <=> NULL
skip leading digit
B -> object register
* C -> C+0 contains key, C+1 closure (value)
caller guarantees
comment: array part must not contain any non-unused properties, as they would
* be configurable and writable.
label: code-design
Note: '\b' in char class is different than outside (assertion),
* '\B' is not allowed and is caught by the duk_unicode_is_identifier_part()
* check below.
Note: combining __FILE__, __LINE__, and __func__ into fmt would be
* possible compile time, but waste some space with shared function names.
at least this function exists
hash part is a 'weak reference' and does not contribute
'pc'
'errThrow'
DUK_TOK_SUPER
This is guaranteed by debugger code.
[... (sep) str1 str2 ... strN buf]
0: no change
Bigint is 2^52. Used to detect normalized IEEE double mantissa values
* which are at the lowest edge (next floating point value downwards has
* a different exponent). The lowest mantissa has the form:
*
* 1000........000 (52 zeroes; only "hidden bit" is set)
reg(ignored)
undefined coerces to zero which is correct
overwrite any previous binding of the same name; the effect is
* that last argument of a certain name wins.
returned after EOF (infinite amount)
comment: XXX: investigate whether write protect can be handled above, if we
* just update length here while ignoring its protected status
label: code-design
comment: This is a bit clunky because it is ANSI C portable. Should perhaps
* relocate to another file because this is potentially platform
* dependent.
label: code-design
Unwind catchstack entries referring to the callstack entry we're reusing
comment: XXX: many operations actually want toforcedtemp() -- brand new temp?
label: code-design
e.g. DUK_OP_POSTINCR
'Uint8ClampedArray'
No copy, leave zero bytes in the buffer. There's no
* ambiguity with Float32/Float64 because zero bytes also
* represent 0.0.
no typedef
[ ... func_template ]
Note: any entries above the callstack top are garbage and not zeroed.
* Also topmost activation idx_retval is garbage (not zeroed), and must
* be ignored.
[ arg1 ... argN obj length ]
Previous value of 'func' caller, restored when unwound. Only in use
* when 'func' is non-strict.
When doing string-to-number, lowest_mantissa is always 0 so
* the exponent check, while incorrect, won't matter.
If the value has a prototype loop, it's critical not to
* throw here. Instead, assume the value is not to be
* augmented.
comment: unused with some debug level combinations
label: code-design
Line number range for function. Needed during debugging to
* determine active breakpoints.
comment: slow init, do only for slow path cases
label: code-design
DUK_BUFOBJ_DUKTAPE_BUFFER
positive
comment: XXX: Here we have a nasty dependency: the need to manipulate
* the callstack means that catchstack must always be unwound by
* the caller before unwinding the callstack. This should be fixed
* later.
label: code-design
e.g. DUK_OP_PREINCP
DUK_JS_H_INCLUDED
DUK_USE_DATE_NOW_WINDOWS
!DUK_SINGLE_FILE
this is added to checks to allow for Duktape
* API calls in addition to function's own use
[ ... key_obj key ]
- A is a source register (it's not a write target, but used
* to identify the target object) but can be shuffled.
* - B cannot be shuffled normally because it identifies a range
* of registers, the emitter has special handling for this
* (the "no shuffle" flag must not be set).
* - C is a non-register number and cannot be shuffled, but
* never needs to be.
is_setget
flags always encodes to 1 byte
Ensure space for 1:1 output plus one escape.
[ ... obj key value ]
* Byte-based matching would be possible for case-sensitive
* matching but not for case-insensitive matching. So, we
* match by decoding the input and bytecode character normally.
*
* Bytecode characters are assumed to be already canonicalized.
* Input characters are canonicalized automatically by
* duk__inp_get_cp() if necessary.
*
* There is no opcode for matching multiple characters. The
* regexp compiler has trouble joining strings efficiently
* during compilation. See doc/regexp.rst for more discussion.
C array of duk_labelinfo
comment: XXX: double evaluation for 'tv' argument.
label: code-design
with stack depth (affects identifier lookups)
[ ... Duktape.modSearch resolved_id last_comp fresh_require exports module ]
* Detect recursive invocation
comment: known to be 32-bit
label: code-design
* Directive prologue tracking.
Handle lightfuncs through object coercion for now.
exponent 0
Identifier found in registers (always non-deletable)
* or declarative environment record and non-configurable.
duk_handle_ecma_call_setup: setup for a tail call
match: keep wiped/resaved values
E5 Section 11.7.2, steps 7 and 8
comment:
* Since there are no references in the catcher structure,
* unwinding is quite simple. The only thing we need to
* look out for is popping a possible lexical environment
* established for an active catch clause.
label: code-design
* String cache.
*
* Provides a cache to optimize indexed string lookups. The cache keeps
* track of (byte offset, char offset) states for a fixed number of strings.
* Otherwise we'd need to scan from either end of the string, as we store
* strings in (extended) UTF-8.
heap thread, used internally and for finalization
Don't allow a constant for the object (even for a number etc), as
* it goes into the 'A' field of the opcode.
For now all calls except Ecma-to-Ecma calls prevent a yield.
If tv1==tv2 this is a NOP, no check is needed
Dispatch loop.
DUK_TOK_SUB
Shared Windows helpers.
This is a pretty awkward control flow, but we need to recheck the
* key coercion here.
catches EOF and invalid digits
If thr->ptr_curr_pc is set, sync curr_pc to act->pc. Then NULL
* thr->ptr_curr_pc so that it's not accidentally used with an incorrect
* activation when side effects occur. If we end up not making the
* call we must restore the value.
comment: XXX: better macro for DUK_TVAL_IS_UNDEFINED_OR_NULL(tv)
label: code-design
* Call the constructor function (called in "constructor mode").
minimum prime
set by atom case clauses
[ ... error func fileName ]
reset callstack limit
right paren eaten
'['
idx_desc
E5 Section 11.7.1, steps 7 and 8
coerced value is updated to value stack even when RangeError thrown
Note: special DUK__EMIT_FLAG_B_IS_TARGETSOURCE
* used to indicate that B is both a source and a
* target register. When shuffled, it needs to be
* both input and output shuffled.
* Number is special because it doesn't have a specific
* tag in the 8-byte representation.
Align 'p' to 4; the input data may have arbitrary alignment.
* End of string check not needed because blen >= 16.
Expression_opt
Exact halfway, round to even.
* Arguments check
comment: Very minimal inlining to handle common idioms '!0' and '!1',
* and also boolean arguments like '!false' and '!true'.
label: code-design
name is empty -> return message
* Rescue or free.
grow by at most one
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 3
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . F G H ] (placeholder marked)
* [ A B C D E F G H ] (actual result at this point)
comment: XXX: helper; rely on Boolean.prototype as being non-writable, non-configurable
label: code-design
Note: proxy handling must happen before key is string coerced.
DUK_HBUFFEROBJECT_H_INCLUDED
[... res]
Note: unconditional throw
DUK_ERRMSG_H_INCLUDED
Neutered buffer, zero length seems
* like good behavior here.
no mark-and-sweep gc
* DUK_BSWAP macros
literals (E5 Section 7.8), except null, true, false, which are treated
* like reserved words (above).
loggerName
will result in undefined
DUK_TOK_QUESTION
* Delayed initialization only occurs for 'NEWENV' functions.
Allow automatic detection of octal base, overrides radix
* argument and forces integer mode.
Load constants onto value stack but don't yet copy to buffer.
[ hobject props enum(props) key desc ]
'Float32Array'
eat comma
range
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT32
Since stack indices are not reliable, we can't do anything useful
* here. Invoke the existing setjmp catcher, or if it doesn't exist,
* call the fatal error handler.
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 4
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . . . . F G H ] (placeholder marked)
* [ A B C D E F F G H ] (actual result at this point)
Commands and notifys initiated by Duktape.
DUK_TOK_GT
* Stringtable
offset is now target of the pending split (right after jump)
U+03A3 = GREEK CAPITAL LETTER SIGMA
always 0 args
exit bytecode executor by rethrowing an error to caller
Note: e_next indicates the number of gc-reachable entries
* in the entry part, and also indicates the index where the
* next new property would be inserted. It does *not* indicate
* the number of non-NULL keys present in the object. That
* value could be counted separately but requires a pass through
* the key list.
initialize built-ins - either by copying or creating new ones
Note: thr->catchstack_top may be 0, so that cat < thr->catchstack
* initially. This is OK and intended.
SCANBUILD: scan-build complains here about assigned value
* being garbage or undefined. This is correct but operating
* on undefined values has no ill effect and is ignored by the
* caller in the case where this happens.
IsAccessorDescriptor(desc) == true
avoid issues with relocation
avoid recursive string table call
res.x1 -> res.x2
-> [ ... x y fn ]
'taint' result as complex -- this is conservative,
* as lookaheads do not backtrack.
LHS is already side effect free
comment: XXX: hack, remove when const lookup is not O(n)
label: code-design
Here the specification requires correct array index enumeration
* which is a bit tricky for sparse arrays (it is handled by the
* enum setup code). We now enumerate ancestors too, although the
* specification is not very clear on whether that is required.
object has an array part (a_size may still be 0)
0x20...0x2f
eat dup slashes
Get the current data pointer (caller must ensure buf != NULL) as a
* duk_uint8_t ptr.
initial estimate based on format string
enable exotic behaviors last
comment: if 'src < src_end_safe', safe to read 4 bytes
label: requirement
comment: Straightforward algorithm, makes fewer compiler assumptions.
label: code-design
[ obj key desc ]
comment: Convenience for some situations; the above macros don't allow NULLs
* for performance reasons.
label: code-design
[... env callee varmap key val]
currently required
* Yield the current thread.
*
* The thread must be in yieldable state: it must have a resumer, and there
* must not be any yield-preventing calls (native calls and constructor calls,
* currently) in the thread's call stack (otherwise a resume would not be
* possible later). This method must be called from an Ecmascript function.
*
* Args:
* - value
* - isError (defaults to false)
*
* Note: yield and resume handling is currently asymmetric.
comment: No need to length check string: it will never exceed even
* the 16-bit length maximum.
label: code-design
(flags<<32) + (line), flags = 0
insert range count
XXX: Set 32-bit result (but must then handle signed and
* unsigned results separately).
[ ... new_glob new_env ]
Count actually used (non-NULL, non-DELETED) entries.
no refcount check
Parse statements until a closing token (EOF or '}') is found.
duk_hthread_callstack_unwind() will decrease this on unwind
Note: array dump will include elements beyond
* 'length'.
Note: currently the catch binding is handled without a register
* binding because we don't support dynamic register bindings (they
* must be fixed for an entire function). So, there is no need to
* record regbases etc.
Shared helper to provide toString() and valueOf(). Checks 'this', gets
* the primitive value to stack top, and optionally coerces with ToString().
size stored in duk_heaphdr unused flag bits
genbuiltins.py ensures
-> [ ... val' ]
CR LF again a special case
Note: computes with 'idx' in assertions, so caller beware.
* 'idx' is preincremented, i.e. '1' on first call, because it
* is more convenient for the caller.
Full, aligned 4-byte reads.
stack[0] = start
* stack[1] = end
* stack[2] = ToObject(this)
* stack[3] = ToUint32(length)
* stack[4] = result array
* Zero the struct, and start initializing roughly in order
stack[0...nargs-1] = unshift args (vararg)
* stack[nargs] = ToObject(this)
* stack[nargs+1] = ToUint32(length)
duk_unicode_idp_m_ids_noa[]
mark-and-sweep is currently running
comment:
* Error codes: defined in duktape.h
*
* Error codes are used as a shorthand to throw exceptions from inside
* the implementation. The appropriate Ecmascript object is constructed
* based on the code. Ecmascript code throws objects directly. The error
* codes are defined in the public API header because they are also used
* by calling code.
label: code-design
DUK_API_INTERNAL_H_INCLUDED
'\xffTarget'
FUNCTION EXPRESSIONS
0x50-0x5f
Note: there is no standard formatter for function pointers
default: no change
internal type tag
* Ecmascript bytecode executor.
comment: 0 = DUK_HOBJECT_CLASS_UNUSED
label: code-design
p points to digit part ('%xy', p points to 'x')
the compressed pointer is zeroed which maps to NULL, so nothing to do.
'count' is more or less comparable to normal trigger counter update
* which happens in memory block (re)allocation.
bottom of current frame
Shared offset/length coercion helper.
E5 Section 15.10.2.11
'writable'
These functions have trouble working as lightfuncs.
* Some of them have specific asserts and some may have
* additional properties (e.g. 'require.id' may be written).
Two lowest bits of opcode are used to distinguish
* variants. Bit 0 = inc(0)/dec(1), bit 1 = pre(0)/post(1).
internal spare
value (error) is at stack top
input byte length
gap (if empty string, NULL)
[ args [crud] arguments ]
lightfunc
higher value conserves memory; also note that linear scan is cache friendly
comment: XXX: to be implemented?
label: code-design
comment: XXX: convert to fixed buffer?
label: code-design
comment: Debug macro to print all parts and dparts (used manually because of debug level).
label: code-design
Assume arrays are dense in the fast path.
cannot happen: strings are not put into refzero list (they don't even have the next/prev pointers)
* Value stack top handling
Set property slot to an empty state. Careful not to invoke
* any side effects while using desc.e_idx so that it doesn't
* get invalidated by a finalizer mutating our object.
x <= y --> not (x > y) --> not (y < x)
[key setter this val]
little endian
Typing: use duk_small_(u)int_fast_t when decoding small
* opcode fields (op, A, B, C) and duk_(u)int_fast_t when
* decoding larger fields (e.g. BC which is 18 bits). Use
* unsigned variant by default, signed when the value is used
* in signed arithmetic. Using variable names such as 'a', 'b',
* 'c', 'bc', etc makes it easier to spot typing mismatches.
* Create required objects:
* - 'arguments' object: array-like, but not an array
* - 'map' object: internal object, tied to 'arguments'
* - 'mappedNames' object: temporary value used during construction
* Misc util stuff
Contract, either:
* - Push string to value stack and return 1
* - Don't push anything and return 0
Node.js return value for failed writes is offset + #bytes
* that would have been written.
NaN sign bit is platform specific with unpacked, un-normalized NaNs
comment: XXX: union would be more correct
label: code-design
* Allocate an duk_hobject.
*
* The allocated object has no allocation for properties; the caller may
* want to force a resize if a desired size is known.
*
* The allocated object has zero reference count and is not reachable.
* The caller MUST make the object reachable and increase its reference
* count before invoking any operation that might require memory allocation.
comment: XXX: Stack discipline is annoying, could be changed in numconv.
label: code-design
'stack'
Also check for the refzero_list; must not be there unless it is
* being finalized when duk_push_heapptr() is called.
*
* Corner case: similar to finalize_list.
* Heap compiled function (Ecmascript function) representation.
*
* There is a single data buffer containing the Ecmascript function's
* bytecode, constants, and inner functions.
Behavior for nargs < 2 is implementation dependent: currently we'll
* set a NaN time value (matching V8 behavior) in this case.
".123"
currently used -> new size
caller is responsible for ensuring this
must be signed
uppercase
comment: This variant is needed by String.prototype.split(); it needs to perform
* global-style matching on a cloned RegExp which is potentially non-global.
label: code-design
comment: XXX: optimize this filling behavior later
label: code-design
replaced
comment:
* Binary bitwise operations use different coercions (ToInt32, ToUint32)
* depending on the operation. We coerce the arguments first using
* ToInt32(), and then cast to an 32-bit value if necessary. Note that
* such casts must be correct even if there is no native 32-bit type
* (e.g., duk_int32_t and duk_uint32_t are 64-bit).
*
* E5 Sections 11.10, 11.7.1, 11.7.2, 11.7.3
label: code-design
[ ... regexp input ] -> [ res_obj ]
Mostly API and built-in method related
E5 Sections 15.9.3.1, B.2.4, B.2.5
alloc and init
prediction corrections for prime list (see genhashsizes.py)
Make _Target and _Handler non-configurable and non-writable.
* They can still be forcibly changed by C code (both user and
* Duktape internal), but not by Ecmascript code.
DUK_USE_REGEXP_SUPPORT
the DUK_TOK_RCURLY is eaten by duk__parse_stmts()
* Interrupt counter fixup (for development only).
Note: recursive call
maximum bytecode length in instructions
get const for value at valstack top
value1 -> label number, pseudo-type to indicate a break continuation (for ENDFIN)
line tracking
first call
* All done
undefined is accepted
* Wrap up
this case can no longer occur because refcount is unsigned
automatic semi will be inserted
Special shuffling for INITGET/INITSET, where slot C
* identifies a register pair and cannot be shuffled
* normally. Use an indirect variant instead.
reachable through activation
[ ... filename &comp_stk ]
comment: XXX: faster initialization (direct access or better primitives)
label: code-design
Loop structure ensures that we don't compute t1^2 unnecessarily
* on the final round, as that might create a bignum exceeding the
* current DUK__BI_MAX_PARTS limit.
comment:
* Check for invalid backreferences; note that it is NOT an error
* to back-reference a capture group which has not yet been introduced
* in the pattern (as in /\1(foo)/); in fact, the backreference will
* always match! It IS an error to back-reference a capture group
* which will never be introduced in the pattern. Thus, we can check
* for such references only after parsing is complete.
label: code-design
+ 1 for rounding
note: any entries above the callstack top are garbage and not zeroed
must be, since env was created when catcher was created
side effects (currently none though)
DUK_BUILTIN_PROTOS_H_INCLUDED
* Find a matching label catcher or 'finally' catcher in
* the same function.
*
* A label catcher must always exist and will match unless
* a 'finally' captures the break/continue first. It is the
* compiler's responsibility to ensure that labels are used
* correctly.
shadowed, ignore
'Uint16Array'
-> [ ... enum_target res ]
* Round-up limit.
*
* For even values, divides evenly, e.g. 10 -> roundup_limit=5.
*
* For odd values, rounds up, e.g. 3 -> roundup_limit=2.
* If radix is 3, 0/3 -> down, 1/3 -> down, 2/3 -> up.
+1 = one retval
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is an overkill for some paths, so optimize this later
* (or maybe switch to a stack arguments model entirely).
label: code-design
'%p' and NULL is portable, but special case it
* anyway to get a standard NULL marker in logs.
[ ... obj key val ]
comment: XXX: for Object.keys() we should check enumerability of key
label: code-design
idx_value may be < 0 (no value), set and get may be NULL
numeric value (character, count)
Note: first character is checked against this. But because
* IdentifierPart includes all IdentifierStart characters, and
* the first character (if unescaped) has already been checked
* in the if condition, this is OK.
assume 'var' has been eaten
empty separator can always match
* Close environment record(s) if they exist.
*
* Only variable environments are closed. If lex_env != var_env, it
* cannot currently contain any register bound declarations.
*
* Only environments created for a NEWENV function are closed. If an
* environment is created for e.g. an eval call, it must not be closed.
coerce to string
* Not found in registers, proceed to the parent record.
* Here we need to determine what the parent would be,
* if 'env' was not NULL (i.e. same logic as when initializing
* the record).
*
* Note that environment initialization is only deferred when
* DUK_HOBJECT_HAS_NEWENV is set, and this only happens for:
* - Function code
* - Strict eval code
*
* We only need to check _Lexenv here; _Varenv exists only if it
* differs from _Lexenv (and thus _Lexenv will also be present).
no check
comment: XXX: optimize to 16 bytes
label: code-design
* Endian conversion
nrets
* Second (and possibly third) pass.
*
* Generate actual code. In most cases the need for shuffle
* registers is detected during pass 1, but in some corner cases
* we'll only detect it during pass 2 and a third pass is then
* needed (see GH-115).
embed: integer value
0=base, 1=esc, 2=class, 3=class+esc
XXX: proper flags?
mark-and-sweep flags automatically active (used for critical sections)
heap string indices are autogenerated in duk_strings.h
some assertions
array writes autoincrement length
comment:
* Special behavior in E5.1.
*
* Note that even though parents == 0, the conflicting property
* may be an inherited property (currently our global object's
* prototype is Object.prototype). Step 5.e first operates on
* the existing property (which is potentially in an ancestor)
* and then defines a new property in the global object (and
* never modifies the ancestor).
*
* Also note that this logic would become even more complicated
* if the conflicting property might be a virtual one. Object
* prototype has no virtual properties, though.
*
* XXX: this is now very awkward, rework.
label: code-design
Avoid zero copy with an invalid pointer. If obj->p is NULL,
* the 'new_a' pointer will be invalid which is not allowed even
* when copy size is zero.
reserved words: keywords
The #ifdef clutter here handles the JX/JC enable/disable
* combinations properly.
[ ... key val ]
comment:
* Check whether or not we have an error handler.
*
* We must be careful of not triggering an error when looking up the
* property. For instance, if the property is a getter, we don't want
* to call it, only plain values are allowed. The value, if it exists,
* is not checked. If the value is not a function, a TypeError happens
* when it is called and that error replaces the original one.
label: code-design
comment: XXX: 'res' setup can be moved to function body level; in fact, two 'res'
* intermediate values suffice for parsing of each function. Nesting is needed
* for nested functions (which may occur inside expressions).
label: code-design
comment: This seems to waste a lot of stack frame entries, but good compilers
* will compute these as needed below. Some of these initial flags are
* also modified in the code below, so they can't all be removed.
label: code-design
[... env callee varmap]
duk_push_(u)int() is guaranteed to support at least (un)signed 32-bit range
[ body formals source template ]
User callback did not return source code, so module loading
* is finished: just update modLoaded with final module.exports
* and we're done.
comment: XXX: make active breakpoints actual copies instead of pointers?
label: code-design
XXX: this bound function resolution also happens elsewhere,
* move into a shared helper.
comment: XXX: non-callable .toJSON() doesn't need to cause an abort
* but does at the moment, probably not worth fixing.
label: code-design
num args starting from idx_argbase
caller must change active thread, and set thr->resumer to NULL
check that the valstack has space for the final amount and any
* intermediate space needed; this is unoptimal but should be safe
unary plus
* Shortcut for accessing global object properties
* slice()
may be changed
step 3.e: replace 'Desc.[[Value]]'
Captures which are undefined have NULL pointers and are returned
* as 'undefined'. The same is done when saved[] pointers are insane
* (this should, of course, never happen in practice).
Only direct eval inherits strictness from calling code
* (E5.1 Section 10.1.1).
Get a (possibly canonicalized) input character from current sp. The input
* itself is never modified, and captures always record non-canonicalized
* characters even in case-insensitive matching.
comment:
* Update idx_retval of current activation.
*
* Although it might seem this is not necessary (bytecode executor
* does this for Ecmascript-to-Ecmascript calls; other calls are
* handled here), this turns out to be necessary for handling yield
* and resume. For them, an Ecmascript-to-native call happens, and
* the Ecmascript call's idx_retval must be set for things to work.
label: code-design
[ ... varmap ]
* Type checking
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
Grow array part for a new highest array index.
no need to mask idx portion
remove hash entry (no decref)
index
exclusive endpoint
Append bytes from a slice already in the buffer.
this also increases refcount by one
whole, won't clip
[ source template ]
Cannot overlap.
DUK__L0() cannot be a digit, because the loop doesn't terminate if it is
apparently no hint?
comment: DUK_USE_REGEXP_CANON_WORKAROUND
label: code-design
stack[0] = separator (string or regexp)
* stack[1] = limit
* stack[2] = input string
* stack[3] = result array
XXX: clumsy sign extend and masking of 16 topmost bits
Note: no key on stack
[... retval]
DUK_USE_JX
num args
end of _Formals
This would be pointless: we'd return NULL for both lightfuncs and
* unexpected types.
2 when called by debugger
* Top level wrappers
DUK_INTERNAL_H_INCLUDED
Report next pc/line to be executed.
Non-object argument is simply int coerced, matches
* V8 behavior (except for "null", which we coerce to
* 0 but V8 TypeErrors).
* Build function fixed size 'data' buffer, which contains bytecode,
* constants, and inner function references.
*
* During the building phase 'data' is reachable but incomplete.
* Only incref's occur during building (no refzero or GC happens),
* so the building process is atomic.
fixed offsets in valstack
* Math built-ins
comment: Temporary structure used to pass a stack allocated region through
* duk_safe_call().
label: code-design
check that there is space for at least one new entry
0xa0...0xaf
eval left argument first
-> [ ... closure template ]
1 << 52
must match genhashsizes.py
setter and/or getter may be NULL
* Encoding helpers
*
* Some of the typing is bytecode based, e.g. slice sizes are unsigned 32-bit
* even though the buffer operations will use duk_size_t.
current thread
comment: Called on a read/write error: NULL all callbacks except the detached
* callback so that we never accidentally call them after a read/write
* error has been indicated. This is especially important for the transport
* I/O callbacks to fulfill guaranteed callback semantics.
label: code-design
Emit 3 bytes and backtrack if there was padding. There's
* always space for the whole 3 bytes so no check needed.
Duktape.Thread.yield() should prevent
encode \xffBar as _Bar if no quotes are applied, this is for
* readable internal keys.
LICENSE.txt
[ ... varname val ]
string is 'eval' or 'arguments'
* The default property attributes are correct for all
* function valued properties of built-in objects now.
Heap udata, used for allocator functions but also for other heap
* level callbacks like pointer compression, etc.
IdentifierStart production with ASCII excluded
nothing to mark
comment: XXX: function properties
label: code-design
prepend regexp to valstack 0 index
act_caller->func may be NULL in some finalization cases,
* just treat like we don't know the caller.
convenience
Previous value doesn't need refcount changes because its ownership
* is transferred to prev_caller.
* Pop built-ins from stack: they are now INCREF'd and
* reachable from the builtins[] array or indirectly
* through builtins[].
[obj key value desc]
stmt has non-empty value
-> [ ... holder name val val ToString(i) ]
stage 2: delete configurable entries above target length
When LHS is not register bound, always go through a
* temporary. No optimization for top level assignment.
keep key reachable for GC etc; guaranteed not to fail
generate mantissa with a single leading whole number digit
* Complex case conversion helper which decodes a bit-packed conversion
* control stream generated by unicode/extract_caseconv.py. The conversion
* is very slow because it runs through the conversion data in a linear
* fashion to save space (which is why ASCII characters have a special
* fast path before arriving here).
*
* The particular bit counts etc have been determined experimentally to
* be small but still sufficient, and must match the Python script
* (src/extract_caseconv.py).
*
* The return value is the case converted codepoint or -1 if the conversion
* results in multiple characters (this is useful for regexp Canonicalization
* operation). If 'buf' is not NULL, the result codepoint(s) are also
* appended to the hbuffer.
*
* Context and locale specific rules must be checked before consulting
* this function.
Stored in duk_heaphdr unused flags.
comment:
* Augmenting errors at their creation site and their throw site.
*
* When errors are created, traceback data is added by built-in code
* and a user error handler (if defined) can process or replace the
* error. Similarly, when errors are thrown, a user error handler
* (if defined) can process or replace the error.
*
* Augmentation and other processing at error creation time is nice
* because an error is only created once, but it may be thrown and
* rethrown multiple times. User error handler registered for processing
* an error at its throw site must be careful to handle rethrowing in
* a useful manner.
*
* Error augmentation may throw an internal error (e.g. alloc error).
*
* Ecmascript allows throwing any values, so all values cannot be
* augmented. Currently, the built-in augmentation at error creation
* only augments error values which are Error instances (= have the
* built-in Error.prototype in their prototype chain) and are also
* extensible. User error handlers have no limitations in this respect.
label: code-design
comment:
* Emit initializers in sets of maximum max_init_values.
* Corner cases such as single value initializers do not have
* special handling now.
*
* Elided elements must not be emitted as 'undefined' values,
* because such values would be enumerable (which is incorrect).
* Also note that trailing elisions must be reflected in the
* length of the final array but cause no elements to be actually
* inserted.
label: code-design
* Initialize built-in objects. Current thread must have a valstack
* and initialization errors may longjmp, so a setjmp() catch point
* must exist.
terminator
DUK_TOK_EQUALSIGN
* Comparison
DUK_JSON_H_INCLUDED
may have side effects
increases key refcount
on first round, skip
comment:
* Ecmascript specification algorithm and conversion helpers.
*
* These helpers encapsulate the primitive Ecmascript operation
* semantics, and are used by the bytecode executor and the API
* (among other places). Note that some primitives are only
* implemented as part of the API and have no "internal" helper.
* (This is the case when an internal helper would not really be
* useful; e.g. the operation is rare, uses value stack heavily,
* etc.)
*
* The operation arguments depend on what is required to implement
* the operation:
*
* - If an operation is simple and stateless, and has no side
* effects, it won't take an duk_hthread argument and its
* arguments may be duk_tval pointers (which are safe as long
* as no side effects take place).
*
* - If complex coercions are required (e.g. a "ToNumber" coercion)
* or errors may be thrown, the operation takes an duk_hthread
* argument. This also implies that the operation may have
* arbitrary side effects, invalidating any duk_tval pointers.
*
* - For operations with potential side effects, arguments can be
* taken in several ways:
*
* a) as duk_tval pointers, which makes sense if the "common case"
* can be resolved without side effects (e.g. coercion); the
* arguments are pushed to the valstack for coercion if
* necessary
*
* b) as duk_tval values
*
* c) implicitly on value stack top
*
* d) as indices to the value stack
*
* Future work:
*
* - Argument styles may not be the most sensible in every case now.
*
* - In-place coercions might be useful for several operations, if
* in-place coercion is OK for the bytecode executor and the API.
label: code-design
Note: may be triggered even if minimal new_size would not reach the limit,
* plan limit accordingly (taking DUK_VALSTACK_GROW_STEP into account).
comment: A little tricky string approach to provide the flags string.
* This depends on the specific flag values in duk_regexp.h,
* which needs to be asserted for. In practice this doesn't
* produce more compact code than the easier approach in use.
label: code-design
Note: intentionally use approximations to shave a few instructions:
* a_used = old_used (accurate: old_used + 1)
* a_size = arr_idx (accurate: arr_idx + 1)
Slot C is used in a non-standard fashion (range of regs),
* emitter code has special handling for it (must not set the
* "no shuffle" flag).
Note: if atom were to contain e.g. captures, we would need to
* re-match the atom to get correct captures. Simply quantifiers
* do not allow captures in their atom now, so this is not an issue.
* Criteria for augmenting:
*
* - augmentation enabled in build (naturally)
* - error value internal prototype chain contains the built-in
* Error prototype object (i.e. 'val instanceof Error')
*
* Additional criteria for built-in augmenting:
*
* - error value is an extensible object
comment: XXX: solve into closed form (smaller code)
label: code-design
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* If the final target function cannot be handled by an ecma-to-ecma
* call, return to the caller with a return value indicating this case.
* The bound chain is resolved and the caller can resume with a plain
* function call.
must be signed for loop structure
is_extra
comment:
* Memory calls: relative to heap, GC interaction, but no error throwing.
*
* XXX: Currently a mark-and-sweep triggered by memory allocation will run
* using the heap->heap_thread. This thread is also used for running
* mark-and-sweep finalization; this is not ideal because it breaks the
* isolation between multiple global environments.
*
* Notes:
*
* - DUK_FREE() is required to ignore NULL and any other possible return
* value of a zero-sized alloc/realloc (same as ANSI C free()).
*
* - There is no DUK_REALLOC_ZEROED because we don't assume to know the
* old size. Caller must zero the reallocated memory.
*
* - DUK_REALLOC_INDIRECT() must be used when a mark-and-sweep triggered
* by an allocation failure might invalidate the original 'ptr', thus
* causing a realloc retry to use an invalid pointer. Example: we're
* reallocating the value stack and a finalizer resizes the same value
* stack during mark-and-sweep. The indirect variant requests for the
* current location of the pointer being reallocated using a callback
* right before every realloc attempt; this circuitous approach is used
* to avoid strict aliasing issues in a more straightforward indirect
* pointer (void **) approach. Note: the pointer in the storage
* location is read but is NOT updated; the caller must do that.
label: code-design
Here 'x' is a Unicode codepoint
[ ToUint32(len) array ToUint32(len) ] -> [ ToUint32(len) array ]
Force a resize so that DELETED entries are eliminated.
* Another option would be duk__recheck_strtab_size_probe();
* but since that happens on every intern anyway, this whole
* check can now be disabled.
* comp_ctx->curr_func is now ready to be converted into an actual
* function template.
Potentially truncated, NUL not guaranteed in any case.
* The (int_rc < 0) case should not occur in practice.
If not found, resume existence check from Function.prototype.
* We can just substitute the value in this case; nothing will
* need the original base value (as would be the case with e.g.
* setters/getters.
"-123456\0"
Get the original arguments. Note that obj_index may be a relative
* index so the stack must have the same top when we use it.
curr value
These are for rate limiting Status notifications and transport peeking.
* Some E5/E5.1 algorithms require that array indices are iterated
* in a strictly ascending order. This is the case for e.g.
* Array.prototype.forEach() and JSON.stringify() PropertyList
* handling.
*
* To ensure this property for arrays with an array part (and
* arbitrary objects too, since e.g. forEach() can be applied
* to an array), the caller can request that we sort the keys
* here.
DUK_USE_LEXER_SLIDING_WINDOW
DUK_TOK_NULL
* Must be careful to catch errors related to value stack manipulation
* and property lookup, not just the call itself.
The file/line arguments are NULL and 0, they're ignored by DUK_ERROR_RAW()
* when non-verbose errors are used.
comment: 8-byte format could be:
* 1111 1111 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [41 bits]
*
* However, this format would not have a zero bit following the
* leading one bits and would not allow 0xFF to be used as an
* "invalid xutf-8" marker for internal keys. Further, 8-byte
* encodings (up to 41 bit code points) are not currently needed.
label: code-design
-> [... obj value]
[ key trap_result ] -> []
replace in stack
(maybe) truncated
nothing to process
Encode string in small chunks, estimating the maximum expansion so that
* there's no need to ensure space while processing the chunk.
* Object.getOwnPropertyDescriptor() (E5 Sections 15.2.3.3, 8.10.4)
*
* This is an actual function call.
knock back "next temp" to this whenever possible
* Detected a directive
'for'
complete the millisecond field
'lt is true'
Pre/post inc/dec for register variables, important for loops.
comment: Lightfunc name, includes Duktape/C native function pointer, which
* can often be used to locate the function from a symbol table.
* The name also includes the 16-bit duk_tval flags field because it
* includes the magic value. Because a single native function often
* provides different functionality depending on the magic value, it
* seems reasonably to include it in the name.
*
* On the other hand, a complicated name increases string table
* pressure in low memory environments (but only when function name
* is accessed).
label: code-design
comment: XXX: if duk_hobject_define_property_internal() was updated
* to handle a pre-existing accessor property, this would be
* a simple call (like for the ancestor case).
label: code-design
Iteration solution
comment: 16 bits would be enough for shared heaphdr flags and duk_hstring
* flags. The initial parts of duk_heaphdr_string and duk_heaphdr
* must match so changing the flags field size here would be quite
* awkward. However, to minimize struct size, we can pack at least
* 16 bits of duk_hstring data into the flags field.
label: code-design
* Helper tables
'this'
comment: XXX: could check for e16 == 0 because NULL is guaranteed to
* encode to zero.
label: code-design
approximate
Avoid NaN-to-integer coercion as it is compiler specific.
Reset to zero size, keep current limit.
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
callback for indirect reallocs, request for current pointer
[ ... this ]
* Portable 12-byte representation
avoid multiple computations of flags address; bypasses macros
comment: Reg/const access macros: these are very footprint and performance sensitive
* so modify with care.
label: code-design
must not truncate
prefix matches, lengths matter now
Careful with reachability here: don't pop 'obj' before pushing
* proxy target.
* Replace valstack top with case converted version.
Shuffle decision not changed.
* Stack index validation/normalization and getting a stack duk_tval ptr.
*
* These are called by many API entrypoints so the implementations must be
* fast and "inlined".
*
* There's some repetition because of this; keep the functions in sync.
numeric value of token
[... constructor arg1 ... argN] -> [retval]
* Rebuild the hash part always from scratch (guaranteed to finish).
*
* Any resize of hash part requires rehashing. In addition, by rehashing
* get rid of any elements marked deleted (DUK__HASH_DELETED) which is critical
* to ensuring the hash part never fills up.
temps
'Object'
not strictly necessary
IsDataDescriptor(desc) == true
POSTFIX EXPRESSION
If argument count is 1 and first argument is a buffer, write the buffer
* as raw data into the file without a newline; this allows exact control
* over stdout/stderr without an additional entrypoint (useful for now).
*
* Otherwise current print/alert semantics are to ToString() coerce
* arguments, join them with a single space, and append a newline.
* Exposed regexp compilation primitive.
*
* Sets up a regexp compilation context, and calls duk__parse_disjunction() to do the
* actual parsing. Handles generation of the compiled regexp header and the
* "boilerplate" capture of the matching substring (save 0 and 1). Also does some
* global level regexp checks after recursive compilation has finished.
*
* An escaped version of the regexp source, suitable for use as a RegExp instance
* 'source' property (see E5 Section 15.10.3), is also left on the stack.
*
* Input stack: [ pattern flags ]
* Output stack: [ bytecode escaped_source ] (both as strings)
'Error'
* Flags for __FILE__ / __LINE__ registered into tracedata
Count actually used entry part entries (non-NULL keys).
DUK_TOK_ARSHIFT
comment: XXX: possibly incorrect handling of empty expression
label: code-design
used entries + approx 100% -> reset load to 50%
'\xffRegbase'
is_decl
but don't allow leading plus
comment:
* String cache should ideally be at duk_hthread level, but that would
* cause string finalization to slow down relative to the number of
* threads; string finalization must check the string cache for "weak"
* references to the string being finalized to avoid dead pointers.
*
* Thus, string caches are now at the heap level now.
label: code-design
For manual debugging: instruction count based on executor and
* interrupt counter book-keeping. Inspect debug logs to see how
* they match up.
[ ... holder name val enum obj_key val obj_key ]
lj.value1 is already set
number of arguments allocated to regs
Optimized for size.
* Default fatal error handler
named "arithmetic" because result is signed
Default implicit return value.
lookup name from current activation record's functions' registers
custom; implies DUK_HOBJECT_IS_BUFFEROBJECT
max # of key-value pairs initialized in one MPUTOBJ set
unicode code points, window[0] is always next
Sync so that augmentation sees up-to-date activations, NULL
* thr->ptr_curr_pc so that it's not used if side effects occur
* in augmentation or longjmp handling.
thread not currently running
Refzero head is still the same. This is the case even if finalizer
* inserted more refzero objects; they are inserted to the tail.
[... key arg1 ... argN]
* GETIDREF: a GetIdentifierReference-like helper.
*
* Provides a parent traversing lookup and a single level lookup
* (for HasBinding).
*
* Instead of returning the value, returns a bunch of values allowing
* the caller to read, write, or delete the binding. Value pointers
* are duk_tval pointers which can be mutated directly as long as
* refcounts are properly updated. Note that any operation which may
* reallocate valstacks or compact objects may invalidate the returned
* duk_tval (but not object) pointers, so caller must be very careful.
*
* If starting environment record 'env' is given, 'act' is ignored.
* However, if 'env' is NULL, the caller may identify, in 'act', an
* activation which hasn't had its declarative environment initialized
* yet. The activation registers are then looked up, and its parent
* traversed normally.
*
* The 'out' structure values are only valid if the function returns
* success (non-zero).
Ignore the normalize/validate helper outputs on the value stack,
* they're popped automatically.
comment: A union is used here as a portable struct size / alignment trick:
* by adding a 32-bit or a 64-bit (unused) union member, the size of
* the struct is effectively forced to be a multiple of 4 or 8 bytes
* (respectively) without increasing the size of the struct unless
* necessary.
label: code-design
Chop extra retvals away / extend with undefined.
MPUTARR emitted by outer loop
comment: XXX: fastint?
label: code-design
compact the exports table
Code is not accepted before the first case/default clause
Process one debug message. Automatically restore value stack top to its
* entry value, so that individual message handlers don't need exact value
* stack handling which is convenient.
-> [ ... key val replacer holder key val ]
Because new_size != 0, if condition doesn't need to be
* (new_valstack != NULL || new_size == 0).
No debugger support.
'<'
treat like property not found
Bound functions don't have all properties so we'd either need to
* lookup the non-bound target function or reject bound functions.
* For now, bound functions are rejected.
Carry is detected based on wrapping which relies on exact 32-bit
* types.
eat (first) input slash
value resides in a register or constant
comment: "get" and "set" are tokens but NOT ReservedWords. They are currently
* parsed and identifiers and these defines are actually now unused.
label: code-design
Overflow, relevant mainly when listlen is 16 bits.
[ ... val ] --> [ ... enum ]
E5.1 standard behavior when deleteCount is not given would be
* to treat it just like if 'undefined' was given, which coerces
* ultimately to 0. Real world behavior is to splice to the end
* of array, see test-bi-array-proto-splice-no-delcount.js.
case 0: nop
comment: XXX: the duk_hobject_enum.c stack APIs should be reworked
label: code-design
Error: try coercing error to string once.
for resizing of array part, use slow path
y == -Infinity
Initialization and finalization (compaction), converting to other types.
must match exactly the number of internal properties inserted to enumerator
required
+ spare
All element accessors are host endian now (driven by TypedArray spec).
Push an arbitrary duk_tval to the stack, coerce it to string, and return
* both a duk_hstring pointer and an array index (or DUK__NO_ARRAY_INDEX).
must "goto restart_execution", e.g. breakpoints changed
Avoid side effects that might disturb curr.e_idx until
* we're done editing the slot.
23: getUTCMilliseconds
no need to normalize
* Windows Date providers
*
* Platform specific links:
*
* - http://msdn.microsoft.com/en-us/library/windows/desktop/ms725473(v=vs.85).aspx
comment: XXX: Change 'anon' handling here too, to use empty string for anonymous functions?
label: code-design
'this binding' is just under bottom
Default exports table
comment: XXX: macro smaller than call?
label: code-design
XXX: assert? compiler is responsible for this never happening
pc of label statement:
* pc+1: break jump site
* pc+2: continue jump site
'require'
* Assertion helpers
multiple codepoint conversion or non-ASCII mapped to ASCII
* --> leave as is.
Computation must not wrap, only srclen + 3 is at risk of
* wrapping because after that the number gets smaller.
* This limit works for 32-bit size_t:
* 0x100000000 - 3 - 1 = 4294967292
19: getUTCMinutes
Inspect a property using a virtual index into a conceptual property list
* consisting of (1) all array part items from [0,a_size[ (even when above
* .length) and (2) all entry part items from [0,e_next[. Unused slots are
* indicated using dvalue 'unused'.
duk__get_min_grow_e() is always >= 1
* Reachable object, keep
'eval'
Array part may be larger than 'length'; if so, iterate
* only up to array 'length'.
reg_catch+0 and reg_catch+1 are reserved for TRYCATCH
resolved id: require(id) must return this same module
We rely on a few object flag / class number relationships here,
* assert for them.
default case control flow patchup; note that if pc_prevcase < 0
* (i.e. no case clauses), control enters default case automatically.
DUK_HEAP_H_INCLUDED
note: original, uncoerced base
If len <= 1, middle will be 0 and for-loop bails out
* immediately (0 < 0 -> false).
DUK_OP_NONE marks a 'plain' assignment
resume execution from pc_base or pc_base+1 (points to 'func' bytecode, stable pointer)
Stack size decreases.
heap->strs: not worth dumping
-> [ ... closure template env funcname closure ]
step 12
Section 7.8.3 (note): NumericLiteral must be followed by something other than
* IdentifierStart or DecimalDigit.
comment: XXX: duk_ssize_t
label: code-design
DUK_ERR_UNCAUGHT_ERROR: no macros needed
-> [ ToObject(this) item1 ... itemN arr ]
C call site gets blamed next, unless flagged not to do so.
* XXX: file/line is disabled in minimal builds, so disable this
* too when appropriate.
* Debug dump type sizes
needed for line number tracking (becomes prev_token.start_line)
don't coerce yet to a plain value (variant 3 needs special handling)
comment: XXX: opcode specific assertions on when consts are allowed
label: code-design
Read value pushed on stack.
* When resizing the valstack, a mark-and-sweep may be triggered for
* the allocation of the new valstack. If the mark-and-sweep needs
* to use our thread for something, it may cause *the same valstack*
* to be resized recursively. This happens e.g. when mark-and-sweep
* finalizers are called. This is taken into account carefully in
* duk__resize_valstack().
*
* 'new_size' is known to be <= valstack_max, which ensures that
* size_t and pointer arithmetic won't wrap in duk__resize_valstack().
'null' enumerator case -> behave as with an empty enumerator
Object literal set/get functions have a name (property
* name) but must not have a lexical name binding, see
* test-bug-getset-func-name.js.
Current compiler state (if any), used for augmenting SyntaxErrors.
push to stack
Note: if DecimalLiteral starts with a '0', it can only be
* followed by a period or an exponent indicator which starts
* with 'e' or 'E'. Hence the if-check above ensures that
* OctalIntegerLiteral is the only valid NumericLiteral
* alternative at this point (even if y is, say, '9').
'catch'
* Special cases like NaN and +/- Infinity are handled explicitly
* because a plain C coercion from double to int handles these cases
* in undesirable ways. For instance, NaN may coerce to INT_MIN
* (not zero), and INT_MAX + 1 may coerce to INT_MIN (not INT_MAX).
*
* This double-to-int coercion differs from ToInteger() because it
* has a finite range (ToInteger() allows e.g. +/- Infinity). It
* also differs from ToInt32() because the INT_MIN/INT_MAX clamping
* depends on the size of the int type on the platform. In particular,
* on platforms with a 64-bit int type, the full range is allowed.
element size shift:
* 0 = u8/i8
* 1 = u16/i16
* 2 = u32/i32/float
* 3 = double
curr_pc synced back above
hash size approx. 1.25 times entries size
Write in little endian
source starts after dest ends
comment:
* Debugging macro calls.
label: code-design
DUK_USE_VERBOSE_ERRORS
0xxx xxxx -> fast path
* Ecmascript modulus ('%') does not match IEEE 754 "remainder"
* operation (implemented by remainder() in C99) but does seem
* to match ANSI C fmod().
*
* Compare E5 Section 11.5.3 and "man fmod".
unsigned shift
Not a very good provider: only full seconds are available.
110x xxxx 10xx xxxx [11 bits]
Note: errors are augmented when they are created, not
* when they are thrown. So, don't augment here, it would
* break re-throwing for instance.
comment: Not necessary to unwind catchstack: return handling will
* do it. The finally flag of 'cat' is no longer set. The
* catch flag may be set, but it's not checked by return handling.
label: code-design
ensure value is 1 or 0 (not other non-zero)
Accept plain buffer values like array initializers
* (new in Duktape 1.4.0).
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
Indicate function type in the function body using a dummy
* directive.
'ObjEnv'
lj.value1 already set
millisec -> 100ns units since jan 1, 1970
comment:
* Note: must use indirect variant of DUK_REALLOC() because underlying
* pointer may be changed by mark-and-sweep.
label: code-design
DUK_TOK_SWITCH
class Object, extensible
idx_end
_Source
1 1 0 <8 bits>
comment: two casts to avoid gcc warning: "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]"
label: code-design
minimum new length is highest_arr_idx + 1
DUK_TOK_RBRACKET
property is configurable and
* Matching complete, create result array or return a 'null'. Update lastIndex
* if necessary. See E5 Section 15.10.6.2.
*
* Because lastIndex is a character (not byte) offset, we need the character
* length of the match which we conveniently get as a side effect of interning
* the matching substring (0th index of result array).
*
* saved[0] start pointer (~ byte offset) of current match
* saved[1] end pointer (~ byte offset) of current match (exclusive)
* char_offset start character offset of current match (-> .index of result)
* char_end_offset end character offset (computed below)
comment: XXX: Refactor key coercion so that it's only called once. It can't
* be trivially lifted here because the object must be type checked
* first.
label: code-design
Caller must ensure 'tv' is indeed a double and not a fastint!
Caller has already eaten the first character ('|') which we don't need.
* String scanning helpers
*
* All bytes other than UTF-8 continuation bytes ([0x80,0xbf]) are
* considered to contribute a character. This must match how string
* character length is computed.
[ ... func this | arg1 ... argN ] ('this' must precede new bottom)
structs from duk_forwdecl.h
assumed to also be PC of "LABEL"
Check that prev/next links are consistent: if e.g. h->prev is != NULL,
* h->prev->next should point back to h.
'{"_undef":true}'
DUK_TOK_ADD_EQ
roughly 1.0 kiB -> but rounds up to DUK_VALSTACK_GROW_STEP in practice
remove the original 'template' atom
The ANSI C pow() semantics differ from Ecmascript.
*
* E.g. when x==1 and y is +/- infinite, the Ecmascript required
* result is NaN, while at least Linux pow() returns 1.
* Heap native function representation.
Note: DUK_HEAP_HAS_REFZERO_FREE_RUNNING(heap) may be true; a refcount
* finalizer may trigger a mark-and-sweep.
'Invalid Date'
dynamic
comment:
* Node.js Buffer.concat()
label: code-design
comment: XXX: substring in-place at idx_place?
label: code-design
* Object's finalizer was executed on last round, and
* object has been happily rescued.
embed: 0 or 1 (false or true)
Labels can be used for iteration statements but also for other statements,
* in particular a label can be used for a block statement. All cases of a
* named label accept a 'break' so that flag is set here. Iteration statements
* also allow 'continue', so that flag is updated when we figure out the
* statement type.
string 2 of token (borrowed, stored to ctx->slot2_idx)
UNARY EXPRESSIONS
* Not found (even in global object).
*
* In non-strict mode this is a silent SUCCESS (!), see E5 Section 11.4.1,
* step 3.b. In strict mode this case is a compile time SyntaxError so
* we should not come here.
should actually never happen, but check anyway
input offset for window leading edge (not window[0])
* Init object properties
*
* Properties should be added in decreasing order of access frequency.
* (Not very critical for function templates.)
[... fallback constructor fallback(this) arg1 ... argN];
* Note: idx_cons points to first 'fallback', not 'constructor'.
comment:
* Canonicalize a range, generating result ranges as necessary.
* Needs to exhaustively scan the entire range (at most 65536
* code points). If 'direct' is set, caller (lexer) has ensured
* that the range is already canonicalization compatible (this
* is used to avoid unnecessary canonicalization of built-in
* ranges like \W, which are not affected by canonicalization).
*
* NOTE: here is one place where we don't want to support chars
* outside the BMP, because the exhaustive search would be
* massively larger.
label: code-design
continuation byte
Note: the realloc may have triggered a mark-and-sweep which may
* have resized our valstack internally. However, the mark-and-sweep
* MUST NOT leave the stack bottom/top in a different state. Particular
* assumptions and facts:
*
* - The thr->valstack pointer may be different after realloc,
* and the offset between thr->valstack_end <-> thr->valstack
* may have changed.
* - The offset between thr->valstack_bottom <-> thr->valstack
* and thr->valstack_top <-> thr->valstack MUST NOT have changed,
* because mark-and-sweep must adhere to a strict stack policy.
* In other words, logical bottom and top MUST NOT have changed.
* - All values above the top are unreachable but are initialized
* to UNDEFINED, up to the post-realloc valstack_end.
* - 'old_end_offset' must be computed after realloc to be correct.
Note: hstring is in heap but has refcount zero and is not strongly reachable.
* Caller should increase refcount and make the hstring reachable before any
* operations which require allocation (and possible gc).
comment:
* "name" is a non-standard property found in at least V8, Rhino, smjs.
* For Rhino and smjs it is non-writable, non-enumerable, and non-configurable;
* for V8 it is writable, non-enumerable, non-configurable. It is also defined
* for an anonymous function expression in which case the value is an empty string.
* We could also leave name 'undefined' for anonymous functions but that would
* differ from behavior of other engines, so use an empty string.
*
* XXX: make optional? costs something per function.
label: code-design
comment:
* duk_hbuffer operations such as resizing and inserting/appending data to
* a dynamic buffer.
*
* Append operations append to the end of the buffer and they are relatively
* efficient: the buffer is grown with a "spare" part relative to the buffer
* size to minimize reallocations. Insert operations need to move existing
* data forward in the buffer with memmove() and are not very efficient.
* They are used e.g. by the regexp compiler to "backpatch" regexp bytecode.
label: code-design
steps 11.c.ii.1 - 11.c.ii.4, but our internal book-keeping
* differs from the reference model
ASCII fast path
Most input bytes go through here.
-> [ ... holder name val ]
Assume that year, month, day are all coerced to whole numbers.
* They may also be NaN or infinity, in which case this function
* must return NaN or infinity to ensure time value becomes NaN.
* If 'day' is NaN, the final return will end up returning a NaN,
* so it doesn't need to be checked here.
useful for debugging
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
*
* A conservative approach would be to use duk__ivalue_totempconst()
* for 'left'. However, allowing a reg-bound variable seems safe here
* and is nice because "foo.bar" is a common expression. If the ivalue
* is used in an expression a GETPROP will occur before any changes to
* the base value can occur. If the ivalue is used as an assignment
* LHS, the assignment code will ensure the base value is safe from
* RHS mutation.
We should never exit the loop above.
may have FINALIZED
LAYOUT 3
comment: unused
label: code-design
these computations are guaranteed to be exact for the valid
* E5 time value range, assuming milliseconds without fractions.
'Int32Array'
an error handler (user callback to augment/replace error) is running
without refcounts
arbitrary marker, outside valid exp range
extra -1 for buffer
For invalid characters the value -1 gets extended to
* at least 16 bits. If either nybble is invalid, the
* resulting 't' will be < 0.
required to guarantee success of rehashing,
* intentionally use unadjusted new_e_size
XXX: A fast path for usual integers would be useful when
* fastint support is not enabled.
-> [ ... ToObject(this) ToUint32(length) final_len final_len ]
[ ...val ] -> [ ... ]
allow empty expression
[ ... closure template name ]
# total registers target function wants on entry (< 0 => "as is")
comment: unnecessary shift for last byte
label: code-design
varenv remains reachable through 'obj'
Special coercion for Uint8ClampedArray.
valstack slot for temp buffer
* Node.js Buffer: constructor
this optimization is important to handle negative literals
* (which are not directly provided by the lexical grammar)
Nothing worked -> not equal.
E5 Section 11.13.1 (and others for other assignments), step 4.
Note: unshift() may operate on indices above unsigned 32-bit range
* and the final length may be >= 2**32. However, we restrict the
* final result to 32-bit range for practicality.
String and buffer enumeration behavior is identical now,
* so use shared handler.
37x32 = 1184 bits
heap->dbg_detached_cb: keep
This check used to be for (t < 0) but on some platforms
* time_t is unsigned and apparently the proper way to detect
* an mktime() error return is the cast above. See e.g.:
* http://pubs.opengroup.org/onlinepubs/009695299/functions/mktime.html
comment: Fast variants, inline refcount operations except for refzero handling.
* Can be used explicitly when speed is always more important than size.
* For a good compiler and a single file build, these are basically the
* same as a forced inline.
label: code-design
[ ... key ] -> [ ... ]
* Use current token to decide whether a RegExp can follow.
*
* We can use either 't' or 't_nores'; the latter would not
* recognize keywords. Some keywords can be followed by a
* RegExp (e.g. "return"), so using 't' is better. This is
* not trivial, see doc/compiler.rst.
Khronos/ES6 requires zeroing even when DUK_USE_ZERO_BUFFER_DATA
* is not set.
* Refcount memory freeing loop.
*
* Frees objects in the refzero_pending list until the list becomes
* empty. When an object is freed, its references get decref'd and
* may cause further objects to be queued for freeing.
*
* This could be expanded to allow incremental freeing: just bail out
* early and resume at a future alloc/decref/refzero.
Note: 'fast' breaks will jump to pc_label_site + 1, which will
* then jump here. The double jump will be eliminated by a
* peephole pass, resulting in an optimal jump here. The label
* site jumps will remain in bytecode and will waste code size.
comment:
* Prototype walking starting from 'env'.
*
* ('act' is not needed anywhere here.)
label: code-design
mark range 'direct', bypass canonicalization (see Wiki)
Do debugger forwarding before raw() because the raw() function
* doesn't get the log level right now.
estimate year upwards (towards positive infinity), then back down;
* two iterations should be enough
return module.exports
* Parsing an expression starting with 'new' is tricky because
* there are multiple possible productions deriving from
* LeftHandSideExpression which begin with 'new'.
*
* We currently resort to one-token lookahead to distinguish the
* cases. Hopefully this is correct. The binding power must be
* such that parsing ends at an LPAREN (CallExpression) but not at
* a PERIOD or LBRACKET (MemberExpression).
*
* See doc/compiler.rst for discussion on the parsing approach,
* and testcases/test-dev-new.js for a bunch of documented tests.
exprtop is the top level variant which resets nud/led counts
control props
push value to stack
* shift()
k+argCount-1; note that may be above 32-bit range
* Assert macro: failure causes panic.
comment: Similar workaround for INFINITY.
label: code-design
* Fallback marking handler if recursion limit is reached.
*
* Iterates 'temproots' until recursion limit is no longer hit. Note
* that temproots may reside either in heap allocated list or the
* refzero work list. This is a slow scan, but guarantees that we
* finish with a bounded C stack.
*
* Note that nodes may have been marked as temproots before this
* scan begun, OR they may have been marked during the scan (as
* we process nodes recursively also during the scan). This is
* intended behavior.
comment: If number would need zero padding (for whole number part), use
* exponential format instead. E.g. if input number is 12300, 3
* digits are generated ("123"), output "1.23e+4" instead of "12300".
* Used for toPrecision().
label: code-design
number
Must be element size multiple from
* start offset to end of buffer.
empty ("") is allowed in some formats (e.g. Number(''), as zero
slow path is shared
* If matching with a regexp:
* - non-global RegExp: lastIndex not touched on a match, zeroed
* on a non-match
* - global RegExp: on match, lastIndex will be updated by regexp
* executor to point to next char after the matching part (so that
* characters in the matching part are not matched again)
*
* If matching with a string:
* - always non-global match, find first occurrence
*
* We need:
* - The character offset of start-of-match for the replacer function
* - The byte offsets for start-of-match and end-of-match to implement
* the replacement values $&, $`, and $', and to copy non-matching
* input string portions (including header and trailer) verbatim.
*
* NOTE: the E5.1 specification is a bit vague how the RegExp should
* behave in the replacement process; e.g. is matching done first for
* all matches (in the global RegExp case) before any replacer calls
* are made? See: test-bi-string-proto-replace.js for discussion.
-> [ ... func ]
* Various defines and file specific helper macros
no net exponent
comment: integer, but may be +/- Infinite, +/- zero (not NaN, though)
label: code-design
11 bits
comment: Lookup active label information. Break/continue distinction is necessary to handle switch
* statement related labels correctly: a switch will only catch a 'break', not a 'continue'.
*
* An explicit label cannot appear multiple times in the active set, but empty labels (unlabelled
* iteration and switch statements) can. A break will match the closest unlabelled or labelled
* statement. A continue will match the closest unlabelled or labelled iteration statement. It is
* a syntax error if a continue matches a labelled switch statement; because an explicit label cannot
* be duplicated, the continue cannot match any valid label outside the switch.
*
* A side effect of these rules is that a LABEL statement related to a switch should never actually
* catch a continue abrupt completion at run-time. Hence an INVALID opcode can be placed in the
* continue slot of the switch's LABEL statement.
label: code-design
get before side effects
DUK_HSTRING_H_INCLUDED
avoid empty label at the end of a compound statement
no specific action, resume normal execution
for manual torture testing: tight allocation, useful with valgrind
XXX: skip count_free w/o debug?
everything except object stay as is
identifiers and environment handling
back to fast loop
DUK_USE_JX || DUK_USE_JC
Run fake finalizer. Avoid creating new refzero queue entries
* so that we are not forced into a forever loop.
In some cases it may be that lo > hi, or hi < 0; these
* degenerate cases happen e.g. for empty arrays, and in
* recursion leaves.
is resume, not a tail call
* Basic stack manipulation: swap, dup, insert, replace, etc
comment: Note: nargs (and nregs) may be negative for a native,
* function, which indicates that the function wants the
* input stack "as is" (i.e. handles "vararg" arguments).
label: code-design
* Indirect magic value lookup for Date methods.
*
* Date methods don't put their control flags into the function magic value
* because they wouldn't fit into a LIGHTFUNC's magic field. Instead, the
* magic value is set to an index pointing to the array of control flags
* below.
*
* This must be kept in strict sync with genbuiltins.py!
strings may have inner refs (extdata) in some cases
class masks
keep label catcher
state updated, restart bytecode execution
Flags for duk_js_equals_helper().
[ ... func this <some bound args> arg1 ... argN _Args ]
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module result(ignored) ]
DUK_USE_TAILCALL
comment: should never be called
label: code-design
denormal
-> loop body
note: this updates refcounts
avoid calling at end of input, will DUK_ERROR (above check suffices to avoid this)
t1 <- (+ r m+)
denormal or zero
mark-and-sweep control
A 'return' statement is only allowed inside an actual function body,
* not as part of eval or global code.
tailcall cannot be flagged to resume calls, and a
* previous frame must exist
DUK_TOK_LET
Remove a slice from inside buffer.
valstack slot for 2nd token value
one-based -> zero-based
Set .buffer
terminate
max size: radix=2 + sign
remaining actual steps are carried out if standard DefineOwnProperty succeeds
comment: The prev/next pointers of the removed duk_heaphdr are left as garbage.
* It's up to the caller to ensure they're written before inserting the
* object back.
label: code-design
'{"_func":true}'
comment: XXX: support unary arithmetic ivalues (useful?)
label: code-design
E5 Section 15.5.5.2
True if slice is full, i.e. offset is zero and length covers the entire
* buffer. This status may change independently of the duk_hbufferobject if
* the underlying buffer is dynamic and changes without the hbufferobject
* being changed.
avoid calling write callback in detach1()
http://en.wikipedia.org/wiki/Replacement_character#Replacement_character
-> [ Object res ]
* Property attribute defaults are defined in E5 Section 15 (first
* few pages); there is a default for all properties and a special
* default for 'length' properties. Variation from the defaults is
* signaled using a single flag bit in the bitstream.
IdentifierStart production with Letter and ASCII excluded
comment:
* DecimalLiteral, HexIntegerLiteral, OctalIntegerLiteral
* "pre-parsing", followed by an actual, accurate parser step.
*
* Note: the leading sign character ('+' or '-') is -not- part of
* the production in E5 grammar, and that the a DecimalLiteral
* starting with a '0' must be followed by a non-digit. Leading
* zeroes are syntax errors and must be checked for.
*
* XXX: the two step parsing process is quite awkward, it would
* be more straightforward to allow numconv to parse the longest
* valid prefix (it already does that, it only needs to indicate
* where the input ended). However, the lexer decodes characters
* using a lookup window, so this is not a trivial change.
label: code-design
* The escapes are same as outside a character class, except that \b has a
* different meaning, and \B and backreferences are prohibited (see E5
* Section 15.10.2.19). However, it's difficult to share code because we
* handle e.g. "\n" very differently: here we generate a single character
* range for it.
comment: Ensure there are no stale active breakpoint pointers.
* Breakpoint list is currently kept - we could empty it
* here but we'd need to handle refcounts correctly, and
* we'd need a 'thr' reference for that.
*
* XXX: clear breakpoint on either attach or detach?
label: code-design
end switch
DUK_TOK_LE
XXX: Currently no inspection of threads, e.g. value stack, call
* stack, catch stack, etc.
[ ... v1(func) v2(pc+flags) ]
Matches both +0 and -0 on purpose.
Note: ToPrimitive(object,hint) == [[DefaultValue]](object,hint),
* so use [[DefaultValue]] directly.
The code for writing reg_temps + 0 to the left hand side has already
* been emitted.
start line of token (first char)
10: getMonth
If caller is global/eval code, 'caller' should be set to
* 'null'.
*
* XXX: there is no exotic flag to infer this correctly now.
* The NEWENV flag is used now which works as intended for
* everything (global code, non-strict eval code, and functions)
* except strict eval code. Bound functions are never an issue
* because 'func' has been resolved to a non-bound function.
x <- y
eat 'var'
cannot have >4G captures
comment: not caught by current thread, thread terminates (yield error to resumer);
* note that this may cause a cascade if the resumer terminates with an uncaught
* exception etc (this is OK, but needs careful testing)
label: code-design
normalize NaN which may not match our canonical internal NaN
Recompute argument count: bound function handling may have shifted.
[ ... key val ] -> [ ... ]
minval
if len_x == len_y == 0, buf_x and/or buf_y may
* be NULL, but that's OK.
DUK_TOK_ARSHIFT_EQ
Slightly smaller code without explicit flag, but explicit flag
* is very useful when 'clen' is dropped.
Here again we parse bytes, and non-ASCII UTF-8 will cause end of
* parsing (which is correct except if there are non-shortest encodings).
* There is also no need to check explicitly for end of input buffer as
* the input is NUL padded and NUL will exit the parsing loop.
*
* Because no unescaping takes place, we can just scan to the end of the
* plain string and intern from the input buffer.
comment: XXX: merge this with duk_js_call.c, as this function implements
* core semantics (or perhaps merge the two files altogether).
label: code-design
* New length lower than old length => delete elements, then
* update length.
*
* Note: even though a bunch of elements have been deleted, the 'desc' is
* still valid as properties haven't been resized (and entries compacted).
* Program code (global and eval code) has an implicit return value
* from the last statement value (e.g. eval("1; 2+3;") returns 3).
* This is not the case with functions. If implicit statement return
* value is requested, all statements are coerced to a register
* allocated here, and used in the implicit return statement below.
* Pass 1
Use unsigned arithmetic to optimize comparison.
type and control flags, label number
DUK_TOK_RSHIFT_EQ
probe steps (see genhashsizes.py), currently assumed to be 32 entries long
* (DUK_UTIL_GET_HASH_PROBE_STEP macro).
[ ... enum_target res trap_result ]
1111 1110 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [36 bits]
* Conversions and coercions
*
* The conversion/coercions are in-place operations on the value stack.
* Some operations are implemented here directly, while others call a
* helper in duk_js_ops.c after validating arguments.
comment: Select a thread for mark-and-sweep use.
*
* XXX: This needs to change later.
label: code-design
Automatic filename: 'eval' or 'input'.
cumulative opcode execution count (overflows are OK)
Fast path for fastints
comment: XXX: any chance of merging these three similar but still slightly
* different algorithms so that footprint would be reduced?
label: code-design
comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.
'input'
countdown state
switch
* Return to bytecode executor, which will resume execution from
* the topmost activation.
Shared exit handling for object/array serialization.
input string scan
as elements
* Rewind lexer.
*
* duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp
* literal" mode with current strictness.
*
* curr_token line number info should be initialized for pass 2 before
* generating prologue, to ensure prologue bytecode gets nice line numbers.
Shared helper for Object.getOwnPropertyNames() and Object.keys().
* Magic: 0=getOwnPropertyNames, 1=Object.keys.
no need to unwind
When looking for .fileName/.lineNumber, blame first
* function which has a .fileName.
comment: XXX: if attempt to push beyond allocated valstack, this double fault
* handling fails miserably. We should really write the double error
* directly to thr->heap->lj.value1 and avoid valstack use entirely.
label: code-design
Strict functions don't get their 'caller' updated.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module mod_func ]
currently nop
[ ... closure template ]
* A tiny random number generator.
*
* Currently used for Math.random().
*
* http://www.woodmann.com/forum/archive/index.php/t-3100.html
'func' on stack (borrowed reference)
comment:
* "prototype" is, by default, a fresh object with the "constructor"
* property.
*
* Note that this creates a circular reference for every function
* instance (closure) which prevents refcount-based collection of
* function instances.
*
* XXX: Try to avoid creating the default prototype object, because
* many functions are not used as constructors and the default
* prototype is unnecessary. Perhaps it could be created on-demand
* when it is first accessed?
label: code-design
-> [... val this]
comment: code emission temporary
label: code-design
* TypedArray.prototype.set()
*
* TypedArray set() is pretty interesting to implement because:
*
* - The source argument may be a plain array or a typedarray. If the
* source is a TypedArray, values are decoded and re-encoded into the
* target (not as a plain byte copy). This may happen even when the
* element byte size is the same, e.g. integer values may be re-encoded
* into floats.
*
* - Source and target may refer to the same underlying buffer, so that
* the set() operation may overlap. The specification requires that this
* must work as if a copy was made before the operation. Note that this
* is NOT a simple memmove() situation because the source and target
* byte sizes may be different -- e.g. a 4-byte source (Int8Array) may
* expand to a 16-byte target (Uint32Array) so that the target overlaps
* the source both from beginning and the end (unlike in typical memmove).
*
* - Even if 'buf' pointers of the source and target differ, there's no
* guarantee that their memory areas don't overlap. This may be the
* case with external buffers.
*
* Even so, it is nice to optimize for the common case:
*
* - Source and target separate buffers or non-overlapping.
*
* - Source and target have a compatible type so that a plain byte copy
* is possible. Note that while e.g. uint8 and int8 are compatible
* (coercion one way or another doesn't change the byte representation),
* e.g. int8 and uint8clamped are NOT compatible when writing int8
* values into uint8clamped typedarray (-1 would clamp to 0 for instance).
*
* See test-bi-typedarray-proto-set.js.
(quotient-remainder (* r B) s) using a dummy subtraction loop
Note: either pointer may be NULL (at entry), so don't assert
String-number-buffer/object -> coerce object to primitive (apparently without hint), then try again.
* Property handling
*
* The API exposes only the most common property handling functions.
* The caller can invoke Ecmascript built-ins for full control (e.g.
* defineProperty, getOwnPropertyDescriptor).
Format of magic, bits:
* 0...1: elem size shift (0-3)
* 2...5: elem type (DUK_HBUFFEROBJECT_ELEM_xxx)
comment: Slow gathering of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. Handling
* of negative numbers is a bit non-obvious in both cases.
label: code-design
Built-in 'name' is not writable by default. Function '.name'
* is writable to allow user code to set a '.name' on a native
* function.
reuse last emitted atom for remaining 'infinite' quantifier
TypeError if rval is not an object (or lightfunc which should behave
* like a Function instance).
* Dragon4 slow path digit generation.
Rule control flags.
USE_PROP_HASH_PART
don't compact objects; needed during object property allocation resize
r <- (remainder (* r B) s)
[ ... error arr ]
String is an own (virtual) property of a lightfunc.
16: getHours
'debugger'
* String manipulation
fmod() return value has same sign as input (negative) so
* the result here will be in the range ]-2,0], 1 indicates
* odd. If x is -Infinity, NaN is returned and the odd check
* always concludes "not odd" which results in desired outcome.
DUK_USE_DEBUGGER_INSPECT
Lookup 'key' from arguments internal 'map', perform a variable write if mapped.
* Used in E5 Section 10.6 algorithm for [[DefineOwnProperty]] (used by [[Put]]).
* Assumes stack top contains 'put' value (which is NOT popped).
* Macro for object validity check
*
* Assert for currently guaranteed relations between flags, for instance.
comment: Process debug messages until we are no longer paused.
label: code-design
* Entries part
[in_val in_val]
DUK_TOK_LBRACKET
36 bits
for zero size allocations NULL is allowed
-> [... obj key value]
* Some change(s) need to be made. Steps 7-11.
-1 = error, -2 = allowed whitespace, -3 = padding ('='), 0...63 decoded bytes
duk_new() will call the constuctor using duk_handle_call().
* A constructor call prevents a yield from inside the constructor,
* even if the constructor is an Ecmascript function.
Select a safe loop count where no output checks are
* needed assuming we won't encounter escapes. Input
* bound checks are not necessary as a NUL (guaranteed)
* will cause a SyntaxError before we read out of bounds.
end of diff run
* Buffer
Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match
comment: XXX: use the pointer as a seed for now: mix in time at least
label: code-design
XXX: stringtable emergency compaction?
thr->ptr_curr_pc is set by bytecode executor early on entry
Allow leading plus sign
if slice not fully valid, treat as error
Now two entries in the same slot, alloc list
* The loop below must avoid issues with potential callstack
* reallocations. A resize (and other side effects) may happen
* e.g. due to finalizer/errhandler calls caused by a refzero or
* mark-and-sweep. Arbitrary finalizers may run, because when
* an environment record is refzero'd, it may refer to arbitrary
* values which also become refzero'd.
*
* So, the pointer 'p' is re-looked-up below whenever a side effect
* might have changed it.
thr->heap->lj.value1 is already the value to throw
Trailing whitespace has been eaten by duk__dec_value(), so if
* we're not at end of input here, it's a SyntaxError.
If user callback did not return source code, module loading
* is finished (user callback initialized exports table directly).
comment:
* Emit a final RETURN.
*
* It would be nice to avoid emitting an unnecessary "return" opcode
* if the current PC is not reachable. However, this cannot be reliably
* detected; even if the previous instruction is an unconditional jump,
* there may be a previous jump which jumps to current PC (which is the
* case for iteration and conditional statements, for instance).
label: code-design
* Because buffer values are often looped over, a number fast path
* is important.
starting line number
x <- x - y, use t as temp
EQUALITY EXPRESSION
* Unicode support tables automatically generated during build.
return thread
comment: No catch variable, e.g. a try-finally; replace LDCONST with
* NOP to avoid a bogus LDCONST.
label: code-design
0x08583b00
Signed shift, named "arithmetic" (asl) because the result
* is signed, e.g. 4294967295 << 1 -> -2. Note that result
* must be masked.
fmax() with args -0 and +0 is not guaranteed to return
* +0 as Ecmascript requires.
not a wordchar
XXX: a "first" flag would suffice
reg count
Buffer used for generated digits, values are in the range [0,B-1].
assume memset with zero size is OK
If ctx->offset >= ctx->length, we "shift zeroes in"
* instead of croaking.
Define own property without inheritance looks and such. This differs from
* [[DefineOwnProperty]] because special behaviors (like Array 'length') are
* not invoked by this method. The caller must be careful to invoke any such
* behaviors if necessary.
Parse a number, other than NaN or +/- Infinity
Must be a "string object", i.e. class "String"
no decref needed for a number
[ ... | (crud) ]
x <- y - z, require x >= y => z >= 0, i.e. y >= z
26 bits
Used to support single-byte stream lookahead.
Filename/line from C macros (__FILE__, __LINE__) are added as an
* entry with a special format: (string, number). The number contains
* the line and flags.
-> [ ToObject(this) ]
Buffer sizes for some UNIX calls. Larger than strictly necessary
* to avoid Valgrind errors.
'\Udeadbeef'
* every(), some(), forEach(), map(), filter()
Test without volatiles
Lexer codepoint with additional info like offset/line number
Low memory options
Constants should be signed so that signed arithmetic involving them
* won't cause values to be coerced accidentally to unsigned.
Note: either pointer may be NULL (at entry), so don't assert.
comment: Portability workaround is required for platforms without
* unaligned access. The replacement code emulates little
* endian access even on big endian architectures, which is
* OK as long as it is consistent for a build.
label: code-design
tail call -> reuse current "frame"
refcount is unsigned, so always true
work list for objects to be finalized (by mark-and-sweep)
comment: XXX: remove the preventcount and make yield walk the callstack?
* Or perhaps just use a single flag, not a counter, faster to just
* set and restore?
label: code-design
comment: still in use with verbose messages
label: code-design
stack is unbalanced, but: [ <something> buf ]
parse ranges until character class ends
'delete'
comment: unused now, not needed until Turkish/Azeri
label: requirement
No platform-specific parsing, this is not an error.
mark finalizable as reachability roots
comment: XXX: Add a proper condition. If formals list is omitted, recheck
* handling for 'length' in duk_js_push_closure(); it currently relies
* on _Formals being set. Removal may need to be conditional to debugging
* being enabled/disabled too.
label: code-design
comment: XXX: naming is inconsistent: ATOM_END_GROUP ends an ASSERT_START_LOOKAHEAD
label: code-design
ToUint32() coercion required
'global'
not popped by side effect
Add a number containing: pc, activation flags.
*
* PC points to next instruction, find offending PC. Note that
* PC == 0 for native code.
Check array density and indicate whether or not the array part should be abandoned.
* Duktape.Buffer: toString(), valueOf()
descriptor type specific checks
DUK_USE_ERRTHROW
Can happen if duk_throw() is called on an empty
* callstack.
* Longjmp and other control flow transfer for the bytecode executor.
*
* The longjmp handler can handle all longjmp types: error, yield, and
* resume (pseudotypes are never actually thrown).
*
* Error policy for longjmp: should not ordinarily throw errors; if errors
* occur (e.g. due to out-of-memory) they bubble outwards rather than being
* handled recursively.
unary minus
ignore non-strings
Clamp to target's end if too long.
*
* NOTE: there's no overflow possibility in the comparison;
* both target_ustart and copy_size are >= 0 and based on
* values in duk_int_t range. Adding them as duk_uint_t
* values is then guaranteed not to overflow.
move pivot to its final place
Setting to NULL causes 'caller' to be set to
* 'null' as desired.
comment:
* Global state for working around missing variadic macros
label: code-design
* Allocate and initialize a new entry, resizing the properties allocation
* if necessary. Returns entry index (e_idx) or throws an error if alloc fails.
*
* Sets the key of the entry (increasing the key's refcount), and updates
* the hash part if it exists. Caller must set value and flags, and update
* the entry value refcount. A decref for the previous value is not necessary.
tolerates NULL h_buf
forced_reg
DUK_TOK_PACKAGE
B -> target register
* C -> constant index of identifier name
no match, next case
* Interned identifier is compared against reserved words, which are
* currently interned into the heap context. See genbuiltins.py.
*
* Note that an escape in the identifier disables recognition of
* keywords; e.g. "\u0069f = 1;" is a valid statement (assigns to
* identifier named "if"). This is not necessarily compliant,
* see test-dec-escaped-char-in-keyword.js.
*
* Note: "get" and "set" are awkward. They are not officially
* ReservedWords (and indeed e.g. "var set = 1;" is valid), and
* must come out as DUK_TOK_IDENTIFIER. The compiler needs to
* work around this a bit.
NULL if tv_obj is primitive
lj value2: thread
Note: use 'curr' as a temp propdesc
Setter APIs detect special year numbers (0...99) and apply a +1900
* only in certain cases. The legacy getYear() getter applies -1900
* unconditionally.
* substring(), substr(), slice()
30: setHours
Expression, ']' terminates
* Number checkers
E5 Section 11.2.3, step 6.a.i
-> [ hobject props ]
XXX: shared handling for 'duk__expr_lhs'?
Fix for https://github.com/svaarala/duktape/issues/155:
* If 'default' is first clause (detected by pc_prevcase < 0)
* we need to ensure we stay in the matching chain.
eat 'in'
This may trigger mark-and-sweep with arbitrary side effects,
* including an attempted resize of the object we're resizing,
* executing a finalizer which may add or remove properties of
* the object we're resizing etc.
Call with count == DUK_LEXER_WINDOW_SIZE to fill buffer initially.
zero-based month
* Must be very careful here, every DECREF may cause reallocation
* of our valstack.
expect_token
periods
idx of first argument on stack
Add trailer if:
* a) non-empty input
* b) empty input and no (zero size) match found (step 11)
check stack first
mod_id may be NULL
http://en.wikipedia.org/wiki/ANSI_escape_code
since closure has NEWENV, never define DUK_STRIDX_INT_VARENV, as it
* will be ignored anyway
DUK_TOK_SET
* Lookup variable and update in-place if found.
'Int8Array'
Last component name in resolved path
Must match src/extract_chars.py, generate_match_table3().
Resize target buffer for requested size. Called by the macro only when the
* fast path test (= there is space) fails.
Ready to make the copy. We must proceed element by element
* and must avoid any side effects that might cause the buffer
* validity check above to become invalid.
*
* Although we work through the value stack here, only plain
* numbers are handled which should be side effect safe.
comment:
* Compared to a direct macro expansion this wrapper saves a few
* instructions because no heap dereferencing is required.
label: code-design
Force pause if we were doing "step into" in another activation.
allow fmt==NULL
comment:
* Reallocate property allocation, moving properties to the new allocation.
*
* Includes key compaction, rehashing, and can also optionally abandoning
* the array part, 'migrating' array entries into the beginning of the
* new entry part. Arguments are not validated here, so e.g. new_h_size
* MUST be a valid prime.
*
* There is no support for in-place reallocation or just compacting keys
* without resizing the property allocation. This is intentional to keep
* code size minimal.
*
* The implementation is relatively straightforward, except for the array
* abandonment process. Array abandonment requires that new string keys
* are interned, which may trigger GC. All keys interned so far must be
* reachable for GC at all times; valstack is used for that now.
*
* Also, a GC triggered during this reallocation process must not interfere
* with the object being resized. This is currently controlled by using
* heap->mark_and_sweep_base_flags to indicate that no finalizers will be
* executed (as they can affect ANY object) and no objects are compacted
* (it would suffice to protect this particular object only, though).
*
* Note: a non-checked variant would be nice but is a bit tricky to
* implement for the array abandonment process. It's easy for
* everything else.
*
* Note: because we need to potentially resize the valstack (as part
* of abandoning the array part), any tval pointers to the valstack
* will become invalid after this call.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGP(b)
* and DUK__REGCONSTP(c). Careful here.
duk_hcompiledfunction flags; quite version specific
these are not necessarily 0 or 1 (may be other non-zero), that's ok
+1 = finally
Clamping needed if duk_int_t is 64 bits.
'id'
output bufwriter
-> x in [-2**31,2**31[
DUK_USE_SELF_TESTS
built-in strings
* Process messages and send status if necessary.
*
* If we're paused, we'll block for new messages. If we're not
* paused, we'll process anything we can peek but won't block
* for more. Detach (and re-attach) handling is all localized
* to duk_debug_process_messages() too.
*
* Debugger writes outside the message loop may cause debugger
* detach1 phase to run, after which dbg_read_cb == NULL and
* dbg_detaching != 0. The message loop will finish the detach
* by running detach2 phase, so enter the message loop also when
* detaching.
* The error object has been augmented with a traceback and other
* info from its creation point -- usually the current thread.
* The error handler, however, is called right before throwing
* and runs in the yielder's thread.
* Error throwing helpers
[ ... new_glob new_env new_glob new_glob ]
For lightfuncs, simply read the virtual property.
0x70-0x7f
stable
XXX: Could add fast path (for each transform callback) with direct byte
* lookups (no shifting) and no explicit check for x < 0x80 before table
* lookup.
Duktape.Thread.resume()
comment:
* Note: of native Ecmascript objects, only Function instances
* have a [[HasInstance]] internal property. Custom objects might
* also have it, but not in current implementation.
*
* XXX: add a separate flag, DUK_HOBJECT_FLAG_ALLOW_INSTANCEOF?
label: code-design
nothing to NULL
use SameValue instead of non-strict equality
a value is left on stack regardless of rc
Detach is pending; can be triggered from outside the
* debugger loop (e.g. Status notify write error) or by
* previous message handling. Call detached callback
* here, in a controlled state, to ensure a possible
* reattach inside the detached_cb is handled correctly.
*
* Recheck for detach in a while loop: an immediate
* reattach involves a call to duk_debugger_attach()
* which writes a debugger handshake line immediately
* inside the API call. If the transport write fails
* for that handshake, we can immediately end up in a
* "transport broken, detaching" case several times here.
* Loop back until we're either cleanly attached or
* fully detached.
*
* NOTE: Reset dbg_processing = 1 forcibly, in case we
* re-attached; duk_debugger_attach() sets dbg_processing
* to 0 at the moment.
Run the finalizer, duk_hobject_run_finalizer() sets FINALIZED.
* Next mark-and-sweep will collect the object unless it has
* become reachable (i.e. rescued). FINALIZED prevents the
* finalizer from being executed again before that.
Note: this must match ToObject() behavior
'new' MemberExpression
The code below is incorrect if .toString() or .valueOf() have
* have been overridden. The correct approach would be to look up
* the method(s) and if they resolve to the built-in function we
* can safely bypass it and look up the internal value directly.
* Unimplemented for now, abort fast path for boxed values.
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx [21 bits]
comment: XXX: avoid this at least when enum_target is an Array, it has an
* array part, and no ancestor properties were included? Not worth
* it for JSON, but maybe worth it for forEach().
label: code-design
Report it to the debug client
no compact
restricted to regs
dummy so sp won't get updated
* Replace global object.
require a (mutable) temporary as a result (or a const if allowed)
contains value
'%s' and NULL is not portable, so special case
* it for debug printing.
Compiler SyntaxErrors (and other errors) come first, and are
* blamed by default (not flagged "noblame").
Relevant PC is just before current one because PC is
* post-incremented. This should match what error augment
* code does.
Parse formals.
[... key arg1 ... argN func]
exit bytecode execution with return value
* Status message and helpers
Note: 'func' is popped from valstack here, but it is
* already reachable from the activation.
points to LABEL; pc+1 = jump site for break; pc+2 = jump site for continue
DUK_SELFTEST_H_INCLUDED
Duktape object
0xb0-0xbf
* 'key_obj' tracks keys encountered so far by associating an
* integer with flags with already encountered keys. The checks
* below implement E5 Section 11.1.5, step 4 for production:
*
* PropertyNameAndValueList: PropertyNameAndValueList , PropertyAssignment
[ ... res ]
* UTF-8 decoder which accepts longer than standard byte sequences.
* This allows full 32-bit code points to be used.
accessor with defined getter
comment: XXX: optimize for packed duk_tval directly?
label: code-design
* Augment created errors upon creation (not when they are thrown or
* rethrown). __FILE__ and __LINE__ are not desirable here; the call
* stack reflects the caller which is correct.
allow source elements
one token before
'filename'
Neutered. We could go into the switch-case safely with
* buf == NULL because check_length == 0. To avoid scanbuild
* warnings, fail directly instead.
Allowed.
-> x in ]-2**32, 2**32[
no need to incref
Ecmascript function
embed: void ptr
Lightfuncs are always native functions and have "newenv".
This upper value has been experimentally determined; debug build will check
* bigint size with assertions.
comment: XXX: cover this with the generic >1 case?
label: code-design
* Variant 1 or 3
'enumerable'
comment:
* There are two [[Construct]] operations in the specification:
*
* - E5 Section 13.2.2: for Function objects
* - E5 Section 15.3.4.5.2: for "bound" Function objects
*
* The chain of bound functions is resolved in Section 15.3.4.5.2,
* with arguments "piling up" until the [[Construct]] internal
* method is called on the final, actual Function object. Note
* that the "prototype" property is looked up *only* from the
* final object, *before* calling the constructor.
*
* Currently we follow the bound function chain here to get the
* "prototype" property value from the final, non-bound function.
* However, we let duk_handle_call() handle the argument "piling"
* when the constructor is called. The bound function chain is
* thus now processed twice.
*
* When constructing new Array instances, an unnecessary object is
* created and discarded now: the standard [[Construct]] creates an
* object, and calls the Array constructor. The Array constructor
* returns an Array instance, which is used as the result value for
* the "new" operation; the object created before the Array constructor
* call is discarded.
*
* This would be easy to fix, e.g. by knowing that the Array constructor
* will always create a replacement object and skip creating the fallback
* object in that case.
*
* Note: functions called via "new" need to know they are called as a
* constructor. For instance, built-in constructors behave differently
* depending on how they are called.
label: code-design
zero size not an issue: pointers are valid
fromPresent = true
The counter value is one less than the init value: init value should
* indicate how many instructions are executed before interrupt. To
* execute 1 instruction (after interrupt handler return), counter must
* be 0.
assumes that allocated pointers and alloc funcs are valid
* if res exists
DUK_TOK_EQ
* >>> struct.pack('>d', 102030405060).encode('hex')
* '4237c17c6dc40000'
XXX: add 'language' argument when locale/language sensitive rule
* support added.
Currently there are no deletable virtual properties, but
* with force_flag we might attempt to delete one.
comment: XXX: This helper is a bit awkward because the handling for the different iteration
* callers is quite different. This now compiles to a bit less than 500 bytes, so with
* 5 callers the net result is about 100 bytes / caller.
label: code-design
Infinity
comment: XXX: unoptimal use of temps, resetting
label: code-design
-> [ ... regexp string ] -> [ ... res_obj ]
token type (with reserved words as DUK_TOK_IDENTIFER)
Note: assumes that these string indexes are 8-bit, genstrings.py must ensure that
start variant 3/4 left-hand-side code (L1 in doc/compiler.rst example)
# argument registers target function wants (< 0 => "as is")
'magic' constants for Murmurhash2
If something is thrown with the debugger attached and nobody will
* catch it, execution is paused before the longjmp, turning over
* control to the debug client. This allows local state to be examined
* before the stack is unwound. Errors are not intercepted when debug
* message loop is active (e.g. for Eval).
Object built-in methods
Skip fully.
switch (ch2)
type
* Allocate memory with garbage collection
* Main switch for statement / source element type.
Shared entry handling for object/array serialization.
overwrite sep
[ message error message ]
[ ... parent stash stash ] -> [ ... parent stash ]
Non-verbose errors for low memory targets: no file, line, or message.
DUK_BUFOBJ_ARRAYBUFFER
comment:
* Recursion limit check.
*
* Note: there is no need for an "ignore recursion limit" flag
* for duk_handle_safe_call now.
label: code-design
Exponent handling: if exponent format is used, record exponent value and
* fake k such that one leading digit is generated (e.g. digits=123 -> "1.23").
*
* toFixed() prevents exponent use; otherwise apply a set of criteria to
* match the other API calls (toString(), toPrecision, etc).
comment: We want the argument expression value to go to "next temp"
* without additional moves. That should almost always be the
* case, but we double check after expression parsing.
*
* This is not the cleanest possible approach.
label: code-design
seconds, doesn't fit into 16 bits
unreferenced w/o tracebacks
We want to avoid making a copy to process set() but that's
* not always possible: the source and the target may overlap
* and because element sizes are different, the overlap cannot
* always be handled with a memmove() or choosing the copy
* direction in a certain way. For example, if source type is
* uint8 and target type is uint32, the target area may exceed
* the source area from both ends!
*
* Note that because external buffers may point to the same
* memory areas, we must ultimately make this check using
* pointers.
*
* NOTE: careful with side effects: any side effect may cause
* a buffer resize (or external buffer pointer/length update)!
comment: NEXTENUM needs a jump slot right after the main instruction.
* When the JUMP is taken, output spilling is not needed so this
* workaround is possible. The jump slot PC is exceptionally
* plumbed through comp_ctx to minimize call sites.
label: code-design
must be updated to work properly (e.g. creation of 'arguments')
Unescaped '/' ANYWHERE in the regexp (in disjunction,
* inside a character class, ...) => same escape works.
1:1 or special conversions, but not locale/context specific: script generated rules
roughly 0.5 kiB
* Value stack resize and stack top adjustment helper.
*
* XXX: This should all be merged to duk_valstack_resize_raw().
comment:
* Macro support functions for reading/writing raw data.
*
* These are done using mempcy to ensure they're valid even for unaligned
* reads/writes on platforms where alignment counts. On x86 at least gcc
* is able to compile these into a bswap+mov. "Always inline" is used to
* ensure these macros compile to minimal code.
*
* Not really bufwriter related, but currently used together.
label: code-design
If tracebacks are enabled, the '_Tracedata' property is the only
* thing we need: 'fileName' and 'lineNumber' are virtual properties
* which use '_Tracedata'.
comment: XXX: could duk_is_undefined() provide defaulting undefined to 'len'
* (the upper limit)?
label: code-design
DUK_TOK_WITH
0xa0-0xaf
* Table for base-64 decoding
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
label: code-design
[... buf]
* Regexp compilation.
*
* See doc/regexp.rst for a discussion of the compilation approach and
* current limitations.
*
* Regexp bytecode assumes jumps can be expressed with signed 32-bit
* integers. Consequently the bytecode size must not exceed 0x7fffffffL.
* The implementation casts duk_size_t (buffer size) to duk_(u)int32_t
* in many places. Although this could be changed, the bytecode format
* limit would still prevent regexps exceeding the signed 32-bit limit
* from working.
*
* XXX: The implementation does not prevent bytecode from exceeding the
* maximum supported size. This could be done by limiting the maximum
* input string size (assuming an upper bound can be computed for number
* of bytecode bytes emitted per input byte) or checking buffer maximum
* size when emitting bytecode (slower).
Production allows 'DecimalDigits', including leading zeroes
Note: must coerce to a (writable) temp register, so that e.g. "!x" where x
* is a reg-mapped variable works correctly (does not mutate the variable register).
[] -> []
key
* Exception for Duktape internal throws when C++ exceptions are used
* for long control transfers.
*
* Doesn't inherit from any exception base class to minimize the chance
* that user code would accidentally catch this exception.
-> [ array totalLength buf ]
Maximum prototype traversal depth. Sanity limit which handles e.g.
* prototype loops (even complex ones like 1->2->3->4->2->3->4->2->3->4).
is valid size
[ O Properties obj ]
extra coercion of strings is OK
comment: XXX: increase ctx->expr_tokens here for every consumed token
* (this would be a nice statistic)?
label: code-design
FAIL
Two digit octal escape, digits validated.
*
* The if-condition is a bit tricky. We could catch e.g.
* '\039' in the three-digit escape and fail it there (by
* validating the digits), but we want to avoid extra
* additional validation code.
For n == 0, Node.js ignores totalLength argument and
* returns a zero length buffer.
* Push result object and init its flags
number of continuation (non-initial) bytes in [0x80,0xbf]
External buffer with 'curr_alloc' managed by user code and pointing to an
* arbitrary address. When heap pointer compression is not used, this struct
* has the same layout as duk_hbuffer_dynamic.
comment: Note: we can reuse 'desc' here
label: code-design
empty statement with an explicit semicolon
* Constructor
* Array exotic behaviors can be implemented at this point. The local variables
* are essentially a 'value copy' of the input descriptor (Desc), which is modified
* by the Array [[DefineOwnProperty]] (E5 Section 15.4.5.1).
* Expression parsing.
*
* Upon entry to 'expr' and its variants, 'curr_tok' is assumed to be the
* first token of the expression. Upon exit, 'curr_tok' will be the first
* token not part of the expression (e.g. semicolon terminating an expression
* statement).
The index range space is conceptually the array part followed by the
* entry part. Unlike normal enumeration all slots are exposed here as
* is and return 'unused' if the slots are not in active use. In particular
* the array part is included for the full a_size regardless of what the
* array .length is.
* toString()
shuffle registers if large number of regs/consts
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8
comment: XXX: add support for variables to not be register bound always, to
* handle cases with a very large number of variables?
label: code-design
entry_top + 2
[ result ]
* Determine call type, then finalize activation, shift to
* new value stack bottom, and call the target.
[ source ]
* Arguments object creation.
*
* Creating arguments objects involves many small details, see E5 Section
* 10.6 for the specific requirements. Much of the arguments object exotic
* behavior is implemented in duk_hobject_props.c, and is enabled by the
* object flag DUK_HOBJECT_FLAG_EXOTIC_ARGUMENTS.
comment: XXX: space in valstack? see discussion in duk_handle_call_xxx().
label: code-design
combines steps 2 and 5; -len ensures max() not needed for step 5
for register-bound and declarative env identifiers
bound functions are never in act 'func'
Lightfuncs cannot be bound.
comment: The resulting buffer object gets the same class and prototype as
* the buffer in 'this', e.g. if the input is a Node.js Buffer the
* result is a Node.js Buffer; if the input is a Float32Array, the
* result is a Float32Array.
*
* For the class number this seems correct. The internal prototype
* is not so clear: if 'this' is a bufferobject with a non-standard
* prototype object, that value gets copied over into the result
* (instead of using the standard prototype for that object type).
label: code-design
Don't allow mixed padding and actual chars.
reject RegExp literal on next advance() call; needed for handling IdentifierName productions
DUK_TOK_CONTINUE
unbalanced stack on purpose
arguments MUST have an initialized lexical environment reference
comment: XXX: sanitize to printable (and maybe ASCII)
label: code-design
tags
regexp compiler should catch these
comment: Current 'this' binding is the value just below idx_bottom.
* Previously, 'this' binding was handled with an index to the
* (calling) valstack. This works for everything except tail
* calls, which must not "cumulate" valstack temps.
label: code-design
* ctx->prev_token token to process with duk__expr_nud()
* ctx->curr_token updated by caller
*
* Note: the token in the switch below has already been eaten.
-> [ ... voidp true ]
The E5.1 specification does not seem to allow IdentifierPart characters
* to be used as identity escapes. Unfortunately this includes '$', which
* cannot be escaped as '\$'; it needs to be escaped e.g. as '\u0024'.
* Many other implementations (including V8 and Rhino, for instance) do
* accept '\$' as a valid identity escape, which is quite pragmatic.
* See: test-regexp-identity-escape-dollar.js.
mp <- b^(e+1)
* Debugger handling for executor restart
*
* Check for breakpoints, stepping, etc, and figure out if we should execute
* in checked or normal mode. Note that we can't do this when an activation
* is created, because breakpoint status (and stepping status) may change
* later, so we must recheck every time we're executing an activation.
* This primitive should be side effect free to avoid changes during check.
at most sizeof(buf) - 1
val
Old solution: don't iterate, incorrect
* API calls related to general value stack manipulation: resizing the value
* stack, pushing and popping values, type checking and reading values,
* coercing values, etc.
*
* Also contains internal functions (such as duk_get_tval()), defined
* in duk_api_internal.h, with semantics similar to the public API.
No BC shuffling now.
syntactically left-associative but parsed as right-associative
* Local result type for duk__get_identifier_reference() lookup.
comment: XXX: would be nice to enumerate an object at specified index
label: code-design
' '
* Heap stringtable handling, string interning.
By default the global object is read-only which is often much
* more of an issue than having read-only built-in objects (like
* RegExp, Date, etc). Use a RAM-based copy of the global object
* and the global environment object for convenience.
Creation time error augmentation
The casts through duk_intr_pt is to avoid the following GCC warning:
*
* warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
*
* This still generates a /Wp64 warning on VS2010 when compiling for x86.
comment:
* Note: currently register bindings must be fixed for the entire
* function. So, even though the catch variable is in a register
* we know, we must use an explicit environment record and slow path
* accesses to read/write the catch binding to make closures created
* within the catch clause work correctly. This restriction should
* be fixable (at least in common cases) later.
*
* See: test-bug-catch-binding-2.js.
*
* XXX: improve to get fast path access to most catch clauses.
label: code-design
check that byte has the form 10xx xxxx
* Memory constants
return 'res' (of right part) as our result
-> [ func funcname env ]
this variant is used when an assert would generate a compile warning by
* being always true (e.g. >= 0 comparison for an unsigned value
Stringcache is used for speeding up char-offset-to-byte-offset
* translations for non-ASCII strings.
comment: Note: strictness is *not* inherited from the current Duktape/C.
* This would be confusing because the current strictness state
* depends on whether we're running inside a Duktape/C activation
* (= strict mode) or outside of any activation (= non-strict mode).
* See tests/api/test-eval-strictness.c for more discussion.
label: code-design
* Finalizer check.
*
* Note: running a finalizer may have arbitrary side effects, e.g.
* queue more objects on refzero_list (tail), or even trigger a
* mark-and-sweep.
*
* Note: quick reject check should match vast majority of
* objects and must be safe (not throw any errors, ever).
Get Proxy target object. If the argument is not a Proxy, return it as is.
* If a Proxy is revoked, an error is thrown.
* Assertion helpers.
is_setget
* Compute new alloc size and alloc new area.
*
* The new area is allocated as a dynamic buffer and placed into the
* valstack for reachability. The actual buffer is then detached at
* the end.
*
* Note: heap_mark_and_sweep_base_flags are altered here to ensure
* no-one touches this object while we're resizing and rehashing it.
* The flags must be reset on every exit path after it. Finalizers
* and compaction is prevented currently for all objects while it
* would be enough to restrict it only for the current object.
replacer function
[ ... ]
comment: remove the string (mark DELETED), could also call
* duk_heap_string_remove() but that would be slow and
* pointless because we already know the slot.
label: code-design
+(function(){}) -> NaN
comment:
* Date built-ins
*
* Unlike most built-ins, Date has some platform dependencies for getting
* UTC time, converting between UTC and local time, and parsing and
* formatting time values. These are all abstracted behind DUK_USE_xxx
* config options. There are built-in platform specific providers for
* POSIX and Windows, but external providers can also be used.
*
* See doc/datetime.rst.
*
label: code-design
Reject attempt to change a read-only object.
final result is already in 'res'
21: getUTCSeconds
Eval is just a wrapper now.
With ROM objects "needs refcount update" is true when the value is
* heap allocated and is not a ROM object.
22: getMilliseconds
binary arithmetic using extraops; DUK_EXTRAOP_INSTOF etc
combined algorithm matching E5 Sections 9.5 and 9.6
Evaluates to (duk_uint8_t *) pointing to start of area.
module.id = resolved_id
Property access expressions ('a[b]') are critical to correct
* LHS evaluation ordering, see test-dev-assign-eval-order*.js.
* We must make sure that the LHS target slot (base object and
* key) don't change during RHS evaluation. The only concrete
* problem is a register reference to a variable-bound register
* (i.e., non-temp). Require temp regs for both key and base.
*
* Don't allow a constant for the object (even for a number
* etc), as it goes into the 'A' field of the opcode.
Maximum number of characters in formatted value.
Read fully.
* Prototypes
For indirect allocs.
always allow 'in', coerce to 'tr' just in case
DUK_USE_DEBUGGER_SUPPORT && (DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT)
Pointer object internal value is immutable
Leave 'value' on stack
prev char
* [[DefaultValue]] (E5 Section 8.12.8)
*
* ==> implemented in the API.
'extends'
result: hash_prime(floor(1.2 * e_size))
bp is assumed to be even
stridx_logfunc[] must be static to allow initializer with old compilers like BCC
Positive index can be higher than valstack top but must
* not go above allocated stack (equality is OK).
out_desc is left untouched (possibly garbage), caller must use return
* value to determine whether out_desc can be looked up
If buffer has been exhausted, truncate bitstream
Can be called multiple times with no harm.
Helper for component setter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), modify one or more components as specified, recompute
* the time value, set it as the internal value. Finally, push the
* new time value as a return value to the value stack and return 1
* (caller can then tail call us).
error
1:1 conversion
Encode into a double constant (53 bits can encode 6*8 = 48 bits + 3-bit length
not LS/PS
invalid codepoint encoding or codepoint
comment: packed advance/token number macro used by multiple functions
label: code-design
The JO(value) operation: encode object.
*
* Stack policy: [ object ] -> [ object ].
DUK_TOK_BAND_EQ
remaining
comment:
* Duktape built-ins
*
* Size optimization note: it might seem that vararg multipurpose functions
* like fin(), enc(), and dec() are not very size optimal, but using a single
* user-visible Ecmascript function saves a lot of run-time footprint; each
* Function instance takes >100 bytes. Using a shared native helper and a
* 'magic' value won't save much if there are multiple Function instances
* anyway.
label: code-design
Value is required to be a number in the fast path so there
* are no side effects in write coercion.
Faster but value stack overruns are memory unsafe.
register for writing value of 'non-empty' statements (global or eval code), -1 is marker
* Possible pending array length update, which must only be done
* if the actual entry write succeeded.
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
If XUTF-8 decoding fails, treat the offending byte as a codepoint directly
* and go forward one byte. This is of course very lossy, but allows some kind
* of output to be produced even for internal strings which don't conform to
* XUTF-8. All standard Ecmascript strings are always CESU-8, so this behavior
* does not violate the Ecmascript specification. The behavior is applied to
* all modes, including Ecmascript standard JSON. Because the current XUTF-8
* decoding is not very strict, this behavior only really affects initial bytes
* and truncated codepoints.
*
* Another alternative would be to scan forwards to start of next codepoint
* (or end of input) and emit just one replacement codepoint.
For initial entry use default value; zero forces an
* interrupt before executing the first insturction.
already in correct reg
the next 'if' is guaranteed to match after swap
Encoding state. Heap object references are all borrowed.
-> [ ... repl_value ]
no prototype
Note: 'q' is top-1
comment:
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
label: code-design
comment: XXX: incref by count (2) directly
label: code-design
')'
source is a function expression (used for Function constructor)
* Variant 2
Stored in duk_heaphdr h_extra16.
Note: intentionally signed.
'Date'
input linenumber at input_offset (not window[0]), init to 1
comment:
* Missing bytes snip base64 example
* 0 4 XXXX
* 1 3 XXX=
* 2 2 XX==
label: code-design
* The remaining matches are emitted as sequence of SPLITs and atom
* copies; the SPLITs skip the remaining copies and match the sequel.
* This sequence needs to be emitted starting from the last copy
* because the SPLITs are variable length due to the variable length
* skip offset. This causes a lot of memory copying now.
*
* Example structure (greedy, match maximum # atoms):
*
* SPLIT1 LSEQ
* (atom)
* SPLIT1 LSEQ ; <- the byte length of this instruction is needed
* (atom) ; to encode the above SPLIT1 correctly
* ...
* LSEQ:
idx_value
[ ... this_new | arg1 ... argN ]
------XX XXXX----
* Get old and new length
comment: Hot variables for interpretation. Critical for performance,
* but must add sparingly to minimize register shuffling.
label: code-design
38: getYear
initjs data is NUL terminated
this.raw(buffer)
return h_bufres
Here we rely on duk_hstring instances always being zero
* terminated even if the actual string is not.
Must coerce key: if key is an object, it may coerce to e.g. 'length'.
-> [ ... regexp_instance ]
Final result is at stack top.
Strict equality is NOT enough, because we cannot use the same
* constant for e.g. +0 and -0.
right exists, [[Put]] regardless whether or not left exists
* Return target object.
reuse 'res' as 'left'
st_used remains the same, DELETED is counted as used
is_join
binding power must be high enough to NOT allow comma expressions directly
Note: these variables must reside in 'curr_func' instead of the global
* context: when parsing function expressions, expression parsing is nested.
Abandon array part, moving array entries into entries part.
* This requires a props resize, which is a heavy operation.
* We also compact the entries part while we're at it, although
* this is not strictly required.
_Formals
base of known return values
TimeClip(), which also handles Infinity -> NaN conversion
[ ... obj ]
Encoding endianness must match target memory layout,
* build scripts and genbuiltins.py must ensure this.
flags used for property attributes in duk_propdesc and packed flags
directly uses slow accesses
* Finalizer torture. Do one fake finalizer call which causes side effects
* similar to one or more finalizers on actual objects.
add AC*2^32
result: updated refcount
Entry level info.
catch depth from current func
indexOf: clamp fromIndex to [-len, len]
* (if fromIndex == len, for-loop terminates directly)
*
* lastIndexOf: clamp fromIndex to [-len - 1, len - 1]
* (if clamped to -len-1 -> fromIndex becomes -1, terminates for-loop directly)
decoding
inline initializer for coercers[] is not allowed by old compilers like BCC
* Create normalized 'source' property (E5 Section 15.10.3).
variable access
Double casting for pointer to avoid gcc warning (cast from pointer to integer of different size)
comment: XXX: refactor out?
label: code-design
same for both error and each subclass like TypeError
[ ... res_obj re_obj input bc saved_buf ]
B -> register for writing enumerator object
* C -> value to be enumerated (register)
entire string is whitespace
'multiline'
'+'
* Parse an identifier and then check whether it is:
* - reserved word (keyword or other reserved word)
* - "null" (NullLiteral)
* - "true" (BooleanLiteral)
* - "false" (BooleanLiteral)
* - anything else => identifier
*
* This does not follow the E5 productions cleanly, but is
* useful and compact.
*
* Note that identifiers may contain Unicode escapes,
* see E5 Sections 6 and 7.6. They must be decoded first,
* and the result checked against allowed characters.
* The above if-clause accepts an identifier start and an
* '\' character -- no other token can begin with a '\'.
*
* Note that "get" and "set" are not reserved words in E5
* specification so they are recognized as plain identifiers
* (the tokens DUK_TOK_GET and DUK_TOK_SET are actually not
* used now). The compiler needs to work around this.
*
* Strictly speaking, following Ecmascript longest match
* specification, an invalid escape for the first character
* should cause a syntax error. However, an invalid escape
* for IdentifierParts should just terminate the identifier
* early (longest match), and let the next tokenization
* fail. For instance Rhino croaks with 'foo\z' when
* parsing the identifier. This has little practical impact.
'lineNumber'
refer to callstack entries below current
statement parsing
comment: Pick a destination register. If either base value or key
* happens to be a temp value, reuse it as the destination.
*
* XXX: The temp must be a "mutable" one, i.e. such that no
* other expression is using it anymore. Here this should be
* the case because the value of a property access expression
* is neither the base nor the key, but the lookup result.
label: code-design
Property access expressions are critical for correct LHS ordering,
* see comments in duk__expr()!
ignore retval -> [key]
%ld
* Octal escape or zero escape:
* \0 (lookahead not DecimalDigit)
* \1 ... \7 (lookahead not DecimalDigit)
* \ZeroToThree OctalDigit (lookahead not DecimalDigit)
* \FourToSeven OctalDigit (no lookahead restrictions)
* \ZeroToThree OctalDigit OctalDigit (no lookahead restrictions)
*
* Zero escape is part of the standard syntax. Octal escapes are
* defined in E5 Section B.1.2, and are only allowed in non-strict mode.
* Any other productions starting with a decimal digit are invalid.
comment: XXX: for Object.keys() the [[OwnPropertyKeys]] result (trap result)
* should be filtered so that only enumerable keys remain. Enumerability
* should be checked with [[GetOwnProperty]] on the original object
* (i.e., the proxy in this case). If the proxy has a getOwnPropertyDescriptor
* trap, it should be triggered for every property. If the proxy doesn't have
* the trap, enumerability should be checked against the target object instead.
* We don't do any of this now, so Object.keys() and Object.getOwnPropertyNames()
* return the same result now for proxy traps. We still do clean up the trap
* result, so that Object.keys() and Object.getOwnPropertyNames() will return a
* clean array of strings without gaps.
label: code-design
syntax error
don't push value
'buffer'
inherit initial strictness from parent
module
Without tracebacks the concrete .fileName and .lineNumber need
* to be added directly.
not emergency
* Raw memory calls: relative to heap, but no GC interaction
Lookup 'key' from arguments internal 'map', perform a variable lookup
* if mapped, and leave the result on top of stack (and return non-zero).
* Used in E5 Section 10.6 algorithms [[Get]] and [[GetOwnProperty]].
Evaluate RHS only when LHS is safe.
debugger detaching; used to avoid calling detach handler recursively
no catchers
* Variant 4
'package'
nothing now
* Reset trigger counter
* Preliminaries
count is already incremented, take into account
comment:
* Setters.
*
* Setters are a bit more complicated than getters. Component setters
* break down the current time value into its (normalized) component
* parts, replace one or more components with -unnormalized- new values,
* and the components are then converted back into a time value. As an
* example of using unnormalized values:
*
* var d = new Date(1234567890);
*
* is equivalent to:
*
* var d = new Date(0);
* d.setUTCMilliseconds(1234567890);
*
* A shared native helper to provide almost all setters. Magic value
* contains a set of flags and also packs the "maxnargs" argument. The
* helper provides:
*
* setMilliseconds()
* setUTCMilliseconds()
* setSeconds()
* setUTCSeconds()
* setMinutes()
* setUTCMinutes()
* setHours()
* setUTCHours()
* setDate()
* setUTCDate()
* setMonth()
* setUTCMonth()
* setFullYear()
* setUTCFullYear()
* setYear()
*
* Notes:
*
* - Date.prototype.setYear() (Section B addition): special year check
* is omitted. NaN / Infinity will just flow through and ultimately
* result in a NaN internal time value.
*
* - Date.prototype.setYear() does not have optional arguments for
* setting month and day-in-month (like setFullYear()), but we indicate
* 'maxnargs' to be 3 to get the year written to the correct component
* index in duk__set_part_helper(). The function has nargs == 1, so only
* the year will be set regardless of actual argument count.
label: code-design
inline string concatenation
DUK_USE_JX && DUK_USE_JC
comment: XXX: ideally this would be just one flag (maybe a derived one) so
* that a single bit test is sufficient to check the condition.
label: test
[key] (coerced)
comment: XXX: no optimized variants yet
label: requirement
Encode a double (checked by caller) from stack top. Stack top may be
* replaced by serialized string but is not popped (caller does that).
This function is only called for objects with array exotic behavior.
* The [[DefineOwnProperty]] algorithm for arrays requires that
* 'length' can never have a value outside the unsigned 32-bit range,
* attempt to write such a value is a RangeError. Here we can thus
* assert for this. When Duktape internals go around the official
* property write interface (doesn't happen often) this assumption is
* easy to accidentally break, so such code must be written carefully.
* See test-bi-array-push-maxlen.js.
comment: DUK__ADVANCECHARS(lex_ctx, 2) would be correct here, but it unnecessary
label: code-design
'base64'
[ sep ToObject(this) len sep ]
comment:
* Various sanity checks for typing
label: code-design
Check whether statement list ends.
invalidates tv1, tv2
Note: MUST NOT wipe_and_return here, as heap->lj must remain intact
-> sets 'f' and 'e'
Check for maximum string length
* Parse an individual source element (top level statement) or a statement.
*
* Handles labeled statements automatically (peeling away labels before
* parsing an expression that follows the label(s)).
*
* Upon entry, 'curr_tok' contains the first token of the statement (parsed
* in "allow regexp literal" mode). Upon exit, 'curr_tok' contains the first
* token following the statement (if the statement has a terminator, this is
* the token after the terminator).
comment: loop_stack_index could be perhaps be replaced by 'depth', but it's nice
* to not couple these two mechanisms unnecessarily.
label: code-design
* Fast path for defining array indexed values without interning the key.
* This is used by e.g. code for Array prototype and traceback creation so
* must avoid interning.
accessor
set to 1 if any match exists (needed for empty input special case)
this should never be possible, because the switch-case is
* comprehensive
avoid double coercion
'DataView'
* Sweep stringtable
[ A B C D E F G H ] rel_index = 2, del_count 3, item count 1
* -> [ A B F G H ] (conceptual intermediate step)
* -> [ A B . F G H ] (placeholder marked)
* [ A B C F G H ] (actual result at this point, C will be replaced)
DUK_TOK_IN
jump to false
comment: XXX: resolve macro definition issue or call through a helper function?
label: code-design
comment: Sanity workaround for handling functions with a large number of
* constants at least somewhat reasonably. Otherwise checking whether
* we already have the constant would grow very slow (as it is O(N^2)).
label: code-design
heapobj recursion depth when deep printing is selected
basic types
temp reset is not necessary after duk__parse_stmt(), which already does it
mark-and-sweep: reachable
Error object is augmented at its creation here.
DUK_USE_COMMONJS_MODULES
at least effective 'this'
* Default allocation functions.
*
* Assumes behavior such as malloc allowing zero size, yielding
* a NULL or a unique pointer which is a no-op for free.
DUK_USE_LIGHTFUNC_BUILTINS
some derived types
functions always have a NEWENV flag, i.e. they get a
* new variable declaration environment, so only lex_env
* matters here.
x == +Infinity
temp_start+0 = key, temp_start+1 = closure
E5.1 Section 15.1.3.2: empty
DUK_TOK_FINALLY
comment: Static call style.
label: code-design
'deleteProperty'
Compiling state of one function, eventually converted to duk_hcompiledfunction
to body
Coerce top into Object.prototype.toString() output.
XXX: this is quite clunky. Add Unicode helpers to scan backwards and
* forwards with a callback to process codepoints?
actual update happens once write has been completed without
* error below.
* 'func' is now a non-bound object which supports [[HasInstance]]
* (which here just means DUK_HOBJECT_FLAG_CALLABLE). Move on
* to execute E5 Section 15.3.5.3.
Target object must be checked for a conflicting
* non-configurable property.
property exists, either 'desc' is empty, or all values
* match (SameValue)
[ func thisArg argArray ]
p overshoots
prefer direct
comment: XXX: what about statements which leave a half-cooked value in 'res'
* but have no stmt value? Any such statements?
label: code-design
Must restart in all cases because we NULLed thr->ptr_curr_pc.
MAXVAL is inclusive
"release" preallocated temps since we won't need them
temp reg value for start of loop
checked by Duktape.Thread.resume()
* Union aliasing, see misc/clang_aliasing.c.
[ offset value littleEndian ], when DUK__FLD_TYPEDARRAY (regardless of ftype)
* Replacements for missing platform functions.
*
* Unlike the originals, fpclassify() and signbit() replacements don't
* work on any floating point types, only doubles. The C typing here
* mimics the standard prototypes.
eat closing quote
setup many variables in nc_ctx
comment: XXX: fast int-to-double
label: code-design
Native function pointer may be different from a void pointer,
* and we serialize it from memory directly now (no byte swapping etc).
comment: XXX: shorter version for 12-byte representation?
label: code-design
a fresh require() with require.id = resolved target module id
Constructor
elision - flush
temp reg for key literal
Unlike break/continue, throw statement does not allow an empty value.
DUK_TOK_VAR
Useful for internal call sites where we either expect an object (function)
* or a lightfunc. Accepts an object (returned as is) or a lightfunc (coerced
* to an object). Return value is NULL if value is neither an object nor a
* lightfunc.
char offset in [0, h_input->clen] (both ends inclusive), checked before entry
NOTE: fmod(x) result sign is same as sign of x, which
* differs from what Javascript wants (see Section 9.6).
[ ... bytecode escaped_source ]
[obj key desc value get set curr_value]
>>
msec
unary plus of a number is identity
equals and strict equals
* Loose equality, strict equality, and SameValue (E5 Sections 11.9.1, 11.9.4,
* 9.12). These have much in common so they can share some helpers.
*
* Future work notes:
*
* - Current implementation (and spec definition) has recursion; this should
* be fixed if possible.
*
* - String-to-number coercion should be possible without going through the
* value stack (and be more compact) if a shared helper is invoked.
The debugger protocol doesn't support a plain integer encoding for
* the full 32-bit unsigned range (only 32-bit signed). For now,
* unsigned 32-bit values simply written as signed ones. This is not
* a concrete issue except for 32-bit heaphdr fields. Proper solutions
* would be to (a) write such integers as IEEE doubles or (b) add an
* unsigned 32-bit dvalue.
comment:
* XXX: attempt to get the call result to "next temp" whenever
* possible to avoid unnecessary register shuffles.
*
* XXX: CSPROP (and CSREG) can overwrite the call target register, and save one temp,
* if the call target is a temporary register and at the top of the temp reg "stack".
label: code-design
tv points to element just below prev top
* Duktape/C function magic
* Identifier handling
error gets its 'name' from the prototype
Use a new environment but there's no 'arguments' object;
* delayed environment initialization. This is the most
* common case.
E5 Sections 11.9.1, 11.9.3
Capital sigma occurred at "end of word", lowercase to
* U+03C2 = GREEK SMALL LETTER FINAL SIGMA. Otherwise
* fall through and let the normal rules lowercase it to
* U+03C3 = GREEK SMALL LETTER SIGMA.
current digit
* Extern
* Mark objects on finalize_list.
*
comment: XXX: repetition of stack pre-checks -> helper or macro or inline
label: code-design
comment:
* Data follows the struct header. The struct size is padded by the
* compiler based on the struct members. This guarantees that the
* buffer data will be aligned-by-4 but not necessarily aligned-by-8.
*
* On platforms where alignment does not matter, the struct padding
* could be removed (if there is any). On platforms where alignment
* by 8 is required, the struct size must be forced to be a multiple
* of 8 by some means. Without it, some user code may break, and also
* Duktape itself breaks (e.g. the compiler stores duk_tvals in a
* dynamic buffer).
label: code-design
'valueOf'
XXX: potential issue with signed pointers, p_end < p.
* Helpers to resize properties allocation on specific needs.
comment: The line number tracking is a bit inconsistent right now, which
* affects debugger accuracy. Mostly call sites emit opcodes when
* they have parsed a token (say a terminating semicolon) and called
* duk__advance(). In this case the line number of the previous
* token is the most accurate one (except in prologue where
* prev_token.start_line is 0). This is probably not 100% correct
* right now.
label: code-design
shared object part
"Have" flags must not be conflicting so that they would
* apply to both a plain property and an accessor at the same
* time.
[ ... re_obj input ]
Backpointers.
string access cache (codepoint offset -> byte offset) for fast string
* character looping; 'weak' reference which needs special handling in GC.
bottom of new func
re_ctx->captures at the start of the atom parsed in this loop
* Scan from shortest distance:
* - start of string
* - end of string
* - cache entry (if exists)
refzero_list treated as reachability roots
* Memory calls.
+0.5 is handled by floor, this is on purpose
Duplicate (shadowing) labels are not allowed, except for the empty
* labels (which are used as default labels for switch and iteration
* statements).
*
* We could also allow shadowing of non-empty pending labels without any
* other issues than breaking the required label shadowing requirements
* of the E5 specification, see Section 12.12.
internal temporary value, used for char classes
comment: format is too large, abort
label: code-design
-> [ ... key val' ]
0x40-0x4f
MPUTOBJ emitted by outer loop
Errors are augmented when they are created, not when they are
* thrown or re-thrown. The current error handler, however, runs
* just before an error is thrown.
-0 is accepted here as index 0 because ToString(-0) == "0" which is
* in canonical form and thus an array index.
be_ctx->offset == length of encoded bitstream
'in'
Duktape.modLoaded[resolved_id] = module
Caller must ensure 'tv' is indeed a fastint!
stage 1 guarantees
typed for duk_unicode_decode_xutf8()
Macros for creating and checking bitmasks for character encoding.
* Bit number is a bit counterintuitive, but minimizes code size.
* Compile input string into an executable function template without
* arguments.
*
* The string is parsed as the "Program" production of Ecmascript E5.
* Compilation context can be either global code or eval code (see E5
* Sections 14 and 15.1.2.1).
*
* Input stack: [ ... filename ]
* Output stack: [ ... func_template ]
comment: XXX: macro? sets both heaphdr and object flags
label: code-design
[ ... varname ]
preinitialize lexer state partially
comment: XXX: slightly awkward
label: code-design
Once recursion depth is increased, exit path must decrease
* it (though it's OK to abort the fast path).
require
rnd in [lo,hi]
must have catch and/or finally
V
Technically Array.prototype.push() can create an Array with length
* longer than 2^32-1, i.e. outside the 32-bit range. The final length
* is *not* wrapped to 32 bits in the specification.
*
* This implementation tracks length with a uint32 because it's much
* more practical.
*
* See: test-bi-array-push-maxlen.js.
DUK_TOK_BXOR
[ ... re_obj input bc saved_buf res_obj val ]
No arr_idx update or limit check
[... varname]
fresh require (argument)
* Resolution loop. At the top of the loop we're expecting a valid
* term: '.', '..', or a non-empty identifier not starting with a period.
String object internal value is immutable
At this point 'res' holds the potential expression value.
* It can be basically any ivalue here, including a reg-bound
* identifier (if code above deems it safe) or a unary/binary
* operation. Operations must be resolved to a side effect free
* plain value, and the side effects must happen exactly once.
highest capture number emitted so far (used as: ++captures)
arbitrary remove only works with double linked heap, and is only required by
* reference counting so far.
comment: never reached, but avoids warnings of
* potentially unused variables.
label: code-design
new entry: previous value is garbage; set to undefined to share write_value
[ ... name name ]
nargs
each call this helper serves has nargs==2
assertion disabled
* Types are different; various cases for non-strict comparison
*
* Since comparison is symmetric, we use a "swap trick" to reduce
* code size.
Ensure dirty state causes a Status even if never process any
* messages. This is expected by the bytecode executor when in
* the running state.
* A C
* B A
* C <- sce ==> B
* D D
Sign extend: 0x0000##00 -> 0x##000000 -> sign extend to 0xssssss##
* Virtual properties.
*
* String and buffer indices are virtual and always enumerable,
* 'length' is virtual and non-enumerable. Array and arguments
* object props have special behavior but are concrete.
* Case conversion
* Helpers for dealing with the input string
const limits
0xc0-0xcf
The issues below can be solved with better flags
curr and desc are data
If forced reg, use it as destination. Otherwise try to
* use either coerced ispec if it is a temporary.
*
* When using extraops, avoid reusing arg2 as dest because that
* would lead to an LDREG shuffle below. We still can't guarantee
* dest != arg2 because we may have a forced_reg.
comment: XXX: putvar takes a duk_tval pointer, which is awkward and
* should be reworked.
label: code-design
bottom of current func
statement is guaranteed to be terminal (control doesn't flow to next statement)
Use a fast break/continue when possible. A fast break/continue is
* just a jump to the LABEL break/continue jump slot, which then jumps
* to an appropriate place (for break, going through ENDLABEL correctly).
* The peephole optimizer will optimize the jump to a direct one.
* Heap buffer representation.
*
* Heap allocated user data buffer which is either:
*
* 1. A fixed size buffer (data follows header statically)
* 2. A dynamic size buffer (data pointer follows header)
*
* The data pointer for a variable size buffer of zero size may be NULL.
Bernstein hash init value is normally 5381; XOR it in in case pointer low bits are 0
comment: Allow headroom for calls during error handling (see GH-191).
* We allow space for 10 additional recursions, with one extra
* for, e.g. a print() call at the deepest level.
label: code-design
http://en.wikipedia.org/wiki/Exponentiation_by_squaring
chain
[ ... closure ]
comment: Calling as a non-constructor is not meaningful.
label: code-design
* Voluntary periodic GC (if enabled)
Step types
'default'
comment: XXX: awkward; we assume there is space for this, overwrite
* directly instead?
label: code-design
E5 Section steps 7-8
result object is created and discarded; wasteful but saves code space
Gather in little endian
'fmt'
not caught by anything before entry level; rethrow and let the
* final catcher unwind everything
NUL terminate for convenient C access
'BYTES_PER_ELEMENT'
We don't log or warn about freeing zero refcount objects
* because they may happen with finalizer processing.
Don't allow a zero divisor. Restrict both v1 and
* v2 to positive values to avoid compiler specific
* behavior.
comment: XXX: logic for handling character ranges is now incorrect, it will accept
* e.g. [\d-z] whereas it should croak from it? SMJS accepts this too, though.
*
* Needs a read through and a lot of additional tests.
label: code-design
* Node.js Buffer.prototype.fill()
* Exposed debug macros: debugging disabled
comment: No NUL term checks in this debug code.
label: code-design
DUK_BUFOBJ_FLOAT64ARRAY
embed: duk_hobject ptr
getters
DUK_TOK_DELETE
DUK_TOK_BOR
comment: pseudotypes, not used in actual longjmps
label: code-design
A -> target reg
* BC -> inner function index
refcount code is processing refzero list
[ ... retval ]; popped below
0x80...0x8f
Get current Ecmascript time (= UNIX/Posix time, but in milliseconds).
Note: all references inside 'data' need to get their refcounts
* upped too. This is the case because refcounts are decreased
* through every function referencing 'data' independently.
comment: NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
label: code-design
entry_top + 1
Set datetime parts from stack arguments, defaulting any missing values.
* Day-of-week is not set; it is not required when setting the time value.
* ToBoolean() (E5 Section 9.2)
* Shift to new valstack_bottom.
0 = don't push current value
"." is not accepted in any format
tmp -> res
[ body formals source ]
comment: XXX: for simple cases like x['y'] an unnecessary LDREG is
* emitted for the base value; could avoid it if we knew that
* the key expression is safe (e.g. just a single literal).
label: code-design
Other initial bytes.
Similar to String comparison.
Finally, blame the innermost callstack entry which has a
* .fileName property.
skip finalizers; queue finalizable objects to heap_allocated
Note that duk__exprtop() here can clobber any reg above current temp_next,
* so any loop variables (e.g. enumerator) must be "preallocated".
* Parse a statement list.
*
* Handles automatic semicolon insertion and implicit return value.
*
* Upon entry, 'curr_tok' should contain the first token of the first
* statement (parsed in the "allow regexp literal" mode). Upon exit,
* 'curr_tok' contains the token following the statement list terminator
* (EOF or closing brace).
fixed top level hashtable size (separate chaining)
not present
end marker
handle negative values
invalidated by pushes, so get out of the way
h is NULL for lightfunc
* Error throwing
Non-buffer value is first ToString() coerced, then converted
* to a buffer (fixed buffer is used unless a dynamic buffer is
* explicitly requested).
comment: unused: not accepted in inbound messages
label: code-design
Reuse buffer as is unless buffer has grown large.
Offset is coerced first to signed integer range and then to unsigned.
* This ensures we can add a small byte length (1-8) to the offset in
* bound checks and not wrap.
internal align target for props allocation, must be 2*n for some n
Set timeval to 'this' from dparts, push the new time value onto the
* value stack and return 1 (caller can then tail call us). Expects
* the value stack to contain 'this' on the stack top.
target
DUK__FLD_FLOAT
XXX: shared helper for toFixed(), toExponential(), toPrecision()?
comment:
* Run an duk_hobject finalizer. Used for both reference counting
* and mark-and-sweep algorithms. Must never throw an error.
*
* There is no return value. Any return value or error thrown by
* the finalizer is ignored (although errors are debug logged).
*
* Notes:
*
* - The thread used for calling the finalizer is the same as the
* 'thr' argument. This may need to change later.
*
* - The finalizer thread 'top' assertions are there because it is
* critical that strict stack policy is observed (i.e. no cruft
* left on the finalizer stack).
label: code-design
-> x in [0, 2**32[
rethrow original error
'\xffThis'
Round up digits to a given position. If position is out-of-bounds,
* does nothing. If carry propagates over the first digit, a '1' is
* prepended to digits and 'k' will be updated. Return value indicates
* whether carry propagated over the first digit.
*
* Note that nc_ctx->count is NOT updated based on the rounding position
* (it is updated only if carry overflows over the first digit and an
* extra digit is prepended).
Check if any lookup above had a negative result.
DUK_USE_DEBUGGER_SUPPORT
* For/for-in main variants are:
*
* 1. for (ExpressionNoIn_opt; Expression_opt; Expression_opt) Statement
* 2. for (var VariableDeclarationNoIn; Expression_opt; Expression_opt) Statement
* 3. for (LeftHandSideExpression in Expression) Statement
* 4. for (var VariableDeclarationNoIn in Expression) Statement
*
* Parsing these without arbitrary lookahead or backtracking is relatively
* tricky but we manage to do so for now.
*
* See doc/compiler.rst for a detailed discussion of control flow
* issues, evaluation order issues, etc.
The specification is a bit vague what to do if the return
* value is not a number. Other implementations seem to
* tolerate non-numbers but e.g. V8 won't apparently do a
* ToNumber().
DUK_TOK_SUB_EQ
* Do a longjmp call, calling the fatal error handler if no
* catchpoint exists.
Fixed header info.
nothing to finalize
throw flag irrelevant (false in std alg)
comment: This approach is a bit shorter than a straight
* if-else-ladder and also a bit faster.
label: code-design
All lightfunc own properties are non-writable and the lightfunc
* is considered non-extensible. However, the write may be captured
* by an inherited setter which means we can't stop the lookup here.
name
accept string if next char is NUL (otherwise reject)
* "WhiteSpace" production check.
value1 -> yield value, iserror -> error / normal
Number of characters that the atom matches (e.g. 3 for 'abc'),
* -1 if atom is complex and number of matched characters either
* varies or is not known.
comment: 'funcs' is quite rarely used, so no local for it
label: code-design
reachable so pop OK
may be NULL, too
No entry in the catchstack which would actually catch a
* throw can refer to the callstack entry being reused.
* There *can* be catchstack entries referring to the current
* callstack entry as long as they don't catch (e.g. label sites).
* Heap creation and destruction
[ ... regexp_object escaped_source ]
now expected to fit into a 32-bit integer
Duktape.modSearch(resolved_id, fresh_require, exports, module).
bits 0...1: shift
Architecture, OS, and compiler strings
overflow
must fit into duk_small_int_t
'continue'
'value'
Non-critical.
comment: XXX: tail call: return duk_push_false(ctx)
label: code-design
comment:
* Sweep garbage and remove marking flags, and move objects with
* finalizers to the finalizer work list.
*
* Objects to be swept need to get their refcounts finalized before
* they are swept. In other words, their target object refcounts
* need to be decreased. This has to be done before freeing any
* objects to avoid decref'ing dangling pointers (which may happen
* even without bugs, e.g. with reference loops)
*
* Because strings don't point to other heap objects, similar
* finalization is not necessary for strings.
label: code-design
Note: target registers a and a+1 may overlap with DUK__REGCONSTP(b)
* and DUK__REGCONSTP(c). Careful here.
DUK_USE_DATE_NOW_GETTIMEOFDAY
comment: XXX: what's the safest way of creating a negative zero?
label: code-design
comment: XXX: several nice-to-have improvements here:
* - Use direct reads avoiding value stack operations
* - Avoid triggering getters, indicate getter values to debug client
* - If side effects are possible, add error catching
label: code-design
ptr may be NULL
E5 Sections 15.10.2.8, 7.3
Target must be stored so that we can recheck whether or not
* keys still exist when we enumerate. This is not done if the
* enumeration result comes from a proxy trap as there is no
* real object to check against.
* Note: currently no fast path for array index writes.
* They won't be possible anyway as strings are immutable.
Important to do a fastint check so that constants are
* properly read back as fastints.
remove artificial bump
important to use normalized NaN with 8-byte tagged types
Only objects in heap_allocated may have finalizers. Check that
* the object itself has a _Finalizer property (own or inherited)
* so that we don't execute finalizers for e.g. Proxy objects.
crossed offsets or zero size
[ ... escaped_source bytecode ]
* E5 Section 11.4.8
* Manipulate valstack so that args are on the current bottom and the
* previous caller's 'this' binding (which is the value preceding the
* current bottom) is replaced with the new 'this' binding:
*
* [ ... this_old | (crud) func this_new arg1 ... argN ]
* --> [ ... this_new | arg1 ... argN ]
*
* For tail calling to work properly, the valstack bottom must not grow
* here; otherwise crud would accumulate on the valstack.
* ToInteger() (E5 Section 9.4)
invalidates tv
* Fatal error
*
* There are no fatal error macros at the moment. There are so few call
* sites that the fatal error handler is called directly.
num_stack_args
property is virtual: used in duk_propdesc, never stored
* (used by e.g. buffer virtual properties)
'\xffVarmap'
Compute (extended) utf-8 length without codepoint encoding validation,
* used for string interning.
*
* NOTE: This algorithm is performance critical, more so than string hashing
* in some cases. It is needed when interning a string and needs to scan
* every byte of the string with no skipping. Having an ASCII fast path
* is useful if possible in the algorithm. The current algorithms were
* chosen from several variants, based on x64 gcc -O2 testing. See:
* https://github.com/svaarala/duktape/pull/422
*
* NOTE: must match src/dukutil.py:duk_unicode_unvalidated_utf8_length().
Only allow Duktape.Buffer when support disabled.
* Digit generation loop.
*
* Different termination conditions:
*
* 1. Free format output. Terminate when shortest accurate
* representation found.
*
* 2. Fixed format output, with specific number of digits.
* Ignore termination conditions, terminate when digits
* generated. Caller requests an extra digit and rounds.
*
* 3. Fixed format output, with a specific absolute cut-off
* position (e.g. 10 digits after decimal point). Note
* that we always generate at least one digit, even if
* the digit is below the cut-off point already.
number of digits changed
comment: re-lookup to update curr.flags
* XXX: would be faster to update directly
label: code-design
* Heap Buffer object representation. Used for all Buffer variants.
comment: Note: reuse variables
label: code-design
_Varmap
= 1 + arg count
* Tables generated with src/gennumdigits.py.
*
* duk__str2num_digits_for_radix indicates, for each radix, how many input
* digits should be considered significant for string-to-number conversion.
* The input is also padded to this many digits to give the Dragon4
* conversion enough (apparent) precision to work with.
*
* duk__str2num_exp_limits indicates, for each radix, the radix-specific
* minimum/maximum exponent values (for a Dragon4 integer mantissa)
* below and above which the number is guaranteed to underflow to zero
* or overflow to Infinity. This allows parsing to keep bigint values
* bounded.
'case'
num_pairs and temp_start reset at top of outer loop
Because size > 0, NULL check is correct
17: getUTCHours
[ ... enum ] -> [ ... next_key ]
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Encode to CESU-8; 'out' must have space for at least
* DUK_UNICODE_MAX_CESU8_LENGTH bytes; codepoints above U+10FFFF
* will encode to garbage but won't overwrite the output buffer.
if density < L, abandon array part, L = 3-bit fixed point, e.g. 2 -> 2/8 = 25%
* Finalize stack
Only a reg fits into 'A' so coerce 'res' into a register
* for PUTVAR.
*
* XXX: here the current A/B/C split is suboptimal: we could
* just use 9 bits for reg_res (and support constants) and 17
* instead of 18 bits for the varname const index.
* Helper for setting up var_env and lex_env of an activation,
* assuming it does NOT have the DUK_HOBJECT_FLAG_NEWENV flag.
no need for 'caller' post-check, because 'key' must be an array index
[ arg undefined ]
''
* String-to-number conversion
We can't shortcut zero here if it goes through special formatting
* (such as forced exponential notation).
0x10...0x1f
Main operation
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT8CLAMPED
* Note: INT8 is -not- copy compatible, e.g. -1 would coerce to 0x00.
invalidated
DUK_USE_CPP_EXCEPTIONS
max(incl)
* Arguments objects have exotic [[DefineOwnProperty]] which updates
* the internal 'map' of arguments for writes to currently mapped
* arguments. More conretely, writes to mapped arguments generate
* a write to a bound variable.
*
* The [[Put]] algorithm invokes [[DefineOwnProperty]] for existing
* data properties and new properties, but not for existing accessors.
* Hence, in E5 Section 10.6 ([[DefinedOwnProperty]] algorithm), we
* have a Desc with 'Value' (and possibly other properties too), and
* we end up in step 5.b.i.
A top-level assignment is e.g. "x = y;". For these it's safe
* to use the RHS as-is as the expression value, even if the RHS
* is a reg-bound identifier. The RHS ('res') is right associative
* so it has consumed all other assignment level operations; the
* only relevant lower binding power construct is comma operator
* which will ignore the expression value provided here. Usually
* the top level assignment expression value is ignored, but it
* is relevant for e.g. eval code.
comment: XXX: use helper for size optimization
label: code-design
'ignoreCase'
Note: env_thr != thr is quite possible and normal, so careful
* with what thread is used for valstack lookup.
frozen and sealed
tv -> value just before prev top value; must relookup
* Found existing inherited plain property.
* Do an access control check, and if OK, write
* new property to 'orig'.
initial estimate for ASCII only codepoints
Parser separator masks.
just in case callback is broken and won't write 'x'
comment: NEXTENUM needs a jump slot right after the main opcode.
* We need the code emitter to reserve the slot: if there's
* target shuffling, the target shuffle opcodes must happen
* after the jump slot (for NEXTENUM the shuffle opcodes are
* not needed if the enum is finished).
label: code-design
then to a register
retval to result[i]
Sanity limit on max number of properties (allocated, not necessarily used).
* This is somewhat arbitrary, but if we're close to 2**32 properties some
* algorithms will fail (e.g. hash size selection, next prime selection).
* Also, we use negative array/entry table indices to indicate 'not found',
* so anything above 0x80000000 will cause trouble now.
expect EOF instead of }
resizing parameters
value from target
this is especially critical to avoid another write call in detach1()
comment: Stripping the filename might be a good idea
* ("/foo/bar/quux.js" -> logger name "quux"),
* but now used verbatim.
label: code-design
return the argument object
new buffer of specified size
* Conversion helpers
%x; only 16 bits are guaranteed
mix-in value for computing string hashes; should be reasonably unpredictable
'debug'
keep default instance
Make buffer compact, matching current written size.
explicit semi follows
* Packed 8-byte representation
comment: XXX: currently no handling for non-allowed identifier characters,
* e.g. a '{' in the function name.
label: code-design
No support for lvalues returned from new or function call expressions.
* However, these must NOT cause compile-time SyntaxErrors, but run-time
* ReferenceErrors. Both left and right sides of the assignment must be
* evaluated before throwing a ReferenceError. For instance:
*
* f() = g();
*
* must result in f() being evaluated, then g() being evaluated, and
* finally, a ReferenceError being thrown. See E5 Section 11.13.1.
comment: XXX: awkward helpers
label: code-design
advance, expecting current token to be a specific token; parse next token in regexp context
stack prepped for func call: [ ... trap handler ]
'{"_nan":true}'
tagged null pointers should never occur
* Heap header definition and assorted macros, including ref counting.
* Access all fields through the accessor macros.
* Finally, longjmp
e.g. DUK_OP_POSTINCP
Allow leading minus sign
copy to buffer with spare to avoid Valgrind gripes from strptime
throw
4: toLocaleDateString
eat 'with'
[ ... this func ]
setters
step 4.c
Note: cannot assume that a non-zero return value of signbit() would
* always be the same -- hence cannot (portably) use something like:
*
* signbit(x) == signbit(y)
check func supports [[HasInstance]] (this is checked for every function
* in the bound chain, including the final one)
There is no need to NUL delimit the sscanf() call: trailing garbage is
* ignored and there is always a NUL terminator which will force an error
* if no error is encountered before it. It's possible that the scan
* would scan further than between [js_ctx->p,p[ though and we'd advance
* by less than the scanned value.
*
* Because pointers are platform specific, a failure to scan a pointer
* results in a null pointer which is a better placeholder than a missing
* value or an error.
comment: XXX: relocate
label: code-design
match fail
* Make a value copy of the input val. This ensures that
* side effects cannot invalidate the pointer.
DUK_USE_DATE_TZO_GMTIME
Treat like debugger statement: nop
Get valstack index for the func argument or throw if insane stack.
comment: 'd3' is never NaN, so no need to normalize
label: code-design
XXX: push_uint_string / push_u32_string
return value from Duktape.Thread.resume()
For the case n==1 Node.js doesn't seem to type check
* the sole member but we do it before returning it.
* For this case only the original buffer object is
* returned (not a copy).
end of loop (careful with len==0)
Result is always fastint compatible.
Handle a BREAK/CONTINUE opcode. Avoid using longjmp() for BREAK/CONTINUE
* handling because it has a measurable performance impact in ordinary
* environments and an extreme impact in Emscripten (GH-342).
DUK_TOK_TRY
Optional UTC conversion.
6
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined fresh_require exports module ]
provideThis=false
* Self test main
prototype is lex_env before catcher created
ToInteger() coercion; NaN -> 0, infinities are clamped to 0 and 10
Keep throwing an error whenever we get here. The unusual values
* are set this way because no instruction is ever executed, we just
* throw an error until all try/catch/finally and other catchpoints
* have been exhausted. Duktape/C code gets control at each protected
* call but whenever it enters back into Duktape the RangeError gets
* raised. User exec timeout check must consistently indicate a timeout
* until we've fully bubbled out of Duktape.
tc1 = true, tc2 = false
no need to handle thread state book-keeping here
Not found. Empty string case is handled specially above.
4 low bits
comment: XXX: option to pretend property doesn't exist if sanity limit is
* hit might be useful.
label: code-design
Use explicit steps in computation to try to ensure that
* computation happens with intermediate results coerced to
* double values (instead of using something more accurate).
* E.g. E5.1 Section 15.9.1.11 requires use of IEEE 754
* rules (= Ecmascript '+' and '*' operators).
*
* Without 'volatile' even this approach fails on some platform
* and compiler combinations. For instance, gcc 4.8.1 on Ubuntu
* 64-bit, with -m32 and without -std=c99, test-bi-date-canceling.js
* would fail because of some optimizations when computing tmp_time
* (MakeTime below). Adding 'volatile' to tmp_time solved this
* particular problem (annoyingly, also adding debug prints or
* running the executable under valgrind hides it).
comment: Smaller heaphdr than for other objects, because strings are held
* in string intern table which requires no link pointers. Much of
* the 32-bit flags field is unused by flags, so we can stuff a 16-bit
* field in there.
label: code-design
comment: Delete semantics are a bit tricky. The description in E5 specification
* is kind of confusing, because it distinguishes between resolvability of
* a reference (which is only known at runtime) seemingly at compile time
* (= SyntaxError throwing).
label: code-design
[ ... enum ] -> [ ... ]
* Augment an error being created using Duktape specific properties
* like _Tracedata or .fileName/.lineNumber.
misc constants and helper macros
zero-based day
28: setMinutes
non-object base, no offending virtual property
Fixed seed value used with ROM strings.
duk__parse_stmts() expects curr_tok to be set; parse in "allow regexp literal" mode with current strictness
E5 Sections 11.8.1, 11.8.5; x < y
may be < thr->catchstack initially
complex, multicharacter conversion
Not enough data to provide a full window, so "scroll" window to
* start of buffer and fill up the rest.
E5.1 Section 15.1.3.1: uriReserved + '#'
comment: XXX: should there be an error or an automatic detach if
* already attached?
label: code-design
For user code this could just return 1 (strict) always
* because all Duktape/C functions are considered strict,
* and strict is also the default when nothing is running.
* However, Duktape may call this function internally when
* the current activation is an Ecmascript function, so
* this cannot be replaced by a 'return 1' without fixing
* the internal call sites.
'"' was eaten by caller
expression is left-hand-side compatible
string is a reserved word (strict)
comment: XXX: Output type could be encoded into native function 'magic' value to
* save space. For setters the stridx could be encoded into 'magic'.
label: code-design
comment:
* Manipulation of thread stacks (valstack, callstack, catchstack).
*
* Ideally unwinding of stacks should have no side effects, which would
* then favor separate unwinding and shrink check primitives for each
* stack type. A shrink check may realloc and thus have side effects.
*
* However, currently callstack unwinding itself has side effects, as it
* needs to DECREF multiple objects, close environment records, etc.
* Stacks must thus be unwound in the correct order by the caller.
*
* (XXX: This should be probably reworked so that there is a shared
* unwind primitive which handles all stacks as requested, and knows
* the proper order for unwinding.)
*
* Valstack entries above 'top' are always kept initialized to
* "undefined unused". Callstack and catchstack entries above 'top'
* are not zeroed and are left as garbage.
*
* Value stack handling is mostly a part of the API implementation.
label: code-design
Step 9: copy elements-to-be-deleted into the result array
0x30-0x3f
2 bits for heap type
setjmp catchpoint setup
comment: not sure whether or not needed; Thursday
label: requirement
emergency mode: try extra hard
Set object 'length'.
byte index limit for element access, exclusive
We could rely on max temp/const checks: if they don't exceed BC
* limit, nothing here can either (just asserts would be enough).
* Currently we check for the limits, which provides additional
* protection against creating invalid bytecode due to compiler
* bugs.
require initializer for var/const
DUK_TOK_FALSE
fall-through control flow patchup; note that pc_prevstmt may be
* < 0 (i.e. no case clauses), in which case this is a no-op.
[ ... eval "eval" eval_input level ]
* ToObject() (E5 Section 9.9)
*
* ==> implemented in the API.
DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
comment:
* Handle integers in 32-bit range (that is, [-(2**32-1),2**32-1])
* specially, as they're very likely for embedded programs. This
* is now done for all radix values. We must be careful not to use
* the fast path when special formatting (e.g. forced exponential)
* is in force.
*
* XXX: could save space by supporting radix 10 only and using
* sprintf "%lu" for the fast path and for exponent formatting.
label: code-design
!(p < r)
Maximum exponent value when parsing numbers. This is not strictly
* compliant as there should be no upper limit, but as we parse the
* exponent without a bigint, impose some limit.
num_stack_args
comment: Executor interrupt counter check, used to implement breakpoints,
* debugging interface, execution timeouts, etc. The counter is heap
* specific but is maintained in the current thread to make the check
* as fast as possible. The counter is copied back to the heap struct
* whenever a thread switch occurs by the DUK_HEAP_SWITCH_THREAD() macro.
label: code-design
complete 'sub atom'
* Intern key via the valstack to ensure reachability behaves
* properly. We must avoid longjmp's here so use non-checked
* primitives.
*
* Note: duk_check_stack() potentially reallocs the valstack,
* invalidating any duk_tval pointers to valstack. Callers
* must be careful.
round out to 8 bytes
for convenience
buffer limits
Handle TypedArray vs. Node.js Buffer arg differences
DUK_TOK_WHILE
offset/value order different from Node.js
* Other cases (function declaration, anonymous function expression,
* strict direct eval code). The "outer" environment will be whatever
* the caller gave us.
* Setup environment record properties based on the template and
* its flags.
*
* If DUK_HOBJECT_HAS_NEWENV(fun_temp) is true, the environment
* records represent identifiers "outside" the function; the
* "inner" environment records are created on demand. Otherwise,
* the environment records are those that will be directly used
* (e.g. for declarations).
*
* _Lexenv is always set; _Varenv defaults to _Lexenv if missing,
* so _Varenv is only set if _Lexenv != _Varenv.
*
* This is relatively complex, see doc/identifier-handling.rst.
continue matched this label -- we can only continue if this is the empty
* label, for which duplication is allowed, and thus there is hope of
* finding a match deeper in the label stack.
Plus sign must be accepted for positive exponents
* (e.g. '1.5e+2'). This clause catches NULs.
DUK_TOK_VOID
DUK_USE_PC2LINE
DUK_HOBJECT_FLAG_STRICT varies
[ ... errval errhandler ]
comment: XXX: Valstack, callstack, and catchstack are currently assumed
* to have non-NULL pointers. Relaxing this would not lead to big
* benefits (except perhaps for terminated threads).
label: code-design
serialize the wrapper with empty string key
* Free a heap object.
*
* Free heap object and its internal (non-heap) pointers. Assumes that
* caller has removed the object from heap allocated list or the string
* intern table, and any weak references (which strings may have) have
* been already dealt with.
BITWISE EXPRESSIONS
comment:
* Copy some internal properties directly
*
* The properties will be writable and configurable, but not enumerable.
label: code-design
Valstack resize flags
comment: XXX: Hex encoded, length limited buffer summary here?
label: code-design
finish up pending jump and split for last alternative
nop
* Local declarations.
stack[0] = object (this)
* stack[1] = ToUint32(length)
* stack[2] = elem at index 0 (retval)
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers). A prototype loop must not cause
* an error to be thrown here; duk_hobject_hasprop_raw() will ignore a
* prototype loop silently and indicate that the property doesn't exist.
comment: XXX: coerce to regs? it might be better for enumeration use, where the
* same PROP ivalue is used multiple times. Or perhaps coerce PROP further
* there?
label: code-design
x > y --> y < x
* Found existing accessor property (own or inherited).
* Call setter with 'this' set to orig, and value as the only argument.
* Setter calls are OK even for ROM objects.
*
* Note: no exotic arguments object behavior, because [[Put]] never
* calls [[DefineOwnProperty]] (E5 Section 8.12.5, step 5.b).
resumee: [... initial_func] (currently actually: [initial_func])
Lookup 'key' from arguments internal 'map', and leave replacement value
* on stack top if mapped (and return non-zero).
* Used in E5 Section 10.6 algorithm for [[GetOwnProperty]] (used by [[Get]]).
proto can also be NULL here (allowed explicitly)
* split()
Validate that the whole slice [0,length[ is contained in the underlying
* buffer. Caller must ensure 'buf' != NULL.
could also just pop?
Parser part indices.
Compiler SyntaxError (or other error) gets the primary blame.
* Currently no flag to prevent blaming.
We don't check the zero padding bytes here right now
* (that they're actually zero). This seems to be common
* behavior for base-64 decoders.
An object may be in heap_allocated list with a zero
* refcount if it has just been finalized and is waiting
* to be collected by the next cycle.
* Local prototypes
low-level property functions
helpers for defineProperty() and defineProperties()
w/o refcounts
Skip dvalues to EOM.
all native functions have NEWENV
+1, right after inserted jump
only accept lowercase 'utf8' now.
comment: XXX: duplicates should be eliminated here
label: code-design
comment: XXX: block removal API primitive
label: code-design
LOGICAL EXPRESSIONS
%lf, %ld etc
* Switch is pretty complicated because of several conflicting concerns:
*
* - Want to generate code without an intermediate representation,
* i.e., in one go
*
* - Case selectors are expressions, not values, and may thus e.g. throw
* exceptions (which causes evaluation order concerns)
*
* - Evaluation semantics of case selectors and default clause need to be
* carefully implemented to provide correct behavior even with case value
* side effects
*
* - Fall through case and default clauses; avoiding dead JUMPs if case
* ends with an unconditional jump (a break or a continue)
*
* - The same case value may occur multiple times, but evaluation rules
* only process the first match before switching to a "propagation" mode
* where case values are no longer evaluated
*
* See E5 Section 12.11. Also see doc/compiler.rst for compilation
* discussion.
8: getFullYear
* Debug connection peek and flush primitives
'do'
duk_xdef_prop() will define an own property without any array
* special behaviors. We'll need to set the array length explicitly
* in the end. For arrays with elisions, the compiler will emit an
* explicit SETALEN which will update the length.
exponential notation forced
NB: 'val' may be invalidated here because put_value may realloc valstack,
* caller beware.
Here we'd have the option to normalize -0 to +0.
comment: XXX: share helper from lexer; duk_lexer.c / hexval().
label: code-design
comment:
* Create an internal enumerator object E, which has its keys ordered
* to match desired enumeration ordering. Also initialize internal control
* properties for enumeration.
*
* Note: if an array was used to hold enumeration keys instead, an array
* scan would be needed to eliminate duplicates found in the prototype chain.
label: code-design
comment: This is essentially the 'scale' algorithm, with recursion removed.
* Note that 'k' is either correct immediately, or will move in one
* direction in the loop. There's no need to do the low/high checks
* on every round (like the Scheme algorithm does).
*
* The scheme algorithm finds 'k' and updates 's' simultaneously,
* while the logical algorithm finds 'k' with 's' having its initial
* value, after which 's' is updated separately (see the Burger-Dybvig
* paper, Section 3.1, steps 2 and 3).
*
* The case where m+ == m- (almost always) is optimized for, because
* it reduces the bigint operations considerably and almost always
* applies. The scale loop only needs to work with m+, so this works.
label: code-design
A -> flags
* BC -> reg_catch; base register for two registers used both during
* trycatch setup and when catch is triggered
*
* If DUK_BC_TRYCATCH_FLAG_CATCH_BINDING set:
* reg_catch + 0: catch binding variable name (string).
* Automatic declarative environment is established for
* the duration of the 'catch' clause.
*
* If DUK_BC_TRYCATCH_FLAG_WITH_BINDING set:
* reg_catch + 0: with 'target value', which is coerced to
* an object and then used as a bindind object for an
* environment record. The binding is initialized here, for
* the 'try' clause.
*
* Note that a TRYCATCH generated for a 'with' statement has no
* catch or finally parts.
default: false
comment: fill new_h with u32 0xff = UNUSED
label: code-design
A non-extensible object cannot gain any more properties,
* so this is a good time to compact.
if direct eval, calling activation must exist
comment: XXX: because of the final check below (that the literal is not
* followed by a digit), this could maybe be simplified, if we bail
* out early from a leading zero (and if there are no periods etc).
* Maybe too complex.
label: code-design
* Create escaped RegExp source (E5 Section 15.10.3).
*
* The current approach is to special case the empty RegExp
* ('' -> '(?:)') and otherwise replace unescaped '/' characters
* with '\/' regardless of where they occur in the regexp.
*
* Note that normalization does not seem to be necessary for
* RegExp literals (e.g. '/foo/') because to be acceptable as
* a RegExp literal, the text between forward slashes must
* already match the escaping requirements (e.g. must not contain
* unescaped forward slashes or be empty). Escaping IS needed
* for expressions like 'new Regexp("...", "")' however.
* Currently, we re-escape in either case.
*
* Also note that we process the source here in UTF-8 encoded
* form. This is correct, because any non-ASCII characters are
* passed through without change.
Value stack is used to ensure reachability of constants and
* inner functions being loaded. Require enough space to handle
* large functions correctly.
comment: Automatic defaulting of logger name from caller. This would
* work poorly with tail calls, but constructor calls are currently
* never tail calls, so tail calls are not an issue now.
label: code-design
Fast check for extending array: check whether or not a slow density check is required.
comment: XXX: using duk_put_prop_index() would cause obscure error cases when Array.prototype
* has write-protected array index named properties. This was seen as DoubleErrors
* in e.g. some test262 test cases. Using duk_xdef_prop_index() is better but heavier.
* The best fix is to fill in the tracedata directly into the array part. There are
* no side effect concerns if the array part is allocated directly and only INCREFs
* happen after that.
label: code-design
filename may be NULL in which case file/line is not recorded
unsigned
comment: XXX: function flag to make this automatic?
label: requirement
Must have array part and no conflicting exotic behaviors.
* Doesn't need to have array special behavior, e.g. Arguments
* object has array part.
Breakpoint entries above the used area are left as garbage.
allow_source_elem
JSON parsing code is allowed to read [p_start,p_end]: p_end is
* valid and points to the string NUL terminator (which is always
* guaranteed for duk_hstrings.
fall through if overflow etc
inner function numbering
comment: XXX: could write output in chunks with fewer ensure calls,
* but relative benefit would be small here.
label: code-design
Assumes that saved[0] and saved[1] are always
* set by regexp bytecode (if not, char_end_offset
* will be zero). Also assumes clen reflects the
* correct char length.
comment: XXX: V8 throws a TypeError for negative values. Would it
* be more useful to interpret negative offsets here from the
* end of the buffer too?
label: code-design
function needs shuffle registers
The compiler should never emit DUK_OP_REGEXP if there is no
* regexp support.
invalid padding
Note: here we must be wary of the fact that a pointer may be
* valid and be a NULL.
comment: Here we can choose either to end parsing and ignore
* whatever follows, or to continue parsing in case
* multiple (possibly padded) base64 strings have been
* concatenated. Currently, keep on parsing.
label: code-design
[ requested_id require require.id resolved_id last_comp ]
advance to get one step of lookup
Write signed 32-bit integer.
* Canonicalize() abstract operation needed for canonicalization of individual
* codepoints during regexp compilation and execution, see E5 Section 15.10.2.8.
* Note that codepoints are canonicalized one character at a time, so no context
* specific rules can apply. Locale specific rules can apply, though.
This should not be necessary because no-one should tamper with the
* regexp bytecode, but is prudent to avoid potential segfaults if that
* were to happen for some reason.
Needs lookahead
* Churn refzero_list until empty
Note: 'q_instr' is still used below
duk_unicode_caseconv_uc[]
comment:
* Make a copy of tv_obj, tv_key, and tv_val to avoid any issues of
* them being invalidated by a valstack resize.
*
* XXX: this is now an overkill for many fast paths. Rework this
* to be faster (although switching to a valstack discipline might
* be a better solution overall).
label: code-design
failed, resize and try again
extend with undefined
comment:
* Traceback handling
*
* The unified helper decodes the traceback and produces various requested
* outputs. It should be optimized for size, and may leave garbage on stack,
* only the topmost return value matters. For instance, traceback separator
* and decoded strings are pushed even when looking for filename only.
*
* NOTE: although _Tracedata is an internal property, user code can currently
* write to the array (or replace it with something other than an array).
* The code below must tolerate arbitrary _Tracedata. It can throw errors
* etc, but cannot cause a segfault or memory unsafe behavior.
label: code-design
Error; error value is in heap->lj.value1.
-> [ ... key val toJSON val key ]
callstack
read 3 bytes into 't', padded by zero
XXX: remove this feature entirely? it would only matter for
* emergency GC. Disable for lowest memory builds.
* Computed values (e.g. INFINITY)
DUK_TOK_DIV_EQ
already set
input 'd' in Windows UTC, 100ns units
Keep current size
50x heap size
Dynamic buffer with 'curr_alloc' pointing to a dynamic area allocated using
* heap allocation primitives. Also used for external buffers when low memory
* options are not used.
[ name this ]
[ ... holder name val enum obj_key new_elem ]
patched later
[ ... regexp_object ]
comment:
* Note: the description in E5 Section 15.10.2.6 has a typo, it
* contains 'A' twice and lacks 'a'; the intent is [0-9a-zA-Z_].
label: documentation
This was the last term, and q_last was
* updated to match this term at loop top.
x <- b^y; use t1 and t2 as temps
prev_token.start_offset points to the closing brace here; when skipping
* we're going to reparse the closing brace to ensure semicolon insertion
* etc work as expected.
more initializers
ref.holder is global object, holder is the object with the
* conflicting property.
essentially tracks digit position of lowest 'f' digit
comment: Prevent any side effects on the string table and the caller provided
* str/blen arguments while interning is in progress. For example, if
* the caller provided str/blen from a dynamic buffer, a finalizer might
* resize that dynamic buffer, invalidating the call arguments.
label: code-design
binding power "levels" (see doc/compiler.rst)
Enter message processing loop for sending Status notifys and
* to finish a pending detach.
result reg
strings are only tracked by stringtable
to avoid relookups
abandoning requires a props allocation resize and
* 'rechecks' the valstack, invalidating any existing
* valstack value pointers!
If object has a .toJSON() property, we can't be certain
* that it wouldn't mutate any value arbitrarily, so bail
* out of the fast path.
*
* If an object is a Proxy we also can't avoid side effects
* so abandon.
Reviving an object using a heap pointer is a dangerous API
* operation: if the application doesn't guarantee that the
* pointer target is always reachable, difficult-to-diagnose
* problems may ensue. Try to validate the 'ptr' argument to
* the extent possible.
':'
comment: Unlike in duk_hex_encode() 'dst' is not necessarily aligned by 2.
* For platforms where unaligned accesses are not allowed, shift 'dst'
* ahead by 1 byte to get alignment and then DUK_MEMMOVE() the result
* in place. The faster encoding loop makes up the difference.
* There's always space for one extra byte because a terminator always
* follows the hex data and that's been accounted for by the caller.
label: code-design
E5 Section 7.3, treat the following as newlines:
* LF
* CR [not followed by LF]
* LS
* PS
*
* For CR LF, CR is ignored if it is followed by LF, and the LF will bump
* the line number.
comment:
* 'nregs' registers are allocated on function entry, at most 'nargs'
* are initialized to arguments, and the rest to undefined. Arguments
* above 'nregs' are not mapped to registers. All registers in the
* active stack range must be initialized because they are GC reachable.
* 'nargs' is needed so that if the function is given more than 'nargs'
* arguments, the additional arguments do not 'clobber' registers
* beyond 'nregs' which must be consistently initialized to undefined.
*
* Usually there is no need to know which registers are mapped to
* local variables. Registers may be allocated to variable in any
* way (even including gaps). However, a register-variable mapping
* must be the same for the duration of the function execution and
* the register cannot be used for anything else.
*
* When looking up variables by name, the '_Varmap' map is used.
* When an activation closes, registers mapped to arguments are
* copied into the environment record based on the same map. The
* reverse map (from register to variable) is not currently needed
* at run time, except for debugging, so it is not maintained.
label: code-design
Slice starting point is beyond current length.
... target is extensible
duk_unicode_support.c
comment: XXX: easier check with less code?
label: code-design
Used when precision is undefined; also used for NaN (-> "NaN"),
* and +/- infinity (-> "Infinity", "-Infinity").
x <- x * y, use t as temp
[ ... v1 v2 str ] -> [ ... str v2 ]
Zero 'count' is also allowed to make call sites easier.
comment: XXX: size optimize
label: code-design
!= 0 => post-update for array 'length' (used when key is an array index)
comment: has inner functions which may slow access (XXX: this can be optimized by looking at the inner functions)
label: code-design
comment: XXX: need to determine LHS type, and check that it is LHS compatible
label: code-design
false
* Built-in strings
* Clear (reachable) flags of finalize_list
*
* We could mostly do in the sweep phase when we move objects from the
* heap into the finalize_list. However, if a finalizer run is skipped
* during a mark-and-sweep, the objects on the finalize_list will be marked
* reachable during the next mark-and-sweep. Since they're already on the
* finalize_list, no-one will be clearing their REACHABLE flag so we do it
* here. (This now overlaps with the sweep handling in a harmless way.)
* Variant 3
* On second pass, skip the function.
OK for NULL.
Note: key issue here is to re-lookup the base pointer on every attempt.
* The pointer being reallocated may change after every mark-and-sweep.
-> [ ... key val toJSON val ]
comment: XXX: It would be nice to build the string directly but ToUint16()
* coercion is needed so a generic helper would not be very
* helpful (perhaps coerce the value stack first here and then
* build a string from a duk_tval number sequence in one go?).
label: code-design
Note: getprop may invoke any getter and invalidate any
* duk_tval pointers, so this must be done first.
[ obj trap_result res_arr propname ]
split1: prefer direct execution (no jump)
in resumer's context
Conceptually we'd extract the plain underlying buffer
* or its slice and then do a type mask check below to
* see if we should reject it. Do the mask check here
* instead to avoid making a copy of the buffer slice.
'try'
-> [in_val]
comment: Currently all built-in native functions are strict.
* This doesn't matter for many functions, but e.g.
* String.prototype.charAt (and other string functions)
* rely on being strict so that their 'this' binding is
* not automatically coerced.
label: code-design
comment:
* Helper for handling an Ecmascript-to-Ecmascript call or an Ecmascript
* function (initial) Duktape.Thread.resume().
*
* Compared to normal calls handled by duk_handle_call(), there are a
* bunch of differences:
*
* - the call is never protected
* - there is no C recursion depth increase (hence an "ignore recursion
* limit" flag is not applicable)
* - instead of making the call, this helper just performs the thread
* setup and returns; the bytecode executor then restarts execution
* internally
* - ecmascript functions are never 'vararg' functions (they access
* varargs through the 'arguments' object)
*
* The callstack of the target contains an earlier Ecmascript call in case
* of an Ecmascript-to-Ecmascript call (whose idx_retval is updated), or
* is empty in case of an initial Duktape.Thread.resume().
*
* The first thing to do here is to figure out whether an ecma-to-ecma
* call is actually possible. It's not always the case if the target is
* a bound function; the final function may be native. In that case,
* return an error so caller can fall back to a normal call path.
label: code-design
Note: 0xff != DUK_BC_B_MAX
* Unions and structs for self tests
Note: masking is done for 'i' to deal with negative numbers correctly
* For property layout 1, tweak e_size to ensure that the whole entry
* part (key + val + flags) is a suitable multiple for alignment
* (platform specific).
*
* Property layout 2 does not require this tweaking and is preferred
* on low RAM platforms requiring alignment.
don't run finalizers; queue finalizable objects back to heap_allocated
val1 = count
* Function declaration, function expression, or (non-standard)
* function statement.
*
* The E5 specification only allows function declarations at
* the top level (in "source elements"). An ExpressionStatement
* is explicitly not allowed to begin with a "function" keyword
* (E5 Section 12.4). Hence any non-error semantics for such
* non-top-level statements are non-standard. Duktape semantics
* for function statements are modelled after V8, see
* test-dev-func-decl-outside-top.js.
Get minimum array part growth for a certain size.
comment: XXX: very slow - better to bulk allocate a gap, and copy
* from args_array directly (we know it has a compact array
* part, etc).
label: code-design
'enumerate'
DUK_TOK_RSHIFT
roughly 256 bytes
comment: For now, just use duk_safe_call() to wrap duk_new(). We can't
* simply use a protected duk_handle_call() because there's post
* processing which might throw. It should be possible to ensure
* the post processing never throws (except in internal errors and
* out of memory etc which are always allowed) and then remove this
* wrapper.
label: code-design
object is now reachable
flags: "im"
Copy trap result keys into the enumerator object.
* Mark-and-sweep flags
*
* These are separate from heap level flags now but could be merged.
* The heap structure only contains a 'base mark-and-sweep flags'
* field and the GC caller can impose further flags.
Success path.
* If entering a 'catch' block which requires an automatic
* catch variable binding, create the lexical environment.
*
* The binding is mutable (= writable) but not deletable.
* Step 4 for the catch production in E5 Section 12.14;
* no value is given for CreateMutableBinding 'D' argument,
* which implies the binding is not deletable.
t1 <- (* r B)
DUK_BUFOBJ_UINT8ARRAY
Accept any duk_hbufferobject, though we're only normally
* called for Duktape.Buffer values.
Lenient: allow function declarations outside top level in
* non-strict mode but reject them in strict mode.
assertions: env must be closed in the same thread as where it runs
EOF (-1) will be cast to an unsigned value first
* and then re-cast for the switch. In any case, it
* will match the default case (syntax error).
refzero not running -> must be empty
comment: XXX: differentiate null pointer from empty string?
label: code-design
Normal object which doesn't get automatically coerced to a
* primitive value. Functions are checked for specially. The
* primitive value coercions for Number, String, Pointer, and
* Boolean can't result in functions so suffices to check here.
DUK_USE_MARK_AND_SWEEP
* Coercion and fast path processing
y == +Infinity
caller required to know
* Function name (if any)
*
* We don't check for prohibited names here, because we don't
* yet know whether the function will be strict. Function body
* parsing handles this retroactively.
*
* For function expressions and declarations function name must
* be an Identifer (excludes reserved words). For setter/getter
* it is a PropertyName which allows reserved words and also
* strings and numbers (e.g. "{ get 1() { ... } }").
comment: XXX: There are no format strings in duk_config.h yet, could add
* one for formatting duk_int64_t. For now, assumes "%lld" and that
* "long long" type exists. Could also rely on C99 directly but that
* won't work for older MSVC.
label: code-design
'toLocaleString'
* Manipulate value stack so that exactly 'num_stack_rets' return
* values are at 'idx_retbase' in every case, assuming there are
* 'rc' return values on top of stack.
*
* This is a bit tricky, because the called C function operates in
* the same activation record and may have e.g. popped the stack
* empty (below idx_retbase).
Exotic behaviors are only enabled for arguments objects
* which have a parameter map (see E5 Section 10.6 main
* algorithm, step 12).
*
* In particular, a non-strict arguments object with no
* mapped formals does *NOT* get exotic behavior, even
* for e.g. "caller" property. This seems counterintuitive
* but seems to be the case.
buffer is automatically zeroed
num_args
DUK_OP_EXTRA, sub-operation in A
insert the required matches (qmin) by copying the atom
DUK_USE_INTEGER_BE
out_clamped
adv = 2 default OK
There is no need to decref anything else than 'env': if 'env'
* becomes unreachable, refzero will handle decref'ing its prototype.
'-0'
module table remains registered to modLoaded, minimize its size
* Detach handling
write back
[ ... filename (temps) func ]
comment: It's not strictly necessary to track the current size, but
* it is useful for writing robust native code.
label: code-design
* Second pass parsing.
comment: Note: cannot portably debug print a function pointer, hence 'func' not printed!
label: code-design
* Arbitrary byteswap for potentially unaligned values
*
* Used to byteswap pointers e.g. in debugger code.
comment: XXX: There's some overlap with duk_js_closure() here, but
* seems difficult to share code. Ensure that the final function
* looks the same as created by duk_js_closure().
label: code-design
comment: It is important not to call this if the last byte read was an EOM.
* Reading ahead in this scenario would cause unnecessary blocking if
* another message is not available.
label: code-design
DUK_USE_EXEC_TIMEOUT_CHECK
* Misc defines
E5.1 Section 15.1.3.4: uriUnescaped
Combined size of separators already overflows
-> [ ... res ]
[ ... this name message ]
"/" and not in regexp mode
DUK_USE_BYTECODE_DUMP_SUPPORT
comment: may indirectly slow access through a direct eval
label: code-design
no incref needed
variable binding register if register-bound (otherwise < 0)
How much to advance before next loop; note that next loop
* will advance by 1 anyway, so -1 from the total escape
* length (e.g. len('\uXXXX') - 1 = 6 - 1). As a default,
* 1 is good.
comment: 'sce' points to the wrong entry here, but is no longer used
label: code-design
Note: this check relies on the fact that even a zero-size string
* has a non-NULL pointer.
[ ... varname val this ] (because throw_flag == 1, always resolved)
No need to reinit setjmp() catchpoint, as call handling
* will store and restore our state.
embed: duk_hbuffer ptr
t >= 0 always true, unsigned
Maximum expansion per input byte is 6:
* - invalid UTF-8 byte causes "\uXXXX" to be emitted (6/1 = 6).
* - 2-byte UTF-8 encodes as "\uXXXX" (6/2 = 3).
* - 4-byte UTF-8 encodes as "\Uxxxxxxxx" (10/4 = 2.5).
Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
xxx -> DUK_HBUFFEROBJECT_ELEM_INT16
vararg function, careful arg handling (e.g. thisArg may not be present)
implicit this value always undefined for
* declarative environment records.
comment:
* IsCallable() (E5 Section 9.11)
*
* XXX: API equivalent is a separate implementation now, and this has
* currently no callers.
label: code-design
Extract 'top' bits of currval; note that the extracted bits do not need
* to be cleared, we just ignore them on next round.
duk_unicode_ids_noabmp[]
Return value of 'sz' or more indicates output was (potentially)
* truncated.
A finalizer is looked up from the object and up its prototype chain
* (which allows inherited finalizers).
Encoding/decoding flags
Shared helper to implement ES6 Object.setPrototypeOf and
* Object.prototype.__proto__ setter.
*
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__
* http://www.ecma-international.org/ecma-262/6.0/index.html#sec-object.setprototypeof
no need to write 'out_bufdata'
new_used / size <= 1 / DIV <=> new_used <= size / DIV
Register the module table early to modLoaded[] so that we can
* support circular references even in modSearch(). If an error
* is thrown, we'll delete the reference.
label handling
Expression
comment: This is performance critical because it appears in every DECREF.
label: code-design
code_idx = entry_top + 0
-> [ ... lval rval ]
* Standard algorithm succeeded without errors, check for exotic post-behaviors.
*
* Arguments exotic behavior in E5 Section 10.6 occurs after the standard
* [[DefineOwnProperty]] has completed successfully.
*
* Array exotic behavior in E5 Section 15.4.5.1 is implemented partly
* prior to the default [[DefineOwnProperty]], but:
* - for an array index key (e.g. "10") the final 'length' update occurs here
* - for 'length' key the element deletion and 'length' update occurs here
* All defined array-indexed properties are in the array part
* (we assume the array part is comprehensive), and all array
* entries are writable, configurable, and enumerable. Thus,
* nothing can prevent array entries from being deleted.
comment:
* Helpers for creating and querying pc2line debug data, which
* converts a bytecode program counter to a source line number.
*
* The run-time pc2line data is bit-packed, and documented in:
*
* doc/function-objects.rst
label: documentation
Represent a null pointer as 'null' to be consistent with
* the JX format variant. Native '%p' format for a NULL
* pointer may be e.g. '(nil)'.
eat 'throw'
always grow the array, no sparse / abandon support here
leave formals on stack for later use
since index non-negative
tzoffset
duk_has_prop() popped the second 'name'
varname
* E5 Section 15.10.2.6 "IsWordChar" abstract operation. Assume
* x < 0 for characters read outside the string.
-------- ----XXXX
stack top: new time value, return 1 to allow tail calls
basereg
E5 Section 15.4.5.1, step 3, steps a - i are implemented here, j - n at the end
jump for 'catch' case
Module object containing module.exports, etc
'prototype' property for all built-in objects (which have it) has attributes:
* [[Writable]] = false,
* [[Enumerable]] = false,
* [[Configurable]] = false
stack[0] = start
* stack[1] = deleteCount
* stack[2...nargs-1] = items
* stack[nargs] = ToObject(this) -3
* stack[nargs+1] = ToUint32(length) -2
* stack[nargs+2] = result array -1
-> [ ... escaped_source bytecode ]
* Write to array part?
*
* Note: array abandonding requires a property resize which uses
* 'rechecks' valstack for temporaries and may cause any existing
* valstack pointers to be invalidated. To protect against this,
* tv_obj, tv_key, and tv_val are copies of the original inputs.
copy existing entries as is
5: toLocaleTimeString
mark-and-sweep: children not processed
Catches EOF of JSON input.
radix
comment: XXX: when optimizing for guaranteed property slots, use a guaranteed
* slot for internal value; this call can then access it directly.
label: code-design
no wrapping
comment:
* Create and throw an error (originating from Duktape internally)
*
* Push an error object on top of the stack, possibly throw augmenting
* the error, and finally longjmp.
*
* If an error occurs while we're dealing with the current error, we might
* enter an infinite recursion loop. This is prevented by detecting a
* "double fault" through the heap->handling_error flag; the recursion
* then stops at the second level.
label: code-design
if property key begins with underscore, encode it with
* forced quotes (e.g. "_Foo") to distinguish it from encoded
* internal properties (e.g. \xffBar -> _Bar).
object or array
no need to check now: both success and error are OK
Note: allow backtracking from p == ptr_end
Relookup if relocated
module.filename for .fileName, default to resolved ID if
* not present.
-> [ ... toLocaleString ToObject(val) ]
DUK_TOK_LBRACKET already eaten, current token is right after that
comment:
* Array needs to grow, but we don't want it becoming too sparse.
* If it were to become sparse, abandon array part, moving all
* array entries into the entries part (for good).
*
* Since we don't keep track of actual density (used vs. size) of
* the array part, we need to estimate somehow. The check is made
* in two parts:
*
* - Check whether the resize need is small compared to the
* current size (relatively); if so, resize without further
* checking (essentially we assume that the original part is
* "dense" so that the result would be dense enough).
*
* - Otherwise, compute the resize using an actual density
* measurement based on counting the used array entries.
label: code-design
Restore stack top after unbalanced code paths.
position of highest digit changed
* duk_heap allocation and freeing.
Careful with borrow condition:
* - If borrow not subtracted: 0x12345678 - 0 - 0xffffffff = 0x12345679 (> 0x12345678)
* - If borrow subtracted: 0x12345678 - 1 - 0xffffffff = 0x12345678 (== 0x12345678)
no statement value (unlike function expression)
Three digit octal escape, digits validated.
comment:
* Addition operator is different from other arithmetic
* operations in that it also provides string concatenation.
* Hence it is implemented separately.
*
* There is a fast path for number addition. Other cases go
* through potentially multiple coercions as described in the
* E5 specification. It may be possible to reduce the number
* of coercions, but this must be done carefully to preserve
* the exact semantics.
*
* E5 Section 11.6.1.
*
* Custom types also have special behavior implemented here.
label: code-design
Quite approximate but should be useful for little and big endian.
For X <op>= Y we need to evaluate the pre-op
* value of X before evaluating the RHS: the RHS
* can change X, but when we do <op> we must use
* the pre-op value.
Count is incremented before DUK__DRAGON4_OUTPUT_PREINC() call
* on purpose, which is taken into account by the macro.
NUL also comes here. Comparison order matters, 0x20
* is most common whitespace.
retval for success path
* Wrapping duk_safe_call() will mangle the stack, just return stack top
* Node.js Buffer.prototype: toJSON()
We'll need to interrupt early so recompute the init
* counter to reflect the number of bytecode instructions
* executed so that step counts for e.g. debugger rate
* limiting are accurate.
'fileName'
* Convert duk_compiler_func to a function template and add it
* to the parent function table.
parse args starting from "next temp"
This seems like a good overall approach. Fast path for ASCII in 4 byte
* blocks.
* Mark-and-sweep garbage collection.
comment:
* Object compaction (emergency only).
*
* Object compaction is a separate step after sweeping, as there is
* more free memory for it to work with. Also, currently compaction
* may insert new objects into the heap allocated list and the string
* table which we don't want to do during a sweep (the reachability
* flags of such objects would be incorrect). The objects inserted
* are currently:
*
* - a temporary duk_hbuffer for a new properties allocation
* - if array part is abandoned, string keys are interned
*
* The object insertions go to the front of the list, so they do not
* cause an infinite loop (they are not compacted).
label: code-design
comment: unnecessary div for last byte
label: code-design
buffer values are coerced first to string here
sanity limit for function pointer size
[ sep ToObject(this) len sep str0 ... str(count-1) ]
DUK_TOK_YIELD
comment: XXX: is valstack top best place for argument?
label: code-design
reset bytecode buffer but keep current size; pass 2 will
* require same amount or more.
duk_hobject_run_finalizer() sets
[ source template closure ]
Successful return: restore jmpbuf and return to caller.
negative -> no atom matched on previous round
[ ... name ]
Note: may be NULL if first call
unresolvable, no stack changes
comment: The DataView .buffer property is ordinarily set to the argument
* which is an ArrayBuffer. We accept any duk_hbufferobject as
* an argument and .buffer will be set to the argument regardless
* of what it is. This may be a bit confusing if the argument
* is e.g. a DataView or another TypedArray view.
*
* XXX: Copy .buffer property from a DataView/TypedArray argument?
* Create a fresh ArrayBuffer for Duktape.Buffer and Node.js Buffer
* arguments? See: test-bug-dataview-buffer-prop.js.
label: code-design
DUK_USE_DATE_NOW_TIME
XXX: valstack handling is awkward. Add a valstack helper which
* avoids dup():ing; valstack_copy(src, dst)?
On entry, item at idx_func is a bound, non-lightweight function,
* but we don't rely on that below.
* Reference counting implementation.
use strict equality instead of non-strict equality
This assert depends on the input parts representing time inside
* the Ecmascript range.
controls for minimum array part growth
-> [ ... key ]
* Returns non-zero if a key and/or value was enumerated, and:
*
* [enum] -> [key] (get_value == 0)
* [enum] -> [key value] (get_value == 1)
*
* Returns zero without pushing anything on the stack otherwise.
allow basic ASCII whitespace
Heap allocated: return heap pointer which is NOT useful
* for the caller, except for debugging.
activation is a direct eval call
current lex_env of the activation (created for catcher)
comment: Figure out all active breakpoints. A breakpoint is
* considered active if the current function's fileName
* matches the breakpoint's fileName, AND there is no
* inner function that has matching line numbers
* (otherwise a breakpoint would be triggered both
* inside and outside of the inner function which would
* be confusing). Example:
*
* function foo() {
* print('foo');
* function bar() { <-. breakpoints in these
* print('bar'); | lines should not affect
* } <-' foo() execution
* bar();
* }
*
* We need a few things that are only available when
* debugger support is enabled: (1) a line range for
* each function, and (2) access to the function
* template to access the inner functions (and their
* line ranges).
*
* It's important to have a narrow match for active
* breakpoints so that we don't enter checked execution
* when that's not necessary. For instance, if we're
* running inside a certain function and there's
* breakpoint outside in (after the call site), we
* don't want to slow down execution of the function.
label: code-design
start byte offset of token in lexer input
* Note: lj.value1 is 'value', lj.value2 is 'resumee'.
* This differs from YIELD.
curr_token = get/set name
Initial '[' has been checked and eaten by caller.
Thread may have changed, e.g. YIELD converted to THROW.
Lookup to encode one byte directly into 2 characters:
*
* def genhextab(bswap):
* for i in xrange(256):
* t = chr(i).encode('hex')
* if bswap:
* t = t[1] + t[0]
* print('0x' + t.encode('hex') + 'U')
* print('big endian'); genhextab(False)
* print('little endian'); genhextab(True)
* 64-bit arithmetic
*
* There are some platforms/compilers where 64-bit types are available
* but don't work correctly. Test for known cases.
be paranoid for 32-bit time values (even avoiding negative ones)
* Node.js Buffer.byteLength()
emit instruction; could return PC but that's not needed in the majority
* of cases.
Fast write calls which assume you control the spare beforehand.
* Multibyte write variants exist and use a temporary write pointer
* because byte writes alias with anything: with a stored pointer
* explicit pointer load/stores get generated (e.g. gcc -Os).
All the flags fit in 16 bits, so will fit into duk_bool_t.
flags: "g"
For cross-checking during development: ensure dispatch count
* matches cumulative interrupt counter init value sums.
valstack should not need changes
end of _Varmap
comment: Certain boxed types are required to go through
* automatic unboxing. Rely on internal value being
* sane (to avoid infinite recursion).
label: code-design
[-0x80000000,0x7fffffff]
DUK_HOBJECT_FLAG_EXOTIC_STRINGOBJ varies
'Arguments'
[key getter this] -> [key retval]
Retry allocation after mark-and-sweep for this
* many times. A single mark-and-sweep round is
* not guaranteed to free all unreferenced memory
* because of finalization (in fact, ANY number of
* rounds is strictly not enough).
only functions can have arguments
E5 Section 9.3.1
* GETVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is GetValue'd]
* 8.7.1 GetValue (V)
* 8.12.1 [[GetOwnProperty]] (P)
* 8.12.2 [[GetProperty]] (P)
* 8.12.3 [[Get]] (P)
*
* If 'throw' is true, always leaves two values on top of stack: [val this].
*
* If 'throw' is false, returns 0 if identifier cannot be resolved, and the
* stack will be unaffected in this case. If identifier is resolved, returns
* 1 and leaves [val this] on top of stack.
*
* Note: the 'strict' flag of a reference returned by GetIdentifierReference
* is ignored by GetValue. Hence we don't take a 'strict' parameter.
*
* The 'throw' flag is needed for implementing 'typeof' for an unreferenced
* identifier. An unreference identifier in other contexts generates a
* ReferenceError.
comment: XXX: top of stack must contain value, which helper doesn't touch,
* rework to use tv_val directly?
label: code-design
* Executor interrupt handling
*
* The handler is called whenever the interrupt countdown reaches zero
* (or below). The handler must perform whatever checks are activated,
* e.g. check for cumulative step count to impose an execution step
* limit or check for breakpoints or other debugger interaction.
*
* When the actions are done, the handler must reinit the interrupt
* init and counter values. The 'init' value must indicate how many
* bytecode instructions are executed before the next interrupt. The
* counter must interface with the bytecode executor loop. Concretely,
* the new init value is normally one higher than the new counter value.
* For instance, to execute exactly one bytecode instruction the init
* value is set to 1 and the counter to 0. If an error is thrown by the
* interrupt handler, the counters are set to the same value (e.g. both
* to 0 to cause an interrupt when the next bytecode instruction is about
* to be executed after error handling).
*
* Maintaining the init/counter value properly is important for accurate
* behavior. For instance, executor step limit needs a cumulative step
* count which is simply computed as a sum of 'init' values. This must
* work accurately even when single stepping.
0xd0...0xdf
tv1 is -below- valstack_bottom
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT32
[ obj Properties ]
* First attempt
not found
Loop check.
XXX: just assert non-NULL values here and make caller arguments
* do the defaulting to the default implementations (smaller code)?
reserved words: additional future reserved words in strict mode
* String table resize check.
*
* Note: this may silently (and safely) fail if GC is caused by an
* allocation call in stringtable resize_hash(). Resize_hash()
* will prevent a recursive call to itself by setting the
* DUK_MS_FLAG_NO_STRINGTABLE_RESIZE in heap->mark_and_sweep_base_flags.
Sync and NULL early.
12 to 21
comment: XXX: we should never shrink here; when we error out later, we'd
* need to potentially grow the value stack in error unwind which could
* cause another error.
label: code-design
-> pushes fixed buffer
comment: XXX: improve check; check against nregs, not against top
label: code-design
byte sizes will match
max # of values initialized in one MPUTARR set
not reached
-> [ ... this ]
* Local defines and forward declarations.
comment: prev value must be unused, no decref
label: code-design
Calling duk_debugger_cooperate() while Duktape is being
* called into is not supported. This is not a 100% check
* but prevents any damage in most cases.
Note: careful with indices like '-x'; if 'x' is zero, it refers to bottom
x >= y --> not (x < y)
yes, must set array length explicitly
* Post resize assertions.
Note: for dstlen=0, dst may be NULL
!DUK_USE_TRACEBACKS
-> [ func funcname env funcname ]
Constants for duk_lexer_ctx.buf.
Difference is in 100ns units, convert to milliseconds w/o fractions
* "IdentifierPart" production check.
prev exists and is not a letter
Note: no recursion issue, we can trust 'map' to behave
if fails, e_size will be zero = not an issue, except performance-wise
comment: XXX: use a NULL error handler for the finalizer call?
label: code-design
comment: workaround: max nbits = 24 now
label: code-design
DUK_USE_HEX_FASTPATH
DUK_UTIL_H_INCLUDED
'Infinity'
We know _Varmap only has own properties so walk property
* table directly. We also know _Varmap is dense and all
* values are numbers; assert for these. GC and finalizers
* shouldn't affect _Varmap so side effects should be fine.
debugger state, only relevant when attached
highest value of temp_reg (temp_max - 1 is highest used reg)
* Init compiler and lexer contexts
Input values are signed 48-bit so we can detect overflow
* reliably from high bits or just a comparison.
pre/post opcode values have constraints,
allocated heap objects
re-read to avoid spill / fetch
LRU: move our entry to first
argument/function declaration shadows 'arguments'
Proxy target
unconditional block
comment: XXX: Using a string return value forces a string intern which is
* not always necessary. As a rough performance measure, hex encode
* time for tests/perf/test-hex-encode.js dropped from ~35s to ~15s
* without string coercion. Change to returning a buffer and let the
* caller coerce to string if necessary?
label: code-design
* Node.js Buffer.prototype.copy()
DUK_VERBOSE_ERRORS
skip '|'
XXX: additional conditions when to close variables? we don't want to do it
* unless the environment may have "escaped" (referenced in a function closure).
* With delayed environments, the existence is probably good enough of a check.
When debugger is enabled, we need to recheck the activation
* status after returning. This is now handled by call handling
* and heap->dbg_force_restart.
'byteLength'
* Parsing implementation.
*
* JSON lexer is now separate from duk_lexer.c because there are numerous
* small differences making it difficult to share the lexer.
*
* The parser here works with raw bytes directly; this works because all
* JSON delimiters are ASCII characters. Invalid xUTF-8 encoded values
* inside strings will be passed on without normalization; this is not a
* compliance concern because compliant inputs will always be valid
* CESU-8 encodings.
* Detect iteration statements; if encountered, establish an
* empty label.
skip ')'
* Poppers
DUK_HOBJECT_H_INCLUDED
always at least the header
A -> target register
* B -> bytecode (also contains flags)
* C -> escaped source
Fast path, decode as is.
* "/" followed by something in regexp mode. See E5 Section 7.8.5.
*
* RegExp parsing is a bit complex. First, the regexp body is delimited
* by forward slashes, but the body may also contain forward slashes as
* part of an escape sequence or inside a character class (delimited by
* square brackets). A mini state machine is used to implement these.
*
* Further, an early (parse time) error must be thrown if the regexp
* would cause a run-time error when used in the expression new RegExp(...).
* Parsing here simply extracts the (candidate) regexp, and also accepts
* invalid regular expressions (which are delimited properly). The caller
* (compiler) must perform final validation and regexp compilation.
*
* RegExp first char may not be '/' (single line comment) or '*' (multi-
* line comment). These have already been checked above, so there is no
* need below for special handling of the first regexp character as in
* the E5 productions.
*
* About unicode escapes within regexp literals:
*
* E5 Section 7.8.5 grammar does NOT accept \uHHHH escapes.
* However, Section 6 states that regexps accept the escapes,
* see paragraph starting with "In string literals...".
* The regexp grammar, which sees the decoded regexp literal
* (after lexical parsing) DOES have a \uHHHH unicode escape.
* So, for instance:
*
* /\u1234/
*
* should first be parsed by the lexical grammar as:
*
* '\' 'u' RegularExpressionBackslashSequence
* '1' RegularExpressionNonTerminator
* '2' RegularExpressionNonTerminator
* '3' RegularExpressionNonTerminator
* '4' RegularExpressionNonTerminator
*
* and the escape itself is then parsed by the regexp engine.
* This is the current implementation.
*
* Minor spec inconsistency:
*
* E5 Section 7.8.5 RegularExpressionBackslashSequence is:
*
* \ RegularExpressionNonTerminator
*
* while Section A.1 RegularExpressionBackslashSequence is:
*
* \ NonTerminator
*
* The latter is not normative and a typo.
*
'break'
in yielder's context
* E5 Section 15.4.5.1, steps 3.k - 3.n. The order at the end combines
* the error case 3.l.iii and the success case 3.m-3.n.
*
* Note: 'length' is always in entries part, so no array abandon issues for
* 'writable' update.
* Avoid a GC if GC is already running. This can happen at a late
* stage in a GC when we try to e.g. resize the stringtable
* or compact objects.
Reject attempt to change virtual properties: not part of the
* standard algorithm, applies currently to e.g. virtual index
* properties of buffer objects (which are virtual but writable).
* (Cannot "force" modification of a virtual property.)
MakeDay
Push 'this' binding, check that it is a Date object; then push the
* internal time value. At the end, stack is: [ ... this timeval ].
* Returns the time value. Local time adjustment is done if requested.
Cannot use duk_to_string() on the buffer because it is usually
* larger than 'len'. Also, 'buf' is usually a stack buffer.
non-leap year: sunday, monday, ...
activation has tail called one or more times
extended types: custom encoding
reg
-> [... enum key val]
EOF
XXX: optimize value stack operation
* Proxy object handling
* Then decode the builtins init data (see genbuiltins.py) to
* init objects
mark as complex (capture handling)
string is a reserved word (non-strict)
s <- b^(1-e) * 2
* Object inspection commands: GetHeapObjInfo, GetObjPropDesc,
* GetObjPropDescRange
* Unreachable object about to be swept. Finalize target refcounts
* (objects which the unreachable object points to) without doing
* refzero processing. Recursive decrefs are also prevented when
* refzero processing is disabled.
*
* Value cannot be a finalizable object, as they have been made
* temporarily reachable for this round.
Map DUK__FLX_xxx to byte size.
Note that we currently parse -bytes-, not codepoints.
* All non-ASCII extended UTF-8 will encode to bytes >= 0x80,
* so they'll simply pass through (valid UTF-8 or not).
* Get/require
key, getter and setter, now reachable through object
comment:
* Finalize objects in the finalization work list. Finalized
* objects are queued back to heap_allocated with FINALIZED set.
*
* Since finalizers may cause arbitrary side effects, they are
* prevented during string table and object property allocation
* resizing using the DUK_MS_FLAG_NO_FINALIZERS flag in
* heap->mark_and_sweep_base_flags. In this case the objects
* remain in the finalization work list after mark-and-sweep
* exits and they may be finalized on the next pass.
*
* Finalization currently happens inside "MARKANDSWEEP_RUNNING"
* protection (no mark-and-sweep may be triggered by the
* finalizers). As a side effect:
*
* 1) an out-of-memory error inside a finalizer will not
* cause a mark-and-sweep and may cause the finalizer
* to fail unnecessarily
*
* 2) any temporary objects whose refcount decreases to zero
* during finalization will not be put into refzero_list;
* they can only be collected by another mark-and-sweep
*
* This is not optimal, but since the sweep for this phase has
* already happened, this is probably good enough for now.
label: code-design
* A Dragon4 number-to-string variant, based on:
*
* Guy L. Steele Jr., Jon L. White: "How to Print Floating-Point Numbers
* Accurately"
*
* Robert G. Burger, R. Kent Dybvig: "Printing Floating-Point Numbers
* Quickly and Accurately"
*
* The current algorithm is based on Figure 1 of the Burger-Dybvig paper,
* i.e. the base implementation without logarithm estimation speedups
* (these would increase code footprint considerably). Fixed-format output
* does not follow the suggestions in the paper; instead, we generate an
* extra digit and round-with-carry.
*
* The same algorithm is used for number parsing (with b=10 and B=2)
* by generating one extra digit and doing rounding manually.
*
* See doc/number-conversion.rst for limitations.
holder will be set to the target object, not the actual object
* where the property was found (see duk__get_identifier_reference()).
'Array'
* INITSET/INITGET are only used to initialize object literal keys.
* The compiler ensures that there cannot be a previous data property
* of the same name. It also ensures that setter and getter can only
* be initialized once (or not at all).
extended utf-8 not allowed for URIs
* E5 Section 15.7.2.1 requires that the constructed object
* must have the original Number.prototype as its internal
* prototype. However, since Number.prototype is non-writable
* and non-configurable, this doesn't have to be enforced here:
* The default object (bound to 'this') is OK, though we have
* to change its class.
*
* Internal value set to ToNumber(arg) or +0; if no arg given,
* ToNumber(undefined) = NaN, so special treatment is needed
* (above). String internal value is immutable.
bytecode limits
guaranteed to find an empty slot
Because 'day since epoch' can be negative and is used to compute weekday
* using a modulo operation, add this multiple of 7 to avoid negative values
* when year is below 1970 epoch. Ecmascript time values are restricted to
* +/- 100 million days from epoch, so this adder fits nicely into 32 bits.
* Round to a multiple of 7 (= floor(100000000 / 7) * 7) and add margin.
Allow trailing garbage (e.g. treat "123foo" as "123)
comment: XXX: Are steps 6 and 7 in E5 Section 15.11.4.4 duplicated by
* accident or are they actually needed? The first ToString()
* could conceivably return 'undefined'.
label: code-design
comment: Size sanity check. Should not be necessary because caller is
* required to check this, but we don't want to cause a segfault
* if the size wraps either in duk_size_t computation or when
* storing the size in a 16-bit field.
label: code-design
steps 3.h and 3.i
Note: toJSON() is a generic function which works even if 'this'
* is not a Date. The sole argument is ignored.
module (argument)
valstack space that suffices for all local calls, including recursion
* of other than Duktape calls (getters etc)
current paren level allows 'in' token
comment: XXX: fast-int-to-double
label: code-design
* ArrayBuffer.isView()
Magically bound variable cannot be an accessor. However,
* there may be an accessor property (or a plain property) in
* place with magic behavior removed. This happens e.g. when
* a magic property is redefined with defineProperty().
* Cannot assert for "not accessor" here.
* We could clear the book-keeping variables for the topmost activation,
* but don't do so now.
* Debugging enabled
* E5 Section 7.4, allow SourceCharacter (which is any 16-bit
* code point).
comment: XXX: duk_set_length
label: code-design
comment: XXX: which lists should participate? to be finalized?
label: code-design
XXXXXX-- --------
* Bitstream decoder.
* The handling here is a bit tricky. If a previous '|' has been processed,
* we have a pending split1 and a pending jump (for a previous match). These
* need to be back-patched carefully. See docs for a detailed example.
Step 16: update length; note that the final length may be above 32 bit range
* (but we checked above that this isn't the case here)
comment: XXX: 'internal error' is a bit of a misnomer
label: code-design
comment: In compatible mode and standard JSON mode, output
* something useful for non-BMP characters. This won't
* roundtrip but will still be more or less readable and
* more useful than an error.
label: code-design
A debugger forced interrupt check is not needed here, as
* problematic safe calls are not caused by side effects.
Real world behavior for map(): trailing non-existent
* elements don't invoke the user callback, but are still
* counted towards result 'length'.
Ensure argument name is not a reserved word in current
* (final) strictness. Formal argument parsing may not
* catch reserved names if strictness changes during
* parsing.
*
* We only need to do this in strict mode because non-strict
* keyword are always detected in formal argument parsing.
retval (sub-atom char length) unused, tainted as complex above
no pre-checks now, assume a previous yield() has left things in
* tip-top shape (longjmp handler will assert for these).
* Peephole optimizer for finished bytecode.
*
* Does not remove opcodes; currently only straightens out unconditional
* jump chains which are generated by several control structures.
should not happen
Avoid doing an actual write callback with length == 0,
* because that's reserved for a write flush.
DUK_TOK_REGEXP
* Peephole optimize JUMP chains.
* Execution timeout check
Recursive value reviver, implements the Walk() algorithm. No C recursion
* check is done here because the initial parsing step will already ensure
* there is a reasonable limit on C recursion depth and hence object depth.
type to represent a reg/const reference during compilation
TypedArray views need an automatic ArrayBuffer which must be
* provided as .buffer property of the view. Just create a new
* ArrayBuffer sharing the same underlying buffer.
*
* The ArrayBuffer offset is always set to zero, so that if one
* accesses the ArrayBuffer at the view's .byteOffset, the value
* matches the view at index 0.
comment: Indent helper. Calling code relies on js_ctx->recursion_depth also being
* directly related to indent depth.
label: code-design
DUK_TOK_PUBLIC
E5 Sections 11.8.4, 11.8.5; x >= y --> not (x < y)
'get'
comment: function name (borrowed reference), ends up in _name
label: code-design
repl_value
quotes
'undefined' already on stack top
'res' is used for "left", and 'tmp' for "right"
def_value
Delete elements required by a smaller length, taking into account
* potentially non-configurable elements. Returns non-zero if all
* elements could be deleted, and zero if all or some elements could
* not be deleted. Also writes final "target length" to 'out_result_len'.
* This is the length value that should go into the 'length' property
* (must be set by the caller). Never throws an error.
* duk_handle_call_protected() and duk_handle_call_unprotected():
* call into a Duktape/C or an Ecmascript function from any state.
*
* Input stack (thr):
*
* [ func this arg1 ... argN ]
*
* Output stack (thr):
*
* [ retval ] (DUK_EXEC_SUCCESS)
* [ errobj ] (DUK_EXEC_ERROR (normal error), protected call)
*
* Even when executing a protected call an error may be thrown in rare cases
* such as an insane num_stack_args argument. If there is no catchpoint for
* such errors, the fatal error handler is called.
*
* The error handling path should be error free, even for out-of-memory
* errors, to ensure safe sandboxing. (As of Duktape 1.4.0 this is not
* yet the case, see XXX notes below.)
comment: XXX: skip null filename?
label: code-design
avoid multiply
New require() function for module, updated resolution base
comment:
* Function pointers
*
* Printing function pointers is non-portable, so we do that by hex printing
* bytes from memory.
label: code-design
"-Infinity", '-' has been eaten
make absolute
'act' already set above
DUK_BUFOBJ_UINT8CLAMPEDARRAY
comment: XXX: turkish / azeri, lowercase rules
label: code-design
comment: Coerce like a string. This makes sense because addition also treats
* buffers like strings.
label: code-design
Non-zero refcounts should not happen for unreachable strings,
* because we refcount finalize all unreachable objects which
* should have decreased unreachable string refcounts to zero
* (even for cycles).
no comma
strict outer context
jump for 'finally' case or end (if no finally)
* Structs
DUK__L0 -> '\' char
* DUK__L1 ... DUK__L5 -> more lookup
from next pc
If the value happens to be 0xFFFFFFFF, it's not a valid array index
* but will then match DUK__NO_ARRAY_INDEX.
use 'left' as a temp
JSON
binary arithmetic; DUK_OP_ADD, DUK_OP_EQ, other binary ops
Innermost fast path processes 4 valid base-64 characters at a time
* but bails out on whitespace, padding chars ('=') and invalid chars.
* Once the slow path segment has been processed, we return to the
* inner fast path again. This handles e.g. base64 with newlines
* reasonably well because the majority of a line is in the fast path.
Key and value indices are either (-2, -1) or (-1, -2). Given idx_key,
* idx_val is always (idx_key ^ 0x01).
* Pointer built-ins
Zero length string is not accepted without quotes
[ key ] -> []
No activation, no variable access. Could also pretend
* we're in the global program context and read stuff off
* the global object.
current function being compiled (embedded instead of pointer for more compact access)
Note: src_data may be NULL if input is a zero-size
* dynamic buffer.
Note: 'this' may be bound to any value, not just an object
comment: XXX: Not needed for now, so not implemented. Note that
* function pointers may have different size/layout than
* a void pointer.
label: requirement
out of spec, don't care
comment: XXX: idx_val would fit into 16 bits, but using duk_small_uint_t
* might not generate better code due to casting.
label: code-design
used by e.g. duk_regexp_executor.c, string built-ins
comment: XXX: could also copy from template, but there's no way to have any
* other value here now (used code has no access to the template).
label: code-design
Share yield longjmp handler.
curr_token slot2 (matches 'lex' slot2_idx)
Error message doesn't matter: the error is ignored anyway.
Have a calling activation, check for direct eval (otherwise
* assume indirect eval.
comment: Compact but lots of churn.
label: code-design
Output shuffling: only one output register is realistically possible.
*
* (Zero would normally be an OK marker value: if the target register
* was zero, it would never be shuffled. But with DUK_USE_SHUFFLE_TORTURE
* this is no longer true, so use -1 as a marker instead.)
comment: actually used
label: code-design
rule match
* Helper structs
terminating conditions
see below
allow automatic semicolon even without lineterm (compatibility)
Outside any activation -> put to global.
+0 = break, +1 = continue
try locale specific formatter; if it refuses to format the
* string, fall back to an ISO 8601 formatted value in local
* time.
-> [ val arr ]
* Byte matching for back-references would be OK in case-
* sensitive matching. In case-insensitive matching we need
* to canonicalize characters, so back-reference matching needs
* to be done with codepoints instead. So, we just decode
* everything normally here, too.
*
* Note: back-reference index which is 0 or higher than
* NCapturingParens (= number of capturing parens in the
* -entire- regexp) is a compile time error. However, a
* backreference referring to a valid capture which has
* not matched anything always succeeds! See E5 Section
* 15.10.2.9, step 5, sub-step 3.
this is needed for regexp mode
jump to next case clause
pop plain buffer, now reachable through h_bufres
* PUTPROP: Ecmascript property write.
*
* Unlike Ecmascript primitive which returns nothing, returns 1 to indicate
* success and 0 to indicate failure (assuming throw is not set).
*
* This is an extremely tricky function. Some examples:
*
* * Currently a decref may trigger a GC, which may compact an object's
* property allocation. Consequently, any entry indices (e_idx) will
* be potentially invalidated by a decref.
*
* * Exotic behaviors (strings, arrays, arguments object) require,
* among other things:
*
* - Preprocessing before and postprocessing after an actual property
* write. For example, array index write requires pre-checking the
* array 'length' property for access control, and may require an
* array 'length' update after the actual write has succeeded (but
* not if it fails).
*
* - Deletion of multiple entries, as a result of array 'length' write.
*
* * Input values are taken as pointers which may point to the valstack.
* If valstack is resized because of the put (this may happen at least
* when the array part is abandoned), the pointers can be invalidated.
* (We currently make a copy of all of the input values to avoid issues.)
add AD*2^16
Proxy handler
comment:
* Tailcall handling
*
* Although the callstack entry is reused, we need to explicitly unwind
* the current activation (or simulate an unwind). In particular, the
* current activation must be closed, otherwise something like
* test-bug-reduce-judofyr.js results. Also catchstack needs be unwound
* because there may be non-error-catching label entries in valid tail calls.
label: code-design
comment: Should not be required because the code below always sets both high
* and low parts, but at least gcc-4.4.5 fails to deduce this correctly
* (perhaps because the low part is set (seemingly) conditionally in a
* loop), so this is here to avoid the bogus warning.
label: code-design
Impose a maximum string length for now. Restricted artificially to
* ensure adding a heap header length won't overflow size_t. The limit
* should be synchronized with DUK_HBUFFER_MAX_BYTELEN.
*
* E5.1 makes provisions to support strings longer than 4G characters.
* This limit should be eliminated on 64-bit platforms (and increased
* closer to maximum support on 32-bit platforms).
relookup exports from module.exports in case it was changed by modSearch
* Indexed read/write helpers (also used from outside this file)
adv = 2 - 1 default OK
comment: XXX: the key in 'key in obj' is string coerced before we're called
* (which is the required behavior in E5/E5.1/E6) so the key is a string
* here already.
label: code-design
comment: XXX: side effect handling is quite awkward here
label: code-design
act->func
comment: Set stack top within currently allocated range, but don't reallocate.
* This is performance critical especially for call handling, so whenever
* changing, profile and look at generated code.
label: code-design
comment: Neutered checks not necessary here: neutered buffers have
* zero 'length' so we'll effectively skip them.
label: code-design
Call setup checks callability.
comment: Flags for intermediate value coercions. A flag for using a forced reg
* is not needed, the forced_reg argument suffices and generates better
* code (it is checked as it is used).
label: code-design
comment: Non-ASCII slow path (range-by-range linear comparison), very slow
label: code-design
Contract, either:
* - Push value on stack and return 1
* - Don't push anything on stack and return 0
0: not IdentifierStart or IdentifierPart
* 1: IdentifierStart and IdentifierPart
* -1: IdentifierPart only
DUK_BUFOBJ_UINT32ARRAY
* Restore 'caller' property for non-strict callee functions.
(>= e 0) AND (not (= f (expt b (- p 1))))
*
* be <- (expt b e) == b^e
* r <- (* f be 2) == 2 * f * b^e [if b==2 -> f * b^(e+1)]
* s <- 2
* m+ <- be == b^e
* m- <- be == b^e
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
A -> unused (reserved for flags, for consistency with DUK_OP_CALL)
* B -> target register and start reg: constructor, arg1, ..., argN
* (for DUK_OP_NEWI, 'b' is indirect)
* C -> num args (N)
0x60...0x6f
>= 0
mimic semantics for strings
Parse a single statement.
*
* Creates a label site (with an empty label) automatically for iteration
* statements. Also "peels off" any label statements for explicit labels.
DUK__FLD_8BIT
[key]
normal key/value
mm <- b^e
steps 4.a and 4.b are tricky
The external string struct is defined even when the feature is inactive.
fixed arg count
A -> flags
* B -> return value reg/const
* C -> currently unused
comment: Because there are quite many call sites, pack error code (require at most
* 8-bit) into a single argument.
label: code-design
Raw helper to extract internal information / statistics about a value.
* The return values are version specific and must not expose anything
* that would lead to security issues (e.g. exposing compiled function
* 'data' buffer might be an issue). Currently only counts and sizes and
* such are given so there should not be a security impact.
-> [ ... closure template newobj ]
XXX: This causes recursion up to inner function depth
* which is normally not an issue, e.g. mark-and-sweep uses
* a recursion limiter to avoid C stack issues. Avoiding
* this would mean some sort of a work list or just refusing
* to serialize deep functions.
* Size-optimized pc->line mapping.
return as is
value1 -> resume value, value2 -> resumee thread, iserror -> error/normal
function: create binding for func name (function templates only, used for named function expressions)
The low 8 bits map directly to duk_hobject.h DUK_PROPDESC_FLAG_xxx.
* The remaining flags are specific to the debugger.
comment: XXX: copy from caller?
label: code-design
always for register bindings
comment: XXX: optimize: allocate an array part to the necessary size (upwards
* estimate) and fill in the values directly into the array part; finally
* update 'length'.
label: code-design
heap->dbg_udata: keep
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
IdentifierStart production with Letter, ASCII, and non-BMP excluded
comment:
* Custom formatter for debug printing, allowing Duktape specific data
* structures (such as tagged values and heap objects) to be printed with
* a nice format string. Because debug printing should not affect execution
* state, formatting here must be independent of execution (see implications
* below) and must not allocate memory.
*
* Custom format tags begin with a '%!' to safely distinguish them from
* standard format tags. The following conversions are supported:
*
* %!T tagged value (duk_tval *)
* %!O heap object (duk_heaphdr *)
* %!I decoded bytecode instruction
* %!C bytecode instruction opcode name (arg is long)
*
* Everything is serialized in a JSON-like manner. The default depth is one
* level, internal prototype is not followed, and internal properties are not
* serialized. The following modifiers change this behavior:
*
* @ print pointers
* # print binary representations (where applicable)
* d deep traversal of own properties (not prototype)
* p follow prototype chain (useless without 'd')
* i include internal properties (other than prototype)
* x hexdump buffers
* h heavy formatting
*
* For instance, the following serializes objects recursively, but does not
* follow the prototype chain nor print internal properties: "%!dO".
*
* Notes:
*
* * Standard snprintf return value semantics seem to vary. This
* implementation returns the number of bytes it actually wrote
* (excluding the null terminator). If retval == buffer size,
* output was truncated (except for corner cases).
*
* * Output format is intentionally different from Ecmascript
* formatting requirements, as formatting here serves debugging
* of internals.
*
* * Depth checking (and updating) is done in each type printer
* separately, to allow them to call each other freely.
*
* * Some pathological structures might take ages to print (e.g.
* self recursion with 100 properties pointing to the object
* itself). To guard against these, each printer also checks
* whether the output buffer is full; if so, early exit.
*
* * Reference loops are detected using a loop stack.
label: code-design
dummy value used as marker
never here, but fall through
comment:
* duk_handle_safe_call(): make a "C protected call" within the
* current activation.
*
* The allowed thread states for making a call are the same as for
* duk_handle_call_xxx().
*
* Error handling is similar to duk_handle_call_xxx(); errors may be thrown
* (and result in a fatal error) for insane arguments.
label: code-design
must never longjmp
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside object 'a_size'.
Must set 'length' explicitly when using duk_xdef_prop_xxx() to
* set the values.
heaphdr size and additional allocation size, followed by
* type specific stuff (with varying value count)
stack top contains 'true'
callbacks and udata; dbg_read_cb != NULL is used to indicate attached state
'\xffHandler'
Note: string is a terminal heap object, so no depth check here
0x80-0x8f
* Internal helper for defining an accessor property, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes. This is called
* very rarely, so the implementation first sets a value to undefined
* and then changes the entry to an accessor (this is to save code space).
Debug print which visualizes the qsort partitioning process.
XXX: this placeholder is not always correct, but use for now.
* It will fail in corner cases; see test-dev-func-cons-args.js.
r <- (2 * f) * b^e
unreferenced with some options
always terminates led()
(reference is valid as long activation exists)
don't report __FILE__ / __LINE__ as fileName/lineNumber
comment: Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
* breaking out of here. Prefer smallest code.
label: code-design
Pause for all step types: step into, step over, step out.
* This is the only place explicitly handling a step out.
awkward; we assume there is space for this
Peek ahead in the stream one byte.
* Breakpoint management
* Compact an object
slot B is both a target and a source (used by extraops like DUK_EXTRAOP_INSTOF
alias for above
handle comma and closing brace
shrink case; leave some spare
strictness is not inherited, intentional
only Array.prototype matches
Parse a function-like expression, assuming that 'comp_ctx->curr_func' is
* correctly set up. Assumes that curr_token is just after 'function' (or
* 'set'/'get' etc).
function: always register bound
comment: XXX: fast primitive to set a bunch of values to UNDEFINED
label: code-design
Buffer size needed for duk_bi_date_format_timeval().
* Accurate value is 32 + 1 for NUL termination:
* >>> len('+123456-01-23T12:34:56.123+12:34')
* 32
* Include additional space to be safe.
We want to compare the slice/view areas of the arguments.
* If either slice/view is invalid (underlying buffer is shorter)
* ensure equals() is false, but otherwise the only thing that
* matters is to be memory safe.
This seems reasonable overall.
Loop prevention
'throw'
we're running inside the caller's activation, so no change in call/catch stack or valstack bottom
Assume that the native representation never contains a closing
* parenthesis.
varargs marker
entry level reached
Current strictness flag: affects API calls.
Because value stack init policy is 'undefined above top',
* we don't need to write, just assert.
'*'
call is from executor, so we know we have a jmpbuf
Yield/resume book-keeping.
finally part will catch
Quite lenient, e.g. allow empty as zero, but don't allow trailing
* garbage.
IEEE requires that NaNs compare false
Load inner functions to value stack, but don't yet copy to buffer.
[ start end ]
comment: Try to make do with a stack buffer to avoid allocating a temporary buffer.
* This works 99% of the time which is quite nice.
label: code-design
This testcase fails when Emscripten-generated code runs on Firefox.
* It's not an issue because the failure should only affect packed
* duk_tval representation, which is not used with Emscripten.
comment: XXX: keys is an internal object with all keys to be processed
* in its (gapless) array part. Because nobody can touch the keys
* object, we could iterate its array part directly (keeping in mind
* that it can be reallocated).
label: code-design
Return value is like write(), number of bytes written.
* The return value matters because of code like:
* "off += buf.copy(...)".
Exponent without digits (e.g. "1e" or "1e+"). If trailing garbage is
* allowed, ignore exponent part as garbage (= parse as "1", i.e. exp 0).
DUK_TOK_THROW
comment: Note: not a typo, "object" is returned for a null value
label: documentation
atom_char_length, atom_start_offset, atom_start_offset reflect the
* atom matched on the previous loop. If a quantifier is encountered
* on this loop, these are needed to handle the quantifier correctly.
* new_atom_char_length etc are for the atom parsed on this round;
* they're written to atom_char_length etc at the end of the round.
Original idiom used, minimal code size.
comment: 'fun' is quite rarely used, so no local for it
label: code-design
comment: XXX: fastint
label: code-design
Note: in integer arithmetic, (x / 4) is same as floor(x / 4) for non-negative
* values, but is incorrect for negative ones.
normal
Careful with wrapping (left shifting idx would be unsafe).
comment: XXX: for negative input offsets, 'offset' will be a large
* positive value so the result here is confusing.
label: code-design
no overflow
"+11:22\0"
borrowed: function being executed; for bound function calls, this is the final, real function, NULL for lightfuncs
comment:
* Augment error (throw time), unless alloc/double error
label: code-design
-> [ ... ToObject(this) ToUint32(length) arg[i] ]
The specification has quite awkward order of coercion and
* checks for toPrecision(). The operations below are a bit
* reordered, within constraints of observable side effects.
caller
match followed by capture(s)
return input buffer, converted to a Duktape.Buffer object
* if called as a constructor (no change if called as a
* function).
We could use a switch-case for the class number but it turns out
* a small if-else ladder on class masks is better. The if-ladder
* should be in order of relevancy.
* New length is smaller than old length, need to delete properties above
* the new length.
*
* If array part exists, this is straightforward: array entries cannot
* be non-configurable so this is guaranteed to work.
*
* If array part does not exist, array-indexed values are scattered
* in the entry part, and some may not be configurable (preventing length
* from becoming lower than their index + 1). To handle the algorithm
* in E5 Section 15.4.5.1, step l correctly, we scan the entire property
* set twice.
'ptr' is evaluated both as LHS and RHS.
* Ecmascript [[Class]]
comment: Quick reject of too large or too small exponents. This check
* would be incorrect for zero (e.g. "0e1000" is zero, not Infinity)
* so zero check must be above.
label: code-design
finalize_list will always be processed completely
comment: XXX: exposed duk_debug_read_pointer
label: code-design
-> [ ... key val replacer holder ]
If index is not valid, idx will be DUK__NO_ARRAY_INDEX which
* is 0xffffffffUL. We don't need to check for that explicitly
* because 0xffffffffUL will never be inside bufferobject length.
open scope information, for compiled functions only
Handle empty separator case: it will always match, and always
* triggers the check in step 13.c.iii initially. Note that we
* must skip to either end of string or start of first codepoint,
* skipping over any continuation bytes!
*
* Don't allow an empty string to match at the end of the input.
temp reg handling
* Parse function body
x <- y - z
'Pointer'
relookup if changed
comment:
* Augment an error at creation time with _Tracedata/fileName/lineNumber
* and allow a user error handler (if defined) to process/replace the error.
* The error to be augmented is at the stack top.
*
* thr: thread containing the error value
* thr_callstack: thread which should be used for generating callstack etc.
* c_filename: C __FILE__ related to the error
* c_line: C __LINE__ related to the error
* noblame_fileline: if true, don't fileName/line as error source, otherwise use traceback
* (needed because user code filename/line are reported but internal ones
* are not)
*
* XXX: rename noblame_fileline to flags field; combine it to some existing
* field (there are only a few call sites so this may not be worth it).
label: code-design
throw_flag
* Else, must be one of:
* - ExpressionStatement, possibly a directive (String)
* - LabelledStatement (Identifier followed by ':')
*
* Expressions beginning with 'function' keyword are covered by a case
* above (such expressions are not allowed in standard E5 anyway).
* Also expressions starting with '{' are interpreted as block
* statements. See E5 Section 12.4.
*
* Directive detection is tricky; see E5 Section 14.1 on directive
* prologue. A directive is an expression statement with a single
* string literal and an explicit or automatic semicolon. Escape
* characters are significant and no parens etc are allowed:
*
* 'use strict'; // valid 'use strict' directive
* 'use\u0020strict'; // valid directive, not a 'use strict' directive
* ('use strict'); // not a valid directive
*
* The expression is determined to consist of a single string literal
* based on duk__expr_nud() and duk__expr_led() call counts. The string literal
* of a 'use strict' directive is determined to lack any escapes based
* num_escapes count from the lexer. Note that other directives may be
* allowed to contain escapes, so a directive with escapes does not
* terminate a directive prologue.
*
* We rely on the fact that the expression parser will not emit any
* code for a single token expression. However, it will generate an
* intermediate value which we will then successfully ignore.
*
* A similar approach is used for labels.
The act->prev_caller should only be set if the entry for 'caller'
* exists (as it is only set in that case, and the property is not
* configurable), but handle all the cases anyway.
break/continue without label
comment: XXX: the best typing needs to be validated by perf measurement:
* e.g. using a small type which is the cast to a larger duk_idx_t
* may be slower than declaring the variable as a duk_idx_t in the
* first place.
label: code-design
comment: XXX: conversion errors should not propagate outwards.
* Perhaps values need to be coerced individually?
label: code-design
XXX: here we need to know if 'left' is left-hand-side compatible.
* That information is no longer available from current expr parsing
* state; it would need to be carried into the 'left' ivalue or by
* some other means.
non-global regexp: lastIndex never updated on match
Note: undefined from Section 11.8.5 always results in false
* return (see e.g. Section 11.8.3) - hence special treatment here.
If there's no catch block, rc_varname will be 0 and duk__patch_trycatch()
* will replace the LDCONST with a NOP. For any actual constant (including
* constant 0) the DUK__CONST_MARKER flag will be set in rc_varname.
exposed because lexer needs these too
empty match (may happen with empty separator) -> bump and continue
As with all inspection code, we rely on the debug client providing
* a valid, non-stale pointer: there's no portable way to safely
* validate the pointer here.
Set up curr_pc for opcode dispatch.
[ ... pattern flags escaped_source ]
comment: The 'magic' field allows an opaque 16-bit field to be accessed by the
* Duktape/C function. This allows, for instance, the same native function
* to be used for a set of very similar functions, with the 'magic' field
* providing the necessary non-argument flags / values to guide the behavior
* of the native function. The value is signed on purpose: it is easier to
* convert a signed value to unsigned (simply AND with 0xffff) than vice
* versa.
*
* Note: cannot place nargs/magic into the heaphdr flags, because
* duk_hobject takes almost all flags already (and needs the spare).
label: code-design
Get minimum entry part growth for a certain size.
valstack index of start of args (arg1) (relative to entry valstack_bottom)
[ ToObject(this) item1 ... itemN arr item(i) item(i)[j] ]
thr->heap->lj.value2 is 'thread', will be wiped out at the end
break/continue with label (label cannot be a reserved word, production is 'Identifier'
property access
Coerce all finite parts with ToInteger(). ToInteger() must not
* be called for NaN/Infinity because it will convert e.g. NaN to
* zero. If ToInteger() has already been called, this has no side
* effects and is idempotent.
*
* Don't read dparts[DUK_DATE_IDX_WEEKDAY]; it will cause Valgrind
* issues if the value is uninitialized.
internal property functions
Report thrown value to client coerced to string
comment: ArrayBuffer argument is handled specially above; the rest of the
* argument variants are handled by shared code below.
label: code-design
DUK_USE_USER_INITJS
Range limited to [0, 0x7fffffff] range, i.e. range that can be
* represented with duk_int32_t. Use this when the method doesn't
* handle the full 32-bit unsigned range correctly.
110x xxxx 10xx xxxx
Sanity limits for stack sizes.
comment: Linear scan: more likely because most objects are small.
* This is an important fast path.
*
* XXX: this might be worth inlining for property lookups.
label: code-design
XXX: will need a force flag if garbage collection is triggered
* explicitly during paused state.
Array length is larger than 'asize'. This shouldn't
* happen in practice. Bail out just in case.
No net refcount change.
* Assert context is valid: non-NULL pointer, fields look sane.
*
* This is used by public API call entrypoints to catch invalid 'ctx' pointers
* as early as possible; invalid 'ctx' pointers cause very odd and difficult to
* diagnose behavior so it's worth checking even when the check is not 100%.
* Setup value stack: clamp to 'nargs', fill up to 'nregs'
This should not happen because DUK_TAG_OBJECT case checks
* for this already, but check just in case.
result array is already at the top of stack
args go here as a comma expression in parens
[ ... source? filename? &comp_args ] (depends on flags)
no extra padding
Start position (inclusive) and end position (exclusive)
tentative, checked later
slot A is a source (default: target)
indexed by recursion_depth
* Fixed buffer helper useful for debugging, requires no allocation
* which is critical for debugging.
Order of unwinding is important
* Final sigma context specific rule. This is a rather tricky
* rule and this handling is probably not 100% correct now.
* The rule is not locale/language specific so it is supported.
tracks maximum initialized index + 1
comment: first register that is a temporary (below: variables)
label: code-design
A -> register of target object
* B -> first register of value data (start_index, value1, value2, ..., valueN)
* C -> number of key/value pairs (N)
Just skip, leaving zeroes in the result.
[ ... arr ]
Note: successive characters could be joined into string matches
* but this is not trivial (consider e.g. '/xyz+/); see docs for
* more discussion.
Coerce an duk_ivalue to a register or constant; result register may
* be a temp or a bound register.
*
* The duk_ivalue argument ('x') is converted into a regconst as a
* side effect.
bytes in source
no voluntary gc
A -> result reg
* B -> object reg
* C -> key reg/const
An object may have FINALIZED here if it was finalized by mark-and-sweep
* on a previous run and refcount then decreased to zero. We won't run the
* finalizer again here.
comment: XXX: allow object to be a const, e.g. in 'foo'.toString()?
* On the other hand, DUK_REGCONSTP() is slower and generates
* more code.
label: code-design
refcount
regexp res_obj is at index 4
stack[0] = callback fn
* stack[1] = initialValue
* stack[2] = object (coerced this)
* stack[3] = length (not needed, but not popped above)
* stack[4] = accumulator
comment: Node.js Buffer variable width integer field. We don't really
* care about speed here, so aim for shortest algorithm.
label: code-design
The spec algorithm first does "R = ToString(separator)" before checking
* whether separator is undefined. Since this is side effect free, we can
* skip the ToString() here.
']'
NULL with zero length represents an empty string; NULL with higher
* length is also now trated like an empty string although it is
* a bit dubious. This is unlike duk_push_string() which pushes a
* 'null' if the input string is a NULL.
-> [ func funcname env funcname func ]
true, because v[1] has at least one bit set
bp to use when parsing a top level Expression
Caller will finish the marking process if we hit a recursion limit.
y
comment:
* E5 Section 7.6:
*
* IdentifierStart:
* UnicodeLetter
* $
* _
* \ UnicodeEscapeSequence
*
* IdentifierStart production has one multi-character production:
*
* \ UnicodeEscapeSequence
*
* The '\' character is -not- matched by this function. Rather, the caller
* should decode the escape and then call this function to check whether the
* decoded character is acceptable (see discussion in E5 Section 7.6).
*
* The "UnicodeLetter" alternative of the production allows letters
* from various Unicode categories. These can be extracted with the
* "src/extract_chars.py" script.
*
* Because the result has hundreds of Unicode codepoint ranges, matching
* for any values >= 0x80 are done using a very slow range-by-range scan
* and a packed range format.
*
* The ASCII portion (codepoints 0x00 ... 0x7f) is fast-pathed below because
* it matters the most. The ASCII related ranges of IdentifierStart are:
*
* 0x0041 ... 0x005a ['A' ... 'Z']
* 0x0061 ... 0x007a ['a' ... 'z']
* 0x0024 ['$']
* 0x005f ['_']
label: code-design
Must be an object, otherwise TypeError (E5.1 Section 8.10.5, step 1).
TypeError if fails
* Entries part
* Delayed env creation check
insert 'undefined' values at idx_rcbase to get the
* return values to idx_retbase
xxx -> DUK_HBUFFEROBJECT_ELEM_INT8
guarantees entry_callstack_top - 1 >= 0
no code needs to be emitted, the regs already have values
magic: 0=getter call, 1=Object.getPrototypeOf
PC is unsigned. If caller does PC arithmetic and gets a negative result,
* it will map to a large PC which is out of bounds and causes a zero to be
* returned.
* Debug connection write primitives
comment: XXX: join these ops (multiply-accumulate), but only if
* code footprint decreases.
label: code-design
module.name for .name, default to last component if
* not present.
* Exposed debug macros: debugging enabled
Object.defineProperty() calls [[DefineOwnProperty]] with Throw=true
0xe0-0xef
compact the prototype
XXX: default priority for infix operators is duk__expr_lbp(tok) -> get it here?
read header
prop index in 'hash part', < 0 if not there
This is based on Rhino EquivalentYear() algorithm:
* https://github.com/mozilla/rhino/blob/f99cc11d616f0cdda2c42bde72b3484df6182947/src/org/mozilla/javascript/NativeDate.java
comment: Clamping to zero makes the API more robust to calling code
* calculation errors.
label: code-design
Surround with parentheses like in JX, ensures NULL pointer
* is distinguishable from null value ("(null)" vs "null").
Attempt to write 'stack', 'fileName', 'lineNumber' works as if
* user code called Object.defineProperty() to create an overriding
* own property. This allows user code to overwrite .fileName etc
* intuitively as e.g. "err.fileName = 'dummy'" as one might expect.
* See https://github.com/svaarala/duktape/issues/387.
object is a native function (duk_hnativefunction)
[ ... error func fileName lineNumber ]
21 bits
comment: XXX: thread selection for mark-and-sweep is currently a hack.
* If we don't have a thread, the entire mark-and-sweep is now
* skipped (although we could just skip finalizations).
label: code-design
embed: duk_hstring ptr
enumeration
* Free memory
Maximum value check ensures 'nbytes' won't wrap below.
Use existing env (e.g. for non-strict eval); cannot have
* an own 'arguments' object (but can refer to an existing one).
currently, even for Array.prototype
unsigned intentionally
DUK_TOK_SNEQ
only outer_lex_env matters, as functions always get a new
* variable declaration environment.
No need to assert, buffer size maximum is 0xffff.
default is explicit index read/write copy
not enumerable
* Exposed data
avoid problems if p == h->prototype
DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
Output shuffle needed after main operation
For native calls must be NULL so we don't sync back
comment: XXX: very basic optimization -> duk_get_prop_stridx_top
label: code-design
omitted
'toGMTString'
* Object related
*
* Note: seal() and freeze() are accessible through Ecmascript bindings,
* and are not exposed through the API.
* ISO 8601 subset parser.
Internal keys are prefixed with 0xFF in the stringtable
* (which makes them invalid UTF-8 on purpose).
without explicit non-BMP support, assume non-BMP characters
* are always accepted as identifier characters.
[res]
dash is already 0
Object flag. There are currently 26 flag bits available. Make sure
* this stays in sync with debugger object inspection code.
This may only happen if built-ins are being "torn down".
* This behavior is out of specification scope.
Not possible because array object 'length' is present
* from its creation and cannot be deleted, and is thus
* caught as an existing property above.
Note: strictness is not inherited from the current Duktape/C
* context. Otherwise it would not be possible to compile
* non-strict code inside a Duktape/C activation (which is
* always strict now). See tests/api/test-eval-strictness.c
* for discussion.
A -> flags
* B -> base register for call (base -> func, base+1 -> this, base+2 -> arg1 ... base+2+N-1 -> argN)
* (for DUK_OP_CALLI, 'b' is indirect)
* C -> nargs
* Wrapper for jmp_buf.
*
* This is used because jmp_buf is an array type for backward compatibility.
* Wrapping jmp_buf in a struct makes pointer references, sizeof, etc,
* behave more intuitively.
*
* http://en.wikipedia.org/wiki/Setjmp.h#Member_types
* This is a bit tricky to implement portably. The result depends
* on the timestamp (specifically, DST depends on the timestamp).
* If e.g. UNIX APIs are used, they'll have portability issues with
* very small and very large years.
*
* Current approach:
*
* - Stay within portable UNIX limits by using equivalent year mapping.
* Avoid year 1970 and 2038 as some conversions start to fail, at
* least on some platforms. Avoiding 1970 means that there are
* currently DST discrepancies for 1970.
*
* - Create a UTC and local time breakdowns from 't'. Then create
* a time_t using gmtime() and localtime() and compute the time
* difference between the two.
*
* Equivalent year mapping (E5 Section 15.9.1.8):
*
* If the host environment provides functionality for determining
* daylight saving time, the implementation of ECMAScript is free
* to map the year in question to an equivalent year (same
* leap-year-ness and same starting week day for the year) for which
* the host environment provides daylight saving time information.
* The only restriction is that all equivalent years should produce
* the same result.
*
* This approach is quite reasonable but not entirely correct, e.g.
* the specification also states (E5 Section 15.9.1.8):
*
* The implementation of ECMAScript should not try to determine
* whether the exact time was subject to daylight saving time, but
* just whether daylight saving time would have been in effect if
* the _current daylight saving time algorithm_ had been used at the
* time. This avoids complications such as taking into account the
* years that the locale observed daylight saving time year round.
*
* Since we rely on the platform APIs for conversions between local
* time and UTC, we can't guarantee the above. Rather, if the platform
* has historical DST rules they will be applied. This seems to be the
* general preferred direction in Ecmascript standardization (or at least
* implementations) anyway, and even the equivalent year mapping should
* be disabled if the platform is known to handle DST properly for the
* full Ecmascript range.
*
* The following has useful discussion and links:
*
* https://bugzilla.mozilla.org/show_bug.cgi?id=351066
keep val_highest
comment: XXX: limit to quoted strings only, to save keys from being cluttered?
label: code-design
DUK_USE_DEBUGGER_THROW_NOTIFY || DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
can't get value, may be accessor
Relookup and initialize dispatch loop variables. Debugger check.
* Longjmp state, contains the information needed to perform a longjmp.
* Longjmp related values are written to value1, value2, and iserror.
leave result on stack top
Resolved, normalized absolute module ID
marker; not actual tagged value
re-lookup curr char on first round
[ ... formals arguments map mappedNames ]
borrowed: full duk_tval for function being executed; for lightfuncs
Shared handler to minimize parser size. Cause will be
* hidden, unfortunately, but we'll have an offset which
* is often quite enough.
Skip dvalue.
comment: XXX: inefficient; block remove primitive
label: code-design
If duk__ivalue_toplain_raw() allocates a temp, forget it and
* restore next temp state.
DUK_HOBJECT_FLAG_CONSTRUCTABLE varies
[ ... pattern flags ]
custom; implies DUK_HOBJECT_IS_THREAD
[ thisArg arg1 ... argN ]
for array and object literals
validation of the regexp is caller's responsibility
regnum is sane
* To avoid creating a heavy intermediate value for the list of ranges,
* only the start token ('[' or '[^') is parsed here. The regexp
* compiler parses the ranges itself.
comment: XXX: Currently function source code is not stored, as it is not
* required by the standard. Source code should not be stored by
* default (user should enable it explicitly), and the source should
* probably be compressed with a trivial text compressor; average
* compression of 20-30% is quite easy to achieve even with a trivial
* compressor (RLE + backwards lookup).
*
* Debugging needs source code to be useful: sometimes input code is
* not found in files as it may be generated and then eval()'d, given
* by dynamic C code, etc.
*
* Other issues:
*
* - Need tokenizer indices for start and end to substring
* - Always normalize function declaration part?
* - If we keep _Formals, only need to store body
label: code-design
Preinc/predec for var-by-name, slow path.
tm_isdst is both an input and an output to mktime(), use 0 to
* avoid DST handling in mktime():
* - https://github.com/svaarala/duktape/issues/406
* - http://stackoverflow.com/questions/8558919/mktime-and-tm-isdst
Small variant; roughly 150 bytes smaller than the fast variant.
-> [ ... closure template env funcname ]
* Free the heap.
*
* Frees heap-related non-heap-tracked allocations such as the
* string intern table; then frees the heap allocated objects;
* and finally frees the heap structure itself. Reference counts
* and GC markers are ignored (and not updated) in this process,
* and finalizers won't be called.
*
* The heap pointer and heap object pointers must not be used
* after this call.
rescue no longer supported
res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK
_Pc2line
Sanity checks for string and token defines
number of escapes and line continuations (for directive prologue)
MakeTime
comment: XXX: this is possible without resorting to the value stack
label: code-design
ignored
NULL for lightfunc
lookup shorthands (note: assume context variable is named 'lex_ctx')
Other callbacks are optional.
truncated in case pass 3 needed
With constants and inner functions on value stack, we can now
* atomically finish the function 'data' buffer, bump refcounts,
* etc.
*
* Here we take advantage of the value stack being just a duk_tval
* array: we can just memcpy() the constants as long as we incref
* them afterwards.
DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
Leave 'getter' on stack
Called as a function, pattern has [[Class]] "RegExp" and
* flags is undefined -> return object as is.
Q...f
x < y
set exotic behavior only after we're done
comment: Default function to write a formatted log line. Writes to stderr,
* appending a newline to the log line.
*
* The argument is a buffer whose visible size contains the log message.
* This function should avoid coercing the buffer to a string to avoid
* string table traffic.
label: code-design
Current size is about 152 bytes.
comment: These base values are never used, but if the compiler doesn't know
* that DUK_ERROR() won't return, these are needed to silence warnings.
* On the other hand, scan-build will warn about the values not being
* used, so add a DUK_UNREF.
label: code-design
hash size relative to entries size: for value X, approx. hash_prime(e_size + e_size / X)
while repl
Note: we don't parse back exponent notation for anything else
* than radix 10, so this is not an ambiguous check (e.g. hex
* exponent values may have 'e' either as a significand digit
* or as an exponent separator).
*
* If the exponent separator occurs twice, 'e' will be interpreted
* as a digit (= 14) and will be rejected as an invalid decimal
* digit.
DUK_HEAPHDR_HAS_FINALIZED may be set if we're doing a
* refzero finalization and mark-and-sweep gets triggered
* during the finalizer.
Setup state. Initial ivalue is 'undefined'.
'object'
If we processed any debug messages breakpoints may have
* changed; restart execution to re-check active breakpoints.
1 1 1 <32 bits>
comment: Leading / trailing whitespace is sometimes accepted and
* sometimes not. After white space trimming, all valid input
* characters are pure ASCII.
label: code-design
patch in range count later
* If tracebacks are disabled, 'fileName' and 'lineNumber' are added
* as plain own properties. Since Error.prototype has accessors of
* the same name, we need to define own properties directly (cannot
* just use e.g. duk_put_prop_stridx). Existing properties are not
* overwritten in case they already exist.
0: toString
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small.
label: code-design
UTF-8 encoded bytes escaped as %xx%xx%xx... -> 3 * nbytes.
* Codepoint range is restricted so this is a slightly too large
* but doesn't matter.
lowest mantissa for this exponent
* Traceback handling when tracebacks disabled.
*
* The fileName / lineNumber stubs are now necessary because built-in
* data will include the accessor properties in Error.prototype. If those
* are removed for builds without tracebacks, these can also be removed.
* 'stack' should still be present and produce a ToString() equivalent:
* this is useful for user code which prints a stacktrace and expects to
* see something useful. A normal stacktrace also begins with a ToString()
* of the error so this makes sense.
all we need to know
ASSIGNMENT EXPRESSION
IdentityEscape
Must decrease recursion depth before returning.
note: mixing len into seed improves hashing when skipping
For join(), nargs is 1. For toLocaleString(), nargs is 0 and
* setting the top essentially pushes an undefined to the stack,
* thus defaulting to a comma separator.
Return with final function pushed on stack top.
Note: 'e' and 'E' are also accepted here.
'%c', passed concretely as int
thread resumed another thread (active but not running)
or a non-catching entry
next char
-> [... key val]
add F
comment: return a specific NaN (although not strictly necessary)
label: code-design
* Variant 1
global regexp: lastIndex updated on match
comment: pre-check how many atom copies we're willing to make (atom_copies not needed below)
label: requirement
Current size (not counting a dynamic buffer's "spare").
+2 = catcher value, catcher lj_type
parsing in "directive prologue", recognize directives
non-strict: non-deletable, writable
DUK_USE_64BIT_OPS
simulate alloc failure on every realloc (except when mark-and-sweep is running)
7
comment: alloc temp just in case, to update max temp
label: code-design
* An array must have a 'length' property (E5 Section 15.4.5.2).
* The special array behavior flag must only be enabled once the
* length property has been added.
*
* The internal property must be a number (and preferably a
* fastint if fastint support is enabled).
* Create a hstring and insert into the heap. The created object
* is directly garbage collectable with reference count zero.
*
* The caller must place the interned string into the stringtable
* immediately (without chance of a longjmp); otherwise the string
* is lost.
Note: this is correct even for default clause statements:
* they participate in 'fall-through' behavior even if the
* default clause is in the middle.
exposed, used by e.g. duk_bi_date.c
* Parsing of ints and floats
flags: "gi"
For TypedArrays 'undefined' return value is specified
* by ES6 (matches V8).
* Return target object
side effects
[ ... result ]
only objects have finalizers
interpret e.g. '0x' and '0xg' as a NaN (= parse error)
comment:
* Get and call the finalizer. All of this must be wrapped
* in a protected call, because even getting the finalizer
* may trigger an error (getter may throw one, for instance).
label: code-design
comment:
* String/JSON conversions
*
* Human readable conversions are now basically ISO 8601 with a space
* (instead of 'T') as the date/time separator. This is a good baseline
* and is platform independent.
*
* A shared native helper to provide many conversions. Magic value contains
* a set of flags. The helper provides:
*
* toString()
* toDateString()
* toTimeString()
* toLocaleString()
* toLocaleDateString()
* toLocaleTimeString()
* toUTCString()
* toISOString()
*
* Notes:
*
* - Date.prototype.toGMTString() and Date.prototype.toUTCString() are
* required to be the same Ecmascript function object (!), so it is
* omitted from here.
*
* - Date.prototype.toUTCString(): E5.1 specification does not require a
* specific format, but result should be human readable. The
* specification suggests using ISO 8601 format with a space (instead
* of 'T') separator if a more human readable format is not available.
*
* - Date.prototype.toISOString(): unlike other conversion functions,
* toISOString() requires a RangeError for invalid date values.
label: code-design
* Thread support.
bytecode start offset of the atom parsed in this loop
* (allows quantifiers to copy the atom bytecode)
temp copy, write back for next loop
char loop
basic platform types
we currently assume virtual properties are not configurable (as none of them are)
Stage 1: find highest preventing non-configurable entry (if any).
* When forcing, ignore non-configurability.
comment: XXX: keep property attributes or tweak them here?
* Properties will now be non-configurable even when they're
* normally configurable for the global object.
label: code-design
address
* Property already exists. Steps 5-6 detect whether any changes need
* to be made.
may be NULL
* Parse Ecmascript source InputElementDiv or InputElementRegExp
* (E5 Section 7), skipping whitespace, comments, and line terminators.
*
* Possible results are:
* (1) a token
* (2) a line terminator (skipped)
* (3) a comment (skipped)
* (4) EOF
*
* White space is automatically skipped from the current position (but
* not after the input element). If input has already ended, returns
* DUK_TOK_EOF indefinitely. If a parse error occurs, uses an DUK_ERROR()
* macro call (and hence a longjmp through current heap longjmp context).
* Comments and line terminator tokens are automatically skipped.
*
* The input element being matched is determined by regexp_mode; if set,
* parses a InputElementRegExp, otherwise a InputElementDiv. The
* difference between these are handling of productions starting with a
* forward slash.
*
* If strict_mode is set, recognizes additional future reserved words
* specific to strict mode, and refuses to parse octal literals.
*
* The matching strategy below is to (currently) use a six character
* lookup window to quickly determine which production is the -longest-
* matching one, and then parse that. The top-level if-else clauses
* match the first character, and the code blocks for each clause
* handle -all- alternatives for that first character. Ecmascript
* specification uses the "longest match wins" semantics, so the order
* of the if-clauses matters.
*
* Misc notes:
*
* * Ecmascript numeric literals do not accept a sign character.
* Consequently e.g. "-1.0" is parsed as two tokens: a negative
* sign and a positive numeric literal. The compiler performs
* the negation during compilation, so this has no adverse impact.
*
* * There is no token for "undefined": it is just a value available
* from the global object (or simply established by doing a reference
* to an undefined value).
*
* * Some contexts want Identifier tokens, which are IdentifierNames
* excluding reserved words, while some contexts want IdentifierNames
* directly. In the latter case e.g. "while" is interpreted as an
* identifier name, not a DUK_TOK_WHILE token. The solution here is
* to provide both token types: DUK_TOK_WHILE goes to 't' while
* DUK_TOK_IDENTIFIER goes to 't_nores', and 'slot1' always contains
* the identifier / keyword name.
*
* * Directive prologue needs to identify string literals such as
* "use strict" and 'use strict', which are sensitive to line
* continuations and escape sequences. For instance, "use\u0020strict"
* is a valid directive but is distinct from "use strict". The solution
* here is to decode escapes while tokenizing, but to keep track of the
* number of escapes. Directive detection can then check that the
* number of escapes is zero.
*
* * Multi-line comments with one or more internal LineTerminator are
* treated like a line terminator to comply with automatic semicolon
* insertion.
IEEE double is approximately 16 decimal digits; print a couple extra
* Resizing and hash behavior
String sanitizer which escapes ASCII control characters and a few other
* ASCII characters, passes Unicode as is, and replaces invalid UTF-8 with
* question marks. No errors are thrown for any input string, except in out
* of memory situations.
comment: Try to optimize X <op>= Y for reg-bound
* variables. Detect side-effect free RHS
* narrowly by seeing whether it emits code.
* If not, rewind the code emitter and overwrite
* the unnecessary temp reg load.
label: code-design
[obj key undefined]
comment: XXX: can be optimized for smaller footprint esp. on 32-bit environments
label: code-design
* isArray()
DUK_USE_HOBJECT_HASH_PART
trailing elisions?
* Simple commands
XXX: The TypeError is currently not applied to bound
* functions because the 'strict' flag is not copied by
* bind(). This may or may not be correct, the specification
* only refers to the value being a "strict mode Function
* object" which is ambiguous.
[ ... global val ] -> [ ... global ]
length in codepoints (must be E5 compatible)
The smallest fastint is no longer 48-bit when
* negated. Positive zero becames negative zero
* (cannot be represented) when negated.
Decode helper. Return zero on error.
XXX: specify array size, as we know it
comment: Numbers are normalized to big (network) endian. We can
* (but are not required) to use integer dvalues when there's
* no loss of precision.
*
* XXX: share check with other code; this check is slow but
* reliable and doesn't require careful exponent/mantissa
* mask tricks as in the fastint downgrade code.
label: code-design
* Use static helpers which can work with math.h functions matching
* the following signatures. This is not portable if any of these math
* functions is actually a macro.
*
* Typing here is intentionally 'double' wherever values interact with
* the standard library APIs.
1111 0xxx; 4 bytes
start array index of current MPUTARR set
cp == -1 (EOF) never matches and causes return value 0
comment: XXX: the handling of character range detection is a bit convoluted.
* Try to simplify and make smaller.
label: code-design
DUK_OP_CALL flags in A
* Shared helper for non-bound func lookup.
*
* Returns duk_hobject * to the final non-bound function (NULL for lightfunc).
Must be >= 0 and multiple of element size.
A stubbed built-in is useful for e.g. compilation torture testing with BCC.
Decode a plain string consisting entirely of identifier characters.
* Used to parse plain keys (e.g. "foo: 123").
note that we can't reliably pop anything here
[... put_value]
5
ref.value and ref.this_binding invalidated here
nret
object is a compiled function (duk_hcompiledfunction)
Push a new closure on the stack.
*
* Note: if fun_temp has NEWENV, i.e. a new lexical and variable declaration
* is created when the function is called, only outer_lex_env matters
* (outer_var_env is ignored and may or may not be same as outer_lex_env).
Need a short reg/const, does not have to be a mutable temp.
delete Duktape.modLoaded[resolved_id]
keep current valstack_top
Disabled until fixed, see above.
'message'
Just transfer the refcount from act->prev_caller to tv_caller,
* so no need for a refcount update. This is the expected case.
Suggested step-by-step method from documentation of RtlTimeToSecondsSince1970:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724928(v=vs.85).aspx
* Migrate array to start of entries if requested.
*
* Note: from an enumeration perspective the order of entry keys matters.
* Array keys should appear wherever they appeared before the array abandon
* operation.
0x70...0x7f
Maximum iteration count for computing UTC-to-local time offset when
* creating an Ecmascript time value from local parts.
comment: XXX: depend on available temps?
label: code-design
default case
%u; only 16 bits are guaranteed
MultiplicativeExpression
Trim white space (= allow leading and trailing whitespace)
* Call user provided module search function and build the wrapped
* module source code (if necessary). The module search function
* can be used to implement pure Ecmacsript, pure C, and mixed
* Ecmascript/C modules.
*
* The module search function can operate on the exports table directly
* (e.g. DLL code can register values to it). It can also return a
* string which is interpreted as module source code (if a non-string
* is returned the module is assumed to be a pure C one). If a module
* cannot be found, an error must be thrown by the user callback.
*
* Because Duktape.modLoaded[] already contains the module being
* loaded, circular references for C modules should also work
* (although expected to be quite rare).
One particular problem case is where an object has been
* queued for finalization but the finalizer hasn't yet been
* executed.
*
* Corner case: we're running in a finalizer for object X, and
* user code calls duk_push_heapptr() for X itself. In this
* case X will be in finalize_list, and we can detect the case
* by seeing that X's FINALIZED flag is set (which is done before
* the finalizer starts executing).
does not modify tv_x
26: setSeconds
patch pending jump and split
traceback depth doesn't take into account the filename/line
* special handling above (intentional)
DUK_USE_ERRTHROW || DUK_USE_ERRCREATE
only needed by debugger for now
Compute day number of the first day of a given year.
ignore_loop
* Begin
Output #1: resolved absolute name
and even number
* DELPROP: Ecmascript property deletion.
normal: implicit leading 1-bit
may throw an error
* Encoding constants, must match genbuiltins.py
'RegExp'
comment: XXX: do something to force a callstack grow/shrink, perhaps
* just a manual forced resize?
label: code-design
<<
comment: XXX: double evaluation of DUK_HCOMPILEDFUNCTION_GET_DATA()
label: code-design
ensure full memcmp() fits in while
unreachable
push operation normalizes NaNs
getter/setter
x == 0x00 (EOF) causes syntax_error
XXX: range assert
comment: XXX: move masks to js_ctx? they don't change during one
* fast path invocation.
label: code-design
flags: "i"
* Init stringtable: probe variant
Catches both doubles and cases where only one argument is a fastint
key coercion (unless already coerced above)
comment: XXX: There's quite a bit of overlap with buffer creation handling in
* duk_bi_buffer.c. Look for overlap and refactor.
label: code-design
Limit checks for bytecode byte size and line number.
The necessary #includes are in place in duk_config.h.
comment: XXX: this could be optimized
label: code-design
duk__handle_return() is guaranteed never to throw, except
* for potential out-of-memory situations which will then
* propagate out of the executor longjmp handler.
comment:
* XXX: if duk_handle_call() took values through indices, this could be
* made much more sensible. However, duk_handle_call() needs to fudge
* the 'this' and 'func' values to handle bound function chains, which
* is now done "in-place", so this is not a trivial change.
label: code-design
Number serialization has a significant impact relative to
* other fast path code, so careful fast path for fastints.
* Compiler intermediate values
*
* Intermediate values describe either plain values (e.g. strings or
* numbers) or binary operations which have not yet been coerced into
* either a left-hand-side or right-hand-side role (e.g. object property).
comment: Silence a few global unused warnings here.
label: code-design
-> [... arr num]
tzoffset seconds are dropped; 16 bits suffice for
* time offset in minutes
thread has yielded
Lightfuncs are always strict.
'\xffArgs'
comment: XXX: for array instances we could take a shortcut here and assume
* Array.prototype doesn't contain an array index property.
label: code-design
PropertyName -> IdentifierName | StringLiteral | NumericLiteral
-1 = top callstack entry, callstack[callstack_top - 1]
* -callstack_top = bottom callstack entry, callstack[0]
Further state-dependent pre-checks
E5 Section 8.12.8
is_decl
at least one activation, ours
s <- b^(-e) * 2
use p_src_base from now on
'taint' result as complex
no issues with memcmp() zero size, even if broken
* Disjunction struct: result of parsing a disjunction
* Emit initializers in sets of maximum max_init_pairs keys.
* Setter/getter is handled separately and terminates the
* current set of initializer values. Corner cases such as
* single value initializers do not have special handling now.
* E5 Section 7.3: CR LF is detected as a single line terminator for
* line numbers. Here we also detect it as a single line terminator
* token.
We don't need to sync back thr->ptr_curr_pc here because
* the bytecode executor always has a setjmp catchpoint which
* does that before errors propagate to here.
Previous entry was inside visited[], nothing to do.
comment: XXX: optimize temp reg use
label: code-design
toFixed()
Detect zero special case.
Number and (minimum) size of bigints in the nc_ctx structure.
We come here for actual aborts (like encountering .toJSON())
* but also for recursion/loop errors. Bufwriter size can be
* kept because we'll probably need at least as much as we've
* allocated so far.
* Preliminaries: trim, sign, Infinity check
*
* We rely on the interned string having a NUL terminator, which will
* cause a parse failure wherever it is encountered. As a result, we
* don't need separate pointer checks.
*
* There is no special parsing for 'NaN' in the specification although
* 'Infinity' (with an optional sign) is allowed in some contexts.
* Some contexts allow plus/minus sign, while others only allow the
* minus sign (like JSON.parse()).
*
* Automatic hex number detection (leading '0x' or '0X') and octal
* number detection (leading '0' followed by at least one octal digit)
* is done here too.
duk_unicode_idp_m_ids_noabmp[]
'(?:)'
* Process replacer/proplist (2nd argument to JSON.stringify)
may be a string constant
return total chars written excluding terminator
[ (builtin objects) name ]
new_free / size <= 1 / DIV <=> new_free <= size / DIV
This shouldn't happen; call sites should avoid looking up
* _Finalizer "through" a Proxy, but ignore if we come here
* with a Proxy to avoid finalizer re-entry.
[ ... holder name val enum obj_key ]
* Create a new function object based on a "template function" which contains
* compiled bytecode, constants, etc, but lacks a lexical environment.
*
* Ecmascript requires that each created closure is a separate object, with
* its own set of editable properties. However, structured property values
* (such as the formal arguments list and the variable map) are shared.
* Also the bytecode, constants, and inner functions are shared.
*
* See E5 Section 13.2 for detailed requirements on the function objects;
* there are no similar requirements for function "templates" which are an
* implementation dependent internal feature. Also see function-objects.rst
* for a discussion on the function instance properties provided by this
* implementation.
*
* Notes:
*
* * Order of internal properties should match frequency of use, since the
* properties will be linearly scanned on lookup (functions usually don't
* have enough properties to warrant a hash part).
*
* * The created closure is independent of its template; they do share the
* same 'data' buffer object, but the template object itself can be freed
* even if the closure object remains reachable.
E5 Section 11.13.1 (and others) step 4 never matches for prop writes -> no check
exit() afterwards to satisfy "noreturn"
string compare is the default (a bit oddly)
'%xx%xx...%xx', p points to char after first '%'
comment: XXX: need a toplain_ignore() which will only coerce a value to a temp
* register if it might have a side effect. Side-effect free values do not
* need to be coerced.
label: code-design
2^4 -> 1/16 = 6.25% spare
* reduce(), reduceRight()
* Macros for accessing size fields
* Resolve module identifier into canonical absolute form.
leap year: sunday, monday, ...
even after a detach and possible reattach
tval
comment: integer mixed endian not really used now
label: code-design
only advance if not tainted
tail insert: don't disturb head in case refzero is running
indexOf: NaN should cause pos to be zero.
* lastIndexOf: NaN should cause pos to be +Infinity
* (and later be clamped to len).
0.000...
leave stack unbalanced on purpose
[ ... func this <bound args> arg1 ... argN ]
Bitfield for each DUK_HBUFFEROBJECT_ELEM_xxx indicating which element types
* are compatible with a blind byte copy for the TypedArray set() method (also
* used for TypedArray constructor). Array index is target buffer elem type,
* bitfield indicates compatible source types. The types must have same byte
* size and they must be coercion compatible.
comment: Run fake finalizer. Avoid creating unnecessary garbage.
label: code-design
* Table for hex encoding bytes
[ ... buf func ] -> [ ... func ]
build result as: (r << 32) + s: start with (BD + E + F)
We only get here when doing non-standard JSON encoding
Without heap pointer compression duk_hbuffer_dynamic and duk_hbuffer_external
* have the same layout so checking for fixed vs. dynamic (or external) is enough.
[target] -> [enum]
Handle both full and partial slice (as long as covered).
envrec: (declarative) record is closed
comment: Log frontend shared helper, magic value indicates log level. Provides
* frontend functions: trace(), debug(), info(), warn(), error(), fatal().
* This needs to have small footprint, reasonable performance, minimal
* memory churn, etc.
label: code-design
XXX: bump preventcount by one for the duration of this call?
for
15: getUTCDay
need_bytes may be zero
register binding lookup is based on varmap (even in first pass)
prototype: the only internal property lifted outside 'e' as it is so central
3 entries actually needed below
end of input and last char has been processed
[ start length str ]
array
fast paths for space and tab
Significand ('f') padding.
comment: not needed
label: requirement
Regardless of whether property is found in entry or array part,
* it may have arguments exotic behavior (array indices may reside
* in entry part for abandoned / non-existent array parts).
add a new pending match jump for latest finished alternative
exclusive
DUK_USE_BUILTIN_INITJS
* If selftests enabled, run them as early as possible
ivalue/ispec helpers
* Determine the effective 'this' binding and coerce the current value
* on the valstack to the effective one (in-place, at idx_this).
*
* The current this value in the valstack (at idx_this) represents either:
* - the caller's requested 'this' binding; or
* - a 'this' binding accumulated from the bound function chain
*
* The final 'this' binding for the target function may still be
* different, and is determined as described in E5 Section 10.4.3.
*
* For global and eval code (E5 Sections 10.4.1 and 10.4.2), we assume
* that the caller has provided the correct 'this' binding explicitly
* when calling, i.e.:
*
* - global code: this=global object
* - direct eval: this=copy from eval() caller's this binding
* - other eval: this=global object
*
* Note: this function may cause a recursive function call with arbitrary
* side effects, because ToObject() may be called.
idx_this = idx_func + 1
comment: XXX: for real world code, could just ignore array inheritance
* and only look at array own properties.
label: code-design
not needed, as we exit right away
XXX: return type should probably be duk_size_t, or explicit checks are needed for
* maximum size.
relookup, may have changed
leading digit + fractions
Select appropriate escape format automatically, and set 'tmp' to a
* value encoding both the escape format character and the nybble count:
*
* (nybble_count << 16) | (escape_char1) | (escape_char2)
tc1 = true, tc2 = true
See comments below on MakeTime why these are volatile.
-> [ val obj val ]
Store lexer position, restoring if quantifier is invalid.
no need to compact since we already did that in duk__abandon_array_checked()
* (regardless of whether an array part existed or not.
marker; not actual tagged type
comment: XXX: expensive check (also shared elsewhere - so add a shared internal API call?)
label: code-design
For NaN/inf, the return value doesn't matter.
curr char
[ regexp string ]
comment: NULL not needed here
label: code-design
duk_pcall_prop() may itself throw an error, but we're content
* in catching the obvious errors (like toLogString() throwing an
* error).
special result value handling
[ ... Logger clog res ]
[... put_value varname]
intermediate join to avoid valstack overflow
ptr before mark-and-sweep
end-of-input breaks
reserve a jumpslot after instr before target spilling, used for NEXTENUM
a label site has been emitted by duk__parse_stmt() automatically
* (it will also emit the ENDLABEL).
* Variable access
comment: function: function must not be tail called
label: code-design
third arg: absolute index (to entire valstack) of idx_bottom of new activation
comment:
* HASPROP variant used internally.
*
* This primitive must never throw an error, callers rely on this.
* In particular, don't throw an error for prototype loops; instead,
* pretend like the property doesn't exist if a prototype sanity limit
* is reached.
*
* Does not implement proxy behavior: if applied to a proxy object,
* returns key existence on the proxy object itself.
label: code-design
'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
!DUK_USE_HSTRING_CLEN
DUK_ERR_EVAL: no macros needed
DUK_USE_PREFER_SIZE
Incref copies, keep originals.
object is a buffer object (duk_hbufferobject) (always exotic)
recheck that the property still exists
jump from true part to end
comment: XXX: fastint fast path would be very useful here
label: code-design
XXX: happens e.g. when evaluating: String(Buffer.prototype).
'name'
eat identifier
* Init stringtable: fixed variant
Copy values through direct validated reads and writes.
break matches always
* "length" maps to number of formals (E5 Section 13.2) for function
* declarations/expressions (non-bound functions). Note that 'nargs'
* is NOT necessarily equal to the number of arguments.
-1 for opcode
* Regexp instance check, bytecode check, input coercion.
*
* See E5 Section 15.10.6.
comment: hash part size or 0 if unused
label: code-design
comment: XXX: this duplicates functionality in duk_regexp.c where a similar loop is
* required anyway. We could use that BUT we need to update the regexp compiler
* 'nranges' too. Work this out a bit more cleanly to save space.
label: code-design
helper to insert a (non-string) heap object into heap allocated list
* Internal API calls which have (stack and other) semantics similar
* to the public API.
retval is directly usable
comment:
* Error throwing helpers
*
* The goal is to provide verbose and configurable error messages. Call
* sites should be clean in source code and compile to a small footprint.
* Small footprint is also useful for performance because small cold paths
* reduce code cache pressure. Adding macros here only makes sense if there
* are enough call sites to get concrete benefits.
label: code-design
digit count
* Hobject property set/get functionality.
*
* This is very central functionality for size, performance, and compliance.
* It is also rather intricate; see hobject-algorithms.rst for discussion on
* the algorithms and memory-management.rst for discussion on refcounts and
* side effect issues.
*
* Notes:
*
* - It might be tempting to assert "refcount nonzero" for objects
* being operated on, but that's not always correct: objects with
* a zero refcount may be operated on by the refcount implementation
* (finalization) for instance. Hence, no refcount assertions are made.
*
* - Many operations (memory allocation, identifier operations, etc)
* may cause arbitrary side effects (e.g. through GC and finalization).
* These side effects may invalidate duk_tval pointers which point to
* areas subject to reallocation (like value stack). Heap objects
* themselves have stable pointers. Holding heap object pointers or
* duk_tval copies is not problematic with respect to side effects;
* care must be taken when holding and using argument duk_tval pointers.
*
* - If a finalizer is executed, it may operate on the the same object
* we're currently dealing with. For instance, the finalizer might
* delete a certain property which has already been looked up and
* confirmed to exist. Ideally finalizers would be disabled if GC
* happens during property access. At the moment property table realloc
* disables finalizers, and all DECREFs may cause arbitrary changes so
* handle DECREF carefully.
*
* - The order of operations for a DECREF matters. When DECREF is executed,
* the entire object graph must be consistent; note that a refzero may
* lead to a mark-and-sweep through a refcount finalizer.
comment:
* Compact the closure, in most cases no properties will be added later.
* Also, without this the closures end up having unused property slots
* (e.g. in Duktape 0.9.0, 8 slots would be allocated and only 7 used).
* A better future solution would be to allocate the closure directly
* to correct size (and setup the properties directly without going
* through the API).
label: code-design
2^3 -> 1/8 = 12.5% min growth
* Reference count updates
*
* Note: careful manipulation of refcounts. The top is
* not updated yet, so all the activations are reachable
* for mark-and-sweep (which may be triggered by decref).
* However, the pointers are NULL so this is not an issue.
'hex'
borrowed label name
* String table algorithm: closed hashing with a probe sequence
*
* This is the default algorithm and works fine for environments with
* minimal memory constraints.
Longjmp state is kept clean in success path
Longjmp callers are required to sync-and-null thr->ptr_curr_pc
* before longjmp.
Would indicate corrupted lists.
Return invalid index; if caller uses this without checking
* in another API call, the index won't map to a valid stack
* entry.
comment: XXX: faster internal way to get this
label: code-design
old value is number: no refcount
Using classification has smaller footprint than direct comparison.
DUK_USE_ROM_GLOBAL_CLONE || DUK_USE_ROM_GLOBAL_INHERIT
leading byte of match string
comment:
* Formal argument list
*
* We don't check for prohibited names or for duplicate argument
* names here, becase we don't yet know whether the function will
* be strict. Function body parsing handles this retroactively.
label: code-design
canonicalized by compiler
[ source template closure this ]
initial index
5 heap flags
DUK_TOK_FUNCTION
exponent for 'f'
* Duktape includes (other than duk_features.h)
*
* The header files expect to be included in an order which satisfies header
* dependencies correctly (the headers themselves don't include any other
* includes). Forward declarations are used to break circular struct/typedef
* dependencies.
always 1 arg
helpers
* Single source autogenerated distributable for Duktape 1.8.0.
*
* Git commit 0a70d7e4c5227c84e3fed5209828973117d02849 (v1.8.0).
* Git branch v1.8-maintenance.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
ignore result
DUK_JMPBUF_H_INCLUDED
Newline allows module last line to contain a // comment.
'static'
* sort()
*
* Currently qsort with random pivot. This is now really, really slow,
* because there is no fast path for array parts.
*
* Signed indices are used because qsort() leaves and degenerate cases
* may use a negative offset.
extended types: compatible encoding
comment: not allowed in strict mode, regardless of whether resolves;
* in non-strict mode DELVAR handles both non-resolving and
* resolving cases (the specification description is a bit confusing).
label: code-design
valstack limit caller has check, prevents wrapping
Note that byte order doesn't affect this test: all bytes in
* 'test' will be 0xFF for two's complement.
Note: number has no explicit tag (in 8-byte representation)
* Calendar helpers
*
* Some helpers are used for getters and can operate on normalized values
* which can be represented with 32-bit signed integers. Other helpers are
* needed by setters and operate on un-normalized double values, must watch
* out for non-finite numbers etc.
Unlike year, the other parts fit into 16 bits so %d format
* is portable.
reg/const for case value
Equivalent year mapping, used to avoid DST trouble when platform
* may fail to provide reasonable DST answers for dates outside the
* ordinary range (e.g. 1970-2038). An equivalent year has the same
* leap-year-ness as the original year and begins on the same weekday
* (Jan 1).
*
* The year 2038 is avoided because there seem to be problems with it
* on some platforms. The year 1970 is also avoided as there were
* practical problems with it; an equivalent year is used for it too,
* which breaks some DST computations for 1970 right now, see e.g.
* test-bi-date-tzoffset-brute-fi.js.
signed integer encoding needed to work with UTF-8
Here val would be potentially invalid if we didn't make
* a value copy at the caller.
'&'
jump is inserted here (variant 3)
* Closing environment records.
*
* The environment record MUST be closed with the thread where its activation
* is. In other words (if 'env' is open):
*
* - 'thr' must match _env.thread
* - 'func' must match _env.callee
* - 'regbase' must match _env.regbase
*
* These are not looked up from the env to minimize code size.
*
* XXX: should access the own properties directly instead of using the API
resumee: [... initial_func undefined(= this) resume_value ]
ignore reclimit, not constructor
'\xffCallee'
is normalized
Variant for writing duk_tvals so that any heap allocated values are
* written out as tagged heap pointers.
Coerce like boolean
mark-and-sweep marking reached a recursion limit and must use multi-pass marking
[ (builtin objects) ]
comment: XXX: tv_func is not actually needed
label: requirement
* Source filename (or equivalent), for identifying thrown errors.
'__proto__'
comment: XXX: this is probably a useful shared helper: for a
* duk_hbufferobject, get a validated buffer pointer/length.
label: code-design
parent env is the prototype
get varenv for varname (callee's declarative lexical environment)
Use a new environment and there's an 'arguments' object.
* We need to initialize it right now.
The timevalue must be in valid Ecmascript range, but since a local
* time offset can be applied, we need to allow a +/- 24h leeway to
* the value. In other words, although the UTC time is within the
* Ecmascript range, the local part values can be just outside of it.
Note: can be safely scanned as bytes (undecoded)
========================================================================
No activation matches, use undefined for both .fileName and
* .lineNumber (matches what we do with a _Tracedata based
* no-match lookup.
also goes into flags
UnaryExpression
comment: XXX: return something more useful, so that caller can throw?
label: code-design
Tailcalls are handled by back-patching the TAILCALL flag to the
* already emitted instruction later (in return statement parser).
* Since A and C have a special meaning here, they cannot be "shuffled".
all virtual properties are non-configurable and non-writable
[ obj trap_result res_arr ]
comment:
* The string conversion here incorporates all the necessary Ecmascript
* semantics without attempting to be generic. nc_ctx->digits contains
* nc_ctx->count digits (>= 1), with the topmost digit's 'position'
* indicated by nc_ctx->k as follows:
*
* digits="123" count=3 k=0 --> 0.123
* digits="123" count=3 k=1 --> 1.23
* digits="123" count=3 k=5 --> 12300
* digits="123" count=3 k=-1 --> 0.0123
*
* Note that the identifier names used for format selection are different
* in Burger-Dybvig paper and Ecmascript specification (quite confusingly
* so, because e.g. 'k' has a totally different meaning in each). See
* documentation for discussion.
*
* Ecmascript doesn't specify any specific behavior for format selection
* (e.g. when to use exponent notation) for non-base-10 numbers.
*
* The bigint space in the context is reused for string output, as there
* is more than enough space for that (>1kB at the moment), and we avoid
* allocating even more stack.
label: code-design
depth check is done when printing an actual type
Preinc/predec for object properties.
* duk_re_range_callback for generating character class ranges.
*
* When ignoreCase is false, the range is simply emitted as is.
* We don't, for instance, eliminate duplicates or overlapping
* ranges in a character class.
*
* When ignoreCase is true, the range needs to be normalized through
* canonicalization. Unfortunately a canonicalized version of a
* continuous range is not necessarily continuous (e.g. [x-{] is
* continuous but [X-{] is not). The current algorithm creates the
* canonicalized range(s) space efficiently at the cost of compile
* time execution time (see doc/regexp.rst for discussion).
*
* Note that the ctx->nranges is a context-wide temporary value
* (this is OK because there cannot be multiple character classes
* being parsed simultaneously).
init function state: inits valstack allocations
comment: Currently about 7*152 = 1064 bytes. The space for these
* duk__bigints is used also as a temporary buffer for generating
* the final string. This is a bit awkard; a union would be
* more correct.
label: code-design
Check statement type based on the first token type.
*
* Note: expression parsing helpers expect 'curr_tok' to
* contain the first token of the expression upon entry.
comment:
* The 'in' operator requires an object as its right hand side,
* throwing a TypeError unconditionally if this is not the case.
*
* However, lightfuncs need to behave like fully fledged objects
* here to be maximally transparent, so we need to handle them
* here.
label: code-design
* Number-to-string conversion. The semantics of these is very tightly
* bound with the Ecmascript semantics required for call sites.
comment: XXX: inject test
label: code-design
comment: SCANBUILD: with suitable dmin/dmax limits 'd' is unused
label: code-design
0xff => 255 - 256 = -1; 0x80 => 128 - 256 = -128
DUK_USE_PARANOID_ERRORS
Does not assume that jump_pc contains a DUK_OP_JUMP previously; this is intentional
* to allow e.g. an INVALID opcode be overwritten with a JUMP (label management uses this).
A 32-bit unsigned integer formats to at most 32 digits (the
* worst case happens with radix == 2). Output the digits backwards,
* and use a memmove() to get them in the right place.
Without ROM objects "needs refcount update" == is heap allocated.
comment: Note: 'act' is dangerous here because it may get invalidate at many
* points, so we re-lookup it multiple times.
label: code-design
comment: XXX: Add a flag to reject an attempt to re-attach? Otherwise
* the detached callback may immediately reattach.
label: code-design
side effects -> don't use tv_x, tv_y after
[... enum]
if gap is empty, behave as if not given at all
When JX/JC not in use, the type mask above will avoid this case if needed.
DUK_TOK_LT
no value
* HASVAR: check identifier binding from a given environment record
* without traversing its parents.
*
* This primitive is not exposed to user code as such, but is used
* internally for e.g. declaration binding instantiation.
*
* See E5 Sections:
* 10.2.1.1.1 HasBinding(N)
* 10.2.1.2.1 HasBinding(N)
*
* Note: strictness has no bearing on this check. Hence we don't take
* a 'strict' parameter.
hash probe sequence
* Make the C call
DUK_USE_NONSTD_FUNC_STMT
has access to 'this' binding
comment: Create a temporary enumerator to get the (non-duplicated) key list;
* the enumerator state is initialized without being needed, but that
* has little impact.
label: code-design
comment: XXX: optimize for string inputs: no need to coerce to a buffer
* which makes a copy of the input.
label: code-design
initial size guess
Buffer writes are often integers.
env[funcname] = closure
Safe to call multiple times.
Default variants. Selection depends on speed/size preference.
* Concretely: with gcc 4.8.1 -Os x64 the difference in final binary
* is about +1kB for _FAST variants.
formatted result limited
[] -> [res]
may be NaN
'undefined', artifact of lookup
assume array part is comprehensive (contains all array indexed elements
* or none of them); hence no need to check the entries part here.
lj value1: value
pushes function template
Identifier, i.e. don't allow reserved words
comment: Parse an inner function, adding the function template to the current function's
* function table. Return a function number to be used by the outer function.
*
* Avoiding O(depth^2) inner function parsing is handled here. On the first pass,
* compile and register the function normally into the 'funcs' array, also recording
* a lexer point (offset/line) to the closing brace of the function. On the second
* pass, skip the function and return the same 'fnum' as on the first pass by using
* a running counter.
*
* An unfortunate side effect of this is that when parsing the inner function, almost
* nothing is known of the outer function, i.e. the inner function's scope. We don't
* need that information at the moment, but it would allow some optimizations if it
* were used.
label: code-design
[ arg toLogString ]
out_token->lineterm set by caller
note: any entries above the catchstack top are garbage and not zeroed
Error code also packs a tracedata related flag.
enumerator must have no keys deleted
Stack size increases or stays the same.
known to be number; in fact an integer
avail_bytes += need_bytes
comment: XXX: this illustrates that a C catchpoint implemented using duk_safe_call()
* is a bit heavy at the moment. The wrapper compiles to ~180 bytes on x64.
* Alternatives would be nice.
label: code-design
temp variable to pass constants and flags to shared code
char length of the atom parsed in this loop
-> [ ... fn x y ]
comment: ToBoolean() does not require any operations with side effects so
* we can do it efficiently. For footprint it would be better to use
* duk_js_toboolean() and then push+replace to the result slot.
label: code-design
-> [...]
topmost activation idx_retval is considered garbage, no need to init
* Delayed activation environment record initialization (for functions
* with NEWENV).
*
* The non-delayed initialization is handled by duk_handle_call().
ref.value, ref.this.binding invalidated here by getprop call
* Field accessor macros
[ ... buf ]
idx_base and idx_base+1 get completion value and type
integer number in range
comment: XXX: duk_xdef_prop_index_wec() would be more appropriate
* here but it currently makes some assumptions that might
* not hold (e.g. that previous property is not an accessor).
*
* Using duk_put_prop() works incorrectly with '__proto__'
* if the own property with that name has been deleted. This
* does not happen normally, but a clever reviver can trigger
* that, see complex reviver case in: test-bug-json-parse-__proto__.js.
label: code-design
Force interrupt right away if we're paused or in "checked mode".
* Step out is handled by callstack unwind.
check stack before interning (avoid hanging temp)
The extra (+4) is tight.
Send version identification and flush right afterwards. Note that
* we must write raw, unframed bytes here.
DUK_TOK_STATIC
No pointer compression because pointer is potentially outside of
* Duktape heap.
'null'
pc2line
always normalized
JUMP L1 omitted
comment: writable, not configurable
label: code-design
* Init/assert flags, copying them where appropriate. Some flags
* (like NEWENV) are processed separately below.
big endian
entry_top + 3
must match bytecode defines now; build autogenerate?
Although NAMEBINDING is not directly needed for using
* function instances, it's needed by bytecode dump/load
* so copy it too.
'.'
* Automatically generated by genbuiltins.py, do not edit!
* Debug connection read primitives
Note: when parsing a formal list in non-strict context, e.g.
* "implements" is parsed as an identifier. When the function is
* later detected to be strict, the argument list must be rechecked
* against a larger set of reserved words (that of strict mode).
* This is handled by duk__parse_func_body(). Here we recognize
* whatever tokens are considered reserved in current strictness
* (which is not always enough).
comment: XXX: optimize with more direct internal access
label: code-design
__proto__ setter returns 'undefined' on success unlike the
* setPrototypeOf() call which returns the target object.
0x00-0x0f
* String comparison (E5 Section 11.8.5, step 4), which
* needs to compare codepoint by codepoint.
*
* However, UTF-8 allows us to use strcmp directly: the shared
* prefix will be encoded identically (UTF-8 has unique encoding)
* and the first differing character can be compared with a simple
* unsigned byte comparison (which strcmp does).
*
* This will not work properly for non-xutf-8 strings, but this
* is not an issue for compliance.
DUK_TOK_BOR_EQ
Argument must be a string, e.g. a buffer is not allowed.
Note: val is a stable duk_tval pointer. The caller makes
* a value copy into its stack frame, so 'tv_val' is not subject
* to side effects here.
number of formal arguments
register, constant, or value
Note: intentionally allow leading zeroes here, as the
* actual parser will check for them.
Impose a maximum buffer length for now. Restricted artificially to
* ensure resize computations or adding a heap header length won't
* overflow size_t and that a signed duk_int_t can hold a buffer
* length. The limit should be synchronized with DUK_HSTRING_MAX_BYTELEN.
h_code: held in bw_code
* Forward declarations.
heap pointer comparison suffices
Note: 'count' is currently not adjusted by rounding (i.e. the
* digits are not "chopped off". That shouldn't matter because
* the digit position (absolute or relative) is passed on to the
* convert-and-push function.
comment: The variable environment for magic variable bindings needs to be
* given by the caller and recorded in the arguments object.
*
* See E5 Section 10.6, the creation of setters/getters.
*
* The variable environment also provides access to the callee, so
* an explicit (internal) callee property is not needed.
label: code-design
All components default to 0 except day-of-month which defaults
* to 1. However, because our internal day-of-month is zero-based,
* it also defaults to zero here.
Backtrack.
comment: XXX: code duplication
label: code-design
arg count
comment: Switch to caller's setjmp() catcher so that if an error occurs
* during error handling, it is always propagated outwards instead
* of causing an infinite loop in our own handler.
label: code-design
[ ... number ] -> [ ... string ]
'data' (and everything in it) is reachable through h_res now
Fast path.
called as a normal function: return new Date().toString()
------XX
must be computed after realloc
'join'
Get the value represented by an duk_ispec to a register or constant.
* The caller can control the result by indicating whether or not:
*
* (1) a constant is allowed (sometimes the caller needs the result to
* be in a register)
*
* (2) a temporary register is required (usually when caller requires
* the register to be safely mutable; normally either a bound
* register or a temporary register are both OK)
*
* (3) a forced register target needs to be used
*
* Bytecode may be emitted to generate the necessary value. The return
* value is either a register or a constant.
comment: XXX: FP_ZERO check can be removed, the else clause handles it
* correctly (preserving sign).
label: code-design
comment: XXX: the string shouldn't appear twice, but we now loop to the
* end anyway; if fixed, add a looping assertion to ensure there
* is no duplicate.
label: code-design
re-lookup first char on first loop
[ ... buf loop (proplist) ]
DUK_BUFOBJ_INT16ARRAY
No net refcount changes.
DUK_USE_DATE_FMT_STRFTIME
eat the right paren
comment: A straightforward 64-byte lookup would be faster
* and cleaner, but this is shorter.
label: code-design
For this to work, DATEMSK must be set, so this is not very
* convenient for an embeddable interpreter.
Fixed buffer; data follows struct, with proper alignment guaranteed by
* struct size.
comment:
* Call handling.
*
* Main functions are:
*
* - duk_handle_call_unprotected(): unprotected call to Ecmascript or
* Duktape/C function
* - duk_handle_call_protected(): protected call to Ecmascript or
* Duktape/C function
* - duk_handle_safe_call(): make a protected C call within current
* activation
* - duk_handle_ecma_call_setup(): Ecmascript-to-Ecmascript calls
* (not always possible), including tail calls and coroutine resume
*
* See 'execution.rst'.
*
* Note: setjmp() and local variables have a nasty interaction,
* see execution.rst; non-volatile locals modified after setjmp()
* call are not guaranteed to keep their value.
label: code-design
-1 if disjunction is complex, char length if simple
noblame_fileline
Backtrack to previous slash or start of buffer.
func limits
This is a rare property helper; it sets the global thrower (E5 Section 13.2.3)
* setter/getter into an object property. This is needed by the 'arguments'
* object creation code, function instance creation code, and Function.prototype.bind().
comment: Workaround for some exotic platforms where NAN is missing
* and the expression (0.0 / 0.0) does NOT result in a NaN.
* Such platforms use the global 'duk_computed_nan' which must
* be initialized at runtime. Use 'volatile' to ensure that
* the compiler will actually do the computation and not try
* to do constant folding which might result in the original
* problem.
label: code-design
A -> target register (A, A+1) for call setup
* (for DUK_OP_CSREGI, 'a' is indirect)
* B -> register containing target function (not type checked here)
Return the Buffer to allow chaining: b.fill(0x11).fill(0x22, 3, 5).toString()
comment: code_idx: not needed
label: requirement
keep func->h_funcs; inner functions are not reparsed to avoid O(depth^2) parsing
load factor min 25%
1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
Note: peek cannot currently trigger a detach
* so the dbg_detaching == 0 assert outside the
* loop is correct.
Assume interrupt init/counter are properly initialized here.
* Parse a case or default clause.
comment: XXX: when this error is caused by a nonexistent
* file given to duk_peval_file() or similar, the
* error message is not the best possible.
label: code-design
impose a reasonable exponent limit, so that exp
* doesn't need to get tracked using a bigint.
marker value; in E5 2^32-1 is not a valid array index (2^32-2 is highest valid)
maxval
valstack space allocated especially for proxy lookup which does a
* recursive property lookup
Accept ASCII strings which conform to identifier requirements
* as being emitted without key quotes. Since we only accept ASCII
* there's no need for actual decoding: 'p' is intentionally signed
* so that bytes >= 0x80 extend to negative values and are rejected
* as invalid identifier codepoints.
Careful overflow handling. When multiplying by 10:
* - 0x19999998 x 10 = 0xfffffff0: no overflow, and adding
* 0...9 is safe.
* - 0x19999999 x 10 = 0xfffffffa: no overflow, adding
* 0...5 is safe, 6...9 overflows.
* - 0x1999999a x 10 = 0x100000004: always overflow.
The Str(key, holder) operation.
*
* Stack policy: [ ... key ] -> [ ... ]
* Bitstream encoder
-> [ sep ToObject(this) len str sep ]
Decrement PC if that was requested, this requires a PC sync.
Array properties have exotic behavior but they are concrete,
* so no special handling here.
*
* Arguments exotic behavior (E5 Section 10.6, [[GetOwnProperty]]
* is only relevant as a post-check implemented below; hence no
* check here.
XXX: request a "last statement is terminal" from duk__parse_stmt() and duk__parse_stmts();
* we could avoid the last RETURN if we could ensure there is no way to get here
* (directly or via a jump)
[ ... key_obj key key flags ]
no side effects
INACTIVE: no activation, single function value on valstack
Equality may be OK but >length not. Checking
* this explicitly avoids some overflow cases
* below.
this cannot initiate a detach
done so that duk__mark_heaphdr() works correctly
if highest bit of a register number is set, it refers to a constant instead
comment: Slow variants, call to a helper to reduce code size.
* Can be used explicitly when size is always more important than speed.
label: code-design
DUK_USE_REFERENCE_COUNTING
Caller ensures space for at least DUK__JSON_MAX_ESC_LEN.
byte offset to buf
* The catch variable must be updated to reflect the new allocated
* register for the duration of the catch clause. We need to store
* and restore the original value for the varmap entry (if any).
comment: unused now
label: code-design
comment: stack[0] = callback
* stack[1] = thisArg
* stack[2] = object
* stack[3] = ToUint32(length) (unused, but avoid unnecessary pop)
* stack[4] = result array (or undefined)
label: code-design
still in prologue
heap->dbg_processing: keep on purpose to avoid debugger re-entry in detaching state
fixed-format termination conditions
DUK_TOK_ELSE
* Add line number to a compiler error.
array of function templates: [func1, offset1, line1, func2, offset2, line2]
* offset/line points to closing brace to allow skipping on pass 2
Ensure copy is covered by underlying buffers.
longjmp state
* Note:
*
* - Intentionally attempt (empty) match at char_offset == k_input->clen
*
* - Negative char_offsets have been eliminated and char_offset is duk_uint32_t
* -> no need or use for a negative check
Expression, terminates at a ')'
can't happen when keeping current stack size
Special handling for CALL/NEW/MPUTOBJ/MPUTARR shuffling.
* For each, slot B identifies the first register of a range
* of registers, so normal shuffling won't work. Instead,
* an indirect version of the opcode is used.
DUK_TOK_FOR
Miscellaneous.
-> [ ... retval ]
If a setter/getter is missing (undefined), the descriptor must
* still have the property present with the value 'undefined'.
-> [ timeval this ]
comment: Clean up stack
label: code-design
comment: dump all allocated entries, unused entries print as 'unused',
* note that these may extend beyond current 'length' and look
* a bit funny.
label: code-design
unwind to 'yield' caller
How much stack to require on entry to object/array decode
(e.g. k=3, digits=2 -> "12X")
Note: changing from writable to non-writable is OK
unwinds valstack, updating refcounts
For JX, expressing the whole unsigned 32-bit range matters.
r <- 2 * f
currently active breakpoints: NULL term, borrowed pointers
conversions, coercions, comparison, etc
[key val] -> [key]
use stack allocated buffer to ensure reachability in errors (e.g. intern error)
comment:
* Manually optimized double-to-fastint downgrade check.
*
* This check has a large impact on performance, especially for fastint
* slow paths, so must be changed carefully. The code should probably be
* optimized for the case where the result does not fit into a fastint,
* to minimize the penalty for "slow path code" dealing with fractions etc.
*
* At least on one tested soft float ARM platform double-to-int64 coercion
* is very slow (and sometimes produces incorrect results, see self tests).
* This algorithm combines a fastint compatibility check and extracting the
* integer value from an IEEE double for setting the tagged fastint. For
* other platforms a more naive approach might be better.
*
* See doc/fastint.rst for details.
label: code-design
* Misc support functions
ch is a literal character here or -1 if parsed entity was
* an escape such as "\s".
Code emission flags, passed in the 'opcode' field. Opcode + flags
* fit into 16 bits for now, so use duk_small_uint.t.
array of formal argument names (-> _Formals)
[ ... func this arg1 ... argN ]
* Simple atom
*
* If atom_char_length is zero, we'll have unbounded execution time for e.g.
* /()*x/.exec('x'). We can't just skip the match because it might have some
* side effects (for instance, if we allowed captures in simple atoms, the
* capture needs to happen). The simple solution below is to force the
* quantifier to match at most once, since the additional matches have no effect.
*
* With a simple atom there can be no capture groups, so no captures need
* to be reset.
key encountered as a getter
comment: XXX: typing
label: code-design
catches EOF (NUL)
'act' is no longer accessed, scanbuild fix
comment: XXX: Array size is known before and (2 * re_ctx.nsaved) but not taken
* advantage of now. The array is not compacted either, as regexp match
* objects are usually short lived.
label: code-design
Ecmascript activation + Duktape.Thread.yield() activation
comment: Presence of 'fun' is config based, there's a marginal performance
* difference and the best option is architecture dependent.
label: code-design
[ ... RegExp ]
DUK_TOK_DECREMENT
[ ... errhandler undefined errval ]
comment: The target for this LDCONST may need output shuffling, but we assume
* that 'pc_ldconst' will be the LDCONST that we can patch later. This
* should be the case because there's no input shuffling. (If there's
* no catch clause, this LDCONST will be replaced with a NOP.)
label: code-design
no wrap assuming h_bufobj->length is valid
Nominal size check.
register bound variables are non-configurable -> always false
-> [ obj trap handler target ]
reasonable output estimate
Note: DST adjustment is determined using UTC time.
* If 'd' is NaN, tzoffset will be 0.
* Character and charcode access
nargs == 2 so we can pass a callstack level to eval().
First pass parse is very lenient (e.g. allows '1.2.3') and extracts a
* string for strict number parsing.
normal valued properties
'\xffLexenv'
Module loading failed. Node.js will forget the module
* registration so that another require() will try to load
* the module again. Mimic that behavior.
comment: Note: for an accessor without getter, falling through to
* check for "caller" exotic behavior is unnecessary as
* "undefined" will never activate the behavior. But it does
* no harm, so we'll do it anyway.
label: code-design
e.g. 12.3 -> digits="123" k=2 -> 1.23e1
comment: XXX: there is room to use a shared helper here, many built-ins
* check the 'this' type, and if it's an object, check its class,
* then get its internal value, etc.
label: code-design
variable map for pass 2 (identifier -> register number or null (unmapped))
buffer pointer is to an externally allocated buffer
'Uint32Array'
'with'
comment:
* (Re)initialize the temporary byte buffer. May be called extra times
* with little impact.
label: code-design
callstack index of related activation
non-standard
may be safe, or non-safe depending on flags
activation prevents yield (native call or "new")
comment: XXX: expensive, but numconv now expects to see a string
label: code-design
DUK__FLD_VARINT; not relevant here
comment:
* Note: use indirect realloc variant just in case mark-and-sweep
* (finalizers) might resize this same buffer during garbage
* collection.
label: code-design
eat 'try'
1110 xxxx 10xx xxxx 10xx xxxx
Note: it's nice if size is 2^N (at least for 32-bit platforms).
Quite heavy assert: check valstack policy. Improper
* shuffle instructions can write beyond valstack_top/end
* so this check catches them in the act.
Expects 'this' at top of stack on entry.
The token in the switch has already been eaten here
currently all labels accept a break, so no explicit check for it now
[ arg result ]
got lineterm preceding non-whitespace, non-lineterm token
intentional overlap with earlier memzero
Allow exponent
'\xffSource'
read-only object, in code section
comment: Slice and accessor information.
*
* Because the underlying buffer may be dynamic, these may be
* invalidated by the buffer being modified so that both offset
* and length should be validated before every access. Behavior
* when the underlying buffer has changed doesn't need to be clean:
* virtual 'length' doesn't need to be affected, reads can return
* zero/NaN, and writes can be ignored.
*
* Note that a data pointer cannot be precomputed because 'buf' may
* be dynamic and its pointer unstable.
label: code-design
Shared object part.
comment: XXX: there are language sensitive rules for the ASCII range.
* If/when language/locale support is implemented, they need to
* be implemented here for the fast path. There are no context
* sensitive rules for ASCII range.
label: code-design
DUK_OP_RETURN flags in A
DUK_TOK_ADD
allocate to reg only (not const)
comment: not strictly necessary, but avoids "uninitialized variable" warnings
label: code-design
* Augment an error at throw time; allow a user error handler (if defined)
* to process/replace the error. The error to be augmented is at the
* stack top.
comment: This macro works when a regconst field is 9 bits, [0,0x1ff]. Adding
* DUK_LIKELY/DUK_UNLIKELY increases code footprint and doesn't seem to
* improve performance on x64 (and actually harms performance in some tests).
label: code-design
requested number of output digits; 0 = free-format
* Shared readfield and writefield methods
*
* The readfield/writefield methods need support for endianness and field
* types. All offsets are byte based so no offset shifting is needed.
Gap in array; check for inherited property,
* bail out if one exists. This should be enough
* to support gappy arrays for all practical code.
comment: XXX: could improve bufwriter handling to write multiple codepoints
* with one ensure call but the relative benefit would be quite small.
label: code-design
comment:
* Delete references to given hstring from the heap string cache.
*
* String cache references are 'weak': they are not counted towards
* reference counts, nor serve as roots for mark-and-sweep. When an
* object is about to be freed, such references need to be removed.
label: code-design
DUK_TOK_EOF
comment: XXX: signalling the need to shrink check (only if unwound)
label: code-design
XXX: duk_dup_unvalidated(ctx, -2) etc.
fill new entries with -unused- (required, gc reachable)
-> [ O toString O ]
accept anything, expect first value (EOF will be
* caught by key parsing below.
unknown, ignore
* Note: fmax() does not match the E5 semantics. E5 requires
* that if -any- input to Math.max() is a NaN, the result is a
* NaN. fmax() will return a NaN only if -both- inputs are NaN.
* Same applies to fmin().
*
* Note: every input value must be coerced with ToNumber(), even
* if we know the result will be a NaN anyway: ToNumber() may have
* side effects for which even order of evaluation matters.
[ ... v1 v2 name filename ]
!DUK_USE_PANIC_HANDLER
comment: XXX: inlined DECREF macro would be nice here: no NULL check,
* refzero queueing but no refzero algorithm run (= no pointer
* instability), inline code.
label: code-design
expected ival
comment: A 16-bit listlen makes sense with 16-bit heap pointers: there
* won't be space for 64k strings anyway.
label: code-design
* Finalize refcounts for heap elements just about to be freed.
* This must be done for all objects before freeing to avoid any
* stale pointer dereferences.
*
* Note that this must deduce the set of objects to be freed
* identically to duk__sweep_heap().
no sce, or sce scan not best
caller must have decref'd values above new_a_size (if that is necessary)
[ ... buf loop (proplist) (gap) ]
comment: XXX: duk_hobject_hasprop() would be correct for
* non-Proxy objects too, but it is about ~20-25%
* slower at present so separate code paths for
* Proxy and non-Proxy now.
label: code-design
Coercion may be needed, the helper handles that by pushing the
* tagged values to the stack.
checked by caller
'Int16Array'
res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits.
entry part must not contain any configurable properties, or
* writable properties (if is_frozen).
thread; minimizes argument passing
step 4.d
comment:
* The Number constructor uses ToNumber(arg) for number coercion
* (coercing an undefined argument to NaN). However, if the
* argument is not given at all, +0 must be used instead. To do
* this, a vararg function is used.
label: code-design
one operator (= assign)
no need to init reg, it will be undefined on entry
string objects must not created without internal value
eat backslash on entry
* Cached module check.
*
* If module has been loaded or its loading has already begun without
* finishing, return the same cached value ('exports'). The value is
* registered when module load starts so that circular references can
* be supported to some extent.
* Setup a preliminary activation and figure out nargs/nregs.
*
* Don't touch valstack_bottom or valstack_top yet so that Duktape API
* calls work normally.
comment: XXX: Rework to use an always-inline function?
label: code-design
comment:
* Common heap header
*
* All heap objects share the same flags and refcount fields. Objects other
* than strings also need to have a single or double linked list pointers
* for insertion into the "heap allocated" list. Strings are held in the
* heap-wide string table so they don't need link pointers.
*
* Technically, 'h_refcount' must be wide enough to guarantee that it cannot
* wrap (otherwise objects might be freed incorrectly after wrapping). This
* means essentially that the refcount field must be as wide as data pointers.
* On 64-bit platforms this means that the refcount needs to be 64 bits even
* if an 'int' is 32 bits. This is a bit unfortunate, and compromising on
* this might be reasonable in the future.
*
* Heap header size on 32-bit platforms: 8 bytes without reference counting,
* 16 bytes with reference counting.
label: code-design
We're a varargs function because we need to detect whether
* initialValue was given or not.
cannot be strict (never mapped variables)
Avoid recursive re-entry; enter when we're attached or
* detaching (to finish off the pending detach).
DUK_DEBUGGER_H_INCLUDED
Maximum length of CommonJS module identifier to resolve. Length includes
* both current module ID, requested (possibly relative) module ID, and a
* slash in between.
comment:
* Property count check. This is the only point where we ensure that
* we don't get more (allocated) property space that we can handle.
* There aren't hard limits as such, but some algorithms fail (e.g.
* finding next higher prime, selecting hash part size) if we get too
* close to the 4G property limit.
*
* Since this works based on allocation size (not actually used size),
* the limit is a bit approximate but good enough in practice.
label: code-design
This loop intentionally does not ensure characters are valid
* ([0-9a-fA-F]) because the hex decode call below will do that.
0 if no used entries
* Basic double / byte union memory layout.
copy values (no overlap even if to_ctx == from_ctx; that's not
* allowed now anyway)
Use match charlen instead of bytelen, just in case the input and
* match codepoint encodings would have different lengths.
comment: Count actually used array part entries and array minimum size.
* NOTE: 'out_min_size' can be computed much faster by starting from the
* end and breaking out early when finding first used entry, but this is
* not needed now.
label: code-design
if new_p == NULL, all of these pointers are NULL
-> [... obj retval/error]
[ ... holder key ] -> [ ... holder ]
'this' binding is just before current activation's bottom
comment:
* Error handling macros, assertion macro, error codes.
*
* There are three level of 'errors':
*
* 1. Ordinary errors, relative to a thread, cause a longjmp, catchable.
* 2. Fatal errors, relative to a heap, cause fatal handler to be called.
* 3. Panic errors, unrelated to a heap and cause a process exit.
*
* Panics are used by the default fatal error handler and by debug code
* such as assertions. By providing a proper fatal error handler, user
* code can avoid panics in non-debug builds.
label: code-design
Arguments can be: [ source? filename? &comp_args] so that
* nargs is 1 to 3. Call site encodes the correct nargs count
* directly into flags.
a
Allow leading zeroes (e.g. "0123" -> "123")
* Default clause.
d <- (quotient (* r B) s) (in range 0...B-1)
comment: XXX: There used to be a shared log buffer here, but it was removed
* when dynamic buffer spare was removed. The problem with using
* bufwriter is that, without the spare, the buffer gets passed on
* as an argument to the raw() call so it'd need to be resized
* (reallocated) anyway. If raw() call convention is changed, this
* could be made more efficient.
label: code-design
Commands initiated by debug client.
next loop requires a comma
0x40...0x4f
'string'
match == search string, by definition
comment: Shared handling for encode/decode argument. Fast path handling for
* buffer and string values because they're the most common. In particular,
* avoid creating a temporary string or buffer when possible.
label: code-design
32-bit x 11-bit = 43-bit, fits accurately into a double
Opcode only emitted by compiler when debugger
* support is enabled. Ignore it silently without
* debugger support, in case it has been loaded
* from precompiled bytecode.
eat closing brace
Behavior for constructor and non-constructor call is
* the same except for augmenting the created error. When
* called as a constructor, the caller (duk_new()) will handle
* augmentation; when called as normal function, we need to do
* it here.
Encode into a single opcode (18 bits can encode 1-2 bytes + length indicator)
defined(DUK_USE_DATE_NOW_WINDOWS) || defined(DUK_USE_DATE_TZO_WINDOWS)
without finally, the second jump slot is used to jump to end of stmt
slot B is a target (default: source)
fastint constants etc
* Unicode codepoints above U+FFFF are encoded as surrogate
* pairs here. This ensures that all CESU-8 codepoints are
* 16-bit values as expected in Ecmascript. The surrogate
* pairs always get a 3-byte encoding (each) in CESU-8.
* See: http://en.wikipedia.org/wiki/Surrogate_pair
*
* 20-bit codepoint, 10 bits (A and B) per surrogate pair:
*
* x = 0b00000000 0000AAAA AAAAAABB BBBBBBBB
* sp1 = 0b110110AA AAAAAAAA (0xd800 + ((x >> 10) & 0x3ff))
* sp2 = 0b110111BB BBBBBBBB (0xdc00 + (x & 0x3ff))
*
* Encoded into CESU-8:
*
* sp1 -> 0b11101101 (0xe0 + ((sp1 >> 12) & 0x0f))
* -> 0b1010AAAA (0x80 + ((sp1 >> 6) & 0x3f))
* -> 0b10AAAAAA (0x80 + (sp1 & 0x3f))
* sp2 -> 0b11101101 (0xe0 + ((sp2 >> 12) & 0x0f))
* -> 0b1011BBBB (0x80 + ((sp2 >> 6) & 0x3f))
* -> 0b10BBBBBB (0x80 + (sp2 & 0x3f))
*
* Note that 0x10000 must be subtracted first. The code below
* avoids the sp1, sp2 temporaries which saves around 20 bytes
* of code.
Duktape.modLoaded
We could do this operation without caller updating bw_ctx->ptr,
* but by writing it back here we can share code better.
Note: if encoding ends by hitting end of input, we don't check that
* the encoding is valid, we just assume it is.
comment: XXX: call method tail call?
label: code-design
w.../
always provideThis=true
Note: only numbered indices are relevant, so arr_idx fast reject
* is good (this is valid unless there are more than 4**32-1 arguments).
* Thread state and calling context checks
token type (with reserved word identification)
comment: XXX: there's no explicit recursion bound here now. For the average
* qsort recursion depth O(log n) that's not really necessary: e.g. for
* 2**32 recursion depth would be about 32 which is OK. However, qsort
* worst case recursion depth is O(n) which may be a problem.
label: code-design
verified at beginning
comment: Fall back to the initial (original) Object.toString(). We don't
* currently have pointers to the built-in functions, only the top
* level global objects (like "Array") so this is now done in a bit
* of a hacky manner. It would be cleaner to push the (original)
* function and use duk_call_method().
label: code-design
XXX: duk_push_uint_string()
Built-in providers
comment: XXX: could add flags for "is valid CESU-8" (Ecmascript compatible strings),
* "is valid UTF-8", "is valid extended UTF-8" (internal strings are not,
* regexp bytecode is), and "contains non-BMP characters". These are not
* needed right now.
label: code-design
pop final_cons
comment: When ptr == NULL, the format argument is unused.
label: code-design
To convert a heap stridx to a token number, subtract
* DUK_STRIDX_START_RESERVED and add DUK_TOK_START_RESERVED.
ANSI C typing
These pointers are at the start of the struct so that they pack
* nicely. Mixing pointers and integer values is bad on some
* platforms (e.g. if int is 32 bits and pointers are 64 bits).
1=little endian
* "IdentifierStart" production check.
* Compiler state
comment: XXX: this is awkward as we use an internal method which doesn't handle
* extensibility etc correctly. Basically we'd want to do a [[DefineOwnProperty]]
* or Object.defineProperty() here.
label: code-design
comment:
* Entries part is a bit more complex
label: code-design
* On first pass, perform actual parsing. Remember valstack top on entry
* to restore it later, and switch to using a new function in comp_ctx.
nop: insert top to top
h_match is borrowed, remains reachable through match_obj
0 = uppercase, 32 = lowercase (= 'a' - 'A')
catch jump
3: toLocaleString
not reachable
leave 'cat' as top catcher (also works if catchstack exhausted)
+1 for opcode
'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
Not halfway, round to nearest.
remove in_val
idx_argbase
Strict by default.
fixed precision and zero padding would be required
Ensuring (reserving) space.
flags: "m"
'setPrototypeOf'
return 1 to allow callers to tail call
* Not found (even in global object)
* Reallocate memory with garbage collection, using a callback to provide
* the current allocated pointer. This variant is used when a mark-and-sweep
* (e.g. finalizers) might change the original pointer.
'number'
label id allocation (running counter)
comment:
* Shared error messages: declarations and macros
*
* Error messages are accessed through macros with fine-grained, explicit
* error message distinctions. Concrete error messages are selected by the
* macros and multiple macros can map to the same concrete string to save
* on code footprint. This allows flexible footprint/verbosity tuning with
* minimal code impact. There are a few limitations to this approach:
* (1) switching between plain messages and format strings doesn't work
* conveniently, and (2) conditional strings are a bit awkward to handle.
*
* Because format strings behave differently in the call site (they need to
* be followed by format arguments), they have a special prefix (DUK_STR_FMT_
* and duk_str_fmt_).
*
* On some compilers using explicit shared strings is preferable; on others
* it may be better to use straight literals because the compiler will combine
* them anyway, and such strings won't end up unnecessarily in a symbol table.
label: code-design
comment: XXX: how to figure correct size?
label: code-design
comment:
* See the following documentation for discussion:
*
* doc/execution.rst: control flow details
*
* Try, catch, and finally "parts" are Blocks, not Statements, so
* they must always be delimited by curly braces. This is unlike e.g.
* the if statement, which accepts any Statement. This eliminates any
* questions of matching parts of nested try statements. The Block
* parsing is implemented inline here (instead of calling out).
*
* Finally part has a 'let scoped' variable, which requires a few kinks
* here.
label: code-design
op_flags
# argument registers target function wants (< 0 => never for ecma calls)
Different calling convention than above used because the helper
* is shared.
equality not actually possible
comment: XXX: make this lenience dependent on flags or strictness?
label: code-design
[ ... func this arg1 ... argN envobj ]
32: setDate
slot C is a target (default: source)
-> [ ... lval rval new_rval ]
Sealed and frozen objects cannot gain any more properties,
* so this is a good time to compact them.
Parse a single variable declaration (e.g. "i" or "i=10"). A leading 'var'
* has already been eaten. These is no return value in 'res', it is used only
* as a temporary.
*
* When called from 'for-in' statement parser, the initializer expression must
* not allow the 'in' token. The caller supply additional expression parsing
* flags (like DUK__EXPR_FLAG_REJECT_IN) in 'expr_flags'.
*
* Finally, out_rc_varname and out_reg_varbind are updated to reflect where
* the identifier is bound:
*
* If register bound: out_reg_varbind >= 0, out_rc_varname == 0 (ignore)
* If not register bound: out_reg_varbind < 0, out_rc_varname >= 0
*
* These allow the caller to use the variable for further assignment, e.g.
* as is done in 'for-in' parsing.
sanity
deal with negative values
Unlike for negative arguments, some call sites
* want length to be clamped if it's positive.
create bound function object
maximum bytecode copies for {n,m} quantifiers
[ ... lval rval ]
comment: Note: Boolean prototype's internal value property is not writable,
* but duk_xdef_prop_stridx() disregards the write protection. Boolean
* instances are immutable.
*
* String and buffer special behaviors are already enabled which is not
* ideal, but a write to the internal value is not affected by them.
label: code-design
use duk_double_union as duk_tval directly
[ ... obj finalizer obj heapDestruct ] -> [ ... obj retval ]
comment:
* Assignments are right associative, allows e.g.
* a = 5;
* a += b = 9; // same as a += (b = 9)
* -> expression value 14, a = 14, b = 9
*
* Right associativiness is reflected in the BP for recursion,
* "-1" ensures assignment operations are allowed.
*
* XXX: just use DUK__BP_COMMA (i.e. no need for 2-step bp levels)?
label: code-design
don't increase 'count'
module.exports = exports
simulate alloc failure on every alloc (except when mark-and-sweep is running)
must relookup act in case of side effects
comment: XXX: take advantage of val being unsigned, no need to mask
label: code-design
status booleans
identifier handling
duk_unicode_caseconv_lc[]
DUK_TOK_PROTECTED
target
reserved words: future reserved words
Ensure space for maximum multi-character result; estimate is overkill.
* Getters.
*
* Implementing getters is quite easy. The internal time value is either
* NaN, or represents milliseconds (without fractions) from Jan 1, 1970.
* The internal time value can be converted to integer parts, and each
* part will be normalized and will fit into a 32-bit signed integer.
*
* A shared native helper to provide all getters. Magic value contains
* a set of flags and also packs the date component index argument. The
* helper provides:
*
* getFullYear()
* getUTCFullYear()
* getMonth()
* getUTCMonth()
* getDate()
* getUTCDate()
* getDay()
* getUTCDay()
* getHours()
* getUTCHours()
* getMinutes()
* getUTCMinutes()
* getSeconds()
* getUTCSeconds()
* getMilliseconds()
* getUTCMilliseconds()
* getYear()
*
* Notes:
*
* - Date.prototype.getDate(): 'date' means day-of-month, and is
* zero-based in internal calculations but public API expects it to
* be one-based.
*
* - Date.prototype.getTime() and Date.prototype.valueOf() have identical
* behavior. They have separate function objects, but share the same C
* function (duk_bi_date_prototype_value_of).
* Pre resize assertions.
In-place unary operation.
Note: expect that caller has already eaten the left paren
implicit leading one
comment:
* Array index and length
*
* Array index: E5 Section 15.4
* Array length: E5 Section 15.4.5.1 steps 3.c - 3.d (array length write)
*
* The DUK_HSTRING_GET_ARRIDX_SLOW() and DUK_HSTRING_GET_ARRIDX_FAST() macros
* call duk_js_to_arrayindex_string_helper().
label: code-design
* Internal helpers for managing object 'length'
biased exp == 0 -> denormal, exp -1022
0xdeadbeef in decimal
strings up to the this length are not cached
DUK_HEAPHDR_H_INCLUDED
[ ... key_obj key val ]
Checking callability of the immediate target
* is important, same for constructability.
* Checking it for functions down the bound
* function chain is not strictly necessary
* because .bind() should normally reject them.
* But it's good to check anyway because it's
* technically possible to edit the bound function
* chain via internal keys.
comment:
* Three possible element formats:
* 1) PropertyName : AssignmentExpression
* 2) get PropertyName () { FunctionBody }
* 3) set PropertyName ( PropertySetParameterList ) { FunctionBody }
*
* PropertyName can be IdentifierName (includes reserved words), a string
* literal, or a number literal. Note that IdentifierName allows 'get' and
* 'set' too, so we need to look ahead to the next token to distinguish:
*
* { get : 1 }
*
* and
*
* { get foo() { return 1 } }
* { get get() { return 1 } } // 'get' as getter propertyname
*
* Finally, a trailing comma is allowed.
*
* Key name is coerced to string at compile time (and ends up as a
* a string constant) even for numeric keys (e.g. "{1:'foo'}").
* These could be emitted using e.g. LDINT, but that seems hardly
* worth the effort and would increase code size.
label: code-design
keep func->h_argnames; it is fixed for all passes
num entries of new func at entry
One digit octal escape, digit validated.
Use result value as is.
step 15.a
formal arg limits
Use the approach described in "Remarks" of FileTimeToLocalFileTime:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724277(v=vs.85).aspx
[ offset noAssert ], when ftype != DUK__FLD_VARINT
bufwriter for temp accumulation
normal comparison; known:
* - both x and y are not NaNs (but one of them can be)
* - both x and y are not zero (but one of them can be)
* - x and y may be denormal or infinite
-1 if invalid
convenience helpers
* Use Object.defineProperty() helper for the actual operation.
Ensure compact use of temps.
* Object handling: property access and other support functions.
allocated from valstack (fixed buffer)
Unlike most built-ins, the internal [[PrimitiveValue]] of a Date
* is mutable.
DUK_TVAL_H_INCLUDED
* Retry with several GC attempts. Initial attempts are made without
* emergency mode; later attempts use emergency mode which minimizes
* memory allocations forcibly.
last component
lexing (tokenization) state (contains two valstack slot indices)
* Update an existing property of the base object.
update length (curr points to length, and we assume it's still valid)
in-place setup
Currently all built-in native functions are strict.
* duk_push_c_function() now sets strict flag, so
* assert for it.
The lo/hi indices may be crossed and hi < 0 is possible at entry.
* Init compilation context
add E
'\xffThread'
Must use memmove() because copy area may overlap (source and target
* buffer may be the same, or from different slices.
* Special name handling
If function creation fails due to out-of-memory, the data buffer
* pointer may be NULL in some cases. That's actually possible for
* GC code, but shouldn't be possible here because the incomplete
* function will be unwound from the value stack and never instantiated.
A -> register of target object
* B -> first register of key/value pair list
* C -> number of key/value pairs
comment: XXX: this is a major target for size optimization
label: code-design
'constructor' property for all built-in objects (which have it) has attributes:
* [[Writable]] = true,
* [[Enumerable]] = false,
* [[Configurable]] = true
XXX: check num_args
pop 'name'
Here 'p' always points to the start of a term.
*
* We can also unconditionally reset q_last here: if this is
* the last (non-empty) term q_last will have the right value
* on loop exit.
* All done, switch properties ('p') allocation to new one.
* Duktape.Buffer, Node.js Buffer, and Khronos/ES6 TypedArray built-ins
decode '%xx' to '%xx' if decoded char in reserved set
comment: XXX: Finalizer lookup should traverse the prototype chain (to allow
* inherited finalizers) but should not invoke accessors or proxy object
* behavior. At the moment this lookup will invoke proxy behavior, so
* caller must ensure that this function is not called if the target is
* a Proxy.
label: code-design
Maximum number of breakpoints. Only breakpoints that are set are
* consulted so increasing this has no performance impact.
any other printable -> as is
Called by duk_hstring.h macros
step type: none, step into, step over, step out
comment: XXX: faster implementation
label: code-design
cleared before entering catch part
Clamp an input byte length (already assumed to be within the nominal
* duk_hbufferobject 'length') to the current dynamic buffer limits to
* yield a byte length limit that's safe for memory accesses. This value
* can be invalidated by any side effect because it may trigger a user
* callback that resizes the underlying buffer.
comment: XXX: ignored now
label: code-design
comment:
* Tagged type definition (duk_tval) and accessor macros.
*
* Access all fields through the accessor macros, as the representation
* is quite tricky.
*
* There are two packed type alternatives: an 8-byte representation
* based on an IEEE double (preferred for compactness), and a 12-byte
* representation (portability). The latter is needed also in e.g.
* 64-bit environments (it usually pads to 16 bytes per value).
*
* Selecting the tagged type format involves many trade-offs (memory
* use, size and performance of generated code, portability, etc),
* see doc/types.rst for a detailed discussion (especially of how the
* IEEE double format is used to pack tagged values).
*
* NB: because macro arguments are often expressions, macros should
* avoid evaluating their argument more than once.
label: code-design
* Automatically generated by extract_caseconv.py, do not edit!
* Support functions for duk_heap.
DUK_HCOMPILEDFUNCTION_H_INCLUDED
write_to_array_part:
comment:
* Parse variant 1 or 2. The first part expression (which differs
* in the variants) has already been parsed and its code emitted.
*
* reg_temps + 0: unused
* reg_temps + 1: unused
label: code-design
E5 Section 15.5.5.1
own pointer
Note: although there is no 'undefined' literal, undefined
* values can occur during compilation as a result of e.g.
* the 'void' operator.
Note: this may cause a corner case situation where a finalizer
* may see a currently reachable activation whose 'func' is NULL.
# total registers target function wants on entry (< 0 => never for ecma calls)
bytecode has a stable pointer
* Thread builtins
overwrite str1
comment: XXX: exposed duk_debug_read_buffer
label: code-design
DUK_JS_BYTECODE_H_INCLUDED
Convert a duk_tval number (caller checks) to a 32-bit index. Returns
* DUK__NO_ARRAY_INDEX if the number is not whole or not a valid array
* index.
SCANBUILD: scan-build produces a NULL pointer dereference warning
* below; it never actually triggers because holder is actually never
* NULL.
Set up pointers to the new property area: this is hidden behind a macro
* because it is memory layout specific.
no need for refcount update
comment: Zero 'count' is also allowed to make call sites easier.
* Arithmetic in bytes generates better code in GCC.
label: code-design
compiler ensures this
[... old_result result] -> [... result]
comment: This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
label: code-design
At the moment Buffer(<str>) will just use the string bytes as
* is (ignoring encoding), so we return the string length here
* unconditionally.
* concat()
different memory layout, alloc size, and init
t2 = (* (+ r m+) B)
exponent non-negative (and thus not minimum exponent)
default: NULL, length 0
env is closed, should be missing _Callee, _Thread, _Regbase
comment: The E5.1 algorithm checks whether or not a decoded codepoint
* is below 0x80 and perhaps may be in the "reserved" set.
* This seems pointless because the single byte UTF-8 case is
* handled separately, and non-shortest encodings are rejected.
* So, 'cp' cannot be below 0x80 here, and thus cannot be in
* the reserved set.
label: code-design
force_flag
Used for minimal 'const': initializer required.
* Table for base-64 encoding
Note: no allocation pressure, no need to check refcounts etc
args incorrect
write on next loop
* Helper to format a time value into caller buffer, used by logging.
* 'out_buf' must be at least DUK_BI_DATE_ISO8601_BUFSIZE long.
comment: XXX: the returned value is exotic in ES6, but we use a
* simple object here with no prototype. Without a prototype,
* [[DefaultValue]] coercion fails which is abit confusing.
* No callable check/handling in the current Proxy subset.
label: code-design
2nd related value (type specific)
comment: Extraop arithmetic opcodes must have destination same as
* first source. If second source matches destination we need
* a temporary register to avoid clobbering the second source.
*
* XXX: change calling code to avoid this situation in most cases.
label: code-design
cannot grow
0=indexOf, 1=lastIndexOf
bump up "allocated" reg count, just in case
Strict standard behavior, ignore trailing elements for
* result 'length'.
For errors a string coerced result is most informative
* right now, as the debug client doesn't have the capability
* to traverse the error object.
DUK_TOK_IF
comment: NOTE: This is a bit fragile. It's important to ensure that
* duk_debug_process_messages() never throws an error or
* act->curr_pc will never be reset.
label: code-design
Working with the pointer and current size.
object has any exotic behavior(s)
DUK_USE_STRTAB_PROBE
written by a previous RESUME handling
comment:
* Macro support functions (use only macros in calling code)
label: code-design
string 1 of token (borrowed, stored to ctx->slot1_idx)
comment: XXX: more accurate?
label: code-design
Note: assume array part is comprehensive, so that either
* the write goes to the array part, or we've abandoned the
* array above (and will not come here).
level string
sufficient for keeping temp reg numbers in check
All other object types.
comment: Flip highest bit of each byte which changes
* the bit pattern 10xxxxxx into 00xxxxxx which
* allows an easy bit mask test.
label: test
mixed endian
min_new_size
length in bytes (not counting NUL term)
No finalizers for ROM objects
last element that was left in the heap
compact; no need to seal because object is internal
0x90...0x9f
const flag for C
[... obj] -> [...]
number of pairs in current MPUTOBJ set
escaped NonEscapeCharacter
Module id requested
Empty searchstring always matches; cpos must be clamped here.
* (If q_blen were < 0 due to clamped coercion, it would also be
* caught here.)
Never executed if new size is smaller.
'protected'
because arg count is 1
'if'
finally free the struct itself
!DUK_USE_PARANOID_ERRORS
Array or Array-like
coerce towards zero
must not be extensible
comment: We've ensured space for one escaped input; then
* bail out and recheck (this makes escape handling
* quite slow but it's uncommon).
label: code-design
mark-and-sweep: finalizable (on current pass)
[ ... replacer match [captures] match_char_offset input ]
DUK_OP_TRYCATCH flags in A
single string token
Use byte copy.
Most common cases first.
no point in supporting encodings of 5 or more bytes
'|'
use_prev_pc
We need 'nbytes' even for a failed offset; return value must be
* (offset + nbytes) even when write fails due to invalid offset.
Return value handling.
Enable DUKFUNC exotic behavior once properties are set up.
duk_bi_duk_object_yield() and duk_bi_duk_object_resume() ensure all of these are met
Assumes that caller has normalized NaNs, otherwise trouble ahead.
0x00: finish (not part of number)
* 0x01: continue
comment: this is relatively expensive
label: code-design
num_values and temp_start reset at top of outer loop
comment:
* Panic error
*
* Panic errors are not relative to either a heap or a thread, and cause
* DUK_PANIC() macro to be invoked. Unless a user provides DUK_USE_PANIC_HANDLER,
* DUK_PANIC() calls a helper which prints out the error and causes a process
* exit.
*
* The user can override the macro to provide custom handling. A macro is
* used to allow the user to have inline panic handling if desired (without
* causing a potentially risky function call).
*
* Panics are only used in debug code such as assertions, and by the default
* fatal error handler.
label: code-design
specific assert for wrapping
Could also rely on native sprintf(), but it will handle
* values like NaN, Infinity, -0, exponent notation etc in
* a JSON-incompatible way.
[ arg1 ... argN this loggerLevel loggerName buffer 'raw' buffer ]
comment: Function declaration for global/eval code is emitted even
* for duplicates, because of E5 Section 10.5, step 5.e of
* E5.1 (special behavior for variable bound to global object).
*
* DECLVAR will not re-declare a variable as such, but will
* update the binding value.
label: code-design
bits 2...5: type
As a first approximation, buffer values are coerced to strings
* for addition. This means that adding two buffers currently
* results in a string.
must be ecmascript
'toUTCString'
Note: no need to re-lookup tv, conversion is side effect free
require.id of current module
low 32 bits is complete
time when status/peek was last done (Date-based rate limit)
[obj key value desc value]
'caller'
rbp_flags
'data'
'type'
comment: XXX: shared strings
label: code-design
-> [ ... source ]
default value
output 3 bytes from 't'
Special flags checks. Since these strings are always
* reachable and a string cannot appear twice in the string
* table, there's no need to check/set these flags elsewhere.
* The 'internal' flag is set by string intern code.
loop iterator init and limit changed from standard algorithm
enum_flags
'++' or '--' in a post-increment/decrement position,
* and a LineTerminator occurs between the operator and
* the preceding expression. Force the previous expr
* to terminate, in effect treating e.g. "a,b\n++" as
* "a,b;++" (= SyntaxError).
by default, use caller's environment
* Note: we currently assume that the setjmp() catchpoint is
* not re-entrant (longjmp() cannot be called more than once
* for a single setjmp()).
*
* See doc/code-issues.rst for notes on variable assignment
* before and after setjmp().
value resides in 'valstack_idx'
Verbose errors with key/value summaries (non-paranoid) or without key/value
* summaries (paranoid, for some security sensitive environments), the paranoid
* vs. non-paranoid distinction affects only a few specific errors.
'typeof' must handle unresolvable references without throwing
* a ReferenceError (E5 Section 11.4.3). Register mapped values
* will never be unresolvable so special handling is only required
* when an identifier is a "slow path" one.
free inner references (these exist e.g. when external
* strings are enabled)
The 'this' after 'sep' will get ToString() coerced by
* duk_join() automatically. We don't want to do that
* coercion when providing .fileName or .lineNumber (GH-254).
surrogate pairs get encoded here
11: getUTCMonth
comment: XXX: any chance of unifying this with the 'length' key handling?
label: code-design
assert just a few critical flags
correction
default to false
* Stack slice primitives
Length in elements: take into account shift, but
* intentionally don't check the underlying buffer here.
[key val] -> []
DUK_USE_STRHASH_DENSE
* Get old and new length
clipped codepoint
h_new_proto may be NULL
-> [ ... errhandler errval ]
this is the case for normalized numbers
flags: "gim"
Starting from this round, use emergency mode
* for mark-and-sweep.
The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
* Found existing own or inherited plain property, but original
* base is a primitive value.
optional callstack level
e.g. duk_push_string_file_raw() pushed undefined
Assume that either all memory funcs are NULL or non-NULL, mixed
* cases will now be unsafe.
'error'
don't throw for prototype loop
(< (* r 2) s)
[ thisArg arg1 ... argN func ] (thisArg+args == nargs total)
Note: not set in template (has no "prototype")
unreferenced w/o asserts
if (is_repl_func)
precision:shortest
don't resize stringtable (but may sweep it); needed during stringtable resize
Write curr_pc back for the debugger.
Note: duk__dec_req_stridx() backtracks one char
'length'
-> [ ... val retval ]
Object property access
* The specification uses RegExp [[Match]] to attempt match at specific
* offsets. We don't have such a primitive, so we use an actual RegExp
* and tweak lastIndex. Since the RegExp may be non-global, we use a
* special variant which forces global-like behavior for matching.
3
Apply timezone offset to get the main parts in UTC
* Zero sign, see misc/tcc_zerosign2.c.
* Boolean built-ins
LeftHandSideExpression does not allow empty expression
comment: XXX: add proper spare handling to dynamic buffer, to minimize
* reallocs; currently there is no spare at all.
label: code-design
Note: escaped characters differentiate directives
defaults, E5 Section 8.6.1, Table 7
* Intern the temporary byte buffer into a valstack slot
* (in practice, slot1 or slot2).
special RegExp literal handling after IdentifierName
XXX: byte offset?
'switch'
* The 'duktape.h' header provides the public API, but also handles all
* compiler and platform specific feature detection, Duktape feature
* resolution, inclusion of system headers, etc. These have been merged
* because the public API is also dependent on e.g. detecting appropriate
* C types which is quite platform/compiler specific especially for a non-C99
* build. The public API is also dependent on the resolved feature set.
*
* Some actions taken by the merged header (such as including system headers)
* are not appropriate for building a user application. The define
* DUK_COMPILING_DUKTAPE allows the merged header to skip/include some
* sections depending on what is being built.
* Check the function type, handle bound function chains, and prepare
* parameters for the rest of the call handling. Also figure out the
* effective 'this' binding, which replaces the current value at
* idx_func + 1.
*
* If the target function is a 'bound' one, follow the chain of 'bound'
* functions until a non-bound function is found. During this process,
* bound arguments are 'prepended' to existing ones, and the "this"
* binding is overridden. See E5 Section 15.3.4.5.1.
*
* Lightfunc detection happens here too. Note that lightweight functions
* can be wrapped by (non-lightweight) bound functions so we must resolve
* the bound function chain first.
avoid side effects
result in csreg
* Other heap related defines
* Start doing property attributes updates. Steps 12-13.
*
* Start by computing new attribute flags without writing yet.
* Property type conversion is done above if necessary.
strict: non-deletable, non-writable
* Assuming a register binds to a variable declared within this
* function (a declarative binding), the 'this' for the call
* setup is always 'undefined'. E5 Section 10.2.1.1.6.
This may happen when forward and backward scanning disagree
* (possible for non-extended-UTF-8 strings).
use fallback as 'this' value
Caller has already eaten the first character ('(') which we don't need.
r <- (* r B)
* s <- s
* m+ <- (* m+ B)
* m- <- (* m- B)
* k <- (- k 1)
A -> object reg
* B -> key reg/const
* C -> value reg/const
*
* Note: intentional difference to register arrangement
* of e.g. GETPROP; 'A' must contain a register-only value.
C recursion check.
b
Misc
catches EOF (0x00)
comment: XXX: duk_get_length?
label: code-design
XXX: if assertions enabled, walk through all valid PCs
* and check line mapping.
'defineProperty'
comment: XXX: awkward and bloated asm -- use faster internal accesses
label: code-design
approximation, close enough
marker for detecting internal "double faults", see duk_error_throw.c
three flags
No difference between raw/ensure because the buffer shrinks.
* Determining which datetime components to overwrite based on
* stack arguments is a bit complicated, but important to factor
* out from setters themselves for compactness.
*
* If DUK_DATE_FLAG_TIMESETTER, maxnargs indicates setter type:
*
* 1 -> millisecond
* 2 -> second, [millisecond]
* 3 -> minute, [second], [millisecond]
* 4 -> hour, [minute], [second], [millisecond]
*
* Else:
*
* 1 -> date
* 2 -> month, [date]
* 3 -> year, [month], [date]
*
* By comparing nargs and maxnargs (and flags) we know which
* components to override. We rely on part index ordering.
False if the object is NULL or the prototype 'p' is NULL.
* In particular, false if both are NULL (don't compare equal).
Start filling in the activation
SCANBUILD: complains about use of uninitialized values.
* The complaint is correct, but operating in undefined
* values here is intentional in some cases and the caller
* ignores the results.
prevent duk__expr_led() by using a binding power less than anything valid
borrowed reference; although 'tv1' comes from a register,
* its value was loaded using LDCONST so the constant will
* also exist and be reachable.
[ ... proplist enum_obj key val ]
* Unix-like Date providers
*
* Generally useful Unix / POSIX / ANSI Date providers.
Push the current 'this' binding; throw TypeError if binding is not object
* coercible (CheckObjectCoercible).
All strings beginning with 0xff are treated as "internal",
* even strings interned by the user. This allows user code to
* create internal properties too, and makes behavior consistent
* in case user code happens to use a string also used by Duktape
* (such as string has already been interned and has the 'internal'
* flag set).
1111 110x 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx 10xx xxxx [31 bits]
shrink failure is not fatal
!(l < p)
valstack index of loop detection object
limit is quite low: one array entry is 8 bytes, one normal entry is 4+1+8+4 = 17 bytes (with hash entry)
yes -> move back to heap allocated
strict flag for putvar comes from our caller (currently: fixed)
catchstack limits
* Manually optimized number-to-double conversion
[ ToObject(this) ToUint32(length) lowerValue upperValue ]
if a tail call:
* - an Ecmascript activation must be on top of the callstack
* - there cannot be any active catchstack entries
[ ... enum_target res trap_result val true ]
Helper for component getter calls: check 'this' binding, get the
* internal time value, split it into parts (either as UTC time or
* local time), push a specified component as a return value to the
* value stack and return 1 (caller can then tail call us).
important for callers
fail
[ sep ToObject(this) len ]
DUK_TOK_PERIOD
Enumeration keys are checked against the enumeration target (to see
* that they still exist). In the proxy enumeration case _Target will
* be the proxy, and checking key existence against the proxy is not
* required (or sensible, as the keys may be fully virtual).
Easiest way to implement the search required by the specification
* is to do a RegExp test() with lastIndex forced to zero. To avoid
* side effects on the argument, "clone" the RegExp if a RegExp was
* given as input.
*
* The global flag of the RegExp should be ignored; setting lastIndex
* to zero (which happens when "cloning" the RegExp) should have an
* equivalent effect.
idx_reviver
comment: Require a lot of stack to force a value stack grow/shrink.
* Recursive mark-and-sweep is prevented by allocation macros
* so this won't trigger another mark-and-sweep.
label: code-design
signed shift
Impose a string maximum length, need to handle overflow
* correctly.
comment: XXX: casts could be improved, especially for GET/SET DATA
label: code-design
bytes left
comment: XXX: these last tricks are unnecessary if the function is made
* a genuine native function.
label: code-design
No locale specific formatter; this is OK, we fall back
* to ISO 8601.
failed
-> [... key]
comment: Tested: not faster on x64
label: code-design
clamp to 10 chars
* "LineTerminator" production check.
A lightfunc might also inherit a .toJSON() so just bail out.
comment: Note: this is very tricky; we must never 'overshoot' the
* correction downwards.
label: code-design
comment: XXX: inefficient; block insert primitive
label: code-design
* Exposed helper for setting up heap longjmp state.
in non-packed representation we don't care about which NaN is used
comment: Period followed by a digit can only start DecimalLiteral
* (handled in slow path). We could jump straight into the
* DecimalLiteral handling but should avoid goto to inside
* a block.
label: code-design
zero
Handle change in value stack top. Respect value stack
* initialization policy: 'undefined' above top. Note that
* DECREF may cause a side effect that reallocates valstack,
* so must relookup after DECREF.
comment: XXX: tostring?
label: code-design
'func' wants stack "as is"
* Debug message processing
Bottom of valstack for this activation, used to reset
* valstack_bottom on return; index is absolute. Note:
* idx_top not needed because top is set to 'nregs' always
* when returning to an Ecmascript activation.
* Sweep heap
Object.keys
map is reachable through obj
comment: XXX: this needs to be reworked so that we never shrink the value
* stack on function entry so that we never need to grow it here.
* Needing to grow here is a sandboxing issue because we need to
* allocate which may cause an error in the error handling path
* and thus propagate an error out of a protected call.
label: code-design
comment:
* Note: since this is an exposed API call, there should be
* no way a mark-and-sweep could have a side effect on the
* memory allocation behind 'ptr'; the pointer should never
* be something that Duktape wants to change.
*
* Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
* have the storage location here anyway).
label: code-design
required for rehash to succeed, equality not that useful
DUK_TOK_CLASS
comment: unused for label
label: code-design
'this' binding shouldn't matter here
comment: remove old value
label: code-design
comment: get rid of the strings early to minimize memory use before intern
label: code-design
always in entry part, no need to look up parents etc
* Raw intern and lookup
Copy the property table verbatim; this handles attributes etc.
* For ROM objects it's not necessary (or possible) to update
* refcounts so leave them as is.
CONDITIONAL EXPRESSION
swap elements; deal with non-existent elements correctly
[ ... closure/error ]
* Create a new property in the original object.
*
* Exotic properties need to be reconsidered here from a write
* perspective (not just property attributes perspective).
* However, the property does not exist in the object already,
* so this limits the kind of exotic properties that apply.
Initial value for highest_idx is -1 coerced to unsigned. This
* is a bit odd, but (highest_idx + 1) will then wrap to 0 below
* for out_min_size as intended.
ignore
comment: XXX: combine all the integer conversions: they share everything
* but the helper function for coercion.
label: code-design
vararg function, thisArg needs special handling
Assert for value stack initialization policy.
comment:
* Shallow fast path checks for accessing array elements with numeric
* indices. The goal is to try to avoid coercing an array index to an
* (interned) string for the most common lookups, in particular, for
* standard Array objects.
*
* Interning is avoided but only for a very narrow set of cases:
* - Object has array part, index is within array allocation, and
* value is not unused (= key exists)
* - Object has no interfering exotic behavior (e.g. arguments or
* string object exotic behaviors interfere, array exotic
* behavior does not).
*
* Current shortcoming: if key does not exist (even if it is within
* the array allocation range) a slow path lookup with interning is
* always required. This can probably be fixed so that there is a
* quick fast path for non-existent elements as well, at least for
* standard Array objects.
label: code-design
curr_token slot1 (matches 'lex' slot1_idx)
eat 'break' or 'continue'
zero-based -> one-based
roughly 512 bytes
* indexOf() and lastIndexOf()
DUK_USE_HEAPPTR16
regexp literal must not follow this token
qmin and qmax will be 0 or 1
same as during entry
Have a catch variable.
Note: in strict mode the compiler should reject explicit
* declaration of 'eval' or 'arguments'. However, internal
* bytecode may declare 'arguments' in the function prologue.
* We don't bother checking (or asserting) for these now.
Object property allocation layout
Node.js accepts only actual Arrays.
[ requested_id require require.id resolved_id last_comp Duktape Duktape.modLoaded undefined ]
comment: XXX: Shrink the stacks to minimize memory usage? May not
* be worth the effort because terminated threads are usually
* garbage collected quite soon.
label: code-design
* Actual Object.defineProperty() default algorithm.
t1 = milliseconds within day (fits 32 bit)
* t2 = day number from epoch (fits 32 bit, may be negative)
'class'
compare: similar to string comparison but for buffer data.
Note: if 'x' is zero, x->n becomes 0 here
Debugger protocol version is defined in the public API header.
not undefined
Endianness indicator
number of activation records in callstack preventing a yield
DUK_TOK_IMPLEMENTS
4'294'967'295
XXX: switch cast?
'trace'
array 'length' is always a number, as we coerce it
NULL is allowed, no output
* Convert duk_compiler_func to a function template
Update duk_tval in-place if pointer provided and the
* property is writable. If the property is not writable
* (immutable binding), use duk_hobject_putprop() which
* will respect mutability.
Better equivalent algorithm. If the compiler is compliant, C and
* Ecmascript semantics are identical for this particular comparison.
* In particular, NaNs must never compare equal and zeroes must compare
* equal regardless of sign. Could also use a macro, but this inlines
* already nicely (no difference on gcc, for instance).
Is whole and within 32 bit range. If the value happens to be 0xFFFFFFFF,
* it's not a valid array index but will then match DUK__NO_ARRAY_INDEX.
* PLAIN: x1
* ARITH: x1 <op> x2
* PROP: x1.x2
* VAR: x1 (name)
eat closing slash
* Regexp range tables
Value stack intentionally mixed size here.
Computation must not wrap; this limit works for 32-bit size_t:
* >>> srclen = 3221225469
* >>> '%x' % ((srclen + 2) / 3 * 4)
* 'fffffffc'
comment:
* Special post-tweaks, for cases not covered by the init data format.
*
* - Set Date.prototype.toGMTString to Date.prototype.toUTCString.
* toGMTString is required to have the same Function object as
* toUTCString in E5 Section B.2.6. Note that while Smjs respects
* this, V8 does not (the Function objects are distinct).
*
* - Make DoubleError non-extensible.
*
* - Add info about most important effective compile options to Duktape.
*
* - Possibly remove some properties (values or methods) which are not
* desirable with current feature options but are not currently
* conditional in init data.
label: code-design
hobject property layout
comment: UNUSED, intentionally empty
label: code-design
double quote or backslash
track utf-8 non-continuation bytes
[ hobject props enum(props) ]
22 to 31
comment: XXX: very similar to DUK_IVAL_ARITH - merge?
label: code-design
comment: XXX: optional check, match_caps is zero if no regexp,
* so dollar will be interpreted literally anyway.
label: code-design
* Internal helper to define a property with specific flags, ignoring
* normal semantics such as extensibility, write protection etc.
* Overwrites any existing value and attributes unless caller requests
* that value only be updated if it doesn't already exists.
*
* Does not support:
* - virtual properties (error if write attempted)
* - getter/setter properties (error if write attempted)
* - non-default (!= WEC) attributes for array entries (error if attempted)
* - array abandoning: if array part exists, it is always extended
* - array 'length' updating
*
* Stack: [... in_val] -> []
*
* Used for e.g. built-in initialization and environment record
* operations.
-> [... enum key enum_target val]
constants arbitrary, chosen for small loads
reset 'allow_in' for parenthesized expression
comment: Internal class is Object: Object.prototype.toString.call(new Buffer(0))
* prints "[object Object]".
label: code-design
* The entire allocated buffer area, regardless of actual used
* size, is kept zeroed in resizes for simplicity. If the buffer
* is grown, zero the new part.
XXX: integrate support for this into led() instead?
* Similar issue as post-increment/post-decrement.
E5 Sections 11.8.2, 11.8.5; x > y --> y < x
if present, forces 16-byte duk_tval
* 'arguments' binding is special; if a shadowing argument or
* function declaration exists, an arguments object will
* definitely not be needed, regardless of whether the identifier
* 'arguments' is referenced inside the function body.
exports (this binding)
disabled
comment: XXX: other variants like uint, u32 etc
label: code-design
rely on interning, must be this string
Does not allow e.g. 2**31-1, but one more would allow overflows of u32.
Note: cannot be a bound function either right now,
* this would be easy to relax though.
Match labels starting from latest; once label_id no longer matches, we can
* safely exit without checking the rest of the labels (only the topmost labels
* are ever updated).
The 'else' ambiguity is resolved by 'else' binding to the innermost
* construct, so greedy matching is correct here.
Short circuit if is safe: if act->curr_pc != NULL, 'fun' is
* guaranteed to be a non-NULL Ecmascript function.
read-only values 'lifted' for ease of use
return value
'source'
'clog'
digits
* Statement value handling.
*
* Global code and eval code has an implicit return value
* which comes from the last statement with a value
* (technically a non-"empty" continuation, which is
* different from an empty statement).
*
* Since we don't know whether a later statement will
* override the value of the current statement, we need
* to coerce the statement value to a register allocated
* for implicit return values. In other cases we need
* to coerce the statement value to a plain value to get
* any side effects out (consider e.g. "foo.bar;").
is_frozen
comment: Downgrade checks are not made everywhere, so 'length' is not always
* a fastint (it is a number though). This can be removed once length
* is always guaranteed to be a fastint.
label: code-design
if duk_uint32_t is exactly 32 bits, this is a NOP
* Not found as a concrete property, check whether a String object
* virtual property matches.
* Function formal arguments, always bound to registers
* (there's no support for shuffling them now).
off >= step, and step >= 1
zero-width joiner
Rethrow error to calling state.
'"'
next temporary register to allocate
* For bound objects, [[HasInstance]] just calls the target function
* [[HasInstance]]. If that is again a bound object, repeat until
* we find a non-bound Function object.
Pointer and buffer primitive values are treated like other
* primitives values which have a fully fledged object counterpart:
* promote to an object value. Lightfuncs are coerced with
* ToObject() even they could also be returned as is.
comment: XXX: option to fix opcode length so it lines up nicely
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_UINT16
relookup after side effects (no side effects currently however)
Note: this order matters (final value before deleting map entry must be done)
'arguments'
* Fast path for bufferobject getprop/putprop
XXX: shrink array allocation or entries compaction here?
inline arithmetic check for constant values
pre-incremented, points to first jump slot
* Helpers for duk_compiler_func.
Note: need to re-lookup because ToNumber() may have side effects
expr_flags
comment: XXX: exposed duk_debug_read_hbuffer
label: code-design
accept string
unreferenced without assertions
comment: XXX: macro checks for array index flag, which is unnecessary here
label: code-design
comment: XXX: this algorithm could be optimized quite a lot by using e.g.
* a logarithm based estimator for 'k' and performing B^n multiplication
* using a lookup table or using some bit-representation based exp
* algorithm. Currently we just loop, with significant performance
* impact for very large and very small numbers.
label: code-design
'toString'
first character has been matched
0xfff0 is -Infinity
comment: XXX: don't want to shrink allocation here
label: code-design
-> [ ... error ]
Lightfunc coerces to a Function instance with concrete
* properties. Since 'length' is virtual for Duktape/C
* functions, don't need to define that.
*
* The result is made extensible to mimic what happens to
* strings:
* > Object.isExtensible(Object('foo'))
* true
curr_token follows 'function'
* Update preventcount
comment: These are not needed to implement quantifier capture handling,
* but might be needed at some point.
label: requirement
'toJSON'
function executes as a constructor (called via "new")
heaphdr:
* - is not reachable
* - is an object
* - is not a finalized object
* - has a finalizer
DUK_ERROR_H_INCLUDED
Number/string-or-buffer -> coerce string to number (e.g. "'1.5' == 1.5" -> true).
XXX: There are several limitations in the current implementation for
* strings with >= 0x80000000UL characters. In some cases one would need
* to be able to represent the range [-0xffffffff,0xffffffff] and so on.
* Generally character and byte length are assumed to fit into signed 32
* bits (< 0x80000000UL). Places with issues are not marked explicitly
* below in all cases, look for signed type usage (duk_int_t etc) for
* offsets/lengths.
* Reset function state and perform register allocation, which creates
* 'varmap' for second pass. Function prologue for variable declarations,
* binding value initializations etc is emitted as a by-product.
*
* Strict mode restrictions for duplicate and invalid argument
* names are checked here now that we know whether the function
* is actually strict. See: test-dev-strict-mode-boundary.js.
*
* Inner functions are compiled during pass 1 and are not reset.
if 1, doing a fixed format output (not free format)
We want to do a straight memory copy if possible: this is
* an important operation because .set() is the TypedArray
* way to copy chunks of memory. However, because set()
* conceptually works in terms of elements, not all views are
* compatible with direct byte copying.
*
* If we do manage a direct copy, the "overlap issue" handled
* below can just be solved using memmove() because the source
* and destination element sizes are necessarily equal.
borrowed; NULL if no step state (NULLed in unwind)
new buffer with string contents
Allow very small lenience because some compilers won't parse
* exact IEEE double constants (happened in matrix testing with
* Linux gcc-4.8 -m32 at least).
We could fit built-in index into magic but that'd make the magic
* number dependent on built-in numbering (genbuiltins.py doesn't
* handle that yet). So map both class and prototype from the
* element type.
* Allocate a new thread.
*
* Leaves the built-ins array uninitialized. The caller must either
* initialize a new global context or share existing built-ins from
* another thread.
no regexp instance should exist without a non-configurable bytecode property
original input stack before nargs/nregs handling must be
* intact for 'arguments' object
replaces top of stack with new value if necessary
33: setUTCDate
Notes:
* - only numbered indices are relevant, so arr_idx fast reject is good
* (this is valid unless there are more than 4**32-1 arguments).
* - since variable lookup has no side effects, this can be skipped if
* DUK_GETDESC_FLAG_PUSH_VALUE is not set.
Automatic semicolon insertion is allowed if a token is preceded
* by line terminator(s), or terminates a statement list (right curly
* or EOF).
eat 'for'
init 'curr_token'
-> [ ... new_global new_globalenv new_global ]
Index clamping is a bit tricky, we must ensure that we'll only iterate
* through elements that exist and that the specific requirements from E5.1
* Sections 15.4.4.14 and 15.4.4.15 are fulfilled; especially:
*
* - indexOf: clamp to [-len,len], negative handling -> [0,len],
* if clamped result is len, for-loop bails out immediately
*
* - lastIndexOf: clamp to [-len-1, len-1], negative handling -> [-1, len-1],
* if clamped result is -1, for-loop bails out immediately
*
* If fromIndex is not given, ToInteger(undefined) = 0, which is correct
* for indexOf() but incorrect for lastIndexOf(). Hence special handling,
* and why lastIndexOf() needs to be a vararg function.
implicit attributes
allow a constant to be returned
prop index in 'entry part', < 0 if not there
add_auto_proto
[ ... ToObject(this) ToUint32(length) val ]
Load bytecode instructions.
unsupported: would consume multiple args
DUK_USE_DEBUGGER_THROW_NOTIFY
* Same type?
*
* Note: since number values have no explicit tag in the 8-byte
* representation, need the awkward if + switch.
There's intentionally no check for
* current underlying buffer length.
follow parent chain
xxx -> DUK_HBUFFEROBJECT_ELEM_FLOAT64
comment: XXX: this should be an assert
label: test
without explicit non-BMP support, assume non-BMP characters
* are always accepted as letters.
No debugger support, just pop values.
The lookup byte is intentionally sign extended to (at least)
* 32 bits and then ORed. This ensures that is at least 1 byte
* is negative, the highest bit of 't' will be set at the end
* and we don't need to check every byte.
[ hobject props enum(props) key desc value? getter? setter? ]
start match from beginning
DUK_HOBJECT_FLAG_ARRAY_PART: don't care
Validity checks for various fraction formats ("0.1", ".1", "1.", ".").
DUK_USE_SECTION_B
!DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
comment: XXX: better to get base and walk forwards?
label: code-design
'ownKeys'
comment: Call this.raw(msg); look up through the instance allows user to override
* the raw() function in the instance or in the prototype for maximum
* flexibility.
label: code-design
restore stack top
DUK_USE_BASE64_FASTPATH
Valstack should suffice here, required on function valstack init
duk_hnativefunction specific fields.
r <- (* f b 2) [if b==2 -> (* f 4)]
* s <- (* (expt b (- 1 e)) 2) == b^(1-e) * 2 [if b==2 -> b^(2-e)]
* m+ <- b == 2
* m- <- 1
* k <- 0
* B <- B
* low_ok <- round
* high_ok <- round
Insert bytes in the middle of the buffer from an external buffer.
identifier names (E5 Section 7.6)
* Set up the resolution input which is the requested ID directly
* (if absolute or no current module path) or with current module
* ID prepended (if relative and current module path exists).
*
* Suppose current module is 'foo/bar' and relative path is './quux'.
* The 'bar' component must be replaced so the initial input here is
* 'foo/bar/.././quux'.
A non-Array object should not have an array part in practice.
* But since it is supported internally (and perhaps used at some
* point), check and abandon if that's the case.
keep heap->dbg_detached_cb
For tv1 == tv2, both pointing to stack top, the end result
* is same as duk_pop(ctx).
If input_offset were assigned a negative value, it would
* result in a large positive value. Most likely it would be
* larger than input_length and be caught here. In any case
* no memory unsafe behavior would happen.
During parsing, month and day are one-based; set defaults here.
comment:
* Logger arguments are:
*
* magic: log level (0-5)
* this: logger
* stack: plain log args
*
* We want to minimize memory churn so a two-pass approach
* is used: first pass formats arguments and computes final
* string length, second pass copies strings either into a
* pre-allocated and reused buffer (short messages) or into a
* newly allocated fixed buffer. If the backend function plays
* nice, it won't coerce the buffer to a string (and thus
* intern it).
label: code-design
Non-zero refcounts should not happen because we refcount
* finalize all unreachable objects which should cancel out
* refcounts (even for cycles).
token allows automatic semicolon insertion (eof or preceded by newline)
Use special opcodes to load short strings
* Add .fileName and .lineNumber to an error on the stack top.
* CommonJS require() and modules support
* Lexing helpers
* Create built-in objects by parsing an init bitstream generated
* by genbuiltins.py.
explicit PropertyList
Special handling for call setup instructions. The target
* is expressed indirectly, but there is no output shuffling.
* Create mantissa
NOTE: act may be NULL if an error is thrown outside of any activation,
* which may happen in the case of, e.g. syntax errors.
ToNumber() for a fastint is a no-op.
[key] -> [undefined] (default value)
traceback depth fits into 16 bits
[ thisArg arg1 ... argN func boundFunc argArray ]
* Parser duk__advance() token eating functions
comment: cleanup varmap from any null entries, compact it, etc; returns number
* of final entries after cleanup.
label: code-design
comment:
* Needs a save of multiple saved[] entries depending on what range
* may be overwritten. Because the regexp parser does no such analysis,
* we currently save the entire saved array here. Lookaheads are thus
* a bit expensive. Note that the saved array is not needed for just
* the lookahead sub-match, but for the matching of the entire sequel.
*
* The temporary save buffer is pushed on to the valstack to handle
* errors correctly. Each lookahead causes a C recursion and pushes
* more stuff on the value stack. If the C recursion limit is less
* than the value stack spare, there is no need to check the stack.
* We do so regardless, just in case.
label: code-design
comment: XXX: split into separate functions for each field type?
label: code-design
Same as above but for unsigned int range.
comma after a value, expected
duplicate key
Given a day number, determine year and day-within-year.
comment: Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
label: code-design
Success path handles
comment: XXX: getter with class check, useful in built-ins
label: code-design
already updated
checking for DUK__DELETED_MARKER is not necessary here, but helper does it now
match: keep saves
DUK_USE_PARANOID_MATH
'boolean'
* Debugging disabled
fixed offset in valstack
DUK_TOK_ENUM
when key is NULL, value is garbage so no need to set
comment:
* Error during call. The error value is at heap->lj.value1.
*
* The very first thing we do is restore the previous setjmp catcher.
* This means that any error in error handling will propagate outwards
* instead of causing a setjmp() re-entry above.
label: code-design
Standard behavior for map(): trailing non-existent
* elements don't invoke the user callback and are not
* counted towards result 'length'.
* Append a Unicode codepoint to the temporary byte buffer. Performs
* CESU-8 surrogate pair encoding for codepoints above the BMP.
* Existing surrogate pairs are allowed and also encoded into CESU-8.
* Proxy helpers
* Found; post-processing (Function and arguments objects)
maps to finalizer 2nd argument
DUK_USE_AVOID_PLATFORM_FUNCPTRS
'roundpos' is relative to nc_ctx->k and increases to the right
* (opposite of how 'k' changes).
key encountered as a plain property
e.g. DUK_OP_POSTINCV
Allow empty string to be interpreted as 0
Math.pow(-0,y) where y<0 should be:
* - -Infinity if y<0 and an odd integer
* - Infinity otherwise
* NetBSD pow() returns -Infinity for all finite y<0. The
* if-clause also catches y == -Infinity (which works even
* without the fix).
comment: XXX: add temporary duk__p pointer here too; sharing
label: code-design
not minimum exponent
* Avoid nested calls. Concretely this happens during debugging, e.g.
* when we eval() an expression.
*
* Also don't interrupt if we're currently doing debug processing
* (which can be initiated outside the bytecode executor) as this
* may cause the debugger to be called recursively. Check required
* for correct operation of throw intercept and other "exotic" halting
* scenarios.
Because new_size > duk__count_used_probe(heap), guaranteed to work
bump refcount to prevent refzero during finalizer processing
* Pointers to function data area for faster access. Function
* data is a buffer shared between all closures of the same
* "template" function. The data buffer is always fixed (non-
* dynamic, hence stable), with a layout as follows:
*
* constants (duk_tval)
* inner functions (duk_hobject *)
* bytecode (duk_instr_t)
*
* Note: bytecode end address can be computed from 'data' buffer
* size. It is not strictly necessary functionally, assuming
* bytecode never jumps outside its allocated area. However,
* it's a safety/robustness feature for avoiding the chance of
* executing random data as bytecode due to a compiler error.
*
* Note: values in the data buffer must be incref'd (they will
* be decref'd on release) for every compiledfunction referring
* to the 'data' element.
comment:
* Advance lookup window by N characters, filling in new characters as
* necessary. After returning caller is guaranteed a character window of
* at least DUK_LEXER_WINDOW_SIZE characters.
*
* The main function duk__advance_bytes() is called at least once per every
* token so it has a major lexer/compiler performance impact. There are two
* variants for the main duk__advance_bytes() algorithm: a sliding window
* approach which is slightly faster at the cost of larger code footprint,
* and a simple copying one.
*
* Decoding directly from the source string would be another lexing option.
* But the lookup window based approach has the advantage of hiding the
* source string and its encoding effectively which gives more flexibility
* going forward to e.g. support chunked streaming of source from flash.
*
* Decodes UTF-8/CESU-8 leniently with support for code points from U+0000 to
* U+10FFFF, causing an error if the input is unparseable. Leniency means:
*
* * Unicode code point validation is intentionally not performed,
* except to check that the codepoint does not exceed 0x10ffff.
*
* * In particular, surrogate pairs are allowed and not combined, which
* allows source files to represent all SourceCharacters with CESU-8.
* Broken surrogate pairs are allowed, as Ecmascript does not mandate
* their validation.
*
* * Allow non-shortest UTF-8 encodings.
*
* Leniency here causes few security concerns because all character data is
* decoded into Unicode codepoints before lexer processing, and is then
* re-encoded into CESU-8. The source can be parsed as strict UTF-8 with
* a compiler option. However, Ecmascript source characters include -all-
* 16-bit unsigned integer codepoints, so leniency seems to be appropriate.
*
* Note that codepoints above the BMP are not strictly SourceCharacters,
* but the lexer still accepts them as such. Before ending up in a string
* or an identifier name, codepoints above BMP are converted into surrogate
* pairs and then CESU-8 encoded, resulting in 16-bit Unicode data as
* expected by Ecmascript.
*
* An alternative approach to dealing with invalid or partial sequences
* would be to skip them and replace them with e.g. the Unicode replacement
* character U+FFFD. This has limited utility because a replacement character
* will most likely cause a parse error, unless it occurs inside a string.
* Further, Ecmascript source is typically pure ASCII.
*
* See:
*
* http://en.wikipedia.org/wiki/UTF-8
* http://en.wikipedia.org/wiki/CESU-8
* http://tools.ietf.org/html/rfc3629
* http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
*
* Future work:
*
* * Reject other invalid Unicode sequences (see Wikipedia entry for examples)
* in strict UTF-8 mode.
*
* * Size optimize. An attempt to use a 16-byte lookup table for the first
* byte resulted in a code increase though.
*
* * Is checking against maximum 0x10ffff really useful? 4-byte encoding
* imposes a certain limit anyway.
*
* * Support chunked streaming of source code. Can be implemented either
* by streaming chunks of bytes or chunks of codepoints.
label: code-design
duk_push_this() + CheckObjectCoercible() + duk_to_string()
pointers for scanning
array part size (entirely gc reachable)
Steps 12 and 13: reorganize elements to make room for itemCount elements
number of tokens parsed
Tear down state.
Don't check for Infinity unless the context allows it.
* 'Infinity' is a valid integer literal in e.g. base-36:
*
* parseInt('Infinity', 36)
* 1461559270678
zero handled by caller
Don't accept relative indices now.
[holder name val] -> [holder]
res_obj
* XUTF-8 and CESU-8 encoding/decoding
1110 xxxx 10xx xxxx 10xx xxxx [16 bits]
function declaration
comment: XXX: disable error handlers for duration of compaction?
label: code-design
* PUTVAR
*
* See E5 Sections:
* 11.1.2 Identifier Reference
* 10.3.1 Identifier Resolution
* 11.13.1 Simple Assignment [example of where the Reference is PutValue'd]
* 8.7.2 PutValue (V,W) [see especially step 3.b, undefined -> automatic global in non-strict mode]
* 8.12.4 [[CanPut]] (P)
* 8.12.5 [[Put]] (P)
*
* Note: may invalidate any valstack (or object) duk_tval pointers because
* putting a value may reallocate any object or any valstack. Caller beware.
'?'
state == 3
Maximum traversal depth for "bound function" chains.
comment: XXX: magic for getter/setter? use duk_def_prop()?
label: code-design
xxx -> DUK_HBUFFEROBJECT_ELEM_INT32
[ thread value ]
* GETPROP: Ecmascript property read.
comment:
* The __FILE__ and __LINE__ information is intentionally not used in the
* creation of the error object, as it isn't useful in the tracedata. The
* tracedata still contains the function which returned the negative return
* code, and having the file/line of this function isn't very useful.
label: code-design
object is a thread (duk_hthread)
'info'
add a new pending split to the beginning of the entire disjunction
duk_push_this() + CheckObjectCoercible() + duk_to_object()
[ ... arr jsonx(arr) res ] -> [ ... res jsonx(arr) ]
this may have side effects, so re-lookup act
Fall through to handle the rest.
[ ... error lineNumber fileName ]
* Number built-ins
comment: XXX: this compiles to over 500 bytes now, even without special handling
* for an array part. Uses signed ints so does not handle full array range correctly.
label: code-design
-> [ ... closure template env ]
Note: if the reg_temp load generated shuffling
* instructions, we may need to rewind more than
* one instruction, so use explicit PC computation.
6: toUTCString
comment: note: ctx-wide temporary
label: code-design
value popped by call
Note: this may fail, caller should protect the call if necessary
Leaves new timevalue on stack top and returns 1, which is correct
* for part setters.
stack[0] = compareFn
* stack[1] = ToObject(this)
* stack[2] = ToUint32(length)
4
Boolean/any -> coerce boolean to number and try again. If boolean is
* compared to a pointer, the final comparison after coercion now always
* yields false (as pointer vs. number compares to false), but this is
* not special cased.
s <- 2 * b
native functions: 149
* Range parsing is done with a special lexer function which calls
* us for every range parsed. This is different from how rest of
* the parsing works, but avoids a heavy, arbitrary size intermediate
* value type to hold the ranges.
*
* Another complication is the handling of character ranges when
* case insensitive matching is used (see docs for discussion).
* The range handler callback given to the lexer takes care of this
* as well.
*
* Note that duplicate ranges are not eliminated when parsing character
* classes, so that canonicalization of
*
* [0-9a-fA-Fx-{]
*
* creates the result (note the duplicate ranges):
*
* [0-9A-FA-FX-Z{-{]
*
* where [x-{] is split as a result of canonicalization. The duplicate
* ranges are not a semantics issue: they work correctly.
Although we can allow non-BMP characters (they'll decode
* back into surrogate pairs), we don't allow extended UTF-8
* characters; they would encode to URIs which won't decode
* back because of strict UTF-8 checks in URI decoding.
* (However, we could just as well allow them here.)
exponent 1070
no need to reset temps, as we're finished emitting code
DUK_ERR_ERROR: no macros needed
comment: XXX: assumed to fit for now
label: code-design
[... fallback retval]
comment: XXX: Migrate bufwriter and other read/write helpers to its own header?
label: code-design
recursive call for a primitive value (guaranteed not to cause second
* recursion).
Getter might have arbitrary side effects,
* so bail out.
* The traceback format is pretty arcane in an attempt to keep it compact
* and cheap to create. It may change arbitrarily from version to version.
* It should be decoded/accessed through version specific accessors only.
*
* See doc/error-objects.rst.
The internal _Target property is kept pointing to the original
* enumeration target (the proxy object), so that the enumerator
* 'next' operation can read property values if so requested. The
* fact that the _Target is a proxy disables key existence check
* during enumeration.
Reject a proxy object as the handler because it would cause
* potentially unbounded recursion. (ES6 has no such restriction)
absolute req_digits; e.g. digits = 1 -> last digit is 0,
* but add an extra digit for rounding.
-> [ ... voidp voidp ]
convert duk_compiler_func into a function template, leaving the result
* on top of stack.
r <- r (updated above: r <- (remainder (* r B) s)
* s <- s
* m+ <- m+ (updated above: m+ <- (* m+ B)
* m- <- m- (updated above: m- <- (* m- B)
* B, low_ok, high_ok are fixed
special helper for emitting u16 lists (used for character ranges for built-in char classes)
[ ... re_obj input bc saved_buf ]
'reg_varbind' is the operation result and can also
* become the expression value for top level assignments
* such as: "var x; x += y;".
comment:
* Three possible outcomes:
* * A try or finally catcher is found => resume there.
* (or)
* * The error propagates to the bytecode executor entry
* level (and we're in the entry thread) => rethrow
* with a new longjmp(), after restoring the previous
* catchpoint.
* * The error is not caught in the current thread, so
* the thread finishes with an error. This works like
* a yielded error, except that the thread is finished
* and can no longer be resumed. (There is always a
* resumer in this case.)
*
* Note: until we hit the entry level, there can only be
* Ecmascript activations.
label: code-design
* Number-to-string and string-to-number conversions.
*
* Slow path number-to-string and string-to-number conversion is based on
* a Dragon4 variant, with fast paths for small integers. Big integer
* arithmetic is needed for guaranteeing that the conversion is correct
* and uses a minimum number of digits. The big number arithmetic has a
* fixed maximum size and does not require dynamic allocations.
*
* See: doc/number-conversion.rst.
Parser separator indices.
Regexp
k > 0 -> k was too low, and cannot be too high
'func' in the algorithm
comment:
* Note: zero works as a "no update" marker because the new length
* can never be zero after a new property is written.
*
* Note: must re-lookup because calls above (e.g. duk__alloc_entry_checked())
* may realloc and compact properties and hence change e_idx.
label: code-design
Outside any activation -> look up from global.
Decrease by 25% every round
For manual testing only.
comment: Execute the fast path in a protected call. If any error is thrown,
* fall back to the slow path. This includes e.g. recursion limit
* because the fast path has a smaller recursion limit (and simpler,
* limited loop detection).
label: code-design
* Main heap structure
* Argument exotic [[Delete]] behavior (E5 Section 10.6) is
* a post-check, keeping arguments internal 'map' in sync with
* any successful deletes (note that property does not need to
* exist for delete to 'succeed').
*
* Delete key from 'map'. Since 'map' only contains array index
* keys, we can use arr_idx for a fast skip.
E5 Section 9.2
Backtrack utf-8 input and return a (possibly canonicalized) input character.
Cause an interrupt after executing one instruction.
Compiler
at least errobj must be on stack
16 bits
* Default panic handler
thr->heap->dbg_detaching may be != 0 if a debugger write outside
* the message loop caused a transport error and detach1() to run.
'modSearch'
comment: The condition could be more narrow and check for the
* copy area only, but there's no need for fine grained
* behavior when the underlying buffer is misconfigured.
label: code-design
comment: XXX: for a memory-code tradeoff, remove 'func' and make it's access either a function
* or a macro. This would make the activation 32 bytes long on 32-bit platforms again.
label: code-design
Function name is an Identifier (not IdentifierName), but we get
* the raw name (not recognizing keywords) here and perform the name
* checks only after pass 1.
does not fit into 16 bits
ensures no overflow
[ ... input buffer ]
execution resumes in bytecode executor
Standard JSON omits functions
7 bits
* Value stack resizing.
*
* This resizing happens above the current "top": the value stack can be
* grown or shrunk, but the "top" is not affected. The value stack cannot
* be resized to a size below the current "top".
*
* The low level reallocation primitive must carefully recompute all value
* stack pointers, and must also work if ALL pointers are NULL. The resize
* is quite tricky because the valstack realloc may cause a mark-and-sweep,
* which may run finalizers. Running finalizers may resize the valstack
* recursively (the same value stack we're working on). So, after realloc
* returns, we know that the valstack "top" should still be the same (there
* should not be live values above the "top"), but its underlying size and
* pointer may have changed.
* Objects have internal references. Must finalize through
* the "refzero" work list.
different thread
number of values in current MPUTARR set
steps 13-14
Compute result length and validate argument buffers.
DUK_BUILTINS_H_INCLUDED
copy bytecode instructions one at a time
comment: E5.1 Section 15.2.4.6, step 3.a, lookup proto once before compare.
* Prototype loops should cause an error to be thrown.
label: code-design
[ ... RegExp val ] -> [ ... res ]
load factor max 75%
[ value offset noAssert ], when ftype != DUK__FLD_VARINT
* Resizing
token closes expression, e.g. ')', ']'
fileName
* Get prototype object for an integer error code.
'\xffNext'
PC/line semantics here are:
* - For callstack top we're conceptually between two
* opcodes and current PC indicates next line to
* execute, so report that (matches Status).
* - For other activations we're conceptually still
* executing the instruction at PC-1, so report that
* (matches error stacktrace behavior).
* - See: https://github.com/svaarala/duktape/issues/281
Don't allow negative zero as it will cause trouble with
* LDINT+LDINTX. But positive zero is OK.
borrow literal Infinity from builtin string
comment: XXX: This now coerces an identifier into a GETVAR to a temp, which
* causes an extra LDREG in call setup. It's sufficient to coerce to a
* unary ivalue?
label: code-design
prefer direct execution
comment: Longjmp state is cleaned up by error handling
label: code-design
comment: spaces[] must be static to allow initializer with old compilers like BCC
label: code-design
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
Ordinary gap, undefined encodes to 'null' in
* standard JSON (and no JX/JC support here now).
fall-through jump to next code of next case (backpatched)
already one-based
comment: XXX: could use at least one fewer loop counters
label: code-design
Wrap checked above.
Create function 'data' buffer but don't attach it yet.
* Function built-ins
* No match, E5 Section 15.10.6.2, step 9.a.i - 9.a.ii apply, regardless
* of 'global' flag of the RegExp. In particular, if lastIndex is invalid
* initially, it is reset to zero.
comment: hacky helper for String.prototype.split()
label: code-design
[ (builtin objects) name func ]
We request a tail call, but in some corner cases
* call handling can decide that a tail call is
* actually not possible.
* See: test-bug-tailcall-preventyield-assert.c.
toString() conditions
Write bytecode executor's curr_pc back to topmost activation (if any).
[] -> [val]
comment: XXX: Extensibility check for target uses IsExtensible(). If we
* implemented the isExtensible trap and didn't reject proxies as
* proxy targets, it should be respected here.
label: code-design
comment: Technically return value is not needed because INVLHS will
* unconditially throw a ReferenceError. Coercion is necessary
* for proper semantics (consider ToNumber() called for an object).
* Use DUK_EXTRAOP_UNP with a dummy register to get ToNumber().
label: code-design
decl type
-> [ sep ToObject(this) len sep str ]
Shared lenient buffer length clamping helper. Indices are treated as
* element indices (though output values are byte offsets) which only
* really matters for TypedArray views as other buffer object have a zero
* shift. Negative indices are counted from end of input slice; crossed
* indices are clamped to zero length; and final indices are clamped
* against input slice. Used for e.g. ArrayBuffer slice().
XXX: perhaps refactor this to allow caller to specify some parameters, or
* at least a 'compact' flag which skips any spare or round-up .. useful for
* emergency gc.
[ ... enum_target res handler trap ]
XXX: Decrementing and restoring act->curr_pc works now, but if the
* debugger message loop gains the ability to adjust the current PC
* (e.g. a forced jump) restoring the PC here will break. Another
* approach would be to use a state flag for the "decrement 1 from
* topmost activation's PC" and take it into account whenever dealing
* with PC values.
Create a fresh object environment for the global scope. This is
* needed so that the global scope points to the newly created RAM-based
* global object.
x <- (1<<y)
* HASPROP: Ecmascript property existence check ("in" operator).
*
* Interestingly, the 'in' operator does not do any coercion of
* the target object.
Any 'res' will do.
If neutered must return 0; length is zeroed during
* neutering.
XXX: assert idx_base
comment: XXX: refactor into internal helper, duk_clone_hobject()
label: code-design
* Get starting character offset for match, and initialize 'sp' based on it.
*
* Note: lastIndex is non-configurable so it must be present (we check the
* internal class of the object above, so we know it is). User code can set
* its value to an arbitrary (garbage) value though; E5 requires that lastIndex
* be coerced to a number before using. The code below works even if the
* property is missing: the value will then be coerced to zero.
*
* Note: lastIndex may be outside Uint32 range even after ToInteger() coercion.
* For instance, ToInteger(+Infinity) = +Infinity. We track the match offset
* as an integer, but pre-check it to be inside the 32-bit range before the loop.
* If not, the check in E5 Section 15.10.6.2, step 9.a applies.
avoid side effect issues
* Setup call: target and 'this' binding. Three cases:
*
* 1. Identifier base (e.g. "foo()")
* 2. Property base (e.g. "foo.bar()")
* 3. Register base (e.g. "foo()()"; i.e. when a return value is a function)
SHIFT EXPRESSION
overflow, fall through
restored if ecma-to-ecma setup fails
Match labels starting from latest label because there can be duplicate empty
* labels in the label set.
If debugger is paused, garbage collection is disabled by default.
DUK_ERR_REFERENCE_ERROR: no macros needed
XXX: shared helper for duk_push_hobject_or_undefined()?
* Strings have no internal references but do have "weak"
* references in the string cache. Also note that strings
* are not on the heap_allocated list like other heap
* elements.
unconditionally
comment: XXX: At the moment Duktape accesses internal keys like _Finalizer using a
* normal property set/get which would allow a proxy handler to interfere with
* such behavior and to get access to internal key strings. This is not a problem
* as such because internal key strings can be created in other ways too (e.g.
* through buffers). The best fix is to change Duktape internal lookups to
* skip proxy behavior. Until that, internal property accesses bypass the
* proxy and are applied to the target (as if the handler did not exist).
* This has some side effects, see test-bi-proxy-internal-keys.js.
label: code-design
Get local time offset (in seconds) for a certain (UTC) instant 'd'.
comment: Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
* to the message loop so that it can be called between messages;
* this avoids corner cases related to immediate debugger reattach
* inside the detached callback.
label: code-design
resumee
* Parse a function body or a function-like expression, depending
* on flags.
actually used, non-NULL entries
Fast path check.
length check
Do decrefs only with safe pointers to avoid side effects
* disturbing e_idx.
'{"_ninf":true}'
shared checks for all descriptor types
There's no need to check for buffer validity status for the
* target here: the property access code will do that for each
* element. Moreover, if we did check the validity here, side
* effects from reading the source argument might invalidate
* the results anyway.
* Process space (3rd argument to JSON.stringify)
Difference to non-strict/strict comparison is that NaNs compare
* equal and signed zero signs matter.
DUK_USE_PANIC_HANDLER
avoid array abandoning which interns strings
traits are separate; in particular, arguments not an array
duk__get_min_grow_a() is always >= 1
9: getUTCFullYear
[key getter this key] -> [key retval]
Source end clamped silently to available length.
First character has already been eaten and checked by the caller.
* We can scan until a NUL in stridx string because no built-in strings
* have internal NULs.
* Proxy built-in (ES6)
Native function, no relevant lineNumber.
* Limited functionality bigint implementation.
*
* Restricted to non-negative numbers with less than 32 * DUK__BI_MAX_PARTS bits,
* with the caller responsible for ensuring this is never exceeded. No memory
* allocation (except stack) is needed for bigint computation. Operations
* have been tailored for number conversion needs.
*
* Argument order is "assignment order", i.e. target first, then arguments:
* x <- y * z --> duk__bi_mul(x, y, z);
* InitJS code - Ecmascript code evaluated from a built-in source
* which provides e.g. backward compatibility. User can also provide
* JS code to be evaluated at startup.
'res' must be a plain ivalue, and not register-bound variable.
function helpers
'Null'
internal properties
custom
* XXX: shrink array allocation or entries compaction here?
ToInteger(lastIndex)
* Encoding/decoding helpers
default: NaN
covers -Infinity
Error instance, use augmented error data directly
t1 = (+ r m+)
[... func arg1 ... argN]
comment: XXX: unnecessary string coercion for array indices,
* intentional to keep small; some overlap with string
* handling.
label: code-design
Some contexts don't allow fractions at all; this can't be a
* post-check because the state ('f' and expt) would be incorrect.
variable value (function, we hope, not checked here)
return 'res_obj'
E5 Section 10.4.2
DUK_FORWDECL_H_INCLUDED
avoid unary minus on unsigned
Just flip the single bit.
unicode code points, window[0] is always next, points to 'buffer'
probe
may be set to 0 by duk_debugger_attach() inside callback
Easy to get wrong, so assert for it.
mask out flags not actually stored
'with' target must be created first, in case we run out of memory
comment: Slow writing of value using either 64-bit arithmetic
* or IEEE doubles if 64-bit types not available. There's
* no special sign handling when writing varints.
label: code-design
Important main primitive.
no throw
[ ... lval rval(func) ]
comment: XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
label: code-design
comment: XXX: The duk_to_number() cast followed by integer coercion
* is platform specific so NaN, +/- Infinity, and out-of-bounds
* values result in platform specific output now.
* See: test-bi-nodejs-buffer-proto-varint-special.js
label: code-design
'lastIndex'
0xd0-0xdf
* Format tag parsing. Since we don't understand all the
* possible format tags allowed, we just scan for a terminating
* specifier and keep track of relevant modifiers that we do
* understand. See man 3 printf.
pop varname
comment: XXX: this should probably just operate on the stack top, because it
* needs to push stuff on the stack anyway...
label: code-design
'advtok' indicates how much to advance and which token id to assign
* at the end. This shared functionality minimizes code size. All
* code paths are required to set 'advtok' to some value, so no default
* init value is used. Code paths calling DUK_ERROR() never return so
* they don't need to set advtok.
debugger
* Automatically generated by extract_chars.py, do not edit!
* Copy keys and values in the entry part (compacting them at the same time).
expensive init, just want to fill window
'toLogString'
split2: prefer jump execution (not direct)
Zero special case: fake requested number of zero digits; ensure
* no sign bit is printed. Relative and absolute fixed format
* require separate handling.
skip line info
heap destruction ongoing, finalizer rescue no longer possible
E5 Section 9.1
value stack indices for tracking objects
two encoding attempts suffices
DUK_ISPEC_XXX
comment: XXX: append primitive
label: code-design
current lexical environment (may be NULL if delayed)
explicit NULL inits
[ ... closure template env ]
use a temp: decref only when valstack reachable values are correct
Helper for string conversion calls: check 'this' binding, get the
* internal time value, and format date and/or time in a few formats.
* Return value allows tail calls.
0 or -1
comment:
* Allocate heap struct
*
* Use a raw call, all macros expect the heap to be initialized
label: code-design
Object.defineProperty() equivalent C binding.
skip jump slots
We can directly access value stack here.
DUK_TOK_TYPEOF
mark as complex
XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
* support all Ecmascript years (like -200000 and +200000)?
* Should equivalent year mapping be used here too? If so, use
* a shared helper (currently integrated into timeval-to-parts).
comment: m+ != m- (very rarely)
label: code-design
* Duktape debugger
Ecmascript activation + Duktape.Thread.resume() activation
'\''
[ ... str ]
-> [ ... value ]
Use temporaries and update lex_ctx only when finished.
mark-and-sweep not running -> must be empty
comment:
* Normal error
*
* Normal error is thrown with a longjmp() through the current setjmp()
* catchpoint record in the duk_heap. The 'curr_thread' of the duk_heap
* identifies the throwing thread.
*
* Error formatting is usually unnecessary. The error macros provide a
* zero argument version (no formatting) and separate macros for small
* argument counts. Variadic macros are not used to avoid portability
* issues and avoid the need for stash-based workarounds when they're not
* available. Vararg calls are avoided for non-formatted error calls
* because vararg call sites are larger than normal, and there are a lot
* of call sites with no formatting.
*
* Note that special formatting provided by debug macros is NOT available.
*
* The _RAW variants allow the caller to specify file and line. This makes
* it easier to write checked calls which want to use the call site of the
* checked function, not the error macro call inside the checked function.
label: code-design
comment: Fast canonicalization lookup at the cost of 128kB footprint.
label: code-design
DUK_TOK_EXPORT
array of active label names
* Helper for C function call negative return values.
entry_top + 0
* Thread switching
*
* To switch heap->curr_thread, use the macro below so that interrupt counters
* get updated correctly. The macro allows a NULL target thread because that
* happens e.g. in call handling.
entry allocation updates hash part and increases the key
* refcount; may need a props allocation resize but doesn't
* 'recheck' the valstack.
Not necessary to unwind catchstack: break/continue
* handling will do it. The finally flag of 'cat' is
* no longer set. The catch flag may be set, but it's
* not checked by break/continue handling.
Shared helper.
x1 must be a string
[ ... value? getter? setter? ]
comment: XXX: the insert here is a bit expensive if there are a lot of items.
* It could also be special cased in the outermost for loop quite easily
* (as the element is dup()'d anyway).
label: code-design
Gather in big endian
comment: SCANBUILD: warning about 'thr' potentially being NULL here,
* warning is incorrect because thr != NULL always here.
label: code-design
format is bit packed
See test-bug-netbsd-math-pow.js: NetBSD 6.0 on x86 (at least) does not
* correctly handle some cases where x=+/-0. Specific fixes to these
* here.
parse args starting from "next temp", reg_target + 1
Note: multiple threads may be simultaneously in the RUNNING
* state, but not in the same "resume chain".
* Named function expression, name needs to be bound
* in an intermediate environment record. The "outer"
* lexical/variable environment will thus be:
*
* a) { funcname: <func>, __prototype: outer_lex_env }
* b) { funcname: <func>, __prototype: <globalenv> } (if outer_lex_env missing)
* x is finite and non-zero
*
* -1.6 -> floor(-1.1) -> -2
* -1.5 -> floor(-1.0) -> -1 (towards +Inf)
* -1.4 -> floor(-0.9) -> -1
* -0.5 -> -0.0 (special case)
* -0.1 -> -0.0 (special case)
* +0.1 -> +0.0 (special case)
* +0.5 -> floor(+1.0) -> 1 (towards +Inf)
* +1.4 -> floor(+1.9) -> 1
* +1.5 -> floor(+2.0) -> 2 (towards +Inf)
* +1.6 -> floor(+2.1) -> 2
* Context init
comment: XXX: rework
label: code-design
Call stack. [0,callstack_top[ is GC reachable.
DUK_NUMCONV_H_INCLUDED
is a function declaration (as opposed to function expression)
Precomputed pointers when using 16-bit heap pointer packing.
The E5.1 Section 15.4.4.4 algorithm doesn't set the length explicitly
* in the end, but because we're operating with an internal value which
* is known to be an array, this should be equivalent.
XXX: Allow customizing the pause and notify behavior at runtime
* using debugger runtime flags. For now the behavior is fixed using
* config options.
= IsAccessorDescriptor(Desc)
36: setFullYear
Object is currently being finalized.
comment: not covered, return all zeroes
label: test
* Unicode range matcher
*
* Matches a codepoint against a packed bitstream of character ranges.
* Used for slow path Unicode matching.
DUK_HTHREAD_H_INCLUDED
DUK_USE_ES6_PROXY
Located in duk_heaphdr h_extra16. Subclasses of duk_hobject (like
* duk_hcompiledfunction) are not free to use h_extra16 for this reason.
When looking for .fileName/.lineNumber, blame compilation
* or C call site unless flagged not to do so.
Pretend like we got EOM
[ regexp source bytecode ]
catch depth at point of definition
-> [... cons target]
Grow entry part allocation for one additional entry.
comment:
* Calls.
*
* Protected variants should avoid ever throwing an error.
label: code-design
comment: XXX: better multiline
label: code-design
object literal key tracking flags
curr is accessor -> cannot be in array part
stmt has explicit/implicit semicolon terminator
lexing
[ ... result/error ]
catches EOF (NUL) and initial comma
comment: If no explicit message given, put error code into message field
* (as a number). This is not fully in keeping with the Ecmascript
* error model because messages are supposed to be strings (Error
* constructors use ToString() on their argument). However, it's
* probably more useful than having a separate 'code' property.
label: code-design
The #ifdef clutter here needs to handle the three cases:
* (1) JX+JC, (2) JX only, (3) JC only.
currently running thread
temproots
Tail call check: if last opcode emitted was CALL(I), and
* the context allows it, change the CALL(I) to a tail call.
* This doesn't guarantee that a tail call will be allowed at
* runtime, so the RETURN must still be emitted. (Duktape
* 0.10.0 avoided this and simulated a RETURN if a tail call
* couldn't be used at runtime; but this didn't work
* correctly with a thread yield/resume, see
* test-bug-tailcall-thread-yield-resume.js for discussion.)
*
* In addition to the last opcode being CALL, we also need to
* be sure that 'rc_val' is the result register of the CALL(I).
* For instance, for the expression 'return 0, (function ()
* { return 1; }), 2' the last opcode emitted is CALL (no
* bytecode is emitted for '2') but 'rc_val' indicates
* constant '2'. Similarly if '2' is replaced by a register
* bound variable, no opcodes are emitted but tail call would
* be incorrect.
*
* This is tricky and easy to get wrong. It would be best to
* track enough expression metadata to check that 'rc_val' came
* from that last CALL instruction. We don't have that metadata
* now, so we check that 'rc_val' is a temporary register result
* (not a constant or a register bound variable). There should
* be no way currently for 'rc_val' to be a temporary for an
* expression following the CALL instruction without emitting
* some opcodes following the CALL. This proxy check is used
* below.
*
* See: test-bug-comma-expr-gh131.js.
*
* The non-standard 'caller' property disables tail calls
* because they pose some special cases which haven't been
* fixed yet.
* Helper: handle Array object 'length' write which automatically
* deletes properties, see E5 Section 15.4.5.1, step 3. This is
* quite tricky to get right.
*
* Used by duk_hobject_putprop().
vararg
Use 'res' as the expression value (it's side effect
* free and may be a plain value, a register, or a
* constant) and write it to the LHS binding too.
Allow NULL 'msg'
borrowed reference
[... s1 s2] -> [... s1+s2]
DUK_TOK_DIV
comment: XXX: lithuanian not implemented
label: requirement
Explicit zero size check to avoid NULL 'tv1'.
* Get holder object
XXX: can shift() / unshift() use the same helper?
* shift() is (close to?) <--> splice(0, 1)
* unshift is (close to?) <--> splice(0, 0, [items])?
lead zero + 'digits' fractions + 1 for rounding
stack discipline consistency check
* Update the interrupt counter
these non-standard properties are copied for convenience
still reachable
* Forward declarations for all Duktape structures.
[ ... obj key ]
comment:
* Object.preventExtensions() and Object.isExtensible() (E5 Sections 15.2.3.10, 15.2.3.13)
*
* Not needed, implemented by macros DUK_HOBJECT_{HAS,CLEAR,SET}_EXTENSIBLE
* and the Object built-in bindings.
label: code-design
* Macros for property handling
val2 = min count, val1 = max count
find and remove string from stringtable; caller must free the string itself
Inner functions recursively.
== DUK__MAX_TEMPS is OK
Don't free h->resumer because it exists in the heap.
* Callstack entries also contain function pointers which
* are not freed for the same reason.
use bigint area as a temp
'n'
* Allocate initial stacks for a thread. Note that 'thr' must be reachable
* as a garbage collection may be triggered by the allocation attempts.
* Returns zero (without leaking memory) if init fails.
step 4.b
(Number.MAX_VALUE).toString(2).length == 1024, + spare
* Check whether already declared.
*
* We need to check whether the binding exists in the environment
* without walking its parents. However, we still need to check
* register-bound identifiers and the prototype chain of an object
* environment target object.
Catch stack. [0,catchstack_top[ is GC reachable.
DUK_USE_DATE_TZO_WINDOWS
-> [ ... res_obj ]
* E5 Section 15.10.2.6. The previous and current character
* should -not- be canonicalized as they are now. However,
* canonicalization does not affect the result of IsWordChar()
* (which depends on Unicode characters never canonicalizing
* into ASCII characters) so this does not matter.
flags is unsigned
Already declared but no initializer value
* (e.g. 'var xyz;'), no-op.
0
comment: XXX: better place for this
label: code-design
Zero encoded pointer is required to match NULL
Given a (year, month, day-within-month) triple, compute day number.
* The input triple is un-normalized and may contain non-finite values.
upper limit, assuming no whitespace etc
Copy slice, respecting underlying buffer limits; remainder
* is left as zero.
comment: not necessary to init, disabled for faster parsing
label: code-design
We already ate 'x', so backup one byte.
maximum token count before error (sanity backstop)
* For ASCII strings, the answer is simple.
'super'
comment: XXX: This won't be shown in practice now
* because this code is not run when builtins
* are in ROM.
label: code-design
'JSON'
combine left->x1 and res->x1 (right->x1, really) -> (left->x1 OP res->x1)
We can't reliably pop anything here because the stack input
* shape is incorrect. So we throw an error; if the caller has
* no catch point for this, a fatal error will occur. Another
* alternative would be to just return an error. But then the
* stack would be in an unknown state which might cause some
* very hard to diagnose problems later on. Also note that even
* if we did not throw an error here, the underlying call handler
* might STILL throw an out-of-memory error or some other internal
* fatal error.
marker: copy t if not changed
thread has terminated
* Context management
Return codes for protected calls (duk_safe_call(), duk_pcall())
RangeError
set/clear writable
DUK_USE_64BIT_OPS
Ecmascript date range is 100 million days from Epoch:
* > 100e6 * 24 * 60 * 60 * 1000 // 100M days in millisecs
* 8640000000000000
* (= 8.64e15)
* Coercion operations: in-place coercion, return coerced value where
* applicable. If index is invalid, throw error. Some coercions may
* throw an expected error (e.g. from a toString() or valueOf() call)
* or an internal error (e.g. from out of memory).
packed tval
(internal) catch compilation errors
* END PUBLIC API
E == 0x7ff, topmost four bits of F != 0 => assume NaN
APIError
* BEGIN PUBLIC API
timeval breakdown: internal time value NaN -> RangeError (toISOString)
internal flag: external buffer
enumerate internal properties (regardless of enumerability)
Ecmascript E5 specification error codes
* Debugger (debug protocol)
lstring
timeval breakdown: internal time value NaN -> zero
include time part in string conversion result
prefer number
Note: parentheses are required so that the comma expression works in assignments.
no error if file does not exist
internal flag value: throw if mask doesn't match
set getter (given on value stack)
* Memory management
*
* Raw functions have no side effects (cannot trigger GC).
Coercion hints
is_copy
* Variable access
weekday: 0 to 6, 0=sunday, 1=monday, etc
DUK_DBLUNION_H_INCLUDED
lightweight function pointer
* String manipulation
getter: subtract 1900 from year when getting year part
Value mask types, used by e.g. duk_get_type_mask()
Ecmascript undefined
file
Log levels
Ecmascript boolean: 0 or 1
* Public API specific typedefs
*
* Many types are wrapped by Duktape for portability to rare platforms
* where e.g. 'int' is a 16-bit type. See practical typing discussion
* in Duktape web documentation.
flags
AssertionError
only enumerate array indices
* Stack management
Flags for duk_def_prop() and its variants
NOTE: when writing a Date provider you only need a few specific
* flags from here, the rest are internal. Avoid using anything you
* don't need.
* Date provider related constants
*
* NOTE: These are "semi public" - you should only use these if you write
* your own platform specific Date provider, see doc/datetime.rst.
internal: request fixed buffer result
Number of value stack entries (in addition to actual call arguments)
* guaranteed to be allocated on entry to a Duktape/C function.
* Indexes of various types with respect to big endian (logical) layout
no error (e.g. from duk_get_error_code())
LICENSE.txt
SyntaxError
* Duktape/C function magic value
internal: request dynamic buffer result
* Avoid C++ name mangling
comment: XXX: replace with TypeError?
label: code-design
comment: XXX: to be removed?
label: code-design
* ===============
* Duktape license
* ===============
*
* (http://opensource.org/licenses/MIT)
*
* Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Git commit, describe, and branch for Duktape build. Useful for
* non-official snapshot builds so that application code can easily log
* which Duktape snapshot was used. Not available in the Ecmascript
* environment.
DUK_API_PUBLIC_H_INCLUDED
Compilation flags for duk_compile() and duk_eval()
* Duktape public API for Duktape 1.8.0.
*
* See the API reference for documentation on call semantics.
* The exposed API is inside the DUK_API_PUBLIC_H_INCLUDED
* include guard. Other parts of the header are Duktape
* internal and related to platform/compiler/feature detection.
*
* Git commit 0a70d7e4c5227c84e3fed5209828973117d02849 (v1.8.0).
* Git branch v1.8-maintenance.
*
* See Duktape AUTHORS.rst and LICENSE.txt for copyright and
* licensing information.
timeval breakdown: convert month and day-of-month parts to one-based (default is zero-based)
Duktape version, (major * 10000) + (minor * 100) + patch. Allows C code
* to #ifdef against Duktape API version. The same value is also available
* to Ecmascript code in Duktape.version. Unofficial development snapshots
* have 99 for patch level (e.g. 0.10.99 would be a development version
* after 0.10.0 but before the next official release).
* Buffer
set enumerable (effective if DUK_DEFPROP_HAVE_ENUMERABLE set)
set configurable (effective if DUK_DEFPROP_HAVE_CONFIGURABLE set)
don't walk prototype chain, only check own properties
UnimplementedError
(internal) omit eval result
comment:
* If no variadic macros, __FILE__ and __LINE__ are passed through globals
* which is ugly and not thread safe.
label: requirement
last value is func pointer, arguments follow in parens
set/clear configurable
Return codes for C functions (shortcut for throwing an error)
* Pop operations
* Require operations: no coercion, throw error if index or type
* is incorrect. No defaulting.
* Bytecode load/dump
compile function code (instead of global code)
enumerate a proxy object itself without invoking proxy behavior
comment: XXX: native 64-bit byteswaps when available
label: code-design
comment: XXX: These calls are incomplete and not usable now. They are not (yet)
* part of the public API.
label: code-design
Error
DUK_USE_FILE_IO
ReferenceError
timeval breakdown: replace year with equivalent year in the [1971,2037] range for DST calculations
* Ecmascript operators
args
* Some defines forwarded from feature detection
(internal) take strlen() of src_buffer (avoids double evaluation in macro)
set/clear enumerable
internal use
* Error handling
EvalError
* Object prototype
setter: perform 2-digit year fixup (00...99 -> 1900...1999)
nop: no need to normalize
* Compilation and evaluation
or is a normalized NaN
AllocError
month: 0 to 11
comment: XXX: Enough space to hold internal suspend/resume structure.
* This is rather awkward and to be fixed when the internal
* structure is visible for the public API header.
label: code-design
internal flag: create backing ArrayBuffer; keep in one byte
additional values begin at bit 12
* Constants
comment: XXX: replace with plain Error?
label: code-design
* Object finalizer
Reverse operation is the same.
duk_context is now defined in duk_config.h because it may also be
* referenced there by prototypes.
* C++ name mangling
UncaughtError
Ecmascript year range:
* > new Date(100e6 * 24 * 3600e3).toISOString()
* '+275760-09-13T00:00:00.000Z'
* > new Date(-100e6 * 24 * 3600e3).toISOString()
* '-271821-04-20T00:00:00.000Z'
create a new global environment
* Global object
DUKTAPE_H_INCLUDED
E == 0x7ff, F != 0 => NaN
DUK_USE_PACKED_TVAL
* Logging
safe variants of a few coercion operations
Indicates that a native function does not have a fixed number of args,
* and the argument stack should not be capped/extended at all.
* Get operations: no coercion, returns default value for invalid
* indices and invalid value types.
*
* duk_get_undefined() and duk_get_null() would be pointless and
* are not included.
comment: use locale specific formatting if available
label: code-design
External duk_config.h provides platform/compiler/OS dependent
* typedefs and macros, and DUK_USE_xxx config options so that
* the rest of Duktape doesn't need to do any feature detection.
internal: don't care about fixed/dynamic nature
* Property access
*
* The basic function assumes key is on stack. The _string variant takes
* a C string as a property name, while the _index variant takes an array
* index as a property name (e.g. 123 is equivalent to the key "123").
* Debugging
64-bit byteswap, same operation independent of target endianness.
* Type checks
*
* duk_is_none(), which would indicate whether index it outside of stack,
* is not needed; duk_is_valid_index() gives the same information.
sort array indices, use with DUK_ENUM_ARRAY_INDICES_ONLY
force change if possible, may still fail for e.g. virtual properties
Millisecond count constants.
used by packed duk_tval, assumes sizeof(void *) == 4
set value (given on value stack)
Used to represent invalid index; if caller uses this without checking,
* this index will map to a non-existent stack entry. Also used in some
* API calls as a marker to denote "no value".
* Module helpers: put multiple function or constant properties
raw void pointer
Flags for duk_push_thread_raw()
* ===============
* Duktape authors
* ===============
*
* Copyright
* =========
*
* Duktape copyrights are held by its authors. Each author has a copyright
* to their contribution, and agrees to irrevocably license the contribution
* under the Duktape ``LICENSE.txt``.
*
* Authors
* =======
*
* Please include an e-mail address, a link to your GitHub profile, or something
* similar to allow your contribution to be identified accurately.
*
* The following people have contributed code, website contents, or Wiki contents,
* and agreed to irrevocably license their contributions under the Duktape
* ``LICENSE.txt`` (in order of appearance):
*
* * Sami Vaarala <sami.vaarala@iki.fi>
* * Niki Dobrev
* * Andreas \u00d6man <andreas@lonelycoder.com>
* * L\u00e1szl\u00f3 Lang\u00f3 <llango.u-szeged@partner.samsung.com>
* * Legimet <legimet.calc@gmail.com>
* * Karl Skomski <karl@skomski.com>
* * Bruce Pascoe <fatcerberus1@gmail.com>
* * Ren\u00e9 Hollander <rene@rene8888.at>
* * Julien Hamaide (https://github.com/crazyjul)
* * Sebastian G\u00f6tte (https://github.com/jaseg)
*
* Other contributions
* ===================
*
* The following people have contributed something other than code (e.g. reported
* bugs, provided ideas, etc; roughly in order of appearance):
*
* * Greg Burns
* * Anthony Rabine
* * Carlos Costa
* * Aur\u00e9lien Bouilland
* * Preet Desai (Pris Matic)
* * judofyr (http://www.reddit.com/user/judofyr)
* * Jason Woofenden
* * Micha\u0142 Przyby\u015b
* * Anthony Howe
* * Conrad Pankoff
* * Jim Schimpf
* * Rajaran Gaunker (https://github.com/zimbabao)
* * Andreas \u00d6man
* * Doug Sanden
* * Josh Engebretson (https://github.com/JoshEngebretson)
* * Remo Eichenberger (https://github.com/remoe)
* * Mamod Mehyar (https://github.com/mamod)
* * David Demelier (https://github.com/markand)
* * Tim Caswell (https://github.com/creationix)
* * Mitchell Blank Jr (https://github.com/mitchblank)
* * https://github.com/yushli
* * Seo Sanghyeon (https://github.com/sanxiyn)
* * Han ChoongWoo (https://github.com/tunz)
* * Joshua Peek (https://github.com/josh)
* * Bruce E. Pascoe (https://github.com/fatcerberus)
* * https://github.com/Kelledin
* * https://github.com/sstruchtrup
* * Michael Drake (https://github.com/tlsa)
* * https://github.com/chris-y
* * Laurent Zubiaur (https://github.com/lzubiaur)
* * Ole Andr\u00e9 Vadla Ravn\u00e5s (https://github.com/oleavr)
*
* If you are accidentally missing from this list, send me an e-mail
* (``sami.vaarala@iki.fi``) and I'll fix the omission.
InternalError
Value types, used by e.g. duk_get_type()
comment: Duktape specific error codes (must be 8 bits at most, see duk_error.h)
label: code-design
no value, e.g. invalid index
* Stack manipulation (other than push/pop)
Byteswap an IEEE double in the duk_double_union from host to network
* order. For a big endian target this is a no-op.
prefer string
external use
Flags for duk_push_string_file_raw()
Duktape debug protocol version used by this build.
comment: DUK_COMPILE_xxx bits 0-2 are reserved for an internal 'nargs' argument
* (the nargs value passed is direct stack arguments + 1 to account for an
* internal extra argument).
label: code-design
fixed or dynamic, garbage collected byte buffer
* Thread management
* Double NaN manipulation macros related to NaN normalization needed when
* using the packed duk_tval representation. NaN normalization is necessary
* to keep double values compatible with the duk_tval format.
*
* When packed duk_tval is used, the NaN space is used to store pointers
* and other tagged values in addition to NaNs. Actual NaNs are normalized
* to a specific quiet NaN. The macros below are used by the implementation
* to check and normalize NaN values when they might be created. The macros
* are essentially NOPs when the non-packed duk_tval representation is used.
*
* A FULL check is exact and checks all bits. A NOTFULL check is used by
* the packed duk_tval and works correctly for all NaNs except those that
* begin with 0x7ff0. Since the 'normalized NaN' values used with packed
* duk_tval begin with 0x7ff8, the partial check is reliable when packed
* duk_tval is used. The 0x7ff8 prefix means the normalized NaN will be a
* quiet NaN regardless of its remaining lower bits.
*
* The ME variant below is specifically for ARM byte order, which has the
* feature that while doubles have a mixed byte order (32107654), unsigned
* long long values has a little endian byte order (76543210). When writing
* a logical double value through a ULL pointer, the 32-bit words need to be
* swapped; hence the #ifdefs below for ULL writes with DUK_USE_DOUBLE_ME.
* This is not full ARM support but suffices for some environments.
either not a NaN
convert time value to local time
not directly applicable, byte order differs from a double
end 'extern "C"' wrapper
* Object operations
set writable (effective if DUK_DEFPROP_HAVE_WRITABLE set)
UnsupportedError
comment: Internal API call flags, used for various functions in this file.
* Certain flags are used by only certain functions, but since the flags
* don't overlap, a single flags value can be passed around to multiple
* functions.
*
* The unused top bits of the flags field are also used to pass values
* to helpers (duk__get_part_helper() and duk__set_part_helper()).
*
* (Must be in-sync with genbuiltins.py.)
label: code-design
There are currently no native functions to yield/resume, due to the internal
* limitations on coroutine handling. These will be added later.
Concrete macros for NaN handling used by the implementation internals.
* Chosen so that they match the duk_tval representation: with a packed
* duk_tval, ensure NaNs are properly normalized; with a non-packed duk_tval
* these are essentially NOPs.
(internal) no source string on stack
* Function (method) calls
plain
Ecmascript string: CESU-8 / extended UTF-8 encoded
internal flag: don't zero allocated buffer
use strict (outer) context for global, eval, or function code
in non-packed representation we don't care about which NaN is used
* Union for accessing double parts, also serves as packed duk_tval
include date part in string conversion result
internal flag: dynamic buffer
Ecmascript null
enumerate non-numerable properties in addition to enumerable
comment: XXX: replace with RangeError?
label: code-design
* Push operations
*
* Push functions return the absolute (relative to bottom of frame)
* position of the pushed value for convenience.
*
* Note: duk_dup() is technically a push.
string
* ROM pointer compression
* Union to access IEEE double memory representation, indexes for double
* memory representation, and some macros for double manipulation.
*
* Also used by packed duk_tval. Use a union for bit manipulation to
* minimize aliasing issues in practice. The C99 standard does not
* guarantee that this should work, but it's a very widely supported
* practice for low level manipulation.
*
* IEEE double format summary:
*
* seeeeeee eeeeffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff
* A B C D E F G H
*
* s sign bit
* eee... exponent field
* fff... fraction
*
* See http://en.wikipedia.org/wiki/Double_precision_floating-point_format.
*
* NaNs are represented as exponent 0x7ff and mantissa != 0. The NaN is a
* signaling NaN when the highest bit of the mantissa is zero, and a quiet
* NaN when the highest bit is set.
*
* At least three memory layouts are relevant here:
*
* A B C D E F G H Big endian (e.g. 68k) DUK_USE_DOUBLE_BE
* H G F E D C B A Little endian (e.g. x86) DUK_USE_DOUBLE_LE
* D C B A H G F E Mixed/cross endian (e.g. ARM) DUK_USE_DOUBLE_ME
*
* ARM is a special case: ARM double values are in mixed/cross endian
* format while ARM duk_uint64_t values are in standard little endian
* format (H G F E D C B A). When a double is read as a duk_uint64_t
* from memory, the register will contain the (logical) value
* E F G H A B C D. This requires some special handling below.
*
* Indexes of various types (8-bit, 16-bit, 32-bit) in memory relative to
* the logical (big endian) order:
*
* byte order duk_uint8_t duk_uint16_t duk_uint32_t
* BE 01234567 0123 01
* LE 76543210 3210 10
* ME (ARM) 32107654 1032 01
*
* Some processors may alter NaN values in a floating point load+store.
* For instance, on X86 a FLD + FSTP may convert a signaling NaN to a
* quiet one. This is catastrophic when NaN space is used in packed
* duk_tval values. See: misc/clang_aliasing.c.
* Helper macros for reading/writing memory representation parts, used
* by duk_numconv.c and duk_tval.h.
string conversion: use 'T' instead of ' ' as a separator
Ecmascript number: double
TypeError
Support array for ROM pointer compression. Only declared when ROM
* pointer compression is active.
comment: Although extra/top could be an unsigned type here, using a signed type
* makes the API more robust to calling code calculation errors or corner
* cases (where caller might occasionally come up with negative values).
* Negative values are treated as zero, which is better than casting them
* to a large unsigned number. (This principle is used elsewhere in the
* API too.)
label: code-design
* Misc conversion
Ecmascript object: includes objects, arrays, functions, threads
URIError
all doubles are considered normalized
AUTHORS.rst
day within month: 0 to 30
setter: call is a time setter (affects hour, min, sec, ms); otherwise date setter (affects year, month, day-in-month)
(internal) no filename on stack
compile eval code (instead of global code)
One problem with this macro is that expressions like the following fail
* to compile: "(void) duk_error(...)". But because duk_error() is noreturn,
* they make little sense anyway.
set setter (given on value stack)
prefer number, unless input is a Date, in which
* case prefer string (E5 Section 8.12.8)
Part indices for internal breakdowns. Part order from DUK_DATE_IDX_YEAR
* to DUK_DATE_IDX_MILLISECOND matches argument ordering of Ecmascript API
* calls (like Date constructor call). Some functions in duk_bi_date.c
* depend on the specific ordering, so change with care. 16 bits are not
* enough for all parts (year, specifically).
*
* (Must be in-sync with genbuiltins.py.)
E == 0x7ff, F == 8 => normalized NaN
Enumeration flags for duk_enum()
year
* Other state related functions
user-id of owner
time of last data modification
file size, in bytes
device type, for special file inode
** Factory of directory iterators
** Get symbolic link information using lstat.
blocks allocated for file
**
push member value and return
next entry
lkmode valid values are:
LK_LOCK Locks the specified bytes. If the bytes cannot be locked, the program immediately tries again after 1 second. If, after 10 attempts, the bytes cannot be locked, the constant returns an error.
LK_NBLCK Locks the specified bytes. If the bytes cannot be locked, the constant returns an error.
LK_NBRLCK Same as _LK_NBLCK.
LK_RLCK Same as _LK_LOCK.
LK_UNLCK Unlocks the specified bytes, which must have been previously locked.
Regions should be locked only briefly and should be unlocked before closing a file or exiting the program.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__locking.asp
** Utility functions
device inode resides on
** Convert the inode protection mode to a string.
** Creates a link.
** @param #1 Object to link to.
** @param #2 Name of link.
** @param #3 True if link is symbolic (optional).
Lua 5.3
group-id of owner
** Convert the inode protection mode to a permission list.
comment: number of hard links to the file
label: documentation
first entry
** Removes a directory.
** @param #1 Directory path.
** Assumes the table is on top of the stack.
MAX_PATH seems to be 260. Seems kind of small. Is there a better one?
** Get file information using stat.
time of last access
** Creates a directory.
** @param #1 Directory path.
Passing (NULL, 0) is not guaranteed to work. Use a temp buffer and size instead.
** Closes directory iterators
Linux, Solaris and HP-UX
** Check if the given element on the stack is a file and returns it.
inode protection mode
AIX
time of last file status change
** Creates directory metatable.
** This function changes the working (current) directory
Define 'getcwd' for systems that do not implement it
For MAXPATHLEN:
** Locks a file.
** @param #1 File handle.
** @param #2 String with lock mode ('w'rite, 'r'ead).
** @param #3 Number with start position (optional).
** @param #4 Number with length (optional).
stores all members in table on top of the stack
** Set access time and modification values for file
** LuaFileSystem
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
**
** File system manipulation library.
** This library offers these functions:
** lfs.attributes (filepath [, attributename])
** lfs.chdir (path)
** lfs.currentdir ()
** lfs.dir (path)
** lfs.lock (fh, mode)
** lfs.lock_dir (path)
** lfs.mkdir (path)
** lfs.rmdir (path)
** lfs.setmode (filepath, mode)
** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts
** lfs.touch (filepath [, atime [, mtime]])
** lfs.unlock (fh)
**
** $Id: lfs.c,v 1.61 2009/07/04 02:10:16 mascarenhas Exp $
** Directory iterator
** Get file or symbolic link information
creates a table if none is given
** Creates lock metatable.
optimal file system I/O blocksize
no more entries => close directory
Method table
inode's number
member not found
Define 'strerror' for systems that do not implement it
permssions string
** This function returns the current directory
** If unable to get the current directory, it returns nil
** and a string describing the error
Metamethods
** Unlocks a file.
** @param #1 File handle.
** @param #2 Number with start position (optional).
** @param #3 Number with length (optional).
set to current date/time
** LuaFileSystem
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
**
** $Id: lfs.h,v 1.5 2008/02/19 20:08:23 mascarenhas Exp $
Define 'chdir' for systems that do not implement it
***********************************************************************
* lsqlite3 *
* Copyright (C) 2002-2016 Tiago Dionizio, Doug Currie *
* All rights reserved. *
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
* Author : Doug Currie <doug.currie@alum.mit.edu> *
* Library : lsqlite3 - an SQLite 3 database binding for Lua 5 *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
***********************************************************************
push error message
db sql svm_ud reg[db_lud] svm_lud db --
compile time features
error codes
Version number of this library
safety measures for userdata field to be present in the stack
From: Wolfgang Oertl
When using lsqlite3 in a multithreaded environment, each thread has a separate Lua
environment, but full userdata structures can't be passed from one thread to another.
This is possible with lightuserdata, however. See: lsqlite_open_ptr().
not yet created? - shouldn't happen in finalize function
use result if there was no error
make sure we have an userdata field (even if nil)
backup structure
register (local) sqlite metatable
top SQL function being called
Source database name
i think it is OK to use assume that using a light user data
** as an entry on LUA REGISTRY table will be unique
save user data
things done properly (SQLite + Lua SQLite)
** this should never happen
set update_hook handler
clear busy handler
column names not known at this point
'trap' userdata - nil extra parameters
userdata is a no-no as it
will be garbage-collected
disable extension loading
push metatable
rollback_hook callback
** =======================================================
** Virtual Machine - generic info
** =======================================================
sqlite3_step info
push nil
sql functions stack usage
metatable.__index = metatable
sdb_vm *svm =
enable extension loading
context table
!
set sqlite's metatable to itself - set as readonly (__newindex)
failed to open database
clear commit_hook handler
true when step succeeds
so, assert(load_extension(...)) works
#if !defined(LSQLITE_OMIT_UPDATE_HOOK) || !LSQLITE_OMIT_UPDATE_HOOK
virtual machine
target db
** Params: db, sql
** returns: code, compiled length or error message
to prevent referenced databases from being garbage collected while bu is live
set trace handler
lua_settop(L,3) above means we don't need: lua_pushvalue(L,3);
unpacked version of db:rows
information about database
Lua 5.3 introduced an integer type, but depending on the implementation, it could be 32
** or 64 bits (or something else?). This helper macro tries to do "the right thing."
reuse context userdata value
stack:
** 3: callback function
** 4: userdata
** 5: column names
** 6: reusable column values
set commit_hook handler
save registered function in db function list
add source and target dbs to table at indices 1 and 2
stepvm may change svm->vm if re-prepare is needed
finalize and check for errors
key: vm; val: sql text
virtual machine information
free allocated memory
update_hook callback
luaL_typerror always used with arg at ndx == NULL
put table in registry with key lightuserdata bu
{"__tostring", dbbu_tostring },
not yet created?
push context - used to set results
else ignore if already finished
column types
create table from registry
** When creating database handles, always creates a `closed' database handle
** before opening the actual database; so, if there is a memory error, the
** database is not left opened.
**
** Creates a new 'table' and leaves it in the stack
db,sql is on top of stack for call to newvm
** trace callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata, sql
setup lua callback call
set context
clear update_hook handler
Authorizer Action Codes
** Register a normal function
** Params: db, function name, number arguments, [ callback | step, finalize], user data
** Returns: true on sucess
**
** Normal function:
** Params: context, params
**
** Aggregate function:
** Params of step: context, params
** Params of finalize: context
already finished
comment: cleanup context
label: code-design
column values table
clear trace handler
comment: if there was a timeout callback registered, it is now
** invalid/useless. free any references we may have
label: code-design
save the setp/normal function callback
call lua function
clear rollback_hook handler
** update_hook callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata, {one of SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE},
** database name, table name (containing the affected row), rowid of the row
** =======================================================
** User Defined Functions - Context Methods
** =======================================================
** Params: db, sql, callback, user
** returns: code [, errmsg]
**
** Callback:
** Params: user, number of columns, values, names
** Returns: 0 to continue, other value will cause abort
ignore closed vms
sqlite3_db_filename may return NULL, in that case Lua pushes nil...
** =======================================================
** Database (internal management)
** =======================================================
invalidate context
terminator
close database
ignore any error generated by this function
i think it is OK to use assume that using a light user data
** as an entry on LUA REGISTRY table will be unique
Destination database name
get callback
associated lua state
conversion warning: int64 -> luaNumber
create and leave in stack
** =======================================================
** Virtual Machine - Bind
** =======================================================
database handle is currently `closed'
number of opcodes
associated database handle
** =======================================================
** Database Methods
** =======================================================
pop vm table
** =======================================================
** Virtual Machine - getters
** =======================================================
function to call
create_collation; contributed by Thomas Lauer
number of columns in result
get callback user data
minimal mem usage
remove entry in database table - no harm if not present in the table
comment: cleanup temporary only tables?
label: code-design
vm already in the stack
scalar function to be called
** callback params: context, values...
db sql svm_ud reg[db_lud] svm_lud --
luaL_openlib always used with name == NULL
comment: maybe an alternative way to allocate memory should be used/avoided
label: code-design
set progress callback
references
sqlite database handle
to use as C user data so i know what function sqlite is calling
called with db,sql text on the lua stack
commit_hook callback
'free' all references
ensure there is enough space in the stack
set metatable
to keep track of 'open' virtual machines
** busy handler:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata, number of tries
** returns: 0 to return immediatly and return SQLITE_BUSY, non-zero to try again
busy callback
(reg[db_lud])[svm_lud] = db ; set the db for this vm
columns names
this should not happen since sqlite3_prepare_v2 will not set ->vm on error
set rollback_hook handler
#if !defined(SQLITE_OMIT_PROGRESS_CALLBACK) || !SQLITE_OMIT_PROGRESS_CALLBACK
free associated memory with created functions
Online Backup API
progress handler
sqlite_step specific return values
From: Wolfgang Oertl
When using lsqlite3 in a multithreaded environment, each thread has a separate Lua
environment, but full userdata structures can't be passed from one thread to another.
This is possible with lightuserdata, however. See: db_get_ptr().
add constants to global table
temporary vm used in db:rows
references to associated lua values
comment: clean things up
label: code-design
Thanks to Wolfgang Oertl...
** =======================================================
** Database Virtual Machine Operations
** =======================================================
database handle already in the stack - return it
trace callback
valid as soon as statement prepared
** Lua 5.2
no callbacks
return
safety measure
ignore closed databases
close all used handles
compatibility names (added by request)
default args to nil, and exclude extras
** progress handler:
** Params: database, number of opcodes, callback function, userdata
**
** callback function:
** Params: userdata
** returns: 0 to return immediatly and return SQLITE_ABORT, non-zero to continue
user data
luaL_register used once, so below expansion is OK for this case
db sql svm_ud reg[db_lud] --
end of Online Backup API
Source database handle
set busy handler
** =======================================================
** General library functions
** =======================================================
abort by default
push params
Destination database handle
** Registering SQL functions:
** commit_hook callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata
** Returned value: Return false or nil to continue the COMMIT operation normally.
** return true (non false, non nil), then the COMMIT is converted into a ROLLBACK.
remove entry in lua registry table
** rollback hook callback:
** Params: database, callback function, userdata
**
** callback function:
** Params: userdata
remove metatable from stack
** Lua 5.3
=======================================================
db sql svm_ud db_lud --
remove it from registry
** callback functions used when calling registered sql functions
traced sql statement
add an entry on the database table: svm -> db to keep db live while svm is live
source db
column values
file open flags
db sql svm_ud --
free associated virtual machines
** =======================================================
** Register functions
** =======================================================
update_hook database name
This is the only API function that runs sqlite3SafetyCheck regardless of
* SQLITE_ENABLE_API_ARMOR and does almost nothing (without an SQL
* statement)
remove table from registry
register metatable functions
should be defined in rockspec, but just in case...
leave key in the stack
total number of rows in result
Last change: revised for Lua 5.1.5
EOF
$Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $
www.lua.org/</A>
EOF
$Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $
www.lua.org/</A>
(S)
======================================================================
(l)
private part
$Id: manual.of,v 1.49.1.2 2012/01/13 20:23:26 roberto Exp $
(n)
(u) number of upvalues
Last change: revised for Lua 5.1.5
get global 'f'
* all.c -- Lua core, libraries and interpreter in a single file
lua.hpp
Lua header files for C++
<<extern "C">> not supplied automatically because Lua also compiles as C++
* min.c -- a minimal Lua interpreter
* loads stdin only with minimal error handling.
* no interaction, and no standard library, only a "print" function.
* The code below can be used to make a Lua core that does not contain the
* parsing modules (lcode, llex, lparser), which represent 35% of the total core.
* You'll only be able to load binary files and strings, precompiled with luac.
* (Of course, you'll have to build luac with the original parsing modules!)
*
* To use this module, simply compile it ("make noparser" does that) and list
* its object file before the Lua libraries. The linker should then not load
* the parsing modules. To try it, do "make luab".
*
* If you also want to avoid the dump module (ldump.o), define NODUMP.
* #define NODUMP
GC values are expressed in Kbytes: #bytes/2^10
function to be called
stack overflow
data to `f_Ccall'
may call tag method
** push functions (C -> stack)
explicit test for incompatible code
invalid option
ensure that true is 1
** access functions (stack -> C)
conversion failed?
** `load' and `call' functions (run Lua code)
signal it
pop value
** set functions (stack -> Lua)
use global table as environment
previous call may reallocate the stack
push function
** Execute a protected C call.
pop index and value
`subtract' index (index is negative)
else n == 1; nothing to do
** Garbage-collection function
remove key
`luaV_tostring' may create a new string
pseudo-indices
** $Id: lapi.c,v 2.55.1.5 2008/07/04 18:41:18 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
** get functions (Lua -> stack)
no enclosing function?
data to `f_call'
** Execute a protected call.
comment: to avoid warnings
label: code-design
push empty string
no more elements
** miscellaneous functions
** basic stack manipulation
push only argument
end of cycle?
function upvalue?
** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
name already in use?
remove previous table
remove both metatables
is there a numeric field `n'?
push prefix
get registry.name
else try sizes[t]
remove table and value
no metafield?
remove it from list
use `sizes'
remove this nil
no stack frame?
put buffer before new value
free list of references
remove only metatable
binary file?
}======================================================
push last suffix
no metatable?
** $Id: lauxlib.c,v 1.159.1.3 2008/01/21 13:20:51 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
metatable(N).__mode = "kv"
copy upvalues to the top
This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
remove it from stack
sizes[t] = n
put nothing on stack
move library table to below upvalues
add new value into B stack
t[ref] = t[FREELIST_REF]
get first free element
remove from stack
return problematic part of the name
reopen in binary mode
convert a stack index to positive
do not count `self'
ref = t[FREELIST_REF]
leave previous value on top, but return 0
get info about it
get _LOADED[libname]
no free elements
create metatable
index of filename on the stack
store in register
use it
value is a userdata?
comment: to avoid warnings
label: code-design
continue after `p'
field has a non-table value?
else error
set new table into field
remove `sizes'
remove _LOADED table
check function at level
put it there
does it have the correct mt?
(t[FREELIST_REF] = t[ref])
new table for field
check whether lib already exists
Unix exec. file?
create it
push replacement in place of pattern
number of levels to concat
_LOADED[libname] = new table
no `size' table?
ignore results from `lua_load'
any free element?
does it have a metatable?
try global variable (and create one if it does not exist)
remove nil
** {======================================================
** Generic Buffer manipulation
** =======================================================
try t.n
registry.name = metatable
** {======================================================
** Load functions
** =======================================================
t[FREELIST_REF] = ref
skip first line
fit into buffer?
remove upvalues
`size' will be its own metatable
remove metatable and metafield
create new reference
remove previous result
close file (even in case of errors)
get correct metatable
** {======================================================
** Error-report functions
** =======================================================
else, no information available...
error is in the self argument itself?
`nil' has a unique fixed reference
not found?
** {======================================================
** getn-setn: size for arrays
** =======================================================
no such field?
is there info?
comment: avoid extra test when d is not 0
label: test
skip eventual `#!...'
current position in buffer
extra error code for `luaL_load'
number of strings in the stack (level)
** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
compatibility with ref system
}======================================================
no op!
compatibility only
pre-defined references
** {======================================================
** Generic Buffer manipulation
** =======================================================
** ===============================================================
** some useful macros
** ===============================================================
function to be called
change environment of current thread
set global _VERSION
and initial value
weaktable[m] = true
skip trailing spaces
metatable(w).__mode = "kv"
return nil plus error message
return status + all results
number of elements
error object is a string?
}======================================================
set global _G
`newproxy' needs a weaktable as upvalue
put error function under function to be called
'normal' (it resumed another coroutine)
add extra info
pop result
move function to top
create proxy
running
standard conversion
metatable is valid; get it
function, eventual name, plus one reserved slot
** $Id: lbaselib.c,v 1.191.1.6 2008/02/14 16:46:22 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
return false + error message
move yielded values
no metatable
open lib into global table
it is running
new table `w'
return the thread's global env.
set global `newproxy'
comment: to avoid warnings
label: code-design
value to print
... and mark `m' as a valid metatable
`ipairs' and `pairs' need auxiliary functions as upvalues
else not a number
save string in a reserved stack slot
push arg[i] (avoiding overflow problems)
return generator,
move error message
error flag
to check if weaktable[metatable(u)] == true
state,
next value
propagate error
returns either __metatable field (if present) or metatable
is a C function?
at least one valid digit?
create a 2nd argument if there isn't one
put before error message
call it
some error occured
return true + `resume' returns
move function from L to NL
suspended
** Reader for generic `load' function: `lua_load' uses the
** stack for internal stuff, so the reader cannot change the
** stack top. Instead, it keeps its resulting string in a
** reserved slot inside the stack.
n <= 0 means arith. overflow
empty range
remove value
no invalid trailing characters?
comment:
** If your system does not support `stdout', you can just remove this function.
** If you need, you can define your own `print' function, following this
** model but changing `fputs' to put the strings at a proper place
** (a console window or a log file, for instance).
label: code-design
initial state
OK?
is there a metafield?
push arg[i + 1...e]
does it have frames?
number of arguments
create a new metatable `m' ...
** {======================================================
** Coroutine library
** =======================================================
`w' will be its own metatable
add extra information?
use its value
main thread is not a coroutine
get result
get function
position after whole expression
operand must be on the `stack'
operand must be on the 'stack'
insert last jump in `f' list
find last element
free registers with list values
invalid var kind to store
jump to default target
put this jump in `t' list
insert last jump in `t' list
else go through
exp is already in a register
end of list
turn offset into absolute position
cannot happen
always false; do nothing
not found
remove previous OP_NOT
put new instruction in code array
interchange true and false lists
constant not found; create a new entry
nothing to do...
constant fit in RK operand?
cannot patch other instructions
those instructions may be jump targets
position of an eventual LOAD true
positions are already clean
there is one value available (somewhere)
o1 <==> o2
cannot use nil as key; instead use table itself to represent nil
do not attempt to divide by 0
point to itself represents end of list
reg. is not a local?
default
no jumps to current position?
** returns current `pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block).
save corresponding line information
do not attempt to produce NaN
exchange args to replace by `<' or `<='
expression is an open function call?
else no optimization
cannot operate on non-numeric constants
** check whether list has any jump that do not produce a value
** (or produce an inverted value)
position of an eventual LOAD false
keep them on hold
constant fit in argC?
save list of jumps to here
not a constant in the right range: put it in a register
always true; do nothing
no constant folding for 'len'
function start?
`pc' will change
can connect both?
no register to put value or register already has the value
put value on it
can relocate its simple result
pc of last jump
list must be closed
cannot operate on constants
** $Id: lcode.c,v 2.25.1.5 2011/01/31 14:53:16 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
** grep "ORDER OPR" if you change these enums
** Marks the end of a patch list. It is an invalid value both as an absolute
** address, and as a list link (would link an element to itself).
** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
set hooks
external hook?
set new hook
out of range?
level 0 may be this own function
size of the first part of the stack
comment: too many levels
label: code-design
level out of range
message is not a string
cannot touch C upvalues from Lua
turn off hooks
no metatable
remove eventual returns
return table
size of the second part of the stack
comment: no more than `LEVELS2' more levels?
label: code-design
** $Id: ldblib.c,v 1.104.1.4 2009/08/04 18:50:18 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
remove hook table
is there a name?
C function or tail call
find last levels
keep going
still before eventual `...'
get hook
main?
do the jump
only active lua functions have current-line information
level found?
a Lua function?
affect all registers above base
change register `a'
move from `b' to `a'
level is of a lost tail call?
does it jump?
global index
is there an error handling function?
invalid option
invalid instruction after an open call
Lua function?
not full check and jump is forward and do not skip `lastpc'?
is Lua code?
pop value
not found
add file:line information
skip lost tail calls
skip the '>'
calling function
no tail call?
function is not a Lua function?
push function
points to final return (a `neutral' instruction)
pop function
is 'n' inside 'ci' stack?
space for results
calling function is not Lua (or is unknown)
check skip
is a local?
set registers from `a' to `b'
at least two operands
turn off hooks?
at least one result (control variable)
b = num. returns
check that it does not jump to a setlist count; this
is tricky, because the count from a previous setlist may
have the same value of an invalid setlist; so, we must
go all the way back to the first of them (if any)
c = num. returns
** $Id: ldebug.c,v 2.29.1.6 2008/05/08 16:56:26 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
upvalue index
no useful name can be found
move argument
try symbolic execution
get name for `b'
key index
** this function can be called asynchronous (e.g. during a signal)
if 'j' is even, previous value is not a setlist (even if
it looks like one)
}======================================================
do not 'execute' these pseudo-instructions
affect all regs above its base
handled by lua_getinfo
only ANSI way to check whether a pointer points to an array
no useful name found
no such level
is a local variable in a Lua function
call it
check its jump
** {======================================================
** Symbolic Execution and code checker
** =======================================================
go through
first operand is wrong
stores position of last instruction that changed `reg'
tracing?
** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
error while handing stack error
tag method is the new function to be called
** {======================================================
** Error-recovery functions
** =======================================================
comment: compat. with old-style vararg?
label: code-design
number of extra arguments
add `arg' parameter
correct 'pc'
yielding?
0 iff wanted == LUA_MULTRET
`func' is not a function?
move results to correct place
double size is enough?
** Execute a protected parser.
initialize eventual upvalues
an error occurred?
comment: put extra arguments into `arg' table
label: code-design
close eventual pending closures
tail call; no debug information about it
Lua function?
finish interrupted execution of `OP_CALL'
final position of first argument
do the actual call
Open a hole inside the stack at `func'
next call may change stack
tail calls
start coroutine?
restore savedpc
hooks assume 'pc' is already incremented
protect stack slots below
** Call a function (C or Lua). The function to be called is at *func.
** The arguments are on the stack, right after the function.
** When returns, all the results are on the stack, starting at the original
** function position.
restore old error handler
res == final position of 1st result
error message on current top
can `undo' overflow?
move fixed parameters to final position
starting point
error?
ensure minimum stack size
yielded inside a hook: just continue its execution
mark thread as `dead'
first fixed argument
overflow while handling overflow?
error code
now `enter' new function
restore base
vararg function
is a Lua function?
** $Id: ldo.c,v 2.38.1.4 2012/01/18 02:27:10 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
create `arg' table
}======================================================
store counter in field `n'
previous call may change stack
resuming from previous yield
complete it...
data to `f_parser'
buffer to be used by the scanner
`common' yield?
Lua function? prepare its call
chain new error handler
there was an overflow?
check the `function' tag method
no varargs?
chain list of long jump buffers
call it
if is a C function, call it
and correct top if not multiple results
previous call may change the stack
cannot call hooks inside a hook
results from luaD_precall
** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
did a call to a C function
comment: type of protected functions, to be ran by `runprotected'
label: code-design
initiated a call to a Lua function
C funtion yielded
** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
cannot happen
** dump Lua function as precompiled chunk
include trailing '\0'
comment: is it dead?
label: code-design
current value lives in the stack
found a corresponding upvalue?
is it open?
not found: create a new one
free upvalue
chain it in the proper position
** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
remove from `uvhead' list
** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found.
is variable active?
not found
ressurect it
remove from open list
double link it in `uvhead' list
remove from `open' list
now current value lives here
link upvalue into `gcroot' list
** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
remove entry from table
closed upvalues need barrier
restore threshold
clear bits
mark nested protos
is there a weak mode?
keep it gray
link `curr' at the end of `tmudata' list
mark basic metatables (again)
end sweep phase
** The next function tells whether a key or value can be cleared from
** a weak table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for userdata
** being finalized, keep them in keys, but not in values
strings are `values', so are never weak
make global table be traversed before main stack
free all string lists
** traverse one gray object, turning it to black.
** Returns `quantity' traversed.
mask to collect all elements
first estimate
creates a circular list
- lim/g->gcstepmul;
must keep invariant?
** $Id: lgc.c,v 2.38.1.2 2011/03/18 18:05:38 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
don't need finalization
comment: table is too big
label: code-design
may be marked, if left from previous GC
comment: remark occasional upvalues of (maybe) dead threads
label: code-design
do not touch the stacks
mark running thread
sweep open upvalues of each thread
mark as white just to avoid other barriers
** Call all GC tag methods
remark gray again
adjust first
number of `ci' in use
start a new collection
total size of userdata to be finalized
move `dead' udata that need finalization to list `tmudata'
no more `gray' objects
is really weak?
don't mind
value was collected?
must erase `curr'
must be cleared after GC, ...
open upvalues are never black
remove value ...
mark its upvalues
dead key; remove it
... so put in the appropriate list
mark root set
end sweep-string phase
reset sweep marks to sweep all elements (returning them to white)
traverse objects cautch by write barrier and by 'remarkupvals'
make it white (for next cycle)
make table gray (again)
link upvalue into `rootgc' list
must call its gc method
return it to `root' list
finish any pending sweep phase
finish mark phase
end collection
flip current white
mark upvalue names
check size of buffer
** clear collected entries from weaktables
separate userdata to be finalized
handling overflow?
remove collected objects from weak tables
restore hooks
list is empty?
comment: not dead?
label: code-design
is the first element of the list?
get first element
nothing more to sweep?
non-empty entry?
** All marks are conditional because a GC may happen while the
** prototype is still being created
still big enough...
remove value
no limit
closed?
check size of string hash
reset other collector lists
mark `preserved' userdata
remark weak tables
avoid GC steps
stop debug hooks during GC tag method
mark literals
remove empty entries
udata are never gray
mark local-variable names
buffer too big?
restore invariant
table is weak?
don't bother with them
remove udata from `tmudata'
part of stack in use
lua_checkmemory(L);
last element?
sweep phase: sweep it (turning it into white)
remark, to propagate `preserveness'
comment:
** some userful bit tricks
label: code-design
** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
comment:
** Layout for bit use in `marked' field:
** bit 0 - object is white (type 0)
** bit 1 - object is white (type 1)
** bit 2 - object is black
** bit 3 - for userdata: has been finalized
** bit 3 - for tables: has weak keys
** bit 4 - for tables: has weak values
** bit 5 - object is fixed (should not be collected)
** bit 6 - object is "super" fixed (only the main thread)
label: code-design
** Possible states of the Garbage Collector
** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $
** Initialization of libraries for lua.c
** See Copyright Notice in lua.h
create (and set) default files
** {======================================================
** READ
** =======================================================
calls to Lua API may change this value
how much to read
close it
** $Id: liolib.c,v 2.73.1.4 2010/05/14 15:33:51 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
pop 'popen'
push nil instead
not a file
until end of count or eof
file is already closed?
open library
do not include `eol'
file methods
** function to (not) close the standard files stdin, stdout, and stderr
line
"result" to be removed
to return 1 result
copy environment
ensure stack space for all results and for auxlib's buffer
error
EOF
close/not close file when finished
will iterate over default input
create environment for 'popen'
file handle is currently `closed'
pop environment for default files
return current value
** When creating file handles, always creates a `closed' file handle
** before opening the actual file; so, if there is a memory error, the
** file is not left opened.
close function for default files
create metatable for file handles
no arguments?
number
generator created file?
push metatable
set fenv for 'popen'
eof?
number of chars actually read
read MAX_SIZE_T chars
}======================================================
create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close)
read at least an `eol'
read fails
** function to close regular files
always success
ignore closed files
remove last result
metatable.__index = metatable
set it
make sure argument is a file
file
still have to read `n' chars
** this function has a separated environment, which defines the
** correct __close for 'popen' files
try to read that much each time
optimization: could be done exactly as for strings
** function to close 'popen' files
close buffer
cannot read more than asked
check whether read something
check that it's a valid file handle
read next token
skip 2nd `]'
LUA_NUMBER
skip 2nd `['
ORDER RESERVED
reserved word?
`E'?
read first char
...
\xxx
skip delimiter
follow locale for decimal point
reserved word
handles \\, \", \', and \?
try updated decimal separator
reserved words are never collected
optional exponent sign
else is a comment
identifier or reserved word
..
try to update decimal point separator
else short comment
initialize buffer
undo change (for error message)
string starts with a newline?
no look-ahead token
** $Id: llex.c,v 2.20.1.2 2009/11/23 14:58:22 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
will raise an error next loop
skip `\n\r' or `\r\n'
make sure `str' will not be collected
comment: to avoid warnings
label: code-design
comment: avoid warnings when `cont' is not used
label: code-design
entry for `str'
format error: try to update decimal point separator
single-char tokens (+ - / ...)
long comment
skip it
is there a look-ahead token?
use this one
format error with correct decimal point: no more options
do not save the `\'
avoid wasting space
`skip_sep' may dirty the buffer
and discharge it
go through
** =======================================================
** LEXICAL ANALYZER
** =======================================================
skip `\n' or `\r'
format error?
input line counter
input stream
current token
current source name
* WARNING: if you change the order of this enumeration,
* grep "ORDER RESERVED"
semantics information
other terminal symbols
** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
buffer for tokens
locale decimal point
look ahead token
line of last token `consumed'
number of reserved words
current character (charint)
array with token `names'
terminal symbols denoted by reserved words
`FuncState' is private to the parser
maximum length of a reserved word
** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
type to ensure maximum alignment
minimum size for string buffer
** conversion of pointer to integer
** this is for hashing only; there is no problem if the integer
** cannot hold the whole pointer value
comment:
** macro to control inclusion of some hard tests on stack reallocation
label: test
** type for virtual-machine instructions
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
maximum stack for a Lua function
minimum size for the string table (must be power of 2)
chars used as small naturals (so that `char' is reserved for characters)
result of a `usual argument conversion' over lua_Number
maximum value of an int (-2 for safety)
comment: to avoid warnings
label: code-design
internal assertions for in-house debugging
only upper limit
number of arguments
Number between 0 and 1
no arguments
** Open math library
** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
lower and upper limits
check number of arguments
int between `l' and `u'
int between 1 and `u'
the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX
cannot double it?
cannot grow even a little?
update only when everything else is OK
minimum size
** generic allocation routine.
still have at least one free place
** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
comment: to avoid warnings
label: code-design
** About the realloc function:
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
** (`osize' is the old size, `nsize' is the new size)
**
** Lua ensures that (ptr == NULL) iff (osize == 0).
**
** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
**
** * frealloc(ud, p, x, 0) frees the block `p'
** (in this specific case, frealloc must return NULL).
** particularly, frealloc(ud, NULL, 0, 0) does nothing
** (which is equivalent to free(NULL) in ANSI C)
**
** frealloc returns NULL if it cannot create or reallocate the area
** (any reallocation to an equal or smaller size cannot fail!)
comment: +1 to avoid warnings
label: code-design
** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
no errors?
remove file name
get _LOADED[modname]
_LOADED[name] = true
root not found
unable to load library
loader returned error message?
create new metatable
not found
** {========================================================================
** This is an implementation of loadlib based on the dlfcn interface.
** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
** as an emulation layer on top of native functions.
** =========================================================================
is table an initialized module?
package is already loaded
did it find module?
check loops
fill it with pre-defined loaders
unable to find function
use default
library loaded successfully
open failed
}======================================================
module did not set a value?
no entry yet; create one
does file exist and is readable?
look for last dot in module name
non-nil return?
get a loader
return nil, error message, and where
check whether table already has a _NAME field
this would be a rare case, but prevents crashing if it happens
** __gc tag method: calls library's `ll_unloadlib' function with the lib
** handle
try to open file
return the loaded function
error codes for ll_loadfunc
index of _LOADED table
set field `preload'
open lib into global table
** {======================================================
** Fallback for other systems
** =======================================================
return that file name
_LOADED table will be at index 2
mt.__index = _G
comment: to avoid warnings
label: code-design
put it in field `loaders'
module._M = module
error accumulator
auxiliary mark (for internal use)
module loaded successfully
_LOADED[name] = sentinel
function not found
skip separators
template
Mac appends a `_' before C function names
is it there?
_LOADED[name] = returned value
set field `cpath'
get calling function
library not found in this path
find next separator
replace ";;" by ";AUXMARK;" and then AUXMARK by default path
module
return function
run loaded module
error message accumulator
no; initialize it
pass name as argument to module
real error
create new type _LOADLIB
else must load it; iterate over available loaders
add entry to possible error message
** $Id: loadlib.c,v 1.52.1.4 2009/09/09 13:17:16 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
** This module contains an implementation of loadlib for Unix systems
** that have dlfcn, an implementation for Darwin (Mac OS X), an
** implementation for Windows, and a stub for other systems.
no more templates
create `package' table
try global variable (and create one if it does not exist)
check library in registry?
** {======================================================
** 'require' function
** =======================================================
set field `path'
remove path template
no environment variable?
error; error message is on stack top
store config information
use true as result
set field `loaded'
call it
separator for open functions in C libraries
_LOADED[modname] = new table
remove previous result
get option (a function)
remove original string
is root
prefix for open functions in C libraries
extra copy to be returned
set _PACKAGE as package name (full module name minus last part)
** {======================================================================
** Native Mac OS X / Darwin Implementation
** =======================================================================
mark library as closed
not found?
** {======================================================================
** This is an implementation of loadlib for Windows using native functions.
** =======================================================================
return 'package' table
** {======================================================
** 'module' function
** =======================================================
is there an entry?
remove 'gsub' result
accumulate it
create `loaders' table
maybe an hexadecimal constant?
skip the `@'
should be enough space for a `%p'
remove first char
** converts an integer to a "floating point byte", represented as
** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
** eeeee != 0 and (xxx) otherwise.
conversion failed
most common case
converts back
out = [string "string"]
out = "source", or "...source"
boolean true must be 1 !!
this function handles only `%d', `%c', %f, %p, and `%s' formats
expoent
must truncate?
ensures null termination
invalid trailing characters?
get last part of file name
** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
stop at first newline
ensures maximum alignment for strings
tags for values visible from Lua
the value (when closed)
information about local variables
Macros to access values
Macros to test type
Macros to set values
constants used by the function
to new object
to table
ensures maximum alignment for `local' udata
functions defined inside the function
** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
comment: first point where variable is dead
label: code-design
** for internal debug only
index to stack elements
double linked list (when open)
** Common header in struct form
** Union of all collectable objects
** String headers for string table
size of `p'
log2 of size of `node' array
upvalue names
from table to same table
from stack to (same) stack
masks for new-style vararg
1<<p means tagmethod(p) is not present
map from opcodes to source lines
size of `array' array
for chaining
array part
** Tables
size of `k'
** `module' operation for hashing (size is always a power of 2)
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
** Tagged Values
** Extra tags for non-values
** Upvalues
** Union of all Lua values
first point where variable is active
** different types of sets, according to destination
number of upvalues
any free position is before this position
** Closures
to stack (not from same stack)
** Function Prototypes
points to stack or to its own value
OP_LOADNIL
OP_UNM
OP_MOVE
OP_SELF
OP_VARARG
OP_RETURN
OP_JMP
OP_FORPREP
OP_CLOSURE
OP_LE
OP_DIV
OP_NOT
OP_LEN
OP_EQ
OP_SETUPVAL
OP_POW
OP_LT
OP_SETGLOBAL
OP_GETGLOBAL
OP_TFORLOOP
OP_SETLIST
T A B C mode opcode
ORDER OP
OP_CONCAT
OP_SETTABLE
OP_MUL
OP_LOADK
OP_GETTABLE
OP_LOADBOOL
OP_FORLOOP
OP_MOD
OP_NEWTABLE
OP_TEST
OP_TAILCALL
** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
** See Copyright Notice in lua.h
OP_CLOSE
OP_ADD
OP_CALL
OP_SUB
OP_GETUPVAL
OP_TESTSET
comment: argument is not used
label: code-design
** invalid register that fits in 8 bits
number of list items to accumulate before a SETLIST instruction
A B C R(A) := R(B)[RK(C)]
A B C if ((RK(B) == RK(C)) ~= A) then pc++
A C if not (R(A) <=> C) then pc++
A B C if (R(B) <=> C) then R(A) := R(B) else pc++
** masks for instruction properties. The format is:
** bits 0-1: op mode
** bits 2-3: C arg mode
** bits 4-5: B arg mode
** bit 6: instruction set register A
** bit 7: operator is a test
test whether value is a constant
A close all variables in the stack up to (>=) R(A)
A B R(A), R(A+1), ..., R(A+B-1) = vararg
A Bx Gbl[Kst(Bx)] := R(A)
** R(x) - register
** Kst(x) - constant (in constant table)
** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
===========================================================================
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
`A' : 8 bits
`B' : 9 bits
`C' : 9 bits
`Bx' : 18 bits (`B' and `C' together)
`sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
for that argument (so that -max is represented by 0, and +max is
represented by 2*max), which is half the maximum for the corresponding
unsigned argument.
===========================================================================
A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
A Bx R(A) := Gbl[Kst(Bx)]
A B C return R(A)(R(A+1), ... ,R(A+B-1))
this bit 1 means constant (0 means register)
A Bx R(A) := Kst(Bx)
** Macros to operate RK indices
basic instruction format
A B C R(A) := RK(B) ^ RK(C)
** the following macros help to manipulate instructions
A B C R(A)[RK(B)] := RK(C)
A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++
** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
A B C R(A) := RK(B) - RK(C)
A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
`sBx' is signed
A B C R(A) := {} (size = B,C)
A B UpValue[B] := R(A)
A sBx R(A)-=R(A+2); pc+=sBx
----------------------------------------------------------------------
name args description
------------------------------------------------------------------------
sBx pc+=sBx
A B C R(A) := RK(B) / RK(C)
** size and position of opcode arguments.
A B R(A) := not R(B)
A B R(A) := ... := R(B) := nil
A B C R(A) := RK(B) * RK(C)
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
argument is used
A B R(A) := length of R(B)
A B R(A) := R(B)
opcode names
** grep "ORDER OP" if you change these enums
argument is a register or a jump offset
A B C R(A) := (Bool)B; if (C) pc++
gets the index of the constant
argument is a constant or register/constant
A B C if ((RK(B) <= RK(C)) ~= A) then pc++
A B return R(A), ... ,R(A+B-2) (see note)
A B C R(A) := RK(B) % RK(C)
A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))
A B R(A) := -R(B)
A B R(A) := UpValue[B]
A B C R(A) := R(B).. ... ..R(C)
A B C if ((RK(B) < RK(C)) ~= A) then pc++
A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
code a constant index as a RK value
===========================================================================
Notes:
(*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
and can be 0: OP_CALL then sets `top' to last_result+1, so
next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
(*) In OP_VARARG, if (B == 0) then use actual number of varargs and
set top (like in OP_CALL with C == 0).
(*) In OP_RETURN, if (B == 0) then return up to `top'
(*) In OP_SETLIST, if (B == 0) then B = `top';
if (C == 0) then next `instruction' is real C
(*) For comparisons, A specifies what condition the test should accept
(true or false).
(*) All `skips' (pc++) assume that next instruction is a jump
===========================================================================
creates a mask with `n' 1 bits at position `p'
creates a mask with `n' 0 bits at position `p'
A B C R(A) := RK(B) + RK(C)
UTC?
** {======================================================
** Time/Date operations
** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
** wday=%w+1, yday=%j, isdst=? }
** =======================================================
9 = number of fields
calls to Lua API may change this value
skip `!'
undefined?
should be big enough for any conversion result
if NULL push nil
get current time
no conversion specifier?
called without args?
make sure table is at the top
invalid date?
does not set field
** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
}======================================================
pretend that `OP_FOR' starts the loop
a block either controls scope or breaks (never both)
body -> `(' parlist `)' chunk END
stat -> assignment
end of scope for declared variables
read first token
assignment -> `,' primaryexp assignment
param -> `...'
`:' NAME funcargs
not found
`[' exp1 `]'
expand while operators have priorities higher than `limit'
block -> chunk
stat -> forstat
no value (yet)
finish scope...
fix it at stack top (for gc)
skip WHILE
free registers
============================================================
stat -> func | assignment
no more levels?
reserve register for parameters
** structure to chain all variables in the left-hand side of an
** assignment
forlist -> NAME {,NAME} IN explist1 forbody
`falses' are all equal here
control variables
left priority for each binary operator
no upvalues?
skip DO
local function?
remove table and prototype from the stack
forstat -> FOR (fornum | forlist) END
stat -> RETURN explist
cond -> exp
create control variables
chain
last list item read
simpleexp -> NUMBER | STRING | NIL | true | false | ... |
constructor | FUNCTION body | primaryexp
only one single value?
funcargs
constructor -> ??
scope block
skip BREAK
logical (and/or)
debug information will only see the variable after this point!
and repeat
may be listfields or recfields
close the loop
return no values
includes call itself
open call
funcstat -> FUNCTION funcname body
equality and inequality
set initial array size
tail call?
may be needed for error messages
last exp. provides the difference
** $Id: lparser.c,v 2.42.1.4 2011/10/21 19:31:42 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
linked list of funcstates
** nodes for block list (list of active blocks)
IF cond THEN block
stat -> breakstat
flush
anchor table of constants and prototype (to avoid being collected)
call statement uses no results
create declared variables
arg list is empty?
`+' `-' `/' `%'
upvalue in this level
skip the '['
default is global variable
stat -> retstat
must be last statement
stat -> DO block END
chunk -> { stat [`;'] }
# active locals outside the breakable structure
else was LOCAL or UPVAL
optional step
there is no list item
constructor
field
return all `active' values
** {======================================================================
** Rules for Constructors
** =======================================================================
registers with returned values
true if some variable in the block is an upvalue
limit
return first untreated operator
default step = 1
comment: to avoid warnings
label: code-design
close last argument
fornum -> NAME = exp1,exp1[,exp1] forbody
`then' part
field -> ['.' | ':'] NAME
ELSEIF cond THEN block
** check whether, in an assignment to a local variable, the local variable
** is needed in a previous assignment (to a table). If so, save original
** local value in a safe place and use this safe copy in the previous
** assignment.
ORDER OPR
info points to global name
variable (global, local, upvalue, or indexed)
previous assignment will use safe copy
ls->t.token == '['
don't need 'arg'
index -> '[' expr ']'
finish scope
}====================================================================
explist1 -> expr { `,' expr }
funcname -> NAME {field} [`:' NAME]
skip RETURN
comment: remove extra values
label: code-design
stat -> funcstat
conflict?
stat -> func
stat -> whilestat
skip the dot or colon
expression?
initial value
registers 0/1 are always valid
true if `block' is a loop
** {======================================================================
** Expression parsing
** =======================================================================
scope for loop and control variables
eventual position to save local variable
prefixexp -> NAME | '(' expr ')'
make copy
if condition then break
param -> NAME
stat -> repeatstat
`else' part
do not count last expression (unknown number of elements)
vararg
power and concat (right associative)
GRAMMAR RULES
repeatstat -> REPEAT block UNTIL cond
comment: extra space to call generator
label: code-design
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
** where `binop' is any binary operator with a priority higher than `limit'
avoid default
finish loop
** {======================================================================
** Rules for Statements
** =======================================================================
forbody -> DO block
optional return values
definition `happens' in the first line
read condition
call remove function and arguments and leaves
(unless changed) one result
false conditions finish the loop
** prototypes for recursive non-terminal functions
skip REPEAT
table descriptor
assignment -> `=' explist1
test_then_block -> [IF | ELSEIF] cond THEN block
stat -> ifstat
right priority
no more items pending
at least one expression
complete semantics when there are upvalues
skip `for'
read sub-expression with higher priority
whilestat -> WHILE cond DO block END
loop block
list of jumps out of this loop
look up at current level
constructor_item -> recfield
funcargs -> `(' [ explist1 ] `)'
read condition (inside scope block)
total number of `record' elements
values must go to the `stack'
order
priority for unary operators
new one
scope for declared variables
not found at current level; try upper one
main func. is always vararg
primaryexp ->
prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs }
close last expression
use `arg' as default name
base register for call
local will be used as an upval
constructor_part -> listfield
first variable name
stat -> LOCAL NAME {`,' NAME} [`=' explist1]
funcargs -> constructor
return all values
must use `seminfo' before `next'
number of array elements pending to be stored
else...
skip ELSE (after patch, for correct line info)
skip LOCAL
set initial table size
skip FUNCTION
stat -> localstat
default assignment
loop scope (`break' jumps to this point)
funcargs -> STRING
recfield -> (NAME | `['exp1`]') = exp1
skip IF or ELSEIF
total number of array elements
}======================================================================
final return
is `parlist' not empty?
ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END
parlist -> [ param { `,' param } ]
last token read was anchored in defunct function; must reanchor it
** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
patch list of `exit when true'
number of elements in `locvars'
info = result register
chain of current blocks
copy of the Lua state
list of pending jumps to `pc'
info = index of constant in `k'
table to find (and reuse) elements in `k'
current function header
upvalues
no value
info = index of upvalue in `upvalues'
next position to code (equivalent to `ncode')
first free register
lexical state
number of elements in `k'
info = table register; aux = index register (or `k')
enclosing function
declared-variable stack
info = index of table; aux = index of global name in `k'
state needed to generate code for a given function
patch list of `exit when false'
nval = numerical value
info = instruction pc
info = local register
number of active local variables
defined in lparser.c
number of elements in `p'
`pc' of last `jump target'
** Expression descriptor
memory allocation error: free partial state
collect all objects
mark it as unfinished state
separate udata that have GC metamethods
close all upvalues for this thread
registry
only the main thread can be closed
initialize first ci
initialize CallInfo array
repeat until no more errors
table of globals
** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
** Global State
** See Copyright Notice in lua.h
init stack
`function' entry for this `ci'
** Main thread combines a thread state and the global state
no error function during GC metamethods
share table of globals
** open parts that may cause memory-allocation errors
initial size of string table
initialize stack array
call GC metamethods for all udata
defined in ldo.c
list of open upvalues in this stack
metatables for basic types
nested C calls when resuming coroutine
array with tag-method names
thread
expected number of results from this function
to be called in unprotected errors
current error recover point
last free slot in the stack
number of tail calls lost under this entry
comment: temporary place for environments
label: code-design
** `global state', shared by all threads of this state
size of pause between successive GCs
base for this function
registry
last element of list of userdata to be GC
GC `granularity'
first free slot in the stack
`savedpc' of current function
stack base
call info for current function
an estimate of number of bytes actually in use
** Union of all collectable objects
position of sweep in `strt'
table of globals
comment: temporary buffer for string concatentation
label: code-design
** `per thread' state
base of current function
how much GC is `behind schedule'
list of objects to be traversed atomically
points after end of ci array
macros to convert a GCObject into a specific value
number of elements
number of bytes currently allocated
head of double-linked list of all open upvalues
macro to convert any Lua object into a GCObject
current error handling function (stack index)
hash table for strings
list of all collectable objects
number of nested C calls
function index in the stack
array of CallInfo's
** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
** Global State
** See Copyright Notice in lua.h
** informations about a call
extra stack space to handle TM calls and some other extras
state of garbage collector
position of sweep in `rootgc'
list of gray objects
list of weak tables (to be cleared)
top for this function
size of array `base_ci'
function to reallocate memory
auxiliary data to `frealloc'
rehash
chain new entry
not found
save next
ending 0
seed
chain it on udata list (after main thread)
** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
is not finalized
compute hash
if string is too long, don't hash all its chars
too crowded
chain it
for each node in the list
new position
comment: string may be dead
label: code-design
cannot resize during GC traverse
** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
`s2' cannot be found after that
explicit request?
else return match(ms, s, ep);
0 or more repetitions
** {======================================================
** PATTERN MATCHING
** =======================================================
not found
add capture to accumulated result
1st char is already checked
else return match(ms, s, ep+1);
using goto's to optimize tail recursion
start
position capture?
relative string position: negative means back from end
to store the format (`%...')
end capture
pop metatable
create metatable for strings
}======================================================
end of pattern
macro to `unsign' a character
0 or more repetitions (minimum)
skip it
format item
avoids a negative `l1'
string library...
add whole match
balanced string?
...is the __index metamethod
matches any char
points to what is next
maximum size of each formatted item (> len(format('%99.99f', -1e308)))
else return match(ms, s, p+2)
keep original text
pop dummy string
comment: no precision and string is too long to be formatted;
keep original string
label: code-design
empty match? go at least one position
empty interval; return no values
match succeeded
string ends out of balance
1 or more repetitions
** $Id: lstrlib.c,v 1.132.1.5 2010/05/14 15:34:19 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
skip the `addsize' at the end
else return match(ms, s+1, ep);
skip the 'addsize' at the end
to search for a `*s2' inside `s1'
init of source string
number of strings pushed
do a plain search
empty strings are everywhere
to store the formatted item
skip escapes (e.g. `%]')
non empty match?
optional
** maximum size of each format specification (such as '%-099.99d')
** (+10 accounts for %99.99x plus margin of error)
%%
skip precision
it is a pattern item
set string metatable
ms->level == 0, too
skip width
end
skip ESC
add result to accumulator
undo capture
total number of captures (finished or unfinished)
look for a `]'
(2 digits at most)
else didn't match; reduce 1 repetition to try again
valid flags in a format specification
start capture
** Open string library
number of substitutions
skip the `^'
end (`\0') of source string
keeps trying to match with the maximum repetitions
is the `$' the last char in pattern?
overflow?
1st char will be checked by `memchr'
capture results (%0-%9)?
check end of string
try with one more repetition
counts maximum expand for item
frontier?
case default
else return match(ms, s, p+4);
skip flags
match failed?
number of arguments
also treat cases `pnLlh'
close capture
correct `l1' and `s1' to try again
nil or false?
dummy string
or no special characters?
shrink array
cannot find a free place?
i is zero or a present index
comment: key may be dead already, but it is ok to use it in `next'
label: code-design
no more elements to count
compute new size for array part
check whether `key' is somewhere in the chain
grow table
count as such
count extra key
that's it
copy colliding node into free pos. (mp->next also goes)
redo the chain with `n' in place of `mp'
is `key' inside array part?
yes; that's the index (corrected to C)
key index in hash table
is `key' an appropriate array index?
** hash for lua_Numbers
try first array part
nums[i] = number of keys between 2^(i-1) and 2^i
** number of ints inside a lua_Number
value
then hash part
use specialized version
2^i
now `mp' is free
temporary values (kept only if some malloc fails)
adjust upper limit
optimal size (till now)
all elements smaller than n will go to array part
re-insert key into grown table
index is int?
new node will go into free position
first iteration
** max size of array part is 2^MAXBITS
count elements in range (2^(lg-1), 2^lg]
** main search function
array part must grow?
else must find a boundary in hash part
re-insert elements from hash part
array part must shrink?
table was built with bad purposes: resort to linear search
key not found
comment:
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
label: code-design
is colliding node out of its main position?
** search function for strings
avoid problems with -0
comment: to avoid warnings
label: code-design
could not find a free place
find previous
total number of elements
for each slice
`key' did not match some condition
number of elements to go to array part
else go through
find original element
** inserts a new key into a hash table; first, check whether key's main
** position is free. If not, check whether colliding node is in its main
** position or not: if it is not, move colliding node to an empty place and
** put new key in its main position; otherwise (colliding node is in its main
** position), new key goes to an empty position.
count to traverse all array keys
reset counts
save old hash ...
optimal size for array part
all elements already counted
resize the table to new computed sizes
** returns the index of a `key' for table traversals. First goes all
** elements in the array part, then elements in the hash part. The
** beginning of a traversal is signalled by -1.
** search function for integers
all those keys are integer keys
colliding node is in its own main position
2^lg
key
a non-nil value?
counter
count keys in array part
now do a binary search between them
chain new position
use common `dummynode'
summation of `nums'
overflow?
no elements to hash part?
all positions are free
re-insert elements from vanishing slice
hash elements are numbered after array ones
find `i' and `j' such that i is present and j is not
there is a boundary in the array part: (binary) search for it
more than half elements present?
** }=============================================================
that is easy...
** $Id: ltable.c,v 2.32.1.2 2007/12/28 15:32:23 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
hash part is empty?
comment:
** Implementation of tables (aka arrays, objects, or hash tables).
** Tables keep its elements in two parts: an array part and a hash part.
** Non-negative integer keys are all candidates to be kept in the array
** part. The actual size of the array is the largest `n' such that at
** least half the slots between 0 and n are in use.
** Hash uses a mix of chained scatter table with Brent's variation.
** A main invariant of these tables is that, if an element is not
** in its main position (i.e. the `original' position that its hash gives
** to it), then the colliding element is in its own main position.
** Hence even when the load factor reaches 100%, performance remains good.
label: code-design
** {=============================================================
** Rehash
** ==============================================================
(1 <= key && key <= t->sizearray)
create new hash part with appropriate size
free old array
number of elements smaller than 2^i
yes; move colliding node into free position
count keys in hash part
** returns the index for `key' if `key' is an appropriate key to live in
** the array part of the table, -1 otherwise.
** Try to find a boundary in table `t'. A `boundary' is an integer index
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
no more elements
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
get a free place
** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
insert new element at the end
remove a[j]
** $Id: ltablib.c,v 1.38.1.3 2008/02/14 16:46:58 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
`grow' array if necessary
-2 to compensate function and `a'
t[i] = t[i-1]
result = t[pos]
repeat --j until a[j] <= P
call recursively the smaller one
called with only 2 arguments
t[e] = nil
remove value
assume array is smaller than 2^40
a < b?
Pivot
function
remove nil result
move up elements
remove value and result
nothing to remove
repeat the routine for the larger one
-1 to compensate function
first key
adjust so that smaller half is in [j..i] and larger one in [l..u]
is there a 2nd argument?
2nd argument is the position
t[pos] = t[pos+1]
a[i]<a[l]?
** {======================================================
** Quicksort
** (based on `Algorithms in MODULA-3', Robert Sedgewick;
** Addison-Wesley, 1993.)
add last value (if interval was not empty)
remove a[l]
pop pivot, a[i], a[j]
a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2
t.n = n-1
for tail recursion
only 3 elements
first empty element
key
a[l..i-1] <= a[i] == P <= a[i+1..u]
swap pivot (a[u-1]) with a[i]
invariant: a[l..i] <= P <= a[j..u]
sort elements a[l], a[(l+u)/2] and a[u]
swap a[l] - a[u]
}======================================================
a[u] < a[l]?
a[u]<a[i]?
2nd argument
only 2 elements
value
function?
position is outside bounds?
new size
1st argument
where to insert new element
repeat ++i until a[i] >= P
remove a[i]
make sure there is two arguments
t[pos] = v
never collect these names
comment:
** function to be used with macro "fasttm": optimized for absence of
** tag methods
label: code-design
cache this fact
no tag method?
** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
ORDER TM
* WARNING: if you change the order of this enumeration,
* grep "ORDER TM"
number of elements in the enum
** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
last tag method with `fast' access
stdin
repeat until gets a complete line
open libraries
number of arguments to the script
not an option?
remove line
invalid option
create state
remove it
pass error message
stop collector during initialization
executes stdin as a file
line ends with newline?
skip this function and traceback
count total number of arguments
status OK
function index
push traceback function
stop if file fails
option
any result to print?
if another SIGINT happens before lstop,
terminate process (default action)
call debug.traceback
join them
invalid args?
** $Id: lua.c,v 1.160.1.2 2007/12/28 15:32:23 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
no more input?
check that argument has no extra characters at the end
cannot try to add lines?
add a new line...
go through
force a complete garbage collection in case of errors
put it under chunk and args
else...
remove global
change it to `return'
clear stack
'message' not a string?
keep it intact
first line starts with `=' ?
...between the two lines
comment: unused arg.
label: code-design
remove traceback function
collect arguments
no input
** ===============================================================
** some useful macros
** ===============================================================
minimum Lua stack available to a C function
** functions that read/write blocks when loading/dumping Lua chunks
** basic types
** push functions (C -> stack)
** prototype for memory-allocation functions
** `load' and `call' functions (load and run Lua code)
** access functions (stack -> C)
** garbage-collection function and options
(n) `global', `local', `field', `method'
(S)
** set functions (stack -> Lua)
thread status; 0 is OK
(l)
** state manipulation
** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
option for multiple returns in `lua_pcall' and `lua_call'
*****************************************************************************
* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************
active function
** Event codes
private part
comment: hack
label: code-design
Functions to be called by the debuger in specific events
type of numbers in Lua
type for integer functions
** get functions (Lua -> stack)
** pseudo-indices
(u) number of upvalues
(S) `Lua', `C', `main', `tail'
** coroutine functions
comment:
** generic extra include file
label: code-design
}======================================================================
** Event masks
** miscellaneous functions
** basic stack manipulation
(n)
activation record
** {======================================================================
** Debug API
** =======================================================================
mark for precompiled code (`<esc>Lua')
** compatibility macros and functions
end of options; keep it
list
default program name
default output file
** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $
** Lua compiler (saves bytecodes to files; also list bytecodes)
** See Copyright Notice in lua.h
actual output file name
output file
show version
unknown option
parse only
strip debug information
end of options; use stdin
list bytecodes?
actual program name
dump bytecodes?
default output file name
strip debug information?
end of options; skip it
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all standard library functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
@@ LUA_PATH and LUA_CPATH are the names of the environment variables that
@* Lua check to set its paths.
@@ LUA_INIT is the name of the environment variable that Lua
@* checks for initialization code.
** CHANGE them if you want different names.
@@ luai_userstate* allow user-specific actions on threads.
** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
** extra when a thread is created/deleted/resumed/yielded.
comment:
@@ LUAI_MAXCALLS limits the number of nested calls.
** CHANGE it if you need really deep recursive calls. This limit is
** arbitrary; its only purpose is to stop infinite recursion before
** exhausting memory.
label: code-design
}==================================================================
16 digits, sign, point, and \0
get line
@@ LUA_INTFRMLEN is the length modifier for integer conversions
@* in 'string.format'.
@@ LUA_INTFRM_T is the integer type correspoding to the previous length
@* modifier.
** CHANGE them if your system supports long long or does not support long.
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_register'
** your uses of 'luaL_openlib'
@@ LUA_ANSI controls the use of non-ansi features.
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
non-empty line?
comment:
@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
** CHANGE it if your system requires alignments larger than double. (For
** instance, if your system supports long doubles and they must be
** aligned in 16-byte boundaries, then you should add long double in the
** union.) Probably you do not need to change this.
label: code-design
===================================================================
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
int has at least 32 bits
@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
** CHANGE it (define it) if you want exact compatibility with the
** behavior of setn/getn in Lua 5.0.
comment: needs an extra library: -ldl
label: code-design
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** ==================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
@@ LUAI_GCMUL defines the default speed of garbage collection relative to
@* memory allocation as a percentage.
** CHANGE it if you want to change the granularity of the garbage
** collection. (Higher values mean coarser collections. 0 represents
** infinity, where each step performs a full collection.) You can also
** change this value dynamically.
@@ LUA_IDSIZE gives the maximum size for the description of the source
@* of a function in debug information.
** CHANGE it if you want a different size.
@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
@* (the data goes just *before* the lua_State pointer).
** CHANGE (define) this if you really need that. This value must be
** a multiple of the maximum alignment required for your machine.
@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
** CHANGE them if you prefer to use longjmp/setjmp even with C++
** or if want/don't to use _longjmp/_setjmp instead of regular
** longjmp/setjmp. By default, Lua handles errors with exceptions when
** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
** and with longjmp/setjmp otherwise.
comment:
@@ lua_number2int is a macro to convert lua_Number to int.
@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
** CHANGE them if you know a faster way to convert a lua_Number to
** int (with any rounding method and without throwing errors) in your
** system. In Pentium machines, a naive typecast from double to int
** in C is extremely slow, so any alternative is worth trying.
label: code-design
@@ LUAI_MAXVARS is the maximum number of local variables per function
@* (must be smaller than 250).
@@ The luai_num* macros define the primitive operations over numbers.
@@ LUAI_FUNC is a mark for all extern functions that are not to be
@* exported to outside modules.
@@ LUAI_DATA is a mark for all extern (const) variables that are not to
@* be exported to outside modules.
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library.
** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
avoid overflows in comparison
dummy variable
@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
@* Interfaces Extension (XSI).
** CHANGE it (define it) if your system is XSI compatible.
200% (wait memory to double before next GC)
C++ exceptions
more often than not the libs go together with the core
assume stdin is a tty
@@ LUA_MAXINPUT is the maximum length for an input line in the
@* stand-alone interpreter.
** CHANGE it if you need longer lines.
@@ lua_readline defines how to show a prompt and then read a line from
@* the standard input.
@@ lua_saveline defines how to "save" a read line in a "history".
@@ lua_freeline defines how to free a line read by lua_readline.
** CHANGE them if you want to improve this functionality (e.g., by using
** GNU readline and history facilities).
@@ LUA_PATHSEP is the character that separates templates in a path.
@@ LUA_PATH_MARK is the string that marks the substitution points in a
@* template.
@@ LUA_EXECDIR in a Windows path is replaced by the executable's
@* directory.
@@ LUA_IGMARK is a mark to ignore all before it when bulding the
@* luaopen_ function name.
** CHANGE them if for some reason your system cannot use those
** characters. (E.g., if one of those characters is a common character
** in file/directory names.) Probably you do not need to change them.
@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
@* can do during pattern-matching.
** CHANGE it if you need more captures. This limit is arbitrary.
@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
@@ LUAI_INT32 is an signed integer with at least 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@* used by Lua.
** CHANGE here if for some weird reason the default definitions are not
** good enough for your machine. (The definitions in the 'else'
** part always works, but may waste space on machines with 64-bit
** longs.) Probably you do not need to change this.
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
** CHANGE it to undefined as soon as your programs use 'math.fmod' or
** the new '%' operator instead of 'math.mod'.
show prompt
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
@* C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
@* syntactical nested non-terminals in a program.
@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
** CHANGE it to undefined as soon as your programs use only '...' to
** access vararg parameters (instead of the old 'arg' table).
** {==================================================================
** Stand-alone configuration
** ===================================================================
On a Pentium, resort to a trick
add it to history
@@ LUA_PROGNAME is the default name for the stand-alone Lua program.
** CHANGE it if your stand-alone interpreter has a different name and
** your system is not able to detect that name automatically.
16-bit ints
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
@@ LUAI_BITSINT defines the number of bits in an int.
** CHANGE here if Lua cannot automatically detect the number of bits of
** your machine. Probably you do not need to change this.
@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
@* is, whether we're running lua interactively).
** CHANGE it if you have a better definition for non-POSIX/non-Windows
** systems.
the next trick should work on any Pentium, but sometimes clashes
with a DirectX idiosyncrasy
@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
@@ lua_popen spawns a new process connected to the current one through
@* the file streams.
** CHANGE it if you have a way to implement it in your system.
@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
** CHANGE it to undefined as soon as you do not need a global 'loadlib'
** function (the function is still available as 'package.loadlib').
** {==================================================================
** CHANGE (to smaller values) the following definitions if your system
** has a small C stack. (Or you may want to change them to larger
** values if your system has a large C stack and these limits are
** too rigid for you.) Some of these constants control the size of
** stack-allocated arrays used by the compiler or the interpreter, while
** others limit the maximum number of recursive calls that the compiler
** or the interpreter can perform. Values too large may cause a C stack
** overflow for some forms of deep constructs.
** ===================================================================
** {==================================================================
@@ LUA_NUMBER is the type of numbers in Lua.
** CHANGE the following definitions only if you want to build Lua
** with a number type different from double. You may also need to
** change lua_number2int & lua_number2integer.
** ===================================================================
comment: in Unix, try _longjmp/_setjmp (more efficient)
label: code-design
comment:
@@ luai_apicheck is the assert macro used by the Lua-C API.
** CHANGE luai_apicheck if you want Lua to perform some checks in the
** parameters it gets from API calls. This may slow down the interpreter
** a bit, but may be quite useful when debugging C code that interfaces
** with Lua. A useful redefinition is to use assert.h.
label: code-design
@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
@* can use.
** CHANGE it if you need lots of (Lua) stack space for your C
** functions. This limit is arbitrary; its only purpose is to stop C
** functions to consume unlimited stack space. (must be smaller than
** -LUA_REGISTRYINDEX)
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
@* facility.
** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
** off the advisory error when nesting [[...]].
@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
@* as a percentage.
** CHANGE it if you want the GC to run faster or slower (higher values
** mean larger pauses which mean slower collection.) You can also change
** this value dynamically.
@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
@* (must be smaller than 250).
@@ LUA_NUMBER_SCAN is the format for reading numbers.
@@ LUA_NUMBER_FMT is the format for writing numbers.
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
@@ lua_str2number converts a string to a number.
On a Microsoft compiler, use assembler
comment: this option always works, but may be slow
label: code-design
default handling with long jumps
GC runs 'twice the speed' of memory allocation
@@ lua_tmpnam is the function that the OS library uses to create a
@* temporary name.
@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
** CHANGE them if you have an alternative to tmpnam (which is considered
** insecure) or if you want the original tmpnam anyway. By default, Lua
** uses tmpnam except when POSIX is available, where it uses mkstemp.
@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
** CHANGE them if you want different prompts. (You can also change the
** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
** CHANGE it to undefined as soon as you rename 'string.gfind' to
** 'string.gmatch'.
comment: needs some extra libraries
label: code-design
@@ LUA_DL_* define which dynamic-library system Lua should use.
** CHANGE here if Lua has problems choosing the appropriate
** dynamic-library system for your platform (either Windows' DLL, Mac's
** dyld, or Unix's dlopen). If your system is some kind of Unix, there
** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
** it. To use dlopen you also need to adapt the src/Makefile (probably
** adding -ldl to the linker options), so Lua does not select it
** automatically. (When you change the makefile to add -ldl, you must
** also add -DLUA_USE_DLOPEN.)
** If you do not want any kind of dynamic library, undefine all these
** options.
** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
empty
comment: does not need extra library
label: code-design
** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
open all previous libraries
Key to file-handle type
is lua_Number integral?
** load precompiled chunk
** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
* make header
remove trailing '\0'
endianness
for header of binary files -- this is Lua 5.1
make header; from lundump.c
print one chunk; from print.c
dump one chunk; from ldump.c
load one chunk; from lundump.c
for header of binary files -- this is the official format
size of header of binary files
** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
first try `le'
true must be 1 !!
remove new frame
try first operand
yes: continue its execution
restart luaV_execute over new Lua function
it was a C function (`precall' called it)
update internal index...
avoid pointing inside table (may rehash)
previous frame
call TM
tail call: put new frame in place of previous one
will try TM
repeat until only 1 result left
else repeat with `tm'
same metatables => same metamethods
both strings longer than `len'; go on comparing (after the `\0')
previous function index
same metamethods?
increment index
collect total length
warning!! several calls may realloc the stack and invalidate `ra'
pre-alloc it at once
or no TM?
** $Id: lvm.c,v 2.63.1.5 2011/08/17 20:43:11 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
second op is empty?
3th argument
l is finished?
no: return
no metamethod
push function
l is smaller than r (because r is not finished)
try second operand
next steps may throw errors
comment: needs more space?
label: code-design
continue loop?
was previous function running `here'?
limit for table tag-method chains (to avoid loops)
entry point
correct top
`t' is a table?
move frame down
result is no nil?
did hook yield?
to be used after possible stack reallocation
func. + 2 args (state and index)
jump back
strings are equal up to a `\0'
r is finished?
concat all strings
at least two string values; get as many as possible
...and external index
try metamethod
one more call lost
got `n' strings to create 1 new
** some macros for common tasks in `luaV_execute'
call base
no TM?
skip next instruction (if C)
yield
result is first op (as string)
save control variable
no metamethod?
else try `lt'
main loop of interpreter
call linehook when enter a new function, when jump back (loop),
or when enter a new line
do a primitive get
index of first `\0' in both strings
different metamethods?
else previous instruction set top
it was a C function (`precall' called it); adjust results
else will try the tag method
2nd argument
do a primitive set
1st argument
number of elements handled in this pass (at least 2)
previous call may change the stack
next assignment may change this value
** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
return number of missing bytes
** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
** a generic input stream interface
** See Copyright Notice in lua.h
min. between n and z->n
------------------------------------------------------------------------
--------------------------------------------------------------- read ---
luaZ_fill removed first byte; put back it
end of stream
current position in buffer
Lua state (for reader)
** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
--------- Private Part ------------------
additional data
bytes still unread
read next n bytes
cannot happen
** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
Last change: revised for Lua 5.2.4
(S)
(t)
Last change: revised for Lua 5.2.4
======================================================================
(l)
private part
$Id: manual.of,v 1.104 2013/06/01 00:13:11 roberto Exp $
(u) number of parameters
(n)
(u)
(u) number of upvalues
get global 'f'
Last change: revised for Lua 5.2.4
no errors?
it has no upvalues
function to be called
not a closure
save continuation
save context
adjust frame top
signal it
stack large enough?
save information for error recovery
do a 'conventional' protected call
** get functions (Lua -> stack)
no continuation or no yieldable?
for unary minus, add fake 2nd operand
test for pseudo index
set global table as 1st upvalue of 'f' (may be LUA_ENV)
include current debt
yes; check is OK
push empty string
end of cycle?
GC values are expressed in Kbytes: #bytes/2^10
may call tag method
generational mode?
does it have one upvalue?
C closure
** access functions (stack -> C)
** `load' and `call' functions (run Lua code)
** set functions (stack -> Lua)
upvalues
Lua closure
not a C function
1st operand
mark that function may do error recovery
get global table from registry
no
2nd operand
light C function?
else n == 1; nothing to do
remove key
use L->top as a temporary
data to `f_call'
pop value and key
comment: to avoid warnings
label: code-design
just do the call
change collector to incremental mode
** push functions (C -> stack)
ensure that true is 1
conversion failed?
global table
need to prepare continuation?
previous call may reallocate the stack
corresponding test
pop index and value
`subtract' index (index is negative)
all other operations expect two operands
can grow without overflow?
** miscellaneous functions
** to be called by 'lua_checkstack' in protected mode, to grow stack
** capturing memory errors
value at a non-valid index
test for valid but not pseudo index
code unreachable; will unlock when control actually leaves the kernel
change collector to generational mode
do a single step
** convert an acceptable stack index into an absolute index
if it is here, there were no errors
get newly created function
invalid option
prepare continuation (call is already protected by 'resume')
negative index
do the call
no continuation or no yieldable
get its upvalue pointer
true if it will do major collection
no; need to grow stack
** Garbage-collection function
`luaV_tostring' may create a new string
** Execute a protected call.
** $Id: lapi.c,v 2.171.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
try to grow stack
lua closure
no more elements
** basic stack manipulation
LUA_REGISTRYINDEX does not need gc barrier
(collector revisits it before finishing collection)
function upvalue?
** $Id: lapi.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
** use appropriate macros to interpret 'pclose' return status
name already in use?
double buffer size
remove previous table
remove table (but keep name)
no more pre-read characters
get _LOADED[modname]
copy to be left at top
remove pushed values
false, because did not find table there
remove both metatables
get/create library table
not big enough?
not found
comment: keep some extra space to run error routines, if needed
label: code-design
push prefix
get a new reference
table already there
read initial portion
return true/nil,what,code
remove table and value
type of termination
add line to correct line numbers
no metafield?
remove it from list
remove this nil
no stack frame?
argument to open function
{
check conversions number -> integer types
remove only metatable
(t[freelist] = t[ref])
binary file?
}======================================================
** reads the first character of file 'f' and skips an optional BOM mark
** in its beginning plus its first line if it starts with '#'. Returns
** true if it skipped the first line. In any case, '*cp' has the
** first "valid" character of the file (after the optional BOM and
** a first-line comment).
push last suffix
re-read initial portion
** {======================================================
** Userdata's metatable manipulation
** =======================================================
start 'next' loop
no metatable?
** {======================================================
** Reference system
** =======================================================
copy upvalues to the top
comment: not used
label: code-design
** $Id: lauxlib.c,v 1.248.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
move name to proper place
remove it from stack
'fread' can return > 0 *and* set the EOF flag. If next call to
'getF' called 'fread', it might still wait for user input.
The next check avoids this problem.
find an upper bound
read a block from file
comment:
** check whether buffer is using a userdata on the stack as a temporary
** buffer
label: code-design
move library table to below upvalues
get first free element
remove from stack
to be read by the parser
return problematic part of the name
** returns a pointer to a free area with at least 'sz' bytes
reopen in binary mode
remove value (but keep name)
put value below buffer
push function
do not count `self'
** set functions from list 'l' into table at top - 'nup'; each
** function gets the 'nup' elements at the top as upvalues.
** Returns with only the table at the stack.
successful termination?
get info about it
leave previous value on top, but return 0
no free elements
create metatable
for each pair in table
no comment
index of filename on the stack
skip end-of-line, if present
ref = t[freelist]
size of the second part of the stack
value is a userdata?
Utf8 BOM mark
there was a comment
index of free-list header
continue after `p'
file being read
field has a non-table value?
copy of 'mod'
number of pre-read characters
** search for 'objidx' in table at index -1.
** return 1 + string at top if find a good name.
are there pre-read characters to be read?
t[ref] = t[freelist]
main?
return next character
'c' is the first character of the stream
set new table into field
_LOADED[modname] = module
return to Lua to abort
remove _LOADED table
assign new table to field
check function at level
calls to Lua API may change this value
create larger buffer
prefix matched; discard it
try recursively
add a '...'
new table for field
t[freelist] = ref
push replacement in place of pattern
try to get metatable
_G[modname] = module
** {======================================================
** Argument check functions
** =======================================================
ignore results from `lua_load'
any free element?
** {======================================================
** Traceback
** =======================================================
does it have a metatable?
remove function and global table
try global variable (and create one if it does not exist)
place '.' between the two names
do a binary search
** {======================================================
** Generic Buffer manipulation
** =======================================================
** stripped-down 'require'. Calls 'openf' to open a module,
** registers the result in 'package.loaded' table and, if 'glb'
** is true, also registers the result in the global table.
** Leaves resulting module on the top.
remove object
first line is a comment (Unix exec. file)?
registry.name = metatable
** {======================================================
** Load functions
** =======================================================
read block
comment: too many levels?
label: code-design
interpret result
value is a userdata with wrong metatable
skip first line
remove upvalues
_LOADED[modname] = new table
found object?
value is not a userdata with a metatable
remove metatable and metafield
not enough space?
ignore non-string keys
and skip to last ones
remove previous result
** Count number of elements in a luaL_Reg list.
close file (even in case of errors)
get correct metatable
** ensure that stack[idx][fname] has a table and push that table
** into the stack
return them (chars already in buffer)
** {======================================================
** Error-report functions
** =======================================================
}
** {======================================================
** Compatibility with 5.1 module functions
** =======================================================
remove value
open module
else, no information available...
make copy of module (call result)
size of the first part of the stack
area for reading file
get _LOADED table
error is in the self argument itself?
not the same?
closure with those upvalues
error?
is there a name?
`nil' has a unique fixed reference
not found?
remove old buffer
no such field?
** Find or create a module table with a given name. The function
** first looks at the _LOADED table and, if that fails, try a
** global variable with that name. In any case, leaves on the stack
** the module table.
is there info?
remove name
move content to new buffer
fill the table with given functions
no op
number of characters in buffer
extra error code for `luaL_load'
compatibility with old module system
buffer size
** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
}======================================================
** {======================================================
** File handles for IO library
** =======================================================
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
stream (NULL for incompletely created streams)
pre-defined references
initial buffer
to close stream (NULL for closed streams)
** {======================================================
** Generic Buffer manipulation
** =======================================================
buffer address
** ===============================================================
** some useful macros
** ===============================================================
create reserved slot
function to be called
'env' parameter?
** Reader for generic `load' function: `lua_load' uses the
** stack for internal stuff, so the reader cannot change the
** stack top. Instead, it keeps its resulting string in a
** reserved slot inside the stack.
set global _VERSION
handle signal
get 3 values from metamethod
and initial value
invalid numeral; force a fail
argument must be a table
** $Id: lbaselib.c,v 1.276.1.1 2013/04/12 18:48:47 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
no invalid trailing characters?
standard conversion
no metamethod?
set it as 1st upvalue
loading from a reader function
end point for 's'
no space for extra boolean?
skip initial spaces
exchange function...
** reserved slot, above all arguments, to hold a copy of the returned
** string to avoid it being collected while parsed. 'load' has four
** optional arguments (chunk, source name, mode, and environment).
skip trailing spaces
loading a string?
no metatable
'env' index or 0 if no 'env'
return nil plus error message
return false, msg
not a number
error (message is on top of the stack)
number of arguments
comment: remove 'env' if not used by previous call
label: code-design
open lib into global table
state,
next value
create space for status result
argument 'self' to metamethod
environment for loaded function
save string in reserved slot
returns either __metatable field (if present) or metatable
}======================================================
set global _G
value to print
...and error handler
put first result in first slot
else not a number; must be something
create space for return values
first result (status)
add extra information?
create a 2nd argument if there isn't one
else not a number
get result
put before error message
** {======================================================
** Generic Read function
** =======================================================
comment: not used
label: code-design
get function
call it
pop result
will return generator,
number of bits to consider in a number
** $Id: lbitlib.c,v 1.18.1.2 2013/07/09 18:01:41 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
builds a number with 'n' ones (1 <= n <= LUA_NBITS)
shift right?
arithmetic shift for 'negative' number
comment:
** get field and width arguments for field-manipulation functions,
** checking whether they are valid.
** ('luaL_error' called without 'return' to avoid later warnings about
** 'width' being used uninitialized.)
label: code-design
add signal bit
macro to trim extra bits
erase bits outside given width
avoid undefined shift of LUA_NBITS when i == 0
shift left
i = i % NBITS
position after whole expression
operand must be on the `stack'
operand must be on the 'stack'
insert last jump in `f' list
find last element
free registers with list values
invalid var kind to store
jump to default target
argument is +1 to reserve 0 as non-op
put this jump in `t' list
else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
go through and create a new entry for this value
base register for op_self
insert last jump in `t' list
else go through
exp is already in a register
end of list
l = max(l, pl)
turn offset into absolute position
always false; do nothing
cannot happen
fold it
not found
remove previous OP_NOT
put new instruction in code array
't' is in a register?
constant fits in RK operand?
interchange true and false lists
regular case
constant not found; create a new entry
nothing to do...
from = min(from, pfrom)
cannot patch other instructions
those instructions may be jump targets
handle -0 and NaN
position of an eventual LOAD true
o1 <==> o2
there is one value available (somewhere)
cannot use nil as key; instead use table itself to represent nil
go through
point to itself represents end of list
do not attempt to divide by 0
last register to set nil
reg. is not a local?
default
no jumps to current position?
** returns current `pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block).
save corresponding line information
numerical value does not need GC barrier;
table has no metatable, so it does not need to invalidate cache
constant fits in argC?
exchange args to replace by `<' or `<='
expression is an open function call?
assume 't' is in an upvalue
else no optimization
** check whether list has any jump that do not produce a value
** (or produce an inverted value)
position of an eventual LOAD false
keep them on hold
not a constant in the right range: put it in a register
save list of jumps to here
always true; do nothing
** $Id: lcode.c,v 2.62.1.1 2013/04/12 18:48:47 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
`pc' will change
register where 'e' was placed
use raw representation as key to avoid numeric problems
function and 'self' produced by op_self
can connect both?
no register to put value or register already has the value
put value on it
can relocate its simple result
pc of last jump
minus constant?
list must be closed
cannot operate on constants
** grep "ORDER OPR" if you change these enums (ORDER OP)
** Marks the end of a patch list. It is an invalid value both as an absolute
** address, and as a list link (would link an element to itself).
** $Id: lcode.h,v 1.58.1.1 2013/04/12 18:48:47 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
does it have frames?
error flag
return true + `resume' returns
move function from L to NL
initial state
** $Id: lcorolib.c,v 1.5.1.1 2013/04/12 18:48:47 roberto Exp $
** Coroutine Library
** See Copyright Notice in lua.h
it is running
propagate error
some error occurred
error object is a string?
move error message
remove results anyway
move function to top
return false + error message
add extra info
move yielded values
EOZ
7.
1.
6.
}
3.
d.
0.
a.
b.
9.
e.
{
** $Id: lctype.c,v 1.11.1.1 2013/04/12 18:48:47 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
5.
2.
c.
f.
4.
8.
comment: ASCII case: can use its own tables; faster and fixed
label: code-design
** use standard C ctypes
must use standard C ctype
{
two more entries for 0 and -1 (EOZ)
** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
** WARNING: the functions defined here do not necessarily correspond
** to the similar functions in the standard C ctype.h. They are
** optimized for the specific needs of Lua
}{
}
** add 1 to char to allow index -1 (EOZ)
** this 'ltolower' only works for alphabetic characters
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
** $Id: ldblib.c,v 1.132.1.2 2015/02/19 17:16:55 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
setmetatable(hooktable) = hooktable
non-string 'msg'?
set hooks
push name
external hook?
set new hook
out of range?
return 1st argument
return it untouched
creating hook table?
push local name
push function
level out of range
turn off hooks
no metatable
remove eventual returns
function argument?
return table
re-order
remove hook table
no name (nor value)
push local value
stack-level argument
local-variable index
* hooktable.__mode = "k"
get hook
cannot know who sets that register
active function; get information through 'ar'
calling instruction index
table index
move from 'b' to 'a'
pop value
not found
no source available; use "?" instead
update 'jmptarget'
for iterator
'name' already filled
is a local?
** $Id: ldebug.c,v 2.90.1.4 2015/02/19 17:05:13 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
get name for 'b'
jumped code can change 'a'
}======================================================
no reasonable name found
first operand is wrong
generic name for any valid slot
** find a "name" for the RK value 'c'
affect all registers above base
check whether 'o' is an upvalue
add file:line information
no 'standard' name?
** {======================================================
** Symbolic Execution
** =======================================================
current position sets that register
information about non-active function?
push function
'c' is a register
name of indexed variable
turn off hooks?
key index
comment: to avoid warnings
label: code-design
affect all regs above its base
no such level
calling instruction
generic name for any vararg
not a Lua function?
level found?
no name
comment:
** only ANSI way to check whether a pointer points to an array
** (used only for error messages, so efficiency is not a big concern)
label: code-design
for all lines with code
is Lua code?
else no useful name can be found
skip the '>'
calling function
literal constant?
all other instructions can call only through metamethods
any code before this address is conditional
search for 'c'
get function name
pop function
boolean 'true' to be the value of all indices
else no reasonable name found
move argument
set registers from 'a' to 'a+b'
no? try a register
access to vararg values?
go through to return NULL
new table to store active lines
handled by lua_getinfo
** try to find last instruction before 'lastpc' that modified register 'reg'
invalid (negative) level
call it
could find instruction?
no such vararg
jump is forward and do not skip `lastpc'?
consider live variables at function start (parameters)
is there an error handling function?
invalid option
found a constant name?
exchange its 'func' and 'extra' values
calling function is a known Lua function?
any instruction that set A
could not find reasonable name
table[line] = true
is 'n' inside 'ci' stack?
else try symbolic execution
is code conditional (inside a jump)?
get function that yielded
** this function can be called asynchronous (e.g. during a signal)
is 'c' a constant?
push it on stack
it is its own name
keep last instruction that changed 'reg'
** $Id: ldebug.h,v 2.7.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
Active Lua function (given call info)
call it (last chance to jump out)
continue running the coroutine
push error message
finish interrupted instruction
correct 'pc'
stack grow uses memory
run continuation
save context
an error occurred?
back to caller
execute down to higher C 'boundary'
do the actual call
Lua function: prepare its call
no pending pcall
allow yields
dynamic structures used by the parser
jump to it
close possible pending closures
is there a continuation?
no recovery point
restore old error handler
res == final position of 1st result
error message on current top
move fixed parameters to final position
ensure minimum stack size
is a Lua function?
not in base level?
}======================================================
comment: reuse preregistered msg.
label: code-design
erase new segment
number of real arguments
re-throw in main thread
finish 'lua_callk'/'lua_pcall'
'oldpc' for caller function
initialize upvalues
does it have a continuation?
no handler at all; abort
C closure
move results to correct place
stack overflow?
'default' status
hook may change stack
dummy variable
** $Id: ldo.c,v 2.108.1.3 2013/11/08 18:22:50 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
C++ exceptions
** do the work for 'lua_resume' in protected mode
finish 'luaD_precall'
light C function
"finish" luaD_pcall
was inside a pcall?
** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By
** default, Lua handles errors with exceptions when compiling as
** C++ code, with _longjmp/_setjmp when asked to use them, and with
** longjmp/setjmp otherwise.
Lua function
number of arguments (Lua) or returns (C)
restore 'nny'
dynamic structure used by the scanner
save 'nny'
retry with 'function' tag method
must have a continuation
stack is empty?
** returns true if function has been executed (C function)
cannot call hooks inside a hook
yielded inside a hook?
memory error?
some space for error handling
unrecoverable error
protect stack below results
cannot yield during parsing
Lua function?
call has error status
shrink it
now 'enter' new function
main thread has a handler?
hooks assume 'pc' is already incremented
return to 'luaD_hook'
jump back to 'lua_resume'
error after extra size?
coroutine is in base level; start running it
panic function?
call continuation
inside a hook?
mark it as dead
'common' yield
first fixed argument
no call status?
resuming from previous yield
check again for new 'base'
previous call may change stack
data to `f_parser'
finish 'lua_pcall'
chain new error handler
** check whether thread has a suspended protected call
coroutine finished normally
chain list of long jump buffers
recover point?
call it
yield results come from continuation
may be starting a coroutine
(here it is)
error while handing stack error
tag method is the new function to be called
** {======================================================
** Error-recovery functions
** =======================================================
call continuation function
yield or regular error
0 iff wanted == LUA_MULTRET
thread has no error handler
complete missing arguments
** Execute a protected parser.
just continue running Lua code
comment: in Unix, try _longjmp/_setjmp (more efficient)
label: code-design
error calling 'lua_resume'?
remove args from the stack
final position of first argument
not a function
Open a hole inside the stack at `func'
search for a pcall
read first character
set status
copy error obj.
default handling with long jumps
** Call a function (C or Lua). The function to be called is at *func.
** The arguments are on the stack, right after the function.
** When returns, all the results are on the stack, starting at the original
** function position.
should be zero to be yieldable
C function?
handling stack overflow?
starting point
error?
mark thread as `dead'
must be inside a hook
previous call can change stack
error code
** signal an error in the call to 'resume', not in the execution of the
** coroutine itself. (Such errors should not be handled by any coroutine
** error handler and should not kill the coroutine.)
would grow instead of shrink?
don't change stack (change only for debugging)
thread has an error handler?
part of stack in use
now it must be a function
save current 'func'
** $Id: ldo.h,v 2.20.1.1 2013/04/12 18:48:47 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
comment: type of protected functions, to be ran by `runprotected'
label: code-design
** dump Lua function as precompiled chunk
** $Id: ldump.c,v 2.17.1.1 2013/04/12 18:48:47 roberto Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
include trailing '\0'
current value lives in the stack
is it open?
remove from `uvhead' list
** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found.
remove from open list
remove upvalue from 'uvhead' list
found a corresponding upvalue?
not found
double link it in `uvhead' list
now current value lives here
move value to upvalue slot
** $Id: lfunc.c,v 2.30.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
comment: is it dead?
label: code-design
not found: create a new one
free upvalue
resurrect it
is variable active?
link upvalue into 'allgc' list
remove from `open' list
** $Id: lfunc.h,v 2.8.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
at this point, all resurrected objects are marked.
is 'curr' dead?
true if table has entry "white-key -> white-value"
"sweep" object
no more strings to sweep?
sweep all objects to turn them back to white
(as white has not changed, nothing extra will be collected)
mark any finalizing object left from previous cycle
mark nested protos
is there a weak mode?
** sweep a list until a live object (or end of list)
comment:
** macro to adjust 'pause': 'pause' is actually used like
** 'pause / PAUSEADJ' (value chosen by tests)
label: code-design
remove it
separate all objects with finalizers
push finalizer...
comment: may have to clean white keys
label: code-design
comment: free extra CallInfo slots
label: code-design
open upvalues remain gray
do not run finalizers during emergency GC
run entire collection
clear nothing
make object white
strings are `values', so are never weak
** {======================================================
** Sweep Functions
** =======================================================
memory traversed in this step
** barrier that moves collector forward, that is, mark the white object
** being pointed by a black object.
** set a reasonable "time" to wait before starting a new GC cycle;
** cycle will start when memory use hits threshold
comment: unused and unmarked key; remove it
label: code-design
nothing else to mark; make it black
start counting work
free all string lists
at this point, all strongly accessible objects are marked.
registry and global metatables may be changed by API
comment:
** barrier for prototypes. When creating first closure (cache is
** NULL), use a forward barrier; this may be the only closure of the
** prototype (if it is a "regular" function, with a single instance)
** and the prototype may be big, so it is better to avoid traversing
** it again. Otherwise, use a backward barrier, to avoid marking all
** possible instances.
label: code-design
return it to 'allgc' list
mark value
mark live elements in the stack
** enter first sweep phase (strings) and prepare pointers for other
** sweep phases. The calls to 'sweeptolive' make pointers point to an
** object inside the list (instead of to the header), so that the real
** sweep do not need to skip objects created between "now" and the start
** of the real sweep.
** Returns how many objects it swept.
it is being visited now
set the old bit of all surviving objects
mark that it is not in 'tobefnz'
start new collection
** clear entries with unmarked keys from all weaktables in list 'l' up
** to element 'f'
avoid removing current sweep object
traverse marked some value?
perform a full regular collection
}======================================================
must keep invariant?
update marks
use a backward barrier
strong keys?
save what was counted
first time?
** check color (and invariants) for an upvalue that was closed,
** i.e., moved into the 'allgc' list
** clear entries with unmarked values from all weaktables in list 'l' up
** to element 'f'
is there an error object?
traverse array part
move 'o' to 'finobj' list
stop counting (objects being finalized)
adjust 'estimate'
may there be some black objects?
has to be cleared later
remove from 'gray' list
comment:
** retraverse all gray lists. Because tables may be reinserted in other
** lists when traversed, traverse the original lists to avoid traversing
** twice the same table (which is not wrong, but inefficient)
label: code-design
remove 'curr' from list
stop counting (do not (re)count grays)
strong values?
is there a white value?
** barrier that moves collector backward, that is, mark the black object
** pointing to a white object as gray again. (Current implementation
** only works for tables; access to 'gclist' is not uniform across
** different types.)
traverse objects caught by write barrier and by 'remarkupvals'
comment: remark occasional upvalues of (maybe) dead threads
label: code-design
** link table 'h' into list pointed by 'p'
start to count memory traversed
is there a finalizer?
** mark root set and reset all gray lists, to start a new
** incremental (or full) collection
entry is empty?
don't bother with it
** 'makewhite' erases all color bits plus the old bit and then
** sets only the current white bit
update control
generational mode?
count call infos to compute size
half the size of the string table
clear keys from all ephemeron tables
no need to clean
mark running thread
... or is finalized...
estimate of total memory traversed
sweep open upvalues
** traverse one gray object, turning it to black (except for threads,
** which are always gray).
stop sweeping this list
complete counting
go to next element
signal for a major collection
standard list for collectable objects
** {======================================================
** Finalization
** =======================================================
** {======================================================
** Generic functions
** =======================================================
traverse main gray list
** mark an object. Userdata, strings, and closed upvalues are visited
** and turned black here. Other objects are marked gray and added
** to appropriate list to be visited (and turned black) later. (Open
** upvalues are already linked in 'headuv' list.)
** cost of sweeping one element (the size of a small object divided
** by some adjust for the sweep speed)
** create a new collectable object (with given type and size) and link
** it to '*list'. 'offset' tells how many bytes to allocate before the
** object itself (used only by states).
or has no finalizer?
** advances the garbage collector until it reaches a state allowed
** by 'statemask'
if there is array part, assume it may have white values (do not
traverse it just to check)
real end of stack
remove it from 'tobefnz' list
** mark all values stored in marked open upvalues. (See comment in
** 'lstate.h'.)
sweep main thread
traverse hash part
halve its size
is really weak?
change to incremental mode
no more `gray' objects
maximum number of finalizers to call in each GC step
make sure gray lists are consistent
... and its argument
mark its prototype
** mark metamethods for basic types
value was collected?
comment:
** macro to adjust 'stepmul': 'stepmul' is actually used like
** 'stepmul / STEPMULADJ' (value chosen by tests)
label: code-design
free concatenation buffer
finish collection
** performs a basic GC step only if collector is running
find last 'next' field in 'tobefnz' list (to add elements in its end)
open upvalues are never black
remove value ...
** {======================================================
** Traverse functions
** =======================================================
mark its upvalues
not keeping invariant?
do not sweep old generation
overflow; truncate to maximum
go through
** if object 'o' has a finalizer, remove it from 'allgc' list (must
** search the list to find it) and link it in 'finobj' list.
prepare to sweep strings, finalizable objects, and regular objects
** $Id: lgc.c,v 2.140.1.3 2014/09/01 16:55:08 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
table must be cleared
won't be finalized again
re-throw error
comment: this "white" makes all objects look dead
label: code-design
clear values from weak tables, before checking finalizers
skip restart
mark objects that will be finalized
not being collected?
error in __gc metamethod
value not marked yet?
** change GC mode
call one finalizer
mark it as such
finish mark phase
restore state
change to generational mode
run a few finalizers (or all of them at the end of a collect cycle)
no white keys
avoid ridiculous low values (and 0)
** if key is not marked, mark its entry as dead (therefore removing it
** from the table)
comment: remove dead objects from weak tables
label: code-design
true if an object is marked in this traversal
** {======================================================
** Mark functions
** =======================================================
bits to clear and to set in all live objects
traverse all finalizable objects
make prototype gray (again)
remove 'o' from root list
flip current white
mark upvalue names
clear values from resurrected weak tables
add what was traversed by 'atomic'
avoid being called too often
mark main obj. as white to avoid other barriers
make object gray (again)
separate objects to be finalized
must sweep all objects to turn them back to white
(as white has not changed, nothing will be collected)
stop sweep when this is true
do not stop
see MOVE OLD rule
restore hooks
no white values
allow cache to be collected
clear not-marked stack slice
save original lists
** sweep at most 'count' elements from a list of GCObjects erasing dead
** objects, where a dead (not alive) object is one marked with the "old"
** (non current) white and not fixed.
** In non-generational mode, change all non-dead objects back to white,
** preparing for next collection cycle.
** In generational mode, keep black objects black, and also mark them as
** old; stop when hitting an old object, as all objects after that
** one will be old too.
** When object is a thread, sweep its list of open upvalues too.
get ephemeron list
** move all unreachable objects (or 'all' objects) that need
** finalization from list 'finobj' to list 'tobefnz' (to be finalized)
tables will return to this list when traversed
always perform at least one single step
insert into 'grayagain' list
** mark all objects in list of being-finalized
mark it now
** tells whether a key or value can be cleared from a weak
** table. Non-collectable objects are never removed from weak
** tables. Strings behave as `values', so are never removed too. for
** other objects: if really collected, cannot keep them; for objects
** being finalized, keep them in keys, but not in values
obj. is already separated...
link at the end of 'tobefnz' list
clear keys from all allweak tables
final traversal?
search for pointer pointing to 'o'
should not change the stack during an emergency gc cycle
get first element
finish any pending sweep phase to start a new cycle
sweep phase
normal mode
keep table gray
restart counting
sweep thread's upvalues
true if table has white keys
overflow?
does table have white keys?
nothing to traverse now
table will have to be cleared
do some work
not weak
remove 'curr' from 'finobj' list
remove value
all weak
** {======================================================
** GC control
** =======================================================
** sweep the (open) upvalues of a thread and resize its stack and
** list of call-info structures.
traverse all elements from 'l'
** performs a full GC cycle; if "isemergency", does not call
** finalizers (which could change stack positions)
generational mode must be kept in propagate phase
no overflow
propagate changes
key is not marked (yet)?
do not change sizes in emergency
stack not completely built yet
error while running __gc?
avoid GC steps
estimate of memory marked by 'atomic'
using less than that half?
mark basic metatables
mark literals
and remove entry from table
no grays left
signal for another major collection?
convert debt from Kb to 'work units' (avoid zero debt and overflows)
stop debug hooks during GC metamethod
clear all color bits + old bit
mark local-variable names
nothing to change
run complete (minor) cycle
will have to revisit all ephemeron tables
pause until next cycle
restore invariant
mark key
open?
have to propagate again
empty
convert 'work units' to Kb
finalizers can create objs. in 'finobj'
maximum number of elements to sweep in each single step
keep estimate from last major coll.
erase 'curr'
** one after last element in a hash array
link it in list 'finobj'
** performs a basic GC step
** call all pending finalizers
nothing to be done
traverse array part (numeric keys are 'strong')
and (next line) call the finalizer
must propagate again
remark, to propagate `preserveness'
comment: Layout for bit use in `marked' field:
label: code-design
object has been separated for finalization
object is old (only in generational mode)
object is fixed (should not be collected)
how much to allocate before next GC step
comment:
** some useful bit tricks
label: code-design
** Collectable objects may have one of three colors: white, which
** means the object is not marked; gray, which means the
** object is marked, but its references may be not marked; and
** black, which means that the object and all its references are marked.
** The main invariant of the garbage collector, while marking objects,
** is that a black object can never point to a white one. Moreover,
** any gray object must be in a "gray list" (gray, grayagain, weak,
** allweak, ephemeron) so that it can be visited again before finishing
** the collection cycle. These lists have no meaning when the invariant
** is not being enforced (e.g., sweep phase).
object is white (type 1)
** macros to tell when main invariant (white objects cannot point to black
** ones) must be kept. During a non-generational collection, the sweep
** phase may break the invariant, as objects turned white may point to
** still-black objects. The invariant is restored when sweep ends and
** all objects are white again. During a generational collection, the
** invariant must be kept all times.
** $Id: lgc.h,v 2.58.1.1 2013/04/12 18:48:47 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
object is white (type 0)
bit 7 is currently used by tests (luaL_checkmemory)
** Possible states of the Garbage Collector
~100 small strings
MOVE OLD rule: whenever an object is moved to the beginning of
a GC list, its old bit must be cleared
neither white nor black
object is black
object is in 'finobj' list or in 'tobefnz'
** Outside the collector, the state in generational mode is kept in
** 'propagate', so 'keepinvariant' is always true.
** these libs are loaded by lua.c and are readily available to any Lua
** program
remove lib
remove _PRELOAD table
** $Id: linit.c,v 1.32.1.1 2013/04/12 18:48:47 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
** If you embed Lua in your program and need to open the standard
** libraries, call luaL_openlibs in your program. If you need a
** different set of libraries, copy this file to your project and edit
** it to suit your needs.
** these libs are preloaded and must be required before used
call open functions from 'loadedlibs' and set results to global table
add open functions from 'preloadedlibs' into 'package.preload' table
create (and set) default files
use standard output
make sure argument is an open stream
** function to (not) close the standard files stdin, stdout, and stderr
skip if char is '+'
true iff read something
ensure stack space for all results and for auxlib's buffer
copy arguments
close/not close file when finished
at least one argument
pop new metatable
chop 'eol' if needed
double buffer size at each iteration
{
mark file handle as 'closed'
mark stream as closed
number
push metatable
number of arguments to read
eof?
push arguments to 'g_read'
}======================================================
** functions for 'io' library
try to read 'n' chars
metatable.__index = metatable
file
optimization: could be done exactly as for strings
read entire file
add file to module
** $Id: liolib.c,v 2.112.1.1 2013/04/12 18:48:47 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
** function to close 'popen' files
avoid buffers too large
check whether read something
file handle
to traverse/check mode
** methods for file handles
'n' is number of results
}{
file is already closed?
line
no argument?
** {======================================================
** lua_fseek: configuration for longer offsets
** =======================================================
ignore closed and incompletely open files
is there error information?
prepare buffer to read whole block
** {======================================================
** lua_popen spawns a new process connected to the current
** one through the file streams.
** =======================================================
** When creating file handles, always creates a `closed' file handle
** before opening the actual file; so, if there is a memory error, the
** file is not left opened.
create metatable for file handles
always success
** function to close regular files
Windows (but not DDK) and Visual C++ 2005 or higher
2nd result is error message
skip if char is 'b'
how much to read in each cycle
put file at index 1
close buffer
add file methods to new metatable
** This definition must come before the inclusion of 'stdio.h'; it
** should not affect non-POSIX systems
** {======================================================
** READ
** =======================================================
add file to registry
close it
close it after iteration
"result" to be removed
keep file opened
file handle already on stack top
** Check whether 'mode' matches '[rwa]%+?b?'.
** Change this macro to accept other modes for 'fopen' besides
** the standard ones.
open a new file
new module
line with end-of-line
number of chars actually read
read at least an `eol'
read fails
default definitions
first result is nil: EOF or error
return them
check that it's a valid file handle
error
push nil instead
not a file
ensure that arguments will fit here and into 'io_readline' stack
should return at least a nil
do not close it after iteration
}
to return 1 result
return current value
no arguments?
generator created file?
push file at the stack top (to be returned)
put it at index 1
remove last result
get default input
no file name?
read at least one value?
LUA_NUMBER
skip 2nd `['
short literal strings
** increment line number and skips newline sequence (any of
** \n, \r, \n\r, or \r\n)
boolean value does not need GC barrier;
table has no metatable, so it does not need to invalidate cache
identifier or reserved word?
'...'
create env name
save 'c'
exponent part?
digital escape \ddd
try to update decimal point separator
else short comment
fixed format (symbols and reserved words)?
initialize buffer
string starts with a newline?
** skip a sequence '[=*[' or ']=*]' and return its number of '='s or
** -1 if sequence is malformed
read up to 3 digits
temporarily anchor it in stack
skip it
use this one
final character to be saved
and discharge it
read next token
** this function is quite liberal in what it accepts, as 'luaO_str2d'
** will reject ill-formed numerals.
spaces
long comment?
reserved words are never collected
string already present
optional exponent sign
long string or simply '['
skip the 'z'
skip `\n\r' or `\r\n'
escape sequences
skip until end of line (or end of file)
comment: to avoid warnings
label: code-design
entry for `str'
for error message
names, strings, and numerals
skip `\n' or `\r'
result accumulator
read next character
ORDER RESERVED
not in use yet? (see 'addK')
else go through
reserved word
** change all characters 'from' in buffer to 'to'
read two hexadecimal digits
hexadecimal?
no look-ahead token
will raise an error next loop
previous call may dirty the buff.
** in case of format error, try to change decimal point separator to
** the one defined in the current locale and check again
keep input for error message
format error with correct decimal point: no more options
do not save the `\'
avoid wasting space
skip long comment
prepare error message
** creates a new string and anchors it in function's table so that
** it will not be collected until the end of the function's compilation
** (by that time it should be anchored in function's prototype)
skip 2nd `]'
create new string
reserved word?
skip delimiter
follow locale for decimal point
line breaks
'..'
re-use value previously stored
'-' or '--' (comment)
remove string from stack
try new decimal separator
'.', '..', '...', or number
t[string] = true
else is a comment
undo change (for error message)
zap following span of spaces
** $Id: llex.c,v 2.63.1.3 2015/02/09 17:56:34 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
single-byte symbols?
single-char tokens (+ - / ...)
never collect this name
is there a look-ahead token?
keep delimiter (for error messages)
`skip_sep' may dirty the buffer
** =======================================================
** LEXICAL ANALYZER
** =======================================================
format error?
environment variable name
** $Id: llex.h,v 1.72.1.1 2013/04/12 18:48:47 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
current character (charint)
terminal symbols denoted by reserved words
input stream
semantics information
dynamic structures used by the parser
input line counter
state of the lexer plus state of the parser when shared by all
functions
look ahead token
number of reserved words
current source name
current token
* WARNING: if you change the order of this enumeration,
* grep "ORDER RESERVED"
other terminal symbols
buffer for tokens
current function (parser)
locale decimal point
line of last token `consumed'
type to ensure maximum alignment
** lua_number2int is a macro to convert lua_Number to int.
** lua_number2integer is a macro to convert lua_Number to lua_Integer.
** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
** luai_hashnum is a macro to hash a lua_Number value into an integer.
** The hash must be deterministic and give reasonable values for
** both small and large values (outside the range of integers).
** conversion of pointer to integer
** this is for hashing only; there is no problem if the integer
** cannot hold the whole pointer value
comment:
** macro to control inclusion of some hard tests on stack reallocation
label: test
** non-return type
** assertion for checking API calls
}{
maximum value of an int (-2 for safety)
realloc stack keeping its size
avoid -0
}
** maximum depth for nested C calls and syntactical nested non-terminals
** in a program. (Value must fit in an unsigned short int.)
comment: the following definitions always work, but may be slow
label: code-design
add double bits for his hash
minimum size for string buffer
** maximum number of upvalues in a closure (both C and Lua). (Value
** must fit in an unsigned char.)
** these macros allow user-specific actions on threads when you defined
** LUAI_EXTRASPACE and need to do something extra when a thread is
** created/deleted/resumed/yielded.
{
the next trick should work on any machine using IEEE754 with
a 32-bit int type
minimum size for the string table (must be power of 2)
chars used as small naturals (so that `char' is reserved for characters)
trick with Microsoft assembler for X86
comment: to avoid warnings
label: code-design
comment: on several machines, coercion from unsigned to double is slow,
so it may be worth to avoid
label: code-design
internal assertions for in-house debugging
to avoid problems with conditions too long
empty
** type for virtual-machine instructions
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
maximum stack for a Lua function
the trick can be expanded to lua_Integer when it is a 32-bit value
result of a `usual argument conversion' over lua_Number
** $Id: llimits.h,v 1.103.1.1 2013/04/12 18:48:47 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h
the following definition assures proper modulo behavior
only upper limit
[l, u]
number of arguments
Number between 0 and 1
** $Id: lmathlib.c,v 1.83.1.1 2013/04/12 18:48:47 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
no arguments
discard first value to avoid undesirable correlations
** Open math library
lower and upper limits
check number of arguments
[1, u]
the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX
** $Id: lmem.c,v 1.84.1.1 2013/04/12 18:48:47 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
cannot double it?
cannot grow even a little?
update only when everything else is OK
minimum size
** generic allocation routine.
force a GC whenever possible
try to free some memory...
still have at least one free place
try again
** About the realloc function:
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
** (`osize' is the old size, `nsize' is the new size)
**
** * frealloc(ud, NULL, x, s) creates a new block of size `s' (no
** matter 'x').
**
** * frealloc(ud, p, x, 0) frees the block `p'
** (in this specific case, frealloc must return NULL);
** particularly, frealloc(ud, NULL, 0, 0) does nothing
** (which is equivalent to free(NULL) in ANSI C)
**
** frealloc returns NULL if it cannot create or reallocate the area
** (any reallocation to an equal or smaller size cannot fail!)
not to be called directly
** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
comment:
** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is
** always constant.
** The macro is somewhat complex to avoid warnings:
** +1 avoids warnings of "comparison has constant result";
** cast to 'void' avoids warnings of "value unused".
label: code-design
no errors?
remove file name
pop CLIBS table
concatenate error message
_LOADED[name] = true
root not found
unable to load library
comment: concatenate error msg. entry
label: code-design
return nil + error message
fill it with pre-defined searchers
CLIBS[#CLIBS + 1] = plib
create new metatable
not found
** {========================================================================
** This is an implementation of loadlib based on the dlfcn interface.
** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
** as an emulation layer on top of native functions.
** =========================================================================
run loader to load module
is table an initialized module?
non-empty separator?
_LOADED[name]
set field 'cpath'
to build error message
name is 1st argument (before search data)
package is already loaded
CLIBS[path] = plib
** LUA_PATH and LUA_CPATH are the names of the environment
** variables that Lua check to set its paths.
comment: remove extra return
label: code-design
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
** LUA_IGMARK is a mark to ignore all before it when building the
** luaopen_ function name.
put it in field 'searchers'
unable to find function
use default
iterate over available searchers to find a loader
copy new environment table to top
open failed
set finalizer for CLIBS table
try alternative name
}======================================================
remove 'getfield' result
module loader found
module did not set a value?
remove function
comment: not used
label: code-design
does file exist and is readable?
did it find a loader?
get a searcher
no errors
** return registry.LUA_NOENV as a boolean
look for last dot in module name
pop CLIBS table and 'plib'
module not found in this path
non-nil return?
searcher returned error message?
return nil, error message, and where
check whether table already has a _NAME field
else must load package
try to open file
return the loaded function
set 'package' as upvalue for next lib
error codes for ll_loadfunc
set field `preload'
** system-dependent functions
open lib into global table
** {======================================================
** Fallback for other systems
** =======================================================
table (in the registry) that keeps handles for all loaded C libraries
return that file name
_LOADED table will be at index 2
mt.__index = _G
put it in field `loaders'
module._M = module
** if needed, includes windows header before everything else
no more searchers?
auxiliary mark (for internal use)
skip separators
template
is it there?
return 'true'
_LOADED[name] = returned value
pop handle
get calling function
pop global table
find next separator
create error message
module
check loaded C libraries
else create new function
module loaded successfully?
** __gc tag method for CLIBS table: calls 'll_unloadlib' for all lib
** handles in list CLIBS
set field 'path'
return open function and file name
no; initialize it
for each handle, in reverse order
open function not found
** optional flags for LoadLibraryEx
real error
no more templates
create `package' table
remove nil
** {======================================================
** 'require' function
** =======================================================
comment: will be 2nd argument to module
label: code-design
metatable for CLIBS
remove path template
no environment variable?
error message is on top of the stack
must load library?
pass name as argument to module loader
error; error message is on stack top
loading only library (no function)?
use true as result
store config information
set field `loaded'
call it
separator for open functions in C libraries
comment: not used: symbols are 'global' by default
label: code-design
** LUA_CSUBSEP is the character that replaces dots in submodule names
** when searching for a C loader.
** LUA_LSUBSEP is the character that replaces dots in submodule names
** when searching for a Lua loader.
get option (a function)
will be at index 3
remove original string
get handle CLIBS[n]
avoid 'calling' extra info.
remove value
replace it by 'dirsep'
is root
else go ahead and try old-style name
make a copy of 'searchers' table
** $Id: loadlib.c,v 1.111.1.1 2013/04/12 18:48:47 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
** This module contains an implementation of loadlib for Unix systems
** that have dlfcn, an implementation for Windows, and a stub for other
** systems.
prefix for open functions in C libraries
extra copy to be returned
set _PACKAGE as package name (full module name minus last part)
create table CLIBS to keep track of loaded C libraries
** changes the environment variable of calling function
not found?
** {======================================================================
** This is an implementation of loadlib for Windows using native functions.
** =======================================================================
plib = CLIBS[path]
return 'package' table
get/create module table
** {======================================================
** 'module' function
** =======================================================
create 'searchers' table
last parameter
remove both returns
replace ";;" by ";AUXMARK;" and then AUXMARK by default path
set 'package' as upvalue for all searchers
each fractional digit divides value by 2^-4
signal
** convert an hexadecimal numeric string to a number, following
** C99 specification for 'strtod'
nothing recognized
read integer part
skip '0x'
1 if number is negative
** $Id: lobject.c,v 2.58.1.1 2013/04/12 18:48:47 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
should be enough space for a `%p'
small enough?
valid up to here
read exponent
string; format as [string "source"]
** converts an integer to a "floating point byte", represented as
** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
** eeeee != 0 and (xxx) otherwise.
check '0x'
invalid format (no '0x')
converts back
add '...' before rest of name
fmt + item
skip initial spaces
exponent part?
check signal
'literal' source
must have at least one digit
truncate it
reject 'inf' and 'nan'
this function handles only `%d', `%c', %f, %p, and `%s' formats
invalid format (no digit)
nothing is valid yet
add prefix
hexa?
OK if no trailing characters
skip dot
skip 'p'
save space for prefix+suffix+'\0'
read fractional part
exponent
file name
keep it
find first new line (if any)
number of chars of a literal string without the ending \0
small one-line source?
stop at first newline
number of characters in string
collectable objects
Macros to access values
constants used by the function
to new object
long strings
reserved words for short strings; "has hash" for longs
double linked list (when open)
** Union of all collectable objects
** numbers are represented in the 'd_' field. All other values have the
** value (NNMARK | tag) in 'tt__'. A number with such pattern would be
** a "signaled NaN", which is never generated by regular operations by
** the CPU (nor by 'strtod')
log2 of size of `node' array
{
Macros for internal tests
index of upvalue (in stack or in outer function's list)
** Tables
numbers
}======================================================
Variant tags for strings
macro defining a nil value
** Extra tags for non-values
map from opcodes to source lines (debug information)
light userdata
allows for external implementation for part of the trick
** Closures
mark a tag as collectable
ensures maximum alignment for strings
maximum stack used by this function
** $Id: lobject.h,v 2.71.1.2 2014/05/07 14:14:58 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
used for debug information
C closure
}{
ensures maximum alignment for `local' udata
functions defined inside the function
Lua closure
** Common header in struct form
size of 'upvalues'
light C function
correspondence with standard representation
** different types of assignments, according to destination
check whether a number is valid (useful only for NaN trick)
whether it is in stack
for chaining
array part
get the actual string (array of bytes) from a TString
** Tagged Values. This is the basic representation of values in Lua,
** an actual value plus a tag with its type.
basic check to distinguish numbers from non-numbers
to stack (not from same stack)
comment:
** these redefinitions are not mandatory, but these forms are more efficient
label: code-design
** (address of) a fixed nil value
the value (when closed)
** Description of an upvalue for function prototypes
type tag of a TValue with no variants (bits 0-3)
Macros to test type
light C functions
** Lua Upvalues
comment: first point where variable is dead
label: code-design
** tags for Tagged Values have the following use of bits:
** bits 0-3: actual tag (a LUA_T* value)
** bits 4-5: variant bits
** bit 6: whether value is collectable
a dead value may get the 'gc' field, but cannot access its contents
no such field; numbers are the entire struct
size of `p'
** LUA_TFUNCTION variants:
** 0 - Lua function
** 1 - light C function
** 2 - regular C function (closure)
** Header for userdata; memory area follows the end of this structure
from table to same table
size of `array' array
short strings
size of `k'
** `module' operation for hashing (size is always a power of 2)
** Description of a local variable for function prototypes
** (used for debug information)
first point where variable is active
any free position is before this position
tag with no variants (bits 0-3)
upvalue name (for debug information)
Variant tags for functions
last created closure with this prototype
points to stack or to its own value
** {======================================================
** types and prototypes
** =======================================================
type tag of a TValue (bits 0-3 for tags + variant bits 4-5)
Macros to set values
booleans
upvalue information
** Header for string value; string bytes follow the end of this structure
little endian
to table
** number of all possible tags (including LUA_TNONE but excluding DEADKEY)
}
Bit mark for collectable types
** {======================================================
** NaN Trick
** =======================================================
index to stack elements
number of fixed parameters
big endian
get the actual string (array of bytes) from a Lua value
raw type tag of a TValue
from stack to (same) stack
1<<p means tagmethod(p) is not present
number of bytes
list of upvalues
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
information about local variables (debug information)
** Union of all Lua values
empty
field-access macros
** Function Prototypes
OP_LOADNIL
OP_UNM
OP_MOVE
OP_SELF
OP_VARARG
OP_RETURN
OP_JMP
OP_FORPREP
OP_CLOSURE
OP_LOADKX
OP_DIV
OP_NOT
OP_LE
OP_TFORCALL
OP_LEN
OP_EQ
OP_SETUPVAL
OP_POW
OP_LT
OP_SETLIST
OP_TFORLOOP
T A B C mode opcode
ORDER OP
OP_EXTRAARG
OP_CONCAT
OP_SETTABLE
OP_MUL
OP_LOADK
OP_GETTABLE
OP_LOADBOOL
OP_GETTABUP
OP_FORLOOP
OP_MOD
OP_NEWTABLE
OP_SETTABUP
OP_TEST
OP_TAILCALL
OP_ADD
** $Id: lopcodes.c,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
OP_CALL
OP_SUB
OP_GETUPVAL
OP_TESTSET
A B R(A), R(A+1), ..., R(A+B) := nil
comment: argument is not used
label: code-design
** invalid register that fits in 8 bits
number of list items to accumulate before a SETLIST instruction
A B C R(A) := R(B)[RK(C)]
A B C if ((RK(B) == RK(C)) ~= A) then pc++
A C if not (R(A) <=> C) then pc++
A B C if (R(B) <=> C) then R(A) := R(B) else pc++
test whether value is a constant
A B C if ((RK(B) < RK(C)) ~= A) then pc++
** R(x) - register
** Kst(x) - constant (in constant table)
** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
===========================================================================
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
`A' : 8 bits
`B' : 9 bits
`C' : 9 bits
'Ax' : 26 bits ('A', 'B', and 'C' together)
`Bx' : 18 bits (`B' and `C' together)
`sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
for that argument (so that -max is represented by 0, and +max is
represented by 2*max), which is half the maximum for the corresponding
unsigned argument.
===========================================================================
A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
A B C return R(A)(R(A+1), ... ,R(A+B-1))
this bit 1 means constant (0 means register)
A Bx R(A) := Kst(Bx)
** Macros to operate RK indices
basic instruction format
A B C R(A) := UpValue[B][RK(C)]
A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
A B C R(A) := RK(B) ^ RK(C)
** the following macros help to manipulate instructions
A B C R(A)[RK(B)] := RK(C)
A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }
A B C R(A) := RK(B) - RK(C)
A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
`sBx' is signed
A B C R(A) := {} (size = B,C)
A B UpValue[B] := R(A)
A B C if ((RK(B) <= RK(C)) ~= A) then pc++
A sBx R(A)-=R(A+2); pc+=sBx
----------------------------------------------------------------------
name args description
------------------------------------------------------------------------
===========================================================================
Notes:
(*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then `top' is
set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,
OP_SETLIST) may use `top'.
(*) In OP_VARARG, if (B == 0) then use actual number of varargs and
set top (like in OP_CALL with C == 0).
(*) In OP_RETURN, if (B == 0) then return up to `top'.
(*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next
'instruction' is EXTRAARG(real C).
(*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.
(*) For comparisons, A specifies what condition the test should accept
(true or false).
(*) All `skips' (pc++) assume that next instruction is a jump.
===========================================================================
A B C R(A) := RK(B) / RK(C)
** size and position of opcode arguments.
A B R(A) := not R(B)
A B C R(A) := RK(B) * RK(C)
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
argument is used
A B R(A) := length of R(B)
A B R(A) := R(B)
opcode names
** grep "ORDER OP" if you change these enums
argument is a register or a jump offset
A B C R(A) := (Bool)B; if (C) pc++
gets the index of the constant
** $Id: lopcodes.h,v 1.142.1.2 2014/10/20 18:32:09 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
comment: Ax extra (larger) argument for previous opcode
label: code-design
argument is a constant or register/constant
A B return R(A), ... ,R(A+B-2) (see note)
A B C R(A) := RK(B) % RK(C)
A B R(A) := -R(B)
A Bx R(A) := closure(KPROTO[Bx])
A B R(A) := UpValue[B]
A B C R(A) := R(B).. ... ..R(C)
A R(A) := Kst(extra arg)
A B C UpValue[A][RK(B)] := RK(C)
A B R(A), R(A+1), ..., R(A+B-2) = vararg
A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
code a constant index as a RK value
** masks for instruction properties. The format is:
** bits 0-1: op mode
** bits 2-3: C arg mode
** bits 4-5: B arg mode
** bit 6: instruction set register A
** bit 7: operator is a test (next instruction must be a jump)
A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1)
creates a mask with `n' 1 bits at position `p'
creates a mask with `n' 0 bits at position `p'
A B C R(A) := RK(B) + RK(C)
valid two-char conversion specifier
** list of valid conversion specifiers for the 'strftime' function
invalid date?
UTC?
** By default, Lua uses tmpnam except when POSIX is available, where it
** uses mkstemp.
** By default, Lua uses gmtime/localtime, except when POSIX is available,
** where it uses gmtime_r/localtime_r
should be big enough for any conversion result
if NULL push nil
get current time
called without args?
one-char conversion specifier?
does not set field
comment: to avoid warnings
label: code-design
}======================================================
end buffer
** {======================================================
** Time/Date operations
** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
** wday=%w+1, yday=%j, isdst=? }
** =======================================================
9 = number of fields
skip `!'
undefined?
comment: 'if' to avoid warnings for unreachable 'return'
label: code-design
no conversion specifier?
make sure table is at the top
** $Id: loslib.c,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
true if there is a shell
fix it at the last register
not found as local at current level; try upvalues
index is the local being assigned? (index cannot be upvalue)
end of scope for declared variables
function created in next register
read first token
must skip over 'then' part if condition is false
assume that locals are already out of scope
global name?
param -> `...'
create and...
`:' NAME funcargs
funcname -> NAME {fieldsel} [`:' NAME]
not found
** check whether, in an assignment to an upvalue/local variable, the
** upvalue/local variable is begin used in a previous assignment to a
** table. If so, save original upvalue/local value in a safe place and
** use this safe copy in the previous assignment.
`[' exp1 `]'
expand while operators have priorities higher than `limit'
must enter block before 'goto'
env[varname]
stat -> forstat
** compiles the main function, which is a regular vararg function with an
** upvalue named LUA_ENV
no value (yet)
skip WHILE
free registers
============================================================
stat -> func | assignment
no more levels?
reserve register for parameters
** structure to chain all variables in the left-hand side of an
** assignment
`falses' are all equal here
control variables
left priority for each binary operator
skip over block if condition is false
skip DO
local function?
~=, >, >=
...set environment upvalue
skip other no-op statements
last token from outer function must be EOS
forstat -> FOR (fornum | forlist) END
^, .. (right associative)
cond -> exp
create control variables
chain
last list item read
skip double colon
instruction to skip 'then' code (if condition is false)
remove goto from pending list
patch escape list to 'if' end
only one single value?
funcargs
upvalues?
scope block
main function is always vararg
generic for
check all previous assignments
correct pending gotos to current block and try to close it
with visible labels
debug information will only see the variable after this point!
variable is local
stat -> ';' (empty statement)
stat -> 'goto' NAME
close the loop
return no values
includes call itself
open call
funcstat -> FUNCTION funcname body
stat -> assignment ?
remove 'near to' from final message
numeric for?
stat -> LOCAL NAME {`,' NAME} [`=' explist]
set initial array size
key is variable name
tail call?
may be needed for error messages
last exp. provides the difference
** "export" pending gotos to outer level, to check them against
** outer labels; if the block being exited has upvalues, and
** the goto exits the scope of any variable (which can be the
** upvalue), close those variables being exited.
** $Id: lparser.c,v 2.130.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
create and anchor TString
check for repeated labels
linked list of funcstates
** nodes for block list (list of active blocks)
close it if label already defined
IF cond THEN block
stat -> breakstat
update pending gotos to outer block
anchor closure (to avoid being collected)
block -> statlist
flush
call statement uses no results
correct label?
label not found; cannot close goto
prototype of current function
create declared variables
arg list is empty?
skip ';'
it's on the stack too
skip the '['
skip no-op statements
stat -> retstat
stat -> label
stat -> DO block END
else was LOCAL or UPVAL
** check whether new label 'lb' matches any pending gotos in current
** block; solves forward jumps
inner block?
optional step
default is global
there is no list item
constructor
return all `active' values
** {======================================================================
** Rules for Constructors
** =======================================================================
registers with returned values
true if some variable in the block is an upvalue
limit
return first untreated operator
comment: maximum number of local variables per function (must be smaller
than 250, due to the bytecode format)
label: code-design
default step = 1
close last argument
fornum -> NAME = exp1,exp1[,exp1] forbody
simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
constructor | FUNCTION body | suffixedexp
`then' part
anchor table of constants (to avoid being collected)
look up locals at current level
ELSEIF cond THEN block
ORDER OPR
may be 'listfield' or 'recfield'
stat -> RETURN [explist] [';']
constructor -> '{' [ field { sep field } [sep] ] '}'
sep -> ',' | ';'
variable (global, local, upvalue, or indexed)
previous assignment will use safe copy
followed by 'else'/'elseif'?
check labels in current block for a match
ls->t.token == '['
finish scope
index -> '[' expr ']'
Find variable with given name 'n'. If it is an upvalue, add this
upvalue into all intermediate functions.
}====================================================================
skip RETURN
close it
comment: remove extra values
label: code-design
** generates an error for an undefined 'goto'; choose appropriate
** message when label name is a reserved word (which can only be 'break')
stat -> funcstat
all scopes should be correctly finished
remove local labels
stat -> func
stat -> whilestat
pending gotos in outer block?
new local variable
** try to close a goto with existing labels; this solves backward jumps
skip the dot or colon
expression?
initial value
must jump over it
label is last no-op statement in the block?
registers 0/1 are always valid
true if `block' is a loop
** {======================================================================
** Expression parsing
** =======================================================================
suffixedexp ->
primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
scope for loop and control variables
label -> '::' NAME '::'
try upper levels
eventual position to save local variable
optional return values
enter its scope
stat -> repeatstat
param -> NAME
'return' must be last statement
move to next one
create a 'jump to here' to close upvalues
`else' part
do not count last expression (unknown number of elements)
field -> listfield | recfield
vararg
regular case (not goto/break)
assignment -> ',' suffixedexp assignment
index of first label in this block
GRAMMAR RULES
repeatstat -> REPEAT block UNTIL cond
and that is it
skip optional semicolon
check for repeated labels on the same block
comment: extra space to call generator
label: code-design
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
** where `binop' is any binary operator with a priority higher than `limit'
avoid default
finish loop
fieldsel -> ['.' | ':'] NAME
** {======================================================================
** Rules for Statements
** =======================================================================
forbody -> DO block
will jump to label if condition is true
read condition
create new entry for this label
call remove function and arguments and leaves
(unless changed) one result
false conditions finish the loop
'goto' is the entire block?
** prototypes for recursive non-terminal functions
index of first pending goto in this block
fieldsel
definition `happens' in the first line
assignment -> `=' explist
** check whether current token is in the follow set of a block.
** 'until' closes syntactical blocks, but do not close scope,
** so it handled in separate.
error
skip REPEAT
table descriptor
test_then_block -> [IF | ELSEIF] cond THEN block
stat -> ifstat
gen, state, control, plus at least one declared var
right priority
** adds a new prototype into list of prototypes
no more items pending
** codes instruction to create new closure in parent function.
** The OP_CLOSURE instruction must use the last available register,
** so that, if it invokes the GC, the GC knows which registers
** are in use at that time.
at least one expression
funcargs -> `(' [ explist ] `)'
read sub-expression with higher priority
whilestat -> WHILE cond DO block END
loop block
skip `for'
read condition (inside scope block)
try existing upvalues
primaryexp -> NAME | '(' expr ')'
`+' `-' `*' `/' `%'
total number of `record' elements
values must go to the `stack'
priority for unary operators
create 'self' parameter
table is the upvalue/local being assigned now?
scope for declared variables
pop table of constants
# active locals outside the block
close last expression
handle goto/break
listfield -> exp
forlist -> NAME {,NAME} IN explist forbody
statlist -> { stat [`;'] }
base register for call
skip break
Mark block where variable at given level was defined
(to emit close instructions later).
local will be used as an upval
index of new label being created
first variable name
semantic error
copy upvalue/local value to a temporary (in position 'extra')
exit list for finished parts
funcargs -> constructor
return all values
must use `seminfo' before `next'
number of array elements pending to be stored
not found; is a global
skip LOCAL
not found?
set initial table size
and, or
** create a label named "break" to resolve break statements
found?
==, <, <=
default assignment
funcargs -> STRING
loop scope (`break' jumps to this point)
will be a new upvalue
recfield -> (NAME | `['exp1`]') = exp1
skip FUNCTION
stat -> localstat
skip IF or ELSEIF
close pending breaks
total number of array elements
}======================================================================
final return
fix it at stack top
assigning to a table?
is `parlist' not empty?
body -> `(' parlist `)' block END
parlist -> [ param { `,' param } ]
explist -> expr { `,' expr }
ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END
parse main body
create main closure
last token read was anchored in defunct function; must re-anchor it
get environment variable
patch list of `exit when true'
whether 't' is register (VLOCAL) or upvalue (VUPVAL)
info = result register
chain of current blocks
t = table register/upvalue; idx = index R/K
list of labels or gotos
for indexed variables (VINDEXED)
label identifier
list of pending jumps to `pc'
array
info = index of constant in `k'
** $Id: lparser.h,v 1.70.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
table to find (and reuse) elements in `k'
number of elements in 'f->locvars'
current function header
no value
for generic use
dynamic structures used by the parser
description of active local variable
variable index in stack
number of entries in use
lexical state
next position to code (equivalent to `ncode')
number of elements in `k'
first free register
enclosing function
description of pending goto statements and label statements
local level where it appears in current block
'label' of last 'jump label'
table (register or upvalue)
list of active local variables
state needed to generate code for a given function
patch list of `exit when false'
nval = numerical value
for VKNUM
info = instruction pc
info = local register
number of upvalues
array size
number of active local variables
list of pending gotos
position in code
defined in lparser.c
number of elements in `p'
control of blocks
list of active labels
index of first local var (in Dyndata array)
** Expression descriptor
info = index of upvalue in 'upvalues'
index (R/K)
line where it appeared
** open parts of the state that may cause memory-allocation errors
no GC while building state
erase new stack
public function
allow gc
memory allocation error: free partial state
** Compute an initial seed as random as possible. In ANSI, rely on
** Address Space Layout Randomization (if present) to increase
** randomness..
collect all objects
registry[LUA_RIDX_GLOBALS] = table of globals
** $Id: lstate.c,v 2.99.1.2 2013/11/08 17:45:31 roberto Exp $
** Global State
** See Copyright Notice in lua.h
heap variable
create registry
close all upvalues for this thread
only the main thread can be closed
200%
initialize first ci
** thread state + extra space
** Create registry table and its predefined values
stack not completely built yet
registry[LUA_RIDX_MAINTHREAD] = L
closing a fully built state?
global variable
local variable
'function' entry for this 'ci'
free stack array
it should never be collected
GC runs 'twice the speed' of memory allocation
init stack
** preinitialize a state with consistent values without allocating
** any memory (to avoid errors)
** a macro to help the creation of a unique random seed when a state is
** created; the seed is used to randomize hashes.
** set GCdebt to a new value keeping the value (totalbytes + GCdebt)
** invariant
** Main thread combines a thread state and the global state
free the entire 'ci' list
free main block
initial size of string table
pre-create memory-error message
initialize stack array
metatables for basic types
thread
to be called in unprotected errors
current error recover point
current position of sweep in list 'finobj'
** Union of all collectable objects
randomized seed for hashes
call is running on same invocation of
luaV_execute of previous call
call has an error status (pcall)
call was tail called
number of elements
head of double-linked list of all open upvalues
function index in the stack
comment: call is a yieldable protected call
label: code-design
list of gray objects
an estimate of the non-garbage memory in use
number of bytes currently allocated - GCdebt
list of tables with weak values
list of open upvalues in this stack
list of collectable objects with finalizers
list of all-weak tables
last free slot in the stack
call is running a Lua function
stack base
true if GC is running
** Bits in CallInfo status
macro to convert any Lua object into a GCObject
current error handling function (stack index)
number of non-yieldable calls in stack
list of all collectable objects
extra stack space to handle TM calls and some other extras
state of garbage collector
call reentered after suspension
actual number of total bytes allocated
bytes allocated not yet compensated by the collector
kinds of Garbage Collection
defined in ldo.c
array with tag-method names
** information about a call
gc was forced by an allocation failure
last hook called yielded
only for Lua functions
** `global state', shared by all threads of this state
size of pause between successive GCs
** Some notes about garbage-collected objects: All objects in Lua must
** be kept somehow accessible until being freed.
**
** Lua keeps most objects linked in list g->allgc. The link uses field
** 'next' of the CommonHeader.
**
** Strings are kept in several lists headed by the array g->strt.hash.
**
** Open upvalues are not subject to independent garbage collection. They
** are collected together with their respective threads. Lua keeps a
** double-linked list with all open upvalues (g->uvhead) so that it can
** mark objects referred by them. (They are always gray, so they must
** be remarked in the atomic step. Usually their contents would be marked
** when traversing the respective threads, but the thread may already be
** dead, while the upvalue is still accessible through closures.)
**
** Objects with finalizers are kept in the list g->finobj.
**
** The list g->tobefnz links all objects being finalized.
base for this function
first free slot in the stack
generational collection
kind of GC running
memory-error message
current position of sweep in list 'allgc'
only for C functions
CallInfo for first level (C calling Lua)
** `per thread' state
list of userdata to be GC
list of objects to be traversed atomically
macros to convert a GCObject into a specific value
hash table for strings
** $Id: lstate.h,v 2.82.1.1 2013/04/12 18:48:47 roberto Exp $
** Global State
** See Copyright Notice in lua.h
last pc traced
top for this function
auxiliary data to `frealloc'
expected number of results from this function
call is running a debug hook
continuation in case of yields
dynamic call link
list of ephemeron tables (weak keys)
common header
GC `granularity'
call info for current function
pointer to version number
position of sweep in `strt'
context info. in case of yields
number of nested C calls
comment: temporary buffer for string concatenation
label: code-design
pause between major collections (only in gen. mode)
function to reallocate memory
memory traversed by the GC
** equality for long strings
same instance or...
cannot resize while GC is traversing strings
short string?
chain it
shrinking slice must be empty
total size of TString object
rehash
equal length and ...
** new zero-terminated string
** $Id: lstring.c,v 2.26.1.1 2013/04/12 18:48:47 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
** compute its hash
** checks whether short string exists and reuses it or creates a new one
(pointer to) list where it will be inserted
** creates a new short string, inserting it into string table
** new string (with explicit length)
ending 0
** resizes the string table
string is dead (but was not collected yet)?
not found; create a new string
resurrect it
** equality for strings
see MOVE OLD rule
too crowded
new position
** creates a new string object
save next
for each node in the list
equal contents
** $Id: lstring.h,v 1.49.1.1 2013/04/12 18:48:47 roberto Exp $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
** test whether a string is a reserved word
** equality for short strings, which are always internalized
`s2' cannot be found after that
0 or more repetitions
end ('\0') of source string
return match(ms, s, ep + 1);
accept empty?
get string library
set table as metatable for strings
** $Id: lstrlib.c,v 1.178.1.1 2013/04/12 18:48:47 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
may overflow?
** {======================================================
** PATTERN MATCHING
** =======================================================
not found
end of pattern?
add capture to accumulated result
remove result from 'luaL_tolstring'
1st char is already checked
using goto's to optimize tail recursion
start
position capture?
{
to store the format (`%...')
end capture
pop metatable
no suffix
return match(ms, s + 1, ep);
}======================================================
macro to `unsign' a character
no; go to default
** LUA_INTFRMLEN is the length modifier for integer conversions in
** 'string.format'; LUA_INTFRM_T is the integer type corresponding to
** the previous length
0 or more repetitions (minimum)
** LUA_FLTFRMLEN is the length modifier for float conversions in
** 'string.format'; LUA_FLTFRM_T is the float type corresponding to
** the previous length
skip it
format item
points to optional suffix
avoids a negative `l1'
add whole match
** add length modifier into formats
balanced string?
may have more after \0
maximum recursion depth for 'match'
recursive function
matches any char
deprecated option
points to what is next
maximum size of each formatted item (> len(format('%99.99f', -1e308)))
keep original text
pop dummy string
comment: no precision and string is too long to be formatted;
keep original string
label: code-design
to put formatted item
empty match? go at least one position
empty interval; return no values
return match(ms, s, p + 4);
string ends out of balance
1 or more repetitions
else fail (s == NULL)
check whether pattern has no special characters
to search for a `*s2' inside `s1'
init of source string
number of strings pushed
do a plain search
return match(ms, s, p + 2)
else return match(ms, s, ep + 1);
pattern class plus optional suffix
reasonable limit to avoid arithmetic overflow
matched once
empty strings are everywhere
skip escapes (e.g. `%]')
return match(ms, s, ep);
go through
non empty match?
optional
** maximum size of each format specification (such as '%-099.99d')
** (+10 accounts for %99.99x plus margin of error)
%%
skip precision
start after string's end?
pattern has a special character
end ('\0') of pattern
copy table
ms->level == 0, too
no special chars found
skip width
** maximum number of captures that a pattern can do during
** pattern-matching. This limit is arbitrary.
comment: avoid empty 'memcpy' (may be expensive)
label: code-design
does not match at least once?
translate a relative string position: negative means back from end
first n-1 copies (followed by separator)
last copy (not followed by separator)
1 match already done
end
skip ESC
fail
match failed
add result to accumulator
table to be metatable for strings
undo capture
total number of captures (finished or unfinished)
look for a `]'
handle optional suffix
else didn't match; reduce 1 repetition to try again
** {======================================================
** STRING FORMAT
** =======================================================
(2 digits at most)
valid flags in a format specification
start capture
** Open string library
(size_t -> int) overflow?
escaped sequences not in the format class[*+?-]?
skip the `^'
number of substitutions
keeps trying to match with the maximum repetitions
is the `$' the last char in pattern?
explicit request or no special characters?
1st char will be checked by `memchr'
check end of string
capture results (%0-%9)?
number of bytes in added item
try with one more repetition
counts maximum expand for item
}
frontier?
skip flags
match failed?
metatable.__index = string
cannot find anything
number of arguments
also treat cases `pnLlh'
skip anchor character
'+' or no suffix
LUA_TNUMBER or LUA_TSTRING
close capture
control for recursive depth (to avoid C stack overflow)
correct `l1' and `s1' to try again
nil or false?
dummy string
shrink array
cannot find a free place?
i is zero or a present index
** $Id: ltable.c,v 2.72.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
comment: key may be dead already, but it is ok to use it in `next'
label: code-design
no more elements to count
compute new size for array part
check whether `key' is somewhere in the chain
grow table
no hash?
count as such
count extra key
that's it
main position is taken?
copy colliding node into free pos. (mp->next also goes)
redo the chain with `n' in place of `mp'
is `key' inside array part?
yes; that's the index (corrected to C)
key index in hash table
is `key' an appropriate array index?
** hash for lua_Numbers
try first array part
value
then hash part
use specialized version
doesn't need barrier/invalidate cache, as entry was
already present in the table
2^i
now `mp' is free
adjust upper limit
optimal size (till now)
all elements smaller than n will go to array part
index is int?
new node will go into free position
first iteration
** max size of array part is 2^MAXBITS
count elements in range (2^(lg-1), 2^lg]
** main search function
array part must grow?
else must find a boundary in hash part
re-insert elements from hash part
array part must shrink?
use unsigned to avoid overflows
** beware: when using this function you probably need to check a GC
** barrier and invalidate the TM cache.
table was built with bad purposes: resort to linear search
key not found
comment:
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
label: code-design
is colliding node out of its main position?
now it has its hash
could not find a free place
find previous
** search function for short strings
total number of elements
for each slice
`key' did not match some condition
number of elements to go to array part
else go through
find original element
count to traverse all array keys
reset counts
save old hash ...
optimal size for array part
all elements already counted
resize the table to new computed sizes
** search function for integers
all those keys are integer keys
colliding node is in its own main position
2^lg
key
a non-nil value?
counter
count keys in array part
now do a binary search between them
chain new position
use common `dummynode'
summation of `nums'
** inserts a new key into a hash table; first, check whether key's main
** position is free. If not, check whether colliding node is in its main
** position or not: if it is not, move colliding node to an empty place and
** put new key in its main position; otherwise (colliding node is in its main
** position), new key goes to an empty position.
overflow?
** returns the index of a `key' for table traversals. First goes all
** elements in the array part, then elements in the hash part. The
** beginning of a traversal is signaled by -1.
no elements to hash part?
must be a positive value
all positions are free
re-insert elements from vanishing slice
hash elements are numbered after array ones
find `i' and `j' such that i is present and j is not
there is a boundary in the array part: (binary) search for it
more than half elements present?
** }=============================================================
that is easy...
hash part is empty?
comment:
** Implementation of tables (aka arrays, objects, or hash tables).
** Tables keep its elements in two parts: an array part and a hash part.
** Non-negative integer keys are all candidates to be kept in the array
** part. The actual size of the array is the largest `n' such that at
** least half the slots between 0 and n are in use.
** Hash uses a mix of chained scatter table with Brent's variation.
** A main invariant of these tables is that, if an element is not
** in its main position (i.e. the `original' position that its hash gives
** to it), then the colliding element is in its own main position.
** Hence even when the load factor reaches 100%, performance remains good.
label: code-design
insert key into grown table
** {=============================================================
** Rehash
** ==============================================================
nums[i] = number of keys with 2^(i-1) < k <= 2^i
whatever called 'newkey' take care of TM cache and GC barrier
(1 <= key && key <= t->sizearray)
create new hash part with appropriate size
handle INT_MIN
free old array
number of elements smaller than 2^i
yes; move colliding node into free position
count keys in hash part
** returns the index for `key' if `key' is an appropriate key to live in
** the array part of the table, -1 otherwise.
** Try to find a boundary in table `t'. A `boundary' is an integer index
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
no more elements
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
get a free place
** $Id: ltable.h,v 2.16.1.2 2013/08/30 15:49:41 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
returns the key, given the value of a table entry
insert new element at the end
remove a[j]
** {======================================================
** Pack/unpack
** =======================================================
-2 to compensate function and `a'
at least one element?
** {======================================================
** Quicksort
** (based on `Algorithms in MODULA-3', Robert Sedgewick;
** Addison-Wesley, 1993.)
** =======================================================
t[i] = t[i-1]
result = t[pos]
repeat --j until a[j] <= P
call recursively the smaller one
called with only 2 arguments
empty range
t.n = number of elements
move table into index 1
remove value
number of elements to pack
a < b?
Pivot
assume array is smaller than 2^40
t[pos] = nil
move up elements
assign other elements
repeat the routine for the larger one
-1 to compensate function
push arg[i + 1...e]
first key
adjust so that smaller half is in [j..i] and larger one in [l..u]
is there a 2nd argument?
2nd argument is the position
t[pos] = t[pos+1]
a[i]<a[l]?
add last value (if interval was not empty)
remove a[l]
pop pivot, a[i], a[j]
a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2
return table
only 3 elements
for tail recursion
a[l..i-1] <= a[i] == P <= a[i+1..u]
first empty element
** $Id: ltablib.c,v 1.65.1.2 2014/05/07 16:32:55 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
swap pivot (a[u-1]) with a[i]
invariant: a[l..i] <= P <= a[j..u]
sort elements a[l], a[(l+u)/2] and a[u]
insert first element
}======================================================
swap a[l] - a[u]
a[u] < a[l]?
a[u]<a[i]?
number of elements minus 1
only 2 elements
function?
create result table
where to insert new element
validate 'pos' if given
push arg[i] (avoiding overflow problems)
_G.unpack = table.unpack
repeat ++i until a[i] >= P
remove a[i]
make sure there is two arguments
t[pos] = v
these last two cases are used for tests only
never collect these names
comment:
** function to be used with macro "fasttm": optimized for absence of
** tag methods
label: code-design
cache this fact
no tag method?
** $Id: ltm.c,v 2.14.1.1 2013/04/12 18:48:47 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
ORDER TM
** $Id: ltm.h,v 2.11.1.1 2013/04/12 18:48:47 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
* WARNING: if you change the order of this enumeration,
* grep "ORDER TM"
number of elements in the enum
last tag method with `fast' access
open libraries
** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
** is, whether we're running lua interactively).
number of arguments to the script
remove line
to be available to 'laction'
remove it
execute arguments -e and -l
count total number of arguments
get line
no concatenated argument?
invalid option; return its index...
any result to print?
-v
add a new line...
mark in error messages for incomplete statements
non-empty line?
try alternative name
is there an error object?
-i option?
create state
line ends with newline?
-E
stop if file fails
-e
assume stdin is a tty
go through
call 'pmain' in protected mode
show prompt
not an option?
no next argument or it is another option
remove result from 'get_prompt'
stop collector during initialization
executes stdin as a file
** $Id: lua.c,v 1.206.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
function index
number of 'has_*'
indices of various argument indicators in array args
error running LUA_INIT
option
if another SIGINT happens before lstop,
terminate process (default action)
join them
no more input?
try its 'tostring' metamethod
** lua_readline defines how to show a prompt and then read a line from
** the standard input.
** lua_saveline defines how to "save" a read line in a "history".
** lua_freeline defines how to free a line read by lua_readline.
execute main script (if there is one)
add it to history
signal no errors
first line starts with `=' ?
option '-E'?
...between the two lines
comment: unused arg.
label: code-design
signal for libraries to ignore env. vars.
stdin
repeat until gets a complete line
both options need an argument
push traceback function
-i
call 'require(name)'
try next 'argv'
check that argument has no extra characters at the end
the next function is called unprotected, so it must avoid errors
cannot try to add lines?
no arguments?
force a complete garbage collection in case of errors
put it under chunk and args
else...
invalid arg?
change it to `return'
...as a negative value
clear stack
2nd argument
global[name] = require return
get result
1st argument
remove traceback function
collect arguments
no input
open standard libraries
*****************************************************************************
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************
(t)
minimum Lua stack available to a C function
** functions that read/write blocks when loading/dumping Lua chunks
** basic types
** push functions (C -> stack)
(u) number of parameters
Functions to be called by the debugger in specific events
mark for precompiled code ('<esc>Lua')
unsigned integer type
** prototype for memory-allocation functions
** access functions (stack -> C)
** garbage-collection function and options
(S)
** set functions (stack -> Lua)
(l)
** state manipulation
predefined values in the registry
active function
(n) 'global', 'local', 'field', 'method'
** Event codes
** $Id: lua.h,v 1.285.1.4 2015/02/21 14:04:50 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
private part
** {======================================================================
** Debug API
** =======================================================================
type of numbers in Lua
type for integer functions
(u)
** get functions (Lua -> stack)
** pseudo-indices
(u) number of upvalues
** 'load' and 'call' functions (load and run Lua code)
option for multiple returns in 'lua_pcall' and 'lua_call'
** coroutine functions
comment:
** generic extra include file
label: code-design
** Comparison and arithmetic functions
** Event masks
}======================================================================
** miscellaneous functions
** basic stack manipulation
(n)
activation record
(S) 'Lua', 'C', 'main', 'tail'
thread status
** RCS ident string
ORDER TM
** ===============================================================
** some useful macros
** ===============================================================
lua.hpp
Lua header files for C++
<<extern "C">> not supplied automatically because Lua also compiles as C++
show version
end of options; use stdin
list bytecodes?
cannot happen
default program name
end of options; skip it
default output file
unknown option
** $Id: luac.c,v 1.69 2011/11/29 17:46:33 lhf Exp $
** Lua compiler (saves bytecodes to files; also list bytecodes)
** See Copyright Notice in lua.h
actual program name
default output file name
strip debug information?
end of options; keep it
list
actual output file name
output file
parse only
strip debug information
dump bytecodes?
** $Id: print.c,v 1.69 2013/07/04 01:03:46 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
** ==================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
comment:
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
label: documentation
@@ LUA_IDSIZE gives the maximum size for the description of the source
@* of a function in debug information.
** CHANGE it if you want a different size.
reserve some space for error handling
pentium 64 bits?
@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
** The next definitions activate some tricks to speed up the
** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
**
@@ LUA_MSASMTRICK uses Microsoft assembler to avoid clashes with a
** DirectX idiosyncrasy.
**
@@ LUA_IEEE754TRICK uses a trick that should work on any machine
** using IEEE754 with a 32-bit integer type.
**
@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
** defined when LUA_INTEGER is a 32-bit integer.
**
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
** (0 for little endian, 1 for big endian); if not defined, Lua will
** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
**
@@ LUA_NANTRICK controls the use of a trick to pack all types into
** a single double value, using NaN values to represent non-number
** values. The trick only works on 32-bit machines (ints and pointers
** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
** with conventional endianess (12345678 or 87654321), in CPUs that do
** not produce signaling NaN values (all NaNs are quiet).
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
assume 'strtod' handles hex formats
@@ lua_str2number converts a decimal numeric string to a number.
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does both conversions. C89, however, has no function
** to convert floating hexadecimal strings to numbers. For these
** systems, you can leave 'lua_strx2number' undefined and Lua will
** provide its own implementation.
@@ LUA_ENV is the name of the variable that holds the current
@@ environment, used to access global names.
** CHANGE it if you do not like this name.
does not need -ldl
}{
@@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
** strings that are internalized. (Cannot be smaller than reserved words
** or tags for metamethods, as these strings must be internalized;
** #("function") = 8, #("__newindex") = 10.)
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
}==================================================================
** {==================================================================
@@ LUA_NUMBER is the type of numbers in Lua.
** CHANGE the following definitions only if you want to build Lua
** with a number type different from double. You may also need to
** change lua_number2int & lua_number2integer.
** ===================================================================
@@ LUA_NUMBER_SCAN is the format for reading numbers.
@@ LUA_NUMBER_FMT is the format for writing numbers.
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
16 digits, sign, point, and \0
}
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
@@ The luai_num* macros define the primitive operations over numbers.
pentium 32 bits?
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
@* C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
@@ luai_writestring/luai_writeline define how 'print' prints its results.
** They are only used in libraries and the stand-alone program. (The #if
** avoids including 'stdio.h' everywhere.)
avoid overflows in comparison
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
@@ LUAI_FUNC is a mark for all extern functions that are not to be
@* exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
@* that are not to be exported to outside modules (LUAI_DDEF for
@* definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
@@ LUA_USE_POSIX includes all functionality listed as X/Open System
@* Interfaces Extension (XSI).
** CHANGE it (define it) if your system is XSI compatible.
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
the following operations need the math library
these are quite standard operations
@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
** It must have at least 32 bits.
more often than not the libs go together with the core
Microsoft compiler on a Pentium (32 bit) ?
@@ LUA_ANSI controls the use of non-ansi features.
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
** Some tricks with doubles
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
** $Id: luaconf.h,v 1.176.1.2 2013/11/21 17:26:16 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
assume 'printf' handles 'aA' specifiers
{
assume support for long long
enable goodies for regular Windows platforms
===================================================================
16-bit ints
comment: needs some extra libraries
label: code-design
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
@@ LUA_INT32 is a signed integer with exactly 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@* used by Lua.
** CHANGE here if for some weird reason the default definitions are not
** good enough for your machine. Probably you do not need to change
** this.
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
comment: needs an extra library: -lreadline
label: code-design
empty
assume IEEE754 and a 32-bit integer type
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
comment:
@@ luai_writestringerror defines how to print error messages.
** (A format string with one argument is enough for Lua...)
label: code-design
** {==================================================================
** Compatibility with previous versions
** ===================================================================
@@ LUAI_BITSINT defines the number of bits in an int.
** CHANGE here if Lua cannot automatically detect the number of bits of
** your machine. Probably you do not need to change this.
int has at least 32 bits
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
comment: needs an extra library: -ldl
label: code-design
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space.
@@ LUA_COMPAT_ALL controls all compatibility options.
** You can define it to get all options, or change specific options
** to fit your specific needs.
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
open all previous libraries
** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
is lua_Number integral?
* make header for precompiled chunks
* if you change the code below be sure to update LoadHeader and FORMAT above
* and LUAC_HEADERSIZE in lundump.h
** load precompiled chunk
empty
comment: the code below must be consistent with the code in luaU_header
label: code-design
first char already read
** $Id: lundump.c,v 2.22.1.1 2013/04/12 18:48:47 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
this is the official format
remove trailing '\0'
endianness
make header; from lundump.c
dump one chunk; from ldump.c
data to catch conversion errors
load one chunk; from lundump.c
size in bytes of header of binary files
** $Id: lundump.h,v 1.39.1.1 2013/04/12 18:48:47 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
first try `le'
true must be 1 !!
remove new frame
try first operand
update internal index...
restart luaV_execute over new Lua function
no previous entry; must create one. (The next test is
always true; we only need the assignment.)
'ci' still the called one
call TM
** create a new Lua closure, push it in the stack, and initialize
** its upvalues. Note that the call to 'luaC_barrierproto' must come
** before the assignment to 'p->cache', as the function needs the
** original value of that field.
undo decrement to zero
** finish execution of an opcode interrupted by an yield
metamethod may yield only when called from Lua code
will try TM
repeat until only 1 result left
last stack slot filled by 'precall'
there is a metamethod
same metatables => same metamethods
anchor new closure in stack
enter a new line
both strings longer than `len'; go on comparing (after the `\0')
else primitive len
same metamethods?
increment index
when jump back (loop), or when
collect total length
metamethod? break switch to call it
WARNING: several calls may realloc the stack and invalidate `ra'
or no TM?
first element to concatenate
reset count
no metamethod; is there a previous entry in the table?
undo increment (resume will increment it again)
comment:
** check whether cached closure in prototype 'p' may be reused, that is,
** whether there is a cached closure with the same upvalues needed by
** new closure to be created.
label: code-design
restore top
invocation via reentry: continue execution
else will try the metamethod
l is finished?
cached closure
B == 0?
no metamethod
is there a cached closure?
second operand is empty?
fill in its upvalues
correct top (in case of previous open call)
push function
close all upvalues from previous call
reentry point when frame changes (call/return)
** $Id: lvm.c,v 2.155.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
top is one after last element (at top-2)
l is smaller than r (because r is not finished)
called frame
try second operand
result is not nil?
result is first operand
adjust results
comment: needs more space?
label: code-design
continue loop?
do not call hook again (VM yielded, so it did not move)
else repeat with 'tm'
are there elements to concat?
Lua function
metamethod should not be called when operand is K
limit for table tag-method chains (to avoid loops)
popped 'n' strings and pushed one
no match?
upvalue refers to local variable?
invert result
top when 'call_binTM' was called
correct top
mark the end of concat operands
`t' is a table?
if has result, move it to its place
push cashed closure
comment: wrong upvalue; cannot reuse closure
label: code-design
3rd argument
call linehook when enter a new function,
no metamethod and (now) there is an entry with given key
move new frame into old one
nresults >= 0?
did hook yield?
function was tail called
to be used after possible stack reallocation
func. + 2 args (state and index)
create a new one
protect stack below results
strings are equal up to a `\0'
jump back
caller frame
r is finished?
concat all strings
for test instructions, execute the jump instruction that follows it
...and external index
try metamethod
'luav_concat' may invoke TMs and move the stack
pre-allocate it at once
** some macros for common tasks in `luaV_execute'
put TM result in proper position
call base
called hook last time?
no TM?
assign new value to that entry
go to next instruction
finish its execution
erase mark
result is second op.
get all var. arguments
at least two non-empty string values; get as many as possible
tail call: put called frame (n) in place of caller one (o)
concat them (may yield again)
mark that it yielded
skip next instruction (if C)
previous value is nil; must check the metamethod
called function
not a table; check metamethod
execute a jump instruction
yet to concatenate
call count hook
call line hook
"<=" using "<" instead?
save control variable
no metamethod?
else try `lt'
got 'n' strings to create 1 new
nb = no break
main loop of interpreter
if previous value is not nil, there must be a previous entry
in the table; moreover, a metamethod has no relevance
caller function
check whether it has right upvalues
interrupted instruction
C function?
correct base
get upvalue from enclosing function
do a primitive get
index of first `\0' in both strings
return cached closure (or NULL if no cached closure)
save it on cache for reuse
skip jump instruction
limit of live values
** equality of Lua values. L == NULL means raw equality (no metamethods)
else previous instruction set top
else will try the tag method
2nd argument
condition failed?
void
no result? 'p3' is third argument
external invocation: return
1st argument
number of elements handled in this pass (at least 2)
previous call may change the stack
next assignment may change this value
move final result to final position
not to called directly
** $Id: lvm.h,v 2.18.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
** $Id: lzio.c,v 1.35.1.1 2013/04/12 18:48:47 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
try to read more
no bytes in buffer?
discount char being returned
luaZ_fill consumed first byte; put it back
no more input; return number of missing bytes
min. between n and z->n
------------------------------------------------------------------------
--------------------------------------------------------------- read ---
end of stream
current position in buffer
Lua state (for reader)
--------- Private Part ------------------
reader function
additional data
bytes still unread
read next n bytes
** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
Last change: revised for Lua 5.3.3
function to be called
calls Lua
number of results
</code>: </b>floor division</li>
%
table to be indexed
second result
uses 'key' (at index -2) and 'value' (at index -1)
call 'f' with 3 arguments and 1 result
======================================================================
set global 'a'
first key
Last change: revised for Lua 5.3.3
first result
number of arguments
</b>’ | ‘<b>^</b>’ | ‘<b>%</b>’ |
code 1
</code>) is a division
table is in the stack at index 't'
$Id: manual.of,v 1.162 2016/05/30 15:57:03 roberto Exp $
</code>)</li>
push result of t.x (2nd arg)
comment: not used
label: code-design
1st argument
remove 't' from the stack
code 2
removes 'value'; keeps 'key' for next iteration
3rd argument
Last change: revised for Lua 5.3.3
no errors?
it has no upvalues
call to 'tointeger' may change 'n' even if it fails
function to be called
not a closure
save continuation
function can do error recovery
call to 'tonumber' may change 'n' even if it fails
save context
adjust frame top
signal it
stack large enough?
pop value
save information for error recovery
'luaO_tostring' may create a new string
do a 'conventional' protected call
** get functions (Lua -> stack)
no continuation or no yieldable?
data to 'f_call'
remove second operand
** Reverse the stack segment from 'from' to 'to'
** (auxiliary to 'lua_rotate')
test for pseudo index
set global table as 1st upvalue of 'f' (may be LUA_ENV)
=1 to signal that it did an actual step
end of prefix
yes; check is OK
push empty string
end of cycle?
GC values are expressed in Kbytes: #bytes/2^10
stack already checked by previous 'api_check'
may call tag method
'subtract' index (index is negative)
does it have an upvalue?
C closure
** access functions (stack -> C)
internal copy's address
** set functions (stack -> Lua)
upvalues
add 'data' to total debt
Lua closure
not a C function
get global table from registry
reverse the prefix with length 'n'
no
light C function?
allow GC to run
else n == 1; nothing to do
** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
remove key
lock done by caller
pop value and key
save value of 'allowhook'
comment: to avoid warnings
label: code-design
just do the call
end of stack segment being rotated
push 'str' (to make it a TValue)
does not need barrier because closure is white
** push functions (C -> stack)
ensure that true is 1
need to prepare continuation?
previous call may reallocate the stack
avoid ridiculous low values (and 0)
corresponding test
reverse the suffix
** Pushes on the stack a string with given length. Avoid using 's' when
** 'len' == 0 (as 's' can be NULL in that case), due to later use of
** 'memcmp' and 'memcpy'.
pop index and value
not convertible?
unlock done in 'auxsetstr'
for unary operations, add fake 2nd operand
all other operations expect two operands
can grow without overflow?
** 'load' and 'call' functions (run Lua code)
** miscellaneous functions
** to be called by 'lua_checkstack' in protected mode, to grow stack
** capturing memory errors
value at a non-valid index
test for valid but not pseudo index
code unreachable; will unlock when control actually leaves the kernel
start of segment
** convert an acceptable stack index into an absolute index
if it is here, there were no errors
get newly created function
invalid option
to do a "small" step
prepare continuation (call is already protected by 'resume')
negative index
do the call
no continuation or no yieldable
get its upvalue pointer
no; need to grow stack
** Garbage-collection function
first operand at top - 2, second at top - 1; result go to top - 2
** Execute a protected call.
reverse the entire segment
restore previous state
test for upvalue
try to grow stack
lua closure
** t[k] = value at the top of the stack (where 'k' is a string)
no more elements
** basic stack manipulation
** Let x = AB, where A is a prefix of length 'n'. Then,
** rotate x n == BA. But BA == (A^r . B^r)^r.
LUA_REGISTRYINDEX does not need gc barrier
(collector revisits it before finishing collection)
function upvalue?
** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
** Again, the use of 'lua_pushvfstring' ensures this function does
** not need reserved stack space when called. (At worst, it generates
** an error with "stack overflow" instead of the given message.)
** use appropriate macros to interpret 'pclose' return status
name already in use?
double buffer size
remove previous table
remove table (but keep name)
no more pre-read characters
copy to be left at top
remove pushed values
false, because did not find table there
remove both metatables
get/create library table
** Stripped-down 'require': After checking "loaded" table, calls 'openf'
** to open a module, registers the result in 'package.loaded' table and,
** if 'glb' is true, also registers the result in the global table.
** Leaves resulting module on the top.
userdata to box arbitrary data
special name for messages
not big enough?
not found
creating metatable?
push prefix
get a new reference
table already there
read initial portion
return true/nil,what,code
remove table and value
type of termination
add line to correct line numbers
no metafield?
remove it from list
remove this nil
no stack frame?
remove field
argument to open function
allocation error?
{
no _LOADED[modname]?
_LOADED[modname]
name for the type of the actual argument
remove only metatable
(t[freelist] = t[ref])
binary file?
comment:
** The use of 'lua_pushfstring' ensures this function does not
** need reserved stack space when called.
label: code-design
}======================================================
** reads the first character of file 'f' and skips an optional BOM mark
** in its beginning plus its first line if it starts with '#'. Returns
** true if it skipped the first line. In any case, '*cp' has the
** first "valid" character of the file (after the optional BOM and
** a first-line comment).
push last suffix
re-read initial portion
** {======================================================
** Userdata's metatable manipulation
** =======================================================
start 'next' loop
no metatable?
** {======================================================
** Reference system
** =======================================================
copy upvalues to the top
comment: not used
label: code-design
call 'openf' to open module
move name to proper place
'fread' can return > 0 *and* set the EOF flag. If next call to
'getF' called 'fread', it might still wait for user input.
The next check avoids this problem.
remove it from stack
find an upper bound
read a block from file
comment:
** check whether buffer is using a userdata on the stack as a temporary
** buffer
label: code-design
move library table to below upvalues
get first free element
remove from stack
to be read by the parser
return problematic part of the name
** returns a pointer to a free area with at least 'sz' bytes
reopen in binary mode
remove value (but keep name)
put value below buffer
push function
** set functions from list 'l' into table at top - 'nup'; each
** function gets the 'nup' elements at the top as upvalues.
** Returns with only the table at the stack.
name start with '_G.'?
successful termination?
get info about it
leave previous value on top, but return 0
no free elements
create metatable
for each pair in table
no comment
index of filename on the stack
use it
skip end-of-line, if present
ref = t[freelist]
size of the second part of the stack
value is a userdata?
delete old buffer
there was a comment
index of free-list header
continue after 'p'
file being read
field has a non-table value?
number of pre-read characters
** search for 'objidx' in table at index -1.
** return 1 + string at top if find a good name.
use the given type name
are there pre-read characters to be read?
t[ref] = t[freelist]
main?
is there a name from code?
return next character
'c' is the first character of the stream
set new table into field
_LOADED[modname] = module
return to Lua to abort
remove _LOADED table
assign new table to field
check function at level
calls to Lua API may change this value
return metafield type
create larger buffer
prefix matched; discard it
try recursively
add a '...'
new table for field
t[freelist] = ref
for Lua functions, use <file:line>
push replacement in place of pattern
do not count 'self'
UTF-8 BOM mark
free buffer
avoid 'memcpy' when 's' can be NULL
_G[modname] = module
** {======================================================
** Argument check functions
** =======================================================
metatable.__gc = boxgc
check numeric types
** This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
any free element?
** {======================================================
** Traceback
** =======================================================
does it have a metatable?
'nil' has a unique fixed reference
** Search for a name for a function in all loaded modules
** (registry._LOADED).
ignore results from 'lua_load'
remove function and global table
no buffer yet
try global variable (and create one if it does not exist)
place '.' between the two names
do a binary search
** {======================================================
** Generic Buffer manipulation
** =======================================================
remove object
first line is a comment (Unix exec. file)?
standard name
registry.name = metatable
** {======================================================
** Load functions
** =======================================================
read block
comment: too many levels?
label: code-design
remove original name
interpret result
value is a userdata with wrong metatable
skip first line
remove upvalues
_LOADED[modname] = new table
found object?
value is not a userdata with a metatable
remove metatable and metafield
not enough space?
ignore non-string keys
and skip to last ones
remove previous result
** Count number of elements in a luaL_Reg list.
close file (even in case of errors)
get correct metatable
push name without prefix
** ensure that stack[idx][fname] has a table and push that table
** into the stack
return them (chars already in buffer)
** {======================================================
** Error-report functions
** =======================================================
}
** {======================================================
** Compatibility with 5.1 module functions
** =======================================================
remove value
is metafield nil?
else, no information available...
make copy of module (call result)
size of the first part of the stack
comment:
** Ensures the stack has at least 'space' extra slots, raising an error
** if it cannot fulfill the request. (The error handling needs a few
** extra slots to format the error message. In case of an error without
** this extra space, Lua will generate the same 'stack overflow' error,
** but without 'msg'.)
label: code-design
area for reading file
get _LOADED table
copy of module
error is in the self argument itself?
try first a global name
not the same?
copy original content
nothing left...
closure with those upvalues
metatable.__name = tname
error?
package not already loaded?
** $Id: lauxlib.c,v 1.286 2016/01/08 15:33:09 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
comment: remove its header from the stack
label: code-design
no such field?
** Find or create a module table with a given name. The function
** first looks at the _LOADED table and, if that fails, try a
** global variable with that name. In any case, leaves on the stack
** the module table.
is there info?
remove name
fill the table with given functions
no op
extra error code for 'luaL_load'
print a newline and flush the output
print a string
stream (NULL for incompletely created streams)
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
print an error message
}==================================================================
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
predefined references
to close stream (NULL for closed streams)
buffer address
initial buffer
}============================================================
** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
** {======================================================
** Generic Buffer manipulation
** =======================================================
}======================================================
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
number of characters in buffer
buffer size
** {======================================================
** File handles for IO library
** =======================================================
compatibility with old module system
** ===============================================================
** some useful macros
** ===============================================================
function to be called
set global _VERSION
there must be a condition
** Continuation function for 'pcall' and 'xpcall'. Both functions
** already pushed a 'true' before doing the call, so in case of success
** 'finishpcall' only has to return everything in the stack minus
** 'extra' values (where 'extra' is exactly the number of items to be
** ignored).
and initial value
invalid numeral
argument must be a table
remove it
function
loading from a reader function
no numbers as strings
skip trailing spaces
return nil plus error message
return false, msg
first result
}======================================================
return all arguments
leave only message (default if no other one)
set global _G
comment: not used
label: code-design
state
pop result
get 3 values from metamethod
** Reader for generic 'load' function: 'lua_load' uses the
** stack for internal stuff, so the reader cannot change the
** stack top. Instead, it keeps its resulting string in a
** reserved slot inside the stack.
successful conversion to number
** 'ipairs' function. Returns 'ipairsaux', given "table", 0.
** (The given "table" may not be a table.)
no metatable
'env' index or 0 if no 'env'
not a number
condition is true?
return all results
open lib into global table
iteration function
argument 'self' to metamethod
comment: to avoid warnings
label: code-design
** Traversal function for 'ipairs'
value to print
call 'error'
default message
else not a number
no digit?
create reserved slot
** Do a protected call with error handling. After 'lua_rotate', the
** stack will have <f, err, true, f, [args...]>; so, the function passes
** 2 to 'finishpcall' to skip the 2 first values when returning results.
handle signal
put it in place
move them below function's arguments
initial value
add extra information
loading a string?
** $Id: lbaselib.c,v 1.313 2016/04/11 19:18:40 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
placeholders
check error function
state,
returns either __metatable field (if present) or metatable
only to match 'lua_Kfunction' prototype
create a 2nd argument if there isn't one
put before error message
call it
standard conversion?
error
'env' parameter?
yes; return it
no metamethod?
set it as 1st upvalue
skip initial spaces
** reserved slot, above all arguments, to hold a copy of the returned
** string to avoid it being collected while parsed. 'load' has four
** optional arguments (chunk, source name, mode, and environment).
error (message is on top of the stack)
number of arguments
comment: remove 'env' if not used by previous call
label: code-design
error message
error?
already a number?
environment for loaded function
save string in reserved slot
get result
** {======================================================
** Generic Read function
** =======================================================
get function
first result (false)
first result if no errors
will return generator,
number of bits to consider in a number
** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must
** be made in two parts to avoid problems when LUA_NBITS is equal to the
** number of bits in a lua_Unsigned.)
** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
builds a number with 'n' ones (1 <= n <= LUA_NBITS)
shift right?
arithmetic shift for 'negative' number
comment:
** get field and width arguments for field-manipulation functions,
** checking whether they are valid.
** ('luaL_error' called without 'return' to avoid later warnings about
** 'width' being used uninitialized.)
label: code-design
{
add signal bit
macro to trim extra bits
avoid undefined shift of LUA_NBITS when i == 0
shift left
}{
i = d % NBITS
}
position after whole expression
nothing to concatenate?
** Traverse a list of tests, patching their destination address and
** registers: tests producing values jump to 'vtarget' (and put their
** values in 'reg'), other tests jump to 'dtarget'.
** Add constant 'v' to prototype's list of constants (field 'k').
** Use scanner's table to cache position of constants in constant list
** and try to reuse constants. Because some values should not be used
** as keys (nil cannot be a key, integer keys can collapse with float
** keys), the caller must provide a useful 'key' for indexing the cache.
** Generate code to store result of expression 'ex' into variable 'var'.
jump when false
** Fix jump instruction at position 'pc' to jump to 'dest'.
** (Jump addresses are relative in Lua)
everything else is valid
correct value? (warning: must distinguish floats from integers!)
** Ensures final expression result is either in a register or it is
** a constant.
l = max(l, pl)
put this jump in 't' list
all those operations are relocatable
** Emit code for binary expressions that "produce values"
** (everything but logical operators 'and'/'or' and comparison
** operators).
** Expression to produce final result will be encoded in 'e1'.
not found
't' is in an upvalue
instruction will put result in 'reg'
remove previous OP_NOT
false list jumps to here (to go through)
** Path all jumps in 'list' to jump to 'target'.
** (The assert means that we cannot fix a jump to a forward address
** because we only know addresses once code is generated.)
put new instruction in code array
non-numeric operands or not safe to fold
'l1' points to 'l2'
no more jumps to here
** Process 1st operand 'v' of binary operation 'op' before reading
** 2nd operand.
insert new jump in 't' list
from = min(from, pfrom)
R/K index for key
** returns current 'pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block).
** Emit a "load constant" instruction, using either 'OP_LOADK'
** (if constant index 'k' fits in 18 bits) or an 'OP_LOADKX'
** instruction with "extra argument".
** Fix an expression to return the number of results 'nresults'.
** Either 'e' is a multi-ret expression (function call or vararg)
** or 'nresults' is LUA_MULTRET (as any expression can satisfy that).
** Ensures final expression result is in a valid R/K index
** (that is, it is either in a register or in 'k' with an index
** in the range of R/K indices).
** Returns R/K index.
point to itself represents end of list
use boolean itself as key
result is already in a register
already returns 1 value
** Create a jump instruction and return its position, so its destination
** can be fixed later (with 'fixjump'). If there are jumps to
** this position (kept in 'jpc'), link them all together so that
** 'patchlistaux' will fix all them directly to the final destination.
** Add an integer to list of constants and return its index.
** Integers use userdata as keys to avoid collision with floats with
** same value; conversion to 'void*' is used only for hashing, so there
** are no "precision" problems.
position of an eventual LOAD false
no original list?
no jumps?
can relocate its simple result
mark "here" as a jump target
** Ensures final expression result (including results from its jump
** lists) is in register 'reg'.
** If expression has jumps, need to patch these jumps either to
** its final position or to "load" instructions (for those tests
** that do not produce values).
** Emit a SETLIST instruction.
** 'base' is register that keeps table;
** 'nelems' is #table plus those to be stored now;
** 'tostore' is number of values (in registers 'base + 1',...) to add to
** table (or LUA_MULTRET to add up to stack top).
** Traverse a list of tests ensuring no one produces a value
** Add elements in 'list' to list of pending jumps to "here"
** (current position)
** Emit code to go through if 'e' is true, jump otherwise.
jump to default target
base register for op_self
already jump if true
** Free register used by expression 'e' (if any)
turn offset into absolute position
** Return false if folding can raise an error.
** Bitwise operations need operands convertible to integers; division
** operations cannot have 0 as divisor.
else keep numeral, which may be folded with 2nd operand
always false; do nothing
does operation
'(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)'
get previous range
index scanner table
** Gets the destination address of a jump instruction. Used to traverse
** a list of jumps.
use string itself as key
jump when it is false
'target' is current position?
constant not found; create a new entry
those instructions may be jump targets
Maximum number of registers in a Lua function (must fit in 8 bits)
there is one value available (somewhere)
insert new jump in false list
** Add a string to list of constants and return its index.
** check whether list has any jump that do not produce a value
** or produce an inverted value
** Add a boolean to list of constants and return its index.
reg. is not a local?
pc of new jump
true list jumps to here (to go through)
invert operands
fake 2nd operand
get a register
not a constant in the right range: put it in a register
save list of jumps to here
add list to pending jumps
register where 'e' was placed
function and 'self' produced by op_self
can connect both?
move constants to 'k'
FALLTHROUGH
** Add nil to list of constants and return its index.
self expression has a fixed register
free registers with list values
** Code a 'return' instruction
** Code a "conditional jump", that is, a test or comparison opcode
** followed by a jump. Return jump position.
** Ensure all pending jumps to current position are fixed (jumping
** to current position with no values) and reset list of pending
** jumps
operand must be on the 'stack'
** Finalize code for binary operation, after reading 2nd operand.
** For '(a .. b .. c)' (which is '(a .. (b .. c))', because
** concatenation is right associative), merge second CONCAT into first
** one.
** Ensures expression value is in any register.
** Returns the position of the instruction "controlling" a given
** jump (that is, its condition), or the jump itself if it is
** unconditional.
argument is +1 to reserve 0 as non-op
** Negate condition 'e' (where 'e' is a comparison).
else go through
** Format and emit an 'iABC' instruction. (Assertions check consistency
** of parameters versus opcode.)
is there an index there?
conversion errors
** Ensures expression value is in register 'reg' (and therefore
** 'e' will become a non-relocatable expression).
** Ensures final expression result (including results from its jump
** lists) is in some (any) register and return that register.
** Ensures final expression result (including results from its jump
** lists) is in next available register.
'pc' will change
use number itself as key
'==', '<', '<=' use their own opcodes
expression already has a register?
** Create a OP_LOADNIL instruction, but try to optimize: if the previous
** instruction is also OP_LOADNIL and ranges are compatible, adjust
** range of previous instruction instead of emitting a new one. (For
** instance, 'local a; local b' will generate a single opcode.)
list closed by 'luK_infix'
go ahead only if 'v' is true
move value to some (pending) register
position of an eventual LOAD true
otherwise, use next available register
put value there
put final result in it
** Fix an expression to return one result.
** If expression is not a multi-ret expression (function call or
** vararg), it already returns one result, so nothing needs to be done.
** Function calls become VNONRELOC expressions (as its result comes
** fixed in the base register of the call), while vararg expressions
** become VRELOCABLE (as OP_VARARG puts its results where it wants).
** (Calls are created returning one result, so that does not need
** to be fixed.)
is 't' in a register?
last register to set nil
save jump position
** Emit code for unary expressions that "produce values"
** (everything but 'not').
** Expression to produce final result will be encoded in 'e'.
no jumps to current position?
save corresponding line information
'(a ~= b)' ==> 'not (a == b)'
reuse index
jump if true
** Aplly prefix operation 'op' to expression 'e'.
expression is an open function call?
** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
else no optimization
** Try to "constant-fold" an operation; return 1 iff successful.
** (In this case, 'e1' has the final result.)
expression itself is a test?
keep them on hold
** Free registers used by expressions 'e1' and 'e2' (if any) in proper
** order.
** Create expression 't[k]'. 't' must have its final result already in a
** register or upvalue.
** Ensures final expression result is either in a register or in an
** upvalue.
register or upvalue index
** Emit code for comparisons.
** 'e1' was already put in R/K form by 'luaK_infix'.
** Reserve 'n' registers in register stack
go ahead only if 'v' is false
no fixed register yet?
not a numeral
true == not nil == not false
** Format and emit an 'iABx' instruction.
** Emit instruction to jump if 'e' is 'cond' (that is, if 'cond'
** is true, code will jump if 'e' is true.) Return jump position.
** Optimize when 'e' is 'not' something, inverting the condition
** and removing the 'not'.
** Code 'not e', doing constant folding.
constant fits in 'argC'?
find last element
compute 'ex' into proper place
invalid var kind to store
opcodes operate only on registers
** Patch destination register for a TESTSET instruction.
** If instruction in position 'node' is not a TESTSET, return 0 ("fails").
** Otherwise, if 'reg' is not 'NO_REG', set it as the destination
** register. Otherwise, change instruction to a simple 'TEST' (produces
** no register value)
** Change line information associated with current position.
end of list
** Emit code to go through if 'e' is false, jump otherwise.
last element links to 'l2'
** Path all jumps in 'list' to close upvalues up to given 'level'
** (The assertion checks that jumps either were closing nothing
** or were closing higher levels, from inner blocks.)
** Emit instruction 'i', checking for array sizes and saving also its
** line information. Return 'i' position.
cannot happen
values are useless when negated
generate opcode
already in a register
condition?
interchange true and false lists
** Free register 'reg', if it is neither a constant index nor
** a local variable.
)
** Add a float to list of constants and return its index.
becomes a non-relocatable value
nothing to do...
** Check register-stack level, keeping track of its maximum size
** in field 'maxstacksize'
previous is LOADNIL?
cannot patch other instructions
** Ensure that expression 'e' is not a variable.
false == not "x" == not 0.5 == not 1 == not true
cannot use nil as key; instead use table itself to represent nil
numerical value does not need GC barrier;
table has no metatable, so it does not need to invalidate cache
comment:
** Emit an "extra argument" instruction (format 'iAx')
label: code-design
no register to put value or register already has the value;
change instruction to simple test
folds neither NaN nor 0.0 (to avoid problems with -0.0)
always true; do nothing
both operands are "RK"
division by 0
result has fixed position
** If expression is a numeric constant, fills 'v' with its value
** and returns 1. Otherwise, returns 0.
** Concatenate jump-list 'l2' into jump-list 'l1'
** Emit SELF instruction (convert expression 'e' into 'e:key(e,').
** Marks the end of a patch list. It is an invalid value both as an absolute
** address, and as a list link (would link an element to itself).
** grep "ORDER OPR" if you change these enums (ORDER OP)
** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
get (pointer to) instruction of given 'expdesc'
does it have frames?
error flag
move function from L to NL
initial state
it is running
propagate error
some error occurred
** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $
** Coroutine Library
** See Copyright Notice in lua.h
return true + 'resume' returns
move error message
remove results anyway
error object is a string?
move function to top
return false + error message
add extra info
move yielded values
EOZ
7.
1.
6.
}
3.
** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
d.
0.
a.
b.
9.
e.
{
5.
2.
c.
f.
4.
8.
comment: ASCII case: can use its own tables; faster and fixed
label: code-design
** use standard C ctypes
must use standard C ctype
** this 'ltolower' only works for alphabetic characters
{
two more entries for 0 and -1 (EOZ)
** WARNING: the functions defined here do not necessarily correspond
** to the similar functions in the standard C ctype.h. They are
** optimized for the specific needs of Lua
}{
}
** add 1 to char to allow index -1 (EOZ)
** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
** Variations of 'lua_settable', used by 'db_getinfo' to put results
** from 'lua_getinfo' into result table. Key is always a string;
** value can be a string, an int, or a boolean.
setmetatable(hooktable) = hooktable
non-string 'msg'?
call hook function
stack level
push name
hooktable[L1] = new Lua hook
external hook?
no hook?
2nd result = mask
create a hook table
out of range?
return 1st argument
value (hook function)
** If L1 != L, L1 can be in any state, and therefore there are no
** guarantees about its stack space; any push in L1 must be
** checked.
return it untouched
comment:
** Auxiliary function used by several library functions: check for
** an optional thread as function's first argument and set 'arg' with
** 1 if this argument is present (so that functions can skip it to
** access their other arguments)
label: code-design
push local name
push event name
push function
1st result = hooktable[L1]
level out of range
key (thread)
move local value
info about a function?
exchange object and table
turn off hooks
no metatable
put object into table
** get (if 'get' is true) or set an upvalue from a closure
upvalue index
is there a hook function?
comment:
** Convert a string mask (for 'sethook') into a bit mask
label: code-design
remove eventual returns
closure
function argument?
return table
re-order
remove hook table
function will operate over current thread
** In function 'db_getinfo', the call to 'lua_getinfo' may push
** results on the stack; later it creates the result table to put
** these objects. Function 'treatstackoption' puts the result from
** 'lua_getinfo' on top of the result table so that it can call
** 'lua_setfield'.
no name (nor value)
move function to 'L1' stack
hook table must exist
set it in position
3rd result = count
add '>' to 'options'
** Convert a bit mask (for 'gethook') into a string mask
stack-level argument
no-op if get is false
** Call hook function registered at hook table for the current
** thread (if there is one)
push current line
local-variable index
pop value (if not popped by 'lua_setlocal')
** The hook table at registry[&HOOKKEY] maps threads to their current
** hook function. (We only need the unique address of 'HOOKKEY'.)
** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
** Check whether a given upvalue from a given closure exists and
** returns its index
return only name (there is no value)
table to collect results
** Calls 'lua_getinfo' and collects all results in a new table.
** L1 needs stack space for an optional input (function) plus
** two optional outputs (function and line table) from function
** 'lua_getinfo'.
* hooktable.__mode = "k"
move object to the "main" stack
cannot know who sets that register
other instructions cannot call a function
active function; get information through 'ar'
calling instruction index
table index
move from 'b' to 'a'
pop value
not found
no source available; use "?" instead
** This function can be called asynchronously (e.g. during a signal).
** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
** 'resethookcount') are for debug only, and it is no problem if they
** get arbitrary values (causes at most one wrong hook call). 'hookmask'
** is an atomic value. We assume that pointers are atomic too (e.g., gcc
** ensures that for all platforms where it runs). Moreover, 'hook' is
** always checked before being called (see 'luaD_hook').
undo decrement to zero
update 'jmptarget'
ORDER OP
for iterator
'name' already filled
is a local?
** Checks whether value 'o' came from an upvalue. (That can only happen
** with instructions OP_GETTABUP/OP_SETTABUP, which operate directly on
** upvalues.)
enter a new line
no line hook and count != 0; nothing to be done
get name for 'b'
when jump back (loop), or when
correct before option 'L', which can raise a mem. error
}======================================================
** Error when both values are convertible to numbers, but not to integers
no reasonable name found
generic name for any valid slot
** find a "name" for the RK value 'c'
affect all registers above base
if Lua function, add source:line information
reset count
check whether 'o' is an upvalue
undo increment (resume will increment it again)
was it called inside a hook?
no 'standard' name?
** {======================================================
** Symbolic Execution
** =======================================================
current position sets that register
information about non-active function?
push function
'c' is a register
name of indexed variable
turn off hooks?
do not call hook again (VM yielded, so it did not move)
key index
** If function yielded, its 'func' can be in the 'extra' field. The
** next function restores 'func' to its correct value for debugging
** purposes. (It exchanges 'func' and 'extra'; so, when called again,
** after debugging, it also "re-restores" ** 'func' to its altered value.
comment: to avoid warnings
label: code-design
affect all regs above its base
no such level
calling instruction
ORDER TM
generic name for any vararg
not a Lua function?
call linehook when enter a new function,
Active Lua function (given call info)
level found?
no name
did hook yield?
protect stack below results
for all lines with code
skip the '>'
calling function
literal constant?
all other instructions can call only through metamethods
any code before this address is conditional
search for 'c'
get function name
pop function
boolean 'true' to be the value of all indices
else no reasonable name found
move argument
set registers from 'a' to 'a+b'
no? try a register
** $Id: ldebug.c,v 2.120 2016/03/31 19:01:21 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
access to vararg values?
assume EXTRA_STACK
go through to return NULL
called hook last time?
new table to store active lines
first operand is wrong?
handled by lua_getinfo
now second is wrong
** try to find last instruction before 'lastpc' that modified register 'reg'
invalid (negative) level
call it
erase mark
could find instruction?
mark that it yielded
no such vararg
consider live variables at function start (parameters)
jump is forward and do not skip 'lastpc'?
is there an error handling function?
invalid option
found a constant name?
exchange its 'func' and 'extra' values
calling function is a known Lua function?
call count hook
call line hook
any instruction that set A
could not find reasonable name
table[line] = true
is 'n' inside 'ci' stack?
add src:line information to 'msg'
** The subtraction of two potentially unrelated pointers is
** not ISO C, but it should not crash a program; the subsequent
** checks are ISO C and ensure a correct result.
else try symbolic execution
format message
is code conditional (inside a jump)?
get function that yielded
is 'c' a constant?
push it on stack
it is its own name
keep last instruction that changed 'reg'
** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
Open a hole inside the stack at 'func'
continue running the coroutine
push error message
error status?
'pos' part: restore 'p'
finish interrupted instruction
comment:
** Do the work for 'lua_resume' in protected mode. Most of the work
** depends on the status of the coroutine: initial state, suspended
** inside a hook, or regularly suspended (optionally with a continuation
** function), plus erroneous cases: non-suspended coroutine or dead
** coroutine.
label: code-design
correct 'pc'
stack grow uses memory
handle typical cases separately
something in the stack
no results?
run continuation
save context
pushing msg. can break this invariant
}==================================================================
an error occurred?
back to caller
execute down to higher C 'boundary'
do the actual call
Lua function: prepare its call
finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already
handled
no pending pcall
allow yields
free all CIs (list grew because of an error)
jump to it
save 'p'
close possible pending closures
dynamic structures used by the parser
shrink list
slot ensured by caller
is there a continuation?
no recovery point
restore old error handler
res == final position of 1st result
error message on current top
nothing to move
{
move fixed parameters to final position
ensure minimum stack size
erase original copy (for GC)
is a Lua function?
not in base level?
}======================================================
** Recovers from an error in a coroutine. Finds a recover point (if
** there is one) and completes the execution of the interrupted
** 'luaD_pcall'. If there is no recover point, returns zero.
** Check whether __call metafield of 'func' is a function. If so, put
** it in stack below original 'func' so that 'luaD_precall' can call
** it. Raise an error if __call metafield is not a function.
comment: reuse preregistered msg.
label: code-design
erase new segment
try to get '__call' metamethod
** $Id: ldo.c,v 2.151 2015/12/16 16:40:07 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
complete wanted number of results
number of real arguments
re-throw in main thread
'oldpc' for caller function
no handler at all; abort
C closure
}{
comment:
** Finishes a function call: calls hook if necessary, removes CallInfo,
** moves current number of results to proper place; returns 0 iff call
** wanted multiple (variable number of) results.
label: code-design
stack overflow?
restore original 'allowhook'
data to 'f_parser'
** Prepares a function call: checks the stack, creates a new CallInfo
** entry, fills in the relevant information, calls hook if needed.
** If function is a C function, does the call, too. (Otherwise, leave
** the execution ('luaV_execute') to the caller, to allow stackless
** calls.) Returns true iff function has been executed (C function).
hook may change stack
dummy variable
top points after the last result
do not use vararg?
C++ exceptions
does it have a continuation function?
finish 'luaD_precall'
light C function
"finish" luaD_pcall
save "number of non-yieldable" calls
move it to proper place
move all results to correct place
ensure space for metamethod
was inside a pcall?
** LUAI_THROW/LUAI_TRY define how Lua does exception handling. By
** default, Lua handles errors with exceptions when compiling as
** C++ code, with _longjmp/_setjmp when asked to use them, and with
** longjmp/setjmp otherwise.
Lua function
normal end or yield
** Call a hook for the given event. Make sure there is a hook to be
** called. (Both 'L->hook' and 'L->hookmask', which triggers this
** function, can be changed asynchronously by signals.)
first argument
restore 'nny'
trying to shrink?
unrecoverable error?
dynamic structure used by the scanner
** Similar to 'luaD_call', but does not allow yields during the call
** Executes "full continuation" (everything in the stack) of a
** previously interrupted coroutine until the stack is empty (or another
** interruption long-jumps out of the loop). If the coroutine is
** recovering from an error, 'ud' points to the error status, which must
** be passed to the first continuation function (otherwise the default
** status is LUA_YIELD).
error status can only happen in a protected call
cannot call hooks inside a hook
yielded inside a hook?
memory error?
** Try to find a suspended protected call (a "recover point") for the
** given thread.
some space for error handling
not handling stack overflow?
protect stack below results
cannot yield during parsing
enough results?
Lua function?
shrink it
unroll continuation
now 'enter' new function
main thread has a handler?
hooks assume 'pc' is already incremented
return to 'luaD_hook'
jump back to 'lua_resume'
error after extra size?
coroutine is in base level; start running it
adjust with nil
panic function?
call continuation
inside a hook?
mark it as dead
number of returns
'common' yield
assume EXTRA_STACK
first fixed argument
make sure there is a hook
was handling stack overflow?
resuming from previous yield
ISO C handling with long jumps
** Given 'nres' results at 'firstResult', move 'wanted' of them to 'res'.
** Handle most typical cases (zero results for commands, one result for
** expressions, multiple results for tail calls/single parameters)
** separated.
not enough results; use all of them plus nils
finish 'lua_pcall'
comment: in POSIX, try _longjmp/_setjmp (more efficient)
label: code-design
chain new error handler
complete its execution
chain list of long jump buffers
call it
yield results come from continuation
may be starting a coroutine
continue running after recoverable errors
error while handing stack error
tag method is the new function to be called
** {======================================================
** Error-recovery functions
** =======================================================
macro to check stack size, preserving 'p'
call continuation function
thread has no error handler
complete missing arguments
** Execute a protected parser.
wanted == LUA_MULTRET
mark thread as 'dead'
move results to proper place
just continue running Lua code
move wanted results to correct place
}
error calling 'lua_resume'?
remove args from the stack
final position of first argument
not a function
search for a pcall
read first character
set status
call panic function (last chance to jump out)
mark that it is running (again)
copy error obj.
** Call a function (C or Lua). The function to be called is at *func.
** The arguments are on the stack, right after the function.
** When returns, all the results are on the stack, starting at the original
** function position.
must have a continuation and must be able to call it
should be zero to be yieldable
C function?
number of arguments
frame size
starting point
** Check appropriate error for stack overflow ("regular" overflow or
** overflow while handling stack overflow). If 'nCalls' is larger than
** LUAI_MAXCCALLS (which means it is handling a "regular" overflow) but
** smaller than 9/8 of LUAI_MAXCCALLS, does not report an error (to
** allow overflow handling to work)
must be inside a hook
error code
** signal an error in the call to 'resume', not in the execution of the
** coroutine itself. (Such errors should not be handled by any coroutine
** error handler and should not kill the coroutine.)
don't change stack (change only for debugging)
** {==================================================================
** Stack reallocation
** ===================================================================
one result needed
finish 'lua_pcallk' callee
thread has an error handler?
part of stack in use
** Completes the execution of an interrupted C function, calling its
** continuation function.
now it must be a function
save current 'func'
** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
In general, 'pre'/'pos' are empty (nothing to save)
** Macro to check stack size and grow stack if needed. Parameters
** 'pre'/'pos' allow the macro to preserve a pointer into the
** stack across reallocations, doing the work only when needed.
** 'condmovestack' is used in heavy tests to force a stack reallocation
** at every check.
comment: type of protected functions, to be ran by 'runprotected'
label: code-design
no need to save '\0'
include trailing '\0'
** dump Lua function as precompiled chunk
** All high-level dumps go through DumpVector; you can change it to
** change the endianness of the result
no debug info or same source as its parent
** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
link it to the list
current value lives in the stack
now current value lives here
found a corresponding upvalue?
remove from 'open' list
is variable active?
free upvalue
make it closed
** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
not found
return it
** Look for n-th local variable at line 'line' in function 'func'.
** Returns NULL if not found.
** fill a closure with new closed upvalues
no references?
not found: create a new upvalue
move value to upvalue slot
link it to list of open upvalues
thread not in list of threads with upvalues?
(when open)
linked list
comment: mark to avoid cycles with dead threads
label: code-design
the value (when closed)
** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
reference counter
** maximum number of upvalues in a closure (both C and Lua). (Value
** must fit in a VM register.)
** Upvalues for Lua closures
test whether thread is in 'twups' list
points to stack or to its own value
at this point, all resurrected objects are marked.
is 'curr' dead?
true if table has entry "white-key -> white-value"
"sweep" object
** barrier that moves collector backward, that is, mark the black object
** pointing to a white object as gray again.
mark any finalizing object left from previous cycle
mark nested protos
is there a weak mode?
** sweep a list until a live object (or end of list)
comment:
** macro to adjust 'pause': 'pause' is actually used like
** 'pause / PAUSEADJ' (value chosen by tests)
label: code-design
remove it
separate all objects with finalizers
minimal debt
push finalizer...
comment: may have to clean white keys
label: code-design
keep marked thread with upvalues in the list
make sure gray list is empty
remove 'o' from 'allgc' list
sweep objects to be finalized
** {======================================================
** Sweep Functions
** =======================================================
** mark an object that can be NULL (either because it is really optional,
** or it was stripped as debug info, or inside an uncompleted structure)
memory traversed in this step
link it to 'fixedgc' list
traverse 'grayagain' list
comment: unused and unmarked key; remove it
label: code-design
at this point, all strongly accessible objects are marked.
start counting work
should not remove 'sweepgc' object
registry and global metatables may be changed by API
first estimate
return it to 'allgc' list
mark value
mark live elements in the stack
finish sweeps
** If key is not marked, mark its entry as dead. This allows key to be
** collected, but keeps its entry in the table. A dead node is needed
** when Lua looks up for a key (it may be part of a chain) and when
** traversing a weak table (key might be removed from the table during
** traversal). Other places never manipulate dead keys, because its
** associated nil value is enough to signal that the entry is logically
** empty.
start new collection
** clear entries with unmarked keys from all weaktables in list 'l' up
** to element 'f'
traverse marked some value?
** barrier that moves collector forward, that is, mark the white object
** being pointed by a black object. (If in sweep phase, clear the black
** object to white [sweep it] to avoid other barrier calls for this
** same object.)
they will be gray forever
}======================================================
must keep invariant?
** create a new collectable object (with given type and size) and link
** it to 'allgc' list.
strong keys?
link it back to the list
change mark to 'white'
** If possible, shrink string table
run up to finalizers
remove object from 'allgc' list
current white
** clear entries with unmarked values from all weaktables in list 'l' up
** to element 'f'
is there an error object?
mark global metatables
nothing more to finalize?
traverse array part
move 'o' to 'finobj' list
stop counting (objects being finalized)
adjust 'estimate'
has to be cleared later
remove from 'gray' list
white-white entry
remove 'curr' from list
strong values?
is there a white value?
markvalue(g, &uvalue);
remove it from hash table
comment: remark occasional upvalues of (maybe) dead threads
label: code-design
remark, to propagate 'resurrection'
GC deficit (be paid now)
is there a finalizer?
entry is empty?
don't bother with it
Clear values from weak tables, before checking finalizers
clear keys from all ephemeron tables
mark that it is out of list
mark running thread
** Traverse an ephemeron table and link it to proper list. Returns true
** iff any object was marked during this traversal (which implies that
** convergence has to continue). During propagation phase, keep table
** in 'grayagain' list, to be visited again in the atomic phase. In
** the atomic phase, if table has any white->white entry, it has to
** be revisited during ephemeron convergence (as that key may turn
** black). Otherwise, if it has any white key, table has to be cleared
** (in the atomic phase).
** traverse one gray object, turning it to black (except for threads,
** which are always gray).
** Traverse a table with weak values and link it to proper list. During
** propagate phase, keep it in 'grayagain' list, to be revisited in the
** atomic phase. In the atomic phase, if table has any white value,
** put it in 'weak' list, to be cleared.
complete counting
** tells whether a key or value can be cleared from a weak
** table. Non-collectable objects are never removed from weak
** tables. Strings behave as 'values', so are never removed too. for
** other objects: if really collected, cannot keep them; for objects
** being finalized, keep them in keys, but not in values
must retraverse it in atomic phase
go to next element
** 'makewhite' erases all color bits then sets only the current white
** bit
** {======================================================
** Finalization
** =======================================================
ensured by macro luaC_upvalbarrier
** {======================================================
** Generic functions
** =======================================================
call remaining finalizers
** Traverse a prototype. (While a prototype is being build, its
** arrays can be larger than needed; the extra slots are filled with
** NULL, so the use of 'markobjectN')
link table into proper list
do not change stack in emergency cycle
** mark an object. Userdata, strings, and closed upvalues are visited
** and turned black here. Other objects are marked gray and added
** to appropriate list to be visited (and turned black) later. (Open
** upvalues are already linked in 'headuv' list.)
if there is array part, assume it may have white values (it is not
worth traversing it now just to check)
link it in 'finobj' list
** cost of sweeping one element (the size of a small object divided
** by some adjust for the sweep speed)
estimate must be correct after a full GC cycle
or has no finalizer?
** advances the garbage collector until it reaches a state allowed
** by 'statemask'
real end of stack
remove it from 'tobefnz' list
sweep main thread
** $Id: lgc.c,v 2.212 2016/03/31 19:02:03 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
** Mark all values stored in marked open upvalues from non-marked threads.
** (Values from marked threads were already marked when traversing the
** thread.) Remove from the list threads that no longer have upvalues and
** not-marked threads.
traverse hash part
is really weak?
collect fixed objects
there may be objects to be finalized
... and its argument
mark its prototype
** mark metamethods for basic types
value was collected?
comment:
** macro to adjust 'stepmul': 'stepmul' is actually used like
** 'stepmul / STEPMULADJ' (value chosen by tests)
label: code-design
emergency mode or no more finalizers
finish collection
strings are 'values', so are never weak
** {======================================================
** Traverse functions
** =======================================================
mark its upvalues
remove value ...
overflow; truncate to maximum
tables may return to this list when traversed
** if object 'o' has a finalizer, remove it from 'allgc' list (must
** search the list to find it) and link it in 'finobj' list.
repeat until pause or enough "credit" (negative debt)
string table too big?
table has white keys?
table must be cleared
** sweep at most 'count' elements from a list of GCObjects erasing dead
** objects, where a dead object is one marked with the old (non current)
** white; change all non-dead objects back to white, preparing for next
** collection cycle. Return where to continue the traversal or NULL if
** list is finished.
re-throw error
comment: this "white" makes all objects look dead
label: code-design
save original list
not being collected?
mark objects that will be finalized
thread is not marked or without upvalues
** mark root set and reset all gray lists, to start a new collection
work is what was traversed by 'atomic'
** find last 'next' field in list 'p' list (to add elements in its end)
error in __gc metamethod
make table gray (again)
value not marked yet?
call one finalizer
mark it as such
restore state
"sweep" object 'o'
mark its metatable
shrink it a little
change 'sweepgc'
comment: remove dead objects from weak tables
label: code-design
true if an object is marked in this traversal
** {======================================================
** Mark functions
** =======================================================
traverse all finalizable objects
remark upvalue's value
** Set a reasonable "time" to wait before starting a new GC cycle; cycle
** will start when memory use hits threshold. (Division by 'estimate'
** should be OK: it cannot be zero (because Lua cannot even start with
** less than PAUSEADJ bytes).
else enter next state
flip current white
mark upvalue names
clear values from resurrected weak tables
avoid being called too often
set flag
mark main obj. as white to avoid other barriers
finish propagate phase
separate objects to be finalized
sweep "regular" objects
sweep objects with finalizers
restore hooks
comment: threads are never black
label: code-design
allow cache to be collected
clear not-marked stack slice
** open upvalues point to values in a thread, so those values should
** be marked when the thread is traversed except in the atomic phase
** (because then the value cannot be changed by the thread and the
** thread may not be traversed again)
** get GC debt and convert it from Kb to 'work units' (avoid zero debt
** and overflows)
get ephemeron list
** move all unreachable objects (or 'all' objects) that need
** finalization from list 'finobj' to list 'tobefnz' (to be finalized)
no more gray objects?
** performs a basic GC step when collector is running
object must be 1st in 'allgc' list!
** mark all objects in list of being-finalized
mark it now
insert into 'grayagain' list
link at the end of 'tobefnz' list
final traversal?
search for pointer pointing to 'o'
'remarkupvals' may have removed thread from 'twups' list
remove thread from the list
get first element
else call a few more next time
finish any pending sweep phase to start a new cycle
sweep phase
restart counting
keep table gray
obj. is already marked...
true if table has white keys
overflow?
table has white->white entries?
nothing to traverse now
table will have to be cleared
black objects?
stop counting (do not recount 'grayagain')
not weak
remove 'curr' from 'finobj' list
remove value
all weak
is there still something to sweep?
** {======================================================
** GC control
** =======================================================
can be marked in 'remarkupvals'
no overflow
propagate changes
key is not marked (yet)?
stack not completely built yet
cost of calling one finalizer
avoid GC steps
error while running __gc?
estimate of memory marked by 'atomic'
mark literals
and remove entry from table
** Performs a full GC cycle; if 'isemergency', set a flag to avoid
** some operations which could change the interpreter state in some
** unexpected ways (running finalizers and shrinking some structures).
** Before running the collection, check 'keepinvariant'; if it is true,
** there may be some objects marked as black, so the collector has
** to sweep all objects to turn them back to white (as white has not
** changed, nothing will be collected).
stop debug hooks during GC metamethod
** barrier for assignments to closed upvalues. Because upvalues are
** shared among closures, it is impossible to know the color of all
** closures pointing to it. So, we assume that the object being assigned
** must be marked.
mark local-variable names
clear keys from all 'allweak' tables
will have to revisit all ephemeron tables
pause until next cycle
restore invariant
mark key
sweep everything to turn them back to white
** link collectable object 'o' into list pointed by 'p'
** Enter first sweep phase.
** The call to 'sweeplist' tries to make pointer point to an object
** inside the list (instead of to the header), so that the real sweep do
** not need to skip objects created between "now" and the start of the
** real sweep.
have to propagate again
** call a few (up to 'g->gcfinnum') finalizers
empty
perform one single step
convert 'work units' to Kb
not running?
maximum number of elements to sweep in each single step
erase 'curr'
** one after last element in a hash array
** internal state for collector while inside the atomic phase. The
** collector should never be in this state while running regular code.
update estimate
** call all pending finalizers
nothing to be done
object is "normal" again
and (next line) call the finalizer
object has been marked for finalization
** Possible states of the Garbage Collector
~100 small strings
** Does one step of collection when debt becomes positive. 'pre'/'pos'
** allows some adjustments to be done only when needed. macro
** 'condchangemem' is used only for heavy tests (forcing a full
** GC cycle on every opportunity)
object is white (type 0)
** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
how much to allocate before next GC step
comment:
** macro to tell when main invariant (white objects cannot point to black
** ones) must be kept. During a collection, the sweep
** phase may break the invariant, as objects turned white may point to
** still-black objects. The invariant is restored when sweep ends and
** all objects are white again.
label: code-design
comment:
** some useful bit tricks
label: code-design
** Collectable objects may have one of three colors: white, which
** means the object is not marked; gray, which means the
** object is marked, but its references may be not marked; and
** black, which means that the object and all its references are marked.
** The main invariant of the garbage collector, while marking objects,
** is that a black object can never point to a white one. Moreover,
** any gray object must be in a "gray list" (gray, grayagain, weak,
** allweak, ephemeron) so that it can be visited again before finishing
** the collection cycle. These lists have no meaning when the invariant
** is not being enforced (e.g., sweep phase).
object is white (type 1)
bit 7 is currently used by tests (luaL_checkmemory)
neither white nor black
object is black
comment: Layout for bit use in 'marked' field:
label: code-design
more often than not, 'pre'/'pos' are empty
** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
"require" functions from 'loadedlibs' and set results to global table
** these libs are loaded by lua.c and are readily available to any Lua
** program
remove lib
** If you embed Lua in your program and need to open the standard
** libraries, call luaL_openlibs in your program. If you need a
** different set of libraries, copy this file to your project and edit
** it to suit your needs.
**
** You can also *preload* libraries, so that a later 'require' can
** open the library, which is already linked to the application.
** For that, do the following code:
**
** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
** lua_pushcfunction(L, luaopen_modname);
** lua_setfield(L, -2, modname);
** lua_pop(L, 1); // remove _PRELOAD table
create (and set) default files
maximum length of a numeral
current character (look ahead)
** {======================================================
** l_fseek: configuration for longer offsets
** =======================================================
invalid format
use standard output
make sure argument is an open stream
move 'n' and 'toclose' to their positions
** function to (not) close the standard files stdin, stdout, and stderr
skip if char is '+'
** Add current char to buffer (if not out of space) and read next one
finish string
** $Id: liolib.c,v 2.149 2016/05/02 14:03:19 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
true iff read something
comment:
** Change this macro to accept other modes for 'fopen' besides
** the standard ones.
label: code-design
ensure stack space for all results and for auxlib's buffer
+1 for ending '\0'
** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit
** in the limit for upvalues of a closure)
close/not close file when finished
at least one argument
read next one
pop new metatable
{
mark file handle as 'closed'
mark stream as closed
number
push metatable
ISO C definitions
number of arguments to read
number of elements in buffer 'buff'
** {======================================================
** l_popen spawns a new process connected to the current
** one through the file streams.
** =======================================================
push arguments to 'g_read'
}======================================================
** functions for 'io' library
try to read 'n' chars
read file in chunks of LUAL_BUFFERSIZE bytes
metatable.__index = metatable
file
save current char
read entire file
optimization: could be done exactly as for strings
add file to module
no-op when c == EOF
fractional part
** function to close 'popen' files
add ending newline to result
** When creating file handles, always creates a 'closed' file handle
** before opening the actual file; so, if there is a memory error, the
** handle is in a consistent state.
to traverse/check mode
** methods for file handles
'n' is number of results
}{
file is already closed?
line
no argument?
skip spaces
ignore closed and incompletely open files
numeral is hexadecimal
is there error information?
** Read a sequence of (hex)digits
prepare buffer to read whole block
is this a valid number?
Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*'
accepted extensions to 'mode' in 'fopen'
create metatable for file handles
ok
get decimal point from locale
always success
** function to close regular files
file being read
** Read a number: first reads a valid prefix of a numeral into a buffer.
** Then it calls 'lua_stringtonumber' to check whether the format is
** correct and to convert it to a Lua number
Windows (but not DDK) and Visual C++ 2005 or higher
2nd result is error message
want a newline and have one?
put file at index 1
count initial '0' as a valid digit
close buffer
add file methods to new metatable
** {======================================================
** READ
** =======================================================
add file to registry
close it
no memory errors can happen inside the lock
invalidate result
close it after iteration
"result" to be removed
keep file opened
fail
exponent digits
exponent mark?
file handle already on stack top
skip optional '*' (for compatibility)
open a new file
exponent signal
new module
line with end-of-line
number of chars actually read
read fails
first result is nil: EOF or error
auxiliary structure used by 'read_number'
check that it's a valid file handle
integral part
return them
error
optional signal
push nil instead
not a file
should return at least a nil
repeat until end of line
do not close it after iteration
}
to return 1 result
always accept a dot
return current value
unread look-ahead char
no arguments?
decimal point?
** Calls the 'close' function from a file handle. The 'volatile' avoids
** a bug in some versions of the Clang compiler (e.g., clang 3.0 for
** 32 bits).
generator created file?
push file at the stack top (to be returned)
put it at index 1
return ok if read something (either a newline or something else)
buffer overflow?
remove last result
get default input
** Accept current char if it is in 'set' (of size 2)
no file name?
preallocate buffer
read at least one value?
remove read digits from buffer
LUA_NUMBER
short literal strings
** increment line number and skips newline sequence (any of
** \n, \r, \n\r, or \r\n)
boolean value does not need GC barrier;
table has no metatable, so it does not need to invalidate cache
identifier or reserved word?
'...'
create env name
exponent part?
remove saved chars from buffer
'skip_sep' may dirty the buffer
else short comment
skip '\n' or '\r'
fixed format (symbols and reserved words)?
initialize buffer
string starts with a newline?
** Check whether current char is in set 'set' (with two chars) and
** saves it
'[=...' missing second bracket
read up to 3 digits
** creates a new string and anchors it in scanner's table so that
** it will not be collected until the end of the compilation
** (by that time it should be anchored somewhere)
temporarily anchor it in stack
skip it
use this one
not in use yet?
final character to be saved
and discharge it
read next token
spaces
long comment?
reserved words are never collected
string already present
optional exponent sign
skip 2nd '['
long string or simply '['
skip the 'z'
remove '\\'
** skip a sequence '[=*[' or ']=*]'; if sequence is well formed, return
** its number of '='s; otherwise, return a negative number (-1 iff there
** are no '='s after initial bracket)
skip '\n\r' or '\r\n'
** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
escape sequences
skip until end of line (or end of file)
comment: to avoid warnings
label: code-design
names, strings, and numerals
go through
skip 2nd ']'
result accumulator
ORDER RESERVED
skip '}'
chars to be removed: '\', 'u', '{', and first digit
reserved word
get env name
hexadecimal?
initial line (for error message)
** this function is quite liberal in what it accepts, as 'luaO_str2num'
** will reject ill-formed numerals.
no look-ahead token
will raise an error next loop
previous call may dirty the buff.
avoid wasting space
digital escape '\ddd'
skip long comment
add current to buffer for error message
error
create new string
reserved word?
skip delimiter
line breaks
'..'
re-use value previously stored
entry for 'str'
remove string from stack
'-' or '--' (comment)
'.', '..', '...', or number
t[string] = true
else is a comment
must have at least one digit
add 'buff' to string
zap following span of spaces
single-byte symbols?
single-char tokens (+ - / ...)
never collect this name
is there a look-ahead token?
keep delimiter (for error messages)
keep '\\' for error messages
skip 'u'
** =======================================================
** LEXICAL ANALYZER
** =======================================================
format error?
** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
environment variable name
current character (charint)
terminal symbols denoted by reserved words
input stream
line of last token 'consumed'
semantics information
dynamic structures used by the parser
input line counter
state of the lexer plus state of the parser when shared by all
functions
look ahead token
number of reserved words
current source name
current token
comment: to avoid collection/reuse strings
label: code-design
* WARNING: if you change the order of this enumeration,
* grep "ORDER RESERVED"
other terminal symbols
buffer for tokens
current function (parser)
maximum value for size_t
maximum size visible for Lua (must be representable in a lua_Integer
type to ensure maximum alignment
comment:
** macro to control inclusion of some hard tests on stack reallocation
label: test
** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count
** the total memory used by Lua (in bytes). Usually, 'size_t' and
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
** The luai_num* macros define the primitive operations over numbers.
the others are quite standard operations
maximum value of an int
** non-return type
** assertion for checking API calls
}{
realloc stack keeping its size
** Size of cache for strings in the API. 'N' is the number of
** sets (better be a prime) and "M" is the size of each set (M == 1
** makes a direct cache.)
}
{ external definitions?
** conversion of pointer to unsigned integer:
** this is for hashing only; there is no problem if the integer
** cannot hold the whole pointer value
comment: macro to avoid warnings about unused variables
label: code-design
** Maximum length for short strings, that is, strings that are
** internalized. (Cannot be smaller than reserved words or tags for
** metamethods, as these strings must be internalized;
** #("function") = 8, #("__newindex") = 10.)
** Initial size for the string table (must be power of 2).
** The Lua core alone registers ~50 strings (reserved words +
** metaevent keys + a few others). Libraries would typically add
** a few dozens more.
** maximum depth for nested C calls and syntactical nested non-terminals
** in a program. (Value must fit in an unsigned short int.)
** type for virtual-machine instructions;
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
types of 'usual argument conversions' for lua_Number and lua_Integer
cast a signed lua_Integer to lua_Unsigned
minimum size for string buffer
** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when
** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of
** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b)
** ~= floor(a/b)'. That happens when the division has a non-integer
** negative result, which is equivalent to the test below.
** these macros allow user-specific actions on threads when you defined
** LUAI_EXTRASPACE and need to do something extra when a thread is
** created/deleted/resumed/yielded.
** cast a lua_Unsigned to a signed lua_Integer; this cast is
** not strict ISO C, but two-complement architectures should
** work fine.
internal assertions for in-house debugging
16-bit ints
to avoid problems with conditions too long
** macros that are executed whenever program enters the Lua core
** ('lua_lock') and leaves the core ('lua_unlock')
** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $
** Limits, basic types, and some other 'installation-dependent' definitions
** See Copyright Notice in lua.h
chars used as small naturals (so that 'char' is reserved for characters)
float division
floor division (defined as 'floor(a/b)')
exponentiation
** macro executed during Lua functions at points where the
** function can yield.
comment: type casts (a macro highlights casts in the code)
label: code-design
index of current maximum value
special cases: -1 or 0
no arguments
lower and upper limits
check number of arguments
}==================================================================
number is its own integer part
}
fractional part (test needed for inf/-inf)
integer is its own ceil
Number between 0 and 1
** {==================================================================
** Deprecated functions (for compatibility only)
** ===================================================================
no fractional part
** Open math library
** This function uses 'double' (instead of 'lua_Number') to ensure that
** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0'
** will keep full precision (ensuring that 'r' is always less than 1.0.)
only upper limit
number of arguments
placeholders
{
does 'd' fit in an integer?
value is not convertible to integer
random integer in the interval [low, up]
result is float
index of current minimum value
integer part (rounds toward zero)
** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
result is integer
(2^31 - 1), following POSIX
** next function does not use 'modf', avoiding problems with 'double*'
** (which is not compatible with 'float*') when lua_Number is not
** 'double'.
integer is its own floor
discard first value to avoid undesirable correlations
avoid overflow with 0x80000... / -1
** About the realloc function:
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
** ('osize' is the old size, 'nsize' is the new size)
**
** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no
** matter 'x').
**
** * frealloc(ud, p, x, 0) frees the block 'p'
** (in this specific case, frealloc must return NULL);
** particularly, frealloc(ud, NULL, 0, 0) does nothing
** (which is equivalent to free(NULL) in ISO C)
**
** frealloc returns NULL if it cannot create or reallocate the area
** (any reallocation to an equal or smaller size cannot fail!)
cannot fail when shrinking a block
cannot double it?
cannot grow even a little?
update only when everything else is OK
minimum size
** generic allocation routine.
force a GC whenever possible
** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
still have at least one free place
try to free some memory...
try again
is state fully built?
not to be called directly
** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
comment:
** Arrays of chars do not need any test
label: test
comment:
** This macro reallocs a vector 'b' from 'on' to 'n' elements, where
** each element has size 'e'. In case of arithmetic overflow of the
** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because
** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e).
**
** (The macro is somewhat complex to avoid warnings: The 'sizeof'
** comparison avoids a runtime comparison when overflow cannot occur.
** The compiler should be able to optimize the real test by itself, but
** when it does it, it may give a warning about "comparison is always
** false due to limited range of data type"; the +1 tricks the compiler,
** avoiding this warning but also this optimization.)
label: code-design
no errors?
** Look for a C function named 'sym' in a dynamically loaded library
** 'path'.
** First, check whether the library is already loaded; if not, try
** to load it.
** Then, if 'sym' is '*', return true (as library has been loaded).
** Otherwise, look for symbol 'sym' in the library and push a
** C function with that symbol.
** Return 0 and 'true' or a function in the stack; in case of
** errors, return an error code and an error message in the stack.
set CLIBS table in registry
remove file name
pop CLIBS table
** unload library 'lib'
concatenate error message
_LOADED[name] = true
root not found
unable to load library
comment: concatenate error msg. entry
label: code-design
return nil + error message
CLIBS[#CLIBS + 1] = plib
create new metatable
not found
** {========================================================================
** This is an implementation of loadlib based on the dlfcn interface.
** The dlfcn interface is available in Linux, SunOS, Solaris, IRIX, FreeBSD,
** NetBSD, AIX 4.2, HPUX 11, and probably most other Unix flavors, at least
** as an emulation layer on top of native functions.
** =========================================================================
run loader to load module
non-empty separator?
_LOADED[name]
set field 'cpath'
to build error message
name is 1st argument (before search data)
package is already loaded
CLIBS[path] = plib
comment: remove extra return
label: code-design
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
** LUA_IGMARK is a mark to ignore all before it when building the
** luaopen_ function name.
put it in field 'searchers'
unable to find function
{
use default
iterate over available searchers to find a loader
push 'package.searchers' to index 3 in the stack
open failed
copy new environment table to top
comment:
** Macro to convert pointer-to-void* to pointer-to-function. This cast
** is undefined according to ISO C, but POSIX assumes that it works.
** (The '__extension__' in gnu compilers is only to avoid warnings.)
label: code-design
set finalizer for CLIBS table
try alternative name
}======================================================
remove 'getfield' result
module loader found
remove function
module set no value?
comment: not used
label: code-design
does file exist and is readable?
did it find a loader?
fill it with predefined searchers
put it in field 'loaders'
no errors
** return registry.LUA_NOENV as a boolean
look for last dot in module name
pop CLIBS table and 'plib'
module not found in this path
non-nil return?
}{
searcher returned error message?
return nil, error message, and where
check whether table already has a _NAME field
else must load package
try to open file
error codes for 'lookforfunc'
return the loaded function
set 'package' as upvalue for next lib
** system-dependent functions
open lib into global table
** {======================================================
** Fallback for other systems
** =======================================================
return that file name
_LOADED table will be at index 2
create metatable for CLIBS
mt.__index = _G
module._M = module
no more searchers?
auxiliary mark (for internal use)
skip separators
template
is it there?
return 'true'
_LOADED[name] = returned value
pop handle
get calling function
pop global table
find next separator
create error message
module
check loaded C libraries
** return registry.CLIBS[path]
else create new function
module loaded successfully?
set field 'path'
return open function and file name
no; initialize it
set field 'preload'
for each handle, in reverse order
open function not found
** optional flags for LoadLibraryEx
real error
no more templates
placeholders
remove nil
** {======================================================
** 'require' function
** =======================================================
comment: will be 2nd argument to module
label: code-design
** registry.CLIBS[path] = plib -- for queries
** registry.CLIBS[#CLIBS + 1] = plib -- also keep a list of all libraries
remove path template
no environment variable?
error message is on top of the stack
must load library?
pass name as argument to module loader
error; error message is on stack top
loading only library (no function)?
use true as result
store config information
call it
separator for open functions in C libraries
** Try to find a function named 'sym' in library 'lib'.
** Returns the function; in case of error, returns NULL plus an
** error string in the stack.
comment: not used: symbols are 'global' by default
label: code-design
** LUA_CSUBSEP is the character that replaces dots in submodule names
** when searching for a C loader.
** LUA_LSUBSEP is the character that replaces dots in submodule names
** when searching for a Lua loader.
get option (a function)
}
remove original string
get handle CLIBS[n]
avoid 'calling' extra info.
table is an initialized module
remove value
replace it by 'dirsep'
** unique key for table in the registry that keeps handles
** for all loaded C libraries
** __gc tag method for CLIBS table: calls 'lsys_unloadlib' for all lib
** handles in list CLIBS
** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment
** variables that Lua check to set its paths.
global symbols if 'sym'=='*'
else go ahead and try old-style name
prefix for open functions in C libraries
is root
make a copy of 'searchers' table
extra copy to be returned
set _PACKAGE as package name (full module name minus last part)
create 'package' table
** create table CLIBS to keep track of loaded C libraries,
** setting a finalizer to close all libraries when closing state.
** load C library in file 'path'. If 'seeglb', load with all names in
** the library global.
** Returns the library; in case of error, returns NULL plus an
** error string in the stack.
** changes the environment variable of calling function
create CLIBS table
not found?
** {======================================================================
** This is an implementation of loadlib for Windows using native functions.
** =======================================================================
plib = CLIBS[path]
** Try to find a load function for module 'modname' at file 'filename'.
** First, change '.' to '_' in 'modname'; then, if 'modname' has
** the form X-Y (that is, it has an "ignore mark"), build a function
** name "luaopen_X" and look for it. (For compatibility, if that
** fails, it also tries "luaopen_Y".) If there is no ignore mark,
** look for a function named "luaopen_modname".
return 'package' table
get/create module table
** {======================================================
** 'module' function
** =======================================================
create 'searchers' table
last parameter
remove both returns
replace ";;" by ";AUXMARK;" and then AUXMARK by default path
set field 'loaded'
set 'package' as upvalue for all searchers
** $Id: loadlib.c,v 1.127 2015/11/23 11:30:45 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
** This module contains an implementation of loadlib for Unix systems
** that have dlfcn, an implementation for Windows, and a stub for other
** systems.
convert the top element to a string
correct decimal point
maximum length of a numeral
true after seen a dot
invalid format
skip '0x'
1 if number is negative
now there is one less bit available in first byte
can read it without overflow?
read exponent
string; format as [string "source"]
check '0x'
add first byte
exponent part?
zero-terminated string
'literal' source
skip trailing spaces
a pointer
try to convert
add prefix
skip '0x' and read numeral
result (accumulator)
skip 'p'
should not fail when folding (compile time)
}======================================================
coarse steps
an 'int' as a UTF-8 sequence
keep it
decimal
x = ceil(x / 16)
no digits?
remove added bits
try again
number of chars of a literal string without the ending \0
looks like an int?
nothing recognized?
signal
an 'int'
maximum length of the conversion of a number to a string
could not perform raw operation; try metamethod
** convert an hexadecimal numeric string to a number, following
** C99 specification for 'strtod'
add continuation bytes
** this function handles only '%d', '%c', '%f', '%p', and '%s'
conventional formats, plus Lua-specific '%I' and '%U'
number of significant digits
conversion failed
invalid format (no '0x')
make relative to 's'
exponent value
reject 'inf' and 'nan'
nothing is valid yet
fine steps
log_2[i] = ceil(log2(i - 1))
x = ceil(x / 2)
too many digits; ignore, but still count for exponent
file name
find first new line (if any)
still needs continuation byte?
neither a dot nor a digit
small one-line source?
something wrong in the numeral
do not accept it (as integer)
hex?
other operations
valid up to here
need continuation bytes
** converts an integer to a "floating point byte", represented as
** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
** eeeee != 0 and (xxx) otherwise.
number of bytes put in buffer (backwards)
converts back
add '...' before rest of name
check signal
decimal digit? correct exponent
else try as a float
success; return string size
an 'int' as a character
exponent signal
second dot? stop loop
each digit multiplies/divides value by 2^4
** Convert a number object to a string
adds '.0' to result
stop at first newline
operate only on floats
overflow?
** {==================================================================
** Lua's implementation for 'lua_strx2number'
** ===================================================================
a 'lua_Number'
** $Id: lobject.c,v 2.111 2016/05/20 14:07:48 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
maximum number of significant digits to read (to avoid overflows
even with single floats)
should be enough space for a '%p'
small enough?
go to the end
ascii?
operate only on integers
skip initial spaces
number of non-significant digits
truncate it
non-significant digit (zero)?
failed? may be a different locale
exponent correction
OK if no trailing characters
save space for prefix+suffix+'\0'
exponent
copy string to buffer
invalid; must have at least one digit
try as an integer
maximum that fits in first byte
string too long or no dot; fail
comment: non-printable character; print its code
label: code-design
** Convert string 's' to a Lua number (put in 'result'). Return NULL
** on fail or the address of the ending '\0' on success.
** 'pmode' points to (and 'mode' contains) special things in the string:
** - 'x'/'X' means an hexadecimal numeral
** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)
** - '.' just optimizes the search for the common case (nothing special)
** This function accepts both the current locale or a dot as the radix
** mark. If the convertion fails, it may mean number has a dot but
** locale accepts something else. In that case, the code copies 's'
** to a buffer (because 's' is read-only), changes the dot to the
** current locale radix mark, and tries to convert again.
** Computes ceil(log2(x))
a 'lua_Integer'
** 'module' operation for hashing (size is always a power of 2)
collectable objects
Variant tags for numbers
Macros to access values
** Header for string value; string bytes follow the end of this structure
** (aligned according to 'UTString'; see next).
user value's tag
constants used by the function
to new object
long strings
reserved words for short strings; "has hash" for longs
2: declared vararg; 1: uses vararg
whether it is in stack (register)
Macros for internal tests
index of upvalue (in stack or in outer function's list)
linked list for hash table
** Tables
integer numbers
get string length from 'TString *s'
Variant tags for strings
macro defining a nil value
** Extra tags for non-values
map from opcodes to source lines (debug information)
length for short strings
light userdata
debug information
** Closures
mark a tag as collectable
ensures maximum alignment for strings
copy a value into a key without messing up field 'next'
used for debug information
** $Id: lobject.h,v 2.116 2015/11/03 18:33:10 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
C closure
functions defined inside the function
Lua closure
size of 'upvalues'
light C function
size of 'p'
** different types of assignments, according to destination
array part
get string length from 'TValue *o'
** Tagged Values. This is the basic representation of values in Lua,
** an actual value plus a tag with its type.
to stack (not from same stack)
** (address of) a fixed nil value
** Description of an upvalue for function prototypes
type tag of a TValue with no variants (bits 0-3)
Macros to test type
light C functions
** Lua Upvalues
for chaining (offset for next node)
comment: first point where variable is dead
label: code-design
** tags for Tagged Values have the following use of bits:
** bits 0-3: actual tag (a LUA_T* value)
** bits 4-5: variant bits
** bit 6: whether value is collectable
a dead value may get the 'gc' field, but cannot access its contents
ensures maximum alignment for 'local' udata
** LUA_TFUNCTION variants:
** 0 - Lua function
** 1 - light C function
** 2 - regular C function (closure)
from table to same table
** Common type for all collectable objects
user value
size of 'k'
** Get the address of memory block inside 'Udata'.
** (Access to 'ttuv_' ensures that value is really a 'Udata'.)
short strings
** Description of a local variable for function prototypes
** (used for debug information)
** Ensures that address after this type is always fully aligned.
first point where variable is active
any free position is before this position
size of buffer for 'luaO_utf8esc' function
length for long strings
tag with no variants (bits 0-3)
upvalue name (for debug information)
Variant tags for functions
** {======================================================
** types and prototypes
** =======================================================
size of 'array' array
** Get the actual string (array of bytes) from a 'TString'.
** (Access to 'extra' ensures that value is really a 'TString'.)
type tag of a TValue (bits 0-3 for tags + variant bits 4-5)
function prototypes
Macros to set values
** Common type has only the common header
booleans
upvalue information
float numbers
removed keys in tables
** number of all possible tags (including LUA_TNONE but excluding DEADKEY)
last-created closure with this prototype
Bit mark for collectable types
opcodes
index to stack elements
number of fixed parameters
get the actual string (array of bytes) from a Lua value
raw type tag of a TValue
** Header for userdata; memory area follows the end of this structure
** (aligned according to 'UUdata'; see next).
from stack to (same) stack
to table (define it as an expression to be used in macros)
1<<p means tagmethod(p) is not present
number of bytes
number of registers needed by this function
list of upvalues
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
information about local variables (debug information)
** Union of all Lua values
log2 of size of 'node' array
** Function Prototypes
OP_LOADNIL
OP_UNM
OP_MOVE
OP_IDIV
OP_SELF
OP_VARARG
OP_RETURN
OP_JMP
OP_FORPREP
OP_CLOSURE
OP_LOADKX
OP_DIV
OP_NOT
OP_LE
OP_TFORCALL
OP_LEN
OP_EQ
OP_SETUPVAL
OP_POW
OP_BNOT
OP_BOR
OP_LT
OP_SETLIST
OP_TFORLOOP
OP_SHR
ORDER OP
T A B C mode opcode
OP_EXTRAARG
OP_CONCAT
** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
OP_SETTABLE
OP_MUL
OP_LOADK
OP_SHL
OP_BXOR
OP_GETTABLE
OP_LOADBOOL
OP_GETTABUP
OP_FORLOOP
OP_BAND
OP_MOD
OP_NEWTABLE
OP_SETTABUP
OP_TEST
OP_TAILCALL
OP_ADD
OP_CALL
OP_SUB
OP_GETUPVAL
OP_TESTSET
A B R(A), R(A+1), ..., R(A+B) := nil
comment: argument is not used
label: code-design
===========================================================================
Notes:
(*) In OP_CALL, if (B == 0) then B = top. If (C == 0), then 'top' is
set to last_result+1, so next open instruction (OP_CALL, OP_RETURN,
OP_SETLIST) may use 'top'.
(*) In OP_VARARG, if (B == 0) then use actual number of varargs and
set top (like in OP_CALL with C == 0).
(*) In OP_RETURN, if (B == 0) then return up to 'top'.
(*) In OP_SETLIST, if (B == 0) then B = 'top'; if (C == 0) then next
'instruction' is EXTRAARG(real C).
(*) In OP_LOADKX, the next 'instruction' is always EXTRAARG.
(*) For comparisons, A specifies what condition the test should accept
(true or false).
(*) All 'skips' (pc++) assume that next instruction is a jump.
===========================================================================
** invalid register that fits in 8 bits
number of list items to accumulate before a SETLIST instruction
A B C R(A) := R(B)[RK(C)]
A B C if ((RK(B) == RK(C)) ~= A) then pc++
A C if not (R(A) <=> C) then pc++
A B C if (R(B) <=> C) then R(A) := R(B) else pc++
test whether value is a constant
creates a mask with 'n' 1 bits at position 'p'
A B C if ((RK(B) < RK(C)) ~= A) then pc++
** R(x) - register
** Kst(x) - constant (in constant table)
** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
A B C return R(A)(R(A+1), ... ,R(A+B-1))
this bit 1 means constant (0 means register)
===========================================================================
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
'A' : 8 bits
'B' : 9 bits
'C' : 9 bits
'Ax' : 26 bits ('A', 'B', and 'C' together)
'Bx' : 18 bits ('B' and 'C' together)
'sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
for that argument (so that -max is represented by 0, and +max is
represented by 2*max), which is half the maximum for the corresponding
unsigned argument.
===========================================================================
A Bx R(A) := Kst(Bx)
** Macros to operate RK indices
A B C R(A) := RK(B) << RK(C)
basic instruction format
A B C R(A) := UpValue[B][RK(C)]
A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
A B C R(A) := RK(B) ^ RK(C)
A B R(A) := ~R(B)
** the following macros help to manipulate instructions
A B C R(A)[RK(B)] := RK(C)
A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx }
A B C R(A) := RK(B) - RK(C)
A sBx R(A)+=R(A+2);
if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
A B C R(A) := {} (size = B,C)
A B C if ((RK(B) <= RK(C)) ~= A) then pc++
A B UpValue[B] := R(A)
A sBx R(A)-=R(A+2); pc+=sBx
----------------------------------------------------------------------
name args description
------------------------------------------------------------------------
A B C R(A) := RK(B) & RK(C)
A B C R(A) := RK(B) / RK(C)
** size and position of opcode arguments.
A B C R(A) := RK(B) | RK(C)
A B C R(A) := RK(B) * RK(C)
A B R(A) := not R(B)
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
argument is used
A B R(A) := length of R(B)
A B R(A) := R(B)
A B C R(A) := RK(B) ~ RK(C)
opcode names
** grep "ORDER OP" if you change these enums
argument is a register or a jump offset
A B C R(A) := (Bool)B; if (C) pc++
gets the index of the constant
creates a mask with 'n' 0 bits at position 'p'
A B C R(A) := RK(B) // RK(C)
comment: Ax extra (larger) argument for previous opcode
label: code-design
argument is a constant or register/constant
A B return R(A), ... ,R(A+B-2) (see note)
A B C R(A) := RK(B) % RK(C)
A B R(A) := -R(B)
A Bx R(A) := closure(KPROTO[Bx])
A B R(A) := UpValue[B]
A B C R(A) := R(B).. ... ..R(C)
A R(A) := Kst(extra arg)
A B C UpValue[A][RK(B)] := RK(C)
A B R(A), R(A+1), ..., R(A+B-2) = vararg
** $Id: lopcodes.h,v 1.148 2014/10/25 11:50:46 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
A B C R(A) := RK(B) >> RK(C)
A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
code a constant index as a RK value
** masks for instruction properties. The format is:
** bits 0-1: op mode
** bits 2-3: C arg mode
** bits 4-5: B arg mode
** bit 6: instruction set register A
** bit 7: operator is a test (next instruction must be a jump)
A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1)
'sBx' is signed
A B C R(A) := RK(B) + RK(C)
options for Windows
copy valid option to buffer
** {==================================================================
** Configuration for time-related stuff
** ===================================================================
next length
options for ANSI C 89
options for ISO C 99 and POSIX
C99 specification
copy specifier to 'cc'
skip '!'
}{
invalid date?
}==================================================================
next block?
}
update fields with normalized values
UTC?
not a conversion specifier?
return next item
absent field; no default?
** {==================================================================
** Configuration for 'tmpnam':
** By default, Lua uses tmpnam except when POSIX is available, where
** it uses mkstemp.
** ===================================================================
field is not an integer?
** Set all fields from structure 'tm' in the table on top of the stack
some other value?
** By default, Lua uses gmtime/localtime, except when POSIX is available,
** where it uses gmtime_r/localtime_r
** type to represent time_t in Lua
match?
get field and its type
** {==================================================================
** List of valid conversion specifiers for the 'strftime' function;
** options are grouped by length; group of length 2 start with '||'.
** ===================================================================
if NULL push nil
{
get current time
maximum value for date fields (to avoid arithmetic overflows with 'int')
buffer for individual conversion specifiers
called without args?
maximum size for an individual 'strftime' item
ISO C definitions
does not set field
comment: to avoid warnings
label: code-design
}======================================================
** $Id: loslib.c,v 1.64 2016/04/18 13:06:55 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
** {======================================================
** Time/Date operations
** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S,
** wday=%w+1, yday=%j, isdst=? }
** =======================================================
9 = number of fields
undefined?
comment: 'if' to avoid warnings for unreachable 'return'
label: code-design
make sure table is at the top
true if there is a shell
'else' part
fix it at the last register
new or old upvalue
not found as local at current level; try upvalues
anchor it (to avoid being collected)
index is the local being assigned? (index cannot be upvalue)
end of scope for declared variables
** check whether current token is in the follow set of a block.
** 'until' closes syntactical blocks, but do not close scope,
** so it is handled in separate.
function created in next register
'/' '//'
read first token
must skip over 'then' part if condition is false
'+' '-'
global name?
assume that locals are already out of scope
create and...
not found
remove "near <token>" from final message
param -> '...'
** check whether, in an assignment to an upvalue/local variable, the
** upvalue/local variable is begin used in a previous assignment to a
** table. If so, save original upvalue/local value in a safe place and
** use this safe copy in the previous assignment.
must enter block before 'goto'
env[varname]
stat -> forstat
** compiles the main function, which is a regular vararg function with an
** upvalue named LUA_ENV
no value (yet)
stat -> LOCAL NAME {',' NAME} ['=' explist]
skip WHILE
free registers
============================================================
stat -> func | assignment
no more levels?
reserve register for parameters
** structure to chain all variables in the left-hand side of an
** assignment
control variables
left priority for each binary operator
** subexpr -> (simpleexp | unop subexpr) { binop subexpr }
** where 'binop' is any binary operator with a priority higher than 'limit'
assignment -> '=' explist
skip over block if condition is false
skip DO
local function?
~=, >, >=
...set environment upvalue
skip other no-op statements
forstat -> FOR (fornum | forlist) END
cond -> exp
create control variables
chain
last list item read
skip double colon
instruction to skip 'then' code (if condition is false)
remove goto from pending list
patch escape list to 'if' end
only one single value?
funcargs
upvalues?
remove scanner's table
scope block
generic for
** create a label named 'break' to resolve break statements
simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... |
constructor | FUNCTION body | suffixedexp
check all previous assignments
correct pending gotos to current block and try to close it
with visible labels
'then' part
variable is local
'falses' are all equal here
debug information will only see the variable after this point!
stat -> ';' (empty statement)
close the loop
stat -> 'goto' NAME
return no values
includes call itself
open call
** $Id: lparser.c,v 2.153 2016/05/13 19:10:16 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
funcstat -> FUNCTION funcname body
stat -> assignment ?
numeric for?
values must go to the stack
funcname -> NAME {fieldsel} [':' NAME]
set initial array size
key is variable name
tail call?
may be needed for error messages
last exp. provides the difference
create and anchor TString
check for repeated labels
linked list of funcstates
** nodes for block list (list of active blocks)
close it if label already defined
IF cond THEN block
stat -> breakstat
update pending gotos to outer block
block -> statlist
flush
call statement uses no results
correct label?
label not found; cannot close goto
prototype of current function
** export pending gotos to outer level, to check them against
** outer labels; if the block being exited has upvalues, and
** the goto exits the scope of any variable (which can be the
** upvalue), close those variables being exited.
statlist -> { stat [';'] }
funcargs -> '(' [ explist ] ')'
arg list is empty?
create declared variables
skip ';'
skip the '['
skip no-op statements
stat -> retstat
stat -> label
stat -> DO block END
create table for scanner
else was LOCAL or UPVAL
** check whether new label 'lb' matches any pending gotos in current
** block; solves forward jumps
inner block?
optional step
default is global
there is no list item
constructor
** {======================================================================
** Rules for Constructors
** =======================================================================
registers with returned values
true if some variable in the block is an upvalue
limit
return first untreated operator
skip 'for'
comment: maximum number of local variables per function (must be smaller
than 250, due to the bytecode format)
label: code-design
default step = 1
close last argument
fornum -> NAME = exp1,exp1[,exp1] forbody
definition "happens" in the first line
look up locals at current level
ELSEIF cond THEN block
function actually uses vararg
ORDER OPR
may be 'listfield' or 'recfield'
stat -> RETURN [explist] [';']
constructor -> '{' [ field { sep field } [sep] ] '}'
sep -> ',' | ';'
variable (global, local, upvalue, or indexed)
previous assignment will use safe copy
followed by 'else'/'elseif'?
check labels in current block for a match
ls->t.token == '['
finish scope
index -> '[' expr ']'
Find variable with given name 'n'. If it is an upvalue, add this
upvalue into all intermediate functions.
}====================================================================
anchor it
'..' (right associative)
because all strings are unified by the scanner, the parser
can use pointer equality for string equality
close it
return all active values
skip RETURN
comment: remove extra values
label: code-design
** generates an error for an undefined 'goto'; choose appropriate
** message when label name is a reserved word (which can only be 'break')
stat -> funcstat
all scopes should be correctly finished
remove local labels
stat -> func
'^' (right associative)
pending gotos in outer block?
stat -> whilestat
new local variable
** try to close a goto with existing labels; this solves backward jumps
skip the dot or colon
expression?
initial value
must jump over it
label is last no-op statement in the block?
is 'parlist' not empty?
registers 0/1 are always valid
closure is on the stack, too
** {======================================================================
** Expression parsing
** =======================================================================
suffixedexp ->
primaryexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
scope for loop and control variables
label -> '::' NAME '::'
try upper levels
it is a global
eventual position to save local variable
enter its scope
stat -> repeatstat
param -> NAME
'return' must be last statement
move to next one
create a 'jump to here' to close upvalues
do not count last expression (unknown number of elements)
loop scope ('break' jumps to this point)
field -> listfield | recfield
vararg
regular case (not goto/break)
true if 'block' is a loop
main function is always declared vararg
assignment -> ',' suffixedexp assignment
index of first label in this block
GRAMMAR RULES
repeatstat -> REPEAT block UNTIL cond
and that is it
skip optional semicolon
check for repeated labels on the same block
comment: extra space to call generator
label: code-design
optional return values
avoid default
finish loop
fieldsel -> ['.' | ':'] NAME
** {======================================================================
** Rules for Statements
** =======================================================================
forbody -> DO block
will jump to label if condition is true
read condition
create new entry for this label
call remove function and arguments and leaves
(unless changed) one result
false conditions finish the loop
'goto' is the entire block?
** prototypes for recursive non-terminal functions
index of first pending goto in this block
fieldsel
error
skip REPEAT
table descriptor
test_then_block -> [IF | ELSEIF] cond THEN block
stat -> ifstat
gen, state, control, plus at least one declared var
recfield -> (NAME | '['exp1']') = exp1
right priority
** adds a new prototype into list of prototypes
parlist -> [ param { ',' param } ]
no more items pending
** codes instruction to create new closure in parent function.
** The OP_CLOSURE instruction must use the last available register,
** so that, if it invokes the GC, the GC knows which registers
** are in use at that time.
at least one expression
read sub-expression with higher priority
whilestat -> WHILE cond DO block END
loop block
read condition (inside scope block)
try existing upvalues
must use 'seminfo' before 'next'
primaryexp -> NAME | '(' expr ')'
do not need barrier here
priority for unary operators
create 'self' parameter
table is the upvalue/local being assigned now?
body -> '(' parlist ')' block END
expand while operators have priorities higher than 'limit'
scope for declared variables
this one must exist
# active locals outside the block
close last expression
'[' exp1 ']'
handle goto/break
listfield -> exp
forlist -> NAME {,NAME} IN explist forbody
declared vararg
base register for call
skip break
Mark block where variable at given level was defined
(to emit close instructions later).
local will be used as an upval
index of new label being created
total number of 'record' elements
first variable name
semantic error
copy upvalue/local value to a temporary (in position 'extra')
exit list for finished parts
funcargs -> constructor
return all values
number of array elements pending to be stored
skip LOCAL
not found?
set initial table size
and, or
==, <, <=
found?
default assignment
skip FUNCTION
funcargs -> STRING
stat -> localstat
will be a new upvalue
':' NAME funcargs
skip IF or ELSEIF
close pending breaks
total number of array elements
}======================================================================
explist -> expr { ',' expr }
final return
fix it at stack top
'<<' '>>'
assigning to a table?
'&' '|' '~'
ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END
parse main body
create main closure
'*' '%'
get environment variable
floating constant; nval = numerical float value
constant nil
whether 't' is register (VLOCAL) or upvalue (VUPVAL)
constant false
chain of current blocks
local variable; info = local register
number of elements in 'p'
list of labels or gotos
expression is a test/comparison;
info = pc of corresponding jump instruction
number of elements in 'k'
for indexed variables (VINDEXED)
label identifier
array
** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
** Expression and variable descriptor.
** Code generation for variables and expressions can be delayed to allow
** optimizations; An 'expdesc' structure describes a potentially-delayed
** variable/expression. It has a description of its "main" value plus a
** list of conditional jumps that can also produce its value (generated
** by short-circuit operators 'and'/'or').
list of pending jumps to 'pc'
upvalue variable; info = index of upvalue in 'upvalues'
number of elements in 'f->locvars'
current function header
kinds of variables/expressions
constant in 'k'; info = index of constant in 'k'
for generic use
when 'expdesc' describes the last expression a list,
this kind means an empty list (so, no expression)
dynamic structures used by the parser
description of active local variable
expression has its value in a fixed register;
info = result register
variable index in stack
number of entries in use
lexical state
first free register
enclosing function
expression can put result in any register;
info = instruction pc
description of pending goto statements and label statements
local level where it appears in current block
indexed variable;
ind.vt = whether 't' is register or upvalue;
ind.t = table register or upvalue;
ind.idx = key's R/K index
for VKFLT
'label' of last 'jump label'
next position to code (equivalent to 'ncode')
vararg expression; info = instruction pc
for VKINT
integer constant; nval = numerical integer value
table (register or upvalue)
patch list of 'exit when false'
list of active local variables
state needed to generate code for a given function
expression is a function call; info = instruction pc
constant true
patch list of 'exit when true'
array size
number of active local variables
number of upvalues
list of pending gotos
position in code
defined in lparser.c
control of blocks
list of active labels
index of first local var (in Dyndata array)
index (R/K)
line where it appeared
comment: avoid warnings about ISO C functions
label: code-design
use -D_XOPEN_SOURCE=0 to undefine it
** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $
** Definitions for Lua code that must come before any other header file
** See Copyright Notice in lua.h
** Allows manipulation of large files in gcc and some other compilers
{
** Windows stuff
** Allows POSIX/XSI stuff
}
anchor it on L stack
no GC while building state
erase new stack
public function
free next
allow gc
memory allocation error: free partial state
will make 'totalbytes == MAX_LMEM'
collect all objects
registry[LUA_RIDX_GLOBALS] = table of globals
initialize L1 extra space
heap variable
create registry
close all upvalues for this thread
next's next
create new thread
only the main thread can be closed
** Compute an initial seed as random as possible. Rely on Address Space
** Layout Randomization (if present) to increase randomness..
200%
initialize first ci
** thread state + extra space
** Create registry table and its predefined values
remove 'next' from the list
while there are two nexts
stack not completely built yet
registry[LUA_RIDX_MAINTHREAD] = L
closing a fully built state?
global variable
local variable
** free half of the CallInfo structures not in use by a thread
'function' entry for this 'ci'
keep next's next
free stack array
link it on list 'allgc'
GC runs 'twice the speed' of memory allocation
init stack
** a macro to help the creation of a unique random seed when a state is
** created; the seed is used to randomize hashes.
thread has no upvalues
** Main thread combines a thread state and the global state
** free all CallInfo structures not in use by a thread
** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $
** Global State
** See Copyright Notice in lua.h
** open parts of the state that may cause memory-allocation errors.
** ('g->version' != NULL flags that the state was completely build)
free the entire 'ci' list
** set GCdebt to a new value keeping the value (totalbytes + GCdebt)
** invariant (and avoiding underflows in 'totalbytes')
free main block
temp = L
temp = new table (global table)
initialize stack array
** preinitialize a thread with consistent values without allocating
** any memory (to avoid errors)
metatables for basic types
thread
to be called in unprotected errors
current error recover point
** 'per thread' state
assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1
randomized seed for hashes
call was tail called
number of elements
function index in the stack
** Information about a call.
** When a thread yields, 'func' is adjusted to pretend that the
** top function has only the yielded values in its stack; in that
** case, the actual 'func' value is saved in field 'extra'.
** When a function calls another with a continuation, 'extra' keeps
** the function index so that, in case of errors, the continuation
** function can be called with the correct top.
comment: call is a yieldable protected call
label: code-design
list of gray objects
an estimate of the non-garbage memory in use
number of finalizers to call in each GC step
number of bytes currently allocated - GCdebt
list of tables with weak values
list of open upvalues in this stack
list of collectable objects with finalizers
list of all-weak tables
last free slot in the stack
call is running a Lua function
stack base
macro to convert a Lua object into a GCObject
true if GC is running
cache for strings in API
** Bits in CallInfo status
** Some notes about garbage-collected objects: All objects in Lua must
** be kept somehow accessible until being freed, so all objects always
** belong to one (and only one) of these lists, using field 'next' of
** the 'CommonHeader' for the link:
**
** 'allgc': all objects not marked for finalization;
** 'finobj': all objects marked for finalization;
** 'tobefnz': all objects ready to be finalized;
** 'fixedgc': all objects that are not to be collected (currently
** only small strings, such as reserved words).
current error handling function (stack index)
number of non-yieldable calls in stack
list of all collectable objects
extra stack space to handle TM calls and some other extras
state of garbage collector
actual number of total bytes allocated
bytes allocated not yet compensated by the collector
kinds of Garbage Collection
defined in ldo.c
array with tag-method names
gc was forced by an allocation failure
last hook called yielded
only for Lua functions
size of pause between successive GCs
base for this function
first free slot in the stack
list of threads with open upvalues
kind of GC running
memory-error message
only for C functions
CallInfo for first level (C calling Lua)
current position of sweep in list
list of userdata to be GC
list of objects to be traversed atomically
macros to convert a GCObject into a specific value
hash table for strings
last pc traced
auxiliary data to 'frealloc'
number of items in 'ci' list
** Union of all collectable objects (only for conversions)
using __lt for __le
top for this function
call is running on a fresh invocation
of luaV_execute
original value of 'allowhook'
expected number of results from this function
call is running a debug hook
continuation in case of yields
dynamic call link
** 'global state', shared by all threads of this state
list of ephemeron tables (weak keys)
common header
comment:
** Atomic type (relative to signals) to better ensure that 'lua_sethook'
** is thread safe
label: requirement
call info for current function
pointer to version number
list of objects not to be collected
context info. in case of yields
GC 'granularity'
number of nested C calls
function to reallocate memory
memory traversed by the GC
** $Id: lstate.h,v 2.130 2015/12/16 16:39:38 roberto Exp $
** Global State
** See Copyright Notice in lua.h
** equality for long strings
** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
dead (but not collected yet)?
same instance or...
short string?
shrink table if needed
remove element from its list
normal route
chain it
** Clear API string cache. (Entries cannot be empty, so fill them with
** a non-collectable string.)
total size of TString object
rehash
equal length and ...
new element is first in the list
otherwise 'memcmp'/'memcpy' are undefined
no hash?
** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to
** compute its hash
** checks whether short string exists and reuses it or creates a new one
find previous element
move out last element
** Initialize the string table and the string cache
** new string (with explicit length)
ending 0
found!
** resizes the string table
fill cache with valid strings
hash
resurrect it
it should never be collected
that is it
** Create or reuse a zero-terminated string, first checking in the
** cache (using the string address as a key). The cache can contain
** only zero-terminated strings, so it is safe to use 'strcmp' to
** check hits.
hit?
new position
now it has its hash
grow table if needed
vanishing slice should be empty
replace it with something fixed
** creates a new string object
save next
recompute with new size
will entry be collected?
initial size of string table
pre-create memory-error message
for each node in the list
equal contents
** equality for short strings, which are always internalized
** test whether a string is a reserved word
** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
first byte
1st char will be checked by 'memchr'
equal to '%g'
0 or more repetitions
end ('\0') of source string
return match(ms, s, ep + 1);
accept empty?
keep entire string
number of bits in a character
replacement type
ensure it uses a dot
correct 'l1' and 's1' to try again
no dot?
size of a lua_Integer
fixed-length strings
get string library
integers
set table as metatable for strings
not found
may overflow?
** {======================================================
** PATTERN MATCHING
** =======================================================
change it to a dot
state for 'gmatch'
end of pattern?
no modifiers?
** Ensures the 'buff' string uses a dot as the radix character.
otherwise, skip one character
add capture to accumulated result
remove result from 'luaL_tolstring'
accumulate total size of result
1st char is already checked
zero-terminated string
add zero at the end
end of last match
using goto's to optimize tail recursion
can be -0...
'X' gets alignment from following option
start
position capture?
is 'align' not a power of 2?
{
** information to pack/unpack stuff
mark to separate arguments from string buffer
end capture
pop metatable
to store the format ('%...')
** maximum number of captures that a pattern can do during
** pattern-matching. This limit is arbitrary, but must fit in
** an unsigned char.
no suffix
true iff machine is little endian
return match(ms, s + 1, ep);
else use default format
}======================================================
value used for padding
no; go to default
also treat cases 'pnLlh'
0 or more repetitions (minimum)
format item
points to optional suffix
end of subject
is number negative?
** maximum size of each format specification (such as "%-099.99d")
add whole match
** add length modifier into formats
replacement count
balanced string?
pack length
skip the '^'
may have more after \0
write as hexa ('%a')
stack space for item + next position
maximum recursion depth for 'match'
recursive function
no number?
add "0x"
need no alignment?
number of results
matches any char
deprecated option
points to what is next
character count
** Read and classify next option. 'size' is filled with option's size.
keep original text
pop dummy string
padding for alignment
's2' cannot be found after that
** Some sizes are better limited to fit in 'int', but must also fit in
** 'size_t'. (We assume that 'lua_Integer' cannot be smaller than 'int'.)
to put formatted item
** Read an integer numeral and raises an error if it is larger
** than the maximum size for integers.
fixed-size string
get argument
dummy structure to get native alignment requirements
negative number need sign extension?
empty interval; return no values
** Number of bits that goes into the first digit. It can be any value
** between 1 and 4; the following definition tries to align the number
** to nibble boundaries by making what is left after that first digit a
** multiple of 4.
return match(ms, s, p + 4);
mask for one character (NB 1's)
string ends out of balance
1 or more repetitions
else fail (s == NULL)
** Initialize Header
check whether pattern has no special characters
remove original value
enforce maximum alignment
padding
default
dummy union to get native endianness
** Read, classify, and fill other details about the next option.
** 'psize' is filled with option's size, 'notoalign' with its
** alignment requirements.
** Local variable 'size' gets the size to be aligned. (Kpadal option
** always gets its full alignment, other options are limited by
** the maximum alignment ('maxalign'). Kchar option needs no alignment
** despite its size.
init of source string
number of strings pushed
do a plain search
return match(ms, s, p + 2)
else return match(ms, s, ep + 1);
pattern class plus optional suffix
subject
add first digit
signed integers
'x' fraction and exponent
matched once
empty strings are everywhere
more digits?
add replacement to buffer
comment: no precision and string is too long to be formatted
label: code-design
is the '$' the last char in pattern?
zero-terminated strings
return match(ms, s, ep);
macro to 'unsign' a character
FALLTHROUGH
optional
** Union for serializing floats
skip string plus final '\0'
%%
look for a ']'
skip precision
fill alignment
get integer part from 'x'
start after string's end?
pattern has a special character
end ('\0') of pattern
** Pack integer 'n' with 'size' bytes and 'islittle' endianness.
** The final 'if' handles the case when 'size' is larger than
** the size of a Lua integer, correcting the extra sign-extension
** bytes if necessary (by default they would be zeros).
copy table
ms->level == 0, too
** Unpack an integer with 'size' bytes and 'islittle' endianness.
** If size is smaller than the size of a Lua integer and integer
** is signed, must do sign extension (propagating the sign to the
** higher bits); if size is larger than the size of a Lua integer,
** it must check the unread bytes to see whether they do not cause an
** overflow.
no special chars found
skip width
float?
does not match at least once?
translate a relative string position: negative means back from end
first n-1 copies (followed by separator)
last copy (not followed by separator)
1 match already done
to search for a '*s2' inside 's1'
end
skip ESC
** Copy 'size' bytes from 'src' to 'dest', correcting endianness if
** given 'islittle' is different from native endianness.
corner case?
fail
match failed
add result to accumulator
current argument to pack
keep them on closure to avoid being collected
(re)prepare state for new match
use hexa
undo capture
total number of captures (finished or unfinished)
** Read an integer numeral from string 'fmt' or return 'df' if
** there is no numeral
format string
table to be metatable for strings
handle optional suffix
(2 digits at most)
else didn't match; reduce 1 repetition to try again
** {======================================================
** STRING FORMAT
** =======================================================
** Hexadecimal floating-point formatter
add as many digits as needed
avoids a negative 'l1'
add string
valid flags in a format specification
match?
start capture
return what is left
correct extra bytes
total space used by option
add radix point
make it positive
undo increment
skip alignment
** Open string library
usually, alignment follows size
maximum size for the binary representation of an integer
return default value
comment: call never return, but to avoid warnings:
label: code-design
must check unread bytes
escaped sequences not in the format class[*+?-]?
no-op (configuration or spaces)
needs sign extension?
number of substitutions
add result to buffer
keeps trying to match with the maximum repetitions
unsigned integers
copy it into 'u'
explicit request or no special characters?
add signal
if number, convert it to string
check end of string
capture results (%0-%9)?
skip escapes (e.g. '%]')
number of bytes in added item
try with one more repetition
counts maximum expand for item
** $Id: lstrlib.c,v 1.251 2016/05/20 14:13:21 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
frontier?
}
strings with prefixed length
add to buffer
skip flags
** options for pack/unpack
this digit goes before the radix point
next position
try locale point
create "0" or "-0" followed by exponent
match failed?
add exponent
real size smaller than lua_Integer?
strings with length count
metatable.__index = string
move 'u' to final result, correcting endianness if needed
** {======================================================
** PACK/UNPACK
** =======================================================
pattern
floating-point numbers
need overflow check?
cannot find anything
number of arguments
do sign extension
skip anchor character
floating-point options
'+' or no suffix
LUA_TNUMBER or LUA_TSTRING
enough for any float type
close capture
arithmetic overflow?
current position
control for recursive depth (to avoid C stack overflow)
max replacements
format the string into 'buff'
empty 'memcpy' is not that cheap
nil or false?
** Add integer part of 'x' to buffer and return new 'x'
inf or NaN?
dummy string
** Maximum size of each formatted item. This maximum size is produced
** by format('%.99f', -maxfloat), and is equal to 99 + 3 ('-', '.',
** and '\0') + number of decimal digits to represent maxfloat (which
** is maximum exponent + 1). (99+3+1 then rounded to 120 for "extra
** expenses", such as locale-dependent stuff)
pad extra space
match state
skip string
shrink array
cannot find a free place?
i is zero or a present index
'key' is an appropriate array index
no more elements to count
compute new size for array part
number of keys in the array part
is 'key' inside array part?
grow table
2^i (candidate for optimal size)
whatever called 'newkey' takes care of TM cache
not found
count as such
count extra key
that's it
main position is taken?
copy colliding node into free pos. (mp->next also goes)
find 'i' and 'j' such that i is present and j is not
key index in hash table
try first array part
** Compute the optimal size for the array part of table 't'. 'nums' is a
** "count array" where 'nums[i]' is the number of integers in the table
** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of
** integer keys in the table and leaves with the number of keys that
** will go to the array part; return the optimal size.
** nums[i] = number of keys 'k' where 2^(i - 1) < k <= 2^i
value
insert it as an integer
yes; that's the index
traverse each slice
use specialized version
doesn't need barrier/invalidate cache, as entry was
already present in the table
all elements up to 'optimal' will go to array part
rechain to point to 'f'
adjust upper limit
correct 'next'
optimal size (till now)
elements added to 'nums' (can go to array part)
index is int?
new node will go into free position
first iteration
** main search function
'key' did not match some condition
array part must grow?
else must find a boundary in hash part
re-insert elements from hash part
array part must shrink?
normal case
** beware: when using this function you probably need to check a GC
** barrier and invalidate the TM cache.
table was built with bad purposes: resort to linear search
key not found
comment:
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
label: code-design
is colliding node out of its main position?
is 'key' an appropriate array index?
comment:
** Implementation of tables (aka arrays, objects, or hash tables).
** Tables keep its elements in two parts: an array part and a hash part.
** Non-negative integer keys are all candidates to be kept in the array
** part. The actual size of the array is the largest 'n' such that
** more than half the slots between 1 and n are in use.
** Hash uses a mix of chained scatter table with Brent's variation.
** A main invariant of these tables is that, if an element is not
** in its main position (i.e. the 'original' position that its hash gives
** to it), then the colliding element is in its own main position.
** Hence even when the load factor reaches 100%, performance remains good.
label: code-design
loop while keys can fill more than half of total size
could not find a free place
find previous
** Try to find a boundary in table 't'. A 'boundary' is an integer index
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
FALLTHROUGH
** search function for short strings
total number of elements
** returns the index of a 'key' for table traversals. First goes all
** elements in the array part, then elements in the hash part. The
** beginning of a traversal is signaled by 0.
number of elements to go to array part
use common 'dummynode'
find original element
hash part
count to traverse all array keys
reset counts
save old hash ...
optimal size for array part
free old hash
resize the table to new computed sizes
** search function for integers
all those keys are integer keys
** returns the 'main' position of an element in a table (that is, the index
** of its hash value)
colliding node is in its own main position
2^lg
key
** Maximum size of hash part is 2^MAXHBITS. MAXHBITS is the largest
** integer such that 2^MAXHBITS fits in a signed int. (Note that the
** maximum number of elements in a table, 2^MAXABITS + 2^MAXHBITS, still
** fits comfortably in an unsigned int.)
count elements in range (2^(lg - 1), 2^lg]
a non-nil value?
** "Generic" get version. (Not that generic: not valid for integers,
** which may be in array part, nor for floats with integral values.)
counter
count keys in array part
now do a binary search between them
chain new position
is 'n' inf/-inf/NaN?
** Maximum size of array part (MAXASIZE) is 2^MAXABITS. MAXABITS is
** the largest integer such that MAXASIZE fits in an unsigned int.
summation of 'nums'
** inserts a new key into a hash table; first, check whether key's main
** position is free. If not, check whether colliding node is in its main
** position or not: if it is not, move colliding node to an empty place and
** put new key in its main position; otherwise (colliding node is in its main
** position), new key goes to an empty position.
overflow?
no elements to hash part?
all positions are free
re-insert elements from vanishing slice
hash elements are numbered after array ones
** $Id: ltable.c,v 2.117 2015/11/19 19:16:22 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
now 'mp' is free
there is a boundary in the array part: (binary) search for it
more than half elements present?
** }=============================================================
that is easy...
hash part is empty?
insert key into grown table
comment: key may be dead already, but it is ok to use it in 'next'
label: code-design
** {=============================================================
** Rehash
** ==============================================================
** Hash for floating-point numbers.
** The main computation should be just
** n = frexp(n, &i); return (n * INT_MAX) + i
** but there are some numerical subtleties.
** In a two-complement representation, INT_MAX does not has an exact
** representation as a float, but INT_MIN does; because the absolute
** value of 'frexp' is smaller than 1 (unless 'n' is inf/NaN), the
** absolute value of the product 'frexp * -INT_MIN' is smaller or equal
** to INT_MAX. Next, the use of 'unsigned int' avoids overflows when
** adding 'i'; the use of '~u' (instead of '-u') avoids problems with
** INT_MIN.
(1 <= key && key <= t->sizearray)
create new hash part with appropriate size
check whether 'key' is somewhere in the chain
** Count keys in array part of table 't': Fill 'nums[i]' with
** number of keys that will go into corresponding slice and return
** total number of non-nil keys.
else...
number of elements smaller than 2^i
comment: for long strings, use generic case
label: code-design
** returns the index for 'key' if 'key' is an appropriate key to live in
** the array part of the table, 0 otherwise.
yes; move colliding node into free position
count keys in hash part
no more elements
get a free place
returns the key, given the value of a table entry
comment: 'const' to avoid wrong writings that can mess up field 'next'
label: code-design
** writable version of 'gkey'; allows updates to individual fields,
** but not to the whole (which has incompatible type)
** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
next loop: repeat --j while P < a[j]
result = t[pos]
range/4
t.n = number of elements
otherwise, nothing to move
lower interval is smaller?
read
number of elements to pack
to be used later
function
move up elements
** Choose an element in the middle (2nd-3th quarters) of [lo,up]
** "randomized" by 'rnd'
non-trivial interval?
** Use 'time' and 'clock' as sources of "randomness". Because we don't
** know the types 'clock_t' and 'time_t', we cannot cast them to
** anything without risking overflows. A safe way to use their values
** is to copy them to an array of a known type and use the array values.
arrays larger than 'RANLIMIT' may use randomized pivots
only 2 elements?
2nd argument is the position
length
call function
{
Pivot index
write
tail call for [lo .. p - 1] (lower interval)
read/write
}======================================================
t[pos] = v
a[lo .. p - 1] <= a[p] == P <= a[p + 1 .. up]
push a[up - 1]
must have metatable
where to insert new element
pop a[j]
pop result
insert new element at the end
remove a[j]
-2 to compensate function and 'a'
sort elements 'lo', 'p', and 'up'
get middle element (Pivot)
comment:
** Operations that an object must define to mimic a table
** (some functions only need some of them)
label: code-design
is it not a table?
** Copy elements (1[f], ..., 1[e]) into (tt[t], tt[t+1], ...). Whenever
** possible, copy in increasing order, which is better for rehashing.
** "possible" means destination after original range, or smaller
** than origin, or copying to another table.
try a new randomization
make sure there are two arguments
small interval or no randomize?
type for array indices
t[pos] = nil
push function
first key
is there a 2nd argument?
add last value (if interval was not empty)
tail call for [p + 1 .. up] (upper interval)
will be decremented before first use
destination table
swap a[up] - a[p]
remove a[lo]
no elements out of place?
call recursively for lower interval
assign elements
swap Pivot (a[p]) with a[up - 1]
** {======================================================
** Quicksort
** (based on 'Algorithms in MODULA-3', Robert Sedgewick;
** Addison-Wesley, 1993.)
** =======================================================
t[pos] = t[pos + 1]
push last element
** Produce a "random" 'unsigned int' to randomize pivot choice. This
** macro is used only when 'sort' detects a big imbalance in the result
** of a partition. (If you don't want/need this "randomness", ~0 is a
** good choice.)
remove a[i]
after the loop, a[j] <= P and a[j + 1 .. up] >= P
loop for tail recursion
must be a function
** {======================================================
** Pack/unpack
** =======================================================
swap a[lo] - a[up]
push Pivot
size of smaller interval
size of 'e' measured in number of 'unsigned int's
partition too imbalanced?
** Return true iff value at stack index 'a' is less than the value at
** index 'b' (according to the order of the sort).
tail call auxsort(L, lo, up, rnd)
pop metatable and tested metamethods
-1 to compensate function
** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
** QuickSort algorithm (recursive function)
next loop: repeat ++i while a[i] < P
after the loop, a[i] >= P and a[lo .. i - 1] < P
a[up] < a[p]?
return table
for larger intervals, it is worth a random pivot
only 3 elements?
a < b
already sorted
t[i] = t[i - 1]
loop invariant: a[lo .. i] <= P <= a[j .. up]
** Does the partition: Pivot P is at the top of the stack.
** precondition: a[lo] <= P == a[up-1] <= a[up],
** so it only needs to do the partition from lo + 1 to up - 2.
** Pos-condition: a[lo .. i - 1] <= a[i] == P <= a[i + 1 .. up]
** returns 'i'.
push arg[i..e - 1] (to avoid overflows)
create result table
a[up] < a[lo]?
swap a[p] - a[lo]
a[p] < a[lo]?
otherwise, swap a[i] - a[j] to restore invariant and repeat
a[lo .. i - 1] <= P <= a[j + 1 .. i .. up]
called with only 2 arguments
empty range
middle element is a good pivot
}
remove value
remove both values
number of elements to move
first empty element
** Check that 'arg' either is a table or can behave like one (that is,
** has a metatable with the required metamethods)
number of elements to pop
j < i but a[j] > P ??
a[i] < P but a[up - 1] == P ??
put it at index 1
swap pivot (a[up - 1]) with a[i] to satisfy pos-condition
return destination table
no function?
call recursively for upper interval
will be incremented before first use
get result
validate 'pos' if given
_G.unpack = table.unpack
force an error
number of elements minus 1 (avoid overflows)
try first operand
comment: call never returns, but to avoid warnings:
label: code-design
comment: calls never return, but to avoid warnings:
label: code-design
never collect these names
no metamethod
comment:
** function to be used with macro "fasttm": optimized for absence of
** tag methods
label: code-design
cache this fact
no tag method?
metamethod may yield only when called from Lua code
is '__name' a string?
** Return the name of the type of an object. For tables and userdata
** with metatable, use their '__name' metafield, if present.
use it as type name
else use standard type name
try second operand
** $Id: ltm.c,v 2.37 2016/02/26 19:20:15 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
this last case is used for tests only
push function (assume EXTRA_STACK)
2nd argument
if has result, move it to its place
no result? 'p3' is third argument
1st argument
FALLTHROUGH
ORDER TM
3rd argument
last tag method with fast access
** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
* WARNING: if you change the order of this enumeration,
* grep "ORDER TM" and "ORDER OP"
number of elements in the enum
** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
** is, whether we're running lua interactively).
number of positive indices
repeat until gets a complete statement
to be available to 'laction'
** Calls 'require(name)' and stores the result in a global variable
** with the given name.
push message handler
remove it
execute arguments -e and -l
** Read multiple lines until a complete Lua statement
** Message handler used to run all chunks
get line
no concatenated argument?
** Prints (calling the Lua 'print' function) any values on the stack
keep history
-v
script "name" is '-'
that is the message
no 'progname' on errors in interactive mode
bad option
{
** $Id: lua.c,v 1.226 2015/08/14 19:11:20 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
mark in error messages for incomplete statements
change '=' to 'return'
remove prompt
try alternative name
check that interpreter has correct version
create table 'arg'
reset hook
original line
'--'
remove table from the stack
already checked
** Create the 'arg' table, which stores all arguments from the
** command line ('argv'). It should be aligned so that, at index 0,
** it has 'argv[script]', which is the script name. The arguments
** to the script (everything after 'script') go to positive indices;
** other arguments (before the script name) go to negative indices.
** If there is no script name, assume interpreter's name as base.
that produces a string?
-i option?
stop handling options
get what it has
}{
create state
'-'
line ends with newline?
if another SIGINT happens, terminate process
reset C-signal handler
-E
** Check whether 'status' is not OK and, if so, prints the error
** message on the top of the stack. It assumes that the error object
** is a string, as it was either generated by Lua or by 'msghandler'.
-e
non empty?
else check option
** Read a line and try to load (compile) it first as an expression (by
** adding "return " in front of it) and second as a statement. Return
** the final status of load/call with the resulting function (if any)
** in the top of the stack.
assume stdin is a tty
** Prints an error message, adding the program name in front of it
** (if present)
set C-signal handler
comment: bits of various argument indicators in 'args'
label: code-design
remove message
add newline...
remove modified line
FALLTHROUGH
does it have a metamethod
no script name
show prompt
not an option?
extra characters after '--'?
no next argument or it is another option
** Push on the stack the contents of table 'arg' from 1 to #arg
(-i implies -v)
executes stdin as a file
no input (prompt will be popped by caller)
** Try to compile line on the stack as 'return <line>;'; on return, stack
** has either compiled chunk or original line (if compilation failed).
try it
function index
** Check whether 'status' signals a syntax error and the error
** message at the top of the stack ends with the above mark for
** incomplete statements.
pop result from 'luaL_loadbuffer' and modified line
error running LUA_INIT
bad arg?
** Interface to 'lua_pcall', which sets appropriate message function
** and C-signal handler. Used to run all chunks.
join them
remove line from the stack
remove message handler from the stack
return the traceback
no script name?
** lua_readline defines how to show a prompt and then read a line from
** the standard input.
** lua_saveline defines how to "save" a read line in a "history".
** lua_freeline defines how to free a line read by lua_readline.
execute main script (if there is one)
running in interactive mode?
cannot or should not try to add continuation line
comment:
** Traverses all arguments from 'argv', returning a mask with those
** needed before running any Lua code (or an error code if it finds
** any invalid argument). 'first' returns the first not-handled argument
** (either the script name or a bad argument in case of error).
label: code-design
signal no errors
comment: 'script' has index of bad arg.
label: code-design
do read-eval-print loop
option '-v'?
** Processes options 'e' and 'l', which involve running Lua code.
** Returns 0 if some code raises an error.
** Hook set by signal function to stop the interpreter.
option '-E'?
** Returns the string to be used as a prompt by the interpreter.
...between the two lines
** Do the REPL: repeatedly read (load) a line, evaluate (call) it, and
** print any results.
comment: unused arg.
label: code-design
signal for libraries to ignore env. vars.
'return ...' did not work?
stdin
push arguments to script
** Main body of stand-alone interpreter (to be called in protected mode).
** Reads the options and handles them all.
run LUA_INIT
any result to be printed?
no option '-E'?
invalid option
** Prompt the user, read a line, and push it into the Lua stack.
** Function to be called at a C signal. Because a C signal cannot
** just change a Lua state (as there is no proper synchronization),
** this function only sets a hook that, when called, will stop the
** interpreter.
something failed
}
both options need an argument
to call 'pmain' in protected mode
is error object not a string?
-i
call 'require(name)'
try next 'argv'
do the call
for compatibility with 5.2, ...
ISO C definition
append a standard traceback
no arguments?
put it under function and args
else...
clear stack
2nd argument
extra characters after 1st?
global[name] = require return
get result
try as command, maybe with continuation lines
1st argument
no input
open standard libraries
(t)
minimum Lua stack available to a C function
** basic types
** push functions (C -> stack)
(u) number of parameters
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
Functions to be called by the debugger in specific events
mark for precompiled code ('<esc>Lua')
unsigned integer type
** Type for C functions registered with Lua
** access functions (stack -> C)
** garbage-collection function and options
*****************************************************************************
* Copyright (C) 1994-2016 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************
(S)
** $Id: lua.h,v 1.331 2016/05/30 15:53:28 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
** set functions (stack -> Lua)
(l)
** state manipulation
** Type for memory-allocation functions
predefined values in the registry
** {==============================================================
** compatibility macros for unsigned conversions
** ===============================================================
active function
(n) 'global', 'local', 'field', 'method'
** Type for continuation functions
type for continuation-function contexts
** Event codes
private part
** {======================================================================
** Debug API
** =======================================================================
type of numbers in Lua
type for integer functions
(u)
** get functions (Lua -> stack)
(u) number of upvalues
** {==============================================================
** some useful macros
** ===============================================================
}==============================================================
** Type for functions that read/write blocks when loading/dumping Lua chunks
** 'load' and 'call' functions (load and run Lua code)
option for multiple returns in 'lua_pcall' and 'lua_call'
** coroutine functions
comment:
** generic extra include file
label: code-design
** Comparison and arithmetic functions
** Event masks
}======================================================================
** miscellaneous functions
** basic stack manipulation
(n)
activation record
(S) 'Lua', 'C', 'main', 'tail'
thread status
** RCS ident string
ORDER TM, ORDER OP
lua.hpp
Lua header files for C++
<<extern "C">> not supplied automatically because Lua also compiles as C++
show version
** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
** Lua compiler (saves bytecodes to files; also lists bytecodes)
** See Copyright Notice in lua.h
end of options; use stdin
list bytecodes?
cannot happen
default program name
** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
end of options; skip it
default output file
unknown option
actual program name
default output file name
strip debug information?
end of options; keep it
list
actual output file name
output file
parse only
strip debug information
dump bytecodes?
#define LUA_COMPAT_FLOATSTRING
** {==================================================================
** Configuration for Numbers.
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
}==================================================================
}{ long double
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
no variant
MacOS does not need -ldl
{
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
===================================================================
@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
** ===================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
** that are not to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
** largest types available for C89 ('long' and 'double')
** {==================================================================
** Compatibility with previous versions
** ===================================================================
otherwise use 'long'
comment: needs an extra library: -ldl
label: code-design
}{ double
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
avoid undefined shifts
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
#define LUA_NOCVTS2N
}{
use presence of macro LLONG_MAX as proxy for C99 compliance
use ISO C99 stuff
}{ long long
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance compiling it with 32-bit numbers or
** restricting it to C89.
** =====================================================================
** $Id: luaconf.h,v 1.255 2016/05/01 20:06:09 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
Incompatibilities from 5.2 -> 5.3
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
#define LUA_USE_C89
more often than not the libs go together with the core
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include header 'locale.h'.)
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
now the variable definitions
@@ LUA_INTEGER is the integer type used by Lua.
**
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
**
@@ LUAI_UACINT is the result of an 'usual argument conversion'
@@ over a lUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ lua_integer2str converts an integer to a string.
predefined options for LUA_FLOAT_TYPE
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
variants not available
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
comment:
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
label: documentation
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
@@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@@ over a floating number.
@@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeric string to a number.
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
** default configuration for 64-bit Lua ('long long' and 'double')
@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
enable support for DLL
enable goodies for regular Windows
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
{ int
** 32-bit integers and 'float'
#define LUA_32BITS
in Windows, can use specific Windows types
comment: needs an extra library: -lreadline
label: code-design
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
even in C99 this type is optional
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
The following definitions are good for most cases here
@@ LUA_QL describes how error messages quote program elements.
** Lua does not use these macros anymore; they are here for
** compatibility only.
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.
@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
** You can define it to get all options, or change specific options
** to fit your specific needs.
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options (if supported
** by your C compiler). The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
}
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
use 'int' if big enough
** {==================================================================
** Configuration for Paths.
** ===================================================================
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua). You probably do not want/need to change them.
** =====================================================================
predefined options for LUA_INT_TYPE
@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
'int' always must have at least 16 bits
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
}{ long
#define LUA_NOCVTN2S
{ single float
comment: needs some extra libraries
label: code-design
** By default, Lua on Windows use (some) specific Windows features
comment:
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
label: code-design
empty
** {==================================================================
** Language Variations
** =====================================================================
@@ lua_numbertointeger converts a float number to an integer, or
** returns 0 if float is not within the range of a lua_Integer.
** (The range comparisons are tricky because of rounding. The tests
** here assume a two-complement representation, where MININTEGER always
** has an exact representation as a float; MAXINTEGER may not have one,
** and therefore its conversion to float may have an ill-defined value.)
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
** can also define LUA_32BITS in the make file, but changing here you
** ensure that all software connected to Lua will be compiled with the
** same configuration.
broadly, Windows is C89
comment:
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space. (For long double,
** 'string.format("%.99f", 1e4932)' needs ~5030 bytes, so a
** smaller buffer would force a memory allocation for each call to
** 'string.format'.)
label: code-design
open all previous libraries
** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
reuse parent's source
1st char already checked
** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
empty
** All high-level loads go through LoadVector; you can change it to
** adapt to the endianness of the input
long string
** load precompiled chunk
short string?
load directly in final place
no source in dump?
larger than both
dump one chunk; from ldump.c
** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
data to catch conversion errors
load one chunk; from lundump.c
this is the official format
... and current position
return nil ...
do not move for 1st character
no such character
read next byte
final result
** utf8len(s [, i [, j]]) --> number of characters that start in the
** range [i,j], or nil + current position if 's' is not well formed in
** that interval
find beginning of next character
start from here
no more codepoints
translate a relative string position: negative means back from end
ascii?
** utfchar(n1, n2, ...) -> char(n1)..char(n2)...
to count number of continuation bytes
did it find given character?
add first byte
from strlib
to test next bit
+1 to include first byte
not a continuation byte?
empty interval; return no values
skip continuation bytes read
** $Id: lutf8lib.c,v 1.15 2015/03/28 19:16:55 roberto Exp $
** Standard library for UTF-8 manipulation
** See Copyright Notice in lua.h
(cannot pass final '\0')
number of arguments
pattern to match a single UTF-8 character
invalid byte sequence
placeholders
** offset(s, n, [i]) -> index where n-th character counting from
** position 'i' starts; 0 means character at 'i'.
find beginning of previous character
first iteration?
(lua_Integer -> int) overflow?
add lower 6 bits from cont. byte
** codepoint(s, [i, [j]]) -> returns codepoints for all characters
** that start in the range [i,j]
and its continuations
conversion error?
move back
find beginning of current byte sequence
still have continuation bytes?
** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.
optimize common case of single char
skip current byte
restore top
save 't' table
try 'le'
true must be 1 !!
remove new frame
'rs' is finished?
not (r < l) ?
clear mark
cache will not break GC invariant?
get metamethod
restart luaV_execute over new Lua function
comment: 'ls' is smaller than 'rs' ('rs' is not finished)
label: requirement
update internal index...
all values are integer
result is nil
floating loop
}==================================================================
** create a new Lua closure, push it in the stack, and initialize
** its upvalues. Note that the closure is not cached if prototype is
** already black (which means that 'cache' was already cleared by the
** GC).
call TM
long string; copy strings directly to final result
not an integral value?
** Main operation for concatenation: concat 'total' values in the stack,
** from 'L->top - total' up to 'L->top - 1'.
** $Id: lvm.c,v 2.268 2016/02/05 19:59:14 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
** finish execution of an opcode interrupted by an yield
** Try to convert a 'for' limit to an integer, preserving the
** semantics of the loop.
** (The following explanation assumes a non-negative step; it is valid
** for negative steps mutatis mutandis.)
** If the limit can be converted to an integer, rounding down, that is
** it.
** Otherwise, check whether the limit can be converted to a number. If
** the number is too large, it is OK to set the limit as LUA_MAXINTEGER,
** which means no limit. If the number is too negative, the loop
** should not run, because any initial integer value is larger than the
** limit. So, it sets the limit to LUA_MININTEGER. 'stopnow' corrects
** the extreme case when the initial value is LUA_MININTEGER, in which
** case the LUA_MININTEGER limit would still run the loop once.
will try TM
repeat until only 1 result left
** Integer division; return 'm // n', that is, floor(m/n).
** C division truncates its result (rounds towards zero).
** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,
** otherwise 'floor(q) == trunc(q) - 1'.
complete required results with nil
last stack slot filled by 'precall'
key must be a string
anchor new closure in stack
'l' is int and 'r' is float
number of bits in an integer
set its new value
else primitive len
increment index
else loop
fast track?
'__newindex' metamethod
create one
both are float
copy strings in stack from top - n up to top - 1 to buffer
metamethod? break switch to call it
local copy of function's base
number of bits in the mantissa of a float
-minint == maxint + 1
** Main operation 'ra' = #rb'.
length of string being copied
invocation via reentry: continue execution
** Check whether integer 'i' is less than float 'f'. If 'i' has an
** exact representation as a float ('l_intfitsf'), compare numbers as
** floats. Otherwise, if 'f' is outside the range for integers, result
** is trivial. Otherwise, compare them as integers. (When 'i' has no
** float representation, either 'f' is "far away" from 'i' or 'f' has
** no precision left for a fractional part; either way, how 'f' is
** truncated is irrelevant.) When 'f' is NaN, comparisons must result
** in false.
'l' must be float
no previous entry?
't' is a table
without NaN, (l <= r) <--> not(r < l)
convert result from 'luaO_str2num' to an integer
top when 'luaT_trybinTM' was called
first element to concatenate
try making all values floats
preallocate it at once
'm/n' would be negative non-integer?
not fit in integer?
first operand is an empty string?
float is smaller than min integer
** Try to convert a value to a float. The float case is already handled
** by the macro 'tonumber'.
cached closure
** Finish the table access 'val = t[key]'.
** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
** t[k] entry (which must be nil).
correct result for different rounding
** Check whether some integers may not fit in a float, that is, whether
** (maxinteger >> NBM) > 0 (that implies (1 << NBM) <= maxinteger).
** (The shifts are done in parts to avoid shifting by more than the size
** of an integer. In a worst case, NBM == 113 for long double and
** sizeof(integer) == 32.)
else will try the metamethod
** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-
** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.
** The code is a little tricky because it allows '\0' in the strings
** and it uses 'strcoll' (to respect locales) for each segments
** of the strings.
comment:
** check whether cached closure in prototype 'p' may be reused, that is,
** whether there is a cached closure with the same upvalues needed by
** new closure to be created.
label: code-design
perform C division
conversion failed
no metamethod
is there a cached closure?
second operand is empty?
fill in its upvalues
correct top (in case of previous open call)
no vararg arguments
** 'l_intfitsf' checks whether a given integer can be converted to a
** float without rounding. Used in comparisons. Left undefined if
** all integers fit in a float precisely.
't' is not a table?
close all upvalues from previous call
check 'ls'
reentry point when frame changes (call/return)
top is one after last element (at top-2)
** Main operation for equality of Lua values; return 't1 == t2'.
** L == NULL means raw equality (no metamethods)
values have same type and same variant
not a number
adjust results
comment: counter to avoid infinite loops
label: code-design
result is first operand
** some macros for common tasks in 'luaV_execute'
called frame
comment: needs more space?
label: code-design
local reference to function's closure
float division (always with floats)
both strings longer than 'len'; go on comparing after the '\0'
continue loop?
are there elements to concat?
Lua function
'r' is int and 'l' is float
try the metamethod
limit for table tag-method chains (to avoid loops)
** Main operation less than; return 'l < r'.
index of first '\0' in both strings
popped 'n' strings and pushed one
no match?
upvalue refers to local variable?
minint <= f <= maxint ?
f <= minint <= i (or 'f' is NaN) --> not(i < f)
correct top
mark the end of concat operands
cannot convert to float?
push cashed closure
comment: wrong upvalue; cannot reuse closure
label: code-design
without NaN, (l < r) <--> not(r <= l)
is metamethod a function?
negate result
next assignment may change this value
** Return 'l <= r', for numbers.
no metamethod and (now) there is an entry with given key
NaN <= i is always false
needs ceil?
two numbers with different variants
is result a short string?
nresults >= 0?
move new frame into old one
** Integer modulus; return 'm % n'. (Assume that C '%' with
** negative operands follows C99 behavior. See previous comment
** about luaV_div.)
** try to convert a value to an integer, rounding according to 'mode':
** mode == 0: accepts only integral values
** mode == 1: takes the floor of the number
** mode == 2: takes the ceil of the number
** Check whether integer 'i' is less than or equal to float 'f'.
** See comments on previous function.
function was tail called
func. + 2 args (state and index)
local 'ci' still from callee
create a new one
** Shift left operation. (Shift right just negates 'y'.)
jump back
convert result of 'luaO_str2num' to a float
if true, float is larger than max integer
caller frame
integer loop?
inc. index
n==-1; avoid overflow with 0x80000...//-1
convert floor to ceil (remember: n != f)
for test instructions, execute the jump instruction that follows it
WARNING: any stack reallocation invalidates 'ra'
compare them as floats
not (r <= l) ?
...and external index
is 't' a table?
comment: less arguments than parameters?
label: code-design
string convertible to number?
B == 0?
try metamethod
comment: macro used by 'luaV_concat' to ensure that element at 'o' is a string
label: code-design
new closure is white, so we do not need a barrier here
both are strings?
not equal?
both operands are numbers?
fails if mode demands integral value
copy strings to buffer
table's metamethod
minint < f <= maxint ?
f >= maxint + 1 > i
'm/n' would be non-integer negative?
both are integers
put TM result in proper position
done
not the same variant?
no TM?
local reference to function's constant table
call base
try 'lt':
go to next instruction
finish its execution
call it
result is negated
size already copied
result is second op.
get all var. arguments
at least two non-empty string values; get as many as possible
error
tail call: put called frame (n) in place of caller one (o)
else repeat (tail call 'luaV_finishget')
concat them (may yield again)
special cases: -1 or 0
** Return 'l < r', for numbers.
skip next instruction (if C)
shift right?
called function
not a table; check metamethod
metamethod
mark it is doing 'lt' for 'le'
else try to access 'tm[key]'
execute a jump instruction
yet to concatenate
NaN < i is always false
objects are different
"<=" using "<" instead?
else repeat assignment over 'tm'
save control variable
no metamethod?
required results
got 'n' strings to create 1 new
fetch an instruction and prepare its execution
main loop of interpreter
update 'base'
caller function
for each segment
shift left
check whether it has right upvalues
'luaV_concat' may invoke TMs and move the stack
try to convert to float
interrupted instruction
strings are equal up to a '\0'
C function?
m % -1 == 0; avoid overflow with 0x80000...%-1
correct base
get upvalue from enclosing function
collect total length and number of strings
return cached closure (or NULL if no cached closure)
save it on cache for reuse
skip jump instruction
limit of live values
fresh invocation of 'luaV_execute"
usually, let loops run
'ls' is finished?
same for 'luaV_settable'
f < minint <= i (or 'f' is NaN) --> not(i <= f)
else previous instruction set top
** Finish a table assignment 't[key] = val'.
** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points
** to the entry 't[key]', or to 'luaO_nilobject' if there is no such
** entry. (The value at 'slot' must be nil, otherwise 'luaV_fastset'
** would have done the job.)
compare them as integers
condition failed?
l < r ?
l <= r ?
** copy of 'luaV_gettable', but protecting the call to potential
** metamethod (which can reallocate the stack)
** {==================================================================
** Function 'luaV_execute': main interpreter loop
** ===================================================================
external invocation: return
number of elements handled in this pass (at least 2)
old value must be nil
previous call may change the stack
create result
only numbers can be equal with different variants
** Main operation less than or equal to; return 'l <= r'. If it needs
** a metamethod and there is no '__le', try '__lt', based on
** l <= r iff !(r < l) (assuming a total order). If the metamethod
** yields during this substitution, the continuation has to know
** about it (to negate the result of r<l); bit CIST_LEQ in the call
** status keeps that information.
floor division
move final result to final position
** fast track for 'gettable': if 't' is a table and 't[k]' is not nil,
** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise,
** return 0 (meaning it will have to check metamethod) with 'slot'
** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise).
** 'f' is the raw get function to use.
** You can define LUA_FLOORN2I if you want to convert floats to integers
** by flooring them (instead of raising an error if they are not
** integral values)
no conversion from numbers to strings
not a table; 'slot' is NULL and result is 0
** $Id: lvm.h,v 2.40 2016/01/05 16:07:21 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
** Fast track for set table. If 't' is a table and 't[k]' is not nil,
** call GC barrier, do a raw 't[k]=v', and return true; otherwise,
** return false with 'slot' equal to NULL (if 't' is not a table) or
** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro
** returns true, there is no need to 'invalidateTMcache', because the
** call is not creating a new entry.
** standard implementation for 'gettable'
else, do raw access
result not nil?
no conversion from strings to numbers
try to read more
no bytes in buffer?
discount char being returned
luaZ_fill consumed first byte; put it back
no more input; return number of missing bytes
min. between n and z->n
--------------------------------------------------------------- read ---
** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
end of stream
current position in buffer
Lua state (for reader)
** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
--------- Private Part ------------------
reader function
additional data
bytes still unread
read next n bytes
Append the N-byte string in zIn to the end of the JsonString string
** under construction. Enclose the string in "..." and escape
** any double-quotes or backslash characters contained within the
** string.
** A NameContext defines a context in which to resolve table and column
** names. The context consists of a list of tables (the pSrcList) field and
** a list of named expression (pEList). The named expression list may
** be NULL. The pSrc corresponds to the FROM clause of a SELECT or
** to the table being operated on by INSERT, UPDATE, or DELETE. The
** pEList corresponds to the result set of a SELECT and is NULL for
** other statements.
**
** NameContexts can be nested. When resolving names, the inner-most
** context is searched first. If no match is found, the next outer
** context is checked. If there is still no match, the next context
** is checked. This process continues until either a match is found
** or all contexts are check. When a match is found, the nRef member of
** the context containing the match is incremented.
**
** Each subquery gets a new NameContext. The pNext field points to the
** NameContext in the parent query. Thus the process of scanning the
** NameContext list corresponds to searching through successively outer
** subqueries looking for a match.
The new root-page may not be allocated on a pointer-map page, or the
** PENDING_BYTE page.
** Search the node hash table for node iNode. If found, return a pointer
** to it. Otherwise, return 0.
** This routine is called after a single SQL statement has been
** parsed and a VDBE program to execute that statement has been
** prepared. This routine puts the finishing touches on the
** VDBE program and resets the pParse structure for the next
** parse.
**
** Note that if an error occurred, it might be the case that
** no VDBE code was generated.
Collating sequence must be the same on all columns
PRAGMA cache_spill=ON
Size of array apSegment
** The following are copied from sqliteInt.h.
**
** Constants for the largest and smallest possible 64-bit signed integers.
** These macros are designed to work correctly on both 32-bit and 64-bit
** compilers.
Next method for this node.
** This function is a no-op if the pager is in exclusive mode and not
** in the ERROR state. Otherwise, it switches the pager to PAGER_OPEN
** state.
**
** If the pager is not in exclusive-access mode, the database file is
** completely unlocked. If the file is unlocked and the file-system does
** not exhibit the UNDELETABLE_WHEN_OPEN property, the journal file is
** closed (if it is open).
**
** If the pager is in ERROR state when this function is called, the
** contents of the pager cache are discarded before switching back to
** the OPEN state. Regardless of whether the pager is in exclusive-mode
** or not, any journal file left in the file-system will be treated
** as a hot-journal and rolled back the next time a read-transaction
** is opened (by this or by any other connection).
If there were FTS5_MIN_DLIDX_SIZE or more empty leaf pages written
** to the database, also write the doclist-index to disk.
** The winMemData structure stores information required by the Win32-specific
** sqlite3_mem_methods implementation.
comment: Database connection for reporting malloc problems
label: code-design
Construct the in-memory representation schema tables (sqlite_master or
** sqlite_temp_master) by invoking the parser directly. The appropriate
** table name will be inserted automatically by the parser so we can just
** use the abbreviation "x" here. The parser will also automatically tag
** the schema table as read-only.
** Advance to the next WhereTerm that matches according to the criteria
** established when the pScan object was initialized by whereScanInit().
** Return NULL if there are no more matching WhereTerms.
eMode is always INCRINIT_NORMAL in single-threaded mode
Bitmask of all indexable tables in the clause
Contains aggregate functions
OUT: Set for new term
comment:
** Each entry in a RowSet is an instance of the following object.
**
** This same object is reused to store a linked list of trees of RowSetEntry
** objects. In that alternative use, pRight points to the next entry
** in the list, pLeft points to the tree, and v is unused. The
** RowSet.pForest value points to the head of this forest list.
label: code-design
If the either the page-size or sector-size in the journal-header is
** invalid, then the process that wrote the journal-header must have
** crashed before the header was synced. In this case stop reading
** the journal file here.
Source-code line that generated this opcode
Invoke the virtual table constructor
** An instance of the TreeView object is used for printing the content of
** data structures on sqlite3DebugPrintf() using a tree-like view.
** Internal function prototypes
** This #if does not rely on the SQLITE_OS_WINCE define because the
** corresponding section in "date.c" cannot use it.
95
************* End of stmt.c ***********************************************
** This routine is a helper for explainIndexRange() below
**
** pStr holds the text of an expression that we are building up one term
** at a time. This routine adds a new term to the end of the expression.
** Terms are separated by AND so add the "AND" text for second and subsequent
** terms only.
Name of the database. Might be NULL
INTERSECT is different from the others since it requires
** two temporary tables. Hence it has its own case. Begin
** by allocating the tables we will need.
comment: Opcode: Insert P1 P2 P3 P4 P5
** Synopsis: intkey=r[P3] data=r[P2]
**
** Write an entry into the table of cursor P1. A new entry is
** created if it doesn't already exist or the data for an existing
** entry is overwritten. The data is the value MEM_Blob stored in register
** number P2. The key is stored in register P3. The key must
** be a MEM_Int.
**
** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
** then rowid is stored for subsequent return by the
** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
**
** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
** run faster by avoiding an unnecessary seek on cursor P1. However,
** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
** seeks on the cursor or if the most recent seek used a key equal to P3.
**
** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
** UPDATE operation. Otherwise (if the flag is clear) then this opcode
** is part of an INSERT operation. The difference is only important to
** the update hook.
**
** Parameter P4 may point to a Table structure, or may be NULL. If it is
** not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked
** following a successful insert.
**
** (WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically
** allocated, then ownership of P2 is transferred to the pseudo-cursor
** and register P2 becomes ephemeral. If the cursor is changed, the
** value of register P2 will then change. Make sure this does not
** cause any problems.)
**
** This instruction only works on tables. The equivalent instruction
** for indices is OP_IdxInsert.
label: code-design
Incremented when %_config is modified
** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
** is really just a macro that uses a compiler intrinsic (e.g. x64).
** So do not try to make this is into a redefinable interface.
Prefix parameter value (or NULL)
** Free all memory associated with the Vdbe passed as the second argument,
** except for object itself, which is preserved.
**
** The difference between this function and sqlite3VdbeDelete() is that
** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
** the database connection and frees the object itself.
Array of PmaReaders to merge data from
Block id for new block
Definitions of all built-in pragmas
comment:
** CAPI3REF: Name Of The Folder Holding Temporary Files
**
** ^(If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite when using a built-in [sqlite3_vfs | VFS]
** will be placed in that directory.)^ ^If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** Applications are strongly discouraged from using this global variable.
** It is required to set a temporary folder on Windows Runtime (WinRT).
** But for all other platforms, it is highly recommended that applications
** neither read nor write this variable. This global variable is a relic
** that exists for backwards compatibility of legacy applications and should
** be avoided in new projects.
**
** It is not safe to read or modify this variable in more than one
** thread at a time. It is not safe to read or modify this variable
** if a [database connection] is being used at the same time in a separate
** thread.
** It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been called and that this variable remain unchanged
** thereafter.
**
** ^The [temp_store_directory pragma] may modify this variable and cause
** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
** the [temp_store_directory pragma] always assumes that any string
** that this variable points to is held in memory obtained from
** [sqlite3_malloc] and the pragma may attempt to free that memory
** using [sqlite3_free].
** Hence, if this variable is modified directly, either it should be
** made NULL or made to point to memory obtained from [sqlite3_malloc]
** or else the use of the [temp_store_directory pragma] should be avoided.
** Except when requested by the [temp_store_directory pragma], SQLite
** does not free the memory that sqlite3_temp_directory points to. If
** the application wants that memory to be freed, it must do
** so itself, taking care to only do so after all [database connection]
** objects have been destroyed.
**
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
** features that require the use of temporary files may fail. Here is an
** example of how to do this using C++ with the Windows Runtime:
**
** <blockquote><pre>
** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
** TemporaryFolder->Path->Data();
** char zPathBuf[MAX_PATH + 1];
** memset(zPathBuf, 0, sizeof(zPathBuf));
** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
** NULL, NULL);
** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
** </pre></blockquote>
label: code-design
Optional list of view column names
** The code in this file is only used if we are compiling multithreaded
** on a Win32 system.
** This method is the destructor for stmt_cursor objects.
1430
synopsis: intkey=r[P3] data=r[P2]
** Locate the in-memory structure that describes a particular database
** table given the name of that table and (optionally) the name of the
** database containing the table. Return NULL if not found. Also leave an
** error message in pParse->zErrMsg.
**
** The difference between this routine and sqlite3FindTable() is that this
** routine leaves an error message in pParse->zErrMsg where
** sqlite3FindTable() does not.
Table used for PK definition
True if the VM needs to be recompiled
Heap storage space
IN/OUT: Pointer to output buffer
** Invalidate the overflow page-list cache for all cursors opened
** on the shared btree structure pBt.
comment:
** Make a copy of a string in memory obtained from sqliteMalloc(). These
** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
** is because when memory debugging is turned on, these two functions are
** called via macros that record the current file and line number in the
** ThreadData structure.
label: code-design
Mode to pass to walCheckpoint()
************* Begin file fts3_tokenizer1.c ********************************
One of the JSON_ type values
For ONEPASS, no need to store the rowid/primary-key. There is only
** one, so just keep it in its register(s) and fall through to the
** delete code.
The target name
Not part of an OR optimization
comment: Finally, jump back to the beginning of the executable code.
label: code-design
** Target size for allocation chunks.
Index sort order
SYNC_NORMAL or SYNC_FULL otherwise
** Translate a single byte of Hex into an integer.
** This routine only works if h really is a valid hexadecimal
** character: 0..9a..fA..F
String or BLOB exceeds size limit
Disable the API redefinition in sqlite3ext.h
Convert the filename to the system encoding.
251
If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
** do not attempt any conversions before assembling the record.
** If this is a real table, attempt conversions as required by the
** table column affinities.
Variable initialization
(305) as ::= ID|STRING
Move the cursor to the first entry in the table. Return SQLITE_OK
** on success. Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty.
case_operand ::= expr
READONLY
Index of new first cell on page
Original value of iSize
Mask of query phrases covered
Get the field width
Number of free bytes on the page
Write the index of a new slot here
True for a read-only page
Opcode: Next P1 P2 P3 P4 P5
**
** Advance cursor P1 so that it points to the next key/data pair in its
** table or index. If there are no more key/value pairs then fall through
** to the following instruction. But if the cursor advance was successful,
** jump immediately to P2.
**
** The Next opcode is only valid following an SeekGT, SeekGE, or
** OP_Rewind opcode used to position the cursor. Next is not allowed
** to follow SeekLT, SeekLE, or OP_Last.
**
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
** been opened prior to this opcode or the program will segfault.
**
** The P3 value is a hint to the btree implementation. If P3==1, that
** means P1 is an SQL index and that this instruction could have been
** omitted if that index had been unique. P3 is usually 0. P3 is
** always either 0 or 1.
**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreeNext().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
**
** See also: Prev, NextIfOpen
Return code from subfunctions
** Return true if the heap is currently under memory pressure - in other
** words if the amount of heap used is close to the limit set by
** sqlite3_soft_heap_limit().
252
Number of opcodes for progress callback
Report errors here, if not NULL
Btree to change journal mode of
Number of elements summed
************* End of parse.h **********************************************
Allocate space for the conch filename and initialize the name to
** the name of the original database file.
pVbeBranchArg
The text encoding used by this database
Table to be opened
Sector size doesn't matter for temporary files. Also, the file
** may not have been opened yet, in which case the OsSectorSize()
** call will segfault.
Verify that the page list is in accending order
comment: Figure out where the doclist for this term ends
label: code-design
Compare pReadr1 and pReadr2. Store the result in variable iRes.
If eStatementOp is non-zero, then a statement transaction needs to
** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
** do so. If this operation returns an error, and the current statement
** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
** current statement error code.
** Added for 3.4.1
** A RowSet in an instance of the following structure.
**
** A typedef of this structure if found in sqliteInt.h.
Reclaim memory used by a Stat4Sample
INTO
Keep advancing iterators until they all point to the same document
comment: Temporary memory used by this routine
label: code-design
Result set of the query
comment: If the db-size header field is incorrect (as it may be if an old
** client has been writing the database file), update it now. Doing
** this sooner rather than later means the database size can safely
** re-read the database size from page 1 if a savepoint or transaction
** rollback occurs within the transaction.
label: code-design
nCellKey will always be between 0 and 0xffffffff because of the way
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented
#include "whereInt.h"
** Cause a function to throw an error if it was call from OP_PureFunc
** rather than OP_Function.
**
** OP_PureFunc means that the function must be deterministic, and should
** throw an error if it is given inputs that would make it non-deterministic.
** This routine is invoked by date/time functions that use non-deterministic
** features such as 'now'.
Find the checksum values to use as input for the recalculating the
** first checksum. If the first frame is frame 1 (implying that the current
** transaction restarted the wal file), these values must be read from the
** wal-file header. Otherwise, read them from the frame header of the
** previous frame.
If this is the first entry to be added to this hash-table, zero the
** entire hash table and aPgno[] array before proceeding.
shared memory and mmap are enabled
The where clause
** The xSavepoint() method.
**
** Flush the contents of the pending-terms table to disk.
Flags for sub-WHERE clause
RHS of the comparison
True if RTree holding integer coordinates
OUT: Byte offset of token in input buffer
** Values passed as the 5th argument to allocateBtreePage()
Offset in aData[] of next change
** This is called as part of registering the FTS5 module with database
** connection db. It registers several user-defined scalar functions useful
** with FTS5.
**
** If successful, SQLITE_OK is returned. If an error occurs, some other
** SQLite error code is returned instead.
Try to keep nFreeSlot above this
Freeblock off the end of the page
# include "os_win.h"
Special case: A DELETE without a WHERE clause deletes everything.
** It is easier just to erase the whole table. Prior to version 3.6.5,
** this optimization caused the row change count (the value returned by
** API function sqlite3_count_changes) to be set incorrectly.
**
** The "rcauth==SQLITE_OK" terms is the
** IMPLEMENTATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
** the truncate optimization is disabled and all rows are deleted
** individually.
** An SQL user-function registered to do the work of an DETACH statement. The
** three arguments to the function come directly from a detach statement:
**
** DETACH DATABASE x
**
** SELECT sqlite_detach(x)
First of nPk cells holding PRIMARY KEY value
** Handle the special case of a compound-select that originates from a
** VALUES clause. By handling this as a special case, we avoid deep
** recursion, and thus do not need to enforce the SQLITE_LIMIT_COMPOUND_SELECT
** on a VALUES clause.
**
** Because the Select object originates from a VALUES clause:
** (1) It has no LIMIT or OFFSET
** (2) All terms are UNION ALL
** (3) There is no ORDER BY clause
child to parent column mapping
************* Continuing where we left off in pager.c *********************
** Argument ppHead contains a pointer to the current head of a query
** expression tree being parsed. pPrev is the expression node most recently
** inserted into the tree. This function adds pNew, which is always a binary
** operator node, into the expression tree based on the relative precedence
** of pNew and the existing nodes of the tree. This may result in the head
** of the tree changing, in which case *ppHead is set to the new root node.
135
The set of notindexed= columns
Number of elements in list aMerge
Indexed column is an expression
Make pRoot, the root page of the b-tree, writable. Allocate a new
** page that will become the new right-child of pPage. Copy the contents
** of the node stored on pRoot into the new child page.
same as TK_NE, synopsis: IF r[P3]!=r[P1]
Argument to parse
True if %_docsize table exists
Methods for the module
Row is being deleted from this table
Used by this thread only
Space for azColumn strings
If this condition is true then the largest rowid for the current
** term may not be stored on the current page. So search forward to
** see where said rowid really is.
** Prepare the two insert statements - Fts5Storage.pInsertContent and
** Fts5Storage.pInsertDocsize - if they have not already been prepared.
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
Total pages involved in the balance
76
varint containing suffix size
Bit values for PgHdr.flags
comment:
** CAPI3REF: Loadable Extension Thunk
**
** A pointer to the opaque sqlite3_api_routines structure is passed as
** the third parameter to entry points of [loadable extensions]. This
** structure must be typedefed in order to work around compiler warnings
** on some platforms.
label: code-design
** Function prototypes
Opcode: SeekGT P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as a key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the smallest entry that
** is greater than the key value. If there are no records greater than
** the key and P2 is not zero, then jump to P2.
**
** This opcode leaves the cursor configured to move in forward order,
** from the beginning toward the end. In other words, the cursor is
** configured to use Next, not Prev.
**
** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
Schema required - "main" is default
** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
For looping over bytes of pCell
SQLITE_STATUS_PAGECACHE_SIZE
Linked list of VDBEs with the same Vdbe.db
Size of zRep
isCommit flag passed to sqlite3PagerMovepage
First in array of registers
Position of next token
FOR
comment: If the Select object is really just a simple VALUES() list with a
** single row (the common case) then keep that one row of values
** and discard the other (unused) parts of the pSelect object
label: code-design
Most jump operations do a goto to this spot in order to update
** the pOp pointer.
If changing the rowid value, or if there are foreign key constraints
** to process, delete the old record. Otherwise, add a noop OP_Delete
** to invoke the pre-update hook.
**
** That (regNew==regnewRowid+1) is true is also important for the
** pre-update hook. If the caller invokes preupdate_new(), the returned
** value is copied from memory cell (regNewRowid+1+iCol), where iCol
** is the column index supplied by the user.
** iAbsLevel is an absolute level that may be assumed to exist within
** the database. This function checks if it is the largest level number
** within its index. Assuming no error occurs, *pbMax is set to 1 if
** iAbsLevel is indeed the largest level, or 0 otherwise, and SQLITE_OK
** is returned. If an error occurs, an error code is returned and the
** final value of *pbMax is undefined.
If pszEst is not NULL, store an estimate of the field size. The
** estimate is scaled so that the size of an integer is 1.
SELECT to read row iDel from %_data
Call xSync() on the wal file. This causes SQLite to sync the
** directory in which the target database and the wal file reside, in
** case it has not been synced since the rename() call in
** rbuMoveOalFile().
If there is cached matchinfo() data, but the format string for the
** cache does not match the format string for this request, discard
** the cached data.
Various elements of the SELECT copied into local variables for
** convenience
The entire doclist will fit on the current leaf.
Escape " characters
************* End of sqlite3.h ********************************************
Return code from sqlite3_create_collation_x()
Authenticated as a normal user
OUT: True if *might* be new term
comment: Register used by each index. 0 for unused indices
label: code-design
Has a child
This routine only runs while holding the checkpoint lock. And
** it only runs if there is actually content in the log (mxFrame>0).
Root of NEAR/AND cluster
PRIMARY KEY index, or NULL for rowid tables
Append the PK part of the WHERE clause
IMP: R-52756-41993 This function is a wrapper around the
** sqlite3_total_changes() C/C++ interface.
** Return the text of a syntax error message on a JSON path. Space is
** obtained from sqlite3_malloc().
45
Acquire the mutex before continuing
in1: P1 is an input
Use write-ahead logging
** Recursively delete a Trigger structure
Write a pointer to the page here
** Create/destroy an Fts5Index object.
Total number of entries in hash table
Interpret the [schema.] part of the pragma statement. iDb is the
** index of the database this pragma is being applied to in db.aDb[].
** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if
** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it
** to zero.
SQLITE_OMIT_DISKIO
** Position the pCsr->pStmt statement so that it is on the row
** of the %_content table that contains the last match. Return
** SQLITE_OK on success.
Number of rows in the result
** This function is called on each phrase after the position lists for
** any deferred tokens have been loaded into memory. It updates the phrases
** current position list to include only those positions that are really
** instances of the phrase (after considering deferred tokens). If this
** means that the phrase does not appear in the current row, doclist.pList
** and doclist.nList are both zeroed.
**
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
nbr of bytes to lock
A column-list is terminated by either a 0x01 or 0x00.
10..17 ........
IMP: R-54466-46756
The requested memory region does not exist. If bExtend is set to
** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
** Set the Expr.nHeight variable using the exprSetHeight() function. If
** the height is greater than the maximum allowed expression depth,
** leave an error in pParse.
**
** Also propagate all EP_Propagate flags from the Expr.x.pList into
** Expr.flags.
RTREE_COORD_REAL32 or RTREE_COORD_INT32
Prev() is noop if negative. Next() is noop if positive.
** Error code if eState==CURSOR_FAULT
The database containing the table to be locked
IMMEDIATE
** Call sqlite3ExprAnalyzeAggregates() for every expression in an
** expression list. Return the number of errors.
**
** If an error is found, the analysis is cut short.
An ".. AND (...)" expression
** Return TRUE if the given SQL string ends in a semicolon.
**
** Special handling is require for CREATE TRIGGER statements.
** Whenever the CREATE TRIGGER keywords are seen, the statement
** must end with ";END;".
**
** This implementation uses a state machine with 8 states:
**
** (0) INVALID We have not yet seen a non-whitespace character.
**
** (1) START At the beginning or end of an SQL statement. This routine
** returns 1 if it ends in the START state and 0 if it ends
** in any other state.
**
** (2) NORMAL We are in the middle of statement which ends with a single
** semicolon.
**
** (3) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
** a statement.
**
** (4) CREATE The keyword CREATE has been seen at the beginning of a
** statement, possibly preceded by EXPLAIN and/or followed by
** TEMP or TEMPORARY
**
** (5) TRIGGER We are in the middle of a trigger definition that must be
** ended by a semicolon, the keyword END, and another semicolon.
**
** (6) SEMI We've seen the first semicolon in the ";END;" that occurs at
** the end of a trigger definition.
**
** (7) END We've seen the ";END" of the ";END;" that occurs at the end
** of a trigger definition.
**
** Transitions between states above are determined by tokens extracted
** from the input. The following tokens are significant:
**
** (0) tkSEMI A semicolon.
** (1) tkWS Whitespace.
** (2) tkOTHER Any other SQL token.
** (3) tkEXPLAIN The "explain" keyword.
** (4) tkCREATE The "create" keyword.
** (5) tkTEMP The "temp" or "temporary" keyword.
** (6) tkTRIGGER The "trigger" keyword.
** (7) tkEND The "end" keyword.
**
** Whitespace never causes a state transition and is always ignored.
** This means that a SQL string of all whitespace is invalid.
**
** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
** to recognize the end of a trigger can be omitted. All we have to do
** is look for a semicolon that is not part of an string or comment.
PREVENTS-HARMLESS-OVERREAD
The title text
** An instance of this object stores information about each a single database
** page that has been loaded into memory. The information in this object
** is derived from the raw on-disk page content.
**
** As each database page is loaded into memory, the pager allocats an
** instance of this object and zeros the first 8 bytes. (This is the
** "extra" information associated with each page of the pager.)
**
** Access to all fields of this structure is controlled by the mutex
** stored in MemPage.pBt->mutex.
Used by: default_cache_size
Restrict matches to these columns
** Fill the InitData structure with an error message that indicates
** that the database is corrupt.
DEFERRED => ID
_FTS3_HASH_H_
** Implementation of the sqlite_source_id() function. The result is a string
** that identifies the particular version of the source code used to build
** SQLite.
Delete any triggers created to implement actions for this FK.
Invoke the callback once if the
xDlError
Allocate required output space
Read in the first 8 bytes of the journal header. If they do not match
** the magic string found at the start of each journal header, return
** SQLITE_DONE. If an IO error occurs, return an error code. Otherwise,
** proceed.
Connection to a write-ahead log (WAL) file.
** There is one object of this type for each pager.
True if error has occurred, else false
Last statement is orphaned TEMP trigger
** Return true if currently inside an sqlite3_declare_vtab() call.
Disable mutex on connections
comment:
** 2010 February 1
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the implementation of a write-ahead log (WAL) used in
** "journal_mode=WAL" mode.
**
** WRITE-AHEAD LOG (WAL) FILE FORMAT
**
** A WAL file consists of a header followed by zero or more "frames".
** Each frame records the revised content of a single page from the
** database file. All changes to the database are recorded by writing
** frames into the WAL. Transactions commit when a frame is written that
** contains a commit marker. A single WAL can and usually does record
** multiple transactions. Periodically, the content of the WAL is
** transferred back into the database file in an operation called a
** "checkpoint".
**
** A single WAL file can be used multiple times. In other words, the
** WAL can fill up with frames and then be checkpointed and then new
** frames can overwrite the old ones. A WAL always grows from beginning
** toward the end. Checksums and counters attached to each frame are
** used to determine which frames within the WAL are valid and which
** are leftovers from prior checkpoints.
**
** The WAL header is 32 bytes in size and consists of the following eight
** big-endian 32-bit unsigned integer values:
**
** 0: Magic number. 0x377f0682 or 0x377f0683
** 4: File format version. Currently 3007000
** 8: Database page size. Example: 1024
** 12: Checkpoint sequence number
** 16: Salt-1, random integer incremented with each checkpoint
** 20: Salt-2, a different random integer changing with each ckpt
** 24: Checksum-1 (first part of checksum for first 24 bytes of header).
** 28: Checksum-2 (second part of checksum for first 24 bytes of header).
**
** Immediately following the wal-header are zero or more frames. Each
** frame consists of a 24-byte frame-header followed by a <page-size> bytes
** of page data. The frame-header is six big-endian 32-bit unsigned
** integer values, as follows:
**
** 0: Page number.
** 4: For commit records, the size of the database image in pages
** after the commit. For all other records, zero.
** 8: Salt-1 (copied from the header)
** 12: Salt-2 (copied from the header)
** 16: Checksum-1.
** 20: Checksum-2.
**
** A frame is considered valid if and only if the following conditions are
** true:
**
** (1) The salt-1 and salt-2 values in the frame-header match
** salt values in the wal-header
**
** (2) The checksum values in the final 8 bytes of the frame-header
** exactly match the checksum computed consecutively on the
** WAL header and the first 8 bytes and the content of all frames
** up to and including the current frame.
**
** The checksum is computed using 32-bit big-endian integers if the
** magic number in the first 4 bytes of the WAL is 0x377f0683 and it
** is computed using little-endian if the magic number is 0x377f0682.
** The checksum values are always stored in the frame header in a
** big-endian format regardless of which byte order is used to compute
** the checksum. The checksum is computed by interpreting the input as
** an even number of unsigned 32-bit integers: x[0] through x[N]. The
** algorithm used for the checksum is as follows:
**
** for i from 0 to n-1 step 2:
** s0 += x[i] + s1;
** s1 += x[i+1] + s0;
** endfor
**
** Note that s0 and s1 are both weighted checksums using fibonacci weights
** in reverse order (the largest fibonacci weight occurs on the first element
** of the sequence being summed.) The s1 value spans all 32-bit
** terms of the sequence whereas s0 omits the final term.
**
** On a checkpoint, the WAL is first VFS.xSync-ed, then valid content of the
** WAL is transferred into the database, then the database is VFS.xSync-ed.
** The VFS.xSync operations serve as write barriers - all writes launched
** before the xSync must complete before any write that launches after the
** xSync begins.
**
** After each checkpoint, the salt-1 value is incremented and the salt-2
** value is randomized. This prevents old and new frames in the WAL from
** being considered valid at the same time and being checkpointing together
** following a crash.
**
** READER ALGORITHM
**
** To read a page from the database (call it page number P), a reader
** first checks the WAL to see if it contains page P. If so, then the
** last valid instance of page P that is a followed by a commit frame
** or is a commit frame itself becomes the value read. If the WAL
** contains no copies of page P that are valid and which are a commit
** frame or are followed by a commit frame, then page P is read from
** the database file.
**
** To start a read transaction, the reader records the index of the last
** valid frame in the WAL. The reader uses this recorded "mxFrame" value
** for all subsequent read operations. New transactions can be appended
** to the WAL, but as long as the reader uses its original mxFrame value
** and ignores the newly appended content, it will see a consistent snapshot
** of the database from a single point in time. This technique allows
** multiple concurrent readers to view different versions of the database
** content simultaneously.
**
** The reader algorithm in the previous paragraphs works correctly, but
** because frames for page P can appear anywhere within the WAL, the
** reader has to scan the entire WAL looking for page P frames. If the
** WAL is large (multiple megabytes is typical) that scan can be slow,
** and read performance suffers. To overcome this problem, a separate
** data structure called the wal-index is maintained to expedite the
** search for frames of a particular page.
**
** WAL-INDEX FORMAT
**
** Conceptually, the wal-index is shared memory, though VFS implementations
** might choose to implement the wal-index using a mmapped file. Because
** the wal-index is shared memory, SQLite does not support journal_mode=WAL
** on a network filesystem. All users of the database must be able to
** share memory.
**
** The wal-index is transient. After a crash, the wal-index can (and should
** be) reconstructed from the original WAL file. In fact, the VFS is required
** to either truncate or zero the header of the wal-index when the last
** connection to it closes. Because the wal-index is transient, it can
** use an architecture-specific format; it does not have to be cross-platform.
** Hence, unlike the database and WAL file formats which store all values
** as big endian, the wal-index can store multi-byte values in the native
** byte order of the host computer.
**
** The purpose of the wal-index is to answer this question quickly: Given
** a page number P and a maximum frame index M, return the index of the
** last frame in the wal before frame M for page P in the WAL, or return
** NULL if there are no frames for page P in the WAL prior to M.
**
** The wal-index consists of a header region, followed by an one or
** more index blocks.
**
** The wal-index header contains the total number of frames within the WAL
** in the mxFrame field.
**
** Each index block except for the first contains information on
** HASHTABLE_NPAGE frames. The first index block contains information on
** HASHTABLE_NPAGE_ONE frames. The values of HASHTABLE_NPAGE_ONE and
** HASHTABLE_NPAGE are selected so that together the wal-index header and
** first index block are the same size as all other index blocks in the
** wal-index.
**
** Each index block contains two sections, a page-mapping that contains the
** database page number associated with each wal frame, and a hash-table
** that allows readers to query an index block for a specific page number.
** The page-mapping is an array of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE
** for the first index block) 32-bit page numbers. The first entry in the
** first index-block contains the database page number corresponding to the
** first frame in the WAL file. The first entry in the second index block
** in the WAL file corresponds to the (HASHTABLE_NPAGE_ONE+1)th frame in
** the log, and so on.
**
** The last index block in a wal-index usually contains less than the full
** complement of HASHTABLE_NPAGE (or HASHTABLE_NPAGE_ONE) page-numbers,
** depending on the contents of the WAL file. This does not change the
** allocated size of the page-mapping array - the page-mapping array merely
** contains unused entries.
**
** Even without using the hash table, the last frame for page P
** can be found by scanning the page-mapping sections of each index block
** starting with the last index block and moving toward the first, and
** within each index block, starting at the end and moving toward the
** beginning. The first entry that equals P corresponds to the frame
** holding the content for that page.
**
** The hash table consists of HASHTABLE_NSLOT 16-bit unsigned integers.
** HASHTABLE_NSLOT = 2*HASHTABLE_NPAGE, and there is one entry in the
** hash table for each page number in the mapping section, so the hash
** table is never more than half full. The expected number of collisions
** prior to finding a match is 1. Each entry of the hash table is an
** 1-based index of an entry in the mapping section of the same
** index block. Let K be the 1-based index of the largest entry in
** the mapping section. (For index blocks other than the last, K will
** always be exactly HASHTABLE_NPAGE (4096) and for the last index block
** K will be (mxFrame%HASHTABLE_NPAGE).) Unused slots of the hash table
** contain a value of 0.
**
** To look for page P in the hash table, first compute a hash iKey on
** P as follows:
**
** iKey = (P * 383) % HASHTABLE_NSLOT
**
** Then start scanning entries of the hash table, starting with iKey
** (wrapping around to the beginning when the end of the hash table is
** reached) until an unused hash slot is found. Let the first unused slot
** be at index iUnused. (iUnused might be less than iKey if there was
** wrap-around.) Because the hash table is never more than half full,
** the search is guaranteed to eventually hit an unused entry. Let
** iMax be the value between iKey and iUnused, closest to iUnused,
** where aHash[iMax]==P. If there is no iMax entry (if there exists
** no hash slot such that aHash[i]==p) then page P is not in the
** current index block. Otherwise the iMax-th mapping entry of the
** current index block corresponds to the last entry that references
** page P.
**
** A hash search begins with the last index block and moves toward the
** first index block, looking for entries corresponding to page P. On
** average, only two or three slots in each index block need to be
** examined in order to either find the last entry for page P, or to
** establish that no such entry exists in the block. Each index block
** holds over 4000 entries. So two or three index blocks are sufficient
** to cover a typical 10 megabyte WAL file, assuming 1K pages. 8 or 10
** comparisons (on average) suffice to either locate a frame in the
** WAL or to establish that the frame does not exist in the WAL. This
** is much faster than scanning the entire 10MB WAL.
**
** Note that entries are added in order of increasing K. Hence, one
** reader might be using some value K0 and a second reader that started
** at a later time (after additional transactions were added to the WAL
** and to the wal-index) might be using a different value K1, where K1>K0.
** Both readers can use the same hash table and mapping section to get
** the correct result. There may be entries in the hash table with
** K>K0 but to the first reader, those entries will appear to be unused
** slots in the hash table and so the first reader will get an answer as
** if no values greater than K0 had ever been inserted into the hash table
** in the first place - which is what reader one wants. Meanwhile, the
** second reader using K1 will see additional values that were inserted
** later, which is exactly what reader two wants.
**
** When a rollback occurs, the value of K is decreased. Hash table entries
** that correspond to frames greater than the new K value are removed
** from the hash table at this point.
label: code-design
Overflow page pointer-map entry page
SQLITE_VDBE_H
** PRAGMA compile_options
**
** Return the names of all compile-time options used in this build,
** one option per row.
** The methods above are in versions 1 through 3 of the sqlite_vfs object.
** New fields may be appended in future versions. The iVersion
** value will increment whenever this happens.
Position read from poslist
** Install the diff hooks on the session object passed as the only
** argument.
The doNotSpill NOSYNC bit is set during times when doing a sync of
** journal (and adding a new header) is not allowed. This occurs
** during calls to sqlite3PagerWrite() while trying to journal multiple
** pages belonging to the same sector.
**
** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling
** regardless of whether or not a sync is required. This is set during
** a rollback or by user request, respectively.
**
** Spilling is also prohibited when in an error state since that could
** lead to database corruption. In the current implementation it
** is impossible for sqlite3PcacheFetch() to be called with createFlag==3
** while in the error state, hence it is impossible for this routine to
** be called in the error state. Nevertheless, we include a NEVER()
** test for the error state as a safeguard against future changes.
OUT: Selected child node
** Obtain an SQLite statement handle that may be used to read data from the
** %_content table.
Page number of free-list trunk page
** 2001 September 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of generic hash-tables used in SQLite.
** We've modified it slightly to serve as a standalone hash table
** implementation for the full-text indexing module.
The special operator TK_ROW means use the rowid for the first
** column in the FROM clause. This is used by the LIMIT and ORDER BY
** clause processing on UPDATE and DELETE statements.
Open a cursor on zDoc/nDoc. Check if there are (nSnippet+nDesired)
** or more tokens in zDoc/nDoc.
** If this Btree is a candidate for shared cache, try to find an
** existing BtShared object that we can share with
val now holds the upper bound of the coordinate pair
Root node of tree for this task
The node from which to extract a coordinate
Coordinate decoded
Total cost of this path ignoring sorting costs
EV: R-19803-45884
** Load the Parse object passed as the first argument with an error
** message of the form:
**
** "sub-select returns N columns - expected M"
EXPLAIN
************* End of fts3_write.c *****************************************
Size of input text in bytes
Minimum required file size
** CAPI3REF: Testing Interface
**
** ^The sqlite3_test_control() interface is used to read out internal
** state of SQLite and to inject faults into SQLite for testing
** purposes. ^The first parameter is an operation code that determines
** the number, meaning, and operation of all subsequent parameters.
**
** This interface is not for use by applications. It exists solely
** for verifying the correct operation of the SQLite library. Depending
** on how the SQLite library is compiled, this interface might not exist.
**
** The details of the operation codes, their meanings, the parameters
** they take, and what they do are all subject to change without notice.
** Unlike most of the SQLite API, this function is not guaranteed to
** operate consistently from one release to the next.
Looping over other all cursors
Height of sub-trees Reinsert() has run on
.szMalloc =
This next condition is true if data has already been loaded from
** the sqlite_stat4 table. In this case ignore stat3 data.
** CAPI3REF: Enable Or Disable Extended Result Codes
** METHOD: sqlite3
**
** ^The sqlite3_extended_result_codes() routine enables or disables the
** [extended result codes] feature of SQLite. ^The extended result
** codes are disabled by default for historical compatibility.
nexprlist ::= nexprlist COMMA expr
Page numbers of new pages before shuffling
Page cache memory
IN/OUT: Integer value
The common case
** xBestIndex - Analyze a WHERE and ORDER BY clause.
comment: Insert code to test every subexpression that can be completely
** computed using the current set of tables.
**
** This loop may run between one and three times, depending on the
** constraints to be generated. The value of stack variable iLoop
** determines the constraints coded by each iteration, as follows:
**
** iLoop==1: Code only expressions that are entirely covered by pIdx.
** iLoop==2: Code remaining expressions that do not contain correlated
** sub-queries.
** iLoop==3: Code all remaining expressions.
**
** An effort is made to skip unnecessary iterations of the loop.
label: code-design
Return the unixInodeInfo object here
** The maximum depth of an expression tree. This is limited to
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
** want to place more severe limits on the complexity of an
** expression.
**
** A value of 0 used to mean that the limit was not enforced.
** But that is no longer true. The limit is now strictly enforced
** at all times.
comment: Read the first three 32-bit fields of the journal header: The nRec
** field, the checksum-initializer and the database size at the start
** of the transaction. Return an error code if anything goes wrong.
label: code-design
comment:
** Change the size of an existing memory allocation.
**
** For this debugging implementation, we *always* make a copy of the
** allocation into a new place in memory. In this way, if the
** higher level code is using pointer to the old allocation, it is
** much more likely to break and we are much more liking to find
** the error.
label: code-design
READWRITE
Guaranteed by the code generator
** The smallest possible node-size is (512-64)==448 bytes. And the largest
** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
** Therefore all non-root nodes must contain at least 3 entries. Since
** 2^40 is greater than 2^64, an r-tree structure always has a depth of
** 40 or less.
x.pSelect is valid (otherwise x.pList is)
** Allocate an Fts3MultiSegReader for each token in the expression headed
** by pExpr.
**
** An Fts3SegReader object is a cursor that can seek or scan a range of
** entries within a single segment b-tree. An Fts3MultiSegReader uses multiple
** Fts3SegReader objects internally to provide an interface to seek or scan
** within the union of all segments of a b-tree. Hence the name.
**
** If the allocated Fts3MultiSegReader just seeks to a single entry in a
** segment b-tree (if the term is not a prefix or it is a prefix for which
** there exists prefix b-tree of the right length) then it may be traversed
** and merged incrementally. Otherwise, it has to be merged into an in-memory
** doclist and then traversed.
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
Name of left-most parent key column
** This routine prepares a memory cell for modification by breaking
** its link to a shallow copy and by marking any current shallow
** copies of this cell as invalid.
**
** This is used for testing and debugging only - to make sure shallow
** copies are not misused.
Opcode: Param P1 P2 * * *
**
** This opcode is only ever present in sub-programs called via the
** OP_Program instruction. Copy a value currently stored in a memory
** cell of the calling (parent) frame to cell P2 in the current frames
** address space. This is used by trigger programs to access the new.*
** and old.* values.
**
** The address of the cell in the parent frame is determined by adding
** the value of the P1 argument to the value of the P1 argument to the
** calling OP_Program instruction.
** CAPI3REF: Close A BLOB Handle
** DESTRUCTOR: sqlite3_blob
**
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
** unconditionally. Even if this routine returns an error code, the
** handle is still closed.)^
**
** ^If the blob handle being closed was opened for read-write access, and if
** the database is in auto-commit mode and there are no other open read-write
** blob handles or active write statements, the current transaction is
** committed. ^If an error occurs while committing the transaction, an error
** code is returned and the transaction rolled back.
**
** Calling this function with an argument that is not a NULL pointer or an
** open blob handle results in undefined behaviour. ^Calling this routine
** with a null pointer (such as would be returned by a failed call to
** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
** is passed a valid open blob handle, the values returned by the
** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
** Write value iVal encoded as a varint to the PMA. Return
** SQLITE_OK if successful, or an SQLite error code if an error occurs.
** Declare that a function has been overloaded by a virtual table.
**
** If the function already exists as a regular global function, then
** this routine is a no-op. If the function does not exist, then create
** a new one that always throws a run-time error.
**
** When virtual tables intend to provide an overloaded function, they
** should call this routine to make sure the global function exists.
** A global function must exist in order for name resolution to work
** properly.
Reader marks
comment: Failure to set the bits in the InJournal bit-vectors is benign.
** It merely means that we might do some extra work to journal a
** page that does not need to be journaled. Nevertheless, be sure
** to test the case where a malloc error occurs while trying to set
** a bit in a bit vector.
label: code-design
Size of read buffer in bytes
** This function is used to set the schema of a virtual table. It is only
** valid to call this function from within the xCreate() or xConnect() of a
** virtual table module.
Table that change applies to
** Create the %_stat table if it does not already exist.
Initialize the count of rows to be inserted
** Register a new tokenizer. This is the implementation of the
** fts5_api.xCreateTokenizer() method.
Move level -1 to level iAbsLevel
Allocate a page. The page that currently resides at pgnoRoot will
** be moved to the allocated page (unless the allocated page happens
** to reside at pgnoRoot).
Write current value here
** A bitmap is an instance of the following structure.
**
** This bitmap records the existence of zero or more bits
** with values between 1 and iSize, inclusive.
**
** There are three possible representations of the bitmap.
** If iSize<=BITVEC_NBIT, then Bitvec.u.aBitmap[] is a straight
** bitmap. The least significant bit is bit 1.
**
** If iSize>BITVEC_NBIT and iDivisor==0 then Bitvec.u.aHash[] is
** a hash table that will hold up to BITVEC_MXHASH distinct values.
**
** Otherwise, the value i is redirected into one of BITVEC_NPTR
** sub-bitmaps pointed to by Bitvec.u.apSub[]. Each subbitmap
** handles up to iDivisor separate values of i. apSub[0] holds
** values between 1 and iDivisor. apSub[1] holds values between
** iDivisor+1 and 2*iDivisor. apSub[N] holds values between
** N*iDivisor+1 and (N+1)*iDivisor. Each subbitmap is normalized
** to hold deal with values between 1 and iDivisor.
.u =
** Convert an SQL-style quoted string into a normal string by removing
** the quote characters. The conversion is done in-place. If the
** input does not begin with a quote character, then this routine
** is a no-op.
**
** The input string must be zero-terminated. A new zero-terminator
** is added to the dequoted string.
**
** The return value is -1 if no dequoting occurs or the length of the
** dequoted string, exclusive of the zero terminator, if dequoting does
** occur.
**
** 2002-Feb-14: This routine is extended to remove MS-Access style
** brackets from around identifiers. For example: "[a-b-c]" becomes
** "a-b-c".
** Return the current time as a Julian Day number in *pTimeOut.
Doclist-index flag (1 bit)
** This routine processes the join information for a SELECT statement.
** ON and USING clauses are converted into extra terms of the WHERE clause.
** NATURAL joins also create extra WHERE clause terms.
**
** The terms of a FROM clause are contained in the Select.pSrc structure.
** The left most table is the first entry in Select.pSrc. The right-most
** table is the last entry. The join operator is held in the entry to
** the left. Thus entry 0 contains the join operator for the join between
** entries 0 and 1. Any ON or USING clauses associated with the join are
** also attached to the left entry.
**
** This routine returns the number of errors encountered.
This routine should not be called if a prior error has occurred.
** But if (due to a coding error elsewhere in the system) it does get
** called, just return the same error code without doing anything.
ONEPASS_OFF, or _SINGLE, or _MULTI
** Release any memory resources held by the Mem. Both the memory that is
** free by Mem.xDel and the Mem.zMalloc allocation are freed.
**
** Use this routine prior to clean up prior to abandoning a Mem, or to
** reset a Mem back to its minimum memory utilization.
**
** Use sqlite3VdbeMemSetNull() to release just the Mem.xDel space
** prior to inserting new content into the Mem.
List for thread to write to a PMA
** Check to see if virtual table module pMod can be have an eponymous
** virtual table instance. If it can, create one if one does not already
** exist. Return non-zero if the eponymous virtual table instance exists
** when this routine returns, and return zero if it does not exist.
**
** An eponymous virtual table instance is one that is named after its
** module, and more importantly, does not require a CREATE VIRTUAL TABLE
** statement in order to come into existance. Eponymous virtual table
** instances always exist. They cannot be DROP-ed.
**
** Any virtual table module for which xConnect and xCreate are the same
** method can have an eponymous virtual table instance.
Allocate and populate the array of LcsIterator objects. The array
** contains one element for each matchable phrase in the query.
*
IN/OUT: Pointer to string buffer
min/max aggregates seen. See note above
Character set tests (like isspace(), isalpha() etc.)
comment:
** The query generator uses an array of instances of this structure to
** help it analyze the subexpressions of the WHERE clause. Each WHERE
** clause subexpression is separated from the others by AND operators,
** usually, or sometimes subexpressions separated by OR.
**
** All WhereTerms are collected into a single WhereClause structure.
** The following identity holds:
**
** WhereTerm.pWC->a[WhereTerm.idx] == WhereTerm
**
** When a term is of the form:
**
** X <op> <expr>
**
** where X is a column name and <op> is one of certain operators,
** then WhereTerm.leftCursor and WhereTerm.u.leftColumn record the
** cursor number and column number for X. WhereTerm.eOperator records
** the <op> using a bitmask encoding defined by WO_xxx below. The
** use of a bitmask encoding for the operator allows us to search
** quickly for terms that match any of several different operators.
**
** A WhereTerm might also be two or more subterms connected by OR:
**
** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
**
** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
** and the WhereTerm.u.pOrInfo field points to auxiliary information that
** is collected about the OR clause.
**
** If a term in the WHERE clause does not match either of the two previous
** categories, then eOperator==0. The WhereTerm.pExpr field is still set
** to the original subexpression content and wtFlags is set up appropriately
** but no other fields in the WhereTerm object are meaningful.
**
** When eOperator!=0, prereqRight and prereqAll record sets of cursor numbers,
** but they do so indirectly. A single WhereMaskSet structure translates
** cursor number into bits and the translated bit is stored in the prereq
** fields. The translation is used in order to maximize the number of
** bits that will fit in a Bitmask. The VDBE cursor numbers might be
** spread out over the non-negative integers. For example, the cursor
** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The WhereMaskSet
** translates these sparse cursor numbers into consecutive integers
** beginning with 0 in order to make the best possible use of the available
** bits in the Bitmask. So, in the example above, the cursor numbers
** would be mapped into integers 0 through 7.
**
** The number of terms in a join is limited by the number of bits
** in prereqRight and prereqAll. The default is 64 bits, hence SQLite
** is only able to process joins with 64 or fewer tables.
label: code-design
comment:
** This function is called when the PmaReader corresponding to pIncr has
** finished reading the contents of aFile[0]. Its purpose is to "refill"
** aFile[0] such that the PmaReader should start rereading it from the
** beginning.
**
** For single-threaded objects, this is accomplished by literally reading
** keys from pIncr->pMerger and repopulating aFile[0].
**
** For multi-threaded objects, all that is required is to wait until the
** background thread is finished (if it is not already) and then swap
** aFile[0] and aFile[1] in place. If the contents of pMerger have not
** been exhausted, this function also launches a new background thread
** to populate the new aFile[1].
**
** SQLITE_OK is returned on success, or an SQLite error code otherwise.
label: code-design
Hash table of column names
IN/OUT: Decrement if row is deleted
** If the field type is etGENERIC, then convert to either etEXP
** or etFLOAT, as appropriate.
xSqllog
DATABASE => ID
** Return the number of consecutive JsonNode slots need to represent
** the parsed JSON at pNode. The minimum answer is 1. For ARRAY and
** OBJECT types, the number might be larger.
**
** Appended elements are not counted. The value returned is the number
** by which the JsonNode counter should increment in order to go to the
** next peer value.
Insertion failed because database is full
SQLITE_ENABLE_STMT_SCANSTATUS
TermOffset associated with next token
True if no shared-cache backends
comment:
** The value of the "pending" byte must be 0x40000000 (1 byte past the
** 1-gibabyte boundary) in a compatible database. SQLite never uses
** the database page that contains the pending byte. It never attempts
** to read or write that page. The pending byte page is set aside
** for use by the VFS layers as space for managing file locks.
**
** During testing, it is often desirable to move the pending byte to
** a different position in the file. This allows code that has to
** deal with the pending byte to run on files that are much smaller
** than 1 GiB. The sqlite3_test_control() interface can be used to
** move the pending byte.
**
** IMPORTANT: Changing the pending byte to any value other than
** 0x40000000 results in an incompatible database file format!
** Changing the pending byte during operation will result in undefined
** and incorrect behavior.
label: code-design
************* Include os.h in the middle of sqliteInt.h *******************
Custom rank function args
Available memory
Tail of table name e.g. "data", "config"
** Tokenize the nul-terminated string zText and add all tokens to the
** pending-terms hash-table. The docid used is that currently stored in
** p->iPrevDocid, and the column is specified by argument iCol.
**
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code.
Next entry is on the current page
Mask of type bits
If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
** entire wal file has been copied into the database file, then block
** until all readers have finished using the wal file. This ensures that
** the next process to write to the database restarts the wal file.
275
#include "sqlite3session.h"
360
MEM cell holding data for the record to be inserted
Name of table containing column, or NULL
pName1->z might be NULL, but not pName1 itself
167
(double)0 In case of SQLITE_OMIT_FLOATING_POINT...
** Allocate cursors for the pTab table and all its indices and generate
** code to open and initialized those cursors.
**
** The cursor for the object that contains the complete data (normally
** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
** ROWID table) is returned in *piDataCur. The first index cursor is
** returned in *piIdxCur. The number of indices is returned.
**
** Use iBase as the first cursor (either the *piDataCur for rowid tables
** or the first index for WITHOUT ROWID tables) if it is non-negative.
** If iBase is negative, then allocate the next available cursor.
**
** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the
** pTab->pIndex list.
**
** If pTab is a virtual table, then this routine is a no-op and the
** *piDataCur and *piIdxCur values are left uninitialized.
The function we are evaluating for match quality
Determine the auto-incr-merge setting if unknown. If enabled,
** estimate the number of leaf blocks of content to be written
(273) cmdlist ::= cmdlist ecmd
Verify that the number of entries in the hash table exactly equals
** the number of entries in the mapping region.
** This function is used to count the entries in a column-list (a
** delta-encoded list of term offsets within a single column of a single
** row). When this function is called, *ppCollist should point to the
** beginning of the first varint in the column-list (the varint that
** contains the position of the first matching term in the column data).
** Before returning, *ppCollist is set to point to the first byte after
** the last varint in the column-list (either the 0x00 signifying the end
** of the position-list, or the 0x01 that precedes the column number of
** the next column in the position-list).
**
** The number of elements in the column-list is returned.
If this is part of a compound SELECT, check that it has the right
** number of expressions in the select list.
Inequality constraint at range start
1240
Write the page pointer here
Nul-terminated UTF-8 string <id>
** xSetOutputs callback used by detail=full and detail=col tables when no
** column filters are specified.
Estimated average row size in bytes
#include <unicode/ustring.h>
** Rtree virtual table module xConnect method.
Log base 2 of minimum allocation size in bytes
Root page of current object
** Return the SQL associated with a prepared statement with
** bound parameters expanded. Space to hold the returned string is
** obtained from sqlite3_malloc(). The caller is responsible for
** freeing the returned string by passing it to sqlite3_free().
**
** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
** expanded bound parameters.
Restriction (7)
If one was specified, code the WHEN clause. If it evaluates to false
** (or NULL) the sub-vdbe is immediately halted by jumping to the
** OP_Halt inserted at the end of the program.
Container of this cell
State variables
comment: Not used on win32
label: code-design
comment:
** The VACUUM command is used to clean up the database,
** collapse free space, etc. It is modelled after the VACUUM command
** in PostgreSQL. The VACUUM command works as follows:
**
** (1) Create a new transient database file
** (2) Copy all content from the database being vacuumed into
** the new transient database file
** (3) Copy content from the transient database back into the
** original database.
**
** The transient database requires temporary disk space approximately
** equal to the size of the original database. The copy operation of
** step (3) requires additional temporary disk space approximately equal
** to the size of the original database for the rollback journal.
** Hence, temporary disk space that is approximately 2x the size of the
** original database is required. Every page of the database is written
** approximately 3 times: Once for step (2) and twice for step (3).
** Two writes per page are required in step (3) because the original
** database content must be written into the rollback journal prior to
** overwriting the database with the vacuumed content.
**
** Only 1x temporary space and only 1x writes would be required if
** the copy of step (3) were replaced by deleting the original database
** and renaming the transient database as the original. But that will
** not work if other processes are attached to the original database.
** And a power loss in between deleting the original and renaming the
** transient would cause the database file to appear to be deleted
** following reboot.
label: code-design
** Free an outstanding memory allocation.
**
** This function assumes that the necessary mutexes, if any, are
** already held by the caller. Hence "Unsafe".
The next action
neardist_opt ::=
172
** Open a connection to the WAL file zWalName. The database file must
** already be opened on connection pDbFd. The buffer that zWalName points
** to must remain valid for the lifetime of the returned Wal* handle.
**
** A SHARED lock should be held on the database file when this function
** is called. The purpose of this SHARED lock is to prevent any other
** client from unlinking the WAL or wal-index file. If another process
** were to do this just after this client opened one of these files, the
** system would be badly broken.
**
** If the log file is successfully opened, SQLITE_OK is returned and
** *ppWal is set to point to a new WAL handle. If an error occurs,
** an SQLite error code is returned and *ppWal is left unmodified.
** Allowed values of unixFile.fsFlags
If this DELETE cannot use the ONEPASS strategy, this is the
** end of the WHERE loop
Union of locks held by connections other than "p"
Dynamically allocated space for aArg[]
** Generate either a changeset (if argument bPatchset is zero) or a patchset
** (if it is non-zero) based on the current contents of the session object
** passed as the first argument.
**
** If no error occurs, SQLITE_OK is returned and the new changeset/patchset
** stored in output variables *pnChangeset and *ppChangeset. Or, if an error
** occurs, an SQLite error code is returned and both output variables set
** to 0.
** 2003 January 11
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the sqlite3_set_authorizer()
** API. This facility is an optional feature of the library. Embedded
** systems that do not need this facility may omit it by recompiling
** the library with -DSQLITE_OMIT_AUTHORIZATION=1
** Initialize memory that will be converted into a BtCursor object.
**
** The simple approach here would be to memset() the entire object
** to zero. But it turns out that the apPage[] and aiIdx[] arrays
** do not need to be zeroed and they are large, so we can save a lot
** of run-time by skipping the initialization of those elements.
Buffer to assemble frame-header in
Filename as passed to xOpen
The content of the page
xClose
An ascii-range separator character. End of token.
Mask for the current column
Copy data from page to buffer (a read operation)
CROSS
** If the REQUIRE_RESEEK flag is set on the cursor passed as the first
** argument, close and reopen all Fts5IndexIter iterators that the cursor
** is using. Then attempt to move the cursor to a rowid equal to or laster
** (in the cursors sort order - ASC or DESC) than the current rowid.
**
** If the new rowid is not equal to the old, set output parameter *pbSkip
** to 1 before returning. Otherwise, leave it unchanged.
**
** Return SQLITE_OK if successful or if no reseek was required, or an
** error code if an error occurred.
IN/OUT: Record pointer
Mem.z points to an agg function context
** Invalidate the overflow cache of the cursor passed as the first argument.
** on the shared btree structure pBt.
Address of jump over the delete logic
#ifndef SQLITE_OMIT_TRIGGER
** Set an Fts3SegReader cursor to point at EOF.
xFindFunction - function overloading
Opcode: Return P1 * * * *
**
** Jump to the next instruction after the address in register P1. After
** the jump, register P1 becomes undefined.
** Implementation of API function xQueryPhrase().
Cursor for IPK b-tree
Next WhereLoop object in the WhereClause
If a temporary file is requested, it is not opened immediately.
** In this case we accept the default page size and delay actually
** opening the file until the first call to OsWrite().
**
** This branch is also run for an in-memory database. An in-memory
** database is the same as a temp-file that is never written out to
** disk and uses an in-memory rollback journal.
**
** This branch also runs for files marked as immutable.
Current read buffer
** The following is the implementation of an SQL function that always
** fails with an error message stating that the function is used in the
** wrong context. The sqlite3_overload_function() API might construct
** SQL function that use this routine so that the functions will exist
** for name resolution but are actually overloaded by the xFindFunction
** method of virtual tables.
Temporary storage for the page
This branch may be executed with Pager.journalMode==MEMORY if
** a hot-journal was just rolled back. In this case the journal
** file should be closed and deleted. If this connection writes to
** the database file, it will do so using an in-memory journal.
1060
** Return TRUE if the given string is a row-id column name.
100's digit
** Free an sqlite3_value object
TK_LE
Size of zDoc in bytes
If the pager is already in exclusive-mode, the WAL module will use
** heap-memory for the wal-index instead of the VFS shared-memory
** implementation. Take the exclusive lock now, before opening the WAL
** file, to make sure this is safe.
a &= (0x7f<<29)|(0x7f<<15)|(0xff);
Once all the cookies have been verified and transactions opened,
** obtain the required table-locks. This is a no-op unless the
** shared-cache feature is enabled.
Amount of space allocated to zMasterPtr[]
Use BtreeGetReserveNoMutex() for the source b-tree, as although it is
** guaranteed that the shared-mutex is held by this thread, handle
** p->pSrc may not actually be the owner.
** A read or write transaction may or may not be active on database handle
** db. If a transaction is active, commit it. If there is a
** write-transaction spanning more than one database file, this routine
** takes care of the master journal trickery.
** Bits for the mask used as the idxNum value by xBestIndex/xFilter.
Set the VdbeCursor.isTable variable. Previous versions of
** SQLite used to check if the root-page flags were sane at this point
** and report database corruption if they were not, but this check has
** since moved into the btree layer.
Locate the cursor number of the Current table
IMP: R-65497-44594
Iterate through all segments, from oldest to newest. Add them to
** the new Fts5Level object so that pLvl->aSeg[0] is the oldest
** segment in the data structure.
Flags for OsSync() (or 0)
Array of size pConfig->nCol
If there is not a recovery running in another thread or process
** then convert BUSY errors to WAL_RETRY. If recovery is known to
** be running, convert BUSY to BUSY_RECOVERY. There is a race here
** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
** would be technically correct. But the race is benign since with
** WAL_RETRY this routine will be called again and will probably be
** right on the second iteration.
Currently executing extension function
xClose - close a cursor
The loop to adjust downward
A rowid/docid conflict.
** Remove from the column cache any entries that were added since the
** the previous sqlite3ExprCachePush operation. In other words, restore
** the cache to the state it was in prior the most recent Push.
Child node (or 0 if this is a leaf)
** Flush all data associated with the SegmentWriter object pWriter to the
** database. This function must be called after all terms have been added
** to the segment using fts3SegWriterAdd(). If successful, SQLITE_OK is
** returned. Otherwise, an SQLite error code.
EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
** possible for a root page of a table that contains no rows) then the
** offset to the cell content area will equal the page size minus the
** bytes of reserved space.
First in list of all tokenizer modules
** Attempt to add, substract, or multiply the 64-bit signed value iB against
** the other 64-bit signed integer at *pA and store the result in *pA.
** Return 0 on success. Or if the operation would have resulted in an
** overflow, leave *pA unchanged and return 1.
Free idxStr using sqlite3_free() if true
plus_num ::= PLUS INTEGER|FLOAT
True for first term on the node
Load the initial configuration
Another SELECT immediately to our left
Statement cursor is currently pointing at
Size of pSorter in bytes
comment:
** CAPI3REF: Standard File Control Opcodes
** KEYWORDS: {file control opcodes} {file control opcode}
**
** These integer constants are opcodes for the xFileControl method
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
** interface.
**
** <ul>
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
** opcode causes the xFileControl method to write the current state of
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
** into an integer that the pArg argument points to. This capability
** is used during testing and is only available when the SQLITE_TEST
** compile-time option is used.
**
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
** layer a hint of how large the database file will grow to be during the
** current transaction. This hint is not guaranteed to be accurate but it
** is often close. The underlying VFS might choose to preallocate database
** file space based on this hint in order to help writes to the database
** file run faster.
**
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
** extends and truncates the database file in chunks of a size specified
** by the user. The fourth argument to [sqlite3_file_control()] should
** point to an integer (type int) containing the new chunk-size to use
** for the nominated database. Allocating database file space in large
** chunks (say 1MB at a time), may reduce file-system fragmentation and
** improve performance on some systems.
**
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with a particular database
** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
**
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with the journal file (either
** the [rollback journal] or the [write-ahead log]) for a particular database
** connection. See also [SQLITE_FCNTL_FILE_POINTER].
**
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
** No longer in use.
**
** <li>[[SQLITE_FCNTL_SYNC]]
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
** sent to the VFS immediately before the xSync method is invoked on a
** database file descriptor. Or, if the xSync method is not invoked
** because the user has configured SQLite with
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
** of the xSync method. In most cases, the pointer argument passed with
** this file-control is NULL. However, if the database file is being synced
** as part of a multi-database commit, the argument points to a nul-terminated
** string containing the transactions master-journal file name. VFSes that
** do not need this signal should silently ignore this opcode. Applications
** should not call [sqlite3_file_control()] with this opcode as doing so may
** disrupt the operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
** and sent to the VFS after a transaction has been committed immediately
** but before the database is unlocked. VFSes that do not need this signal
** should silently ignore this opcode. Applications should not call
** [sqlite3_file_control()] with this opcode as doing so may disrupt the
** operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
** retry counts and intervals for certain disk I/O operations for the
** windows [VFS] in order to provide robustness in the presence of
** anti-virus programs. By default, the windows VFS will retry file read,
** file write, and file delete operations up to 10 times, with a delay
** of 25 milliseconds before the first retry and with the delay increasing
** by an additional 25 milliseconds with each subsequent retry. This
** opcode allows these two values (10 retries and 25 milliseconds of delay)
** to be adjusted. The values are changed for all database connections
** within the same process. The argument is a pointer to an array of two
** integers where the first integer is the new retry count and the second
** integer is the delay. If either integer is negative, then the setting
** is not changed but instead the prior value of that setting is written
** into the array entry, allowing the current retry settings to be
** interrogated. The zDbName parameter is ignored.
**
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
** write ahead log and shared memory files used for transaction control
** are automatically deleted when the latest connection to the database
** closes. Setting persistent WAL mode causes those files to persist after
** close. Persisting the files is useful when other processes that do not
** have write permission on the directory containing the database file want
** to read the database file, as the WAL and shared memory files must exist
** in order for the database to be readable. The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
** WAL mode. If the integer is -1, then it is overwritten with the current
** WAL persistence setting.
**
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
** xDeviceCharacteristics methods. The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
** mode. If the integer is -1, then it is overwritten with the current
** zero-damage mode setting.
**
** <li>[[SQLITE_FCNTL_OVERWRITE]]
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
** a write transaction to indicate that, unless it is rolled back for some
** reason, the entire database file will be overwritten by the current
** transaction. This is used by VACUUM operations.
**
** <li>[[SQLITE_FCNTL_VFSNAME]]
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
** all [VFSes] in the VFS stack. The names are of all VFS shims and the
** final bottom-level VFS are written into memory obtained from
** [sqlite3_malloc()] and the result is stored in the char* variable
** that the fourth parameter of [sqlite3_file_control()] points to.
** The caller is responsible for freeing the memory when done. As with
** all file-control actions, there is no guarantee that this will actually
** do anything. Callers should initialize the char* variable to a NULL
** pointer in case this file-control is not implemented. This file-control
** is intended for diagnostic use only.
**
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
** [VFSes] currently in use. ^(The argument X in
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
** of type "[sqlite3_vfs] **". This opcodes will set *X
** to a pointer to the top-level VFS.)^
** ^When there are multiple VFS shims in the stack, this opcode finds the
** upper-most shim only.
**
** <li>[[SQLITE_FCNTL_PRAGMA]]
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
** file control is sent to the open [sqlite3_file] object corresponding
** to the database file to which the pragma statement refers. ^The argument
** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
** pointers to strings (char**) in which the second element of the array
** is the name of the pragma and the third element is the argument to the
** pragma or NULL if the pragma has no argument. ^The handler for an
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
** or the equivalent and that string will become the result of the pragma or
** the error message if the pragma fails. ^If the
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
** file control returns [SQLITE_OK], then the parser assumes that the
** VFS has handled the PRAGMA itself and the parser generates a no-op
** prepared statement if result string is NULL, or that returns a copy
** of the result string if the string is non-NULL.
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
** that the VFS encountered an error while handling the [PRAGMA] and the
** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
** file control occurs at the beginning of pragma statement analysis and so
** it is able to override built-in [PRAGMA] statements.
**
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
** ^The [SQLITE_FCNTL_BUSYHANDLER]
** file-control may be invoked by SQLite on the database file handle
** shortly after it is opened in order to provide a custom VFS with access
** to the connections busy-handler callback. The argument is of type (void **)
** - an array of two (void *) values. The first (void *) actually points
** to a function of type (int (*)(void *)). In order to invoke the connections
** busy-handler, this function should be invoked with the second (void *) in
** the array as the only argument. If it returns non-zero, then the operation
** should be retried. If it returns zero, the custom VFS should abandon the
** current operation.
**
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
** to have SQLite generate a
** temporary filename using the same algorithm that is followed to generate
** temporary filenames for TEMP tables and other internal uses. The
** argument should be a char** which will be filled with the filename
** written into memory obtained from [sqlite3_malloc()]. The caller should
** invoke [sqlite3_free()] on the result to avoid a memory leak.
**
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
** maximum number of bytes that will be used for memory-mapped I/O.
** The argument is a pointer to a value of type sqlite3_int64 that
** is an advisory maximum number of bytes in the file to memory map. The
** pointer is overwritten with the old value. The limit is not changed if
** the value originally pointed to is negative, and so the current limit
** can be queried by passing in a pointer to a negative number. This
** file-control is used internally to implement [PRAGMA mmap_size].
**
** <li>[[SQLITE_FCNTL_TRACE]]
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
** to the VFS about what the higher layers of the SQLite stack are doing.
** This file control is used by some VFS activity tracing [shims].
** The argument is a zero-terminated string. Higher layers in the
** SQLite stack may generate instances of this file control if
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
**
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
** pointer to an integer and it writes a boolean into that integer depending
** on whether or not the file has been renamed, moved, or deleted since it
** was first opened.
**
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
** underlying native file handle associated with a file handle. This file
** control interprets its argument as a pointer to a native file handle and
** writes the resulting value there.
**
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
** opcode causes the xFileControl method to swap the file handle with the one
** pointed to by the pArg argument. This capability is used during testing
** and only needs to be supported when SQLITE_TEST is defined.
**
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
** be advantageous to block on the next WAL lock if the lock is not immediately
** available. The WAL subsystem issues this signal during rare
** circumstances in order to fix a problem with priority inversion.
** Applications should <em>not</em> use this file-control.
**
** <li>[[SQLITE_FCNTL_ZIPVFS]]
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
** VFS should return SQLITE_NOTFOUND for this opcode.
**
** <li>[[SQLITE_FCNTL_RBU]]
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
** this opcode.
** </ul>
label: code-design
** This is the implementation of a scalar SQL function used to test the
** expression parser. It should be called as follows:
**
** fts3_exprtest(<tokenizer>, <expr>, <column 1>, ...);
**
** The first argument, <tokenizer>, is the name of the fts3 tokenizer used
** to parse the query expression (see README.tokenizers). The second argument
** is the query expression to parse. Each subsequent argument is the name
** of a column of the fts3 table that the query expression may refer to.
** For example:
**
** SELECT fts3_exprtest('simple', 'Bill col2:Bloggs', 'col1', 'col2');
Checksum of string zMaster
OUT: True if plan uses an IN(...) op
Initial size of write buffer
Data is coming from a SELECT or from a multi-row VALUES clause.
** Generate a co-routine to run the SELECT.
Index of a mem5.aPool[] slot
Page number of the frame
** 2015-03-02
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code that is specific to Wind River's VxWorks
Statement to iterate through segments
Operator for the combined expression
Unique file ID
** This routine sets the progress callback for an Sqlite database to the
** given callback function with the given argument. The progress callback will
** be invoked every nOps opcodes.
If values are not available for all fields of the index to the left
** of this one, no estimate can be made. Return SQLITE_NOTFOUND.
If triggers are not supported by this compile then the statement machine
** used to detect the end of a statement is much simpler
Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined.
Default values for second and subsequent columns need to match.
expr ::= expr PLUS|MINUS expr
conch host and lock path match
OUT: Rank function name
ifndef SQLITE_OMIT_TRIGGER
Checksum based on contents of indexes
Number of indices
Database name (e.g. "main")
770
EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
** single argument which is a pointer to an sqlite3_pcache_methods2
** object. SQLite copies of the current page cache implementation into
** that object.
Only delete if aRegIdx!=0 && aRegIdx[i]>0
** The input, pIn, is a binary tree (or subtree) of RowSetEntry objects.
** Convert this tree into a linked list connected by the pRight pointers
** and return pointers to the first and last elements of the new list.
Allocated size of aFirst[]
SELECT used to determine types and collations
** Make sure pMem->z points to a writable allocation of at least
** min(n,32) bytes.
**
** If the bPreserve argument is true, then copy of the content of
** pMem->z into the new allocation. pMem must be either a string or
** blob if bPreserve is true. If bPreserve is false, any prior content
** in pMem->z is discarded.
If we reach this points it means that the new candidate path
** needs to be added to the set of best-so-far paths.
comment:
** CAPI3REF: Compiling An SQL Statement
** KEYWORDS: {SQL statement compiler}
** METHOD: sqlite3
** CONSTRUCTOR: sqlite3_stmt
**
** To execute an SQL statement, it must first be compiled into a byte-code
** program using one of these routines. Or, in other words, these routines
** are constructors for the [prepared statement] object.
**
** The preferred routine to use is [sqlite3_prepare_v2()]. The
** [sqlite3_prepare()] interface is legacy and should be avoided.
** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
** for special purposes.
**
** The use of the UTF-8 interfaces is preferred, as SQLite currently
** does all parsing using UTF-8. The UTF-16 interfaces are provided
** as a convenience. The UTF-16 interfaces work by converting the
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
**
** The first argument, "db", is a [database connection] obtained from a
** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
** [sqlite3_open16()]. The database connection must not have been closed.
**
** The second argument, "zSql", is the statement to be compiled, encoded
** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),
** and sqlite3_prepare_v3()
** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
** and sqlite3_prepare16_v3() use UTF-16.
**
** ^If the nByte argument is negative, then zSql is read up to the
** first zero terminator. ^If nByte is positive, then it is the
** number of bytes read from zSql. ^If nByte is zero, then no prepared
** statement is generated.
** If the caller knows that the supplied string is nul-terminated, then
** there is a small performance advantage to passing an nByte parameter that
** is the number of bytes in the input string <i>including</i>
** the nul-terminator.
**
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
** past the end of the first SQL statement in zSql. These routines only
** compile the first statement in zSql, so *pzTail is left pointing to
** what remains uncompiled.
**
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
** to NULL. ^If the input text contains no SQL (if the input is an empty
** string or a comment) then *ppStmt is set to NULL.
** The calling procedure is responsible for deleting the compiled
** SQL statement using [sqlite3_finalize()] after it has finished with it.
** ppStmt may not be NULL.
**
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
** otherwise an [error code] is returned.
**
** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
** are retained for backwards compatibility, but their use is discouraged.
** ^In the "vX" interfaces, the prepared statement
** that is returned (the [sqlite3_stmt] object) contains a copy of the
** original SQL text. This causes the [sqlite3_step()] interface to
** behave differently in three ways:
**
** <ol>
** <li>
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
** always used to do, [sqlite3_step()] will automatically recompile the SQL
** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
** retries will occur before sqlite3_step() gives up and returns an error.
** </li>
**
** <li>
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
** [error codes] or [extended error codes]. ^The legacy behavior was that
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
** and the application would have to make a second call to [sqlite3_reset()]
** in order to find the underlying cause of the problem. With the "v2" prepare
** interfaces, the underlying reason for the error is returned immediately.
** </li>
**
** <li>
** ^If the specific value bound to [parameter | host parameter] in the
** WHERE clause might influence the choice of query plan for a statement,
** then the statement will be automatically recompiled, as if there had been
** a schema change, on the first [sqlite3_step()] call following any change
** to the [sqlite3_bind_text | bindings] of that [parameter].
** ^The specific value of WHERE-clause [parameter] might influence the
** choice of query plan if the parameter is the left-hand side of a [LIKE]
** or [GLOB] operator or if the parameter is compared to an indexed column
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
** </li>
**
** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
** the extra prepFlags parameter, which is a bit array consisting of zero or
** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The
** sqlite3_prepare_v2() interface works exactly the same as
** sqlite3_prepare_v3() with a zero prepFlags parameter.
** </ol>
label: code-design
There is no prefix-length field for first term in a node
Term to compare to
Write new OR root to *(*ppOr)++
Register keeping track of errors remaining
Estimated output rows per loop
298
Number terms in the ORDER BY clause
comment:
** CAPI3REF: Configuration Options
** KEYWORDS: {configuration option}
**
** These constants are the available integer configuration options that
** can be passed as the first argument to the [sqlite3_config()] interface.
**
** New configuration options may be added in future releases of SQLite.
** Existing configuration options might be discontinued. Applications
** should check the return code from [sqlite3_config()] to make sure that
** the call worked. The [sqlite3_config()] interface will return a
** non-zero [error code] if a discontinued or unsupported configuration option
** is invoked.
**
** <dl>
** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Single-thread. In other words, it disables
** all mutexing and puts SQLite into a mode where it can only be used
** by a single thread. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to change the [threading mode] from its default
** value of Single-thread and so [sqlite3_config()] will return
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
** configuration option.</dd>
**
** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Multi-thread. In other words, it disables
** mutexing on [database connection] and [prepared statement] objects.
** The application is responsible for serializing access to
** [database connections] and [prepared statements]. But other mutexes
** are enabled so that SQLite will be safe to use in a multi-threaded
** environment as long as no two threads attempt to use the same
** [database connection] at the same time. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to set the Multi-thread [threading mode] and
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
**
** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Serialized. In other words, this option enables
** all mutexes including the recursive
** mutexes on [database connection] and [prepared statement] objects.
** In this mode (which is the default when SQLite is compiled with
** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
** to [database connections] and [prepared statements] so that the
** application is free to use the same [database connection] or the
** same [prepared statement] in different threads at the same time.
** ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to set the Serialized [threading mode] and
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
**
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
** a pointer to an instance of the [sqlite3_mem_methods] structure.
** The argument specifies
** alternative low-level memory allocation routines to be used in place of
** the memory allocation routines built into SQLite.)^ ^SQLite makes
** its own private copy of the content of the [sqlite3_mem_methods] structure
** before the [sqlite3_config()] call returns.</dd>
**
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
** The [sqlite3_mem_methods]
** structure is filled with the currently defined memory allocation routines.)^
** This option can be used to overload the default memory allocation
** routines with a wrapper that simulations memory allocation failure or
** tracks memory usage, for example. </dd>
**
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
** interpreted as a boolean, which enables or disables the collection of
** memory allocation statistics. ^(When memory allocation statistics are
** disabled, the following SQLite interfaces become non-operational:
** <ul>
** <li> [sqlite3_memory_used()]
** <li> [sqlite3_memory_highwater()]
** <li> [sqlite3_soft_heap_limit64()]
** <li> [sqlite3_status64()]
** </ul>)^
** ^Memory allocation statistics are enabled by default unless SQLite is
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
** allocation statistics are disabled by default.
** </dd>
**
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
** that SQLite can use for scratch memory. ^(There are three arguments
** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
** aligned memory buffer from which the scratch allocations will be
** drawn, the size of each scratch allocation (sz),
** and the maximum number of scratch allocations (N).)^
** The first argument must be a pointer to an 8-byte aligned buffer
** of at least sz*N bytes of memory.
** ^SQLite will not use more than one scratch buffers per thread.
** ^SQLite will never request a scratch buffer that is more than 6
** times the database page size.
** ^If SQLite needs needs additional
** scratch memory beyond what is provided by this configuration option, then
** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
** ^When the application provides any amount of scratch memory using
** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
** [sqlite3_malloc|heap allocations].
** This can help [Robson proof|prevent memory allocation failures] due to heap
** fragmentation in low-memory embedded systems.
** </dd>
**
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
** that SQLite can use for the database page cache with the default page
** cache implementation.
** This configuration option is a no-op if an application-define page
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
** and the number of cache lines (N).
** The sz argument should be the size of the largest database page
** (a power of two between 512 and 65536) plus some extra bytes for each
** page header. ^The number of extra bytes needed by the page header
** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
** ^It is harmless, apart from the wasted memory,
** for the sz parameter to be larger than necessary. The pMem
** argument must be either a NULL pointer or a pointer to an 8-byte
** aligned block of memory of at least sz*N bytes, otherwise
** subsequent behavior is undefined.
** ^When pMem is not NULL, SQLite will strive to use the memory provided
** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
** a page cache line is larger than sz bytes or if all of the pMem buffer
** is exhausted.
** ^If pMem is NULL and N is non-zero, then each database connection
** does an initial bulk allocation for page cache memory
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
** of -1024*N bytes if N is negative, . ^If additional
** page cache memory is needed beyond what is provided by the initial
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
** additional cache line. </dd>
**
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
** that SQLite will use for all of its dynamic memory allocation needs
** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
** [SQLITE_CONFIG_PAGECACHE].
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
** [SQLITE_ERROR] if invoked otherwise.
** ^There are three arguments to SQLITE_CONFIG_HEAP:
** An 8-byte aligned pointer to the memory,
** the number of bytes in the memory buffer, and the minimum allocation size.
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
** to using its default memory allocator (the system malloc() implementation),
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
** memory pointer is not NULL then the alternative memory
** allocator is engaged to handle all of SQLites memory allocation needs.
** The first pointer (the memory pointer) must be aligned to an 8-byte
** boundary or subsequent behavior of SQLite will be undefined.
** The minimum allocation size is capped at 2**12. Reasonable values
** for the minimum allocation size are 2**5 through 2**8.</dd>
**
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
** pointer to an instance of the [sqlite3_mutex_methods] structure.
** The argument specifies alternative low-level mutex routines to be used
** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
** the content of the [sqlite3_mutex_methods] structure before the call to
** [sqlite3_config()] returns. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** the entire mutexing subsystem is omitted from the build and hence calls to
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
** return [SQLITE_ERROR].</dd>
**
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
** [sqlite3_mutex_methods]
** structure is filled with the currently defined mutex routines.)^
** This option can be used to overload the default mutex allocation
** routines with a wrapper used to track mutex usage for performance
** profiling or testing, for example. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** the entire mutexing subsystem is omitted from the build and hence calls to
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
** return [SQLITE_ERROR].</dd>
**
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
** the default size of lookaside memory on each [database connection].
** The first argument is the
** size of each lookaside buffer slot and the second is the number of
** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
** option to [sqlite3_db_config()] can be used to change the lookaside
** configuration on individual connections.)^ </dd>
**
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
** the interface to a custom page cache implementation.)^
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
**
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
** the current page cache implementation into that object.)^ </dd>
**
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
** global [error log].
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
** function with a call signature of void(*)(void*,int,const char*),
** and a pointer to void. ^If the function pointer is not NULL, it is
** invoked by [sqlite3_log()] to process each logging event. ^If the
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
** passed through as the first parameter to the application-defined logger
** function whenever that function is invoked. ^The second parameter to
** the logger function is a copy of the first parameter to the corresponding
** [sqlite3_log()] call and is intended to be a [result code] or an
** [extended result code]. ^The third parameter passed to the logger is
** log message after formatting via [sqlite3_snprintf()].
** The SQLite logging interface is not reentrant; the logger function
** supplied by the application must not invoke any SQLite interface.
** In a multi-threaded application, the application-defined logger
** function must be threadsafe. </dd>
**
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
** If non-zero, then URI handling is globally enabled. If the parameter is zero,
** then URI handling is globally disabled.)^ ^If URI handling is globally
** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
** [sqlite3_open16()] or
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
** connection is opened. ^If it is globally disabled, filenames are
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
** database connection is opened. ^(By default, URI handling is globally
** disabled. The default value may be changed by compiling with the
** [SQLITE_USE_URI] symbol defined.)^
**
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
** argument which is interpreted as a boolean in order to enable or disable
** the use of covering indices for full table scans in the query optimizer.
** ^The default setting is determined
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
** if that compile-time option is omitted.
** The ability to disable the use of covering indices for full table scans
** is because some incorrectly coded legacy applications might malfunction
** when the optimization is enabled. Providing the ability to
** disable the optimization allows the older, buggy application code to work
** without change even with newer versions of SQLite.
**
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
** <dd> These options are obsolete and should not be used by new code.
** They are retained for backwards compatibility but are now no-ops.
** </dd>
**
** [[SQLITE_CONFIG_SQLLOG]]
** <dt>SQLITE_CONFIG_SQLLOG
** <dd>This option is only available if sqlite is compiled with the
** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
** The second should be of type (void*). The callback is invoked by the library
** in three separate circumstances, identified by the value passed as the
** fourth parameter. If the fourth parameter is 0, then the database connection
** passed as the second argument has just been opened. The third argument
** points to a buffer containing the name of the main database file. If the
** fourth parameter is 1, then the SQL statement that the third parameter
** points to has just been executed. Or, if the fourth parameter is 2, then
** the connection being passed as the second parameter is being closed. The
** third parameter is passed NULL In this case. An example of using this
** configuration option can be seen in the "test_sqllog.c" source file in
** the canonical SQLite source tree.</dd>
**
** [[SQLITE_CONFIG_MMAP_SIZE]]
** <dt>SQLITE_CONFIG_MMAP_SIZE
** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
** that are the default mmap size limit (the default setting for
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
** ^The default setting can be overridden by each database connection using
** either the [PRAGMA mmap_size] command, or by using the
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
** will be silently truncated if necessary so that it does not exceed the
** compile-time maximum mmap size set by the
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
** ^If either argument to this option is negative, then that argument is
** changed to its compile-time default.
**
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
** that specifies the maximum size of the created heap.
**
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
** is a pointer to an integer and writes into that integer the number of extra
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
** The amount of extra space required can change depending on the compiler,
** target platform, and SQLite version.
**
** [[SQLITE_CONFIG_PMASZ]]
** <dt>SQLITE_CONFIG_PMASZ
** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
** sorter to that integer. The default minimum PMA Size is set by the
** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
** to help with sort operations when multithreaded sorting
** is enabled (using the [PRAGMA threads] command) and the amount of content
** to be sorted exceeds the page size times the minimum of the
** [PRAGMA cache_size] setting and this value.
**
** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
** becomes the [statement journal] spill-to-disk threshold.
** [Statement journals] are held in memory until their size (in bytes)
** exceeds this threshold, at which point they are written to disk.
** Or if the threshold is -1, statement journals are always held
** exclusively in memory.
** Since many statement journals never become large, setting the spill
** threshold to a value such as 64KiB can greatly reduce the amount of
** I/O required to support statement rollback.
** The default value for this setting is controlled by the
** [SQLITE_STMTJRNL_SPILL] compile-time option.
** </dl>
label: code-design
One of the uses of pBt->pTmpSpace is to format cells before
** inserting them into a leaf page (function fillInCell()). If
** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
** by the various routines that manipulate binary cells. Which
** can mean that fillInCell() only initializes the first 2 or 3
** bytes of pTmpSpace, but that the first 4 bytes are copied from
** it into a database page. This is not actually a problem, but it
** does cause a valgrind error when the 1 or 2 bytes of unitialized
** data is passed to system call write(). So to avoid this error,
** zero the first 4 bytes of temp space here.
**
** Also: Provide four bytes of initialized space before the
** beginning of pTmpSpace as an area available to prepend the
** left-child pointer to the beginning of a cell.
** Trigger the alarm
** Invoke a virtual table constructor (either xCreate or xConnect). The
** pointer to the function to invoke is passed as the fourth parameter
** to this procedure.
!defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
Ticket #2804: When we open a database in the newer file format,
** clear the legacy_file_format pragma flag so that a VACUUM will
** not downgrade the database and thus invalidate any descending
** indices that the user might have created.
MATCH => ID
** Insert a record into the %_segdir table.
310
Knuth multiplicative hashing. (Sorting & Searching, p. 510).
** 0x9e3779b1 is 2654435761 which is the closest prime number to
** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
comment: TODO: Check if all of these are really required.
label: requirement
The journal file needs to be opened. Higher level routines have already
** obtained the necessary locks to begin the write-transaction, but the
** rollback journal might not yet be open. Open it now if this is the case.
**
** This is done before calling sqlite3PcacheMakeDirty() on the page.
** Otherwise, if it were done after calling sqlite3PcacheMakeDirty(), then
** an error might occur and the pager would end up in WRITER_LOCKED state
** with pages marked as dirty in the cache.
Location of new mapping
Size information about the cell
** Register a collation sequence factory callback with the database handle
** db. Replace any previously installed collation sequence factory.
Write the number of columns here
38..3f 89:;<=>?
(288) nm ::= JOIN_KW
True if range start uses ==, >= or <=
comment:
** The Pager.eLock variable is almost always set to one of the
** following locking-states, according to the lock currently held on
** the database file: NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
** This variable is kept up to date as locks are taken and released by
** the pagerLockDb() and pagerUnlockDb() wrappers.
**
** If the VFS xLock() or xUnlock() returns an error other than SQLITE_BUSY
** (i.e. one of the SQLITE_IOERR subtypes), it is not clear whether or not
** the operation was successful. In these circumstances pagerLockDb() and
** pagerUnlockDb() take a conservative approach - eLock is always updated
** when unlocking the file, and only updated when locking the file if the
** VFS call is successful. This way, the Pager.eLock variable may be set
** to a less exclusive (lower) value than the lock that is actually held
** at the system level, but it is never set to a more exclusive value.
**
** This is usually safe. If an xUnlock fails or appears to fail, there may
** be a few redundant xLock() calls or a lock may be held for longer than
** required, but nothing really goes wrong.
**
** The exception is when the database file is unlocked as the pager moves
** from ERROR to OPEN state. At this point there may be a hot-journal file
** in the file-system that needs to be rolled back (as part of an OPEN->SHARED
** transition, by the same pager or any other). If the call to xUnlock()
** fails at this point and the pager is left holding an EXCLUSIVE lock, this
** can confuse the call to xCheckReservedLock() call made later as part
** of hot-journal detection.
**
** xCheckReservedLock() is defined as returning true "if there is a RESERVED
** lock held by this process or any others". So xCheckReservedLock may
** return true because the caller itself is holding an EXCLUSIVE lock (but
** doesn't know it because of a previous error in xUnlock). If this happens
** a hot-journal may be mistaken for a journal being created by an active
** transaction in another process, causing SQLite to read from the database
** without rolling it back.
**
** To work around this, if a call to xUnlock() fails when unlocking the
** database in the ERROR state, Pager.eLock is set to UNKNOWN_LOCK. It
** is only changed back to a real locking state after a successful call
** to xLock(EXCLUSIVE). Also, the code to do the OPEN->SHARED state transition
** omits the check for a hot-journal if Pager.eLock is set to UNKNOWN_LOCK
** lock. Instead, it assumes a hot-journal exists and obtains an EXCLUSIVE
** lock on the database file before attempting to roll it back. See function
** PagerSharedLock() for more detail.
**
** Pager.eLock may only be set to UNKNOWN_LOCK when the pager is in
** PAGER_OPEN state.
label: code-design
Begin the database scan.
This routine has been called to create an automatic index as a
** result of a PRIMARY KEY or UNIQUE clause on a column definition, or
** a PRIMARY KEY or UNIQUE clause following the column definitions.
** i.e. one of:
**
** CREATE TABLE t(x PRIMARY KEY, y);
** CREATE TABLE t(x, y, UNIQUE(x, y));
**
** Either way, check to see if the table already has such an index. If
** so, don't bother creating this one. This only applies to
** automatically created indices. Users can do as they wish with
** explicit indices.
**
** Two UNIQUE or PRIMARY KEY constraints are considered equivalent
** (and thus suppressing the second one) even if they have different
** sort orders.
**
** If there are different collating sequences or if the columns of
** the constraint occur in different orders, then the constraints are
** considered distinct and both result in separate indices.
Message from strerror() or equivalent
** Increase the reference count of a supplied page by 1.
If the file is a temp-file has not yet been opened, open it now. It
** is not possible for rc to be other than SQLITE_OK if this branch
** is taken, as pager_wait_on_lock() is a no-op for temp-files.
10, 9, 8, 7, 6
Dequoted name of collation sequence
** Implementation of the total_changes() SQL function. The return value is
** the same as the sqlite3_total_changes() API function.
Number of bytes in a page
List of tables in the join
xConnect
Values between 0 and 127
** 2009 Nov 12
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
id that may be used to recursive triggers
comment: A malloc() may have failed within the call to sqlite3_value_text16()
** above. If this is the case, then the db->mallocFailed flag needs to
** be cleared before returning. Do this directly, instead of via
** sqlite3ApiExit(), to avoid setting the database handle error message.
label: code-design
Number of winShm objects pointing to this
** Change the default pages size and the number of reserved bytes per page.
** Or, if the page size has already been fixed, return SQLITE_READONLY
** without changing anything.
**
** The page size must be a power of 2 between 512 and 65536. If the page
** size supplied does not meet this constraint then the page size is not
** changed.
**
** Page sizes are constrained to be a power of two so that the region
** of the database file used for locking (beginning at PENDING_BYTE,
** the first byte past the 1GB boundary, 0x40000000) needs to occur
** at the beginning of a page.
**
** If parameter nReserve is less than zero, then the number of reserved
** bytes per page is left unchanged.
**
** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size
** and autovacuum mode can no longer be changed.
Output variables
At this point, if the literal was an integer, the parse is
** finished. Or, if it is a floating point value, it may continue
** with either a decimal point or an 'E' character.
******* End of fts5.h ********
Set the foreign key value to its default
comment:
** SUMMARY
**
** Writing a transaction containing a large number of operations on
** b-tree indexes that are collectively larger than the available cache
** memory can be very inefficient.
**
** The problem is that in order to update a b-tree, the leaf page (at least)
** containing the entry being inserted or deleted must be modified. If the
** working set of leaves is larger than the available cache memory, then a
** single leaf that is modified more than once as part of the transaction
** may be loaded from or written to the persistent media multiple times.
** Additionally, because the index updates are likely to be applied in
** random order, access to pages within the database is also likely to be in
** random order, which is itself quite inefficient.
**
** One way to improve the situation is to sort the operations on each index
** by index key before applying them to the b-tree. This leads to an IO
** pattern that resembles a single linear scan through the index b-tree,
** and all but guarantees each modified leaf page is loaded and stored
** exactly once. SQLite uses this trick to improve the performance of
** CREATE INDEX commands. This extension allows it to be used to improve
** the performance of large transactions on existing databases.
**
** Additionally, this extension allows the work involved in writing the
** large transaction to be broken down into sub-transactions performed
** sequentially by separate processes. This is useful if the system cannot
** guarantee that a single update process will run for long enough to apply
** the entire update, for example because the update is being applied on a
** mobile device that is frequently rebooted. Even after the writer process
** has committed one or more sub-transactions, other database clients continue
** to read from the original database snapshot. In other words, partially
** applied transactions are not visible to other clients.
**
** "RBU" stands for "Resumable Bulk Update". As in a large database update
** transmitted via a wireless network to a mobile device. A transaction
** applied using this extension is hence refered to as an "RBU update".
**
**
** LIMITATIONS
**
** An "RBU update" transaction is subject to the following limitations:
**
** * The transaction must consist of INSERT, UPDATE and DELETE operations
** only.
**
** * INSERT statements may not use any default values.
**
** * UPDATE and DELETE statements must identify their target rows by
** non-NULL PRIMARY KEY values. Rows with NULL values stored in PRIMARY
** KEY fields may not be updated or deleted. If the table being written
** has no PRIMARY KEY, affected rows must be identified by rowid.
**
** * UPDATE statements may not modify PRIMARY KEY columns.
**
** * No triggers will be fired.
**
** * No foreign key violations are detected or reported.
**
** * CHECK constraints are not enforced.
**
** * No constraint handling mode except for "OR ROLLBACK" is supported.
**
**
** PREPARATION
**
** An "RBU update" is stored as a separate SQLite database. A database
** containing an RBU update is an "RBU database". For each table in the
** target database to be updated, the RBU database should contain a table
** named "data_<target name>" containing the same set of columns as the
** target table, and one more - "rbu_control". The data_% table should
** have no PRIMARY KEY or UNIQUE constraints, but each column should have
** the same type as the corresponding column in the target database.
** The "rbu_control" column should have no type at all. For example, if
** the target database contains:
**
** CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
**
** Then the RBU database should contain:
**
** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
**
** The order of the columns in the data_% table does not matter.
**
** Instead of a regular table, the RBU database may also contain virtual
** tables or view named using the data_<target> naming scheme.
**
** Instead of the plain data_<target> naming scheme, RBU database tables
** may also be named data<integer>_<target>, where <integer> is any sequence
** of zero or more numeric characters (0-9). This can be significant because
** tables within the RBU database are always processed in order sorted by
** name. By judicious selection of the <integer> portion of the names
** of the RBU tables the user can therefore control the order in which they
** are processed. This can be useful, for example, to ensure that "external
** content" FTS4 tables are updated before their underlying content tables.
**
** If the target database table is a virtual table or a table that has no
** PRIMARY KEY declaration, the data_% table must also contain a column
** named "rbu_rowid". This column is mapped to the tables implicit primary
** key column - "rowid". Virtual tables for which the "rowid" column does
** not function like a primary key value cannot be updated using RBU. For
** example, if the target db contains either of the following:
**
** CREATE VIRTUAL TABLE x1 USING fts3(a, b);
** CREATE TABLE x1(a, b)
**
** then the RBU database should contain:
**
** CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
**
** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
** target table must be present in the input table. For virtual tables,
** hidden columns are optional - they are updated by RBU if present in
** the input table, or not otherwise. For example, to write to an fts4
** table with a hidden languageid column such as:
**
** CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
**
** Either of the following input table schemas may be used:
**
** CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
** CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
**
** For each row to INSERT into the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 0. The
** other columns should be set to the values that make up the new record
** to insert.
**
** If the target database table has an INTEGER PRIMARY KEY, it is not
** possible to insert a NULL value into the IPK column. Attempting to
** do so results in an SQLITE_MISMATCH error.
**
** For each row to DELETE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 1. The
** real primary key values of the row to delete should be stored in the
** corresponding columns of the data_% table. The values stored in the
** other columns are not used.
**
** For each row to UPDATE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain a value of type text.
** The real primary key values identifying the row to update should be
** stored in the corresponding columns of the data_% table row, as should
** the new values of all columns being update. The text value in the
** "rbu_control" column must contain the same number of characters as
** there are columns in the target database table, and must consist entirely
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
** each column that is being updated, the corresponding character is set to
** 'x'. For those that remain as they are, the corresponding character of the
** rbu_control value should be set to '.'. For example, given the tables
** above, the update statement:
**
** UPDATE t1 SET c = 'usa' WHERE a = 4;
**
** is represented by the data_t1 row created by:
**
** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x');
**
** Instead of an 'x' character, characters of the rbu_control value specified
** for UPDATEs may also be set to 'd'. In this case, instead of updating the
** target table with the value stored in the corresponding data_% column, the
** user-defined SQL function "rbu_delta()" is invoked and the result stored in
** the target table column. rbu_delta() is invoked with two arguments - the
** original value currently stored in the target table column and the
** value specified in the data_xxx table.
**
** For example, this row:
**
** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
**
** is similar to an UPDATE statement such as:
**
** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
**
** Finally, if an 'f' character appears in place of a 'd' or 's' in an
** ota_control string, the contents of the data_xxx table column is assumed
** to be a "fossil delta" - a patch to be applied to a blob value in the
** format used by the fossil source-code management system. In this case
** the existing value within the target database table must be of type BLOB.
** It is replaced by the result of applying the specified fossil delta to
** itself.
**
** If the target database table is a virtual table or a table with no PRIMARY
** KEY, the rbu_control value should not include a character corresponding
** to the rbu_rowid value. For example, this:
**
** INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
** VALUES(NULL, 'usa', 12, '.x');
**
** causes a result similar to:
**
** UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
**
** The data_xxx tables themselves should have no PRIMARY KEY declarations.
** However, RBU is more efficient if reading the rows in from each data_xxx
** table in "rowid" order is roughly the same as reading them sorted by
** the PRIMARY KEY of the corresponding target database table. In other
** words, rows should be sorted using the destination table PRIMARY KEY
** fields before they are inserted into the data_xxx tables.
**
** USAGE
**
** The API declared below allows an application to apply an RBU update
** stored on disk to an existing target database. Essentially, the
** application:
**
** 1) Opens an RBU handle using the sqlite3rbu_open() function.
**
** 2) Registers any required virtual table modules with the database
** handle returned by sqlite3rbu_db(). Also, if required, register
** the rbu_delta() implementation.
**
** 3) Calls the sqlite3rbu_step() function one or more times on
** the new handle. Each call to sqlite3rbu_step() performs a single
** b-tree operation, so thousands of calls may be required to apply
** a complete update.
**
** 4) Calls sqlite3rbu_close() to close the RBU update handle. If
** sqlite3rbu_step() has been called enough times to completely
** apply the update to the target database, then the RBU database
** is marked as fully applied. Otherwise, the state of the RBU
** update application is saved in the RBU database for later
** resumption.
**
** See comments below for more detail on APIs.
**
** If an update is only partially applied to the target database by the
** time sqlite3rbu_close() is called, various state information is saved
** within the RBU database. This allows subsequent processes to automatically
** resume the RBU update from where it left off.
**
** To remove all RBU extension state information, returning an RBU database
** to its original contents, it is sufficient to drop all tables that begin
** with the prefix "rbu_"
**
** DATABASE LOCKING
**
** An RBU update may not be applied to a database in WAL mode. Attempting
** to do so is an error (SQLITE_ERROR).
**
** While an RBU handle is open, a SHARED lock may be held on the target
** database file. This means it is possible for other clients to read the
** database, but not to write it.
**
** If an RBU update is started and then suspended before it is completed,
** then an external client writes to the database, then attempting to resume
** the suspended RBU update is also an error (SQLITE_BUSY).
label: code-design
** An instance of the following object is used to read records out of a
** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
** aKey might point into aMap or into aBuffer. If neither of those locations
** contain a contiguous representation of the key, then aAlloc is allocated
** and the key is copied into aAlloc and aKey is made to poitn to aAlloc.
**
** pFd==0 at EOF.
ANALYZE => ID
** Return meta information about a specific column of a database table.
** See comment in sqlite3.h (sqlite.h.in) for details.
Naming context
Offset within poslist
Do not attempt to process this query if there are an WITH clauses
** attached to it. Proceeding may generate a false "no such table: xxx"
** error if pSelect reads from a CTE named "xxx".
Generate code that runs whenever the GROUP BY changes.
** Changes in the GROUP BY are detected by the previous code
** block. If there were no changes, this block is skipped.
**
** This code copies current group by terms in b0,b1,b2,...
** over to a0,a1,a2. It then calls the output subroutine
** and resets the aggregate accumulator registers in preparation
** for the next GROUP BY batch.
Number of elements in a bitmap array.
Configured "cache_size" value
comment: Comment to improve readability
label: code-design
Jump to here if a malloc() fails.
** CAPI3REF: Custom Page Cache Object
**
** The sqlite3_pcache_page object represents a single page in the
** page cache. The page cache will allocate instances of this
** object. Various methods of the page cache use pointers to instances
** of this object as parameters or as their return value.
**
** See [sqlite3_pcache_methods2] for additional information.
Check the integrity of the freelist
comment: Bytes of opcode memory used
label: code-design
Column into which text is being inserted
We have already reached the end of this doclist. EOF.
LIKE
Information used during initialization
The WHERE clause. May be null
Configuration object to update
Find the root of the NEAR expression
Number of instructions in the program
Usable bytes per page
Check that zKey/nKey is larger than the largest key the candidate
SQLITE_EMPTY
** This routine is a Walker callback for "expanding" a SELECT statement.
** "Expanding" means to do the following:
**
** (1) Make sure VDBE cursor numbers have been assigned to every
** element of the FROM clause.
**
** (2) Fill in the pTabList->a[].pTab fields in the SrcList that
** defines FROM clause. When views appear in the FROM clause,
** fill pTabList->a[].pSelect with a copy of the SELECT statement
** that implements the view. A copy is made of the view's SELECT
** statement so that we can freely modify or delete that statement
** without worrying about messing up the persistent representation
** of the view.
**
** (3) Add terms to the WHERE clause to accommodate the NATURAL keyword
** on joins and the ON and USING clause of joins.
**
** (4) Scan the list of columns in the result set (pEList) looking
** for instances of the "*" operator or the TABLE.* operator.
** If found, expand each "*" to be every column in every table
** and TABLE.* to be every column in TABLE.
**
The table from which rows are deleted
If the write version is set to 2, this database should be accessed
** in WAL mode. If the log is not already open, open it now. Then
** return SQLITE_OK and return without populating BtShared.pPage1.
** The caller detects this and calls this function again. This is
** required as the version of page 1 currently in the page1 buffer
** may not be the latest version - there may be a newer one in the log
** file.
** Invoke the destructor function associated with FuncDef p, if any. Except,
** if this is not the last copy of the function, do not invoke it. Multiple
** copies of a single function are created when create_function() is called
** with SQLITE_ANY as the encoding.
This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
** below would return the same value.
A-overwrites-B
** This function is called from within a pre-update callback to retrieve
** the number of columns in the row being updated, deleted or inserted.
Handle to return
xRandomness
Context pointer for xCreate/xConnect
Delete the index and table entries. Skip this step if pTab is really
** a view (in which case the only effect of the DELETE statement is to
** fire the INSTEAD OF triggers).
**
** If variable 'count' is non-zero, then this OP_Delete instruction should
** invoke the update-hook. The pre-update-hook, on the other hand should
** be invoked unless table pTab is a system table. The difference is that
** the update-hook is not invoked for rows removed by REPLACE, but the
** pre-update-hook is.
** This function is only called from with a pre-update-hook reporting a
** change on table pTab (attached to session pSession). The type of change
** (UPDATE, INSERT, DELETE) is specified by the first argument.
**
** Unless one is already present or an error occurs, an entry is added
** to the changed-rows hash table associated with table pTab.
** This function is called as part of initializing or reinitializing an
** incremental checkpoint.
**
** It populates the sqlite3rbu.aFrame[] array with the set of
** (wal frame -> db page) copy operations required to checkpoint the
** current wal file, and obtains the set of shm locks required to safely
** perform the copy operations directly on the file-system.
**
** If argument pState is not NULL, then the incremental checkpoint is
** being resumed. In this case, if the checksum of the wal-index-header
** following recovery is not the same as the checksum saved in the RbuState
** object, then the rbu handle is set to DONE state. This occurs if some
** other client appends a transaction to the wal file in the middle of
** an incremental checkpoint.
Value to return if (lhs > rhs)
** This routine generates the code for the inside of the inner loop
** of a SELECT.
**
** If srcTab is negative, then the pEList expressions
** are evaluated in order to get the data for this row. If srcTab is
** zero or more, then data is pulled from srcTab and pEList is used only
** to get the number of columns and the collation sequence for each column.
A-overwrites-Y
stmt_vtab is a subclass of sqlite3_vtab which will
** serve as the underlying representation of a stmt virtual table
Generate a coroutine to evaluate the SELECT statement to the
** left of the compound operator - the "A" select.
** The xUpdate method for rtree module virtual tables.
comment: Space for aMem[0] even if not used
label: code-design
ifndef NDEBUG
************* Begin file rowset.c *****************************************
3
0x40 .. 0x4F
** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
** computed.
If the file should be created now, create it and write the new data
** into the file on disk.
One or more aggregate functions seen
comment: If there is no IDLIST term but the table has an integer primary
** key, the set the ipkColumn variable to the integer primary key
** column index in the original table definition.
label: code-design
1560
vfs module to open wal and wal-index
Number of bytes still to come
OUT: Array of column names for table
All information about this parse
** Load pointers to all cells on sibling pages and the divider cells
** into the local b.apCell[] array. Make copies of the divider cells
** into space obtained from aSpace1[]. The divider cells have already
** been removed from pParent.
**
** If the siblings are on leaf pages, then the child pointers of the
** divider cells are stripped from the cells before they are copied
** into aSpace1[]. In this way, all cells in b.apCell[] are without
** child pointers. If siblings are not leaves, then all cell in
** b.apCell[] include child pointers. Either way, all cells in b.apCell[]
** are alike.
**
** leafCorrection: 4 if pPage is a leaf. 0 if pPage is not a leaf.
** leafData: 1 if pPage holds key+data and pParent holds only keys.
************* Begin file attach.c *****************************************
Return address register for output subroutine
Deep, not shallow copies
** PRAGMA [schema.]max_page_count
** PRAGMA [schema.]max_page_count=N
**
** The first form reports the current setting for the
** maximum number of pages in the database file. The
** second form attempts to change this setting. Both
** forms return the current setting.
**
** The absolute value of N is used. This is undocumented and might
** change. The only purpose is to provide an easy way to test
** the sqlite3AbsInt32() function.
**
** PRAGMA [schema.]page_count
**
** Return the number of pages in the specified database.
SQLITE_MIGHT_BE_SINGLE_CORE
** An instance of the following structure holds the context of a
** sum() or avg() aggregate computation.
Name of column in zTo. If NULL use PRIMARY KEY
Hash table of tokenizers
************* Begin file table.c ******************************************
Phrase to return doclist for
** Fts5SegIter.iLeafOffset currently points to the first byte of a
** position-list size field. Read the value of the field and store it
** in the following variables:
**
** Fts5SegIter.nPos
** Fts5SegIter.bDel
**
** Leave Fts5SegIter.iLeafOffset pointing to the first byte of the
** position list content (if any).
** The xRelease() method.
**
** This is a no-op.
** Let V[] be an array of unsigned characters sufficient to hold
** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
** Then the following macros can be used to set, clear, or test
** individual bits within V.
** Attempt to set the maximum database page count if mxPage is positive.
** Make no changes if mxPage is zero or negative. And never reduce the
** maximum page count below the current size of the database.
**
** Regardless of mxPage, return the current maximum page count.
************* Continuing where we left off in os.h ************************
Used by: index_list
** Initialize PmaReader pReadr to scan through the PMA stored in file pFile
** starting at offset iStart and ending at offset iEof-1. This function
** leaves the PmaReader pointing to the first key in the PMA (or EOF if the
** PMA is empty).
**
** If the pnByte parameter is NULL, then it is assumed that the file
** contains a single PMA, and that that PMA omits the initial length varint.
WhereLoop.u.vtab is valid
If the inner loop is driven by an index such that values from
** the same iteration of the inner loop are in sorted order, then
** immediately jump to the next iteration of an inner loop if the
** entry from the current iteration does not fit into the top
** LIMIT+OFFSET entries of the sorter.
17
The FROM clause
Array of flags, set on indexed & PK cols
** This is a comparison function used as a qsort() callback when sorting
** an array of pending terms by term. This occurs as part of flushing
** the contents of the pending-terms hash table to the database.
Ex
** All of the FuncDef structures in the aBuiltinFunc[] array above
** to the global function hash table. This occurs at start-time (as
** a consequence of calling sqlite3_initialize()).
**
** After this routine runs
** Table of methods for MemJournal sqlite3_file object.
SAVEPOINT => ID
The right pointer of the child page pOld becomes the left
** pointer of the divider cell
OUT: Set to true if EOF
Non-recursive mutex required to access this object
Next token type
Close all database connections
Check that all non-HIDDEN columns in the destination table are also
** present in the input table. Populate the abTblPk[], azTblType[] and
** aiTblOrder[] arrays at the same time.
SQLITE_NOTADB
2
Failed to open the file for read/write access. Try read-only.
get sign of exponent
** Return the value of a status counter for a prepared statement
Pages journalled since last j-header written
If the subquery is not correlated and if we are not inside of
** a trigger, then we only need to compute the value of the subquery
** once.
Check to see if z[0..n-1] is a keyword. If it is, write the
** parser symbol code for that keyword into *pType. Always
** return the integer n (the length of the token).
** If the expression list pEList contains more than iLimit elements,
** leave an error message in pParse.
** 2009 Oct 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
SQLITE_INTERNAL
Maximum nColumn is BMS-2, not BMS-1, so that we can compute
** BITMASK(nExpr) without overflowing
Unless the database is sharable and unlocked, then BtShared.db
** should already be set correctly.
xBestIndex
** Class derived from sqlite3_tokenizer_cursor
The binary operation
Parser state when parsing URI
SQLITE_BUSY? proxyTakeConch called
during locking
** 2017-05-31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file demonstrates an eponymous virtual table that returns information
** about all prepared statements for the database connection.
**
** Usage example:
**
** .load ./stmt
** .mode line
** .header on
** SELECT * FROM stmt;
Initialize the count of updated rows
Used by: wal_checkpoint
Used to iterate through aTC[] array.
Finally, sync the database file.
** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
** are assert() statements in the code to verify this.
**
** Value constraints (enforced via assert()):
** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
** The following macro converts a relative address in the p2 field
** of a VdbeOp structure into a negative number so that
** sqlite3VdbeAddOpList() knows that the address is relative. Calling
** the macro again restores the address.
comment: we can skip this cause it was (effectively) done above in calc'ing s
label: code-design
* Each trigger present in the database schema is stored as an instance of
* struct Trigger.
*
* Pointers to instances of struct Trigger are stored in two ways.
* 1. In the "trigHash" hash table (part of the sqlite3* that represents the
* database). This allows Trigger structures to be retrieved by name.
* 2. All triggers associated with a single table form a linked list, using the
* pNext member of struct Trigger. A pointer to the first element of the
* linked list is stored as the "pTrigger" member of the associated
* struct Table.
*
* The "step_list" member points to the first element of a linked list
* containing the SQL statements specified as the trigger program.
Checksum of last frame in log
** Delete any previous value and set the value to be a BLOB of length
** n containing all zeros.
Stat4Accum.aBest[], a[]
True if p is a compound select
** Control and query of the open file handle.
Bitmask of FROM clause terms referenced by pExpr
Token with unqualified schema object name
** Increment the reference count of node p.
The common case of ?N for a single digit N
x<EXPR or x<=EXPR constraint
List of VTable objects.
Pointer to data for string (char array) types
Use for looping over pSrcList items
0
Cursor number of pseudo-table
If changeCountDone is set, a RESERVED lock or greater must be held
** on the file.
End of the 'extern "C"' block
the table into which we are inserting
Two salt values copied from WAL header
A value was pulled from the index
** The implementation of the sqlite_record() function. This function accepts
** a single argument of any type. The return value is a formatted database
** record (a blob) containing the argument value.
**
** This is used to convert the value stored in the 'sample' column of the
** sqlite_stat3 table to the record format SQLite uses internally.
** These are definitions of bits in the WhereLoop.wsFlags field.
** The particular combination of bits in each WhereLoop help to
** determine the algorithm that WhereLoop represents.
** Convert a 64-bit IEEE double into a 64-bit signed integer.
** If the double is out of range of a 64-bit signed integer then
** return the closest available 64-bit signed integer.
If this database is not shareable, or if the client is reading
** and has the read-uncommitted flag set, then no lock is required.
** Return true immediately.
One of the PAGER_JOURNALMODE_XXX symbols
Cursors that are not yet positioned
unicode characters usable in IDs
** Lock the file with the lock specified by parameter eFileLock - one
** of the following:
**
** (1) SHARED_LOCK
** (2) RESERVED_LOCK
** (3) PENDING_LOCK
** (4) EXCLUSIVE_LOCK
**
** Sometimes when requesting one lock state, additional lock states
** are inserted in between. The locking might fail on one of the later
** transitions leaving the lock state different from what it started but
** still short of its goal. The following chart shows the allowed
** transitions and the inserted intermediate states:
**
** UNLOCKED -> SHARED
** SHARED -> RESERVED
** SHARED -> (PENDING) -> EXCLUSIVE
** RESERVED -> (PENDING) -> EXCLUSIVE
** PENDING -> EXCLUSIVE
**
** Semaphore locks only really support EXCLUSIVE locks. We track intermediate
** lock states in the sqlite3_file structure, but all locks SHARED or
** above are really EXCLUSIVE locks and exclude all other processes from
** access the file.
**
** This routine will only increase a lock. Use the sqlite3OsUnlock()
** routine to lower a locking level.
Head of in-memory chunk-list
Bytes of runtime space required for sub-program
Next available unixShm.id value
Allocate the mutex and register the new VFS (not as the default)
Begin with this column of pList
One character in z[]
** Structure used internally by this VFS to record the state of an
** open shared memory connection.
**
** The following fields are initialized when this object is created and
** are read-only thereafter:
**
** unixShm.pFile
** unixShm.id
**
** All other fields are read/write. The unixShm.pFile->mutex must be held
** while accessing any read/write fields.
Error message for circular references
** 2013 November 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code that is specific to Windows.
Filename in UTF-8 encoding
** Delete a P4 value if necessary.
Trigger to code
Which read lock is being held. -1 for none
Set the abort flag and return
#include "sqliteInt.h"
Desired amount of reserved space per page
DROP
297
Iterator handle
Name of the database file
List of tables in FROM clause
comment: The heap subsystem has now been shutdown and these values are supposed
** to be NULL or point to memory that was obtained from sqlite3_malloc(),
** which would rely on that heap subsystem; therefore, make sure these
** values cannot refer to heap memory that was just invalidated when the
** heap subsystem was shutdown. This is only done if the current call to
** this function resulted in the heap subsystem actually being shutdown.
label: code-design
** This routine is called after all of the trigger actions have been parsed
** in order to complete the process of building the trigger.
This function contains the logic that determines if a statement or
** transaction will be committed or rolled back as a result of the
** execution of this virtual machine.
**
** If any of the following errors occur:
**
** SQLITE_NOMEM
** SQLITE_IOERR
** SQLITE_FULL
** SQLITE_INTERRUPT
**
** Then the internal cache might have been left in an inconsistent
** state. We need to rollback the statement transaction, if there is
** one, or the complete transaction if there is no statement transaction.
Used for testing and analysis only
Pointer to buffer containing token
Stmt-journal spill-to-disk threshold
Number of fields in test sample
** In this implementation, error checking is provided for testing
** and debugging purposes. The mutexes still do not provide any
** mutual exclusion.
This routine is only called from the OP_JournalMode opcode, and
** the logic there will never allow a temporary file to be changed
** to WAL mode.
** Push an authorization context. After this routine is called, the
** zArg3 argument to authorization callbacks will be zContext until
** popped. Or if pParse==0, this routine is a no-op.
Number of deferred imm fk.
** Analyze a term that consists of two or more OR-connected
** subterms. So in:
**
** ... WHERE (a=5) AND (b=7 OR c=9 OR d=13) AND (d=13)
** ^^^^^^^^^^^^^^^^^^^^
**
** This routine analyzes terms such as the middle term in the above example.
** A WhereOrTerm object is computed and attached to the term under
** analysis, regardless of the outcome of the analysis. Hence:
**
** WhereTerm.wtFlags |= TERM_ORINFO
** WhereTerm.u.pOrInfo = a dynamically allocated WhereOrTerm object
**
** The term being analyzed must have two or more of OR-connected subterms.
** A single subterm might be a set of AND-connected sub-subterms.
** Examples of terms under analysis:
**
** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
** (B) x=expr1 OR expr2=x OR x=expr3
** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
** (F) x>A OR (x=A AND y>=B)
**
** CASE 1:
**
** If all subterms are of the form T.C=expr for some single column of C and
** a single table T (as shown in example B above) then create a new virtual
** term that is an equivalent IN expression. In other words, if the term
** being analyzed is:
**
** x = expr1 OR expr2 = x OR x = expr3
**
** then create a new virtual term like this:
**
** x IN (expr1,expr2,expr3)
**
** CASE 2:
**
** If there are exactly two disjuncts and one side has x>A and the other side
** has x=A (for the same x and A) then add a new virtual conjunct term to the
** WHERE clause of the form "x>=A". Example:
**
** x>A OR (x=A AND y>B) adds: x>=A
**
** The added conjunct can sometimes be helpful in query planning.
**
** CASE 3:
**
** If all subterms are indexable by a single table T, then set
**
** WhereTerm.eOperator = WO_OR
** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
**
** A subterm is "indexable" if it is of the form
** "T.C <op> <expr>" where C is any column of table T and
** <op> is one of "=", "<", "<=", ">", ">=", "IS NULL", or "IN".
** A subterm is also indexable if it is an AND of two or more
** subsubterms at least one of which is indexable. Indexable AND
** subterms have their eOperator set to WO_AND and they have
** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
**
** From another point of view, "indexable" means that the subterm could
** potentially be used with an index if an appropriate index exists.
** This analysis does not consider whether or not the index exists; that
** is decided elsewhere. This analysis only looks at whether subterms
** appropriate for indexing exist.
**
** All examples A through E above satisfy case 3. But if a term
** also satisfies case 1 (such as B) we know that the optimizer will
** always prefer case 1, so in that case we pretend that case 3 is not
** satisfied.
**
** It might be the case that multiple tables are indexable. For example,
** (E) above is indexable on tables P, Q, and R.
**
** Terms that satisfy case 3 are candidates for lookup by using
** separate indices to find rowids for each subterm and composing
** the union of all rowids using a RowSet object. This is similar
** to "bitmap indices" in other database engines.
**
** OTHERWISE:
**
** If none of cases 1, 2, or 3 apply, then leave the eOperator set to
** zero. This term is not useful for search.
tcons ::= CHECK LP expr RP onconf
84
** Clear the content of node p (set all bytes to 0x00).
Index of column in first table
The FROM clause term to process
For every "*" that occurs in the column list, insert the names of
** all columns in all tables. And for every TABLE.* insert the names
** of all columns in TABLE. The parser inserted a special expression
** with the TK_ASTERISK operator for each "*" that it found in the column
** list. The following code just has to locate the TK_ASTERISK
** expressions and expand each one to the list of all columns in
** all tables.
**
** The first loop just checks to see if there are any "*" operators
** that need expanding.
Number of registers left to copy
930
If this session is attached to a different database ("main", "temp"
** etc.), or if it is not currently enabled, there is nothing to do. Skip
** to the next session object attached to this database.
comment: We can only reach this point when reading a corrupt database
** file. In that case we are not in any hurry. Use the (relatively
** slow) general-purpose sqlite3GetVarint() routine to extract the
** value.
label: code-design
The expression to code when the VDBE initializes
comment:
** Finalize the statement passed as the second argument.
**
** If the sqlite3_finalize() call indicates that an error occurs, and the
** rbu handle error code is not already set, set the error code and error
** message accordingly.
label: code-design
True once backup has been registered with pager
** Free all memory allocations associated with the tree pTree.
** CAPI3REF: Error Codes And Messages
** METHOD: sqlite3
**
** ^If the most recent sqlite3_* API call associated with
** [database connection] D failed, then the sqlite3_errcode(D) interface
** returns the numeric [result code] or [extended result code] for that
** API call.
** If the most recent API call was successful,
** then the return value from sqlite3_errcode() is undefined.
** ^The sqlite3_extended_errcode()
** interface is the same except that it always returns the
** [extended result code] even when extended result codes are
** disabled.
**
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
** text that describes the error, as either UTF-8 or UTF-16 respectively.
** ^(Memory to hold the error message string is managed internally.
** The application does not need to worry about freeing the result.
** However, the error string might be overwritten or deallocated by
** subsequent calls to other SQLite interface functions.)^
**
** ^The sqlite3_errstr() interface returns the English-language text
** that describes the [result code], as UTF-8.
** ^(Memory to hold the error message string is managed internally
** and must not be freed by the application)^.
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
** interfaces always report the most recent result. To avoid
** this, each thread can obtain exclusive use of the [database connection] D
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
** all calls to the interfaces listed here are completed.
**
** If an interface fails with SQLITE_MISUSE, that means the interface
** was invoked incorrectly by the application. In that case, the
** error code and message may or may not be set.
If the opcode is TK_TRIGGER, then the expression is a reference
** to a column in the new.* or old.* pseudo-tables available to
** trigger programs. In this case Expr.iTable is set to 1 for the
** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
** is set to the column of the pseudo-table to read, or to -1 to
** read the rowid field.
**
** The expression is implemented using an OP_Param opcode. The p1
** parameter is set to 0 for an old.rowid reference, or to (i+1)
** to reference another column of the old.* pseudo-table, where
** i is the index of the column. For a new.rowid reference, p1 is
** set to (n+1), where n is the number of columns in each pseudo-table.
** For a reference to any other column in the new.* pseudo-table, p1
** is set to (n+2+i), where n and i are as defined previously. For
** example, if the table on which triggers are being fired is
** declared as:
**
** CREATE TABLE t1(a, b);
**
** Then p1 is interpreted as follows:
**
** p1==0 -> old.rowid p1==3 -> new.rowid
** p1==1 -> old.a p1==4 -> new.a
** p1==2 -> old.b p1==5 -> new.b
This constraint creates the same index as a previous
** constraint specified somewhere in the CREATE TABLE statement.
** However the ON CONFLICT clauses are different. If both this
** constraint and the previous equivalent constraint have explicit
** ON CONFLICT clauses this is an error. Otherwise, use the
** explicitly specified behavior for the index.
Pointers to the body of overflow cells
** Generate code that will increment the schema cookie.
**
** The schema cookie is used to determine when the schema for the
** database changes. After each schema change, the cookie value
** changes. When a process first reads the schema it records the
** cookie. Thereafter, whenever it goes to access the database,
** it checks the cookie to make sure the schema has not changed
** since it was last read.
**
** This plan is not completely bullet-proof. It is possible for
** the schema to change multiple times and for the cookie to be
** set back to prior value. But schema changes are infrequent
** and the probability of hitting the same cookie value is only
** 1 chance in 2^32. So we're safe enough.
**
** IMPLEMENTATION-OF: R-34230-56049 SQLite automatically increments
** the schema-version whenever the schema changes.
Because of isCandidateForInOpt(p)
A copy of pPage->pBt
FROM clause of subquery
Cursor is for seek/delete only
Name of automatically created rbu vfs
Copy data from buffer to page (a write operation)
Position list data following iHead
(281) savepoint_opt ::= SAVEPOINT
Argument to xInit() and xShutdown()
Rowid is stored in this register, if not zero
1540
What to do with the lock
Length of string z
x is the INTEGER PRIMARY KEY
Total number of blocks read
Column is part of the primary key
OP_Compare: use the permutation
The UTF-8 string to compare against
Write the results into a priority queue that is order according to
** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
** index with pSO->nExpr+2 columns. Build a key using pSO for the first
** pSO->nExpr columns, then make sure all keys are unique by adding a
** final OP_Sequence column. The last column is the record as a blob.
******************************** Unix Pthreads ***************************
expr ::= expr OR expr
comment: If this is the first term selected, copy the doclist to the output
** buffer using memcpy().
**
** Add FTS3_VARINT_MAX bytes of unused space to the end of the
** allocation. This is so as to ensure that the buffer is big enough
** to hold the current doclist AND'd with any other doclist. If the
** doclists are stored in order=ASC order, this padding would not be
** required (since the size of [doclistA AND doclistB] is always less
** than or equal to the size of [doclistA] in that case). But this is
** not true for order=DESC. For example, a doclist containing (1, -1)
** may be smaller than (-1), as in the first example the -1 may be stored
** as a single-byte delta, whereas in the second it must be stored as a
** FTS3_VARINT_MAX byte varint.
**
** Similar padding is added in the fts3DoclistOrMerge() function.
label: code-design
Current OR clause term
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
** KEYWORDS: {busy-handler callback} {busy handler}
** METHOD: sqlite3
**
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
** that might be invoked with argument P whenever
** an attempt is made to access a database table associated with
** [database connection] D when another thread
** or process has the table locked.
** The sqlite3_busy_handler() interface is used to implement
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
**
** ^If the busy callback is NULL, then [SQLITE_BUSY]
** is returned immediately upon encountering the lock. ^If the busy callback
** is not NULL, then the callback might be invoked with two arguments.
**
** ^The first argument to the busy handler is a copy of the void* pointer which
** is the third argument to sqlite3_busy_handler(). ^The second argument to
** the busy handler callback is the number of times that the busy handler has
** been invoked previously for the same locking event. ^If the
** busy callback returns 0, then no additional attempts are made to
** access the database and [SQLITE_BUSY] is returned
** to the application.
** ^If the callback returns non-zero, then another attempt
** is made to access the database and the cycle repeats.
**
** The presence of a busy handler does not guarantee that it will be invoked
** when there is lock contention. ^If SQLite determines that invoking the busy
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
** to the application instead of invoking the
** busy handler.
** Consider a scenario where one process is holding a read lock that
** it is trying to promote to a reserved lock and
** a second process is holding a reserved lock that it is trying
** to promote to an exclusive lock. The first process cannot proceed
** because it is blocked by the second and the second process cannot
** proceed because it is blocked by the first. If both processes
** invoke the busy handlers, neither will make any progress. Therefore,
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
** will induce the first process to release its read lock and allow
** the second process to proceed.
**
** ^The default busy callback is NULL.
**
** ^(There can only be a single busy handler defined for each
** [database connection]. Setting a new busy handler clears any
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
** or evaluating [PRAGMA busy_timeout=N] will change the
** busy handler and thus clear any previously set busy handler.
**
** The busy callback should not take any actions which modify the
** database connection that invoked the busy handler. In other words,
** the busy handler is not reentrant. Any such actions
** result in undefined behavior.
**
** A busy handler must not close the database connection
** or [prepared statement] that invoked the busy handler.
One or more subtasks
Select from a "CREATE ... AS SELECT"
Set the lower and upper bounds on docids to return
Number of cells in page pPage
** Many compilers we encounter do not define constants for the
** minimum and maximum 64-bit integers, or they define them
** inconsistently. And many do not understand the "LL" notation.
** So we define our own static constants here using nothing
** larger than a 32-bit integer constant.
** If the PmaReader passed as the first argument is not an incremental-reader
** (if pReadr->pIncr==0), then this function is a no-op. Otherwise, it invokes
** the vdbePmaReaderIncrMergeInit() function with the parameters passed to
** this routine to initialize the incremental merge.
**
** If the IncrMerger object is multi-threaded (IncrMerger.bUseThread==1),
** then a background thread is launched to call vdbePmaReaderIncrMergeInit().
** Or, if the IncrMerger is single threaded, the same function is called
** using the current thread.
End of analysis
If a languageid= option was specified, remove the language id
** column from the aCol[] array.
comment: Not WITHOUT ROWID table. (FIXME: Why not?)
label: code-design
Maximum file pathname length
Number of errors seen
Try to get the file to memory map
58
If the lock failed (busy):
* 1st try: get the mod time of the conch, wait 0.5s and try again.
* 2nd try: fail if the mod time changed or host id is different, wait
* 10 sec and try again
* 3rd try: break the lock unless the mod time has changed.
!defined(SQLITE_DISABLE_FTS3_UNICODE)
No match found
comment:
** Sort the list of pages in accending order by pgno. Pages are
** connected by pDirty pointers. The pDirtyPrev pointers are
** corrupted by this sort.
**
** Since there cannot be more than 2^31 distinct pages in a database,
** there cannot be more than 31 buckets required by the merge sorter.
** One extra bucket is added to catch overflow in case something
** ever changes to make the previous sentence incorrect.
label: documentation
comment:
** CAPI3REF: Apply A Changeset To A Database
**
** Apply a changeset to a database. This function attempts to update the
** "main" database attached to handle db with the changes found in the
** changeset passed via the second and third arguments.
**
** The fourth argument (xFilter) passed to this function is the "filter
** callback". If it is not NULL, then for each table affected by at least one
** change in the changeset, the filter callback is invoked with
** the table name as the second argument, and a copy of the context pointer
** passed as the sixth argument to this function as the first. If the "filter
** callback" returns zero, then no attempt is made to apply any changes to
** the table. Otherwise, if the return value is non-zero or the xFilter
** argument to this function is NULL, all changes related to the table are
** attempted.
**
** For each table that is not excluded by the filter callback, this function
** tests that the target database contains a compatible table. A table is
** considered compatible if all of the following are true:
**
** <ul>
** <li> The table has the same name as the name recorded in the
** changeset, and
** <li> The table has at least as many columns as recorded in the
** changeset, and
** <li> The table has primary key columns in the same position as
** recorded in the changeset.
** </ul>
**
** If there is no compatible table, it is not an error, but none of the
** changes associated with the table are applied. A warning message is issued
** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
** one such warning is issued for each table in the changeset.
**
** For each change for which there is a compatible table, an attempt is made
** to modify the table contents according to the UPDATE, INSERT or DELETE
** change. If a change cannot be applied cleanly, the conflict handler
** function passed as the fifth argument to sqlite3changeset_apply() may be
** invoked. A description of exactly when the conflict handler is invoked for
** each type of change is below.
**
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
** of passing anything other than a valid function pointer as the xConflict
** argument are undefined.
**
** Each time the conflict handler function is invoked, it must return one
** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
** if the second argument passed to the conflict handler is either
** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
** returns an illegal value, any changes already made are rolled back and
** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
** actions are taken by sqlite3changeset_apply() depending on the value
** returned by each invocation of the conflict-handler function. Refer to
** the documentation for the three
** [SQLITE_CHANGESET_OMIT|available return values] for details.
**
** <dl>
** <dt>DELETE Changes<dd>
** For each DELETE change, this function checks if the target database
** contains a row with the same primary key value (or values) as the
** original row values stored in the changeset. If it does, and the values
** stored in all non-primary key columns also match the values stored in
** the changeset the row is deleted from the target database.
**
** If a row with matching primary key values is found, but one or more of
** the non-primary key fields contains a value different from the original
** row value stored in the changeset, the conflict-handler function is
** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
** database table has more columns than are recorded in the changeset,
** only the values of those non-primary key fields are compared against
** the current database contents - any trailing database table columns
** are ignored.
**
** If no row with matching primary key values is found in the database,
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
** passed as the second argument.
**
** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
** (which can only happen if a foreign key constraint is violated), the
** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
** passed as the second argument. This includes the case where the DELETE
** operation is attempted because an earlier call to the conflict handler
** function returned [SQLITE_CHANGESET_REPLACE].
**
** <dt>INSERT Changes<dd>
** For each INSERT change, an attempt is made to insert the new row into
** the database. If the changeset row contains fewer fields than the
** database table, the trailing fields are populated with their default
** values.
**
** If the attempt to insert the row fails because the database already
** contains a row with the same primary key values, the conflict handler
** function is invoked with the second argument set to
** [SQLITE_CHANGESET_CONFLICT].
**
** If the attempt to insert the row fails because of some other constraint
** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
** This includes the case where the INSERT operation is re-attempted because
** an earlier call to the conflict handler function returned
** [SQLITE_CHANGESET_REPLACE].
**
** <dt>UPDATE Changes<dd>
** For each UPDATE change, this function checks if the target database
** contains a row with the same primary key value (or values) as the
** original row values stored in the changeset. If it does, and the values
** stored in all modified non-primary key columns also match the values
** stored in the changeset the row is updated within the target database.
**
** If a row with matching primary key values is found, but one or more of
** the modified non-primary key fields contains a value different from an
** original row value stored in the changeset, the conflict-handler function
** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
** UPDATE changes only contain values for non-primary key fields that are
** to be modified, only those fields need to match the original values to
** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
**
** If no row with matching primary key values is found in the database,
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
** passed as the second argument.
**
** If the UPDATE operation is attempted, but SQLite returns
** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
** This includes the case where the UPDATE operation is attempted after
** an earlier call to the conflict handler function returned
** [SQLITE_CHANGESET_REPLACE].
** </dl>
**
** It is safe to execute SQL statements, including those that write to the
** table that the callback related to, from within the xConflict callback.
** This can be used to further customize the applications conflict
** resolution strategy.
**
** All changes made by this function are enclosed in a savepoint transaction.
** If any other error (aside from a constraint failure when attempting to
** write to the target database) occurs, then the savepoint transaction is
** rolled back, restoring the target database to its original state, and an
** SQLite error code returned.
label: code-design
in3: P3 is an input
Return the number of rows that were deleted. If this routine is
** generating code because of a call to sqlite3NestedParse(), do not
** invoke the callback function.
explain ::= EXPLAIN QUERY PLAN
New path replaces the prior worst to keep count below mxChoice
Otherwise, fall thru into the TK_COLUMN case
Default lookaside buffer count
Number of equality constraints
This can happen using journal_mode=off. Move the pager to the error
** state to indicate that the contents of the cache may not be trusted.
** Any active readers will get SQLITE_ABORT.
** Drop a trigger given a pointer to that trigger.
28
Search an ephemeral b-tree
localtime
**
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
** show local time.
Number of fragmented bytes on the page
True if IPK can be equal to maxKey
** False if IPK must be strictly less than maxKey
If there is not already a read-only (or read-write) transaction opened
** on the b-tree database, open one now. If a transaction is opened, it
** will be closed immediately after reading the meta-value.
String in Mem.z is zero terminated
ccons ::= DEFAULT LP expr RP
comment:
** At least two bugs have slipped in because we changed the MEMORY_DEBUG
** macro to SQLITE_DEBUG and some older makefiles have not yet made the
** switch. The following code should catch this problem at compile-time.
label: code-design
OUT: Block id of last entry written
Filter used with cursor pCsr
typetoken ::= typename LP signed RP
Special case: Parsing the sqlite_master or sqlite_temp_master schema
** An instance of the following structure is used as a dynamic buffer
** to build up nodes or other blobs of data in.
**
** The function blobGrowBuffer() is used to extend the allocation.
** Write up to nBuf bytes of randomness into zBuf.
OUT: End of parsed string
Reference counted destructor function
** The cursor passed as the only argument must point to a valid entry
** when this function is called (i.e. have eState==CURSOR_VALID). This
** function saves the current cursor key in variables pCur->nKey and
** pCur->pKey. SQLITE_OK is returned if successful or an SQLite error
** code otherwise.
**
** If the cursor is open on an intkey table, then the integer key
** (the rowid) is stored in pCur->nKey and pCur->pKey is left set to
** NULL. If the cursor is open on a non-intkey table, then pCur->pKey is
** set to point to a malloced buffer pCur->nKey bytes in size containing
** the key.
** Transfer all bindings from the first statement over to the second.
No. of reg prior to regData available for use
zero columns if RHS argument is present
Operands of the opcode used to ends the loop
Reset the cursor to the same state as rtreeOpen() leaves it in.
path for the new unixFile
limit_opt ::=
A block of WALINDEX_LOCK_RESERVED bytes beginning at
** WALINDEX_LOCK_OFFSET is reserved for locks. Since some systems
** only support mandatory file-locks, we do not read or write data
** from the region of the file on which locks are applied.
Transform this into an alias to the result set
True to fail EXCLUSIVE locks
Opcode: Le P1 P2 P3 P4 P5
** Synopsis: IF r[P3]<=r[P1]
**
** This works just like the Lt opcode except that the jump is taken if
** the content of register P3 is less than or equal to the content of
** register P1. See the Lt opcode for additional information.
RENAME
Size of source db in pages
Foreign key to get action for
Rowid of row about to be deleted/updated
Root page of scanned b-tree
Scratch memory
Expression we are trying to match
token.z was originally in "..."
** Set the suggested cache-spill value. Make no changes if if the
** argument is zero. Return the effective cache-spill size, which will
** be the larger of the szSpill and szCache.
True for write lock. False for a read lock
Construct a query to find the rowid or primary key for every row
** to be deleted, based on the WHERE clause. Set variable eOnePass
** to indicate the strategy used to implement this delete:
**
** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values.
** ONEPASS_SINGLE: One-pass approach - at most one row deleted.
** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted.
SQLITE_OMIT_COMPILEOPTION_DIAGS
************* Include os_common.h in the middle of os_unix.c **************
!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
The group by clause
comment:
** The sqlite3_mutex_try() routine is very rarely used, and when it
** is used it is merely an optimization. So it is OK for it to always
** fail.
**
** The TryEnterCriticalSection() interface is only available on WinNT.
** And some windows compilers complain if you try to use it without
** first doing some #defines that prevent SQLite from building on Win98.
** For that reason, we will omit this optimization for now. See
** ticket #2685.
label: code-design
** Process statements of the form:
**
** INSERT INTO table(table) VALUES('merge=A,B');
**
** A and B are integers that decode to be the number of leaf pages
** written for the merge, and the minimum number of segments on a level
** before it will be selected for a merge, respectively.
Result of a successful parse
** Given the name of a database file, compute the name of its conch file.
** Store the conch filename in memory obtained from sqlite3_malloc64().
** Make *pConchPath point to the new name. Return SQLITE_OK on success
** or SQLITE_NOMEM if unable to obtain memory.
**
** The caller is responsible for ensuring that the allocated memory
** space is eventually freed.
**
** *pConchPath is set to NULL if a memory allocation error occurs.
** This routine is callback for sqlite3WalkExpr().
**
** Resolve symbolic names into TK_COLUMN operators for the current
** node in the expression tree. Return 0 to continue the search down
** the tree or 2 to abort the tree walk.
**
** This routine also does error checking and name resolution for
** function names. The operator for aggregate functions is changed
** to TK_AGG_FUNCTION.
String to return
Zero values greater than this
207
The parser to be deleted
SQLITE_AFF_REAL
Store the current value of the database handles deferred constraint
** counter. If the statement transaction needs to be rolled back,
** the value of this counter needs to be restored too.
317
Bitmap of columns used for indexing
DETACH
** End of interface to code in fts5_varint.c.
*************************************************************************
Index iterator
** Maximum size of any allocation is ((1<<LOGMAX)*mem5.szAtom). Since
** mem5.szAtom is always at least 8 and 32-bit integers are used,
** it is not actually possible to reach this limit.
** Windows will only let you create file view mappings
** on allocation size granularity boundaries.
** During sqlite3_os_init() we do a GetSystemInfo()
** to get the granularity size.
Register a trace callback using the version-2 interface.
** Attempt to start a new transaction. A write-transaction
** is started if the second argument is nonzero, otherwise a read-
** transaction. If the second argument is 2 or more and exclusive
** transaction is started, meaning that no other process is allowed
** to access the database. A preexisting transaction may not be
** upgraded to exclusive by calling this routine a second time - the
** exclusivity flag only works for a new transaction.
**
** A write-transaction must be started before attempting any
** changes to the database. None of the following routines
** will work unless a transaction is started first:
**
** sqlite3BtreeCreateTable()
** sqlite3BtreeCreateIndex()
** sqlite3BtreeClearTable()
** sqlite3BtreeDropTable()
** sqlite3BtreeInsert()
** sqlite3BtreeDelete()
** sqlite3BtreeUpdateMeta()
**
** If an initial attempt to acquire the lock fails because of lock contention
** and the database was previously unlocked, then invoke the busy handler
** if there is one. But if there was previously a read-lock, do not
** invoke the busy handler - just return SQLITE_BUSY. SQLITE_BUSY is
** returned when there is already a read-lock in order to avoid a deadlock.
**
** Suppose there are two processes A and B. A has a read lock and B has
** a reserved lock. B tries to promote to exclusive but is blocked because
** of A's read lock. A tries to promote to reserved but is blocked by B.
** One or the other of the two processes must give way or there can be
** no progress. By returning SQLITE_BUSY and not invoking the busy callback
** when A already has a read lock, we encourage A to give up and let B
** proceed.
*************************************************************************
** Interface to code in fts5_hash.c.
** GCC does not define the offsetof() macro so we'll have to do it
** ourselves.
Column number of matching column on the right
** Constants for the largest and smallest possible 64-bit signed integers.
** These macros are designed to work correctly on both 32-bit and 64-bit
** compilers.
Offset to the cell pointer array
Bitmask of tables referenced by pExpr
If we reach this point, it means the two subterms can be combined
Open and close a connection to a write-ahead log.
Size of one page
Number of the page to get
** Used as an fts3ExprIterate() context when loading phrase doclists to
** Fts3Expr.aDoclist[]/nDoclist.
Number of bytes of URI args at *zUri
Boolean properties. See COLFLAG_ defines below
Take a shared-cache advisory read-lock on the parent table. Allocate
** a cursor to use to search the unique index on the parent key columns
** in the parent table.
pIdx is a covering index. No need to access the main table.
Overwrite deleted information with zeros when the secure_delete
** option is enabled
Opcode: OpenDup P1 P2 * * *
**
** Open a new cursor P1 that points to the same ephemeral table as
** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
** opcode. Only ephemeral cursors may be duplicated.
**
** Duplicate ephemeral cursors are used for self-joins of materialized views.
If true, store 0 for segment size
Minimum amount of payload held locally
Samples of the left-most key
Find any inequality constraint terms for the start and end
** of the range.
#include "os_win.h"
Number of rows in the entire table
List of triggers on pTab, if required
** True if we are evaluating an out-of-memory callback.
Check for index coverage
Store the value in this register
EXCLUSIVE => ID
Number of entries in aVar[]
** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
Size of term in bytes
The content of the whole page
** PRAGMA table_info(<table>)
**
** Return a single row for each column of the named table. The columns of
** the returned data set are:
**
** cid: Column id (numbered from left to right, starting at 0)
** name: Column name
** type: Column declaration type.
** notnull: True if 'NOT NULL' is part of column declaration
** dflt_value: The default value for the column, if any.
************* Include vdbe.h in the middle of sqliteInt.h *****************
Initialize all iterators
If there is anything other than a rowset object in memory cell P1,
** delete it now and initialize P1 with an empty rowset
idx
** FTS4 virtual tables may maintain multiple indexes - one index of all terms
** in the document set and zero or more prefix indexes. All indexes are stored
** as one or more b+-trees in the %_segments and %_segdir tables.
**
** It is possible to determine which index a b+-tree belongs to based on the
** value stored in the "%_segdir.level" column. Given this value L, the index
** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with
** level values between 0 and 1023 (inclusive) belong to index 0, all levels
** between 1024 and 2047 to index 1, and so on.
**
** It is considered impossible for an index to use more than 1024 levels. In
** theory though this may happen, but only after at least
** (FTS3_MERGE_COUNT^1024) separate flushes of the pending-terms tables.
If pToRelease is not zero than pPrior points into the data area
** of pToRelease. Make sure pToRelease is still writeable.
The virtual table to be modified
** Return the declared type of a column. Or return zDflt if the column
** has no declared type.
**
** The column type is an extra string stored after the zero-terminator on
** the column name if and only if the COLFLAG_HASTYPE flag is set.
For each term in the FROM clause, do two things:
** (1) Authorized unreferenced tables
** (2) Generate code for all sub-queries
sortlist ::= sortlist COMMA expr sortorder
Page not on the PCache.pDirty list
******* General Implementation Functions ***********************************
Number of SHARED locks held
Find out what action to take in case there is a uniqueness conflict
Length of position list
Generate code to remove the index and from the master table
Opcode: Jump P1 P2 P3 * *
**
** Jump to the instruction at address P1, P2, or P3 depending on whether
** in the most recent OP_Compare instruction the P1 vector was less than
** equal to, or greater than the P2 vector, respectively.
The thread routine
comment: By default use a full table scan. This is an expensive option,
** so search through the constraints to see if a more efficient
** strategy is possible.
label: code-design
comment: Save the current term so that it can be used to prefix-compress the next.
** If the isCopyTerm parameter is true, then the buffer pointed to by
** zTerm is transient, so take a copy of the term data. Otherwise, just
** store a copy of the pointer.
label: code-design
** Mark term iChild as being a child of term iParent
Enlarge the allocation
Leaf pages in a "unit" of work
The token codes above must all fit in 8 bits
Allocated array
Number of input segments on best level
3x
** 2008 May 27
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains inline asm code for retrieving "high-performance"
** counters for x86 class CPUs.
Values for xColumnSize()
103
same as TK_EQ, jump, in1, in3
SELECT may not be DISTINCT
Value is an integer
SQLite error code
comment:
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** The code in this file implements the function that runs the
** bytecode of a prepared statement.
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files. The formatting
** of the code in this file is, therefore, important. See other comments
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
label: code-design
pPager->errCode = 0;
If the RHS is a vector, then we can immediately check to see that
** the size of the RHS and LHS match. But if the RHS is a SELECT,
** wildcards ("*") in the result set of the SELECT must be expanded before
** we can do the size check, so defer the size check until code generation.
Remove either the OP_OpenWrite or OpenRead. Set the P2
** parameter of the other to pTab->tnum.
************* Begin file vdbetrace.c **************************************
Start of subroutine that outputs a result row
48..4f HIJKLMNO
** Return a KeyInfo structure that is appropriate for the given Index.
**
** The caller should invoke sqlite3KeyInfoUnref() on the returned object
** when it has finished using it.
Put the new key into this register if not 0
Chain of simple selects to delete
Compute the complete text of the CREATE VIRTUAL TABLE statement
** Return TRUE if database connection db has unfinalized prepared
** statements or unfinished sqlite3_backup objects.
** Walk an expression tree. Invoke the callback once for each node
** of the expression, while descending. (In other words, the callback
** is invoked before visiting children.)
**
** The return value from the callback should be one of the WRC_*
** constants to specify how to proceed with the walk.
**
** WRC_Continue Continue descending down the tree.
**
** WRC_Prune Do not descend into child nodes, but allow
** the walk to continue with sibling nodes.
**
** WRC_Abort Do no more callbacks. Unwind the stack and
** return from the top-level walk call.
**
** The return value from this routine is WRC_Abort to abandon the tree walk
** and WRC_Continue to continue.
Add "0" or "0x"
NOT REACHED
Ideal number of tokens to shift forward
Opcode: Cast P1 P2 * * *
** Synopsis: affinity(r[P1])
**
** Force the value in register P1 to be the type defined by P2.
**
** <ul>
** <li> P2=='A' → BLOB
** <li> P2=='B' → TEXT
** <li> P2=='C' → NUMERIC
** <li> P2=='D' → INTEGER
** <li> P2=='E' → REAL
** </ul>
**
** A NULL value is not changed by this routine. It remains NULL.
selectNodeIsConstant will disallow
Unread parts of the buffer must be zero-filled
** Implementation of the sqlite_compileoption_get() function.
** The result is a string that identifies the compiler options
** used to build SQLite.
The new table name.
** Generate code that will
**
** (1) acquire a lock for table pTab then
** (2) open pTab as cursor iCur.
**
** If pTab is a WITHOUT ROWID table, then it is the PRIMARY KEY index
** for that table that is actually opened.
seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt
Allocated size of aFrame[] array
Index of containing database.
If the B-Tree was successfully opened, set the pager-cache size to the
** default value. Except, when opening on an existing shared pager-cache,
** do not change the pager-cache size.
Twice the number of dimensions
For columns use the column name name
C
OUT: Bytes actually loaded
Remove connection p from the set of connections associated
** with pShmNode
a &= (0x7f<<14)|(0x7f);
Versions of SQLite prior to 3.5.8 set the page-size field of the
** journal header to zero. In this case, assume that the Pager.pageSize
** variable is already set to the correct page size.
SQL_DELETE_SEGDIR_ENTRY
** Delete the %_segdir entry on absolute level :1 with index :2.
Populate new node buffer
Total internal fragmentation
someone else has the lock when we are in NO_LOCK
Prior journalmode
current position in pInput
If we are doing a normal write to a database file (as opposed to
** doing a hot-journal rollback or a write to some file other than a
** normal database file) and we truncate the file to zero length,
** that effectively updates the change counter. This might happen
** when restoring a database using the backup API from a zero-length
** source.
Used by reverse iterators
Result code stored here
Characters to treat as exceptions
Next node in this hash collision chain
Left subnode
Stat4Accum.nMaxEqZero is set to the maximum number of leading 0
** values in the anEq[] array of any sample in Stat4Accum.a[]. In
** other words, if nMaxEqZero is n, then it is guaranteed that there
** are no samples with Stat4Sample.anEq[m]==0 for (m>=n).
Number of parameters to the SQL function
Remove the cursor from the Fts5Global.pCsr list
cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt
OUT: Merged change
Free any old pages that were not reused as new pages.
** Set the name of the idx'th column to be returned by the SQL statement.
** zName must be a pointer to a nul terminated string.
**
** This call must be made after a call to sqlite3VdbeSetNumCols().
**
** The final parameter, xDel, must be one of SQLITE_DYNAMIC, SQLITE_STATIC
** or SQLITE_TRANSIENT. If it is SQLITE_DYNAMIC, then the buffer pointed
** to by zName will be freed by sqlite3DbFree() when the vdbe is destroyed.
If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
** is case sensitive causing 'a' LIKE 'A' to be false
A column name: ID
** Or table name and column name: ID.ID
** Or a database, table and column: ID.ID.ID
**
** The TK_ID and TK_OUT cases are combined so that there will only
** be one call to lookupName(). Then the compiler will in-line
** lookupName() for a size reduction and performance increase.
Linked list of main db files
The entire segment is stored in the root node.
createkw ::= CREATE
joinop ::= JOIN_KW nm JOIN
int int*
Table of WHERE clause constraints
Figure out if we have any triggers and if the table being
** updated is a view.
EVIDENCE-OF: R-64536-51728 The values for each column in the record
** immediately follow the header.
Configured by FCNTL_CHUNK_SIZE
** Structure version. Should always be set to 0 or 1.
Current docid
Language id
CASCADE => ID
comment:
** All of the static variables used by this module are collected
** into a single structure named "mem". This is to keep the
** static variables organized and to reduce namespace pollution
** when this module is combined with other in the amalgamation.
label: code-design
Allocate registers for holding the rowid of the new row,
** the content of the new row, and the assembled row record.
If the auto-commit flag is set to true, then any locks that were held
** by connection db have now been released. Call sqlite3ConnectionUnlocked()
** to invoke any required unlock-notify callbacks.
** Argument apSegment is an array of nSegment elements. It is known that
** the final (nSegment-nSuspect) members are already in sorted order
** (according to the comparison function provided). This function shuffles
** the array around until all entries are in sorted order.
Cursor containing term and doclist
Loop through all the foreign key constraints that refer to this table.
** (the "child" constraints)
Tokenizer module methods object
Pages from root to current page
** For LIKE and GLOB matching on EBCDIC machines, assume that every
** character is exactly one byte in size. Also, provde the Utf8Read()
** macro for fast reading of the next character in the common case where
** the next character is ASCII.
comment:
** The page getter methods each try to acquire a reference to a
** page with page number pgno. If the requested reference is
** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
**
** There are different implementations of the getter method depending
** on the current state of the pager.
**
** getPageNormal() -- The normal getter
** getPageError() -- Used if the pager is in an error state
** getPageMmap() -- Used if memory-mapped I/O is enabled
**
** If the requested page is already in the cache, it is returned.
** Otherwise, a new page object is allocated and populated with data
** read from the database file. In some cases, the pcache module may
** choose not to allocate a new page object and may reuse an existing
** object with no outstanding references.
**
** The extra data appended to a page is always initialized to zeros the
** first time a page is loaded into memory. If the page requested is
** already in the cache when this function is called, then the extra
** data is left as it was when the page object was last used.
**
** If the database image is smaller than the requested page or if
** the flags parameter contains the PAGER_GET_NOCONTENT bit and the
** requested page is not already stored in the cache, then no
** actual disk read occurs. In this case the memory image of the
** page is initialized to all zeros.
**
** If PAGER_GET_NOCONTENT is true, it means that we do not care about
** the contents of the page. This occurs in two scenarios:
**
** a) When reading a free-list leaf page from the database, and
**
** b) When a savepoint is being rolled back and we need to load
** a new page into the cache to be filled with the data read
** from the savepoint journal.
**
** If PAGER_GET_NOCONTENT is true, then the data returned is zeroed instead
** of being read from the database. Additionally, the bits corresponding
** to pgno in Pager.pInJournal (bitvec of pages already written to the
** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
** savepoints are set. This means if the page is made writable at any
** point in the future, using a call to sqlite3PagerWrite(), its contents
** will not be journaled. This saves IO.
**
** The acquisition might fail for several reasons. In all cases,
** an appropriate error code is returned and *ppPage is set to NULL.
**
** See also sqlite3PagerLookup(). Both this routine and Lookup() attempt
** to find a page in the in-memory cache first. If the page is not already
** in memory, this routine goes to disk to read it in whereas Lookup()
** just returns 0. This routine acquires a read-lock the first time it
** has to go to disk, and could also playback an old journal if necessary.
** Since Lookup() never goes to disk, it never has to deal with locks
** or journal files.
label: code-design
************* End of threads.c ********************************************
************* Begin file fts3_tokenizer.h *********************************
Named semaphore locking uses the file path so it needs to be
** included in the semLockingContext
Specify an alternative mutex implementation
Next offset to read from log file
Bytes of storage available in zBuf[]
** Values for RbuObjIter.eType
**
** 0: Table does not exist (error)
** 1: Table has an implicit rowid.
** 2: Table has an explicit IPK column.
** 3: Table has an external PK index.
** 4: Table is WITHOUT ROWID.
** 5: Table is a virtual table.
EP_Static if space not obtained from malloc
** Set *ppData to point to the Fts5Bm25Data object for the current query.
** If the object has not already been allocated, allocate and populate it
** now.
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
** to contains a zero-length string, all attached databases are
** checkpointed.
Load automatic extensions - extensions that have been registered
** using the sqlite3_automatic_extension() API.
******* Page Allocation/SQLITE_CONFIG_PCACHE Related Functions *************
** These are the initializer values used when declaring a "static" mutex
** on Win32. It should be noted that all mutexes require initialization
** on the Win32 platform.
23
************* Begin file mem2.c *******************************************
Make nMaxCells a multiple of 4 in order to preserve 8-byte
** alignment
18
EVIDENCE-OF: R-12976-22893 Value is the integer 0.
** Tokenization callback used when inserting tokens into the FTS index.
Current value of 'col' column
Calculate an IDF for each phrase in the query
** Generate code that will push the record in registers regData
** through regData+nData-1 onto the sorter.
anLt[] + anEq[] of largest sample pRec is >
** Return true if we can prove the pE2 will always be true if pE1 is
** true. Return false if we cannot complete the proof or if pE2 might
** be false. Examples:
**
** pE1: x==5 pE2: x==5 Result: true
** pE1: x>0 pE2: x==5 Result: false
** pE1: x=21 pE2: x=21 OR y=43 Result: true
** pE1: x!=123 pE2: x IS NOT NULL Result: true
** pE1: x!=?1 pE2: x IS NOT NULL Result: true
** pE1: x IS NULL pE2: x IS NOT NULL Result: false
** pE1: x IS ?2 pE2: x IS NOT NULL Reuslt: false
**
** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
** Expr.iTable<0 then assume a table number given by iTab.
**
** If pParse is not NULL, then the values of bound variables in pE1 are
** compared against literal values in pE2 and pParse->pVdbe->expmask is
** modified to record which bound variables are referenced. If pParse
** is NULL, then false will be returned if pE1 contains any bound variables.
**
** When in doubt, return false. Returning true might give a performance
** improvement. Returning false might cause a performance reduction, but
** it will always give the correct answer and is hence always safe.
** Routines to implement min() and max() aggregate functions.
If the trigger name was unqualified, and the table is a temp table,
** then set iDb to 1 to create the trigger in the temporary database.
** If sqlite3SrcListLookup() returns 0, indicating the table does not
** exist, the error is caught by the block below.
Set to ", " later on
** 2004 May 26
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to manipulate "Mem" structure. A "Mem"
** stores a single value in the VDBE. Mem is an opaque structure visible
** only within the VDBE. Interface routines refer to a Mem using the
** name sqlite_value
************* End of hash.h ***********************************************
** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN
Add column type information to this table
If bCloseTrans is true, then this function opened a read transaction
** on the source database. Close the read transaction here. There is
** no need to check the return values of the btree methods here, as
** "committing" a read-only transaction cannot fail.
Add the freeblocks to the min-heap
**
** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
** is the offset of the first freeblock, or zero if there are no
** freeblocks on the page.
comment: Number of bytes of extra space to alloc
label: code-design
If the database supports auto-vacuum, and the second or subsequent
** overflow page is being allocated, add an entry to the pointer-map
** for that page now.
**
** If this is the first overflow page, then write a partial entry
** to the pointer-map. If we write nothing to this pointer-map slot,
** then the optimistic overflow chain processing in clearCell()
** may misinterpret the uninitialized values and delete the
** wrong pages from the database.
When playing back page 1, restore the nReserve setting
Jump destination
Compose and prepare an SQL statement to loop through the content table
Table has only 64-bit signed integer keys
2^32 - to avoid use of LL and warnings in gcc
Use pread() and pwrite() if they are available
Where clause context
Magic number for detect library misuse
Previous content. 0 for INSERTs
************* End of vxworks.h ********************************************
The index for which to generate a key
** Hash and comparison functions when the mode is FTS3_HASH_STRING
This branch runs if the record-size field of the cell is a
** single byte varint and the record fits entirely on the main
** b-tree page.
Number of Records in the journal
Subset of btreeMask that requires a lock
End of the loop
************* Begin file vdbemem.c ****************************************
** Compute a hash on a page number. The resulting hash value must land
** between 0 and (HASHTABLE_NSLOT-1). The walHashNext() function advances
** the hash to the next value in the event of a collision.
Open file descriptor of file being opened
comment:
** Return true if the DISTINCT expression-list passed as the third argument
** is redundant.
**
** A DISTINCT list is redundant if any subset of the columns in the
** DISTINCT list are collectively unique and individually non-null.
label: code-design
Rows are coming out in undetermined order. We have to push
** each row into a sorting index, terminate the first loop,
** then loop over the sorting index in order to get the output
** in sorted order
Local cache of jsl
If one has been configured, invoke the rollback-hook callback
It is possible that if journal_mode=wal here that neither the
** journal file nor the WAL file are open. This happens during
** a rollback transaction that switches from journal_mode=off
** to journal_mode=wal.
******************************* End Unix Pthreads ************************
Check any rowid-less pages that occur before the current leaf.
For looping over pList
True if iDocid is valid
Changset operation (SQLITE_UPDATE etc.)
At EOF already
Size of buffer pChangeset in bytes
Table column this handle is open on
Expression pPhrase belongs to
Password used to authenticate
This cell was just inserted
OUT: Write the cell contents here
DEFERRED
colset ::= MINUS STRING
2-byte signed integer
A parameter used by the eDest disposal method
** CAPI3REF: A Handle To An Open BLOB
** KEYWORDS: {BLOB handle} {BLOB handles}
**
** An instance of this object represents an open BLOB on which
** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
** ^Objects of this type are created by [sqlite3_blob_open()]
** and destroyed by [sqlite3_blob_close()].
** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
** can be used to read or write small subsections of the BLOB.
** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
UTF-16 encoded SQL statement.
** Try to insert a new prerequisite/cost entry into the WhereOrSet pSet.
**
** The new entry might overwrite an existing entry, or it might be
** appended, or it might be discarded. Do whatever is the right thing
** so that pSet keeps the N_OR_COST best entries seen so far.
** Conversion types fall into various categories as defined by the
** following enumeration.
This happens when parsing a token or quoted phrase that contains
** no token characters at all. (e.g ... MATCH '""').
2 or greater. A position.
This term does not restrict search space
The statement to bind against
Fall through into OP_AggStep
For each CTE in the WITH clause....
Open a cursor to iterate through the contents of the oldest nSeg
** indexes of absolute level iAbsLevel. If this cursor is opened using
** the 'hint' parameters, it is possible that there are less than nSeg
** segments available in level iAbsLevel. In this case, no work is
** done on iAbsLevel - fall through to the next iteration of the loop
** to start work on some other level.
AS
** The main routine for background threads that populate aFile[1] of
** multi-threaded IncrMerger objects.
Token to query for
P4 is a 64-bit signed integer
Size of the SHM filename in bytes
** A tree of these objects forms the RHS of a MATCH operator.
**
** If Fts3Expr.eType is FTSQUERY_PHRASE and isLoaded is true, then aDoclist
** points to a malloced buffer, size nDoclist bytes, containing the results
** of this phrase query in FTS3 doclist format. As usual, the initial
** "Length" field found in doclists stored on disk is omitted from this
** buffer.
**
** Variable aMI is used only for FTSQUERY_NEAR nodes to store the global
** matchinfo data. If it is not NULL, it points to an array of size nCol*3,
** where nCol is the number of columns in the queried FTS table. The array
** is populated as follows:
**
** aMI[iCol*3 + 0] = Undefined
** aMI[iCol*3 + 1] = Number of occurrences
** aMI[iCol*3 + 2] = Number of rows containing at least one instance
**
** The aMI array is allocated using sqlite3_malloc(). It should be freed
** when the expression node is.
Before calling sqlite3ExprDelete(), set the EP_Static flag. This
** prevents ExprDelete() from deleting the Expr structure itself,
** allowing it to be repopulated by the memcpy() on the following line.
** The pExpr->u.zToken might point into memory that will be freed by the
** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
** make a copy of the token before doing the sqlite3DbFree().
Results of the query
Newly allocated VFS
Open a read-only cursor, execute the OP_Count, close the cursor.
Try to flatten subqueries in the FROM clause up into the main query
The double-precision datatype used by RTree depends on the
** SQLITE_RTREE_INT_ONLY compile-time option.
EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
** call to sqlite3_backup_init() and is destroyed by a call to
** sqlite3_backup_finish().
** This function is called to select the tokens (if any) that will be
** deferred. The array aTC[] has already been populated when this is
** called.
**
** This function is called once for each AND/NEAR cluster in the
** expression. Each invocation determines which tokens to defer within
** the cluster with root node pRoot. See comments above the definition
** of struct Fts3TokenAndCost for more details.
**
** If no error occurs, SQLITE_OK is returned and sqlite3Fts3DeferToken()
** called on each token to defer. Otherwise, an SQLite error code is
** returned.
A slot for the record has already been allocated in the
** SQLITE_MASTER table. We just need to update that slot with all
** the information we've collected.
A single node of parsed JSON
total space to allocate
Offset to start writing file at
comment: We have to initialize zBuf to prevent valgrind from reporting
** errors. The reports issued by valgrind are incorrect - we would
** prefer that the randomness be increased by making use of the
** uninitialized space in zBuf - but valgrind errors tend to worry
** some users. Rather than argue, it seems easier just to initialize
** the whole array and silence valgrind, even if that means less randomness
** in the random seed.
**
** When testing, initializing zBuf[] to zero is all we do. That means
** that we always use the same random number sequence. This makes the
** tests repeatable.
label: code-design
Size of the pCell cell in bytes
Number of subqueries that the label is moving
Number of bytes to copy
Need to sqlite3DbFree() Expr.zToken
don't break the lock if the host id doesn't match
Counter for IN constraints
Value is a BLOB
** Execute the statement pStmt, either until a row of data is ready, the
** statement is completely executed or an error occurs.
**
** This routine implements the bulk of the logic behind the sqlite_step()
** API. The only thing omitted is the automatic recompile if a
** schema change has occurred. That detail is handled by the
** outer sqlite3_step() wrapper procedure.
xRollbackTo
This call is to open a *-wal file. Intead, open the *-oal. This
** code ensures that the string passed to xOpen() is terminated by a
** pair of '\0' bytes in case the VFS attempts to extract a URI
** parameter from it.
If isIgnoreErrors is true, then a table is being dropped. In this
** case SQLite runs a "DELETE FROM xxx" on the table being dropped
** before actually dropping it in order to check FK constraints.
** If the parent table of an FK constraint on the current table is
** missing, behave as if it is empty. i.e. decrement the relevant
** FK counter for each row of the current table with non-NULL keys.
** This function is called to configure the RtreeConstraint object passed
** as the second argument for a MATCH constraint. The value passed as the
** first argument to this function is the right-hand operand to the MATCH
** operator.
Name of the mmapped file
IMP: R-37434-19929 Abs(X) returns NULL if X is NULL.
Determine the number of phrases in the query
Suppress errors if the trigger already exists
Pointer to HighlightContext object
** Implementation of the SQL scalar function for accessing the underlying
** hash table. This function may be called as follows:
**
** SELECT <function-name>(<key-name>);
** SELECT <function-name>(<key-name>, <pointer>);
**
** where <function-name> is the name passed as the second argument
** to the sqlite3Fts3InitHashTable() function (e.g. 'fts3_tokenizer').
**
** If the <pointer> argument is specified, it must be a blob value
** containing a pointer to be stored as the hash data corresponding
** to the string <key-name>. If <pointer> is not specified, then
** the string <key-name> must already exist in the has table. Otherwise,
** an error is returned.
**
** Whether or not the <pointer> argument is specified, the value returned
** is a blob containing the pointer stored as the hash data corresponding
** to string <key-name> (after the hash-table is updated, if applicable).
** NOTE: We are dealing with a relative path name and the data
** directory has been set. Therefore, use it as the basis
** for converting the relative path name to an absolute
** one by prepending the data directory and a backslash.
Largest serialized key seen so far
FROM clause element to resolve
** Free all entries in the pCsr->pDeffered list. Entries are added to
** this list using sqlite3Fts3DeferToken().
This INSERT command is part of a VACUUM operation, which guarantees
** that the destination table is empty. If all indexed columns use
** collation sequence BINARY, then it can also be assumed that the
** index will be populated by inserting keys in strictly sorted
** order. In this case, instead of seeking within the b-tree as part
** of every OP_IdxInsert opcode, an OP_Last is added before the
** OP_IdxInsert to seek to the point within the b-tree where each key
** should be inserted. This is faster.
**
** If any of the indexed columns use a collation sequence other than
** BINARY, this optimization is disabled. This is because the user
** might change the definition of a collation sequence and then run
** a VACUUM command. In that case keys may not be written in strictly
** sorted order.
OUT: True to remove PK row and retry
The record to verify
** The unicode() function. Return the integer unicode code-point value
** for the first character of the input string.
310
Version 3.10.0 and later
This is a new term. Append a term to the output segment.
If running in direct mode, write the contents of page 1 to the file.
If the above search did not find a BtLock struct associating Btree p
** with table iTable, allocate one and link it into the list.
** PRAGMA [schema.]schema_version
** PRAGMA [schema.]schema_version = <integer>
**
** PRAGMA [schema.]user_version
** PRAGMA [schema.]user_version = <integer>
**
** PRAGMA [schema.]freelist_count
**
** PRAGMA [schema.]data_version
**
** PRAGMA [schema.]application_id
** PRAGMA [schema.]application_id = <integer>
**
** The pragma's schema_version and user_version are used to set or get
** the value of the schema-version and user-version, respectively. Both
** the schema-version and the user-version are 32-bit signed integers
** stored in the database header.
**
** The schema-cookie is usually only manipulated internally by SQLite. It
** is incremented by SQLite whenever the database schema is modified (by
** creating or dropping a table or index). The schema version is used by
** SQLite each time a query is executed to ensure that the internal cache
** of the schema used when compiling the SQL query matches the schema of
** the database against which the compiled query is actually executed.
** Subverting this mechanism by using "PRAGMA schema_version" to modify
** the schema-version is potentially dangerous and may lead to program
** crashes or database corruption. Use with caution!
**
** The user-version is not used internally by SQLite. It may be used by
** applications for any purpose.
** Append a doclist to buffer pBuf.
**
** This function assumes that space within the buffer has already been
** allocated.
** Return the amount of memory currently checked out.
pPager->pBusyHandlerArg = 0;
RHS is a string
Database connection for this cursor
Initialize iLast, the "lastest" rowid any iterator points to. If the
** iterator skips through rowids in the default ascending order, this means
** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
** means the minimum rowid.
Update the assumed sector-size to match the value used by
** the process that created this journal. If this journal was
** created by a process other than this one, then this routine
** is being called from within pager_playback(). The local value
** of Pager.sectorSize is restored at the end of that routine.
Index of changed index field
** Compare key1 (buffer pKey1, size nKey1 bytes) with key2 (buffer pKey2,
** size nKey2 bytes). Use (pTask->pKeyInfo) for the collation sequences
** used by the comparison. Return the result of the comparison.
**
** If IN/OUT parameter *pbKey2Cached is true when this function is called,
** it is assumed that (pTask->pUnpacked) contains the unpacked version
** of key2. If it is false, (pTask->pUnpacked) is populated with the unpacked
** version of key2 and *pbKey2Cached set to true before returning.
**
** If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
** to SQLITE_NOMEM.
Read this many bytes
OUT: UPDATE statement handle
comment: Database connection, for malloc()
label: code-design
Sequence number of leaf within tree
690
Boolean array - true if column is in PK
List terminator
A table is not writable under the following circumstances:
**
** 1) It is a virtual table and no implementation of the xUpdate method
** has been provided, or
** 2) It is a system table (i.e. sqlite_master), this call is not
** part of a nested parse and writable_schema pragma has not
** been specified.
**
** In either case leave an error message in pParse and return non-zero.
Next position
** Allocate nBytes of memory.
comment:
** sqlite3_snprintf() works like snprintf() except that it ignores the
** current locale settings. This is important for SQLite because we
** are not able to use a "," as the decimal point in place of "." as
** specified by some locales.
**
** Oops: The first two arguments of sqlite3_snprintf() are backwards
** from the snprintf() standard. Unfortunately, it is too late to change
** this without breaking compatibility, so we just have to live with the
** mistake.
**
** sqlite3_vsnprintf() is the varargs version.
label: code-design
OUT: Number of entries in output array
Honor DESC
Use full fsync for checkpoint
** Return the index of a column in a table. Return -1 if the column
** is not contained in the table.
** Return a static string that describes the kind of error specified in the
** argument.
** If a prior call to sqlite3GenerateIndexKey() generated a jump-over label
** because it was a partial index, then this routine should be called to
** resolve that label.
A named index with an explicit CREATE INDEX statement
Or here, if bUseThreads==0
First slot in %_segments written
The Source list to check and modify
If the SET_FULLSYNC macro is not defined above, then make it
** a no-op
** Values for Fts5Cursor.csrflags
True if this call is part of a bulk load
** An instance of the following object is used to record information about
** the ORDER BY (or GROUP BY) clause of query is being coded.
First term on new page
** isConsonant() and isVowel() determine if their first character in
** the string they point to is a consonant or a vowel, according
** to Porter ruls.
**
** A consonate is any letter other than 'a', 'e', 'i', 'o', or 'u'.
** 'Y' is a consonant unless it follows another consonant,
** in which case it is a vowel.
**
** In these routine, the letters are in reverse order. So the 'y' rule
** is that 'y' is a consonant unless it is followed by another
** consonent.
Opcode: NotExists P1 P2 P3 * *
** Synopsis: intkey=r[P3]
**
** P1 is the index of a cursor open on an SQL table btree (with integer
** keys). P3 is an integer rowid. If P1 does not contain a record with
** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then
** leave the cursor pointing at that record and fall through to the next
** instruction.
**
** The OP_SeekRowid opcode performs the same operation but also allows the
** P3 register to contain a non-integer value, in which case the jump is
** always taken. This opcode requires that P3 always contain an integer.
**
** The OP_NotFound opcode performs the same operation on index btrees
** (with arbitrary multi-value keys).
**
** This opcode leaves the cursor in a state where it cannot be advanced
** in either direction. In other words, the Next and Prev opcodes will
** not work following this opcode.
**
** See also: Found, NotFound, NoConflict, SeekRowid
** zIn is a UTF-16 encoded unicode string at least nChar characters long.
** Return the number of bytes in the first nChar unicode characters
** in pZ. nChar must be non-negative.
TK_UPDATE, TK_INSERT or TK_DELETE
There are now 4 possibilities:
**
** 1. uPattern is an unescaped match-all character "%",
** 2. uPattern is an unescaped match-one character "_",
** 3. uPattern is an unescaped escape character, or
** 4. uPattern is to be handled as an ordinary character
PRAGMA synchronous=NORMAL
Like optimization range constraints always occur in pairs
** Implementation of a special SQL scalar function for testing tokenizers
** designed to be used in concert with the Tcl testing framework. This
** function must be called with two or more arguments:
**
** SELECT <function-name>(<key-name>, ..., <input-string>);
**
** where <function-name> is the name passed as the second argument
** to the sqlite3Fts3InitHashTable() function (e.g. 'fts3_tokenizer')
** concatenated with the string '_test' (e.g. 'fts3_tokenizer_test').
**
** The return value is a string that may be interpreted as a Tcl
** list. For each token in the <input-string>, three elements are
** added to the returned list. The first is the token position, the
** second is the token text (folded, stemmed, etc.) and the third is the
** substring of <input-string> associated with the token. For example,
** using the built-in "simple" tokenizer:
**
** SELECT fts_tokenizer_test('simple', 'I don't see how');
**
** will return the string:
**
** "{0 i I 1 dont don't 2 see see 3 how how}"
**
True if resizeIndexObject() has been called
Store result in a memory cell
Size of buffer at zNode
State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END
** Set the pIter->bEof variable based on the state of the sub-iterators.
ORDER BY processing for min() func
** The testcase() macro is only used by the amalgamation. If undefined,
** make it a no-op.
number of sizeof(int) objects needed for zName
The entire tree fits on the root node. Write it to the segdir table.
Number of pages in apNew[]
** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
**
** Register hooks to call to indicate which malloc() failures
** are benign.
Create a new tokenizer
FTS5_VOCAB_COL or ROW
** This function is called to rollback a transaction on a WAL database.
Forward declarations of structures.
Selects no more than one row
comment: If a malloc() failure occurred in sqlite3HashInsert(), it will
** return the pColl pointer to be deleted (because it wasn't added
** to the hash table).
label: code-design
open file object for the database file
Define the fts5yytestcase() macro to be a no-op if is not already defined
** otherwise.
**
** Applications can choose to define fts5yytestcase() in the %include section
** to a macro that can assist in verifying code coverage. For production
** code the fts5yytestcase() macro should be turned off. But it is useful
** for testing.
Number of pages in database after autovacuuming
Check that the new column is not specified as PRIMARY KEY or UNIQUE.
** If there is a NOT NULL constraint, then the default value for the
** column must not be NULL.
** Set the collation function of the most recently parsed table column
** to the CollSeq given.
Existence of VDBE checked by caller
Objects
Chomp all segments opened by this cursor
If there are dirty pages in the page cache with page numbers greater
** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
** make the file smaller (presumably by auto-vacuum code). Do not write
** any such pages to the file.
**
** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
** set (set by sqlite3PagerDontWrite()).
************* End of sqliteInt.h ******************************************
unreachable code
How to dispose of results
Default number of tokens in snippet
Beginning of the body of this loop
** Return true if the prepared statement is in need of being reset.
Pointer to doclist
Schema name of attached database
Fallback token
comment: This index implies that the DISTINCT qualifier is redundant.
label: code-design
These are used by 'col' tables only
** pFile is a file that has been opened by a prior xOpen call. dbPath
** is a string buffer at least MAXPATHLEN+1 characters in size.
**
** This routine find the filename associated with pFile and writes it
** int dbPath.
comment:
** Overview:
**
** The %_data table contains all the FTS indexes for an FTS5 virtual table.
** As well as the main term index, there may be up to 31 prefix indexes.
** The format is similar to FTS3/4, except that:
**
** * all segment b-tree leaf data is stored in fixed size page records
** (e.g. 1000 bytes). A single doclist may span multiple pages. Care is
** taken to ensure it is possible to iterate in either direction through
** the entries in a doclist, or to seek to a specific entry within a
** doclist, without loading it into memory.
**
** * large doclists that span many pages have associated "doclist index"
** records that contain a copy of the first rowid on each page spanned by
** the doclist. This is used to speed up seek operations, and merges of
** large doclists with very small doclists.
**
** * extra fields in the "structure record" record the state of ongoing
** incremental merge operations.
**
label: code-design
comment: The PGHDR_DIRTY bit is set above when the page was added to the dirty-list
** and before writing the page into the rollback journal. Wait until now,
** after the page has been successfully journalled, before setting the
** PGHDR_WRITEABLE bit that indicates that the page can be safely modified.
label: code-design
Default lookaside buffer size
Initialize the contents of sCtx.aTerm[] for column iCol. There is
** no way that this operation can fail, so the return code from
** fts3ExprIterate() can be discarded.
The table being referenced
sqlite3_finalize() return code
If the calls to xBestIndex() in the above loop did not find a plan
** that requires no source tables at all (i.e. one guaranteed to be
** usable), make a call here with all source tables disabled
The input string A
Number of pages written to journal
xOpen
defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
Iterate through all tokens in this AND/NEAR cluster, in ascending order
** of the number of overflow pages that will be loaded by the pager layer
** to retrieve the entire doclist for the token from the full-text index.
** Load the doclists for tokens that are either:
**
** a. The cheapest token in the entire query (i.e. the one visited by the
** first iteration of this loop), or
**
** b. Part of a multi-token phrase.
**
** After each token doclist is loaded, merge it with the others from the
** same phrase and count the number of documents that the merged doclist
** contains. Set variable "nMinEst" to the smallest number of documents in
** any phrase doclist for which 1 or more token doclists have been loaded.
** Let nOther be the number of other phrases for which it is certain that
** one or more tokens will not be deferred.
**
** Then, for each token, defer it if loading the doclist would result in
** loading N or more overflow pages into memory, where N is computed as:
**
** (nMinEst + 4^nOther - 1) / (4^nOther)
** Move the cursor down to the left-most leaf entry beneath the
** entry to which it is currently pointing.
**
** The left-most leaf is the one with the smallest key - the first
** in ascending order.
Internal logic error in SQLite
Parse context
** The macro USEFETCH is true if we are allowed to use the xFetch and xUnfetch
** interfaces to access the database using memory-mapped I/O.
Cannot optimize overly large ORDER BYs
Opcode: Init P1 P2 * P4 *
** Synopsis: Start at P2
**
** Programs contain a single instance of this opcode as the very first
** opcode.
**
** If tracing is enabled (by the sqlite3_trace()) interface, then
** the UTF-8 string contained in P4 is emitted on the trace callback.
** Or if P4 is blank, use the string returned by sqlite3_sql().
**
** If P2 is not zero, jump to instruction P2.
**
** Increment the value of P1 so that OP_Once opcodes will jump the
** first time they are evaluated for this run.
Access to the unixShmNode object is serialized by the caller
Index of next free chunk
** Register built-in functions used to help read ANALYZE data.
Number of indices that need updating
comment:
** This function is used to allocate an Fts3SegReader that iterates through
** a subset of the terms stored in the Fts3Table.pendingTerms array.
**
** If the isPrefixIter parameter is zero, then the returned SegReader iterates
** through each term in the pending-terms table. Or, if isPrefixIter is
** non-zero, it iterates through each term and its prefixes. For example, if
** the pending terms hash table contains the terms "sqlite", "mysql" and
** "firebird", then the iterator visits the following 'terms' (in the order
** shown):
**
** f fi fir fire fireb firebi firebir firebird
** m my mys mysq mysql
** s sq sql sqli sqlit sqlite
**
** Whereas if isPrefixIter is zero, the terms visited are:
**
** firebird mysql sqlite
label: code-design
turn off proxy locking - not supported. If support is added for
** switching proxy locking mode off then it will need to fail if
** the journal mode is WAL mode.
** CAPI3REF: Testing Interface Operation Codes
**
** These constants are the valid operation code parameters used
** as the first argument to [sqlite3_test_control()].
**
** These parameters and their meanings are subject to change
** without notice. These values are for testing purposes only.
** Applications should not use any of these parameters or the
** [sqlite3_test_control()] interface.
90
Delete this when closing file
The hash function
** Locate a pragma in the aPragmaName[] array.
cmd ::= DROP TRIGGER ifexists fullname
True to hash the new.* PK
** The number of different kinds of things that can be limited
** using the sqlite3_limit() interface.
comment: The "xxx" in the name "xxx.yyy" or "xxx"
label: code-design
Size of buffer pToken in bytes
Do not omit these constraints
Search through the cursors list of Fts5Auxdata objects for one that
** corresponds to the currently executing auxiliary function.
Mark all dirty list pages as clean
True for SQLITE_PRINTF_SQLFUNC
Invoke the virtual table xBestIndex() method
True for native byte-order checksums
Hash table iterator
xSavepoint
29
Optional database for lookaside. Can be NULL
Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
** constraints or (b) there are no triggers and this table is not a
** parent table in a foreign key constraint. It is safe to set the
** flag in the second case as if any REPLACE constraint is hit, an
** OP_Delete or OP_IdxDelete instruction will be executed on each
** cursor that is disturbed. And these instructions both clear the
** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
** functionality.
*********** Begin %include sections from the grammar ***********************
comment:
** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
** This allows better measurements of where memcpy() is used when running
** cachegrind. But this macro version of memcpy() is very slow so it
** should not be used in production. This is a performance measurement
** hack only.
label: code-design
TK_COLUMN: column index. -1 for rowid.
** TK_VARIABLE: variable number (always >= 1).
** TK_SELECT_COLUMN: column of the result vector
Address of this instruction
Name of table or index
************* Begin file loadext.c ****************************************
comment:
** CAPI3REF: OS Interface File Virtual Methods Object
**
** Every file opened by the [sqlite3_vfs.xOpen] method populates an
** [sqlite3_file] object (or, more commonly, a subclass of the
** [sqlite3_file] object) with a pointer to an instance of this object.
** This object defines the methods used to perform various operations
** against the open file represented by the [sqlite3_file] object.
**
** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
** to NULL.
**
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
** flag may be ORed in to indicate that only the data of the file
** and not its inode needs to be synced.
**
** The integer values to xLock() and xUnlock() are one of
** <ul>
** <li> [SQLITE_LOCK_NONE],
** <li> [SQLITE_LOCK_SHARED],
** <li> [SQLITE_LOCK_RESERVED],
** <li> [SQLITE_LOCK_PENDING], or
** <li> [SQLITE_LOCK_EXCLUSIVE].
** </ul>
** xLock() increases the lock. xUnlock() decreases the lock.
** The xCheckReservedLock() method checks whether any database connection,
** either in this process or in some other process, is holding a RESERVED,
** PENDING, or EXCLUSIVE lock on the file. It returns true
** if such a lock exists and false otherwise.
**
** The xFileControl() method is a generic interface that allows custom
** VFS implementations to directly control an open file using the
** [sqlite3_file_control()] interface. The second "op" argument is an
** integer opcode. The third argument is a generic pointer intended to
** point to a structure that may contain arguments or space in which to
** write return values. Potential uses for xFileControl() might be
** functions to enable blocking locks with timeouts, to change the
** locking strategy (for example to use dot-file locks), to inquire
** about the status of a lock, or to break stale locks. The SQLite
** core reserves all opcodes less than 100 for its own use.
** A [file control opcodes | list of opcodes] less than 100 is available.
** Applications that define a custom xFileControl method should use opcodes
** greater than 100 to avoid conflicts. VFS implementations should
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
** recognize.
**
** The xSectorSize() method returns the sector size of the
** device that underlies the file. The sector size is the
** minimum write that can be performed without disturbing
** other bytes in the file. The xDeviceCharacteristics()
** method returns a bit vector describing behaviors of the
** underlying device:
**
** <ul>
** <li> [SQLITE_IOCAP_ATOMIC]
** <li> [SQLITE_IOCAP_ATOMIC512]
** <li> [SQLITE_IOCAP_ATOMIC1K]
** <li> [SQLITE_IOCAP_ATOMIC2K]
** <li> [SQLITE_IOCAP_ATOMIC4K]
** <li> [SQLITE_IOCAP_ATOMIC8K]
** <li> [SQLITE_IOCAP_ATOMIC16K]
** <li> [SQLITE_IOCAP_ATOMIC32K]
** <li> [SQLITE_IOCAP_ATOMIC64K]
** <li> [SQLITE_IOCAP_SAFE_APPEND]
** <li> [SQLITE_IOCAP_SEQUENTIAL]
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
** <li> [SQLITE_IOCAP_IMMUTABLE]
** </ul>
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite().
**
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
** in the unread portions of the buffer with zeros. A VFS that
** fails to zero-fill short reads might seem to work. However,
** failure to zero-fill short reads will eventually lead to
** database corruption.
label: code-design
Obtain all b-tree mutexes before making any calls to BtreeRollback().
** This is important in case the transaction being rolled back has
** modified the database schema. If the b-tree mutexes are not taken
** here, then another shared-cache connection might sneak in between
** the database rollback and schema reset, which can cause false
** corruption reports in some cases.
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the SQLite parser
** when syntax rules are reduced. The routines in this file handle the
** following kinds of SQL syntax:
**
** CREATE TABLE
** DROP TABLE
** CREATE INDEX
** DROP INDEX
** creating ID lists
** BEGIN TRANSACTION
** COMMIT
** ROLLBACK
Cursor number for the table
comment:
** A macro used for invoking the codec if there is one
label: code-design
Mask of all ORDER BY terms
All the allocations succeeded. Put the expression object together.
** Different Unix systems declare open() in different ways. Same use
** open(const char*,int,mode_t). Others use open(const char*,int,...).
** The difference is important when using a pointer to the function.
**
** The safest way to deal with the problem is to always use this wrapper
** which always has the same well-defined interface.
The P4 operand as an integer
In a NATURAL join, omit the join columns from the
** table to the right of the join
Add the entries to the stat3 or stat4 table.
Information about each nested IN operator
Replacement values
True for rowid tables. False for indexes
** The number of rowset entries per allocation chunk.
New chunk is required to extend the file.
comment: The VFS pointer. Not used
label: code-design
Return code from sqlite3_prepare()
Set or get the suggested spill-size for the specified pager-cache.
**
** The spill-size is the minimum number of pages in cache before the cache
** will attempt to spill dirty pages by calling xStress.
Type name follows column name
** Advance iterator pIter until it points to a value equal to or laster
** than the initial value of *piLast. If this means the iterator points
** to a value laster than *piLast, update *piLast to the new lastest value.
**
** If the iterator reaches EOF, set *pbEof to true before returning. If
** an error occurs, set *pRc to an error code. If either *pbEof or *pRc
** are set, return a non-zero value. Otherwise, return zero.
comment: TERM_xxx bit flags. See below
label: code-design
Same as READ_UTF8() above but without the zTerm parameter.
** For this routine, we assume the UTF8 string is always zero-terminated.
** The type used to represent a page number. The first page in a file
** is called page 1. 0 is used to represent "not a page".
Page number is 1 or more
True if journal file exists
Number of elements in argv array
** Evaluate a view and store its result in an ephemeral table. The
** pWhere argument is an optional WHERE clause that restricts the
** set of rows in the view that are to be added to the ephemeral table.
Cache configuration parameters. Page size (szPage) and the purgeable
** flag (bPurgeable) are set when the cache is created. nMax may be
** modified at any time by a call to the pcache1Cachesize() method.
** The PGroup mutex must be held when accessing nMax.
** Copy nPage pages from the source b-tree to the destination.
If the output is destined for a temporary table, open that table.
Size of apSegment array
This is the only way out of this procedure. We have to
** release the mutexes on btrees that were acquired at the
** top.
This routine is only called by btree immediately after creating
** the Pager object. There has not been an opportunity to transition
** to WAL mode yet.
Allocate a temporary buffer to store the fully qualified file
** name for the temporary file. If this fails, we cannot continue.
Opcode: BitOr P1 P2 P3 * *
** Synopsis: r[P3]=r[P1]|r[P2]
**
** Take the bit-wise OR of the values in register P1 and P2 and
** store the result in register P3.
** If either input is NULL, the result is NULL.
(2b)
Mask of locks to take or release
** This routine runs at the end of parsing a CREATE TABLE statement that
** has a WITHOUT ROWID clause. The job of this routine is to convert both
** internal schema data structures and the generated VDBE code so that they
** are appropriate for a WITHOUT ROWID table instead of a rowid table.
** Changes include:
**
** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
** (2) Convert the OP_CreateTable into an OP_CreateIndex. There is
** no rowid btree for a WITHOUT ROWID. Instead, the canonical
** data storage is a covering index btree.
** (3) Bypass the creation of the sqlite_master table entry
** for the PRIMARY KEY as the primary key index is now
** identified by the sqlite_master table entry of the table itself.
** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
** schema to the rootpage from the main table.
** (5) Add all table columns to the PRIMARY KEY Index object
** so that the PRIMARY KEY is a covering index. The surplus
** columns are part of KeyInfo.nXField and are not used for
** sorting or lookup or uniqueness checks.
** (6) Replace the rowid tail on all automatically generated UNIQUE
** indices with the PRIMARY KEY columns.
**
** For virtual tables, only (1) is performed.
Store the name and decltype
** The following function extracts information on the current change
** from a changeset iterator. It may only be called after changeset_next()
** has returned SQLITE_ROW.
** Select the fragment of text consisting of nFragment contiguous tokens
** from column iCol that represent the "best" snippet. The best snippet
** is the snippet with the highest score, where scores are calculated
** by adding:
**
** (a) +1 point for each occurrence of a matchable phrase in the snippet.
**
** (b) +1000 points for the first occurrence of each matchable phrase in
** the snippet for which the corresponding mCovered bit is not set.
**
** The selected snippet parameters are stored in structure *pFragment before
** returning. The score of the selected snippet is stored in *piScore
** before returning.
Rhs input changeset
Return code
comment:
** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
** that can be stored in a u32 without loss of data. The value
** is 0x00000000ffffffff. But because of quirks of some compilers, we
** have to specify the value in the less intuitive manner shown:
label: code-design
Num of col names. 0 means use pragma name
** Set the 32-bit cookie value stored at the start of all structure
** records to the value passed as the second argument.
**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
*************************************************************************
** Start of porter stemmer implementation.
18..1f ........
Next buffer in the list of free buffers
Step 5. If we do not care about the difference between NULL and
** FALSE, then just return false.
Number of valid bytes of data in a[]
if i==0 and iCol==0, then record pRec is smaller than all samples
** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
** be greater than or equal to the (iCol) field prefix of sample i.
** If (i>0), then pRec must also be greater than sample (i-1).
** The block of page numbers associated with the first hash-table in a
** wal-index is smaller than usual. This is so that there is a complete
** hash-table on each aligned 32KB page of the wal-index.
comment:
** This function is used by the implementation of the IN (...) operator.
** The pX parameter is the expression on the RHS of the IN operator, which
** might be either a list of expressions or a subquery.
**
** The job of this routine is to find or create a b-tree object that can
** be used either to test for membership in the RHS set or to iterate through
** all members of the RHS set, skipping duplicates.
**
** A cursor is opened on the b-tree object that is the RHS of the IN operator
** and pX->iTable is set to the index of that cursor.
**
** The returned value of this function indicates the b-tree type, as follows:
**
** IN_INDEX_ROWID - The cursor was opened on a database table.
** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
** IN_INDEX_EPH - The cursor was opened on a specially created and
** populated epheremal table.
** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
** implemented as a sequence of comparisons.
**
** An existing b-tree might be used if the RHS expression pX is a simple
** subquery such as:
**
** SELECT <column1>, <column2>... FROM <table>
**
** If the RHS of the IN operator is a list or a more complex subquery, then
** an ephemeral table might need to be generated from the RHS and then
** pX->iTable made to point to the ephemeral table instead of an
** existing table.
**
** The inFlags parameter must contain exactly one of the bits
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP. If inFlags contains
** IN_INDEX_MEMBERSHIP, then the generated table will be used for a
** fast membership test. When the IN_INDEX_LOOP bit is set, the
** IN index will be used to loop over all values of the RHS of the
** IN operator.
**
** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
** through the set members) then the b-tree must not contain duplicates.
** An epheremal table must be used unless the selected columns are guaranteed
** to be unique - either because it is an INTEGER PRIMARY KEY or due to
** a UNIQUE constraint or index.
**
** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
** for fast set membership tests) then an epheremal table must
** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
** index can be found with the specified <columns> as its left-most.
**
** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
** if the RHS of the IN operator is a list (not a subquery) then this
** routine might decide that creating an ephemeral b-tree for membership
** testing is too expensive and return IN_INDEX_NOOP. In that case, the
** calling routine should implement the IN operator using a sequence
** of Eq or Ne comparison operations.
**
** When the b-tree is being used for membership tests, the calling function
** might need to know whether or not the RHS side of the IN operator
** contains a NULL. If prRhsHasNull is not a NULL pointer and
** if there is any chance that the (...) might contain a NULL value at
** runtime, then a register is allocated and the register number written
** to *prRhsHasNull. If there is no chance that the (...) contains a
** NULL value, then *prRhsHasNull is left unchanged.
**
** If a register is allocated and its location stored in *prRhsHasNull, then
** the value in that register will be NULL if the b-tree contains one or more
** NULL values, and it will be some non-NULL value if the b-tree contains no
** NULL values.
**
** If the aiMap parameter is not NULL, it must point to an array containing
** one element for each column returned by the SELECT statement on the RHS
** of the IN(...) operator. The i'th entry of the array is populated with the
** offset of the index column that matches the i'th column returned by the
** SELECT. For example, if the expression and selected index are:
**
** (?,?,?) IN (SELECT a, b, c FROM t1)
** CREATE INDEX i1 ON t1(b, c, a);
**
** then aiMap[] is populated with {2, 0, 1}.
label: code-design
Next in linked list (see above)
Allocate space for the new unixShm object.
** Return TRUE if the given yDbMask object is empty - if it contains no
** 1 bits. This routine is used by the DbMaskAllZero() and DbMaskNotZero()
** macros when SQLITE_MAX_ATTACHED is greater than 30.
** An instance of the following structure is allocated for each open
** inode. Or, on LinuxThreads, there is one of these structures for
** each inode opened by each thread.
**
** A single inode can have multiple file descriptors, so each unixFile
** structure contains a pointer to an instance of this object and this
** object keeps a count of the number of unixFile pointing to it.
trigger_cmd ::= insert_cmd INTO trnm idlist_opt select
STEP 3:
** Loop through the entire memory pool. Coalesce adjacent free
** chunks. Recompute the master chunk as the largest free chunk.
** Then try again to satisfy the allocation by carving a piece off
** of the end of the master chunk. This step happens very
** rarely (we hope!)
#include <stdarg.h>
Unpacked version of key
True if the output segment is the oldest
True if IDLIST is in table order
assert( pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
** Each call to sqlite3_rtree_geometry_callback() or
** sqlite3_rtree_query_callback() creates an ordinary SQLite
** scalar function that is implemented by this routine.
**
** All this function does is construct an RtreeMatchArg object that
** contains the geometry-checking callback routines and a list of
** parameters to this function, then return that RtreeMatchArg object
** as a BLOB.
**
** The R-Tree MATCH operator will read the returned BLOB, deserialize
** the RtreeMatchArg object, and use the RtreeMatchArg object to figure
** out which elements of the R-Tree should be returned by the query.
Opcode: VRename P1 * * P4 *
**
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
** This opcode invokes the corresponding xRename method. The value
** in register P1 is passed as the zName argument to the xRename method.
Opcode: Sort P1 P2 * * *
**
** This opcode does exactly the same thing as OP_Rewind except that
** it increments an undocumented global variable used for testing.
**
** Sorting is accomplished by writing records into a sorting index,
** then rewinding that index and playing it back from beginning to
** end. We use the OP_Sort opcode instead of OP_Rewind to do the
** rewinding so that the global variable will be incremented and
** regression tests can determine whether or not the optimizer is
** correctly optimizing out sorts.
** CAPI3REF: Determine If An SQL Statement Writes The Database
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
** and only if the [prepared statement] X makes no direct changes to
** the content of the database file.
**
** Note that [application-defined SQL functions] or
** [virtual tables] might change the database indirectly as a side effect.
** ^(For example, if an application defines a function "eval()" that
** calls [sqlite3_exec()], then the following SQL statement would
** change the database file through side-effects:
**
** <blockquote><pre>
** SELECT eval('DELETE FROM t1') FROM t2;
** </pre></blockquote>
**
** But because the [SELECT] statement does not change the database file
** directly, sqlite3_stmt_readonly() would still return true.)^
**
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
** since the statements themselves do not actually modify the database but
** rather they control the timing of when other statements modify the
** database. ^The [ATTACH] and [DETACH] statements also cause
** sqlite3_stmt_readonly() to return true since, while those statements
** change the configuration of a database connection, they do not make
** changes to the content of the database files on disk.
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
** sqlite3_stmt_readonly() returns false for those commands.
** pTab is a pointer to a Table structure representing a virtual-table.
** Return a pointer to the VTable object used by connection db to access
** this virtual-table, if one has been created, or NULL otherwise.
If condition (a) is not met, assume (b) is true. StructurePromoteTo()
** is a no-op if it is not.
Number of samples
assume positive
161
** Once the sorter has been populated by calls to sqlite3VdbeSorterWrite,
** this function is called to prepare for iterating through the records
** in sorted order.
comment:
** CAPI3REF: Declare The Schema Of A Virtual Table
**
** ^The [xCreate] and [xConnect] methods of a
** [virtual table module] call this interface
** to declare the format (the names and datatypes of the columns) of
** the virtual tables they implement.
label: code-design
IN/OUT: Iterator pointer
** *pCurrent gets an accurate estimate of the amount of memory used
** to store all prepared statements.
** *pHighwater is set to zero.
Number of phrases in query
If the sqlite_sequence table exists in this database, then update
** it with the new table name.
Value of %_segdir.end_block
SQLITE_STATUS_PARSER_STACK
A 32-bit varint is used to store size information in btrees.
** Objects are rarely larger than 2MiB limit of a 3-byte varint.
** A 3-byte varint is sufficient, for example, to record the size
** of a 1048569-byte BLOB or string.
**
** We only unroll the first 1-, 2-, and 3- byte cases. The very
** rare larger cases can be handled by the slower 64-bit varint
** routine.
Saved value of db->suppressErr
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.
**
** If an error occurs, an error code is returned and *pp is set to NULL.
**
** Otherwise, if the isWrite parameter is 0 and the requested shared-memory
** region has not been allocated (by any client, including one running in a
** separate process), then *pp is set to NULL and SQLITE_OK returned. If
** isWrite is non-zero and the requested shared-memory region has not yet
** been allocated, it is allocated by this function.
**
** If the shared-memory region has already been allocated or is allocated by
** this call as described above, then it is mapped into this processes
** address space (if it is not already), *pp is set to point to the mapped
** memory and SQLITE_OK returned.
Template for VFS
IN/OUT: Docid pointer
** The xSavepoint method.
**
** This module does not need to do anything to support savepoints. However,
** it uses this hook to close any open blob handle. This is done because a
** DROP TABLE command - which fortunately always opens a savepoint - cannot
** succeed if there are any open blob handles. i.e. if the blob handle were
** not closed here, the following would fail:
**
** BEGIN;
** INSERT INTO rtree...
** DROP TABLE <tablename>; -- Would fail with SQLITE_LOCKED
** COMMIT;
Check if the query is of one of the following forms:
**
** SELECT min(x) FROM ...
** SELECT max(x) FROM ...
**
** If it is, then ask the code in where.c to attempt to sort results
** as if there was an "ORDER ON x" or "ORDER ON x DESC" clause.
** If where.c is able to produce results sorted in this order, then
** add vdbe code to break out of the processing loop after the
** first iteration (since the first iteration of the loop is
** guaranteed to operate on the row with the minimum or maximum
** value of x, the only row required).
**
** A special flag must be passed to sqlite3WhereBegin() to slightly
** modify behavior as follows:
**
** + If the query is a "SELECT min(x)", then the loop coded by
** where.c should not iterate over any values with a NULL value
** for x.
**
** + The optimizer code in where.c (the thing that decides which
** index or indices to use) should place a different priority on
** satisfying the 'ORDER BY' clause than it does in other cases.
** Refer to code and comments in where.c for details.
** Return the sector-size in bytes for an rbuVfs-file.
** Record the set of tables that satisfy case 3. The set might be
** empty.
Byte offset of end of token within input text
Parent node
Next entry is not on the current page
True once iDelta has been written
** Each auxiliary function registered with the FTS5 module is represented
** by an object of the following type. All such objects are stored as part
** of the Fts5Global.pAux list.
Write the new value here
Cursor to retrieve value from
OUT: Write the score here
comment:
** Move to the next document
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
** is not considered an error if the query does not match any documents.
label: documentation
** Rowids for the averages and structure records in the %_data table.
First varint to store in hint
Mask of all non-compound WO_* values
Use the two-part index name to determine the database
** to search for the table. 'Fix' the table name to this db
** before looking up the table.
1330
** Store the current contents of the p->nTotalRow and p->aTotalSize[]
** variables in the "averages" record on disk.
**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
** Generate code for a BETWEEN operator.
**
** x BETWEEN y AND z
**
** The above is equivalent to
**
** x>=y AND x<=z
**
** Code it as such, taking care to do the common subexpression
** elimination of x.
**
** The xJumpIf parameter determines details:
**
** NULL: Store the boolean result in reg[dest]
** sqlite3ExprIfTrue: Jump to dest if true
** sqlite3ExprIfFalse: Jump to dest if false
**
** The jumpIfNull parameter is ignored if xJumpIf is NULL.
Delete any foreign keys attached to this table.
Index of the database containing the table to lock
Backup is not possible if the page size of the destination is changing
** and a codec is in use.
** Argument is a pointer to an Fts5Data structure that contains a
** leaf page.
Size of apVal[] array
** Resolve label "x" to be the address of the next instruction to
** be inserted. The parameter "x" must have been obtained from
** a prior call to sqlite3VdbeMakeLabel().
Check that the page exists
Forward references to the various page getters
** Indicate that subsequent calls to sqlite3Fts5IndexWrite() pertain to
** document iDocid.
Number of entries in aPhrase[] array
Flags that can be added to a token code when it is not
** being stored in a u8:
Justification of ALWAYS(); The index must be on the list of
** indices.
This block serves to assert() that the cursor really does point
** to the last entry in the b-tree.
Pointer to a prior allocation
Base register where results are written
Handle pointing to row containing value
Grow the hash table if required
Table associated with change
** Maximum error message length (in chars) for WinRT.
zNum is empty or contains non-numeric text or is longer
** than 19 digits (thus guaranteeing that it is too large)
Value to return if (rhs < lhs)
Opcode: Divide P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]/r[P1]
**
** Divide the value in register P1 by the value in register P2
** and store the result in register P3 (P3=P2/P1). If the value in
** register P1 is zero, then the result is NULL. If either input is
** NULL, the result is NULL.
326
** Obtain permyriadage (permyriadage is to 10000 as percentage is to 100)
** progress indications for the two stages of an RBU update. This API may
** be useful for driving GUI progress indicators and similar.
**
** An RBU update is divided into two stages:
**
** * Stage 1, in which changes are accumulated in an oal/wal file, and
** * Stage 2, in which the contents of the wal file are copied into the
** main database.
**
** The update is visible to non-RBU clients during stage 2. During stage 1
** non-RBU reader clients may see the original database.
**
** If this API is called during stage 2 of the update, output variable
** (*pnOne) is set to 10000 to indicate that stage 1 has finished and (*pnTwo)
** to a value between 0 and 10000 to indicate the permyriadage progress of
** stage 2. A value of 5000 indicates that stage 2 is half finished,
** 9000 indicates that it is 90% finished, and so on.
**
** If this API is called during stage 1 of the update, output variable
** (*pnTwo) is set to 0 to indicate that stage 2 has not yet started. The
** value to which (*pnOne) is set depends on whether or not the RBU
** database contains an "rbu_count" table. The rbu_count table, if it
** exists, must contain the same columns as the following:
**
** CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
**
** There must be one row in the table for each source (data_xxx) table within
** the RBU database. The 'tbl' column should contain the name of the source
** table. The 'cnt' column should contain the number of rows within the
** source table.
**
** If the rbu_count table is present and populated correctly and this
** API is called during stage 1, the *pnOne output variable is set to the
** permyriadage progress of the same stage. If the rbu_count table does
** not exist, then (*pnOne) is set to -1 during stage 1. If the rbu_count
** table exists but is not correctly populated, the value of the *pnOne
** output variable during stage 1 is undefined.
Maximum number of entries in hash table before
** sub-dividing and re-hashing.
IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns
** zero if and only if SQLite was compiled with mutexing code omitted due to
** the SQLITE_THREADSAFE compile-time option being set to 0.
comment: If the file was just truncated to a size smaller than the currently
** mapped region, reduce the effective mapping size as well. SQLite will
** use read() and write() to access data beyond this point from now on.
label: code-design
Best index found so far
Number of bytes in zPathname
An ORDER BY or GROUP BY clause to resolve
Page number of current leaf page
xDestroy
Bytes of content in pCell
Opcode: BitNot P1 P2 * * *
** Synopsis: r[P1]= ~r[P1]
**
** Interpret the content of register P1 as an integer. Store the
** ones-complement of the P1 value into register P2. If P1 holds
** a NULL then store a NULL in P2.
True to unlink wal and wal-index files
The OFFSET expression. NULL if there is none
** CAPI3REF: Low-level system error code
**
** ^Attempt to return the underlying operating system error code or error
** number that caused the most recent I/O error or failure to open a file.
** The return value is OS-dependent. For example, on unix systems, after
** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
** called to get back the underlying "errno" that caused the problem, such
** as ENOSPC, EAUTH, EISDIR, and so forth.
Used only by system that substitute their own storage engine
trigger_time ::=
rowid >= ? expression (or NULL)
Number of outstanding xFetch refs
adjust exponent by d, and update sign
57
If Y==0 and X will fit in a 64-bit int,
** handle the rounding directly,
** otherwise use printf.
** Deallocate and destroy a parser. Destructors are called for
** all stack elements before shutting the parser down.
**
** If the YYPARSEFREENEVERNULL macro exists (for example because it
** is defined in a %include section of the input grammar) then it is
** assumed that the input pointer is never NULL.
An open database
Parent table of FK constraint pFKey
Pointer to the end of the file
Generate code to implement the subquery
**
** The subquery is implemented as a co-routine if all of these are true:
** (1) The subquery is guaranteed to be the outer loop (so that it
** does not need to be computed more than once)
** (2) The ALL keyword after SELECT is omitted. (Applications are
** allowed to say "SELECT ALL" instead of just "SELECT" to disable
** the use of co-routines.)
** (3) Co-routines are not disabled using sqlite3_test_control()
** with SQLITE_TESTCTRL_OPTIMIZATIONS.
**
** TODO: Are there other reasons beside (1) to use a co-routine
** implementation?
VDBE cursor number of the pSub result set temp table
******************************** Win32 Threads ***************************
True if range end uses ==, >= or <=
Fill in the zName and zDb fields of the vtab structure.
Index in p->pSrc->a[] of the inner subquery
LHS of LIKE/GLOB operator
** Construct one or more SQL statements from the format string given
** and then evaluate those statements. The success code is written
** into *pRc.
**
** If *pRc is initially non-zero then this routine is a no-op.
comment:
** This function is called by unixOpen() to determine the unix permissions
** to create new files with. If no error occurs, then SQLITE_OK is returned
** and a value suitable for passing as the third argument to open(2) is
** written to *pMode. If an IO error occurs, an SQLite error code is
** returned and the value of *pMode is not modified.
**
** In most cases, this routine sets *pMode to 0, which will become
** an indication to robust_open() to create the file using
** SQLITE_DEFAULT_FILE_PERMISSIONS adjusted by the umask.
** But if the file being opened is a WAL or regular journal file, then
** this function queries the file-system for the permissions on the
** corresponding database file and sets *pMode to this value. Whenever
** possible, WAL and journal files are created using the same permissions
** as the associated database file.
**
** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
** original filename is unavailable. But 8_3_NAMES is only used for
** FAT filesystems and permissions do not matter there, so just use
** the default permissions.
label: code-design
True if input contains UTF16 with high byte non-zero
SQLITE_AFF_BLOB
254
193
Symbol on the left-hand side of the rule
Assuming no errors have occurred, set up a merger structure to
** incrementally read and merge all remaining PMAs.
True if the doclist is desc
287
311
************* End of keywordhash.h ****************************************
Page header size. 0 or 100
Work around a sign-extension bug in the HP compiler for HP/UX
Cursor for table associated with pIdx
Jump to the this point in order to terminate the query.
Cursor returned by simpleOpen
c0..c7 ........
** If the expression p codes a constant integer that is small enough
** to fit in a 32-bit integer, return 1 and put the value of the integer
** in *pValue. If the expression is not an integer or if it is too big
** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
** Allocate an appendable output segment on absolute level iAbsLevel+1
** with idx value iIdx.
**
** In the %_segdir table, a segment is defined by the values in three
** columns:
**
** start_block
** leaves_end_block
** end_block
**
** When an appendable segment is allocated, it is estimated that the
** maximum number of leaf blocks that may be required is the sum of the
** number of leaf blocks consumed by the input segments, plus the number
** of input segments, multiplied by two. This value is stored in stack
** variable nLeafEst.
**
** A total of 16*nLeafEst blocks are allocated when an appendable segment
** is created ((1 + end_block - start_block)==16*nLeafEst). The contiguous
** array of leaf nodes starts at the first block allocated. The array
** of interior nodes that are parents of the leaf nodes start at block
** (start_block + (1 + end_block - start_block) / 16). And so on.
**
** In the actual code below, the value "16" is replaced with the
** pre-processor macro FTS_MAX_APPENDABLE_HEIGHT.
if SQLITE_THREADSAFE
Stop the operation but leave all prior changes
Pointer to the rightmost select in sub-query
Read the %_segdir entry for index iIdx absolute level (iAbsLevel+1)
Client data for xCreate/xConnect
Used to iterate through samples
Write new entries to *(*ppTC)++
'-'. Minus or SQL-style comment
** Valid sqlite3_blob* handles point to Incrblob structures.
ICU break-iterator object
Read the first integer value
Iterator for WHERE terms
comment: Attempt a direct implementation of the built-in COALESCE() and
** IFNULL() functions. This avoids unnecessary evaluation of
** arguments past the first non-NULL argument.
label: code-design
The output
Possibly new term to test
Total cost of this path
Tokenizer hash table
Final block of segment
215
P2 to OP_Open** is a register number
attempt to handle extremely small/large numbers better
jump, in1, out3
Write the new old.* record. Consists of the PK columns from the
** original old.* record, and the other values from the original
** new.* record.
etfs cluster size writes are atomic
comment:
** CAPI3REF: Convenience Routines For Running Queries
** METHOD: sqlite3
**
** This is a legacy interface that is preserved for backwards compatibility.
** Use of this interface is not recommended.
**
** Definition: A <b>result table</b> is memory data structure created by the
** [sqlite3_get_table()] interface. A result table records the
** complete query results from one or more queries.
**
** The table conceptually has a number of rows and columns. But
** these numbers are not part of the result table itself. These
** numbers are obtained separately. Let N be the number of rows
** and M be the number of columns.
**
** A result table is an array of pointers to zero-terminated UTF-8 strings.
** There are (N+1)*M elements in the array. The first M pointers point
** to zero-terminated strings that contain the names of the columns.
** The remaining entries all point to query results. NULL values result
** in NULL pointers. All other values are in their UTF-8 zero-terminated
** string representation as returned by [sqlite3_column_text()].
**
** A result table might consist of one or more memory allocations.
** It is not safe to pass a result table directly to [sqlite3_free()].
** A result table should be deallocated using [sqlite3_free_table()].
**
** ^(As an example of the result table format, suppose a query result
** is as follows:
**
** <blockquote><pre>
** Name | Age
** -----------------------
** Alice | 43
** Bob | 28
** Cindy | 21
** </pre></blockquote>
**
** There are two column (M==2) and three rows (N==3). Thus the
** result table has 8 entries. Suppose the result table is stored
** in an array names azResult. Then azResult holds this content:
**
** <blockquote><pre>
** azResult[0] = "Name";
** azResult[1] = "Age";
** azResult[2] = "Alice";
** azResult[3] = "43";
** azResult[4] = "Bob";
** azResult[5] = "28";
** azResult[6] = "Cindy";
** azResult[7] = "21";
** </pre></blockquote>)^
**
** ^The sqlite3_get_table() function evaluates one or more
** semicolon-separated SQL statements in the zero-terminated UTF-8
** string of its 2nd parameter and returns a result table to the
** pointer given in its 3rd parameter.
**
** After the application has finished with the result from sqlite3_get_table(),
** it must pass the result table pointer to sqlite3_free_table() in order to
** release the memory that was malloced. Because of the way the
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
** function must not try to call [sqlite3_free()] directly. Only
** [sqlite3_free_table()] is able to release the memory properly and safely.
**
** The sqlite3_get_table() interface is implemented as a wrapper around
** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
** to any internal data structures of SQLite. It uses only the public
** interface defined here. As a consequence, errors that occur in the
** wrapper layer outside of the internal [sqlite3_exec()] call are not
** reflected in subsequent calls to [sqlite3_errcode()] or
** [sqlite3_errmsg()].
label: code-design
Convert the OP_CreateTable opcode that would normally create the
** root-page for the table into an OP_CreateIndex opcode. The index
** created will become the PRIMARY KEY index.
Take care here not to generate a TK_VECTOR containing only a
** single value. Since the parser never creates such a vector, some
** of the subroutines do not handle this case.
** For table-valued-functions, transform the function arguments into
** new WHERE clause terms.
**
** Each function argument translates into an equality constraint against
** a HIDDEN column in the table.
IMP: R-17817-00630
** Write code to erase the table with root-page iTable from database iDb.
** Also write code to modify the sqlite_master table and internal schema
** if a root-page of another table is moved by the btree-layer whilst
** erasing iTable (this can happen with an auto-vacuum database).
Object being parsed at the point of error
init_deferred_pred_opt ::= INITIALLY IMMEDIATE
Restriction (3)
Generation counter. Incremented with each change
What version of MSVC is being used. 0 means MSVC is not being used
Original schema cookie in destination
Try to pull the page from the write-ahead log.
If more than one frame was recovered from the log file, report an
** event via sqlite3_log(). This is to help with identifying performance
** problems caused by applications routinely shutting down without
** checkpointing the log file.
comment:
** THREAD SAFETY NOTES:
**
** Once it has been created using backup_init(), a single sqlite3_backup
** structure may be accessed via two groups of thread-safe entry points:
**
** * Via the sqlite3_backup_XXX() API function backup_step() and
** backup_finish(). Both these functions obtain the source database
** handle mutex and the mutex associated with the source BtShared
** structure, in that order.
**
** * Via the BackupUpdate() and BackupRestart() functions, which are
** invoked by the pager layer to report various state changes in
** the page cache associated with the source database. The mutex
** associated with the source database BtShared structure will always
** be held when either of these functions are invoked.
**
** The other sqlite3_backup_XXX() API functions, backup_remaining() and
** backup_pagecount() are not thread-safe functions. If they are called
** while some other thread is calling backup_step() or backup_finish(),
** the values returned may be invalid. There is no way for a call to
** BackupUpdate() or BackupRestart() to interfere with backup_remaining()
** or backup_pagecount().
**
** Depending on the SQLite configuration, the database handles and/or
** the Btree objects may have their own mutexes that require locking.
** Non-sharable Btrees (in-memory databases for example), do not have
** associated mutexes.
label: requirement
Magic number to detect structure corruption.
Mask of ORDER BY terms satisfied so far
Append to this buffer
typetoken ::= typename LP signed COMMA signed RP
ERROR: copy extends past end of input
Jump here to break out of UPDATE loop
Modify the .nOut and maybe .rRun fields
*************************************************************************
** Utility routines for dealing with JsonString objects
*************************************************************************
** END OF REGISTRATION API
************************************************************************
An unconstrained column that might be NULL means that this
** WhereLoop is not well-ordered
Extra table options. Usually 0.
True if records are patchset records
Make sure the locking sequence is correct
** (1) We never move from unlocked to anything higher than shared lock.
** (2) SQLite never explicitly requests a pendig lock.
** (3) A shared lock is always held when a reserve lock is requested.
At one point the following block copied a single frame from the
** wal file to the database file. So that one call to sqlite3rbu_step()
** checkpointed a single frame.
**
** However, if the sector-size is larger than the page-size, and the
** application calls sqlite3rbu_savestate() or close() immediately
** after this step, then rbu_step() again, then a power failure occurs,
** then the database page written here may be damaged. Work around
** this by checkpointing frames until the next page in the aFrame[]
** lies on a different disk sector to the current one.
Operation Savepoint Name
If this frame set completes a transaction, then nTruncate>0. If
** nTruncate==0 then this frame set does not complete the transaction.
************* Include hwtime.h in the middle of vdbe.c ********************
HAVE_LOCALTIME_R || HAVE_LOCALTIME_S
** If SQLITE_RTREE_INT_ONLY is defined, then this virtual table will
** only deal with integer coordinates. No floating point operations
** will be done.
Space used in zNewRecord[] header
ON DELETE action
Unable to edit this page. Rebuild it from scratch instead.
SQLITE_SCHEMA
** xEof - Return true if the cursor is at EOF, or false otherwise.
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation for TRIGGERs
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
** but are associated with the library instead of the header file. ^(Cautious
** programmers might include assert() statements in their application to
** verify that values returned by these interfaces match the macros in
** the header, and thus ensure that the application is
** compiled with matching library and header files.
**
** <blockquote><pre>
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
** </pre></blockquote>)^
**
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
** macro. ^The sqlite3_libversion() function returns a pointer to the
** to the sqlite3_version[] string constant. The sqlite3_libversion()
** function is provided for use in DLLs since DLL users usually do not have
** direct access to string constants within the DLL. ^The
** sqlite3_libversion_number() function returns an integer equal to
** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
** a pointer to a string constant whose value is the same as the
** [SQLITE_SOURCE_ID] C preprocessor macro.
**
** See also: [sqlite_version()] and [sqlite_source_id()].
** This function is called by the parser to process a string token. The
** string may or may not be quoted. In any case it is tokenized and a
** phrase object consisting of all tokens returned.
** Return the cost of sorting nRow rows, assuming that the keys have
** nOrderby columns and that the first nSorted columns are already in
** order.
** CAPI3REF: Load An Extension
** METHOD: sqlite3
**
** ^This interface loads an SQLite extension library from the named file.
**
** ^The sqlite3_load_extension() interface attempts to load an
** [SQLite extension] library contained in the file zFile. If
** the file cannot be loaded directly, attempts are made to load
** with various operating-system specific extensions added.
** So for example, if "samplelib" cannot be loaded, then names like
** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
** be tried also.
**
** ^The entry point is zProc.
** ^(zProc may be 0, in which case SQLite will try to come up with an
** entry point name on its own. It first tries "sqlite3_extension_init".
** If that does not work, it constructs a name "sqlite3_X_init" where the
** X is consists of the lower-case equivalent of all ASCII alphabetic
** characters in the filename from the last "/" to the first following
** "." and omitting any initial "lib".)^
** ^The sqlite3_load_extension() interface returns
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
** ^If an error occurs and pzErrMsg is not 0, then the
** [sqlite3_load_extension()] interface shall attempt to
** fill *pzErrMsg with error message text stored in memory
** obtained from [sqlite3_malloc()]. The calling function
** should free this memory by calling [sqlite3_free()].
**
** ^Extension loading must be enabled using
** [sqlite3_enable_load_extension()] or
** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
** prior to calling this API,
** otherwise an error will be returned.
**
** <b>Security warning:</b> It is recommended that the
** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
** interface. The use of the [sqlite3_enable_load_extension()] interface
** should be avoided. This will keep the SQL function [load_extension()]
** disabled and prevent SQL injections from giving attackers
** access to extension loading capabilities.
**
** See also the [load_extension() SQL function].
Opcode: ResetCount * * * * *
**
** The value of the change counter is copied to the database handle
** change counter (returned by subsequent calls to sqlite3_changes()).
** Then the VMs internal change counter resets to 0.
** This is used by trigger programs.
1: Open a cursor
If there is already a lock of this type or more restrictive on the
** OsFile, do nothing. Don't use the end_lock: exit path, as
** sqlite3OsEnterMutex() hasn't been called yet.
Entry point. Derived from zFile if 0
sortlist
** Cast the datatype of the value in pMem according to the affinity
** "aff". Casting is different from applying affinity in that a cast
** is forced. In other words, the value is converted into the desired
** affinity even if that results in loss of data. This routine is
** used (for example) to implement the SQL "cast()" operator.
** Append the hash of the blob passed via the second and third arguments to
** the hash-key value passed as the first. Return the new hash-key value.
Handle to the database.
comment:
** 2013-11-12
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains structure and macro definitions for the query
** planner logic in "where.c". These definitions are broken out into
** a separate source file for easier editing.
label: code-design
** Format and write a message to the log if logging is enabled.
The input VList. Might be NULL
Free any SQLite statements used while processing the previous object
OUT: Error message
Allowed values for WhereLoopBuider.bldFlags
Backup is not possible if the number of bytes of reserve space differ
** between source and destination. If there is a difference, try to
** fix the destination to agree with the source. If that is not possible,
** then the backup cannot proceed.
** The RBU handle is currently in RBU_STAGE_OAL state, with a SHARED lock
** on the database file. This proc moves the *-oal file to the *-wal path,
** then reopens the database file (this time in vanilla, non-oal, WAL mode).
** If an error occurs, leave an error code and error message in the rbu
** handle.
The requested region is not mapped into this processes address space.
** Check to see if it has been allocated (i.e. if the wal-index file is
** large enough to contain the requested region).
************* Begin file rtree.c ******************************************
Cell to insert into rtree
Allocate temporary space used by the merge-sort routine. This block
** of memory will be freed before this function returns.
True if pTask->pUnpacked is pKey2
Not a correlated subquery
Bitmask of tables used by pExpr->pRight
Net change in number of documents
Maximum column in pSrc->colUsed
(2)
** Construct and install a Module object for a virtual table. When this
** routine is called, it is guaranteed that all appropriate locks are held
** and the module is not already part of the connection.
Expressions that are indexed
The element to be removed from the pH
** If it is currently memory mapped, unmap file pFd.
The recursive part of a recursive CTE
Callback routine requested an abort
** Initialize the MergeEngine object passed as the second argument. Once this
** function returns, the first key of merged data may be read from the
** MergeEngine object in the usual fashion.
**
** If argument eMode is INCRINIT_ROOT, then it is assumed that any IncrMerge
** objects attached to the PmaReader objects that the merger reads from have
** already been populated, but that they have not yet populated aFile[0] and
** set the PmaReader objects up to read from it. In this case all that is
** required is to call vdbePmaReaderNext() on each PmaReader to point it at
** its first key.
**
** Otherwise, if eMode is any value other than INCRINIT_ROOT, then use
** vdbePmaReaderIncrMergeInit() to initialize each PmaReader that feeds data
** to pMerger.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
No need to use cachedCellSize() here. The sizes of all cells that
** are to be freed have already been computing while deciding which
** cells need freeing
Only needed by assert() statements
Content is raw, not JSON encoded
Decode the three function arguments
170
comment:
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the sqlite3_get_table() and sqlite3_free_table()
** interface routines. These are just wrappers around the main
** interface routine of sqlite3_exec().
**
** These routines are in a separate files so that they will not be linked
** if they are not used.
label: code-design
Buffer to merge doclists in
raisetype ::= FAIL
** This function is called when a transaction opened by the database
** handle associated with the VM passed as an argument is about to be
** committed. If there are outstanding deferred foreign key constraint
** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK.
**
** If there are outstanding FK violations and this function returns
** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT_FOREIGNKEY
** and write an error message to it. Then return SQLITE_ERROR.
** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields
** are necessary under two condidtions: (1) Debug builds and (2) using
** home-grown mutexes. Encapsulate these conditions into a single #define.
** Return an Expr object that refers to column iCol of table pTab which
** has cursor iCur.
Colset to filter on
** Sort the linked list of records headed at pTask->pList. Return
** SQLITE_OK if successful, or an SQLite error code (i.e. SQLITE_NOMEM) if
** an error occurs.
Store the token that zCsr points to in tname.
We explicitly don't support UTF-8 delimiters for now.
using_opt ::= USING LP idlist RP
** If parameter iOp is less than zero, then invoke the destructor for
** all auxiliary data pointers currently cached by the VM passed as
** the first argument.
**
** Or, if iOp is greater than or equal to zero, then the destructor is
** only invoked for those auxiliary data pointers created by the user
** function invoked by the OP_Function opcode at instruction iOp of
** VM pVdbe, and only then if:
**
** * the associated function parameter is the 32nd or later (counting
** from left to right), or
**
** * the corresponding bit in argument mask is clear (where the first
** function parameter corresponds to bit 0 etc.).
** Set or retrieve the codec for this pager
Forward Declaration
Shared memory segment information
EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
** fractions and the leaf payload fraction values must be 64, 32, and 32.
**
** The original design allowed these amounts to vary, but as of
** version 3.6.0, we require them to be fixed.
When the NATURAL keyword is present, add WHERE clause terms for
** every column that the two tables have in common.
Test to make sure the linear array exactly matches the
** Bitvec object. Start with the assumption that they do
** match (rc==0). Change rc to non-zero if a discrepancy
** is found.
** A memory allocation (also called a "chunk") consists of two or
** more blocks where each block is 8 bytes. The first 8 bytes are
** a header that is not returned to the user.
**
** A chunk is two or more blocks that is either checked out or
** free. The first block has format u.hdr. u.hdr.size4x is 4 times the
** size of the allocation in blocks if the allocation is free.
** The u.hdr.size4x&1 bit is true if the chunk is checked out and
** false if the chunk is on the freelist. The u.hdr.size4x&2 bit
** is true if the previous chunk is checked out and false if the
** previous chunk is free. The u.hdr.prevSize field is the size of
** the previous chunk in blocks if the previous chunk is on the
** freelist. If the previous chunk is checked out, then
** u.hdr.prevSize can be part of the data for that chunk and should
** not be read or written.
**
** We often identify a chunk by its index in mem3.aPool[]. When
** this is done, the chunk index refers to the second block of
** the chunk. In this way, the first chunk has an index of 1.
** A chunk index of 0 means "no such chunk" and is the equivalent
** of a NULL pointer.
**
** The second block of free chunks is of the form u.list. The
** two fields form a double-linked list of chunks of related sizes.
** Pointers to the head of the list are stored in mem3.aiSmall[]
** for smaller chunks and mem3.aiHash[] for larger chunks.
**
** The second block of a chunk is user data if the chunk is checked
** out. If a chunk is checked out, the user data may extend into
** the u.hdr.prevSize value of the following chunk.
** This is a copy of the sqlite3GetVarint32() routine from the SQLite core.
** Except, this version does handle the single byte case that the core
** version depends on being handled before its function is called.
** Change the value of the P4 operand for a specific instruction.
** This routine is useful when a large program is loaded from a
** static array using sqlite3VdbeAddOpList but we want to make a
** few minor changes to the program.
**
** If n>=0 then the P4 operand is dynamic, meaning that a copy of
** the string is made into memory obtained from sqlite3_malloc().
** A value of n==0 means copy bytes of zP4 up to and including the
** first null byte. If n>0 then copy n+1 bytes of zP4.
**
** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points
** to a string or structure that is guaranteed to exist for the lifetime of
** the Vdbe. In these cases we can just copy the pointer.
**
** If addr<0 then change P4 on the most recently inserted instruction.
sqlite3PageMalloc()
Memory location that acts as accumulator
pPage might not be a btree page; it might be an overflow page
** or ptrmap page or a free page. In those cases, the following
** call to btreeInitPage() will likely return SQLITE_CORRUPT.
** But no harm is done by this. And it is very important that
** btreeInitPage() be called on every btree page so we make
** the call for every page that comes in for re-initing.
Size each output buffer in bytes
Number of retrys
OUT: Score
Allocate the iterator
** This function is an optimized version of sqlite3VdbeRecordCompare()
** that (a) the first field of pPKey2 is a string, that (b) the first field
** uses the collation sequence BINARY and (c) that the size-of-header varint
** at the start of (pKey1/nKey1) fits in a single byte.
dbnm ::= DOT nm
s: p0<<21 | p1<<14 | p2<<7 | p3 (masked)
If an error occurred in findInodeInfo(), close the file descriptor
** immediately, before releasing the mutex. findInodeInfo() may fail
** in two scenarios:
**
** (a) A call to fstat() failed.
** (b) A malloc failed.
**
** Scenario (b) may only occur if the process is holding no other
** file descriptors open on the same file. If there were other file
** descriptors on this file, then no malloc would be required by
** findInodeInfo(). If this is the case, it is quite safe to close
** handle h - as it is guaranteed that no posix locks will be released
** by doing so.
**
** If scenario (a) caused the error then things are not so safe. The
** implicit assumption here is that if fstat() fails, things are in
** such bad shape that dropping a lock or two doesn't matter much.
860
If all the following are true:
**
** 1) this is a read operation, and
** 2) data is required from the start of this overflow page, and
** 3) there is no open write-transaction, and
** 4) the database is file-backed, and
** 5) the page is not in the WAL file
** 6) at least 4 bytes have already been read into the output buffer
**
** then data can be read directly from the database file into the
** output buffer, bypassing the page-cache altogether. This speeds
** up loading large records that span many overflow pages.
** Add the file descriptor used by file handle pFile to the corresponding
** pUnused list.
New cursor object
Filename might have query parameters
The minimum PMA size is set to this value multiplied by the database
** page size in bytes.
idlist_opt
comment:
** Copy the contents of sample *pNew into the p->a[] array. If necessary,
** remove the least desirable sample from p->a[] to make room.
label: code-design
Db name for state ("stat" or "main")
even though it is the conch
This section of code's only "output" is via assert() statements.
** Information and control of an open file handle.
Read position list size
Min and max heap requests sizes
To reset column cache
The common case: Advance to the next row
4 CREATE:
Information that depends on pWLoop->wsFlags
The conflict algorithm. (OE_Abort, OE_Ignore, etc)
Invalid key size: 0x80 0x80 0x01
Search for an existing entry that matching the canonical name.
** If found, increment the reference count and return a pointer to
** the existing file ID.
** Allocate space for memory structures
comment: Optimization note: Adding the "pgno<=1" term before "pgno==0" here
** allows the compiler optimizer to reuse the results of the "pgno>1"
** test in the previous statement, and avoid testing pgno==0 in the
** common case where pgno is large.
label: code-design
Reattach the ORDER BY clause to the query.
collate ::= COLLATE ID|STRING
Left outer join
An in-memory journal file should only ever be appended to. Random
** access writes are not required. The only exception to this is when
** the in-memory journal is being used by a connection using the
** atomic-write optimization. In this case the first 28 bytes of the
** journal file may be written as part of committing the transaction.
** Call from within the xCreate() or xConnect() methods to provide
** the SQLite core with additional information about the behavior
** of the virtual table being implemented.
55
Number of children of returned node
If this is a database file (not a journal, master-journal or temp
** file), the bytes in the locking range should never be read or written.
** Recompute all indices of pTab that use the collating sequence pColl.
** If pColl==0 then recompute all indices of pTab.
True if a locking error has occurred
END => ID
** Select a currently unused rowid for a new r-tree record.
Add the change to the hash-table
224
Store the index column value in this register
First stack entry
Combine Step 3 and Step 5 into a single opcode
Name of the file to be locked or unlocked
Rows less than the lower bound
Block number of last allocated block
** pExpr is an operand of a comparison operator. aff2 is the
** type affinity of the other operand. This routine returns the
** type affinity that should be used for the comparison operator.
Only used in legacy parse mode
PLAN
Expression defining the new record number
Context object passed to callback
Escape ' characters
P4 operand type
the ORDER BY clause
List of expressions to scan
Index of largest aReadMark[] value
** Print out information about all locking operations.
**
** This routine is used for troubleshooting locks on multithreaded
** platforms. Enable by compiling with the -DSQLITE_LOCK_TRACE
** command-line option on the compiler. This code is normally
** turned off.
** This function is called for every node of an expression that is a candidate
** for a cursor hint on an index cursor. For TK_COLUMN nodes that reference
** the table CCurHint.iTabCur, verify that the same column can be
** accessed through the index. If it cannot, then set pWalker->eCode to 1.
TUNING: Each index lookup yields 20 rows in the table. This
** is more than the usual guess of 10 rows, since we have no way
** of knowing how selective the index will ultimately be. It would
** not be unreasonable to make this value much larger.
nSelectRow set by a constant LIMIT
comment:
** Return the number of bytes required to create a duplicate of the
** expression passed as the first argument. The second argument is a
** mask containing EXPRDUP_XXX flags.
**
** The value returned includes space to create a copy of the Expr struct
** itself and the buffer referred to by Expr.u.zToken, if any.
**
** If the EXPRDUP_REDUCE flag is set, then the return value includes
** space to duplicate all Expr nodes in the tree formed by Expr.pLeft
** and Expr.pRight variables (but not for any structures pointed to or
** descended from the Expr.x.pList or Expr.x.pSelect variables).
label: code-design
Used by sqlite3Fts3EvalPhrasePoslist() if this is a descendent of an
** OR condition.
EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise.
Conflict resolution algorithms.
Number of elements in pTabList
** The following routine suspends the current thread for at least ms
** milliseconds. This is equivalent to the Win32 Sleep() interface.
EVIDENCE-OF: R-01470-60482 The sqlite3_value_type(V) interface returns
** the datatype code for the initial datatype of the sqlite3_value object
** V. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT,
** SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL.
Array of arguments for Fts5Config
** Append the value passed as the second argument to the buffer passed
** as the first.
**
** This function is a no-op if *pRc is non-zero when it is called.
** Otherwise, if an error occurs, *pRc is set to an SQLite error code
** before returning.
Index of child node in parent
Address at which row is visited
Index of the table column
This is an aggregate query
The parsing context
If there are one or more deferred tokens, load the current row into
** memory and scan it to determine the position list for each deferred
** token. Then, see if this row is really a match, considering deferred
** tokens and NEAR operators (neither of which were taken into account
** earlier, by fts3EvalNextRow()).
** Change the page size for PCache object. The caller must ensure that there
** are no outstanding page references when this function is called.
If the index or temporary table used by the GROUP BY sort
** will naturally deliver rows in the order required by the ORDER BY
** clause, cancel the ephemeral table open coded earlier.
**
** This is an optimization - the correct answer should result regardless.
** Use the SQLITE_GroupByOrder flag with SQLITE_TESTCTRL_OPTIMIZER to
** disable this optimization for testing purposes.
If the node is not the tree root and now has less than the minimum
** number of cells, remove it from the tree. Otherwise, update the
** cell in the parent node so that it tightly contains the updated
** node.
*************************** sqlite3_result_ *******************************
** The following routines are used by user-defined functions to specify
** the function result.
**
** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
** result as a string or blob but if the string or blob is too large, it
** then sets the error code to SQLITE_TOOBIG
**
** The invokeValueDestructor(P,X) routine invokes destructor function X()
** on value P is not going to be used and need to be destroyed.
All optimizations
** This is called by the parser when it sees a CREATE TRIGGER statement
** up to the point of the BEGIN before the trigger actions. A Trigger
** structure is generated based on the information available and stored
** in pParse->pNewTrigger. After the trigger actions have been parsed, the
** sqlite3FinishTrigger() function is called to complete the trigger
** construction process.
comment: There is one entry in the aRegIdx[] array for each index on the table
** being updated. Fill in aRegIdx[] with a register number that will hold
** the key for accessing each index.
**
** FIXME: Be smarter about omitting indexes that use expressions.
label: code-design
X-overwrites-A
This routine is never called during trigger-generation. It is
** only called from the top-level
Construct the WhereLoop objects
** Set *ppModule to point at the implementation of the ICU tokenizer.
Result code of a subroutine
Value type (SQLITE_NULL, TEXT etc.)
Current number of allocations
To ensure unique results if UNION
The value for the token
Seek the index cursor to the start of the range.
Next FKey with the same in pFrom. Next parent of pFrom
** The parser calls this routine when it sees the first token
** of an argument to the module name in a CREATE VIRTUAL TABLE statement.
Return true if index X is a PRIMARY KEY index
The random check-hash initializer
Randomly chosen byte used as a shared lock
Access to mutexes used by sqlite3_status()
Nul-terminated string containing "A,B"
174
** This function is called during initialization (sqlite3_initialize()) to
** install the default pluggable cache module, assuming the user has not
** already provided an alternative.
** Advance the first term iterator in the first phrase of pNear. Set output
** variable *pbEof to true if it reaches EOF or if an error occurs.
**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
#include <unicode/ucol.h>
PK index if pTab is WITHOUT ROWID
PASSIVE, FULL, RESTART, or TRUNCATE
Scan for a consonent
turn on proxy file locking
First arg to xCompare()
True this expression is at EOF already
Type of error
Number of days since 1st day of year
Number of pages in database file
** Assign a variable number to an expression that encodes a wildcard
** in the original SQL statement.
**
** Wildcards consisting of a single "?" are assigned the next sequential
** variable number.
**
** Wildcards of the form "?nnn" are assigned the number "nnn". We make
** sure "nnn" is not too big to avoid a denial of service attack when
** the SQL statement comes from an external source.
**
** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
** as the previous instance of the same wildcard. Or if this is the first
** instance of the wildcard, the next sequential variable number is
** assigned.
When adding an index to the list of indices for a table, make
** sure all indices labeled OE_Replace come after all those labeled
** OE_Ignore. This is necessary for the correct constraint check
** processing (in sqlite3GenerateConstraintChecks()) as part of
** UPDATE and INSERT statements.
Opcode: ResetSorter P1 * * * *
**
** Delete all contents from the ephemeral table or sorter
** that is open on cursor P1.
**
** This opcode only works for cursors used for sorting and
** opened with OP_OpenEphemeral or OP_SorterOpen.
** Allocate a new page from the database file.
**
** The new page is marked as dirty. (In other words, sqlite3PagerWrite()
** has already been called on the new page.) The new page has also
** been referenced and the calling routine is responsible for calling
** sqlite3PagerUnref() on the new page when it is done.
**
** SQLITE_OK is returned on success. Any other return value indicates
** an error. *ppPage is set to NULL in the event of an error.
**
** If the "nearby" parameter is not 0, then an effort is made to
** locate a page close to the page number "nearby". This can be used in an
** attempt to keep related pages close to each other in the database file,
** which in turn can make database access faster.
**
** If the eMode parameter is BTALLOC_EXACT and the nearby page exists
** anywhere on the free-list, then it is guaranteed to be returned. If
** eMode is BTALLOC_LT then the page returned will be less than or equal
** to nearby if any such page exists. If eMode is BTALLOC_ANY then there
** are no restrictions on which page is returned.
True if resolving a partial index WHERE
** CAPI3REF: File Locking Levels
**
** SQLite uses one of these integer values as the second
** argument to calls it makes to the xLock() and xUnlock() methods
** of an [sqlite3_io_methods] object.
** Release a reference to an Fts5Structure object returned by an earlier
** call to fts5StructureRead() or fts5StructureDecode().
(318) tridxby ::=
Cannot transition directly from MEMORY to WAL. Use mode OFF
** as an intermediate
synopsis: r[P1]=NULL
Scan to write OP_Explain opcode for
If setting the version fields to 1, do not automatically open the
** WAL connection, even if the version fields are currently set to 2.
Context argument for xBusyHandler
PRIMARY
File descriptor returned by open()
** Argument pExpr is an (?, ?...) IN(...) expression. This
** function allocates and returns a nul-terminated string containing
** the affinities to be used for each column of the comparison.
**
** It is the responsibility of the caller to ensure that the returned
** string is eventually freed using sqlite3DbFree().
Copy the filename and any query parameters into the zFile buffer.
** Decode %HH escape codes along the way.
**
** Within this loop, variable eState may be set to 0, 1 or 2, depending
** on the parsing context. As follows:
**
** 0: Parsing file-name.
** 1: Parsing name section of a name=value query parameter.
** 2: Parsing value section of a name=value query parameter.
ON
zStmt = sqlite3MPrintf("");
This test catches attempts to make either operand of a NEAR
** operator something other than a phrase. For example, either of
** the following:
**
** (bracketed expression) NEAR phrase
** phrase NEAR (bracketed expression)
**
** Return an error in either case.
Result to set *pbRes to
in_op ::= NOT IN
SQLITE_OMIT_LOOKASIDE
Add the term to the terms index
Generate code to cause the string zStr to be loaded into
** register iDest
If the RHS of this IN(...) operator is a SELECT, and if it matters
** whether or not the SELECT result contains NULL values, check whether
** or not NULL is actually possible (it may not be, for example, due
** to NOT NULL constraints in the schema). If no NULL values are possible,
** set prRhsHasNull to 0 before continuing.
Array of size nPhrase
************* Begin file fts3_tokenize_vtab.c *****************************
** Within the RBU_STAGE_OAL stage, each call to sqlite3rbu_step() performs
** one of the following operations.
WAL
HASH_INT, _POINTER, _STRING, _BINARY
comment:
** Get an unused page.
**
** This works just like btreeGetPage() with the addition:
**
** * If the page is already in use for some other purpose, immediately
** release it and return an SQLITE_CURRUPT error.
** * Make sure the isInit flag is clear
label: documentation
Number of arguments used so far
#include "opcodes.h"
Memory cell to write value into
** Replace the current "averages" record with the contents of the buffer
** supplied as the second argument.
** Compute the difference (in milliseconds) between localtime and UTC
** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
** return this value and set *pRc to SQLITE_OK.
**
** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
** is undefined in this case.
A real table
True if UNIQUE and NOT NULL for all columns
same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2])
************************************************************************
Create VDBE to loop through the entries in pSrc that match the WHERE
** clause. For each row found, increment either the deferred or immediate
** foreign key constraint counter.
Setup information needed to write frames into the WAL
sign of exponent
Pointer to nul-term of zCopy
comment: Malloc a buffer to read frames into.
label: code-design
** Delete the entry that the cursor is pointing to.
**
** If the BTREE_SAVEPOSITION bit of the flags parameter is zero, then
** the cursor is left pointing at an arbitrary location after the delete.
** But if that bit is set, then the cursor is left in a state such that
** the next call to BtreeNext() or BtreePrev() moves it to the same row
** as it would have been on if the call to BtreeDelete() had been omitted.
**
** The BTREE_AUXDELETE bit of flags indicates that is one of several deletes
** associated with a single table entry and its indexes. Only one of those
** deletes is considered the "primary" delete. The primary delete occurs
** on a cursor that is not a BTREE_FORDELETE cursor. All but one delete
** operation on non-FORDELETE cursors is tagged with the AUXDELETE flag.
** The BTREE_AUXDELETE bit is a hint that is not used by this implementation,
** but which might be used by alternative storage engines.
Primary key array
Bytes of payload total (local+overflow)
selectnowith ::= selectnowith multiselect_op oneselect
IN/OUT: Pointer into buffer
nearby parameter for allocateBtreePage()
EV: R-40812-03570
if we already have a lock, it is exclusive.
** Just adjust level and punt on outta here.
Get the VDBE program ready for execution
Register holding largest rowid for AUTOINCREMENT
Which loop to provide hints for
** Retrieve the next token from the tokenizer cursor pCursor. This
** method should either return SQLITE_OK and set the values of the
** "OUT" variables identified below, or SQLITE_DONE to indicate that
** the end of the buffer has been reached, or an SQLite error code.
**
** *ppToken should be set to point at a buffer containing the
** normalized version of the token (i.e. after any case-folding and/or
** stemming has been performed). *pnBytes should be set to the length
** of this buffer in bytes. The input text that generated the token is
** identified by the byte offsets returned in *piStartOffset and
** *piEndOffset. *piStartOffset should be set to the index of the first
** byte of the token in the input buffer. *piEndOffset should be set
** to the index of the first byte just past the end of the token in
** the input buffer.
**
** The buffer *ppToken is set to point at is managed by the tokenizer
** implementation. It is only required to be valid until the next call
** to xNext() or xClose().
Block id of child node to descend to
For debugging use only:
mxMmap
Base register for data coming from SELECT
EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op.
Size of pKey, or last integer key
Open a transaction on the database file. Regardless of the journal
** mode, this transaction always uses a rollback journal.
The comparison opcode
** Provide flag hints to the cursor.
Must be a power of 2
ifndef SQLITE_OMIT_FOREIGN_KEY
The following block runs if pExpr is the root of a NEAR query.
** For example, the query:
**
** "w" NEAR "x" NEAR "y" NEAR "z"
**
** which is represented in tree form as:
**
** |
** +--NEAR--+ <-- root of NEAR query
** | |
** +--NEAR--+ "z"
** | |
** +--NEAR--+ "y"
** | |
** "w" "x"
**
** The right-hand child of a NEAR node is always a phrase. The
** left-hand child may be either a phrase or a NEAR node. There are
** no exceptions to this - it's the way the parser in fts3_expr.c works.
comment: One of the SQL_XXX constants above
label: code-design
** Memory barrier.
** Both *pMem1 and *pMem2 contain string values. Compare the two values
** using the collation sequence pColl. As usual, return a negative , zero
** or positive value if *pMem1 is less than, equal to or greater than
** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
Copy of input using utf-16 encoding
Table to be indexed
Configure the OP_TableLock instruction
Pointer to MatchInfo structure
EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
** big-endian integer which is the offset in the b-tree page of the next
** freeblock in the chain, or zero if the freeblock is the last on the
** chain.
pPage is not necessarily writeable since pCell might be auxiliary
** buffer space that is separate from the pPage buffer area
** This function does the work for both the xDisconnect and xDestroy methods.
** These tables have no persistent representation of their own, so xDisconnect
** and xDestroy are identical operations.
Append the new serialized varint to the end of the list.
Input path for each iteration of loop
** Return a pointer to the pPager->pBackup variable. The backup module
** in backup.c maintains the content of this variable. This module
** uses it opaquely as an argument to sqlite3BackupRestart() and
** sqlite3BackupUpdate() only.
Set the value of a single config attribute
Make this EXPR node point to the selected column
Previous term
******************************** Single-Threaded *************************
Error code returned by pagerUnlockDb()
Happens with a UNIQUE index on ROWID
Preserve the user version
** Invert a changeset object.
comment: Locate the table which we want to delete. This table has to be
** put in an SrcList structure because some of the subroutines we
** will be calling are designed to work with multiple tables and expect
** an SrcList* parameter instead of just a Table* parameter.
label: code-design
Reset and close the cache object
Name of %_data table
Virtual table implementations will typically add additional fields
comment: Ensure that the size of a VDBE does not grow too large
label: code-design
** Generate code that will do an analysis of an entire database
** Guard words
Save the positions of any other cursors open on this table before
** making any modifications.
** Virtual table cursor structure.
Value to be returned
True if rowid is modified by this update
Use the incremental approach.
Expected pointer map type
If the cell deleted was not located on a leaf page, then the cursor
** is currently pointing to the largest entry in the sub-tree headed
** by the child-page of the cell that was just deleted from an internal
** node. The cell from the leaf node needs to be moved to the internal
** node to replace the deleted cell.
Cursor handle passed through apVal[0]
Static space for the 2 default backends
True if there is a NOT INDEXED clause
Last update statement (or NULL)
Column counter
Approximate number of tokens in snippet
Append header to this buffer
pContext from when function registered
Delete on close
Of the form A==B, both columns
** CAPI3REF: Closing A Database Connection
** DESTRUCTOR: sqlite3
**
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
** for the [sqlite3] object.
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
** the [sqlite3] object is successfully destroyed and all associated
** resources are deallocated.
**
** ^If the database connection is associated with unfinalized prepared
** statements or unfinished sqlite3_backup objects then sqlite3_close()
** will leave the database connection open and return [SQLITE_BUSY].
** ^If sqlite3_close_v2() is called with unfinalized prepared statements
** and/or unfinished sqlite3_backups, then the database connection becomes
** an unusable "zombie" which will automatically be deallocated when the
** last prepared statement is finalized or the last sqlite3_backup is
** finished. The sqlite3_close_v2() interface is intended for use with
** host languages that are garbage collected, and where the order in which
** destructors are called is arbitrary.
**
** Applications should [sqlite3_finalize | finalize] all [prepared statements],
** [sqlite3_blob_close | close] all [BLOB handles], and
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
** with the [sqlite3] object prior to attempting to close the object. ^If
** sqlite3_close_v2() is called on a [database connection] that still has
** outstanding [prepared statements], [BLOB handles], and/or
** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
** of resources is deferred until all [prepared statements], [BLOB handles],
** and [sqlite3_backup] objects are also destroyed.
**
** ^If an [sqlite3] object is destroyed while a transaction is open,
** the transaction is automatically rolled back.
**
** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
** must be either a NULL
** pointer or an [sqlite3] object pointer obtained
** from [sqlite3_open()], [sqlite3_open16()], or
** [sqlite3_open_v2()], and not previously closed.
** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
** argument is a harmless no-op.
The main database structure
790
** This function is called when a row is inserted into or deleted from the
** child table of foreign key constraint pFKey. If an SQL UPDATE is executed
** on the child table of pFKey, this function is invoked twice for each row
** affected - once to "delete" the old row, and then again to "insert" the
** new row.
**
** Each time it is called, this function generates VDBE code to locate the
** row in the parent table that corresponds to the row being inserted into
** or deleted from the child table. If the parent row can be found, no
** special action is taken. Otherwise, if the parent row can *not* be
** found in the parent table:
**
** Operation | FK type | Action taken
** --------------------------------------------------------------------------
** INSERT immediate Increment the "immediate constraint counter".
**
** DELETE immediate Decrement the "immediate constraint counter".
**
** INSERT deferred Increment the "deferred constraint counter".
**
** DELETE deferred Decrement the "deferred constraint counter".
**
** These operations are identified in the comment at the top of this file
** (fkey.c) as "I.1" and "D.1".
This column was already computed by the previous index
Value of 'path' column
The SQL table being indexed
************* Begin file os.h *********************************************
Filesystem type name
The FTS table to delete from
We will be overwriting WhereLoop p[]. But before we do, first
** go through the rest of the list and delete any other entries besides
** p[] that are also supplated by pTemplate
int iCid = sqlite3_column_int(pXInfo, 0);
Copy of p->aMem
** Virtual-table cursor object.
**
** iSpecial:
** If this is a 'special' query (refer to function fts5SpecialMatch()),
** then this variable contains the result of the query.
**
** iFirstRowid, iLastRowid:
** These variables are only used for FTS5_PLAN_MATCH cursors. Assuming the
** cursor iterates in ascending order of rowids, iFirstRowid is the lower
** limit of rowids to return, and iLastRowid the upper. In other words, the
** WHERE clause in the user's query might have been:
**
** <tbl> MATCH <expr> AND rowid BETWEEN $iFirstRowid AND $iLastRowid
**
** If the cursor iterates in descending order of rowid, iFirstRowid
** is the upper limit (i.e. the "first" rowid visited) and iLastRowid
** the lower.
Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
** is encountered.
** This is the maximum amount of data (in bytes) to store in the
** Fts3Table.pendingTerms hash table. Normally, the hash table is
** populated as documents are inserted/updated/deleted in a transaction
** and used to create a new segment when the transaction is committed.
** However if this limit is reached midway through a transaction, a new
** segment is created and the hash table cleared immediately.
Here code is inserted which will be executed whenever the
** parser accepts
** Copy the complete content of pBtFrom into pBtTo. A transaction
** must be active for both files.
**
** The size of file pTo may be reduced by this operation. If anything
** goes wrong, the transaction on pTo is rolled back. If successful, the
** transaction is committed before returning.
Pluggable cache module
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
** is greater than sqlite3.pWalArg cast to an integer (the value configured by
** wal_autocheckpoint()).
33==sqlite3LogEst(10)
Cached next search point
The BTree that contains the table
The first fields of the two keys are equal. Compare the trailing
** fields.
comment:
** Alternative datatype for the argument to the malloc() routine passed
** into sqlite3ParserAlloc(). The default is size_t.
label: code-design
** Clear the current cursor position.
comment:
** Initialize the memory allocator.
**
** This routine is not threadsafe. The caller must be holding a mutex
** to prevent multiple threads from entering at the same time.
label: code-design
Leaf page number to load dlidx for
Size of serialized value in bytes
************* Include sqliteicu.h in the middle of main.c *****************
Find the column for which info is requested
Space to hold MJ filename from a journal file
#include <pthread.h>
** Return the rowid for the current row. In this implementation, the
** rowid is the same as the output value.
** Convert a LogEst into an integer.
**
** Note that this routine is only used when one or more of various
** non-standard compile-time options is enabled.
comment:
** CAPI3REF: Memory Allocation Subsystem
**
** The SQLite core uses these three routines for all of its own
** internal memory allocation needs. "Core" in the previous sentence
** does not include operating-system specific VFS implementation. The
** Windows VFS uses native malloc() and free() for some operations.
**
** ^The sqlite3_malloc() routine returns a pointer to a block
** of memory at least N bytes in length, where N is the parameter.
** ^If sqlite3_malloc() is unable to obtain sufficient free
** memory, it returns a NULL pointer. ^If the parameter N to
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
** a NULL pointer.
**
** ^The sqlite3_malloc64(N) routine works just like
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
** of a signed 32-bit integer.
**
** ^Calling sqlite3_free() with a pointer previously returned
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
** that it might be reused. ^The sqlite3_free() routine is
** a no-op if is called with a NULL pointer. Passing a NULL pointer
** to sqlite3_free() is harmless. After being freed, memory
** should neither be read nor written. Even reading previously freed
** memory might result in a segmentation fault or other severe error.
** Memory corruption, a segmentation fault, or other severe error
** might result if sqlite3_free() is called with a non-NULL pointer that
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
**
** ^The sqlite3_realloc(X,N) interface attempts to resize a
** prior memory allocation X to be at least N bytes.
** ^If the X parameter to sqlite3_realloc(X,N)
** is a NULL pointer then its behavior is identical to calling
** sqlite3_malloc(N).
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
** negative then the behavior is exactly the same as calling
** sqlite3_free(X).
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
** of at least N bytes in size or NULL if insufficient memory is available.
** ^If M is the size of the prior allocation, then min(N,M) bytes
** of the prior allocation are copied into the beginning of buffer returned
** by sqlite3_realloc(X,N) and the prior allocation is freed.
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
** prior allocation is not freed.
**
** ^The sqlite3_realloc64(X,N) interfaces works the same as
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
** of a 32-bit signed integer.
**
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
** sqlite3_msize(X) returns the size of that memory allocation in bytes.
** ^The value returned by sqlite3_msize(X) might be larger than the number
** of bytes requested when X was allocated. ^If X is a NULL pointer then
** sqlite3_msize(X) returns zero. If X points to something that is not
** the beginning of memory allocation, or if it points to a formerly
** valid memory allocation that has now been freed, then the behavior
** of sqlite3_msize(X) is undefined and possibly harmful.
**
** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
** sqlite3_malloc64(), and sqlite3_realloc64()
** is always aligned to at least an 8 byte boundary, or to a
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
** option is used.
**
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
** implementation of these routines to be omitted. That capability
** is no longer provided. Only built-in memory allocators can be used.
**
** Prior to SQLite version 3.7.10, the Windows OS interface layer called
** the system malloc() and free() directly when converting
** filenames between the UTF-8 encoding used by SQLite
** and whatever filename encoding is used by the particular Windows
** installation. Memory allocation errors were detected, but
** they were reported back as [SQLITE_CANTOPEN] or
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
**
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
** must be either NULL or else pointers obtained from a prior
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
** not yet been released.
**
** The application must not read or write any part of
** a block of memory after it has been released using
** [sqlite3_free()] or [sqlite3_realloc()].
label: code-design
Ax
Context for fts3ExprTermOffsetInit()
The cursor number of the table
** Flush the contents of pendingTerms to level 0 segments.
** Return the filename of the database associated with a database
** connection.
If there is enough space between gap and top for one more cell pointer
** array entry offset, and if the freelist is not empty, then search the
** freelist looking for a free slot big enough to satisfy the request.
Append the assignments
** These routines are Walker callbacks used to check expressions to
** see if they are "constant" for some definition of constant. The
** Walker.eCode value determines the type of "constant" we are looking
** for.
**
** These callback routines are used to implement the following:
**
** sqlite3ExprIsConstant() pWalker->eCode==1
** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
** sqlite3ExprIsTableConstant() pWalker->eCode==3
** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
**
** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
** is found to not be a constant.
**
** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
** an existing schema and 4 when processing a new statement. A bound
** parameter raises an error for new statements, but is silently converted
** to NULL for existing schemas. This allows sqlite_master tables that
** contain a bound parameter because they were generated by older versions
** of SQLite to be parsed by newer versions of SQLite without raising a
** malformed schema error.
#define sqliteHashCount(H) ((H)->count) // NOT USED
Set variable i to the maximum number of bytes of input to tokenize.
Data for tables. NULL for indexes
** Check to see if the FROM clause term pFrom has table-valued function
** arguments. If it does, leave an error message in pParse and return
** non-zero, since pFrom is not allowed to be a table-valued function.
164
Out-of-Order hidden columns
whereexpr.c:
due to (6)
Host database connection
Cursor number of LHS
Decode any more doclist data that appears on the page before the
** first term.
Sorter that owns this sub-task
NO-OP
Opcode: SorterInsert P1 P2 * * *
** Synopsis: key=r[P2]
**
** Register P2 holds an SQL index key made using the
** MakeRecord instructions. This opcode writes that key
** into the sorter P1. Data for the entry is nil.
List of triggers to (potentially) fire
xFindFunction
comment: The public SQLite interface. The _FILE_OFFSET_BITS macro must appear
** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for
** MinGW.
label: code-design
If any of the expressions is an IPK column on table iBase, then return
** true. Note: The (p->iTable==iBase) part of this test may be false if the
** current SELECT is a correlated sub-query.
One register allocated to each index
comment:
** CAPI3REF: Function Auxiliary Data
** METHOD: sqlite3_context
**
** These functions may be used by (non-aggregate) SQL functions to
** associate metadata with argument values. If the same value is passed to
** multiple invocations of the same SQL function during query execution, under
** some circumstances the associated metadata may be preserved. An example
** of where this might be useful is in a regular-expression matching
** function. The compiled version of the regular expression can be stored as
** metadata associated with the pattern string.
** Then as long as the pattern string remains the same,
** the compiled regular expression can be reused on multiple
** invocations of the same function.
**
** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
** value to the application-defined function. ^N is zero for the left-most
** function argument. ^If there is no metadata
** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
** returns a NULL pointer.
**
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
** argument of the application-defined function. ^Subsequent
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
** NULL if the metadata has been discarded.
** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
** SQLite will invoke the destructor function X with parameter P exactly
** once, when the metadata is discarded.
** SQLite is free to discard the metadata at any time, including: <ul>
** <li> ^(when the corresponding function parameter changes)^, or
** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
** SQL statement)^, or
** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
** parameter)^, or
** <li> ^(during the original sqlite3_set_auxdata() call when a memory
** allocation error occurs.)^ </ul>
**
** Note the last bullet in particular. The destructor X in
** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
** should be called near the end of the function implementation and the
** function implementation should not make any use of P after
** sqlite3_set_auxdata() has been called.
**
** ^(In practice, metadata is preserved between function calls for
** function parameters that are compile-time constants, including literal
** values and [parameters] and expressions composed from the same.)^
**
** The value of the N parameter to these interfaces should be non-negative.
** Future enhancements may make use of negative N values to define new
** kinds of function caching behavior.
**
** These routines must be called from the same thread in which
** the SQL function is running.
label: code-design
Reader to advance to next docid
Name of the collating sequence, UTF-8 encoded
Temp var to store a page number in
** Create a new collating function for database "db". The name is zName
** and the encoding is enc.
The open database file
** The MEM structure is already a MEM_Real. Try to also make it a
** MEM_Int if we can.
Advance each segment iterator until it points to the term zTerm/nTerm.
Change record
OUT: number of columns
** Return true if the iterator passed as the second argument currently
** points to a delete marker. A delete marker is an entry with a 0 byte
** position-list.
For use by built-in VFS
If the cursor is not currently open or is open on a different
** index, then fall through into OP_OpenRead to force a reopen
true if shared-cache mode enabled
Subquery id 2
NOTNULL
Step 3.
maybe a number
************* Begin file fault.c ******************************************
** Read the wal-index header from the wal-index and into pWal->hdr.
** If the wal-header appears to be corrupt, try to reconstruct the
** wal-index from the WAL before returning.
**
** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
** changed by this operation. If pWal->hdr is unchanged, set *pChanged
** to 0.
**
** If the wal-index header is successfully read, return SQLITE_OK.
** Otherwise an SQLite error code.
** Initialize the memory allocation subsystem.
Index of next ? host parameter
Statement holding cursor open
** Return the margin length of cell p. The margin length is the sum
** of the objects size in each dimension.
!defined(SQLITE_OMIT_ANALYZE)
OUT: New merge-engine
** Parameter zName points to a nul-terminated buffer containing the name
** of a database ("main", "temp" or the name of an attached db). This
** function returns the index of the named database in db->aDb[], or
** -1 if the named db cannot be found.
YYERRORSYMBOL is not defined
Cursor number for the table corresponding to the index
Bytes of title; includes '\0'
Check the table schema is still Ok.
Iterate through the b-tree hierarchy.
** CAPI3REF: Create A New Session Object
**
** Create a new session object attached to database handle db. If successful,
** a pointer to the new object is written to *ppSession and SQLITE_OK is
** returned. If an error occurs, *ppSession is set to NULL and an SQLite
** error code (e.g. SQLITE_NOMEM) is returned.
**
** It is possible to create multiple session objects attached to a single
** database handle.
**
** Session objects created using this function should be deleted using the
** [sqlite3session_delete()] function before the database handle that they
** are attached to is itself closed. If the database handle is closed before
** the session object is deleted, then the results of calling any session
** module function, including [sqlite3session_delete()] on the session object
** are undefined.
**
** Because the session module uses the [sqlite3_preupdate_hook()] API, it
** is not possible for an application to register a pre-update hook on a
** database handle that has one or more session objects attached. Nor is
** it possible to create a session object attached to a database handle for
** which a pre-update hook is already defined. The results of attempting
** either of these things are undefined.
**
** The session object will be used to create changesets for tables in
** database zDb, where zDb is either "main", or "temp", or the name of an
** attached database. It is not an error if database zDb is not attached
** to the database when the session object is created.
Current number of distinct checkouts
True for temp files (incl. in-memory files)
Set of pages in this savepoint
New journal mode
SegmentWriter to flush to the db
Allocate space for the output. Both the input and output doclists
** are delta encoded. If they are in ascending order (bDescDoclist==0),
** then the first docid in each list is simply encoded as a varint. For
** each subsequent docid, the varint stored is the difference between the
** current and previous docid (a positive number - since the list is in
** ascending order).
**
** The first docid written to the output is therefore encoded using the
** same number of bytes as it is in whichever of the input lists it is
** read from. And each subsequent docid read from the same input list
** consumes either the same or less bytes as it did in the input (since
** the difference between it and the previous value in the output must
** be a positive value less than or equal to the delta value read from
** the input list). The same argument applies to all but the first docid
** read from the 'other' list. And to the contents of all position lists
** that will be copied and merged from the input to the output.
**
** However, if the first docid copied to the output is a negative number,
** then the encoding of the first docid from the 'other' input list may
** be larger in the output than it was in the input (since the delta value
** may be a larger positive integer than the actual docid).
**
** The space required to store the output is therefore the sum of the
** sizes of the two inputs, plus enough space for exactly one of the input
** docids to grow.
**
** A symetric argument may be made if the doclists are in descending
** order.
** If we get here it means the result set contains one or more "*"
** operators that need to be expanded. Loop through each expression
** in the result set and expand them one by one.
** Code an OP_Affinity opcode to apply the column affinity string zAff
** to the n registers starting at base.
**
** As an optimization, SQLITE_AFF_BLOB entries (which are no-ops) at the
** beginning and end of zAff are ignored. If all entries in zAff are
** SQLITE_AFF_BLOB, then no code gets generated.
**
** This routine makes its own copy of zAff so that the caller is free
** to modify zAff after this routine returns.
String to return via *pzImposterPK
127
C89 specifies that the constant "dummy" will be initialized to all
** zeros, which is correct. MSVC generates a warning, nevertheless.
Store result in an queue
** A global array of all winShmNode objects.
**
** The winShmMutexHeld() must be true while reading or writing this list.
comment:
** Sub-iterator iChanged of iterator pIter has just been advanced. It still
** points to the same term though - just a different rowid. This function
** attempts to update the contents of the pIter->aFirst[] accordingly.
** If it does so successfully, 0 is returned. Otherwise 1.
**
** If non-zero is returned, the caller should call fts5MultiIterAdvanced()
** on the iterator instead. That function does the same as this one, except
** that it deals with more complicated cases as well.
label: code-design
SQLITE_HAS_CODEC
The CREATE token that begins this statement
Result of previous sqlite3BtreeMoveto() or 0
** if there have been no prior seeks on the cursor.
<tbl> MATCH ? expression (or NULL)
Left-most SELECT statement
Checksum over all prior fields
simulate multiple hosts by creating unique hostid file paths
** This routine is called to process a compound query form from
** two or more separate queries using UNION, UNION ALL, EXCEPT, or
** INTERSECT
**
** "p" points to the right-most of the two queries. the query on the
** left is p->pPrior. The left query could also be a compound query
** in which case this routine will be called recursively.
**
** The results of the total query are to be written into a destination
** of type eDest with parameter iParm.
**
** Example 1: Consider a three-way compound SQL statement.
**
** SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
**
** This statement is parsed up as follows:
**
** SELECT c FROM t3
** |
** `-----> SELECT b FROM t2
** |
** `------> SELECT a FROM t1
**
** The arrows in the diagram above represent the Select.pPrior pointer.
** So if this routine is called with p equal to the t3 query, then
** pPrior will be the t2 query. p->op will be TK_UNION in this case.
**
** Notice that because of the way SQLite parses compound SELECTs, the
** individual selects always group from left to right.
Contents of master journal file
same as TK_OR, in1, in2, out3
comment:
** Gather statistics on the sizes of memory allocations.
** nAlloc[i] is the number of allocation attempts of i*8
** bytes. i==NCSIZE is the number of allocation attempts for
** sizes more than NCSIZE*8 bytes.
label: code-design
For a rowid table, initialize the RowSet to an empty set
Binary representation of iNew
Current size of database file
Text encoding
comment: Langid of recently inserted document
label: documentation
First byte to be locked
Value for "from" column of output
** The SELECT statement iterating through the keys for the current object
** (p->objiter.pSelect) currently points to a valid row. However, there
** is something wrong with the rbu_control value in the rbu_control value
** stored in the (p->nCol+1)'th column. Set the error code and error message
** of the RBU handle to something reflecting this.
** If SQLITE_ENABLE_8_3_NAMES is set at compile-time and if the database
** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
** three characters, then shorten the suffix on z[] to be the last three
** characters of the original suffix.
**
** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
** do the suffix shortening regardless of URI parameter.
**
** Examples:
**
** test.db-journal => test.nal
** test.db-wal => test.wal
** test.db-shm => test.shm
** test.db-mj7f3319fa => test.9fa
A small processing code
** This function gathers 'y' or 'b' data for a single phrase.
Return from sqlite3WhereBegin()
Neither side of the comparison is a column. Compare the
** results directly.
Largest allocation (exclusive of internal frag)
A column number within table iCur
True if auto-vacuum is enabled
WHERE clause information
The string collected so far
** Write an error message into *pzErr
Opcode: DropIndex P1 * * P4 *
**
** Remove the internal (in-memory) data structures that describe
** the index named P4 in database P1. This is called after an index
** is dropped from disk (using the Destroy opcode)
** in order to keep the internal representation of the
** schema consistent with what is on disk.
Index of first cell to add
Append the data to the string buffer.
Text of the SQL statement that generated this
** Apply a delta.
**
** The output buffer should be big enough to hold the whole output
** file and a NUL terminator at the end. The delta_output_size()
** routine will determine this size for you.
**
** The delta string should be null-terminated. But the delta string
** may contain embedded NUL characters (if the input and output are
** binary files) so we also have to pass in the length of the delta in
** the lenDelta parameter.
**
** This function returns the size of the output file in bytes (excluding
** the final NUL terminator character). Except, if the delta string is
** malformed or intended for use with a source file other than zSrc,
** then this routine returns -1.
**
** Refer to the delta_create() documentation above for a description
** of the delta file format.
Number of columns in the PRIMARY KEY
struct Trigger
Only one of WHERE_OR_SUBCLAUSE or WHERE_USE_LIMIT
Temporarily holds the number of cursors assigned
zero or more BTCF_* flags defined below
Page 1 is always available in cache, because
** pCache->nRefSum>0
** Maximum size (in Mem3Blocks) of a "small" chunk.
** The "file format" number is an integer that is incremented whenever
** the VDBE-level file format changes. The following macros define the
** the default file format for new databases and the maximum file format
** that the library can read.
Text inserted into table-name column
Default locking-mode for attached dbs
OS Interface
The right-hand side of the AS subexpression
Buffer containing segment interior node
(285) columnlist ::= columnname carglist
Unsorted entry count
IMP: R-51463-25634
Begin scannning through the ephemeral table.
Create the new column data
comment: Opcode: Goto * P2 * * *
**
** An unconditional jump to address P2.
** The next instruction executed will be
** the one at index P2 from the beginning of
** the program.
**
** The P1 parameter is not actually used by this opcode. However, it
** is sometimes set to 1 instead of 0 as a hint to the command-line shell
** that this Goto is the bottom of a loop and that the lines from P2 down
** to the current line should be indented for EXPLAIN output.
label: code-design
!SQLITE_CORE || SQLITE_ENABLE_FTS3
Update the Fts5Structure. It is written back to the database by the
** fts5StructureRelease() call below.
No usable constraint
Is a label of an object
** Free a hash table object.
Current block id
If input table has column "rbu_rowid"
A-overwrites-X
comment:
** This function is used after merging multiple segments into a single large
** segment to delete the old, now redundant, segment b-trees. Specifically,
** it:
**
** 1) Deletes all %_segments entries for the segments associated with
** each of the SegReader objects in the array passed as the third
** argument, and
**
** 2) deletes all %_segdir entries with level iLevel, or all %_segdir
** entries regardless of level if (iLevel<0).
**
** SQLITE_OK is returned if successful, otherwise an SQLite error code.
label: code-design
** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
** that it points to iTo. Parameter eType describes the type of pointer to
** be modified, as follows:
**
** PTRMAP_BTREE: pPage is a btree-page. The pointer points at a child
** page of pPage.
**
** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
** page pointed to by one of the cells on pPage.
**
** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
** overflow page in the list.
** Compare the entries pointed to by two Fts3SegReader structures.
** Comparison is as follows:
**
** 1) EOF is greater than not EOF.
**
** 2) The current terms (if any) are compared using memcmp(). If one
** term is a prefix of another, the longer term is considered the
** larger.
**
** 3) By segment age. An older segment is considered larger.
comment:
** CAPI3REF: Result Values From A Query
** KEYWORDS: {column access functions}
** METHOD: sqlite3_stmt
**
** <b>Summary:</b>
** <blockquote><table border=0 cellpadding=0 cellspacing=0>
** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result
** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result
** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result
** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result
** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result
** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result
** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an
** [sqlite3_value|unprotected sqlite3_value] object.
** <tr><td> <td> <td>
** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB
** or a UTF-8 TEXT result in bytes
** <tr><td><b>sqlite3_column_bytes16 </b>
** <td>→ <td>Size of UTF-16
** TEXT in bytes
** <tr><td><b>sqlite3_column_type</b><td>→<td>Default
** datatype of the result
** </table></blockquote>
**
** <b>Details:</b>
**
** ^These routines return information about a single column of the current
** result row of a query. ^In every case the first argument is a pointer
** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
** that was returned from [sqlite3_prepare_v2()] or one of its variants)
** and the second argument is the index of the column for which information
** should be returned. ^The leftmost column of the result set has the index 0.
** ^The number of columns in the result can be determined using
** [sqlite3_column_count()].
**
** If the SQL statement does not currently point to a valid row, or if the
** column index is out of range, the result is undefined.
** These routines may only be called when the most recent call to
** [sqlite3_step()] has returned [SQLITE_ROW] and neither
** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
** If any of these routines are called after [sqlite3_reset()] or
** [sqlite3_finalize()] or after [sqlite3_step()] has returned
** something other than [SQLITE_ROW], the results are undefined.
** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
** are called from a different thread while any of these routines
** are pending, then the results are undefined.
**
** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
** each return the value of a result column in a specific data format. If
** the result column is not initially in the requested format (for example,
** if the query returns an integer but the sqlite3_column_text() interface
** is used to extract the value) then an automatic type conversion is performed.
**
** ^The sqlite3_column_type() routine returns the
** [SQLITE_INTEGER | datatype code] for the initial data type
** of the result column. ^The returned value is one of [SQLITE_INTEGER],
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
** The return value of sqlite3_column_type() can be used to decide which
** of the first six interface should be used to extract the column value.
** The value returned by sqlite3_column_type() is only meaningful if no
** automatic type conversions have occurred for the value in question.
** After a type conversion, the result of calling sqlite3_column_type()
** is undefined, though harmless. Future
** versions of SQLite may change the behavior of sqlite3_column_type()
** following a type conversion.
**
** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
** or sqlite3_column_bytes16() interfaces can be used to determine the size
** of that BLOB or string.
**
** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
** routine returns the number of bytes in that BLOB or string.
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
** the string to UTF-8 and then returns the number of bytes.
** ^If the result is a numeric value then sqlite3_column_bytes() uses
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
** the number of bytes in that string.
** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
**
** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
** routine returns the number of bytes in that BLOB or string.
** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
** the string to UTF-16 and then returns the number of bytes.
** ^If the result is a numeric value then sqlite3_column_bytes16() uses
** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
** the number of bytes in that string.
** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
**
** ^The values returned by [sqlite3_column_bytes()] and
** [sqlite3_column_bytes16()] do not include the zero terminators at the end
** of the string. ^For clarity: the values returned by
** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
** bytes in the string, not the number of characters.
**
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
** even empty strings, are always zero-terminated. ^The return
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
**
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
** [unprotected sqlite3_value] object. In a multithreaded environment,
** an unprotected sqlite3_value object may only be used safely with
** [sqlite3_bind_value()] and [sqlite3_result_value()].
** If the [unprotected sqlite3_value] object returned by
** [sqlite3_column_value()] is used in any other way, including calls
** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
** or [sqlite3_value_bytes()], the behavior is not threadsafe.
** Hence, the sqlite3_column_value() interface
** is normally only useful within the implementation of
** [application-defined SQL functions] or [virtual tables], not within
** top-level application code.
**
** The these routines may attempt to convert the datatype of the result.
** ^For example, if the internal representation is FLOAT and a text result
** is requested, [sqlite3_snprintf()] is used internally to perform the
** conversion automatically. ^(The following table details the conversions
** that are applied:
**
** <blockquote>
** <table border="1">
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
**
** <tr><td> NULL <td> INTEGER <td> Result is 0
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
** <tr><td> TEXT <td> BLOB <td> No change
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
** </table>
** </blockquote>)^
**
** Note that when type conversions occur, pointers returned by prior
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
** sqlite3_column_text16() may be invalidated.
** Type conversions and pointer invalidations might occur
** in the following cases:
**
** <ul>
** <li> The initial content is a BLOB and sqlite3_column_text() or
** sqlite3_column_text16() is called. A zero-terminator might
** need to be added to the string.</li>
** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
** sqlite3_column_text16() is called. The content must be converted
** to UTF-16.</li>
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
** sqlite3_column_text() is called. The content must be converted
** to UTF-8.</li>
** </ul>
**
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
** not invalidate a prior pointer, though of course the content of the buffer
** that the prior pointer references will have been modified. Other kinds
** of conversion are done in place when it is possible, but sometimes they
** are not possible and in those cases prior pointers are invalidated.
**
** The safest policy is to invoke these routines
** in one of the following ways:
**
** <ul>
** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
** </ul>
**
** In other words, you should call sqlite3_column_text(),
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
** into the desired format, then invoke sqlite3_column_bytes() or
** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
** to sqlite3_column_text() or sqlite3_column_blob() with calls to
** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
** with calls to sqlite3_column_bytes().
**
** ^The pointers returned are valid until a type conversion occurs as
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
** and BLOBs is freed automatically. Do not pass the pointers returned
** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
** [sqlite3_free()].
**
** ^(If a memory allocation error occurs during the evaluation of any
** of these routines, a default value is returned. The default value
** is either the integer 0, the floating point number 0.0, or a NULL
** pointer. Subsequent calls to [sqlite3_errcode()] will return
** [SQLITE_NOMEM].)^
label: code-design
#include "sqlite3ext.h"
comment:
** 2008 October 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to implement an in-memory rollback journal.
** The in-memory rollback journal is used to journal transactions for
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
**
** Update: The in-memory journal is also used to temporarily cache
** smaller journals that are not critical for power-loss recovery.
** For example, statement journals that are not too big will be held
** entirely in memory, thus reducing the number of file I/O calls, and
** more importantly, reducing temporary file creation events. If these
** journals become too large for memory, they are spilled to disk. But
** in the common case, they are usually small and no file I/O needs to
** occur.
label: code-design
Used by fts3.c only.
** CAPI3REF: Copy And Free SQL Values
** METHOD: sqlite3_value
**
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
** is a [protected sqlite3_value] object even if the input is not.
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
** memory allocation fails.
**
** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
** then sqlite3_value_free(V) is a harmless no-op.
WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY
** This function is used as part of the big assert() procedure implemented by
** fts5AssertMultiIterSetup(). It ensures that the result currently stored
** in *pRes is the correct result of comparing the current positions of the
** two iterators.
comment:
** Reassign page numbers so that the new pages are in ascending order.
** This helps to keep entries in the disk file in order so that a scan
** of the table is closer to a linear scan through the file. That in turn
** helps the operating system to deliver pages from the disk more rapidly.
**
** An O(n^2) insertion sort algorithm is used, but since n is never more
** than (NB+2) (a small constant), that should not be a problem.
**
** When NB==3, this one optimization makes the database about 25% faster
** for large insertions and deletions.
label: code-design
The index of the cell within the node
890
Next select to the left in a compound
TUNING: One-time cost for computing the automatic index is
** estimated to be X*N*log2(N) where N is the number of rows in
** the table being indexed and where X is 7 (LogEst=28) for normal
** tables or 1.375 (LogEst=4) for views and subqueries. The value
** of X is smaller for views and subqueries so that the query planner
** will be more aggressive about generating automatic indexes for
** those objects, since there is no opportunity to add schema
** indexes on subqueries and views.
** The following global variable is incremented whenever the
** transfer optimization is used. This is used for testing
** purposes only - to make sure the transfer optimization really
** is happening when it is supposed to.
Second part of the name of the table or view
Leave error message here
** This function is called when an UPDATE or DELETE operation is being
** compiled on table pTab, which is the parent table of foreign-key pFKey.
** If the current operation is an UPDATE, then the pChanges parameter is
** passed a pointer to the list of columns being modified. If it is a
** DELETE, pChanges is passed a NULL pointer.
**
** It returns a pointer to a Trigger structure containing a trigger
** equivalent to the ON UPDATE or ON DELETE action specified by pFKey.
** If the action is "NO ACTION" or "RESTRICT", then a NULL pointer is
** returned (these actions require no special handling by the triggers
** sub-system, code for them is created by fkScanChildren()).
**
** For example, if pFKey is the foreign key and pTab is table "p" in
** the following schema:
**
** CREATE TABLE p(pk PRIMARY KEY);
** CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
**
** then the returned trigger structure is equivalent to:
**
** CREATE TRIGGER ... DELETE ON p BEGIN
** DELETE FROM c WHERE ck = old.pk;
** END;
**
** The returned pointer is cached as part of the foreign key object. It
** is eventually freed along with the rest of the foreign key object by
** sqlite3FkDelete().
Figure out if we have any triggers and if the table being
** deleted from is a view
** Reset the aggregate accumulator.
**
** The aggregate accumulator is a set of memory cells that hold
** intermediate results while calculating an aggregate. This
** routine generates code that stores NULLs in all of those memory
** cells.
Wal-index header for current transaction
** sqlite3_test_control(FAULT_INSTALL, xCallback)
**
** Arrange to invoke xCallback() whenever sqlite3FaultSim() is called,
** if xCallback is not NULL.
**
** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
** is called immediately after installing the new callback and the return
** value from sqlite3FaultSim(0) becomes the return from
** sqlite3_test_control().
Column number of the index
comment: PmaReaders should be normally initialized in order, as if they are
** reading from the same temp file this makes for more linear file IO.
** However, in the INCRINIT_ROOT case, if PmaReader aReadr[nTask-1] is
** in use it will block the vdbePmaReaderNext() call while it uses
** the main thread to fill its buffer. So calling PmaReaderNext()
** on this PmaReader before any of the multi-threaded PmaReaders takes
** better advantage of multi-processor hardware.
label: code-design
Make sure there are enough memory cells allocated to accommodate
** the regPrev array and a trailing rowid (the rowid slot is required
** when building a record to insert into the sample column of
** the sqlite_stat4 table.
** This function is used to read a single varint from a buffer. Parameter
** pEnd points 1 byte past the end of the buffer. When this function is
** called, if *pp points to pEnd or greater, then the end of the buffer
** has been reached. In this case *pp is set to 0 and the function returns.
**
** If *pp does not point to or past pEnd, then a single varint is read
** from *pp. *pp is then set to point 1 byte past the end of the read varint.
**
** If bDescIdx is false, the value read is added to *pVal before returning.
** If it is true, the value read is subtracted from *pVal before this
** function returns.
Strategy index
This is the case if the data for the INSERT is coming from a
** single-row VALUES clause
Delete the %_content record
comment: The first time a column affinity string for a particular index is
** required, it is allocated and populated here. It is then stored as
** a member of the Index structure for subsequent use.
**
** The column affinity string will eventually be deleted by
** sqliteDeleteIndex() when the Index structure itself is cleaned
** up.
label: code-design
** Let any sequence of one or more vowels be represented by V and let
** C be sequence of one or more consonants. Then every word can be
** represented as:
**
** [C] (VC){m} [V]
**
** In prose: A word is an optional consonant followed by zero or
** vowel-consonant pairs followed by an optional vowel. "m" is the
** number of vowel consonant pairs. This routine computes the value
** of m for the first i bytes of a word.
**
** Return true if the m-value for z is 1 or more. In other words,
** return true if z contains at least one vowel that is followed
** by a consonant.
**
** In this routine z[] is in reverse order. So we are really looking
** for an instance of a consonant followed by a vowel.
return true if number and no extra non-whitespace chracters after
** Each SQLite module (virtual table definition) is defined by an
** instance of the following structure, stored in the sqlite3.aModule
** hash table.
** Increment the r-tree reference count.
Any tokens larger than this (in bytes) are passed through without
** stemming.
#include "config.h"
OUTER
If the P3 value cannot be converted into any kind of a number,
** then the seek is not possible, so jump to P2
The evaluation of the IN/EXISTS/SELECT must be repeated every time it
** is encountered if any of the following is true:
**
** * The right-hand side is a correlated subquery
** * The right-hand side is an expression list containing variables
** * We are inside a trigger
**
** If all of the above are false, then we can run this code just once
** save the results, and reuse the same result on subsequent invocations.
** Return the ROWID of the most recent insert
Database connection to notify of OOM errors
Name of indexed column
Savepoint name (nul-terminated)
** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
** must be either NO_LOCK or SHARED_LOCK.
**
** If the locking level of the file descriptor is already at or below
** the requested locking level, this routine is a no-op.
**
** When the locking level reaches NO_LOCK, delete the lock file.
Offset in pFile
New name of FTS5 table
Value to pass to log callback (or 0)
Copy of pOrig
Printf format string to append
Checksum for wal-header
Set to cheapest remaining token.
VM being reprepared (sqlite3Reprepare())
** CAPI3REF: Status Parameters for prepared statements
** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
**
** These preprocessor macros define integer codes that name counter
** values associated with the [sqlite3_stmt_status()] interface.
** The meanings of the various counters are as follows:
**
** <dl>
** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
** <dd>^This is the number of times that SQLite has stepped forward in
** a table as part of a full table scan. Large numbers for this counter
** may indicate opportunities for performance improvement through
** careful use of indices.</dd>
**
** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
** <dd>^This is the number of sort operations that have occurred.
** A non-zero value in this counter may indicate an opportunity to
** improvement performance through careful use of indices.</dd>
**
** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
** <dd>^This is the number of rows inserted into transient indices that
** were created automatically in order to help joins run faster.
** A non-zero value in this counter may indicate an opportunity to
** improvement performance by adding permanent indices that do not
** need to be reinitialized each time the statement is run.</dd>
**
** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
** <dd>^This is the number of virtual machine operations executed
** by the prepared statement if that number is less than or equal
** to 2147483647. The number of virtual machine operations can be
** used as a proxy for the total work done by the prepared statement.
** If the number of virtual machine operations exceeds 2147483647
** then the value returned by this statement status code is undefined.
**
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
** <dd>^This is the number of times that the prepare statement has been
** automatically regenerated due to schema changes or change to
** [bound parameters] that might affect the query plan.
**
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
** <dd>^This is the number of times that the prepared statement has
** been run. A single "run" for the purposes of this counter is one
** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
** The counter is incremented on the first [sqlite3_step()] call of each
** cycle.
**
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
** <dd>^This is the approximate number of bytes of heap memory
** used to store the prepared statement. ^This value is not actually
** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
** </dd>
** </dl>
pList!=0 if pF->pFunc has NEEDCOLL
pDone never used on non-savepoint
First argument to xCmp()
Configuration cookie value
Next in list of all blocked connections
True if this is a covering index
Store results as keys in an index
Total size of the database file
Advance zCsr to the next token. Store that token type in 'token',
** and its length in 'len' (to be used next iteration of this loop).
Arguments to rank function
Checksum on the header content
** Sometimes, after a file handle is closed by SQLite, the file descriptor
** cannot be closed immediately. In these cases, instances of the following
** structure are used to store the file descriptor while waiting for an
** opportunity to either close or reuse it.
comment: Next unused file descriptor on same file
label: code-design
True to defer constraints
** On machines with a small stack size, you can redefine the
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
Default value for the new column
The object to be destroyed
** Create a new sqlite3_value object, containing the value of pExpr.
**
** This only works for very simple expressions that consist of one constant
** token (i.e. "5", "5.1", "'a string'"). If the expression can
** be converted directly into a value, then the value is allocated and
** a pointer written to *ppVal. The caller is responsible for deallocating
** the value by passing it to sqlite3ValueFree() later on. If the expression
** cannot be converted to a value, then *ppVal is set to NULL.
Free the connection p
Instead of invoking the conflict handler, append the change blob
** to the SessionApplyCtx.constraints buffer.
** Return UTF-8 encoded English language explanation of the most recent
** error.
comment:
** The replace() function. Three arguments are all strings: call
** them A, B, and C. The result is also a string which is derived
** from A by replacing every occurrence of B with C. The match
** must be exact. Collating sequences are not used.
label: code-design
** Release a reference to data record returned by an earlier call to
** fts5DataRead().
Table for associated with an index on expr, or negative
** of the base register during check-constraint eval
** The following object holds a copy of the wal-index header content.
**
** The actual header in the wal-index consists of two copies of this
** object followed by one instance of the WalCkptInfo object.
** For all versions of SQLite through 3.10.0 and probably beyond,
** the locking bytes (WalCkptInfo.aLock) start at offset 120 and
** the total header size is 136 bytes.
**
** The szPage value can be any power of 2 between 512 and 32768, inclusive.
** Or it can be 1 to represent a 65536-byte page. The latter case was
** added in 3.7.1 when support for 64K pages was added.
** Returns non-zero if the specified path name should be used verbatim. If
** non-zero is returned from this function, the calling function must simply
** use the provided path name verbatim -OR- resolve it into a full path name
** using the GetFullPathName Win32 API function (if available).
Page size
RTree to search
inner
Least sig. 32 bits of new offset
This function currently works by first transforming the UTF-16
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
** tricky bit is figuring out the pointer to return in *pzTail.
** Returns non-zero if the character should be treated as a directory
** separator.
TABLE => nothing
The root page of the b-tree is overfull. In this case call the
** balance_deeper() function to create a new child for the root-page
** and copy the current contents of the root-page to it. The
** next iteration of the do-loop will balance the child page.
************* Continuing where we left off in mutex_w32.c *****************
** Generate code that will evaluate expression pExpr and store the
** results in register target. The results are guaranteed to appear
** in register target.
Delete all indices associated with this table.
Grow the output buffer so that there is sufficient space to fit the
** largest possible utf-8 character.
** Return the SQLITE_PREPARE flags for a Vdbe.
** Return the sqlite3* database handle to which the prepared statement given
** in the argument belongs. This is the same database handle that was
** the first argument to the sqlite3_prepare() that was used to create
** the statement in the first place.
Set to true if constraints may cause a replace
joinop ::= COMMA|JOIN
A row is being added to the child table. If a parent row cannot
** be found, adding the child row has violated the FK constraint.
**
** If this operation is being performed as part of a trigger program
** that is actually a "SET NULL" action belonging to this very
** foreign key, then omit this scan altogether. As all child key
** values are guaranteed to be NULL, it is not possible for adding
** this row to cause an FK violation.
Request is out of range. Return a transient error.
MUST BE LAST (see below)
If the first attempt failed, it might have been due to a race
** with a writer. So get a WRITE lock and try again.
comment:
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error. This
** is used for testing the I/O recovery logic.
label: code-design
Page cache allocations
comment: This term must be of the form t1.a==t2.b where t2 is in the
** chngToIN set but t1 is not. This term will be either preceded
** or follwed by an inverted copy (t2.b==t1.a). Skip this term
** and use its inversion.
label: code-design
Write the referenced table cursor and column here
** The file suffix added to the data base filename in order to create the
** lock directory.
Cursor of the table that is being indexed
comment:
** CAPI3REF: Dynamically Typed Value Object
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
**
** SQLite uses the sqlite3_value object to represent all values
** that can be stored in a database table. SQLite uses dynamic typing
** for the values it stores. ^Values stored in sqlite3_value objects
** can be integers, floating point values, strings, BLOBs, or NULL.
**
** An sqlite3_value object may be either "protected" or "unprotected".
** Some interfaces require a protected sqlite3_value. Other interfaces
** will accept either a protected or an unprotected sqlite3_value.
** Every interface that accepts sqlite3_value arguments specifies
** whether or not it requires a protected sqlite3_value. The
** [sqlite3_value_dup()] interface can be used to construct a new
** protected sqlite3_value from an unprotected sqlite3_value.
**
** The terms "protected" and "unprotected" refer to whether or not
** a mutex is held. An internal mutex is held for a protected
** sqlite3_value object but no mutex is held for an unprotected
** sqlite3_value object. If SQLite is compiled to be single-threaded
** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
** or if SQLite is run in one of reduced mutex modes
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
** then there is no distinction between protected and unprotected
** sqlite3_value objects and they can be used interchangeably. However,
** for maximum code portability it is recommended that applications
** still make the distinction between protected and unprotected
** sqlite3_value objects even when not strictly required.
**
** ^The sqlite3_value objects that are passed as parameters into the
** implementation of [application-defined SQL functions] are protected.
** ^The sqlite3_value object returned by
** [sqlite3_column_value()] is unprotected.
** Unprotected sqlite3_value objects may only be used with
** [sqlite3_result_value()] and [sqlite3_bind_value()].
** The [sqlite3_value_blob | sqlite3_value_type()] family of
** interfaces require protected sqlite3_value objects.
label: code-design
For an index btree, save the complete key content
OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER
Tail recursion
RECURSIVE
Entries in aOvfl[]
OUT: visibility of the cell
Remove any and all aliases between the result set and the
** GROUP BY clause.
Term searched for (or NULL)
Size of term prefix
MUTEX_STATIC_LRU or NULL
How to allocate space. Or NULL
trigger_cmd
Pointer to Fts5InsertCtx object
If the statement transaction is being rolled back, also restore the
** database handles deferred constraint counter to the value it had when
** the statement transaction was opened.
Data yet to be written
** Free as much memory as possible from the pager.
comment: Character classes for tokenizing
**
** In the sqlite3GetToken() function, a switch() on aiClass[c] is implemented
** using a lookup table, whereas a switch() directly on c uses a binary search.
** The lookup table is much faster. To maximize speed, and to ensure that
** a lookup table is used, all of the classes need to be small integers and
** all of them need to be used within the switch.
label: code-design
wait 0.5 sec and try the lock again
Initialize a new parser that has already been allocated.
** Helper function for exprIsDeterministic().
SELECT to the right of IN operator
Name of the index
trnm ::= nm DOT nm
API offered by current FTS version
If a transaction is still open on the Btree, roll it back.
Read the old.* and new.* records for the update change.
** Register the ICU extension functions with database db.
** Return the ceiling of the logarithm base 2 of iValue.
**
** Examples: memsys5Log(1) -> 0
** memsys5Log(2) -> 1
** memsys5Log(4) -> 2
** memsys5Log(5) -> 3
** memsys5Log(8) -> 3
** memsys5Log(9) -> 4
** A pointer to a structure of the following type is passed as the
** argument to scored geometry callback registered using
** sqlite3_rtree_query_callback().
**
** Note that the first 5 fields of this structure are identical to
** sqlite3_rtree_geometry. This structure is a subclass of
** sqlite3_rtree_geometry.
Address of "next_row:"
Fields below are only available in SQLite 3.9.0 and later
Btree cursor used for pIndex
The LEMON-generated LALR(1) parser
3*nCol*nPhrase values
** This routine is used to check if the UTF-8 string zName is a legal
** unqualified name for a new schema object (table, index, view or
** trigger). All names are legal except those that begin with the string
** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
** is reserved for internal use.
Run-cost of the new entry
If the overflow page-list cache has been allocated and the
** entry for the first required overflow page is valid, skip
** directly to it.
cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt
comment: PragTyp_XXX value
label: code-design
Special case - lookup by rowid.
Rootpage of table being initialized
Database handle
New root page image
** The following routine is called if the stack overflows.
String inserted between snippets
************* Begin file vdbe.h *******************************************
comment: The testcase() macro should already be defined in the amalgamation. If
** it is not, make it a no-op.
label: code-design
OUT: Next overflow page number
PRIMARY KEY index for WITHOUT ROWID tables
Least recently used entry has the smallest value
Restriction (19)
To downgrade to shared, simply update our internal notion of the
** lock state. No need to mess with the file on disk.
comment:
** Lock the virtual table so that it cannot be disconnected.
** Locks nest. Every lock should have a corresponding unlock.
** If an unlock is omitted, resources leaks will occur.
**
** If a disconnect is attempted while a virtual table is locked,
** the disconnect is deferred until all locks have been removed.
label: code-design
SQLITE_STMTSTATUS_FULLSCAN_STEP
Register holding co-routine entry-point
Opcode: OpenRead P1 P2 P3 P4 P5
** Synopsis: root=P2 iDb=P3
**
** Open a read-only cursor for the database table whose root page is
** P2 in a database file. The database file is determined by P3.
** P3==0 means the main database, P3==1 means the database used for
** temporary tables, and P3>1 means used the corresponding attached
** database. Give the new cursor an identifier of P1. The P1
** values need not be contiguous but all P1 values should be small integers.
** It is an error for P1 to be negative.
**
** If P5!=0 then use the content of register P2 as the root page, not
** the value of P2 itself.
**
** There will be a read lock on the database whenever there is an
** open cursor. If the database was unlocked prior to this instruction
** then a read lock is acquired as part of this instruction. A read
** lock allows other processes to read the database but prohibits
** any other process from modifying the database. The read lock is
** released when all cursors are closed. If this instruction attempts
** to get a read lock but fails, the script terminates with an
** SQLITE_BUSY error code.
**
** The P4 value may be either an integer (P4_INT32) or a pointer to
** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
** structure, then said structure defines the content and collating
** sequence of the index being opened. Otherwise, if P4 is an integer
** value, it is set to the number of columns in the table.
**
** See also: OpenWrite, ReopenIdx
Second argument for valueNew()
Compare function to use
If this is stat4 data, then calculate aAvgEq[] values for all
** sample columns except the last. The last is always set to 1, as
** once the trailing PK fields are considered all index keys are
** unique.
** Possible values for WAL.readOnly
Index of right-hand Fts5SegIter
** Return the bitmask for the given cursor number. Return 0 if
** iCursor is not in the set.
SQLITE_INTROSPECTION_PRAGMAS
comment: Some compilers complain about constants of the form 0x7fffffffffffffff.
** Others complain about 0x7ffffffffffffffffLL. The following macro seems
** to provide the constant while making all compilers happy.
label: code-design
SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is
** created. SQLite doesn't use it to indicate "exclusive access"
** as it is usually understood.
The table to code triggers from
comment: Initialize all term iterators in the NEAR object.
label: code-design
comment:
** Macro used to suppress compiler warnings for unused parameters.
label: code-design
** This function is also purely an internal test. It does not contribute to
** FTS functionality, or even the integrity-check, in any way.
Zero all hash-table entries that correspond to frame numbers greater
** than pWal->hdr.mxFrame.
Offset into the file to begin writing at
** This routine will drop an existing named index. This routine
** implements the DROP INDEX statement.
SELECT to read %_segdir entry
comment:
** This API allows applications to modify the global configuration of
** the SQLite library at run-time.
**
** This routine should only be called when there are no outstanding
** database connections or memory allocations. This routine is not
** threadsafe. Failure to heed these warnings can lead to unpredictable
** behavior.
label: code-design
Hint read from %_stat table
Current block image
** This version of the memory allocator is used only when
** SQLITE_ENABLE_MEMSYS5 is defined.
** Implementation of the sqlite3_pcache.xDestroy method.
**
** Destroy a cache allocated using pcache1Create().
0x1d
** Check to see if the given expression is a LIKE or GLOB operator that
** can be optimized using inequality constraints. Return TRUE if it is
** so and false if not.
**
** In order for the operator to be optimizible, the RHS must be a string
** literal that does not begin with a wildcard. The LHS must be a column
** that may only be NULL, a string, or a BLOB, never a number. (This means
** that virtual tables cannot participate in the LIKE optimization.) The
** collating sequence for the column on the LHS must be appropriate for
** the operator.
REPLACE_DOCSIZE
Obtain a reference to the index structure and allocate a new segment-id
** for the new level-0 segment.
Cannot EXPRDUP_REDUCE this Expr
Part of a parenthesized FROM clause
Apply change to "main" db of this handle
** Parameter zSrcData points to a buffer containing the data for
** page iSrcPg from the source database. Copy this data into the
** destination database.
************* Begin file whereexpr.c **************************************
Number of bytes yet to be written
** Allowed values for the NameContext, ncFlags field.
**
** Value constraints (all checked via assert()):
** NC_HasAgg == SF_HasAgg
** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
**
Each iteration of this loop gobbles up a contiguous run of separators,
** then the next token.
If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
** is not defined), then it is important to call OP_Destroy on the
** table and index root-pages in order, starting with the numerically
** largest root-page number. This guarantees that none of the root-pages
** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
** following were coded:
**
** OP_Destroy 4 0
** ...
** OP_Destroy 5 0
**
** and root page 5 happened to be the largest root-page number in the
** database, then root page 5 would be moved to page 4 by the
** "OP_Destroy 4 0" opcode. The subsequent "OP_Destroy 5 0" would hit
** a free-list page.
** Process a modifier to a date-time stamp. The modifiers are
** as follows:
**
** NNN days
** NNN hours
** NNN minutes
** NNN.NNNN seconds
** NNN months
** NNN years
** start of month
** start of year
** start of week
** start of day
** weekday N
** unixepoch
** localtime
** utc
**
** Return 0 on success and 1 if there is any kind of error. If the error
** is in a system call (i.e. localtime()), then an error message is written
** to context pCtx. If the error is an unrecognized modifier, no error is
** written to pCtx.
** The buffer pointed to by argument zNode (size nNode bytes) contains an
** interior node of a b-tree segment. The zTerm buffer (size nTerm bytes)
** contains a term. This function searches the sub-tree headed by the zNode
** node for the range of leaf nodes that may contain the specified term
** or terms for which the specified term is a prefix.
**
** If piLeaf is not NULL, then *piLeaf is set to the blockid of the
** left-most leaf node in the tree that may contain the specified term.
** If piLeaf2 is not NULL, then *piLeaf2 is set to the blockid of the
** right-most leaf node that may contain a term for which the specified
** term is a prefix.
**
** It is possible that the range of returned leaf nodes does not contain
** the specified term or any terms for which it is a prefix. However, if the
** segment does contain any such terms, they are stored within the identified
** range. Because this function only inspects interior segment nodes (and
** never loads leaf nodes into memory), it is not possible to be sure.
**
** If an error occurs, an error code other than SQLITE_OK is returned.
** CAPI3REF: Changegroup Handle
** Flush the contents of memory to a real file on disk.
Search for self-joins in this FROM clause
Number of columns in index + pk/rowid
If nBest is still 0, then the index must be empty.
In the absence of explicit truth probabilities, use heuristics to
** guess a reasonable truth probability.
F_UNLCK, F_RDLCK, or F_WRLCK
Loop addresses
distinct ::= ALL
IN/OUT: Size of buffer *ppList in bytes
#include "wal.h"
Bytes of memory required
ON UPDATE action
Index of this phrase in matchinfo() results
** Expression pVar is guaranteed to be an SQL variable. pExpr may be any
** type of expression.
**
** If pExpr is a simple SQL value - an integer, real, string, blob
** or NULL value - then the VDBE currently being prepared is configured
** to re-prepare each time a new value is bound to variable pVar.
**
** Additionally, if pExpr is a simple SQL value and the value is the
** same as that currently bound to variable pVar, non-zero is returned.
** Otherwise, if the values are not the same or if pExpr is not a simple
** SQL value, zero is returned.
Get an appropriate name for the column
Current insert batch
** Advance the cursor to the next row in the table that matches the
** search criteria.
**
** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
** even if we reach end-of-file. The fts5EofMethod() will be called
** subsequently to determine whether or not an EOF was hit.
Factor out constant terms
** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared
** btree as the argument handle holds an exclusive lock on the
** sqlite_master table. Otherwise SQLITE_OK.
** CAPI3REF: Last Insert Rowid
** METHOD: sqlite3
**
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
** has a unique 64-bit signed
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
** names are not also used by explicitly declared columns. ^If
** the table has a column of type [INTEGER PRIMARY KEY] then that column
** is another alias for the rowid.
**
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
** the most recent successful [INSERT] into a rowid table or [virtual table]
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
** on the database connection D, then sqlite3_last_insert_rowid(D) returns
** zero.
**
** As well as being set automatically as rows are inserted into database
** tables, the value returned by this function may be set explicitly by
** [sqlite3_set_last_insert_rowid()]
**
** Some virtual table implementations may INSERT rows into rowid tables as
** part of committing a transaction (e.g. to flush data accumulated in memory
** to disk). In this case subsequent calls to this function return the rowid
** associated with these internal INSERT operations, which leads to
** unintuitive results. Virtual table implementations that do write to rowid
** tables in this way can avoid this problem by restoring the original
** rowid value using [sqlite3_set_last_insert_rowid()] before returning
** control to the user.
**
** ^(If an [INSERT] occurs within a trigger then this routine will
** return the [rowid] of the inserted row as long as the trigger is
** running. Once the trigger program ends, the value returned
** by this routine reverts to what it was before the trigger was fired.)^
**
** ^An [INSERT] that fails due to a constraint violation is not a
** successful [INSERT] and does not change the value returned by this
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
** and INSERT OR ABORT make no changes to the return value of this
** routine when their insertion fails. ^(When INSERT OR REPLACE
** encounters a constraint violation, it does not fail. The
** INSERT continues to completion after deleting rows that caused
** the constraint problem so INSERT OR REPLACE will always change
** the return value of this interface.)^
**
** ^For the purposes of this routine, an [INSERT] is considered to
** be successful even if it is subsequently rolled back.
**
** This function is accessible to SQL statements via the
** [last_insert_rowid() SQL function].
**
** If a separate thread performs a new [INSERT] on the same
** database connection while the [sqlite3_last_insert_rowid()]
** function is running and thus changes the last insert [rowid],
** then the value returned by [sqlite3_last_insert_rowid()] is
** unpredictable and might not equal either the old or the new
** last insert [rowid].
Check to see if a legacy fts3 table has been "upgraded" by the
** addition of a %_stat table so that it can use incremental merge.
** Free a WhereInfo structure
Estimate the upper limit on the number of leaf nodes in a new segment
** created by merging the oldest :2 segments from absolute level :1. See
** function sqlite3Fts3Incrmerge() for details.
** Return the approximate number of bytes of memory currently
** used by the pager and its associated cache.
Write the resulting vtab structure here
Tokenize return code
True if attempting to append
If the fts5YYNOERRORRECOVERY macro is defined, then do not attempt to
** do any kind of error recovery. Instead, simply invoke the syntax
** error routine and continue going as if nothing had happened.
**
** Applications can set this macro (for example inside %include) if
** they intend to abandon the parse upon the first syntax error seen.
An existing page in the cache
Storage for BLOB written into %_stat
Sync at the end of each transaction
Position lists for current row
** Return the database associated with the Vdbe.
************* End of pcache.h *********************************************
True if sPoint is valid
If opening an attached database, the encoding much match ENC(db)
Name of column in the right table
SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT)
** Join two expressions using an AND operator. If either expression is
** NULL, then just return the other expression.
**
** If one side or the other of the AND is known to be false, then instead
** of returning an AND expression, just return a constant expression with
** a value of false.
Sync the WAL to disk
** Each tokenizer module registered with the FTS5 module is represented
** by an object of the following type. All such objects are stored as part
** of the Fts5Global.pTok list.
OUT: MemPage handle (may be NULL)
True if analyzing arguments to an agg func
comment: Clean up the rbu_tmp_xxx table for the previous table. It
** cannot be dropped as there are currently active SQL statements.
** But the contents can be deleted.
label: code-design
************* End of date.c ***********************************************
Backup process error code
** When this function is called, buffer *ppList (size *pnList bytes) contains
** a position list that may (or may not) feature multiple columns. This
** function adjusts the pointer *ppList and the length *pnList so that they
** identify the subset of the position list that corresponds to column iCol.
**
** If there are no entries in the input position list for column iCol, then
** *pnList is set to zero before returning.
**
** If parameter bZero is non-zero, then any part of the input list following
** the end of the output list is zeroed before returning.
QUERY
OUT: Number of bytes in output changeset
Offset into the data
Pointer to start of phrase position list
True if in a normal write operation
** This file contains the implementation of an in-memory hash table used
** to accumuluate "term -> doclist" content before it is flused to a level-0
** segment.
cross
Deferred constraints are stored here
Insert an OP_Halt at the end of the sub-program.
Address of MustBeInt instruction
** Write data to an rbuVfs-file.
** Given a token, return a string that consists of the text of that
** token. Space to hold the returned string
** is obtained from sqliteMalloc() and must be freed by the calling
** function.
**
** Any quotation marks (ex: "name", 'name', [name], or `name`) that
** surround the body of the token are removed.
**
** Tokens are often just pointers into the original SQL text and so
** are not \000 terminated and are not persistent. The returned string
** is \000 terminated and is persistent.
** PRAGMA [schema.]auto_vacuum
** PRAGMA [schema.]auto_vacuum=N
**
** Get or set the value of the database 'auto-vacuum' parameter.
** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
Start of column names in pragCName[]
The offset for WriteFile.
** This function is used to allocate and populate UnpackedRecord
** structures intended to be compared against sample index keys stored
** in the sqlite_stat4 table.
**
** A single call to this function populates zero or more fields of the
** record starting with field iVal (fields are numbered from left to
** right starting with 0). A single field is populated if:
**
** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
**
** * The expression is a bound variable, and this is a reprepare, or
**
** * The sqlite3ValueFromExpr() function is able to extract a value
** from the expression (i.e. the expression is a literal value).
**
** Or, if pExpr is a TK_VECTOR, one field is populated for each of the
** vector components that match either of the two latter criteria listed
** above.
**
** Before any value is appended to the record, the affinity of the
** corresponding column within index pIdx is applied to it. Before
** this function returns, output parameter *pnExtract is set to the
** number of values appended to the record.
**
** When this function is called, *ppRec must either point to an object
** allocated by an earlier call to this function, or must be NULL. If it
** is NULL and a value can be successfully extracted, a new UnpackedRecord
** is allocated (and *ppRec set to point to it) before returning.
**
** Unless an error is encountered, SQLITE_OK is returned. It is not an
** error if a value cannot be extracted from pExpr. If an error does
** occur, an SQLite error code is returned.
We are trying for an exclusive lock but another thread in this
** same process is still holding a shared lock.
If pSortCsr is non-NULL, then this call is being made as part of
** processing for a "... MATCH <expr> ORDER BY rank" query (ePlan is
** set to FTS5_PLAN_SORTED_MATCH). pSortCsr is the cursor that will
** return results to the user for this query. The current cursor
** (pCursor) is used to execute the query issued by function
** fts5CursorFirstSorted() above.
************* Begin file pcache.h *****************************************
Verify that the every entry in the mapping region is reachable
** via the hash table. This turns out to be a really, really expensive
** thing to check, so only do this occasionally - not on every
** iteration.
It is not safe to allow the reader to continue here if frames
** may have been appended to the log before READ_LOCK(0) was obtained.
** When holding READ_LOCK(0), the reader ignores the entire log file,
** which implies that the database file contains a trustworthy
** snapshot. Since holding READ_LOCK(0) prevents a checkpoint from
** happening, this is usually correct.
**
** However, if frames have been appended to the log (or if the log
** is wrapped and written for that matter) before the READ_LOCK(0)
** is obtained, that is not necessarily true. A checkpointer may
** have started to backfill the appended frames but crashed before
** it finished. Leaving a corrupt image in the database file.
If azData[0] is not an SQL NULL value, it is the rowid of a
** record to delete from the r-tree table. The following block does
** just that.
Destination database handle
** Enable or disable extension loading. Extension loading is disabled by
** default so as not to open security holes in older applications.
Opcode: NotFound P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
** P4>0 then register P3 is the first of P4 registers that form an unpacked
** record.
**
** Cursor P1 is on an index btree. If the record identified by P3 and P4
** is not the prefix of any entry in P1 then a jump is made to P2. If P1
** does contain an entry whose prefix matches the P3/P4 record then control
** falls through to the next instruction and P1 is left pointing at the
** matching entry.
**
** This operation leaves the cursor in a state where it cannot be
** advanced in either direction. In other words, the Next and Prev
** opcodes do not work after this operation.
**
** See also: Found, NotExists, NoConflict
** Propagate all EP_Propagate flags from the Expr.x.pList into
** Expr.flags.
Index of column in parent tbl
Do the comparison
State must be valid.
Number of elements on left side vector
** Streaming versions of changegroup_add().
** xFilter - Initialize a cursor to point at the start of its data.
List to be merged
comment:
** The default SQLite sqlite3_vfs implementations do not allocate
** memory (actually, os_unix.c allocates a small amount of memory
** from within OsOpen()), but some third-party implementations may.
** So we test the effects of a malloc() failing and the sqlite3OsXXX()
** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
**
** The following functions are instrumented for malloc() failure
** testing:
**
** sqlite3OsRead()
** sqlite3OsWrite()
** sqlite3OsSync()
** sqlite3OsFileSize()
** sqlite3OsLock()
** sqlite3OsCheckReservedLock()
** sqlite3OsFileControl()
** sqlite3OsShmMap()
** sqlite3OsOpen()
** sqlite3OsDelete()
** sqlite3OsAccess()
** sqlite3OsFullPathname()
**
label: code-design
Create the content table
Match these columns only
Next unread data byte
indexed_opt ::=
Take a copy of the sample. Add two 0x00 bytes the end of the buffer.
** This is in case the sample record is corrupted. In that case, the
** sqlite3VdbeRecordCompare() may read up to two varints past the
** end of the allocated buffer before it realizes it is dealing with
** a corrupt record. Adding the two 0x00 bytes prevents this from causing
** a buffer overread.
New value
Case 1: expr IN (SELECT ...)
**
** Generate code to write the results of the select into the temporary
** table allocated and opened above.
Result of the comparison of pIn1 against pIn3
Parsing context used to create this Vdbe
63
Integer primary key index
If eMode==BTALLOC_EXACT and a query of the pointer-map
** shows that the page 'nearby' is somewhere on the free-list, then
** the entire-list will be searched for that page.
Doclist to iterate through
Content is irrelevant for
** 1. the typeof() function,
** 2. the length(X) function if X is a blob, and
** 3. if the content length is zero.
** So we might as well use bogus content rather than reading
** content from disk.
**
** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
** buffer passed to it, debugging function VdbeMemPrettyPrint() may
** read up to 16. So 16 bytes of bogus content is supplied.
Bytes to allocate for each journal fd
Override onError to this if not OE_Default
Adjust pTemplate cost upward so that it is costlier than p since
** pTemplate is a proper subset of p
autoinc ::= AUTOINCR
The database of pDest
See if the checksum matches the master journal name
** A single cell from a node, deserialized
** This is called to implement the special "VALUES('merge', $nMerge)"
** INSERT command.
The page to move to.
Fill in pC->aType[i] and aOffset[i] values through the p2-th field.
Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
** if the allocation fails. Otherwise, zero the new portion in case a
** malloc failure occurs while populating it in the for(...) loop below.
If this is a REPLACE, first remove the current entry (if any)
OUT: Prepared statement handle
Information about the WHERE clause
** CAPI3REF: Delete A Changegroup Object
** Return the total number of key-value operations (inserts, deletes or
** updates) that have been performed on the target database since the
** current RBU update was started.
** Invoke the busy handler for a btree.
comment: Update the page-size to match the value read from the journal.
** Use a testcase() macro to make sure that malloc failure within
** PagerSetPagesize() is tested.
label: code-design
Mode parameter for allocateBtreePage()
... of the TK_xx values...
Generate code that deals with a rowid collision
Chunk of wal-index containing header
NOT => nothing
Free all allocated memory and reset the JsonString object back to its
** initial state.
Iterator to advance
1000
For comparing with previous entry
languageid
comment:
** These no-op macros are used in front of interfaces to mark those
** interfaces as either deprecated or experimental. New applications
** should not use deprecated interfaces - they are supported for backwards
** compatibility only. Application writers should be aware that
** experimental interfaces are subject to change in point releases.
**
** These macros used to resolve to various kinds of compiler magic that
** would generate warning messages when they were used. But that
** compiler magic ended up generating such a flurry of bug reports
** that we have taken it all out and gone back to using simple
** noop macros.
label: code-design
Open conch file
Configured cache size
Value is a RowSet object
comment:
** Adjust the WhereLoop.nOut value downward to account for terms of the
** WHERE clause that reference the loop but which are not used by an
** index.
*
** For every WHERE clause term that is not used by the index
** and which has a truth probability assigned by one of the likelihood(),
** likely(), or unlikely() SQL functions, reduce the estimated number
** of output rows by the probability specified.
**
** TUNING: For every WHERE clause term that is not used by the index
** and which does not have an assigned truth probability, heuristics
** described below are used to try to estimate the truth probability.
** TODO --> Perhaps this is something that could be improved by better
** table statistics.
**
** Heuristic 1: Estimate the truth probability as 93.75%. The 93.75%
** value corresponds to -1 in LogEst notation, so this means decrement
** the WhereLoop.nOut field for every such WHERE clause term.
**
** Heuristic 2: If there exists one or more WHERE clause terms of the
** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
** final output row estimate is no greater than 1/4 of the total number
** of rows in the table. In other words, assume that x==EXPR will filter
** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
** "x" column is boolean or else -1 or 0 or 1 is a common default value
** on the "x" column and so in that case only cap the output row estimate
** at 1/2 instead of 1/4.
label: code-design
** Called when we are unable to satisfy an allocation of nBytes.
comment: Unmap any pages of the existing mapping that cannot be reused.
label: code-design
155
First byte of buffer to write
** The actual function that does the work of creating a new module.
** This function implements the sqlite3_create_module() and
** sqlite3_create_module_v2() interfaces.
"content_rowid=" option value
True if field width constant starts with zero
make our hash too "full".
0=entries. 1=leaf node. 2+ for higher
Size before spilling occurs
Which db file is being initialized
** Free an Fts3MultiSegReader allocated by fts3TermSegReaderCursor().
synopsis: r[P3]=rowset(P1)
All above except SYNCHRONOUS
Language id of row being written
** This function is called by the xUpdate() method for an INSERT operation.
** The apVal parameter is passed a copy of the apVal argument passed by
** SQLite to the xUpdate() method. i.e:
**
** apVal[0] Not used for INSERT.
** apVal[1] rowid
** apVal[2] Left-most user-defined column
** ...
** apVal[p->nColumn+1] Right-most user-defined column
** apVal[p->nColumn+2] Hidden column with same name as table
** apVal[p->nColumn+3] Hidden "docid" column (alias for rowid)
** apVal[p->nColumn+4] Hidden languageid column
** The xDisconnect() virtual table method.
Counter used to generate aColCache[].lru values
Value extracted from pLower
Keep cursor valid
** An instance of the following structure encodes all information that can
** be gleaned from the CREATE VIRTUAL TABLE statement.
**
** And all information loaded from the %_config table.
**
** nAutomerge:
** The minimum number of segments that an auto-merge operation should
** attempt to merge together. A value of 1 sets the object to use the
** compile time default. Zero disables auto-merge altogether.
**
** zContent:
**
** zContentRowid:
** The value of the content_rowid= option, if one was specified. Or
** the string "rowid" otherwise. This text is not quoted - if it is
** used as part of an SQL statement it needs to be quoted appropriately.
**
** zContentExprlist:
**
** pzErrmsg:
** This exists in order to allow the fts5_index.c module to return a
** decent error message if it encounters a file-format version it does
** not understand.
**
** bColumnsize:
** True if the %_docsize table is created.
**
** bPrefixIndex:
** This is only used for debugging. If set to false, any prefix indexes
** are ignored. This value is configured using:
**
** INSERT INTO tbl(tbl, rank) VALUES('prefix-index', $bPrefixIndex);
**
Allocate nArg registers to martial the arguments to VUpdate. Then
** create and open the ephemeral table in which the records created from
** these arguments will be temporarily stored.
** This routine is the core allocator for Expr nodes.
**
** Construct a new expression node and return a pointer to it. Memory
** for this node and for the pToken argument is a single allocation
** obtained from sqlite3DbMalloc(). The calling function
** is responsible for making sure the node eventually gets freed.
**
** If dequote is true, then the token (if it exists) is dequoted.
** If dequote is false, no dequoting is performed. The deQuote
** parameter is ignored if pToken is NULL or if the token does not
** appear to be quoted. If the quotes were of the form "..." (double-quotes)
** then the EP_DblQuoted flag is set on the expression node.
**
** Special case: If op==TK_INTEGER and pToken points to a string that
** can be translated into a 32-bit integer, then the token is not
** stored in u.zToken. Instead, the integer values is written
** into u.iValue and the EP_IntValue flag is set. No extra storage
** is allocated to hold the integer text and the dequote flag is ignored.
Cursor used to iterate through aLeft
** Launch a background thread to run xTask(pIn).
** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not
** a conjunction, then return just pTerm when N==0. If N is exceeds
** the number of available subterms, return NULL.
** CAPI3REF: Opening A New Database Connection
** CONSTRUCTOR: sqlite3
**
** ^These routines open an SQLite database file as specified by the
** filename argument. ^The filename argument is interpreted as UTF-8 for
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
** order for sqlite3_open16(). ^(A [database connection] handle is usually
** returned in *ppDb, even if an error occurs. The only exception is that
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
** object.)^ ^(If the database is opened (and/or created) successfully, then
** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
** an English language description of the error following a failure of any
** of the sqlite3_open() routines.
**
** ^The default encoding will be UTF-8 for databases created using
** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
** created using sqlite3_open16() will be UTF-16 in the native byte order.
**
** Whether or not an error occurs when it is opened, resources
** associated with the [database connection] handle should be released by
** passing it to [sqlite3_close()] when it is no longer required.
**
** The sqlite3_open_v2() interface works like sqlite3_open()
** except that it accepts two additional parameters for additional control
** over the new database connection. ^(The flags parameter to
** sqlite3_open_v2() can take one of
** the following three values, optionally combined with the
** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
**
** <dl>
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
** <dd>The database is opened in read-only mode. If the database does not
** already exist, an error is returned.</dd>)^
**
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
** <dd>The database is opened for reading and writing if possible, or reading
** only if the file is write protected by the operating system. In either
** case the database must already exist, otherwise an error is returned.</dd>)^
**
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
** <dd>The database is opened for reading and writing, and is created if
** it does not already exist. This is the behavior that is always used for
** sqlite3_open() and sqlite3_open16().</dd>)^
** </dl>
**
** If the 3rd parameter to sqlite3_open_v2() is not one of the
** combinations shown above optionally combined with other
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
** then the behavior is undefined.
**
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
** opens in the multi-thread [threading mode] as long as the single-thread
** mode has not been set at compile-time or start-time. ^If the
** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
** in the serialized [threading mode] unless single-thread was
** previously selected at compile-time or start-time.
** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
** eligible to use [shared cache mode], regardless of whether or not shared
** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
** participate in [shared cache mode] even if it is enabled.
**
** ^The fourth parameter to sqlite3_open_v2() is the name of the
** [sqlite3_vfs] object that defines the operating system interface that
** the new database connection should use. ^If the fourth parameter is
** a NULL pointer then the default [sqlite3_vfs] object is used.
**
** ^If the filename is ":memory:", then a private, temporary in-memory database
** is created for the connection. ^This in-memory database will vanish when
** the database connection is closed. Future versions of SQLite might
** make use of additional special filenames that begin with the ":" character.
** It is recommended that when a database filename actually does begin with
** a ":" character you should prefix the filename with a pathname such as
** "./" to avoid ambiguity.
**
** ^If the filename is an empty string, then a private, temporary
** on-disk database will be created. ^This private database will be
** automatically deleted as soon as the database connection is closed.
**
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
**
** ^If [URI filename] interpretation is enabled, and the filename argument
** begins with "file:", then the filename is interpreted as a URI. ^URI
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
** set in the fourth argument to sqlite3_open_v2(), or if it has
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
** As of SQLite version 3.7.7, URI filename interpretation is turned off
** by default, but future releases of SQLite might enable URI filename
** interpretation by default. See "[URI filenames]" for additional
** information.
**
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
** authority, then it must be either an empty string or the string
** "localhost". ^If the authority is not an empty string or "localhost", an
** error is returned to the caller. ^The fragment component of a URI, if
** present, is ignored.
**
** ^SQLite uses the path component of the URI as the name of the disk file
** which contains the database. ^If the path begins with a '/' character,
** then it is interpreted as an absolute path. ^If the path does not begin
** with a '/' (meaning that the authority section is omitted from the URI)
** then the path is interpreted as a relative path.
** ^(On windows, the first component of an absolute path
** is a drive specification (e.g. "C:").)^
**
** [[core URI query parameters]]
** The query component of a URI may contain parameters that are interpreted
** either by SQLite itself, or by a [VFS | custom VFS implementation].
** SQLite and its built-in [VFSes] interpret the
** following query parameters:
**
** <ul>
** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
** a VFS object that provides the operating system interface that should
** be used to access the database file on disk. ^If this option is set to
** an empty string the default VFS object is used. ^Specifying an unknown
** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
** present, then the VFS specified by the option takes precedence over
** the value passed as the fourth parameter to sqlite3_open_v2().
**
** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
** "rwc", or "memory". Attempting to set it to any other value is
** an error)^.
** ^If "ro" is specified, then the database is opened for read-only
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
** third argument to sqlite3_open_v2(). ^If the mode option is set to
** "rw", then the database is opened for read-write (but not create)
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
** been set. ^Value "rwc" is equivalent to setting both
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
** set to "memory" then a pure [in-memory database] that never reads
** or writes from disk is used. ^It is an error to specify a value for
** the mode parameter that is less restrictive than that specified by
** the flags passed in the third parameter to sqlite3_open_v2().
**
** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
** "private". ^Setting it to "shared" is equivalent to setting the
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
** a URI filename, its value overrides any behavior requested by setting
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
**
** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
** [powersafe overwrite] property does or does not apply to the
** storage media on which the database file resides.
**
** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
** which if set disables file locking in rollback journal modes. This
** is useful for accessing a database on a filesystem that does not
** support locking. Caution: Database corruption might result if two
** or more processes write to the same database and any one of those
** processes uses nolock=1.
**
** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
** parameter that indicates that the database file is stored on
** read-only media. ^When immutable is set, SQLite assumes that the
** database file cannot be changed, even by a process with higher
** privilege, and so the database is opened read-only and all locking
** and change detection is disabled. Caution: Setting the immutable
** property on a database file that does in fact change can result
** in incorrect query results and/or [SQLITE_CORRUPT] errors.
** See also: [SQLITE_IOCAP_IMMUTABLE].
**
** </ul>
**
** ^Specifying an unknown parameter in the query component of a URI is not an
** error. Future versions of SQLite might understand additional query
** parameters. See "[query parameters with special meaning to SQLite]" for
** additional information.
**
** [[URI filename examples]] <h3>URI filename examples</h3>
**
** <table border="1" align=center cellpadding=5>
** <tr><th> URI filenames <th> Results
** <tr><td> file:data.db <td>
** Open the file "data.db" in the current directory.
** <tr><td> file:/home/fred/data.db<br>
** file:///home/fred/data.db <br>
** file://localhost/home/fred/data.db <br> <td>
** Open the database file "/home/fred/data.db".
** <tr><td> file://darkstar/home/fred/data.db <td>
** An error. "darkstar" is not a recognized authority.
** <tr><td style="white-space:nowrap">
** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
** <td> Windows only: Open the file "data.db" on fred's desktop on drive
** C:. Note that the %20 escaping in this example is not strictly
** necessary - space characters can be used literally
** in URI filenames.
** <tr><td> file:data.db?mode=ro&cache=private <td>
** Open file "data.db" in the current directory for read-only access.
** Regardless of whether or not shared-cache mode is enabled by
** default, use a private cache.
** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
** that uses dot-files in place of posix advisory locking.
** <tr><td> file:data.db?mode=readonly <td>
** An error. "readonly" is not a valid option for the "mode" parameter.
** </table>
**
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
** query components of a URI. A hexadecimal escape sequence consists of a
** percent sign - "%" - followed by exactly two hexadecimal digits
** specifying an octet value. ^Before the path or query components of a
** URI filename are interpreted, they are encoded using UTF-8 and all
** hexadecimal escape sequences replaced by a single byte containing the
** corresponding octet. If this process generates an invalid UTF-8 encoding,
** the results are undefined.
**
** <b>Note to Windows users:</b> The encoding used for the filename argument
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
** codepage is currently defined. Filenames containing international
** characters must be converted to UTF-8 prior to passing them into
** sqlite3_open() or sqlite3_open_v2().
**
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
** features that require the use of temporary files may fail.
**
** See also: [sqlite3_temp_directory]
124
Number of hidden columns if TABLE is virtual
Next available cursor
comment: LIMIT value. NULL means not used
label: code-design
Index of statement to evaluate
** This is the equivalent of fts5MergePrefixLists() for detail=none mode.
** In this case the buffers consist of a delta-encoded list of rowids only.
SrcList to be returned
Length of the delta
Sorter key to copy into pOut
Reset high-water mark if true
OUT: Changeset iterator handle
Schema that contains this table
# include "sqlite3ext.h"
DISTINCT
comment: Mapping between variable names and numbers
label: code-design
Opcode: DropTable P1 * * P4 *
**
** Remove the internal (in-memory) data structures that describe
** the table named P4 in database P1. This is called after a table
** is dropped from disk (using the Destroy opcode) in order to keep
** the internal representation of the
** schema consistent with what is on disk.
expr ::= expr likeop expr ESCAPE expr
Pointer to input string
if we are not initializing,
** build the sqlite_master entry
Temp file
FTS3 cursor object
String to be tokenized
Function Return Code
** Do a memory allocation with statistics and alarms. Assume the
** lock is already held.
Required file size
If the pParse->declareVtab flag is set, do not delete any table
** structure built up in pParse->pNewTable. The calling code (see vtab.c)
** will take responsibility for freeing the Table structure.
TRIGGER
Callback function to invoke
!SQLITE_OS_WINRT
The unqualified db name
Buffer to load WAL header into
Fts5 index object
** Argument pIdxInfo is already populated with all constraints that may
** be used by the virtual table identified by pBuilder->pNew->iTab. This
** function marks a subset of those constraints usable, invokes the
** xBestIndex method and adds the returned plan to pBuilder.
**
** A constraint is marked usable if:
**
** * Argument mUsable indicates that its prerequisites are available, and
**
** * It is not one of the operators specified in the mExclude mask passed
** as the fourth argument (which in practice is either WO_IN or 0).
**
** Argument mPrereq is a mask of tables that must be scanned before the
** virtual table in question. These are added to the plans prerequisites
** before it is added to pBuilder.
**
** Output parameter *pbIn is set to true if the plan added to pBuilder
** uses one or more WO_IN terms, or false otherwise.
If this is the magic sqlite_sequence table used by autoincrement,
** then record a pointer to this table in the main database structure
** so that INSERT can find the table easily.
This function does notmwork with detail=none databases.
************************************************************************
** Start of highlight() implementation.
50
Current term read from page
ePragTyp:
Copy data from the log to the database file.
Assign a bit from the bitmask to every term in the FROM clause.
**
** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
**
** The rule of the previous sentence ensures thta if X is the bitmask for
** a table T, then X-1 is the bitmask for all other tables to the left of T.
** Knowing the bitmask for all tables to the left of a left join is
** important. Ticket #3015.
**
** Note that bitmasks are created for all pTabList->nSrc tables in
** pTabList, not just the first nTabList tables. nTabList is normally
** equal to pTabList->nSrc but might be shortened to 1 if the
** WHERE_OR_SUBCLAUSE flag is set.
Buffer to gobble string/bareword from
86
P4 is a pointer to a SubProgram structure
VM being reprepared
The P4 operand
Doclist data
xFetch, xUnfetch
** When this function is called, the database file has been completely
** updated to reflect the changes made by the current transaction and
** synced to disk. The journal file still exists in the file-system
** though, and if a failure occurs at this point it will eventually
** be used as a hot-journal and the current transaction rolled back.
**
** This function finalizes the journal file, either by deleting,
** truncating or partially zeroing it, so that it cannot be used
** for hot-journal rollback. Once this is done the transaction is
** irrevocably committed.
**
** If an error occurs, an IO error code is returned and the pager
** moves into the error state. Otherwise, SQLITE_OK is returned.
comment: Takes a fully configured proxy locking-style unix file and switches
** the local lock file path
label: code-design
Name of the container - used for error messages
Resume scanning at this->pWC->a[this->k]
Match "*"
True to reset page prior to first page rollback
** Return a bitmask where 1s indicate that the corresponding column of
** the table is used by an index. Only the first 63 columns are considered.
Node of the TARGET in pParse
** Obtain a snapshot handle for the snapshot of database zDb currently
** being read by handle db.
same as TK_LT, jump, in1, in3
Extra information if (eOperator & WO_OR)!=0
The cursor
aKWCode[i] is the parser symbol code for the i-th keyword
** Recursively delete an expression tree.
If the OS does not have posix_fallocate(), fake it. Write a
** single byte to the last byte in each block that falls entirely
** within the extended region. Then, if required, a single byte
** at offset (nSize-1), to set the size of the file correctly.
** This is a similar technique to that used by glibc on systems
** that do not have a real fallocate() call.
Recently parsed phrase
** Make an shallow copy of pFrom into pTo. Prior contents of
** pTo are freed. The pFrom->z field is not duplicated. If
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
** and flags gets srcType (either MEM_Ephem or MEM_Static).
** Acquire a page if it is already in the in-memory cache. Do
** not read the page from disk. Return a pointer to the page,
** or 0 if the page is not in cache.
**
** See also sqlite3PagerGet(). The difference between this routine
** and sqlite3PagerGet() is that _get() will go to the disk and read
** in the page if the page is not already in cache. This routine
** returns NULL if the page is not in cache or if a disk I/O error
** has ever happened.
** This function is not available on Windows CE or WinRT.
************* Begin file fts3_expr.c **************************************
The btree to set the safety level on
xDestroy
49
**
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
** Otherwise, fts3EvalPhraseStart() is called on all phrases within the
** expression. Also the Fts3Expr.bDeferred variable is set to true for any
** expressions for which all descendent tokens are deferred.
**
** If parameter bOptOk is zero, then it is guaranteed that the
** Fts3Phrase.doclist.aAll/nAll variables contain the entire doclist for
** each phrase in the expression (subject to deferred token processing).
** Or, if bOptOk is non-zero, then one or more tokens within the expression
** may be loaded incrementally, meaning doclist.aAll/nAll is not available.
**
** If an error occurs within this function, *pRc is set to an SQLite error
** code before returning.
PRAGMA main.index_xinfo = $zIdx
Read (and consume) the next character from the input pattern.
Buffer of at least nBuf bytes
** Retrieve information about the current candidate snippet of snippet
** iterator pIter.
Information about AUTOINCREMENT counters
String or BLOB value
Variables above this point are populated when the expression is
** parsed (by code in fts3_expr.c). Below this point the variables are
** used when evaluating the expression.
Current index
comment:
** NOTE: Windows CE is handled differently here due its lack of the Win32
** API LockFileEx.
label: test
** pCur points at an index entry created using the OP_MakeRecord opcode.
** Read the rowid (the last field in the record) and store it in *rowid.
** Return SQLITE_OK if everything works, or an error code otherwise.
**
** pCur might be pointing to text obtained from a corrupt database file.
** So the content cannot be trusted. Do appropriate checks on the content.
** Size of struct Mem not including the Mem.zMalloc member or anything that
** follows.
Size of column in tokens
** Assuming the current table columns are "a", "b" and "c", and the zObj
** paramter is passed "old", return a string of the form:
**
** "old.a, old.b, old.b"
**
** With the column names escaped.
**
** For tables with implicit rowids - RBU_PK_EXTERNAL and RBU_PK_NONE, append
** the text ", old._rowid_" to the returned value.
No-op
Database in which to run SQL
The LIMIT expression. NULL if there is no limit
The final Fts3Expr data structure, including the Fts3Phrase,
** Fts3PhraseToken structures token buffers are all stored as a single
** allocation so that the expression can be freed with a single call to
** sqlite3_free(). Setting this up requires a two pass approach.
**
** The first pass, in the block below, uses a tokenizer cursor to iterate
** through the tokens in the expression. This pass uses fts3ReallocOrFree()
** to assemble data in two dynamic buffers:
**
** Buffer p: Points to the Fts3Expr structure, followed by the Fts3Phrase
** structure, followed by the array of Fts3PhraseToken
** structures. This pass only populates the Fts3PhraseToken array.
**
** Buffer zTemp: Contains copies of all tokens.
**
** The second pass, in the block that begins "if( rc==SQLITE_DONE )" below,
** appends buffer zTemp to buffer p, and fills in the Fts3Expr and Fts3Phrase
** structures.
Array of tables to search
synopsis: r[P2@P3]=r[P1@P3]
Locking style specific state
Left-hand Fts5SegIter
** On some systems, calls to fchown() will trigger a message in a security
** log if they come from non-root processes. So avoid calling fchown() if
** we are not running as root.
True if the subquery uses aggregate functions
DEFERRABLE
Invoke the token callback
Bytes of temp space
If this is a non-covering index scan, add in the cost of
** doing table lookups. The cost will be 3x the number of
** lookups. Take into account WHERE clause terms that can be
** satisfied using just the index, and that do not require a
** table lookup.
RBU handle
If the opcode is TK_TRIGGER, then the expression is a reference
** to a column in the new.* or old.* pseudo-tables available to
** trigger programs. In this case Expr.iTable is set to 1 for the
** new.* pseudo-table, or 0 for the old.* pseudo-table. Expr.iColumn
** is set to the column of the pseudo-table to read, or to -1 to
** read the rowid field.
(311) nmnum ::= ON
If pNew is still NULL, try to create an entirely new mapping.
Normal (non-error) return.
267
Display all terms of the WHERE clause
CURTYPE_BTREE. Btree cursor
Halt the sub-program. Return control to the parent frame.
If STRERROR_R_CHAR_P (set by autoconf scripts) or __USE_GNU is defined,
** assume that the system provides the GNU version of strerror_r() that
** returns a pointer to a buffer containing the error message. That pointer
** may point to aErr[], or it may point to some static storage somewhere.
** Otherwise, assume that the system provides the POSIX version of
** strerror_r(), which always writes an error message into aErr[].
**
** If the code incorrectly assumes that it is the POSIX version that is
** available, the error message will often be an empty string. Not a
** huge problem. Incorrectly concluding that the GNU version is available
** could lead to a segfault though.
same as TK_REM, in1, in2, out3
Make sure the sort order is compatible in an ORDER BY clause.
** Sort order is irrelevant for a GROUP BY clause.
comment:
** A phrase. One or more terms that must appear in a contiguous sequence
** within a document for it to match.
label: documentation
Rtree node cache
Tokenizer cursor open on zDoc/nDoc
For use by application VFS
Usually the path zFilename should not be a relative pathname. The
** exception is when opening the proxy "conch" file in builds that
** include the special Apple locking styles.
Pointer to one journal within MJ file
cmd ::= select
************* Include os_setup.h in the middle of os.h ********************
Index of constraint to use
Query for existance of table only
68..6f hijklmno
** Provide a default value for SQLITE_TEMP_STORE in case it is not specified
** on the command-line
120
rand_s() is not available with MinGW
Fifth parameter is an unsigned 16-bit integer
Instruction number of OP_Function
comment:
** A list of expressions. Each expression may optionally have a
** name. An expr/name combination can be used in several ways, such
** as the list of "expr AS ID" fields following a "SELECT" or in the
** list of "ID = expr" items in an UPDATE. A list of expressions can
** also be used as the argument to a function, in which case the a.zName
** field is not used.
**
** By default the Expr.zSpan field holds a human-readable description of
** the expression that is used in the generation of error messages and
** column labels. In this case, Expr.zSpan is typically the text of a
** column expression as it exists in a SELECT statement. However, if
** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
** of the result column in the form: DATABASE.TABLE.COLUMN. This later
** form is used for name resolution with nested FROM clauses.
label: code-design
End of file
Commit by truncating journal
Associated FTS5 index
Content size or sub-node count
IMP: R-03371-37637
Convert the connection into a zombie and then close it.
** This lookup table is used to help decode the first byte of
** a multi-byte UTF8 character.
Number of arguments in subprograms
Size of subclassed sqlite3_file
Handle for accessing the blob returned here
Usable size of the page
Source database handle
OUT: Number of bytes in token
for() loop iterator variable
sqlite3.aDb[] index of db to checkpoint
True for patchset, false for changeset
comment:
** The packing computed by the previous block is biased toward the siblings
** on the left side (siblings with smaller keys). The left siblings are
** always nearly full, while the right-most sibling might be nearly empty.
** The next block of code attempts to adjust the packing of siblings to
** get a better balance.
**
** This adjustment is more than an optimization. The packing above might
** be so out of balance as to be illegal. For example, the right-most
** sibling might be completely empty. This adjustment is not optional.
label: code-design
Thread context used to create new PMA
Non-zero if connection is in exclusive mode
** Argument aCol points to an array of integers containing one entry for
** each table column. This function reads the %_docsize record for the
** specified rowid and populates aCol[] with the results.
**
** An SQLite error code is returned if an error occurs, or SQLITE_OK
** otherwise.
Input "x" is a sequence of unsigned characters that represent a
** big-endian integer. Return the equivalent native integer
IN/OUT: Right-hand buffer pointer
** json_remove(JSON, PATH, ...)
**
** Remove the named elements from JSON and return the result. malformed
** JSON or PATH arguments result in an error.
** The first time the bm25() function is called for a query, an instance
** of the following structure is allocated and populated.
First argument to pass to xTableFilter
Verify that constants are precomputed correctly
** Take an EXCLUSIVE lock on the database file.
Current entry in aRowidOffset[]
pPage
** CAPI3REF: Checkpoint a database
** METHOD: sqlite3
**
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
**
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
** [write-ahead log] for database X on [database connection] D to be
** transferred into the database file and for the write-ahead log to
** be reset. See the [checkpointing] documentation for addition
** information.
**
** This interface used to be the only way to cause a checkpoint to
** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
** interface was added. This interface is retained for backwards
** compatibility and as a convenience for applications that need to manually
** start a callback but which do not need the full power (and corresponding
** complication) of [sqlite3_wal_checkpoint_v2()].
Mask of NEW.* columns accessed by BEFORE triggers
Write error message here
If the number of pages in the database is not available from the
** WAL sub-system, determine the page count based on the size of
** the database file. If the size of the database file is not an
** integer multiple of the page-size, round up the result.
pPager->stmtJSize = 0;
Also frees aRegIdx[] and aToOpen[]
Values between 16384 and 2097151
Always the first entry
comment: Calculate the IDF (Inverse Document Frequency) for phrase i.
** This is done using the standard BM25 formula as found on wikipedia:
**
** IDF = log( (N - nHit + 0.5) / (nHit + 0.5) )
**
** where "N" is the total number of documents in the set and nHit
** is the number that contain at least one instance of the phrase
** under consideration.
**
** The problem with this is that if (N < 2*nHit), the IDF is
** negative. Which is undesirable. So the mimimum allowable IDF is
** (1e-6) - roughly the same as a term that appears in just over
** half of set of 5,000,000 documents.
label: documentation
comment: If malloc() failed during an encoding conversion within an
** sqlite3_column_XXX API, then set the return code of the statement to
** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
** and _finalize() will return NOMEM.
label: code-design
133
Descend to the child node of the cell that the cursor currently
** points at. This is the right-child if (iIdx==pPage->nCell).
2
A table in the schema
Array of unquoted target column names
Create the imposter table used to write to this index.
NOTREACHED
Add this WhereLoop to the end of pPath->aLoop[]
Prefix query
Take data to be written from here
EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36
** stores stores the total number of pages on the freelist.
Bitmask of schema verified databases
The tokenizer always gives us a token
Obtain a reference to the root node to initialize Rtree.iDepth
Skip backwards past any 0x00 varints.
In this mode, write each query result to the key of the temporary
** table iParm.
Index of old.* value to retrieve
Special case: No FROM clause
Write the sorted results here
Increment the reference count of an existing page
limit_opt ::= LIMIT expr
0x08
The complex case - There is a multi-file write-transaction active.
** This requires a master journal file to ensure the transaction is
** committed atomically.
Statements to read/write/delete a record from xxx_rowid
if HAVE_ISNAN
Size of the original file in pages
Rowid components
** Allocate and zero memory.
Flags to send to sqlite3PagerGet()
************* Begin file vtab.c *******************************************
** Return the index in pList of the identifier named zId. Return -1
** if not found.
If a SHARED lock is requested, and some thread using this PID already
** has a SHARED or RESERVED lock, then increment reference counts and
** return SQLITE_OK.
VERIFY: F13021
SQLITE_OS_WINRT
"*" or "%"
** Argument pIn points to a character that is part of a nul-terminated
** string. Return a pointer to the first character following *pIn in
** the string that is not a "bareword" character.
** pArray is a pointer to an array of objects. Each object in the
** array is szEntry bytes in size. This routine uses sqlite3DbRealloc()
** to extend the array so that there is space for a new object at the end.
**
** When this function is called, *pnEntry contains the current size of
** the array (in entries - so the allocation is ((*pnEntry) * szEntry) bytes
** in total).
**
** If the realloc() is successful (i.e. if no OOM condition occurs), the
** space allocated for the new object is zeroed, *pnEntry updated to
** reflect the new size of the array and a pointer to the new allocation
** returned. *pIdx is set to the index of the new array entry in this case.
**
** Otherwise, if the realloc() fails, *pIdx is set to -1, *pnEntry remains
** unchanged and a copy of pArray returned.
** Set the buffer to contain nData/pData. If an OOM error occurs, leave an
** the error code in p. If an error has already occurred when this function
** is called, it is a no-op.
Number of pages in the LRU list
** We do not trust systems to provide a working fdatasync(). Some do.
** Others do no. To be safe, we will stick with the (slightly slower)
** fsync(). If you know that your system does support fdatasync() correctly,
** then simply compile with -Dfdatasync=fdatasync or -DHAVE_FDATASYNC
The first column is in this register
** Reset an StrAccum string. Reclaim all malloced memory.
Value extracted from pUpper
same as TK_LT, synopsis: IF r[P3]<r[P1]
** Pragma virtual table module xConnect method.
Single step in trigger program
1380
comment: Suppress a harmless compiler warning
label: code-design
Jump here to break out of the inner loop
Append the rowid to the output
Common case: early out without every having to acquire a mutex
** Close the cursor. For additional information see the documentation
** on the xClose method of the virtual table interface.
Check if it is an FTS4 special argument.
Size of pHeap[]
EVIDENCE-OF: R-22564-11647 The header begins with a single varint
** which determines the total number of bytes in the header. The varint
** value is the size of the header in bytes including the size varint
** itself.
Mask of public flags
Seconds
211
comment:
** The argument to this macro must be of type u32. On a little-endian
** architecture, it returns the u32 value that results from interpreting
** the 4 bytes as a big-endian value. On a big-endian architecture, it
** returns the value that would be produced by interpreting the 4 bytes
** of the input value as a little-endian integer.
label: code-design
Expr struct EXPR_REDUCEDSIZE bytes only
194
comment: TODO: It would be better to have some system for reusing statement
** handles here, rather than preparing a new one for each query. But that
** is not possible as SQLite reference counts the virtual table objects.
** And since the statement required here reads from this very virtual
** table, saving it creates a circular reference.
**
** If SQLite a built-in statement cache, this wouldn't be a problem.
label: code-design
If the auto-commit flag is set and this is the only active writer
** VM, then we do either a commit or rollback of the current transaction.
**
** Note: This block also runs if one of the special errors handled
** above has occurred.
No checkpoint on close()/DETACH
b &= (0x7f<<28)|(0x7f<<14)|(0x7f);
comment: Unused arg for sqlite3WhereOkOnePass()
label: code-design
Node chain of patch for JNODE_PATCH
likeop ::= NOT LIKE_KW|MATCH
What operation to perform
** Close the RBU handle.
Register holding counter
************* End of wal.h ************************************************
(309) nmnum ::= plus_num (OPTIMIZED OUT)
Which entry in the FROM clause
values ::= values COMMA LP exprlist RP
Result code from subfunctions
__APPLE__ or not __APPLE__
true to ignore case differences
search key and new file ID
Check to see if pExpr is a duplicate of another aggregate
** function that is already in the pAggInfo structure
Ensure both child nodes have node numbers assigned to them by calling
** nodeWrite(). Node pRight always needs a node number, as it was created
** by nodeNew() above. But node pLeft sometimes already has a node number.
** In this case avoid the all to nodeWrite().
** Read and decode the "averages" record from the database.
**
** Parameter anSize must point to an array of size nCol, where nCol is
** the number of user defined columns in the FTS table.
Number of bytes in buffer aFrame[]
Size of aTask[] array
** Compute a string that describes the P4 parameter for an opcode.
** Use zTemp for any required temporary buffer space.
The user-supplied minor token value. This
** is the value of the token
** Advance the iterator passed as the only argument.
Smallest possible allocation in bytes
comment: The following could be done by calling fts5SegIterLoadNPos(). But
** this block is particularly performance critical, so equivalent
** code is inlined.
**
** Later: Switched back to fts5SegIterLoadNPos() because it supports
** detail=none mode. Not ideal.
label: code-design
Name of that semaphore
EVIDENCE-OF: R-56861-42673 sqlite3_prepare_v3() differs from
** sqlite3_prepare_v2() only in having the extra prepFlags parameter,
** which is a bit array consisting of zero or more of the
** SQLITE_PREPARE_* flags.
**
** Proof by comparison to the implementation of sqlite3_prepare_v2()
** directly above.
Jump out of the pTerm loop
Search for an existing statement. If one is found, shift it to the front
** of the LRU queue and return immediately. Otherwise, leave nUp pointing
** to the number of statements currently in the cache and pUp to the
** last object in the list.
************* Begin file fts3_aux.c ***************************************
Right and left size of LIKE operator
Condition 4
DELETE, or UPDATE and return
For a BITVEC_SZ of 512, this would be 34,359,739.
Figure out the total size of the current row in tokens.
1 value
The MEM_Cleared bit is only allowed on NULLs
pIter now points at the 64-bit integer key value, a variable length
** integer. The following block moves pIter to point at the first byte
** past the end of the key value.
** Allocate memory, either lookaside (if possible) or heap.
** If the allocation fails, set the mallocFailed flag in
** the connection pointer.
**
** If db!=0 and db->mallocFailed is true (indicating a prior malloc
** failure on the same database connection) then always return 0.
** Hence for a particular database connection, once malloc starts
** failing, it fails consistently until mallocFailed is reset.
** This is an important assumption. There are many places in the
** code that do things like this:
**
** int *a = (int*)sqlite3DbMallocRaw(db, 100);
** int *b = (int*)sqlite3DbMallocRaw(db, 200);
** if( b ) a[10] = 9;
**
** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
** that all prior mallocs (ex: "a") worked too.
**
** The sqlite3MallocRawNN() variant guarantees that the "db" parameter is
** not a NULL pointer.
Which level of the tree we are on
(296) conslist_opt ::= COMMA conslist
************* Begin file global.c *****************************************
Read the page-size and sector-size journal header fields.
Read the nKeep field of the next term.
Pager page handle
Saved value of db->nChange
The blocking transaction has been concluded. Or there never was a
** blocking transaction. In either case, invoke the notify callback
** immediately.
read only FS/ lockless
** Allocate a new MergeEngine object capable of handling up to
** nReader PmaReader inputs.
**
** nReader is automatically rounded up to the next power of two.
** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up.
Jump here to continue with next cycle
** Rtree virtual table module xOpen method.
** The sizes for serial types less than 128
pDone always used on sub-journals
Last freeblock extends past page end
PREFIX
** Compare the key of the index entry that cursor pC is pointing to against
** the key string in pUnpacked. Write into *pRes a number
** that is negative, zero, or positive if pC is less than, equal to,
** or greater than pUnpacked. Return SQLITE_OK on success.
**
** pUnpacked is either created without a rowid or is truncated so that it
** omits the rowid at the end. The rowid at the end of the index entry
** is ignored as well. Hence, this routine only compares the prefixes
** of the keys prior to the final rowid, not the entire key.
New binary node to insert into expression tree
** Ensure that the sub-journal file is open. If it is already open, this
** function is a no-op.
**
** SQLITE_OK is returned if everything goes according to plan. An
** SQLITE_IOERR_XXX error code is returned if a call to sqlite3OsOpen()
** fails.
IN/OUT: Pointer to poslist
If (res==0) is true, then pRec must be equal to sample i.
Jump here for next cycle
Context pointer for xChunk callback
comment:
** Set bit pgno of the BtShared.pHasContent bitvec. This is called
** when a page that previously contained data becomes a free-list leaf
** page.
**
** The BtShared.pHasContent bitvec exists to work around an obscure
** bug caused by the interaction of two useful IO optimizations surrounding
** free-list leaf pages:
**
** 1) When all data is deleted from a page and the page becomes
** a free-list leaf page, the page is not written to the database
** (as free-list leaf pages contain no meaningful data). Sometimes
** such a page is not even journalled (as it will not be modified,
** why bother journalling it?).
**
** 2) When a free-list leaf page is reused, its content is not read
** from the database or written to the journal file (why should it
** be, if it is not at all meaningful?).
**
** By themselves, these optimizations work fine and provide a handy
** performance boost to bulk delete or insert operations. However, if
** a page is moved to the free-list and then reused within the same
** transaction, a problem comes up. If the page is not journalled when
** it is moved to the free-list and it is also not journalled when it
** is extracted from the free-list and reused, then the original data
** may be lost. In the event of a rollback, it may not be possible
** to restore the database to its original configuration.
**
** The solution is the BtShared.pHasContent bitvec. Whenever a page is
** moved to become a free-list leaf page, the corresponding bit is
** set in the bitvec. Whenever a leaf page is extracted from the free-list,
** optimization 2 above is omitted if the corresponding bit is already
** set in BtShared.pHasContent. The contents of the bitvec are cleared
** at the end of every transaction.
label: code-design
** 2007 October 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The SQLite user supplies a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
comment: Next unused slot in aEquiv[]
label: code-design
Locate the index named by the INDEXED BY clause, if any.
Top of the co-routine
comment:
** This function returns the collation sequence for database native text
** encoding identified by the string zName, length nName.
**
** If the requested collation sequence is not available, or not available
** in the database native encoding, the collation factory is invoked to
** request it. If the collation factory does not supply such a sequence,
** and the sequence is available in another text encoding, then that is
** returned instead.
**
** If no versions of the requested collations sequence are available, or
** another error occurs, NULL is returned and an error message written into
** pParse.
**
** This routine is a wrapper around sqlite3FindCollSeq(). This routine
** invokes the collation factory if the named collation cannot be found
** and generates an error message.
**
** See also: sqlite3FindCollSeq(), sqlite3GetCollSeq()
label: code-design
The PRIMARY KEY index
First time through the loop
SQLITE_OS_WINCE
** Add N to the value of a status record. The caller must hold the
** appropriate mutex. (Locking is checked by assert()).
**
** The StatusUp() routine can accept positive or negative values for N.
** The value of N is added to the current status value and the high-water
** mark is adjusted if necessary.
**
** The StatusDown() routine lowers the current value by N. The highwater
** mark is unchanged. N must be non-negative for StatusDown().
7
Loop over tables of a schema
comment:
** Return a nul-terminated string consisting of nByte comma separated
** "?" expressions. For example, if nByte is 3, return a pointer to
** a buffer containing the string "?,?,?".
**
** The memory for the returned string is obtained from sqlite3_malloc().
** It is the responsibility of the caller to eventually free it using
** sqlite3_free().
**
** If an OOM error is encountered when allocating space for the new
** string, an error code is left in the rbu handle passed as the first
** argument and NULL is returned. Or, if an error has already occurred
** when this function is called, NULL is returned immediately, without
** attempting the allocation or modifying the stored error code.
label: code-design
SQLITE_AFF_INTEGER
The "NEAR" node (FTS5_TERM)
Undo the local locks
** Allowed values for RowSet.rsFlags
** Make sure all writes to a particular file are committed to disk.
**
** If dataOnly==0 then both the file itself and its metadata (file
** size, access time, etc) are synced. If dataOnly!=0 then only the
** file data is synced.
**
** Under Unix, also make sure that the directory entry for the file
** has been created by fsync-ing the directory that contains the file.
** If we do not do this and we encounter a power failure, the directory
** entry for the journal might not exist after we reboot. The next
** SQLite to access the file will not know that the journal exists (because
** the directory entry for the journal was never created) and the transaction
** will not roll back - possibly leading to database corruption.
** If LcsIterator.iCol is set to the following value, the iterator has
** finished iterating through all offsets for all columns.
Force an SQLITE_TOOBIG error.
** Mark the VDBE as one that can only be run one time.
SQLITE_STATUS_MALLOC_SIZE
If this is an EXPLAIN, skip this step
Number of key fields in each record
** Context pointer passed down through the tree-walk.
Text to tokenize
An SQLITE_NOMEM error.
True if resolving names in a CHECK constraint
Shared memory segment used for locking
Fts5 Backend to iterate within
OUT: Prepared SELECT statement
If no error has occurred, return the calculated score. Otherwise,
** throw an SQL exception.
FAIL => ID
************* Begin file sqliteInt.h **************************************
File descriptor for database
************* Begin file pager.h ******************************************
** An SQL user-function registered to do the work of an ATTACH statement. The
** three arguments to the function come directly from an attach statement:
**
** ATTACH DATABASE x AS y KEY z
**
** SELECT sqlite_attach(x, y, z)
**
** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
** third argument.
Space for pStep->zTarget
When doing a nested parse, one can include terms in an expression
** that look like this: #1 #2 ... These terms refer to registers
** in the virtual machine. #N is the N-th register.
getenv("USERPROFILE")
** Add WhereLoop entries to handle OR terms. This works for either
** btrees or virtual tables.
** Structure for changeset iterators.
Number of columns in table zName
0x15
Changes whenever database file changes
Size of argument array
sz value
Number of bytes available on the local btree page
End of the PRAGMA switch
Call lockBtree() until either pBt->pPage1 is populated or
** lockBtree() returns something other than SQLITE_OK. lockBtree()
** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
** reading page 1 it discovers that the page-size of the database
** file is not pBt->pageSize. In this case lockBtree() will update
** pBt->pageSize to the page-size of the file on disk.
** Close a VDBE cursor and release all the resources that cursor
** happens to hold.
Flags to pass to OsSync() (or 0)
UTF-8 -> UTF-16 Big-endian
************* Begin file os_common.h **************************************
If the sub-journal was opened successfully (or was already open),
** write the journal record into the file.
Unlock notify callback
Last position from pp1
xCreate
Fake SrcList for pParse->pNewTable
Transaction state
** The argument is an IN operator with a list (not a subquery) on the
** right-hand side. Return TRUE if that list is constant.
************* End of tokenize.c *******************************************
Conditional skipped
Pretend we already have a lock
P4 is a pointer to a transient string
ONEPASS is ok with multiple rows
Ephemeral table used for DISTINCT processing
In theory, it is only necessary to write the 28 bytes that the
** journal header consumes to the journal file here. Then increment the
** Pager.journalOff variable by JOURNAL_HDR_SZ so that the next
** record is written to the following sector (leaving a gap in the file
** that will be implicitly filled in by the OS).
**
** However it has been discovered that on some systems this pattern can
** be significantly slower than contiguously writing data to the file,
** even if that means explicitly writing data to the block of
** (JOURNAL_HDR_SZ - 28) bytes that will not be used. So that is what
** is done.
**
** The loop is required here in case the sector-size is larger than the
** database page size. Since the zHeader buffer is only Pager.pageSize
** bytes in size, more than one call to sqlite3OsWrite() may be required
** to populate the entire journal header sector.
This routine is only called from b-tree and only when there are no
** outstanding pages. This implies that the pager state should either
** be OPEN or READER. READER is only possible if the pager is or was in
** exclusive access mode.
Find the first two PmaReaders to compare. The one that was just
** advanced (iPrev) and the one next to it in the array.
comment:
** Indicate that all subsequent calls to sqlite3Fts5IndexWrite() pertain
** to the document with rowid iRowid.
label: documentation
Pointer to database schema (possibly shared)
** Return the size of the database file in pages. If there is any kind of
** error, return ((unsigned int)-1).
Step 2: If the page was found in the hash table, then return it.
** If the page was not in the hash table and createFlag is 0, abort.
** Otherwise (page not in hash and createFlag!=0) continue with
** subsequent steps to try to create the page.
Load the entire master journal file into space obtained from
** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain
** sufficient space (in zMasterPtr) to hold the names of master
** journal files extracted from regular rollback-journals.
Corruption
** Commute a comparison operator. Expressions of the form "X op Y"
** are converted into "Y op X".
**
** If left/right precedence rules come into play when determining the
** collating sequence, then COLLATE operators are adjusted to ensure
** that the collating sequence does not change. For example:
** "Y collate NOCASE op X" becomes "X op Y" because any collation sequence on
** the left hand side of a comparison overrides any collation sequence
** attached to the right. For the same reason the EP_Collate flag
** is not commuted.
SQLITE_ENABLE_COLUMN_USED_MASK
zFilename
** Write meta-information back into the database. Meta[0] is
** read-only and may not be written.
** This structure is a subclass of sqlite3_file. Each open memory-journal
** is an instance of this class.
ADD
Value to return
Access to the winShmNode object is serialized by the caller
Names of table columns
** Check to see if the pThis entry of pTabList is a self-join of a prior view.
** If it is, then return the SrcList_item for the prior view. If it is not,
** then return 0.
New value for pMem->n
Skip indices that do not change
True if "-" flag is present
** Compute the Hour, Minute, and Seconds from the julian day number.
Functions used only by user authorization logic
Auth callback return code
** CAPI3REF: Determine If An SQL Statement Is Complete
**
** These routines are useful during command-line input to determine if the
** currently entered text seems to form a complete SQL statement or
** if additional input is needed before sending the text into
** SQLite for parsing. ^These routines return 1 if the input string
** appears to be a complete SQL statement. ^A statement is judged to be
** complete if it ends with a semicolon token and is not a prefix of a
** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
** string literals or quoted identifier names or comments are not
** independent tokens (they are part of the token in which they are
** embedded) and thus do not count as a statement terminator. ^Whitespace
** and comments that follow the final semicolon are ignored.
**
** ^These routines return 0 if the statement is incomplete. ^If a
** memory allocation fails, then SQLITE_NOMEM is returned.
**
** ^These routines do not parse the SQL statements thus
** will not detect syntactically incorrect SQL.
**
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
** automatically by sqlite3_complete16(). If that initialization fails,
** then the return value from sqlite3_complete16() will be non-zero
** regardless of whether or not the input SQL is complete.)^
**
** The input to [sqlite3_complete()] must be a zero-terminated
** UTF-8 string.
**
** The input to [sqlite3_complete16()] must be a zero-terminated
** UTF-16 string in native byte order.
Initial value of write-counter
Malloc failed while inserting the new entry. This can only
** happen if there was no previous entry for this token.
Extra information associated with the page
All the rest are undocumented and are for internal use only
comment: Clean up the WHERE clause constructed above.
label: code-design
Floating point sum
The following structure represents a single element of the
** parser's stack. Information stored includes:
**
** + The state number for the parser at this level of the stack.
**
** + The value of the token stored at this level of the stack.
** (In other words, the "major" token.)
**
** + The semantic value stored at this level of the stack. This is
** the information used by the action routines in the grammar.
** It is sometimes called the "minor" token.
**
** After the "shift" half of a SHIFTREDUCE action, the stateno field
** actually contains the reduce action for the second half of the
** SHIFTREDUCE.
************* Include pragma.h in the middle of pragma.c ******************
If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op. But go ahead and call fstat() to validate the file
** descriptor as we need a method to provoke a failure during
** coverate testing.
Set default values
ccons ::= DEFAULT MINUS term
If foreign-key support is enabled, rewrite the CREATE TABLE
** statements corresponding to all child tables of foreign key constraints
** for which the renamed table is the parent table.
(1)
Mask of src visited by (..)
SQLITE_MISUSE
Make sure all objects are contained in this database
One of SHARED_LOCK, RESERVED_LOCK etc.
unsigned int szPma
Opcode: VUpdate P1 P2 P3 P4 P5
** Synopsis: data=r[P3@P2]
**
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
** This opcode invokes the corresponding xUpdate method. P2 values
** are contiguous memory cells starting at P3 to pass to the xUpdate
** invocation. The value in register (P3+P2-1) corresponds to the
** p2th element of the argv array passed to xUpdate.
**
** The xUpdate method will do a DELETE or an INSERT or both.
** The argv[0] element (which corresponds to memory cell P3)
** is the rowid of a row to delete. If argv[0] is NULL then no
** deletion occurs. The argv[1] element is the rowid of the new
** row. This can be NULL to have the virtual table select the new
** rowid for itself. The subsequent elements in the array are
** the values of columns in the new row.
**
** If P2==1 then no insert is performed. argv[0] is the rowid of
** a row to delete.
**
** P1 is a boolean flag. If it is set to true and the xUpdate call
** is successful, then the value returned by sqlite3_last_insert_rowid()
** is set to the value of the rowid for the row just inserted.
**
** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
** apply in the case of a constraint failure on an insert or update.
Output leaf pages left to write
Check if the main database is a zipvfs db. If it is, set the upper
** level pager to use "journal_mode=off". This prevents it from
** generating a large journal using a temp file.
The beginning and end of the LRU list
Number of key columns in the index
This function should only be called on a sharable b-tree after it
** has been determined that no other b-tree holds a conflicting lock.
** Convert the N-th element of pStmt->pColName[] into a string using
** xFunc() then return that string. If N is out of range, return 0.
**
** There are up to 5 names for each column. useType determines which
** name is returned. Here are the names:
**
** 0 The column name as it should be displayed for output
** 1 The datatype name for the column
** 2 The name of the database that the column derives from
** 3 The name of the table that the column derives from
** 4 The name of the table column that the result column derives from
**
** If the result is not a simple column reference (if it is an expression
** or a constant) then useTypes 2, 3, and 4 return NULL.
** Rollback the transaction in progress.
**
** If tripCode is not SQLITE_OK then cursors will be invalidated (tripped).
** Only write cursors are tripped if writeOnly is true but all cursors are
** tripped if writeOnly is false. Any attempt to use
** a tripped cursor will result in an error.
**
** This will release the write lock on the database file. If there
** are no active cursors, it also releases the read lock.
** All of the code in this file may be omitted by defining a single
** macro.
Size of IndexSample.anEq[] and so on
If the iterator is already at the end of the changeset, return DONE.
** Use sqlite3OsFileControl() when we are doing something that might fail
** and we need to know about the failures. Use sqlite3OsFileControlHint()
** when simply tossing information over the wall to the VFS and we do not
** really care if the VFS receives and understands the information since it
** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
** routine has no return value since the return value would be meaningless.
Opcode: Column P1 P2 P3 P4 P5
** Synopsis: r[P3]=PX
**
** Interpret the data that cursor P1 points to as a structure built using
** the MakeRecord instruction. (See the MakeRecord opcode for additional
** information about the format of the data.) Extract the P2-th column
** from this record. If there are less that (P2+1)
** values in the record, extract a NULL.
**
** The value extracted is stored in register P3.
**
** If the record contains fewer than P2 fields, then extract a NULL. Or,
** if the P4 argument is a P4_MEM use the value of the P4 argument as
** the result.
**
** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
** then the cache of the cursor is reset prior to extracting the column.
** The first OP_Column against a pseudo-table after the value of the content
** register has changed should have this bit set.
**
** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
** the result is guaranteed to only be used as the argument of a length()
** or typeof() function, respectively. The loading of large blobs can be
** skipped for length() and all content loading can be skipped for typeof().
** This function is used to help parse position-lists. When this function is
** called, *pp may point to the start of the next varint in the position-list
** being parsed, or it may point to 1 byte past the end of the position-list
** (in which case **pp will be a terminator bytes POS_END (0) or
** (1)).
**
** If *pp points past the end of the current position-list, set *pi to
** POSITION_LIST_END and return. Otherwise, read the next varint from *pp,
** increment the current value of *pi by the value read, and set *pp to
** point to the next value before returning.
**
** Before calling this routine *pi must be initialized to the value of
** the previous position, or zero if we are reading the first position
** in the position-list. Because positions are delta-encoded, the value
** of the previous position is needed in order to compute the value of
** the next position.
** Implementation of FTS3 xRename method. Rename an fts3 table.
First byte past the iStart buffer
worring about sub-dividing and re-hashing.
EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit
** floating point number.
Table to open
Last possible cell index
** This routine checks that the sqlite3.nVdbeActive count variable
** matches the number of vdbe's in the list sqlite3.pVdbe that are
** currently active. An assertion fails if the two counts do not match.
** This is an internal self-check only - it is not an essential processing
** step.
**
** This is a no-op if NDEBUG is defined.
70..77 pqrstuvw
(328) anylist ::= anylist ANY
Root frame of VDBE
Compound SELECTs that have an ORDER BY clause are handled separately.
The IdxRowid and Seek opcodes are combined because of the commonality
** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid().
Suffix length
#define WAL_HDRSIZE 24
Like RESTART but also truncate WAL
comment:
** Clean up a VDBE after execution but do not delete the VDBE just yet.
** Write any error messages into *pzErrMsg. Return the result code.
**
** After this routine is run, the VDBE should be ready to be executed
** again.
**
** To look at it another way, this routine resets the state of the
** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
** VDBE_MAGIC_INIT.
label: code-design
** PRAGMA data_store_directory
** PRAGMA data_store_directory = ""|"directory_name"
**
** Return or set the local value of the data_store_directory flag. Changing
** the value sets a specific directory to be used for database files that
** were specified with a relative pathname. Setting to a null string reverts
** to the default database directory, which for database files specified with
** a relative path will probably be based on the current directory for the
** process. Database file specified with an absolute path are not impacted
** by this setting, regardless of its value.
**
If sqlite3_prepare returns a tail pointer, we calculate the
** equivalent pointer into the UTF-16 string by counting the unicode
** characters between zSql8 and zTail8, and then returning a pointer
** the same number of characters into the UTF-16 string.
If the cache contains a page with page-number pgno, remove it
** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
** page pgno before the 'move' operation, it needs to be retained
** for the page moved there.
** Generate code for the trigger program associated with trigger p on
** table pTab. The reg, orconf and ignoreJump parameters passed to this
** function are the same as those described in the header function for
** sqlite3CodeRowTrigger()
comment:
** Pointers to the end of sqlite3GlobalConfig.pScratch memory
** (so that a range test can be used to determine if an allocation
** being freed came from pScratch) and a pointer to the list of
** unused scratch allocations.
label: code-design
74
The last field of the index should be an integer - the ROWID.
** Verify that the last entry really is an integer.
Best score of columns checked so far
comment: Database connection for malloc errors
label: code-design
** Swap two objects of type TYPE.
** Write the nRec Field - the number of page records that follow this
** journal header. Normally, zero is written to this value at this time.
** After the records are added to the journal (and the journal synced,
** if in full-sync mode), the zero is overwritten with the true number
** of records (see syncJournal()).
**
** A faster alternative is to write 0xFFFFFFFF to the nRec field. When
** reading the journal this value tells SQLite to assume that the
** rest of the journal file contains valid page records. This assumption
** is dangerous, as if a failure occurred whilst writing to the journal
** file it may contain some garbage data. There are two scenarios
** where this risk can be ignored:
**
** * When the pager is in no-sync mode. Corruption can follow a
** power failure in this case anyway.
**
** * When the SQLITE_IOCAP_SAFE_APPEND flag is set. This guarantees
** that garbage data is never appended to the journal file.
Determine whether we should code this trigger
This both clears the schemas and reduces the size of the db->aDb[]
** array.
** Return a copy of index structure pStruct. Except, promote as many
** segments as possible to level iPromote. If an OOM occurs, NULL is
** returned.
** CAPI3REF: Database Snapshot
** KEYWORDS: {snapshot} {sqlite3_snapshot}
** EXPERIMENTAL
**
** An instance of the snapshot object records the state of a [WAL mode]
** database for some specific point in history.
**
** In [WAL mode], multiple [database connections] that are open on the
** same database file can each be reading a different historical version
** of the database file. When a [database connection] begins a read
** transaction, that connection sees an unchanging copy of the database
** as it existed for the point in time when the transaction first started.
** Subsequent changes to the database from other connections are not seen
** by the reader until a new read transaction is started.
**
** The sqlite3_snapshot object records state information about an historical
** version of the database file so that it is possible to later open a new read
** transaction that sees that historical version of the database rather than
** the most recent version.
**
** The constructor for this object is [sqlite3_snapshot_get()]. The
** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
** to an historical snapshot (if possible). The destructor for
** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
Waiting connection
refact ::= NO ACTION
Open file handle on the write-ahead log file.
Return no rowids later than this
OUT: Set to 1 if EOF
** This function is used internally to remove the page pPage from the
** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
** LRU list, then this function is a no-op.
**
** The PGroup mutex must be held when this function is called.
** Argument p points to a buffer containing utf-8 text that is n bytes in
** size. Return the number of bytes in the nChar character prefix of the
** buffer, or 0 if there are less than nChar characters in total.
If the module has been registered and includes a Create method,
** invoke it now. If the module has not been registered, return an
** error. Otherwise, do nothing.
comment: Only JUMP opcodes and the short list of special opcodes in the switch
** below need to be considered. The mkopcodeh.tcl generator script groups
** all these opcodes together near the front of the opcode list. Skip
** any opcode that does not need processing by virtual of the fact that
** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
label: code-design
** This variable is set to false when running tests for which the on disk
** structures should not be corrupt. Otherwise, true. If it is false, extra
** assert() conditions in the fts5 code are activated - conditions that are
** only true if it is guaranteed that the fts5 database is not corrupt.
IMP: R-15569-63625
610
Pointer p currently points at the first byte of an offset list. The
** following block advances it to point one byte past the end of
** the same offset list.
The name of the new table
Change-list for UPDATE, NULL for DELETE
** Append a record of the current state of page pPg to the sub-journal.
**
** If successful, set the bit corresponding to pPg->pgno in the bitvecs
** for all open savepoints before returning.
**
** This function returns SQLITE_OK if everything is successful, an IO
** error code if the attempt to write to the sub-journal fails, or
** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
** bitvec.
If >0, bytes of buffer aNode[] loaded
Buffer to append to
The following callback (if not NULL) is invoked on every VDBE branch
** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
OUT: Created tokenizer
Only ephemeral cursors can be duplicated
Number of columns in current object
Index of database containing pTab
Compute the total free space on the page
** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
** start of the first freeblock on the page, or is zero if there are no
** freeblocks.
** Estimate the location of a particular key among all keys in an
** index. Store the results in aStat as follows:
**
** aStat[0] Est. number of rows less than pRec
** aStat[1] Est. number of rows equal to pRec
**
** Return the index of the sample that is the smallest sample that
** is greater than or equal to pRec. Note that this index is not an index
** into the aSample[] array - it is an index into a virtual set of samples
** based on the contents of aSample[] and the number of fields in record
** pRec.
Value of 'ncell' column
if( pSrcList )
For a table with implicit rowids, append "old._rowid_" to the list.
The checkpoint status information
synopsis: r[P2]=P1
Number of pages in the database file
Left input list
One of the WHERE_DISTINCT_* values
1x
Locate and if necessary initialize the target table object
Truncate WAL to this size on reset
28
Loop through each expression in <exprlist>.
************* Begin file complete.c ***************************************
The string to compare against the glob
The locking context for the proxy lock
Regs for sorter record
A direct lookup on the rowid or docid column. Assign a cost of 1.0.
If an error occurred above, free the Pager structure and close the file.
ROWID is never NULL
True (1) if Y,M,D are valid
** The results of a SELECT can be distributed in several ways, as defined
** by one of the following macros. The "SRT" prefix means "SELECT Result
** Type".
**
** SRT_Union Store results as a key in a temporary index
** identified by pDest->iSDParm.
**
** SRT_Except Remove results from the temporary index pDest->iSDParm.
**
** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
** set is not empty.
**
** SRT_Discard Throw the results away. This is used by SELECT
** statements within triggers whose only purpose is
** the side-effects of functions.
**
** All of the above are free to ignore their ORDER BY clause. Those that
** follow must honor the ORDER BY clause.
**
** SRT_Output Generate a row of output (using the OP_ResultRow
** opcode) for each row in the result set.
**
** SRT_Mem Only valid if the result is a single column.
** Store the first column of the first result row
** in register pDest->iSDParm then abandon the rest
** of the query. This destination implies "LIMIT 1".
**
** SRT_Set The result must be a single column. Store each
** row of result as the key in table pDest->iSDParm.
** Apply the affinity pDest->affSdst before storing
** results. Used to implement "IN (SELECT ...)".
**
** SRT_EphemTab Create an temporary table pDest->iSDParm and store
** the result there. The cursor is left open after
** returning. This is like SRT_Table except that
** this destination uses OP_OpenEphemeral to create
** the table first.
**
** SRT_Coroutine Generate a co-routine that returns a new row of
** results each time it is invoked. The entry point
** of the co-routine is stored in register pDest->iSDParm
** and the result row is stored in pDest->nDest registers
** starting with pDest->iSdst.
**
** SRT_Table Store results in temporary table pDest->iSDParm.
** SRT_Fifo This is like SRT_EphemTab except that the table
** is assumed to already be open. SRT_Fifo has
** the additional property of being able to ignore
** the ORDER BY clause.
**
** SRT_DistFifo Store results in a temporary table pDest->iSDParm.
** But also use temporary table pDest->iSDParm+1 as
** a record of all prior results and ignore any duplicate
** rows. Name means: "Distinct Fifo".
**
** SRT_Queue Store results in priority queue pDest->iSDParm (really
** an index). Append a sequence number so that all entries
** are distinct.
**
** SRT_DistQueue Store results in priority queue pDest->iSDParm only if
** the same record has never been stored before. The
** index at pDest->iSDParm+1 hold all prior stores.
Name of trigger
Size of output buffer in bytes
** If the memory cell contains a value that must be freed by
** invoking the external callback in Mem.xDel, then this routine
** will free that value. It also sets Mem.flags to MEM_Null.
**
** This is a helper routine for sqlite3VdbeMemSetNull() and
** for sqlite3VdbeMemRelease(). Use those other routines as the
** entry point for releasing Mem resources.
bNoLock
************* Begin file utf.c ********************************************
** Allocate heap space to hold an Index object with nCol columns.
**
** Increase the allocation size to provide an extra nExtra bytes
** of 8-byte aligned space after the Index object and return a
** pointer to this extra space in *ppExtra.
A fake table from which we get the result set
** These values must match the values defined in wal.c for the equivalent
** locks. These are not magic numbers as they are part of the SQLite file
** format.
Index column used for ORDER BY
00..07 ........
Data to decode list-of-rowids from
Database holding FTS index (e.g. "main")
** xSetOutputs callback used when:
**
** * detail=col,
** * there is a column filter, and
** * the table contains 100 or fewer columns.
**
** The last point is to ensure all column numbers are stored as
** single-byte varints.
************* Begin file auth.c *******************************************
comment: Not needed. Only used to silence a warning.
label: requirement
Iterator
build the NEW.* reference row. Note that if there is an INTEGER
** PRIMARY KEY into which a NULL is being inserted, that NULL will be
** translated into a unique ID for the row. But on a BEFORE trigger,
** we do not know what the unique ID will be (because the insert has
** not happened yet) so we substitute a rowid of -1
Do Nothing
Determine the value of the flags parameter passed to POSIX function
** open(). These must be calculated even if open() is not called, as
** they may be stored as part of the file handle and used by the
** 'conch file' locking functions later on.
301
The byte immediately before the last 0x00 byte has the 0x80 bit
** set. So the last 0x00 is only a varint 0 if there are 8 more 0x80
** bytes before a[ii].
One of the SQLITE_AFF_... values
** The first value in the apVal[] array is assumed to contain an integer.
** This function tests if there exist any documents with docid values that
** are different from that integer. i.e. if deleting the document with docid
** pRowid would mean the FTS3 table were empty.
**
** If successful, *pisEmpty is set to true if the table is empty except for
** document pRowid, or false otherwise, and SQLITE_OK is returned. If an
** error occurs, an SQLite error code is returned.
Array of primary key flags, or NULL
Temporary expression node
200
Configured FCNTL_MMAP_SIZE value
OUT: Size of buffer at *ppOut
The PRIMARY KEY index for WITHOUT ROWID tables
Special query text
Number of entries in aIdx[]
** Return a boolean value for a query parameter.
The table the contains the triggers
Synthesized from VALUES clause
** Buffer aBuf[] contains a list of varints, all small enough to fit
** in a 32-bit integer. Return the size of the largest prefix of this
** list nMax bytes or less in size.
DATA, MISSING, CONFLICT, CONSTRAINT
Trigger opcode
FTS5 Configuration
Sync the master journal file. If the IOCAP_SEQUENTIAL device
** flag is set this is not required.
ccons ::= defer_subclause
** Delete a virtual table handle allocated by fts5InitVtab().
For looping over pages
same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1]
************* End of whereexpr.c ******************************************
Literal "old" token
comment:
** CAPI3REF: Column Names In A Result Set
** METHOD: sqlite3_stmt
**
** ^These routines return the name assigned to a particular column
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
** interface returns a pointer to a zero-terminated UTF-8 string
** and sqlite3_column_name16() returns a pointer to a zero-terminated
** UTF-16 string. ^The first parameter is the [prepared statement]
** that implements the [SELECT] statement. ^The second parameter is the
** column number. ^The leftmost column is number 0.
**
** ^The returned string pointer is valid until either the [prepared statement]
** is destroyed by [sqlite3_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite3_step()] for a particular run
** or until the next call to
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
**
** ^If sqlite3_malloc() fails during the processing of either routine
** (for example during a conversion from UTF-8 to UTF-16) then a
** NULL pointer is returned.
**
** ^The name of a result column is the value of the "AS" clause for
** that column, if there is an AS clause. If there is no AS clause
** then the name of the column is unspecified and may change from
** one release of SQLite to the next.
label: code-design
Tokenizer creation arguments
comment: Expressions of the form
**
** expr1 IN ()
** expr1 NOT IN ()
**
** simplify to constants 0 (false) and 1 (true), respectively,
** regardless of the value of expr1.
label: code-design
Maximum page size. The upper bound on this value is 65536. This a limit
** imposed by the use of 16-bit offsets within each page.
**
** Earlier versions of SQLite allowed the user to change this value at
** compile time. This is no longer permitted, on the grounds that it creates
** a library that is technically incompatible with an SQLite library
** compiled with a different limit. If a process operating on a database
** with a page-size of 65536 bytes crashes, then an instance of SQLite
** compiled with the default page-size limit will not be able to rollback
** the aborted transaction. This could lead to database corruption.
Currently there is an SQL level transaction open on the vacuum
** database. No locks are held on any other files (since the main file
** was committed at the btree level). So it safe to end the transaction
** by manually setting the autoCommit flag to true and detaching the
** vacuum database. The vacuum_db journal file is deleted when the pager
** is closed by the DETACH.
')'
** Implementations of scalar functions for case mapping - upper() and
** lower(). Function upper() converts its input to upper-case (ABC).
** Function lower() converts to lower-case (abc).
**
** ICU provides two types of case mapping, "general" case mapping and
** "language specific". Refer to ICU documentation for the differences
** between the two.
**
** To utilise "general" case mapping, the upper() or lower() scalar
** functions are invoked with one argument:
**
** upper('ABC') -> 'abc'
** lower('abc') -> 'ABC'
**
** To access ICU "language specific" case mapping, upper() or lower()
** should be invoked with two arguments. The second argument is the name
** of the locale to use. Passing an empty string ("") or SQL NULL value
** as the second argument is the same as invoking the 1 argument version
** of upper() or lower().
**
** lower('I', 'en_us') -> 'i'
** lower('I', 'tr_tr') -> '\u131' (small dotless i)
**
** http://www.icu-project.org/userguide/posix.html#case_mappings
comment:
** Prepare a statement used to insert rows into the "rbu_tmp_xxx" table.
** Specifically a statement of the form:
**
** INSERT INTO rbu_tmp_xxx VALUES(?, ?, ? ...);
**
** The number of bound variables is equal to the number of columns in
** the target table, plus one (for the rbu_control column), plus one more
** (for the rbu_rowid column) if the target table is an implicit IPK or
** virtual table.
label: code-design
IMP: R-54100-20147
** This function is used by both blob_open() and blob_reopen(). It seeks
** the b-tree cursor associated with blob handle p to point to row iRow.
** If successful, SQLITE_OK is returned and subsequent calls to
** sqlite3_blob_read() or sqlite3_blob_write() access the specified row.
**
** If an error occurs, or if the specified row does not exist or does not
** contain a value of type TEXT or BLOB in the column nominated when the
** blob handle was opened, then an error code is returned and *pzErr may
** be set to point to a buffer containing an error message. It is the
** responsibility of the caller to free the error message buffer using
** sqlite3DbFree().
**
** If an error does occur, then the b-tree cursor is closed. All subsequent
** calls to sqlite3_blob_read(), blob_write() or blob_reopen() will
** immediately return SQLITE_ABORT.
comment: Prevent warning when SQLITE_THREADSAFE=0
label: code-design
Generate new record numbers semi-randomly
** sqlite3_test_control(BITVEC_TEST, size, program)
**
** Run a test against a Bitvec object of size. The program argument
** is an array of integers that defines the test. Return -1 on a
** memory allocation error, 0 on success, or non-zero for an error.
** See the sqlite3BitvecBuiltinTest() for additional information.
Pointer to vtab instance
** This function sets the value of the sqlite3_value object passed as the
** first argument to a copy of the string or blob held in the aData[]
** buffer. SQLITE_OK is returned if successful, or SQLITE_NOMEM if an OOM
** error occurs.
Index of next byte to read from input
xUnlock
Omit if ExprList.u.x.iOrderByCol
If there are active savepoints and any of them were created
** since the most recent journal header was written, update the
** PagerSavepoint.iHdrOffset fields now.
** Initialize a string accumulator.
**
** p: The accumulator to be initialized.
** db: Pointer to a database connection. May be NULL. Lookaside
** memory is used if not NULL. db->mallocFailed is set appropriately
** when not NULL.
** zBase: An initial buffer. May be NULL in which case the initial buffer
** is malloced.
** n: Size of zBase in bytes. If total space requirements never exceed
** n then no memory allocations ever occur.
** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
** allocations will ever occur.
If the QUERY_SCAN flag is set, all other flags must be clear.
xTestCallback
Page 1 of the database file
File handle from winOpen
Last element in link-list. Valid for 1st elem only
Destructor for Mem.z - only valid if MEM_Dyn
Preserve the default page cache size
copy digits to exponent
** Return the collating function associated with a function.
** Free any prior content in *pz and replace it with a copy of zNew.
Use this for the table cursor, if there is one
The LHS of the IN operator
pPager->stmtInUse = 0;
Expressions defining the result set
Context for active vtab connect/create
** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
** that the YYYY-MM-DD is according to the Gregorian calendar.
**
** Reference: Meeus page 61
** Performance statistics
uniqueflag ::= UNIQUE
Function definition
SQL_SELECT_INDEXES
** Return the list of valid segment indexes for absolute level ?
comment:
** This function is now an anachronism. It used to be used to recover from a
** malloc() failure, but SQLite now does this automatically.
label: code-design
** We need to define _XOPEN_SOURCE as follows in order to enable
** recursive mutexes on most Unix systems and fchmod() on OpenBSD.
** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit
** it.
Neither X nor Y have COLLATE operators, but X has a non-default
** collating sequence. So add the EP_Collate marker on X to cause
** it to be searched first.
Create the INSERT statement to write to the target PK b-tree
comment:
** Hard-coded maximum amount of data to accumulate in memory before flushing
** to a level 0 PMA. The purpose of this limit is to prevent various integer
** overflows. 512MiB.
label: code-design
Fix items to this schema
xAccess
** Each time a blob is read from the %_data table, it is padded with this
** many zero bytes. This makes it easier to decode the various record formats
** without overreading if the records are corrupt.
Forward declaration for the function that does the work of
** the virtual table module xCreate() and xConnect() methods.
** Arguments pList/nList contain the doclist for token iToken of phrase p.
** It is merged into the main doclist stored in p->doclist.aAll/nAll.
**
** This function assumes that pList points to a buffer allocated using
** sqlite3_malloc(). This function takes responsibility for eventually
** freeing the buffer.
**
** SQLITE_OK is returned if successful, or SQLITE_NOMEM if an error occurs.
True for descending docids
It is acceptable to use a read-only (mmap) page for any page except
** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
** flag was specified by the caller. And so long as the db is not a
** temporary or in-memory database.
First Mem address for previous GROUP BY
** CAPI3REF: Session Object Handle
** The suggested maximum number of in-memory pages to use for
** the main database table and for temporary tables.
**
** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
** which means the cache size is limited to 2048000 bytes of memory.
** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
************* End of notify.c *********************************************
comment: This is the 2-bit case and we are on the second iteration and
** current term is from the first iteration. So skip this term.
label: code-design
Step 2
** This function is called by the xUpdate() method as part of an INSERT
** operation. It adds entries for each term in the new record to the
** pendingTerms hash table.
**
** Argument apVal is the same as the similarly named argument passed to
** fts3InsertData(). Parameter iDocid is the docid of the new row.
** If the expression passed as the only argument is of type TK_VECTOR
** return the number of expressions in the vector. Or, if the expression
** is a sub-select, return the number of columns in the sub-select. For
** any other type of expression, return 1.
** This function is called after transitioning from PAGER_UNLOCK to
** PAGER_SHARED state. It tests if there is a hot journal present in
** the file-system for the given pager. A hot journal is one that
** needs to be played back. According to this function, a hot-journal
** file exists if the following criteria are met:
**
** * The journal file exists in the file system, and
** * No process holds a RESERVED or greater lock on the database file, and
** * The database file itself is greater than 0 bytes in size, and
** * The first byte of the journal file exists and is not 0x00.
**
** If the current size of the database file is 0 but a journal file
** exists, that is probably an old journal left over from a prior
** database with the same name. In this case the journal file is
** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
** is returned.
**
** This routine does not check if there is a master journal filename
** at the end of the file. If there is, and that master journal file
** does not exist, then the journal file is not really hot. In this
** case this routine will return a false-positive. The pager_playback()
** routine will discover that the journal file is not really hot and
** will not roll it back.
**
** If a hot-journal file is found to exist, *pExists is set to 1 and
** SQLITE_OK returned. If no hot-journal file is present, *pExists is
** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
** to determine whether or not a hot-journal file exists, the IO error
** code is returned and the value of *pExists is undefined.
** Debug tracing macros. Enable by by changing the "0" to "1" and
** recompiling.
**
** When sqlite3PcacheTrace is 1, single line trace messages are issued.
** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
** is displayed for many operations, resulting in a lot of output.
Elements of the linked list at Vdbe.pAuxData
Number of tokens in the phrase
** This routine reactivates the memory allocator and clears the
** db->mallocFailed flag as necessary.
**
** The memory allocator is not restarted if there are running
** VDBEs.
current position in zInput
Estimate the average row size for the table and for all implied indices
Use pPager->journalOff as the effective size of the main rollback
** journal. The actual file might be larger than this in
** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST. But anything
** past pPager->journalOff is off-limits to us.
************* End of pragma.h *********************************************
** An rtree structure node.
Length of z in bytes (excl. nul-term)
force new CREATE statements into vacuum_db
Rowid in sqlite_sequence
PRAGMA
FROM clause term being analyzed
Array of segment iterators
Write the new.* vector
Bytes of zBuf[] currently used
** Include the configuration header output by 'configure' if we're using the
** autoconf-based build
The new column
19
True if *pRowid really is in the table
Inode number
Rowid used for the averages record
P2
269
Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
** to 0. This is used by the implementations of sqlite3_backup_step()
** and sqlite3_backup_finish() to detect that they are being called
** from this function, not directly by the user.
If the VDBE has be run even partially, then transfer the error code
** and error message from the VDBE into the main database structure. But
** if the VDBE has just been set to run but has not actually executed any
** instructions yet, leave the main database error information unchanged.
** Get a reference to pPage1 of the database file. This will
** also acquire a readlock on that file.
**
** SQLITE_OK is returned on success. If the file is not a
** well-formed database file, then SQLITE_CORRUPT is returned.
** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
** is returned if we run out of memory.
FROM clause
comment:
** If SQLITE_DEBUG_SORTER_THREADS is defined, this module outputs various
** messages to stderr that may be helpful in understanding the performance
** characteristics of the sorter in multi-threaded mode.
label: code-design
EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
** the b-tree page type.
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
** statement. The module name has been parsed, but the optional list
** of parameters that follow the module name are still pending.
Data space required for this record
Set the EOF flag if either all synonym iterators are at EOF or an
** error has occurred.
Run the progress counter just before returning.
** Search a FuncDefHash for a function with the given name. Return
** a pointer to the matching FuncDef if found, or 0 if there is no match.
Enable load_extension() SQL func
comment: FROM clause term being coded
label: code-design
Started out as two integer operands
Set to true if segment is appendable
IN: Left hand input list
b: p1<<14 | p3 (unmasked)
Advance the iterator for each token in the phrase once.
Min-heap used for checking cell coverage
comment: ************************************************** General Interfaces ******
**
** Initialize and shutdown the page cache subsystem. Neither of these
** functions are threadsafe.
label: code-design
JSON type values
** Create a new aggregate context for p and return a pointer to
** its pMem->z element.
When transistioning from TRUNCATE or PERSIST to any other journal
** mode except WAL, unless the pager is in locking_mode=exclusive mode,
** delete the journal file.
** This structure is used to pass data from sqlite3_get_table() through
** to the callback function is uses to build the result.
** This is a public wrapper for the winMbcsToUtf8() function.
Flag parameters, such as SF_Distinct
** Create the mutex and shared memory used for locking in the file
** descriptor pFile
** This function is called from within a pre-update callback to retrieve
** a field of the row currently being updated or inserted.
f0..f7 ........
Read & merge multiple PMAs
** Add the virtual table pVTab to the array sqlite3.aVTrans[]. Space should
** have already been reserved using growVTrans().
** Special setup for VxWorks
** Return true if z[] begins with 4 (or more) hexadecimal digits
FROM clause: A list of all tables to be scanned
Step 4. Try to recycle a page.
Number of open transactions (read + write)
Or if it is a non-periodic sample. Add it in this case too.
Locks are within range
580
** Decode a segment-data rowid from the %_data table. This function is
** the opposite of macro FTS5_SEGMENT_ROWID().
Page flags
The table to insert into. aka TABLE
** Test for access permissions. Return true if the requested permission
** is available, or false otherwise.
Invoke this callback routine
Ran out of input before finding the table name. Return NULL.
** Truncate the file.
**
** If the journal file is already on disk, truncate it there. Or, if it
** is still in main memory but is being truncated to zero bytes in size,
** ignore
Call the xFindFunction method on the virtual table implementation
** to see if the implementation wants to overload this function
Sometimes the code for a subquery will be generated more than
** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
** for example. In that case, do not regenerate the code to manifest
** a view or the co-routine to implement a view. The first instance
** is sufficient, though the subroutine to manifest the view does need
** to be invoked again.
The database we are looking in
Read the schema cookie from the database. If it does not match the
** value stored as part of the in-memory schema representation,
** set Parse.rc to SQLITE_SCHEMA.
True if we use the index only
comment: There must be at least one argument passed to this function (otherwise
** the non-overloaded version would have been called instead of this one).
label: code-design
YYFALLBACK
#define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback
Number of entries in apMem[]
** Each sample stored in the sqlite_stat3 table is represented in memory
** using a structure of this type. See documentation at the top of the
** analyze.c source file for additional information.
** Include standard header files as necessary
At this point variables should be set as follows:
**
** nPayload Total payload size in bytes
** pPayload Begin writing payload here
** spaceLeft Space available at pPayload. If nPayload>spaceLeft,
** that means content must spill into overflow pages.
** *pnSize Size of the local cell (not counting overflow pages)
** pPrior Where to write the pgno of the first overflow page
**
** Use a call to btreeParseCellPtr() to verify that the values above
** were computed correctly.
Thread-sanitizer reports that the following is an unsafe read,
** as some other thread may be in the process of updating the value
** of the aReadMark[] slot. The assumption here is that if that is
** happening, the other client may only be increasing the value,
** not decreasing it. So assuming either that either the "old" or
** "new" version of the value is read, and not some arbitrary value
** that would never be written by a real client, things are still
** safe.
Do an integrity check on each database file
If the DELETE has generated immediate foreign key constraint
** violations, halt the VDBE and return an error at this point, before
** any modifications to the schema are made. This is because statement
** transactions are not able to rollback schema changes.
**
** If the SQLITE_DeferFKs flag is set, then this is not required, as
** the statement transaction will not be rolled back even if FK
** constraints are violated.
** Change the value of the opcode, or P1, P2, P3, or P5 operands
** for a specific instruction.
Transformation type code
comment: Magic number 1 is the WAL_CKPT_LOCK lock. Preventing SQLite from
** taking this lock also prevents any checkpoints from occurring.
** todo: really, it's not clear why this might occur, as
** wal_autocheckpoint ought to be turned off.
label: code-design
Close the transaction, if one was opened.
** Return code from the parse-tree walking primitives and their
** callbacks.
** Discard the entire contents of the in-memory page-cache.
There is no INDEXED BY clause. Create a fake Index object in local
** variable sPk to represent the rowid primary key index. Make this
** fake index the first in a chain of Index objects with all of the real
** indices to follow
2147418112
Allocate space for the new sqlite3_shm object. Also speculatively
** allocate space for a new winShmNode and filename.
Total bytes of space to allocate
comment: Variable DUMMY1 is initialized to a negative value above. Elsewhere
** in the FTS code the variable that the third argument to xNext points to
** is initialized to zero before the first (*but not necessarily
** subsequent*) call to xNext(). This is done for a particular application
** that needs to know whether or not the tokenizer is being used for
** snippet generation or for some other purpose.
**
** Extreme care is required when writing code to depend on this
** initialization. It is not a documented part of the tokenizer interface.
** If a tokenizer is used directly by any code outside of FTS, this
** convention might not be respected.
label: code-design
The attempt to extend the existing mapping failed. Free it.
Number of deferred fk violations
The operator
IN/OUT: Left input list
Timezone was set explicitly
Number of backtraces on this alloc
Figure out how many savepoints will still be active after this
** operation. Store this value in nNew. Then free resources associated
** with any savepoints that are destroyed by this operation.
************* Begin file vacuum.c *****************************************
** This function does a "phrase" merge of two doclists. In a phrase merge,
** the output contains a copy of each position from the right-hand input
** doclist for which there is a position in the left-hand input doclist
** exactly nDist tokens before it.
**
** If the docids in the input doclists are sorted in ascending order,
** parameter bDescDoclist should be false. If they are sorted in ascending
** order, it should be passed a non-zero value.
**
** The right-hand input doclist is overwritten by this function.
** CAPI3REF: Configure an auto-checkpoint
** METHOD: sqlite3
**
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
** [sqlite3_wal_hook()] that causes any database on [database connection] D
** to automatically [checkpoint]
** after committing a transaction if there are N or
** more frames in the [write-ahead log] file. ^Passing zero or
** a negative value as the nFrame parameter disables automatic
** checkpoints entirely.
**
** ^The callback registered by this function replaces any existing callback
** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
** configured by this function.
**
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
** from SQL.
**
** ^Checkpoints initiated by this mechanism are
** [sqlite3_wal_checkpoint_v2|PASSIVE].
**
** ^Every new [database connection] defaults to having the auto-checkpoint
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
** pages. The use of this interface
** is only necessary if the default setting is found to be suboptimal
** for a particular application.
Set this flag to 1
Original value of pNew->u.btree.nEq
Database is closed
outer
** Link the chunk at mem3.aPool[i] so that is on the list rooted
** at *pRoot.
Index in sParse.aNode[] of current row
Specific token to advance
** Set the title string for subsequent allocations.
** Names of locks. This routine is used to provide debugging output and is not
** a part of an ordinary build.
Index added to make the name unique
OUT: *ppToken is the token text
Context object for function invocation
Copy of idxNum search parameter
Second and subsequent calls get processed here
For looping through SELECT statements
Variable 'dist' stores the number of tokens read since the most
** recent TK_DOT or TK_ON. This means that when a WHEN, FOR or BEGIN
** token is read and 'dist' equals 2, the condition stated above
** to be met.
**
** Note that ON cannot be a database, table or column name, so
** there is no need to worry about syntax like
** "CREATE TRIGGER ... ON ON.ON BEGIN ..." etc.
** This function is called when the root page of a b-tree structure is
** overfull (has one or more overflow pages).
**
** A new child page is allocated and the contents of the current root
** page, including overflow cells, are copied into the child. The root
** page is then overwritten to make it an empty page with the right-child
** pointer pointing to the new page.
**
** Before returning, all pointer-map entries corresponding to pages
** that the new child-page now contains pointers to are updated. The
** entry corresponding to the new right-child pointer of the root
** page is also updated.
**
** If successful, *ppChild is set to contain a reference to the child
** page and SQLITE_OK is returned. In this case the caller is required
** to call releasePage() on *ppChild exactly once. If an error occurs,
** an error code is returned and *ppChild is set to 0.
Check for authorization to create an index.
Type field
Total number of rows in FTS table
Used when p4type is P4_EXPR
Uses OS features not supported on host
The root page of the PRIMARY KEY is the table root page
Store result in reg[P2] rather than jump
skip leading spaces
** Walk the expression tree pExpr and increase the aggregate function
** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
** This needs to occur when copying a TK_AGG_FUNCTION node from an
** outer query into an inner subquery.
**
** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
** is a helper function - a callback for the tree walker.
EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
** leaf index b-tree page.
comment:
** Flags passed as the third argument to sqlite3BtreeCursor().
**
** For read-only cursors the wrFlag argument is always zero. For read-write
** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or just
** (BTREE_WRCSR). If the BTREE_FORDELETE bit is set, then the cursor will
** only be used by SQLite for the following:
**
** * to seek to and then delete specific entries, and/or
**
** * to read values that will be used to create keys that other
** BTREE_FORDELETE cursors will seek to and delete.
**
** The BTREE_FORDELETE flag is an optimization hint. It is not used by
** by this, the native b-tree engine of SQLite, but it is available to
** alternative storage engines that might be substituted in place of this
** b-tree system. For alternative storage engines in which a delete of
** the main table row automatically deletes corresponding index rows,
** the FORDELETE flag hint allows those alternative storage engines to
** skip a lot of work. Namely: FORDELETE cursors may treat all SEEK
** and DELETE operations as no-ops, and any READ operation against a
** FORDELETE cursor may return a null row: 0x01 0x00.
label: code-design
If a transient index is required, create it by calling
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
** opening it. If a transient table is required, just use the
** automatically created table with root-page 1 (an BLOB_INTKEY table).
Buffer size
** Add all WhereLoop objects for all tables
****************** NOTES ON THE DESIGN OF THE PAGER ************************
**
** This comment block describes invariants that hold when using a rollback
** journal. These invariants do not apply for journal_mode=WAL,
** journal_mode=MEMORY, or journal_mode=OFF.
**
** Within this comment block, a page is deemed to have been synced
** automatically as soon as it is written when PRAGMA synchronous=OFF.
** Otherwise, the page is not synced until the xSync method of the VFS
** is called successfully on the file containing the page.
**
** Definition: A page of the database file is said to be "overwriteable" if
** one or more of the following are true about the page:
**
** (a) The original content of the page as it was at the beginning of
** the transaction has been written into the rollback journal and
** synced.
**
** (b) The page was a freelist leaf page at the start of the transaction.
**
** (c) The page number is greater than the largest page that existed in
** the database file at the start of the transaction.
**
** (1) A page of the database file is never overwritten unless one of the
** following are true:
**
** (a) The page and all other pages on the same sector are overwriteable.
**
** (b) The atomic page write optimization is enabled, and the entire
** transaction other than the update of the transaction sequence
** number consists of a single page change.
**
** (2) The content of a page written into the rollback journal exactly matches
** both the content in the database when the rollback journal was written
** and the content in the database at the beginning of the current
** transaction.
**
** (3) Writes to the database file are an integer multiple of the page size
** in length and are aligned on a page boundary.
**
** (4) Reads from the database file are either aligned on a page boundary and
** an integer multiple of the page size in length or are taken from the
** first 100 bytes of the database file.
**
** (5) All writes to the database file are synced prior to the rollback journal
** being deleted, truncated, or zeroed.
**
** (6) If a master journal file is used, then all writes to the database file
** are synced prior to the master journal being deleted.
**
** Definition: Two databases (or the same database at two points it time)
** are said to be "logically equivalent" if they give the same answer to
** all queries. Note in particular the content of freelist leaf
** pages can be changed arbitrarily without affecting the logical equivalence
** of the database.
**
** (7) At any time, if any subset, including the empty set and the total set,
** of the unsynced changes to a rollback journal are removed and the
** journal is rolled back, the resulting database file will be logically
** equivalent to the database file at the beginning of the transaction.
**
** (8) When a transaction is rolled back, the xTruncate method of the VFS
** is called to restore the database file to the same size it was at
** the beginning of the transaction. (In some VFSes, the xTruncate
** method is a no-op, but that does not change the fact the SQLite will
** invoke it.)
**
** (9) Whenever the database file is modified, at least one bit in the range
** of bytes from 24 through 39 inclusive will be changed prior to releasing
** the EXCLUSIVE lock, thus signaling other connections on the same
** database to flush their caches.
**
** (10) The pattern of bits in bytes 24 through 39 shall not repeat in less
** than one billion transactions.
**
** (11) A database file is well-formed at the beginning and at the conclusion
** of every transaction.
**
** (12) An EXCLUSIVE lock is held on the database file when writing to
** the database file.
**
** (13) A SHARED lock is held on the database file while reading any
** content out of the database file.
**
*****************************************************************************
** Register a new collation sequence with the database handle db.
Current node image
Decode the position list tail at the start of the page
Open the sqlite_stat1 table on this cursor
** Return status data for a single loop within query pStmt.
Figure out how many records are in the journal. Abort early if
** the journal is empty.
Affinity to use
** The second argument to this function contains the text of an SQL statement
** that returns a single integer value. The statement is compiled and executed
** using database connection db. If successful, the integer value returned
** is written to *piVal and SQLITE_OK returned. Otherwise, an SQLite error
** code is returned and the value of *piVal after returning is not defined.
First argument passed to xConflict
If the secure_delete option is enabled, then
** always fully overwrite deleted information with zeros.
** When a sub-program is executed (OP_Program), a structure of this type
** is allocated to store the current value of the program counter, as
** well as the current memory cell array and various other frame specific
** values stored in the Vdbe struct. When the sub-program is finished,
** these values are copied back to the Vdbe from the VdbeFrame structure,
** restoring the state of the VM to as it was before the sub-program
** began executing.
**
** The memory for a VdbeFrame object is allocated and managed by a memory
** cell in the parent (calling) frame. When the memory cell is deleted or
** overwritten, the VdbeFrame object is not freed immediately. Instead, it
** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
** this instead of deleting the VdbeFrame immediately is to avoid recursive
** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
** child frame are released.
**
** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
** set to NULL if the currently executing frame is the main program.
WHEN clause for the trigger
No WHERE clause
Can't reestablish the shared lock. Sqlite can't deal, this is
** a critical I/O error
True if PAGER_GET_NOCONTENT is set
** Deprecated external interface. Internal/core SQLite code
** should call sqlite3TransferBindings.
**
** It is misuse to call this routine with statements from different
** database connections. But as this is a deprecated interface, we
** will not bother to check for that condition.
**
** If the two statements contain a different number of bindings, then
** an SQLITE_ERROR is returned. Nothing else can go wrong, so otherwise
** SQLITE_OK is returned.
255
Bytes of data available in buffer
Put error message here if not 0
The following are used by the fts3_snippet.c module.
For each expression in the list
comment:
** The macro MEMDB is true if we are dealing with an in-memory database.
** We do this as a macro so that if the SQLITE_OMIT_MEMORYDB macro is set,
** the value of MEMDB will be a constant and the compiler will optimize
** out code that would never execute.
label: code-design
** Recommended number of samples for sqlite_stat4
Memory registers holding LIMIT & OFFSET counters
(pKey1/nKey1) is a number or a null
No need to log a failure to lock
Min-heap used for analyzing cell coverage
Index for p->aIndex[]
Load table details if required
** Given table pTab, return a list of all the triggers attached to
** the table. The list is connected by Trigger.pNext pointers.
**
** All of the triggers on pTab that are in the same database as pTab
** are already attached to pTab->pTrigger. But there might be additional
** triggers on pTab in the TEMP schema. This routine prepends all
** TEMP triggers on pTab to the beginning of the pTab->pTrigger list
** and returns the combined list.
**
** To state it another way: This routine returns a list of all triggers
** that fire off of pTab. The list will include any TEMP triggers on
** pTab as well as the triggers lised in pTab->pTrigger.
source and destination must both be WITHOUT ROWID or not
comment: Loop through all %_segdir entries for segments in this index with
** levels equal to or greater than iAbsLevel. As each entry is visited,
** updated it to set (level = -1) and (idx = N), where N is 0 for the
** oldest segment in the range, 1 for the next oldest, and so on.
**
** In other words, move all segments being promoted to level -1,
** setting the "idx" fields as appropriate to keep them in the same
** order. The contents of level -1 (which is never used, except
** transiently here), will be moved back to level iAbsLevel below.
label: code-design
** Return true if the iterator is at EOF or if an error has occurred.
** False otherwise.
Previously obtained value for P4
comment: Loop through the tables in the main database. For each, do
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
** the contents to the temporary database.
label: code-design
The offset for ReadFile.
CURTYPE_SORTER. Sorter object
Elements in aOp[]
pPager->state = PAGER_UNLOCK;
comment: Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
** of one or more PCaches that are able to recycle each other's unpinned
** pages when they are under memory pressure. A PGroup is an instance of
** the following object.
**
** This page cache implementation works in one of two modes:
**
** (1) Every PCache is the sole member of its own PGroup. There is
** one PGroup per PCache.
**
** (2) There is a single global PGroup that all PCaches are a member
** of.
**
** Mode 1 uses more memory (since PCache instances are not able to rob
** unused pages from other PCaches) but it also operates without a mutex,
** and is therefore often faster. Mode 2 requires a mutex in order to be
** threadsafe, but recycles pages more efficiently.
**
** For mode (1), PGroup.mutex is NULL. For mode (2) there is only a single
** PGroup which is the pcache1.grp global variable and its mutex is
** SQLITE_MUTEX_STATIC_LRU.
label: code-design
Column names corresponding to IDLIST.
** CAPI3REF: Set a table filter on a Session Object.
**
** The second argument (xFilter) is the "filter callback". For changes to rows
** in tables that are not attached to the Session object, the filter is called
** to determine whether changes to the table's rows should be tracked or not.
** If xFilter returns 0, changes is not tracked. Note that once a table is
** attached, xFilter will not be called again.
** Scan the column type name zType (length nType) and return the
** associated affinity type.
**
** This routine does a case-independent search of zType for the
** substrings in the following table. If one of the substrings is
** found, the corresponding affinity is returned. If zType contains
** more than one of the substrings, entries toward the top of
** the table take priority. For example, if zType is 'BLOBINT',
** SQLITE_AFF_INTEGER is returned.
**
** Substring | Affinity
** --------------------------------
** 'INT' | SQLITE_AFF_INTEGER
** 'CHAR' | SQLITE_AFF_TEXT
** 'CLOB' | SQLITE_AFF_TEXT
** 'TEXT' | SQLITE_AFF_TEXT
** 'BLOB' | SQLITE_AFF_BLOB
** 'REAL' | SQLITE_AFF_REAL
** 'FLOA' | SQLITE_AFF_REAL
** 'DOUB' | SQLITE_AFF_REAL
**
** If none of the substrings in the above table are found,
** SQLITE_AFF_NUMERIC is returned.
Number of fields in pRec
** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
** attempts to find the lowest cost path that visits each WhereLoop
** once. This path is then loaded into the pWInfo->a[].pWLoop fields.
**
** Assume that the total number of output rows that will need to be sorted
** will be nRowEst (in the 10*log2 representation). Or, ignore sorting
** costs if nRowEst==0.
**
** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
** error occurs.
Parse array
** This is a helper function used by sessionMergeUpdate().
**
** When this function is called, both *paOne and *paTwo point to a value
** within a change record. Before it returns, both have been advanced so
** as to point to the next value in the record.
**
** If, when this function is called, *paTwo points to a valid value (i.e.
** *paTwo[0] is not 0x00 - the "no value" placeholder), a copy of the *paTwo
** pointer is returned and *pnVal is set to the number of bytes in the
** serialized value. Otherwise, a copy of *paOne is returned and *pnVal
** set to the number of bytes in the value at *paOne. If *paOne points
** to the "no value" placeholder, *pnVal is set to 1. In other words:
**
** if( *paTwo is valid ) return *paTwo;
** return *paOne;
**
Value for "end_block" field
a column type code
Store result as data with an automatic rowid
Initialize the structure. The sqlite3_index_info structure contains
** many fields that are declared "const" to prevent xBestIndex from
** changing them. We have to do some funky casting in order to
** initialize those fields.
** The following set of routines are used to disable the simulated
** I/O error mechanism. These routines are used to avoid simulated
** errors in places where we do not care about errors.
**
** Unless -DSQLITE_TEST=1 is used, these routines are all no-ops
** and generate no code.
Drop all SQLITE_MASTER table and index entries that refer to the
** table. The program name loops through the master table and deletes
** every row that refers to a table of the same name as the one being
** dropped. Triggers are handled separately because a trigger can be
** created in the temp database that refers to a table in another
** database.
** Locate a user function given a name, a number of arguments and a flag
** indicating whether the function prefers UTF-16 over UTF-8. Return a
** pointer to the FuncDef structure that defines that function, or return
** NULL if the function does not exist.
**
** If the createFlag argument is true, then a new (blank) FuncDef
** structure is created and liked into the "db" structure if a
** no matching function previously existed.
**
** If nArg is -2, then the first valid function found is returned. A
** function is valid if xSFunc is non-zero. The nArg==(-2)
** case is used to see if zName is a valid function name for some number
** of arguments. If nArg is -2, then createFlag must be 0.
**
** If createFlag is false, then a function with the required name and
** number of arguments may be returned even if the eTextRep flag does not
** match that requested.
True if aOverflow is valid
Table on the left with matching column name
Text encoding used by this database
Make the new connection a child of the unixShmNode
If the VM did not run to completion or if it encountered an
** error, then it might not have been halted properly. So halt
** it now.
EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
** integer offsets to the cell contents.
True exponent is either not used or is well-formed
OUT: SQLITE_INSERT, DELETE or UPDATE
Added ???
** 2006 June 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the SQLite interface for use by
** shared libraries that want to be imported as extensions into
** an SQLite instance. Shared libraries that intend to be loaded
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
Number of references to columns in other FROM clauses
** Allowed values for Select.selFlags. The "SF" prefix stands for
** "Select Flag".
**
** Value constraints (all checked via assert())
** SF_HasAgg == NC_HasAgg
** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
** SF_FixedLimit == WHERE_USE_LIMIT
If there is a doclist-index, check that it looks right.
comment: "[...]" immediately follows the "*". We have to do a slow
** recursive search in this case, but it is an unusual case.
label: code-design
** Return the column of index pIdx that corresponds to table
** column iCol. Return -1 if not found.
** Memory map or remap the file opened by file-descriptor pFd (if the file
** is already mapped, the existing mapping is replaced by the new). Or, if
** there already exists a mapping for this file, and there are still
** outstanding xFetch() references to it, this function is a no-op.
**
** If parameter nByte is non-negative, then it is the requested size of
** the mapping to create. Otherwise, if nByte is less than zero, then the
** requested size is the size of the file on disk. The actual size of the
** created mapping is either the requested size or the value configured
** using SQLITE_FCNTL_MMAP_LIMIT, whichever is smaller.
**
** SQLITE_OK is returned if no error occurs (even if the mapping is not
** recreated as a result of outstanding references) or an SQLite error
** code otherwise.
** Populate the Fts5Config.zContentExprlist string.
Additional methods may be added in future releases
The comparison operator
Connection that caused SQLITE_LOCKED
Read the wal-index header.
** Return true if the parser passed as the first argument is being
** used to code a trigger that is really a "SET NULL" action belonging
** to trigger pFKey.
Number of errors reported
Subroutine for resetting the accumulator
** Set the value if the iSrcLine field for the previously coded instruction.
** Free any overflow pages associated with the given Cell. Write the
** local Cell size (the number of bytes on the original page, omitting
** overflow) into *pnSize.
** This function searches pList for an entry that matches the iCol-th column
** of index pIdx.
**
** If such an expression is found, its index in pList->a[] is returned. If
** no expression is found, -1 is returned.
Usable size of mapped region
compress=? parameter (or NULL)
Initialization context
The WHERE clause. May be NULL
The flags specified at open()
FTS5_AND node to advance
Value returned by conflict handler
Populate the coverage-checking heap for leaf pages
SQLITE_OS_WIN_THREADS
************* Begin file where.c ******************************************
Insert an element into the hash table pH. The key is pKey
** and the data is "data".
**
** If no element exists with a matching key, then a new
** element is created and NULL is returned.
**
** If another element already exists with the same key, then the
** new data replaces the old data and the old data is returned.
** The key is not copied in this instance. If a malloc fails, then
** the new data is returned and the hash table is unchanged.
**
** If the "data" parameter to this function is NULL, then the
** element corresponding to "key" is removed from the hash table.
Verifies FORDELETE and AUXDELETE flags
First try to append the term to the current node. Return early if
** this is possible.
** Return a section of the pPage->aData to the freelist.
** The first byte of the new free block is pPage->aData[iStart]
** and the size of the block is iSize bytes.
**
** Adjacent freeblocks are coalesced.
**
** Note that even though the freeblock list was checked by btreeInitPage(),
** that routine will not detect overlap between cells or freeblocks. Nor
** does it detect cells or freeblocks that encrouch into the reserved bytes
** at the end of the page. So do additional corruption checks inside this
** routine and return SQLITE_CORRUPT if any problems are found.
Flags to sqlite3BtreeOpen()
tcons ::= CONSTRAINT nm
If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
** no-op
Find an existing tokenizer
defined(SQLITE_WIN32_HAS_ANSI)
EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
** single argument of type int, interpreted as a boolean, which enables
** or disables the collection of memory allocation statistics.
** Read data from a blob handle.
xSleep
** Return the maximum height of any expression tree referenced
** by the select statement passed as an argument.
Info about locks on this inode
The WhereClause to be initialized
mem1.flags = 0; // Will be initialized by sqlite3VdbeSerialGet()
Return code for this function
Allocate and populate the context object.
The i-th index expression
*****************************************************************************
************************* Begin dot-file Locking ******************************
**
** The dotfile locking implementation uses the existence of separate lock
** files (really a directory) to control access to the database. This works
** on just about every filesystem imaginable. But there are serious downsides:
**
** (1) There is zero concurrency. A single reader blocks all other
** connections from reading or writing the database.
**
** (2) An application crash or power loss can leave stale lock files
** sitting around that need to be cleared manually.
**
** Nevertheless, a dotlock is an appropriate locking mode for use if no
** other locking strategy is available.
**
** Dotfile locking works by creating a subdirectory in the same directory as
** the database and with the same name but with a ".lock" extension added.
** The existence of a lock directory implies an EXCLUSIVE lock. All other
** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
Search the hash table or tables for an entry matching page number
** pgno. Each iteration of the following for() loop searches one
** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
**
** This code might run concurrently to the code in walIndexAppend()
** that adds entries to the wal-index (and possibly to this hash
** table). This means the value just read from the hash
** slot (aHash[iKey]) may have been added before or after the
** current read transaction was opened. Values added after the
** read transaction was opened may have been written incorrectly -
** i.e. these slots may contain garbage data. However, we assume
** that any slots written before the current read transaction was
** opened remain unmodified.
**
** For the reasons above, the if(...) condition featured in the inner
** loop of the following block is more stringent that would be required
** if we had exclusive access to the hash-table:
**
** (aPgno[iFrame]==pgno):
** This condition filters out normal hash-table collisions.
**
** (iFrame<=iLast):
** This condition filters out entries that were added to the hash
** table after the current read-transaction had started.
Snippet iterator
** Return the number of dirty pages currently in the cache, as a percentage
** of the configured cache size.
Enable recursive triggers
Iterator used to gather data from index
Don't do any authorization checks if the database is initialising
** or if the parser is being invoked from within sqlite3_declare_vtab.
The parser's stack
Absolute level number to work on
************* End of vacuum.c *********************************************
Content of this chunk
Address of OP_Explain (or 0)
***************************************************************************
** The following routines are the only publically visible identifiers in this
** file. Call the following routines in order to register the various SQL
** functions and the virtual table implemented by this file.
***************************************************************************
Last field of the record
Est. number of distinct keys less than this sample
** The following is guaranteed when this function is called:
**
** a) the WRITER lock is held,
** b) the entire log file has been checkpointed, and
** c) any existing readers are reading exclusively from the database
** file - there are no readers that may attempt to read a frame from
** the log file.
**
** This function updates the shared-memory structures so that the next
** client to write to the database (which may be this one) does so by
** writing frames into the start of the log file.
**
** The value of parameter salt1 is used as the aSalt[1] value in the
** new wal-index header. It should be passed a pseudo-random value (i.e.
** one obtained from sqlite3_randomness()).
The WHERE clause to be searched
Alternate addrEofA if B is uninitialized
750
The following assert statements check that the binary search code
** above found the right answer. This block serves no purpose other
** than to invoke the asserts.
failed to open/create the lock directory
Index used to optimize scan, or NULL
** This function does all the work for both the xConnect and xCreate methods.
** These tables have no persistent representation of their own, so xConnect
** and xCreate are identical operations.
If the child table is the same as the parent table, then add terms
** to the WHERE clause that prevent this entry from being scanned.
** The added WHERE clause terms are like this:
**
** $current_rowid!=rowid
** NOT( $current_a==a AND $current_b==b AND ... )
**
** The first form is used for rowid tables. The second form is used
** for WITHOUT ROWID tables. In the second form, the primary key is
** (a,b,...)
CREATE VIEW name AS... without an argument list. Construct
** the column names from the SELECT statement that defines the view.
** Sync the journal. In other words, make sure all the pages that have
** been written to the journal have actually reached the surface of the
** disk and can be restored in the event of a hot-journal rollback.
**
** If the Pager.noSync flag is set, then this function is a no-op.
** Otherwise, the actions required depend on the journal-mode and the
** device characteristics of the file-system, as follows:
**
** * If the journal file is an in-memory journal file, no action need
** be taken.
**
** * Otherwise, if the device does not support the SAFE_APPEND property,
** then the nRec field of the most recently written journal header
** is updated to contain the number of journal records that have
** been written following it. If the pager is operating in full-sync
** mode, then the journal file is synced before this field is updated.
**
** * If the device does not support the SEQUENTIAL property, then
** journal file is synced.
**
** Or, in pseudo-code:
**
** if( NOT <in-memory journal> ){
** if( NOT SAFE_APPEND ){
** if( <full-sync mode> ) xSync(<journal file>);
** <update nRec field>
** }
** if( NOT SEQUENTIAL ) xSync(<journal file>);
** }
**
** If successful, this routine clears the PGHDR_NEED_SYNC flag of every
** page currently held in memory before returning SQLITE_OK. If an IO
** error is encountered, then the IO error code is returned to the caller.
** Obtain or release the mutex needed to access global data structures.
** Open a new database handle.
Number of sub-vdbes seen so far
The antipenultimate character of the master journal name must
** be "9" to avoid name collisions when using 8+3 filenames.
If the blob handle is not open at this point, open it and seek
** to the requested entry.
** Convert a Microsoft Unicode string to UTF-8.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
Close the open database handle and VFS object.
Fsync the rollback journal before
** writing this page to the database
Opcode: SCopy P1 P2 * * *
** Synopsis: r[P2]=r[P1]
**
** Make a shallow copy of register P1 into register P2.
**
** This instruction makes a shallow copy of the value. If the value
** is a string or blob, then the copy is only a pointer to the
** original and hence if the original changes so will the copy.
** Worse, if the original is deallocated, the copy becomes invalid.
** Thus the program must guarantee that the original will not change
** during the lifetime of the copy. Use OP_Copy to make a complete
** copy.
Code generator context
If the log file is not already open, but does exist in the file-system,
** it may need to be checkpointed before the connection can switch to
** rollback mode. Open it now so this can happen.
Used to build up table PK declaration
Number of bytes written by seekAndWrite
comment: If ORDER BY makes no difference in the output then neither does
** DISTINCT so it can be removed too.
label: code-design
** Convert OP_Column opcodes to OP_Copy in previously generated code.
**
** This routine runs over generated VDBE code and translates OP_Column
** opcodes into OP_Copy when the table is being accessed via co-routine
** instead of via table lookup.
**
** If the bIncrRowid parameter is 0, then any OP_Rowid instructions on
** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
** then each OP_Rowid is transformed into an instruction to increment the
** value stored in its output register.
This is an mmap page object
Jump here to continue with next row
** Add an entry to the in-memory hash table. The key is the concatenation
** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
**
** (bByte || pToken) -> (iRowid,iCol,iPos)
**
** Or, if iCol is negative, then the value is a delete marker.
Big-endian salt values
The automatic index is partial
** Free an iterator allocated by walIteratorInit().
orconf ::= OR resolvetype
Move the page currently at pgnoRoot to pgnoMove.
zJournal
True to enable core mutexing
** Malloc and Free functions
First leaf page number in segment
Pointer to current cell in pPage
Index to search
************* Begin file delete.c *****************************************
Most recent seek operation on this cursor
Populated object for xBestIndex
4
** Configuration settings for an individual database connection
OUT: Number of tokens in query
** This is a public wrapper for the winUnicodeToUtf8() function.
26
This index is not unique over the IN RHS columns
The current term of the first nMerge entries in the array
** of Fts3SegReader objects is the same. The doclists must be merged
** and a single term returned with the merged doclist.
YYNOERRORRECOVERY
Integer sum
Special case: WHERE terms that do not refer to any tables in the join
** (constant expressions). Evaluate each such term, and jump over all the
** generated code if the result is not true.
**
** Do not do this if the expression contains non-deterministic functions
** that are not within a sub-select. This is not strictly required, but
** preserves SQLite's legacy behaviour in the following two cases:
**
** FROM ... WHERE random()>0; -- eval random() once per row
** FROM ... WHERE (SELECT random())>0; -- eval random() once overall
************* End of opcodes.c ********************************************
Pagesize after VACUUM if >0
** If the WAL file is currently larger than nMax bytes in size, truncate
** it to exactly nMax bytes. If an error occurs while doing so, ignore it.
Set the output variables.
blobSeekToRow() will initialize r[1] to the desired rowid
input we are tokenizing
comment: OUT: Error message (sqlite3_malloc)
label: code-design
Base register
** Resize the hash table by doubling the number of slots.
This function is only available internally, it is not part of the
** external API. It works in a similar way to sqlite3_value_text(),
** except the data returned is in the encoding specified by the second
** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
** SQLITE_UTF8.
**
** (2006-02-16:) The enc value can be or-ed with SQLITE_UTF16_ALIGNED.
** If that is the case, then the result must be aligned on an even byte
** boundary.
RHS is an integer
** Return the offset of frame iFrame in the write-ahead log file,
** assuming a database page size of szPage bytes. The offset returned
** is to the start of the write-ahead log frame-header.
PageWriter object
True for an UPDATE or DELETE
This variable holds the process id (pid) from when the xRandomness()
** method was called. If xOpen() is called from a different process id,
** indicating that a fork() has occurred, the PRNG will be reset.
The list is being searched and this trunk page is the page
** to allocate, regardless of whether it has leaves.
synopsis: data=r[P3@P2]
Array of column names for fts3 table
** CAPI3REF: Return The Filename For A Database Connection
** METHOD: sqlite3
**
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
** associated with database N of connection D. ^The main database file
** has the name "main". If there is no attached database N on the database
** connection D, or if database N is a temporary or in-memory database, then
** a NULL pointer is returned.
**
** ^The filename returned by this function is the output of the
** xFullPathname method of the [VFS]. ^In other words, the filename
** will be an absolute pathname, even if the filename used
** to open the database originally was a URI or relative pathname.
Time when query started - used for profiling
if non zero missing dirs will be created
** If node pLeaf is not the root of the r-tree and its pParent pointer is
** still NULL, load all ancestor nodes of pLeaf into memory and populate
** the pLeaf->pParent chain all the way up to the root node.
**
** This operation is required when a row is deleted (or updated - an update
** is implemented as a delete followed by an insert). SQLite provides the
** rowid of the row to delete, which can be used to find the leaf on which
** the entry resides (argument pLeaf). Once the leaf is located, this
** function is called to determine its ancestry.
comment: Make copies of constant WHERE-clause terms in the outer query down
** inside the subquery. This can help the subquery to run more efficiently.
label: code-design
SQL name of the function.
Decoded structure object
** Attempt to transform a query of the form
**
** SELECT count(*) FROM (SELECT x FROM t1 UNION ALL SELECT y FROM t2)
**
** Into this:
**
** SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2)
**
** The transformation only works if all of the following are true:
**
** * The subquery is a UNION ALL of two or more terms
** * There is no WHERE or GROUP BY or HAVING clauses on the subqueries
** * The outer query is a simple count(*)
**
** Return TRUE if the optimization is undertaken.
Offset within aMemory of next record
Add the new BtShared object to the linked list sharable BtShareds.
OUT: Bitmask of phrases covered
Analyze the right-child page of internal pages
Opcode: SqlExec * * * P4 *
**
** Run the SQL statement or statements specified in the P4 string.
Flags passed through to sqlite3_vfs.xOpen()
** This routine is called to report the final ")" that terminates
** a CREATE TABLE statement.
**
** The table structure that other action routines have been building
** is added to the internal hash tables, assuming no errors have
** occurred.
**
** An entry for the table is made in the master table on disk, unless
** this is a temporary table or db->init.busy==1. When db->init.busy==1
** it means we are reading the sqlite_master table because we just
** connected to the database or because the sqlite_master table has
** recently changed, so the entry for this table already exists in
** the sqlite_master table. We do not want to create it again.
**
** If the pSelect argument is not NULL, it means that this routine
** was called to create a table generated from a
** "CREATE TABLE ... AS SELECT ..." statement. The column names of
** the new table will match the result set of the SELECT.
Reprepare only called for prepare_v2() statements
The name-context to resolve expressions in
Docid of the row pCsr points to
exponent of real numbers
True if some process holds a RESERVED lock
Tables that might satisfy case 1
Size of pCsr->pKeyInfo in bytes
** DO NOT EDIT THIS MACHINE GENERATED FILE.
Verify condition (2): If cells are moving right, update iPg
** only after iPg+1 has already been updated.
The current column index in pp1
For this path res2 must be exactly 0 or 1
If there are no other statements currently running, then
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
** from interrupting a statement that has not yet started.
** Write a set of frames to the log. The caller must hold the write-lock
** on the log file (obtained using sqlite3WalBeginWriteTransaction()).
SEMI => nothing
Number of segments to merge (iLevel>=0)
Extra prerequesites for using this table
Does the table have a rowid
OUT: malloc'd buffer containing str/bw
If the database file is corrupt, it is possible for the value of idx
** to be invalid here. This can only occur if a second cursor modifies
** the page while cursor pCur is holding a reference to it. Which can
** only happen if the database is corrupt in such a way as to link the
** page into more than one b-tree structure.
** Check to see if pIndex uses the collating sequence pColl. Return
** true if it does and false if it does not.
Size threshold above which reanalysis is needd
Context for sqlite3_result_xxx() calls
create_table_args ::= LP columnlist conslist_opt RP table_options
** The rollback journal is composed of a linked list of these structures.
**
** The zChunk array is always at least 8 bytes in size - usually much more.
** Its actual size is stored in the MemJournal.nChunkSize variable.
** When compiling the test fixture or with debugging enabled (on Win32),
** this variable being set to non-zero will cause OSTRACE macros to emit
** extra diagnostic information.
The function definition object
** Find a tokenizer. This is the implementation of the
** fts5_api.xFindTokenizer() method.
** Pop the parser's stack once.
**
** If there is a destructor routine associated with the token which
** is popped from the stack, then call it.
When opening a zero-size database, the findInodeInfo() procedure
** writes a single byte into that file in order to work around a bug
** in the OS-X msdos filesystem. In order to avoid problems with upper
** layers, we need to report this file size as zero even though it is
** really 1. Ticket #3260.
This is the (easy) common case where the entire payload fits
** on the local page. No overflow is required.
the HAVING clause
comment: Try 3 times to get the pending lock. This is needed to work
** around problems caused by indexing and/or anti-virus software on
** Windows systems.
** If you are using this code as a model for alternative VFSes, do not
** copy this retry logic. It is a hack intended for Windows only.
label: code-design
Database filenames are double-zero terminated if they are not
** URIs with parameters. Hence, they can always be passed into
** sqlite3_uri_parameter().
Save the positions of all other cursors open on this table. This is
** required in case any of them are holding references to an xFetch
** version of the b-tree page modified by the accessPayload call below.
**
** Note that pCsr must be open on a INTKEY table and saveCursorPosition()
** and hence saveAllCursors() cannot fail on a BTREE_INTKEY table, hence
** saveAllCursors can only return SQLITE_OK.
THEN
** Return the Btree pointer identified by zDbName. Return NULL if not found.
expr ::= exprlist
xFindMethod
Number of hash collisions remaining
wait 10 sec and try the lock again
** Translate a single UTF-8 character. Return the unicode value.
**
** During translation, assume that the byte that zTerm points
** is a 0x00.
**
** Write a pointer to the next unread byte back into *pzNext.
**
** Notes On Invalid UTF-8:
**
** * This routine never allows a 7-bit character (0x00 through 0x7f) to
** be encoded as a multi-byte character. Any multi-byte character that
** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
**
** * This routine never allows a UTF16 surrogate value to be encoded.
** If a multi-byte character attempts to encode a value between
** 0xd800 and 0xe000 then it is rendered as 0xfffd.
**
** * Bytes in the range of 0x80 through 0xbf which occur as the first
** byte of a character are interpreted as single-byte characters
** and rendered as themselves even though they are technically
** invalid characters.
**
** * This routine accepts over-length UTF8 encodings
** for unicode values 0x80 and greater. It does not change over-length
** encodings to 0xfffd as some systems recommend.
Device number
Content to be written
FTS virtual table handle
Transfer the FROM clause terms from the subquery into the
** outer query.
** Invoke the VDBE coverage callback, if that callback is defined. This
** feature is used for test suite validation only and does not appear an
** production builds.
**
** M is an integer, 2 or 3, that indices how many different ways the
** branch can go. It is usually 2. "I" is the direction the branch
** goes. 0 means falls through. 1 means branch is taken. 2 means the
** second alternative branch is taken.
**
** iSrcLine is the source code line (from the __LINE__ macro) that
** generated the VDBE instruction. This instrumentation assumes that all
** source code is in a single file (the amalgamation). Special values 1
** and 2 for the iSrcLine parameter mean that this particular branch is
** always taken or never taken, respectively.
** The following routines are substitutes for constants SQLITE_CORRUPT,
** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
** constants. They serve two purposes:
**
** 1. Serve as a convenient place to set a breakpoint in a debugger
** to detect when version error conditions occurs.
**
** 2. Invoke sqlite3_log() to provide the source code location where
** a low-level error is first detected.
comment:
** Translate a string containing an fts5vocab table type to an
** FTS5_VOCAB_XXX constant. If successful, set *peType to the output
** value and return SQLITE_OK. Otherwise, set *pzErr to an error message
** and return SQLITE_ERROR.
label: code-design
************* Begin file os_unix.c ****************************************
** If expression pExpr is of type TK_SELECT, generate code to evaluate
** it. Return the register in which the result is stored (or, if the
** sub-select returns more than one column, the first in an array
** of registers in which the result is stored).
**
** If pExpr is not a TK_SELECT expression, return 0.
EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
** single argument which is a pointer to an sqlite3_pcache_methods2
** object. This object specifies the interface to a custom page cache
** implementation.
Register for new.* values
cmd ::= create_vtab LP vtabarglist RP
The state of the parser is completely contained in an instance of
** the following structure
0x50 .. 0x5F
The requested data is not all available in the in-memory buffer.
** In this case, allocate space at p->aAlloc[] to copy the requested
** range into. Then return a copy of pointer p->aAlloc to the caller.
Prepared statement in use by the cursor
The index to be created
NULL or constants 0 or 1
Delete any auxdata allocations made by the VM
** CAPI3REF: Extended Result Codes
** KEYWORDS: {extended result code definitions}
**
** In its default configuration, SQLite API routines return one of 30 integer
** [result codes]. However, experience has shown that many of
** these result codes are too coarse-grained. They do not provide as
** much information about problems as programmers might like. In an effort to
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
** and later) include
** support for additional result codes that provide more detailed information
** about errors. These [extended result codes] are enabled or disabled
** on a per database connection basis using the
** [sqlite3_extended_result_codes()] API. Or, the extended code for
** the most recent error can be obtained using
** [sqlite3_extended_errcode()].
Used to iterate through tokens
Label for the start of the merge algorithm
0x0c
comment:
** The type for a callback function.
** This is legacy and deprecated. It is included for historical
** compatibility and is not documented.
label: documentation
Current row as a Stat4Sample
OUT: The page number of the next page
Return open Btree* here
1520
Variable tname now contains the token that is the old table-name
** in the CREATE TRIGGER statement.
Invoked by sqlite3FaultSim()
** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
** type of join. Return an integer constant that expresses that type
** in terms of the following bit values:
**
** JT_INNER
** JT_CROSS
** JT_OUTER
** JT_NATURAL
** JT_LEFT
** JT_RIGHT
**
** A full outer join is the combination of JT_LEFT and JT_RIGHT.
**
** If an illegal or unsupported join type is seen, then still return
** a join type, but put an error in the pParse structure.
*****************************************************************************
**************** Non-locking sqlite3_file methods *****************************
**
** The next division contains implementations for all methods of the
** sqlite3_file object other than the locking methods. The locking
** methods were defined in divisions above (one locking method per
** division). Those methods that are common to all locking modes
** are gather together into this division.
For each expression in pEList that is a copy of an expression in
** the ORDER BY clause (pSort->pOrderBy), set the associated
** iOrderByCol value to one more than the index of the ORDER BY
** expression within the sort-key that pushOntoSorter() will generate.
** This allows the pEList field to be omitted from the sorted record,
** saving space and CPU cycles.
Code the current SELECT into temporary table "tab2"
Pad transactions out to the next sector
** We already know that pExpr is a binary operator where both operands are
** column references. This routine checks to see if pExpr is an equivalence
** relation:
** 1. The SQLITE_Transitive optimization must be enabled
** 2. Must be either an == or an IS operator
** 3. Not originating in the ON clause of an OUTER JOIN
** 4. The affinities of A and B must be compatible
** 5a. Both operands use the same collating sequence OR
** 5b. The overall collating sequence is BINARY
** If this routine returns TRUE, that means that the RHS can be substituted
** for the LHS anyplace else in the WHERE clause where the LHS column occurs.
** This is an optimization. No harm comes from returning 0. But if 1 is
** returned when it should not be, then incorrect answers might result.
If we cannot open the rollback journal file in order to see if
** it has a zero header, that might be due to an I/O error, or
** it might be due to the race condition described above and in
** ticket #3883. Either way, assume that the journal is hot.
** This might be a false positive. But if it is, then the
** automatic journal playback and recovery mechanism will deal
** with it under an EXCLUSIVE lock where we do not need to
** worry so much with race conditions.
** Get the RtreeNode for the search point with the lowest score.
** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON
** object that contains all name/value given in arguments. Or if any name
** is not a string or if any value is a BLOB, throw an error.
Smallest sample larger than or equal to pRec
** A cell with the same content as pCell has just been inserted into
** the node pNode. This function updates the bounding box cells in
** all ancestor elements.
comment: TODO: Could use temporary registers here. Also could attempt to
** avoid copying the contents of the rowid register.
label: code-design
** The default number of frames to accumulate in the log file before
** checkpointing the database in WAL mode.
** Initialize a preallocated WhereClause structure.
Error if integer primary key greater than this
Digits
Reparse everything to update our internal data structures
Conflict resolution algorithm
SAVEPOINT
325
1030
value of function parameters
OUT: Database page number for frame
Obtain a reference to the leaf node that contains the entry
** about to be deleted.
aMI[iCol*3 + 1] = Number of occurrences
** aMI[iCol*3 + 2] = Number of rows containing at least one instance
Stop accumulating errors when this reaches zero
** CAPI3REF: Free Memory Used By A Database Connection
** METHOD: sqlite3
**
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
** memory as possible from database connection D. Unlike the
** [sqlite3_release_memory()] interface, this interface is in effect even
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
** omitted.
**
** See also: [sqlite3_release_memory()]
comment:
** Append a term and (optionally) doclist to the FTS segment node currently
** stored in blob *pNode. The node need not contain any terms, but the
** header must be written before this function is called.
**
** A node header is a single 0x00 byte for a leaf node, or a height varint
** followed by the left-hand-child varint for an internal node.
**
** The term to be appended is passed via arguments zTerm/nTerm. For a
** leaf node, the doclist is passed as aDoclist/nDoclist. For an internal
** node, both aDoclist and nDoclist must be passed 0.
**
** If the size of the value in blob pPrev is zero, then this is the first
** term written to the node. Otherwise, pPrev contains a copy of the
** previous term. Before this function returns, it is updated to contain a
** copy of zTerm/nTerm.
**
** It is assumed that the buffer associated with pNode is already large
** enough to accommodate the new entry. The buffer associated with pPrev
** is extended by this function if requrired.
**
** If an error (i.e. OOM condition) occurs, an SQLite error code is
** returned. Otherwise, SQLITE_OK.
label: code-design
** Return a "position-list blob" corresponding to the current position of
** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
** the current position-list for each phrase in the query associated with
** cursor pCsr.
**
** A position-list blob begins with (nPhrase-1) varints, where nPhrase is
** the number of phrases in the query. Following the varints are the
** concatenated position lists for each phrase, in order.
**
** The first varint (if it exists) contains the size of the position list
** for phrase 0. The second (same disclaimer) contains the size of position
** list 1. And so on. There is no size field for the final position list,
** as it can be derived from the total size of the blob.
The maximum supported page-size is 65536 bytes. This means that
** the maximum number of record bytes stored on an index B-Tree
** page is less than 16384 bytes and may be stored as a 2-byte
** varint. This information is used to attempt to avoid parsing
** the entire cell by checking for the cases where the record is
** stored entirely within the b-tree page by inspecting the first
** 2 bytes of the cell.
expr ::= PLUS expr
expr ::= colset COLON LP expr RP
208
0x17
Use sqlite3EndTable() to add the view to the SQLITE_MASTER table
************* Begin file rtree.h ******************************************
Number of values to buffer
Source registers if SQLITE_ECEL_REF
Caused by OOM in sqlite3KeyInfoAlloc()
Return the sqlite3_file object for the WAL file
Pointer into the body of aDoclist
** Open a new iterator to iterate though all rowids that match the
** specified token or token prefix.
synopsis: accum=r[P1] N=P2
xCommit
Combined size of cells placed on i-th page
** A single object of this type is allocated when the FTS5 module is
** registered with a database handle. It is used to store pointers to
** all registered FTS5 extensions - tokenizers and auxiliary functions.
Control reaches here if best-so-far path pTo=aTo[jj] covers the
** same set of loops and has the same isOrdered setting as the
** candidate path. Check to see if the candidate should replace
** pTo or if the candidate should be skipped.
**
** The conditional is an expanded vector comparison equivalent to:
** (pTo->rCost,pTo->nRow,pTo->rUnsorted) <= (rCost,nOut,rUnsorted)
Persistent WAL mode
Fields below are only available in SQLite 3.8.2 and later
case_else
content
MJ checksum value read from journal
Promote anything this size or smaller
Callback information
************* End of vdbetrace.c ******************************************
OP_Delete: index in a DELETE op
Count the tokens in this AND/NEAR cluster. If none of the doclists
** associated with the tokens spill onto overflow pages, or if there is
** only 1 token, exit early. No tokens to defer in this case.
In direct mode, reference the sorting index rather
** than the source table
Write the aPgno[] array entry and the hash-table slot.
OUTPUT: Collation sequence name
endif pGroupBy. Begin aggregate queries without GROUP BY:
Name of the WAL file
Indexed columns affinity
This iterator is already at EOF for this column.
Opcode: VOpen P1 * * P4 *
**
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
** P1 is a cursor number. This opcode opens a cursor to the virtual
** table and stores that cursor in P1.
810
** Return the size of a BtCursor object in bytes.
**
** This interfaces is needed so that users of cursors can preallocate
** sufficient storage to hold a cursor. The BtCursor object is opaque
** to users so they cannot do the sizeof() themselves - they must call
** this routine.
Link the new Index structure to its table and to the other
** in-memory database structures.
Index in b.paCell[] of cell after i-th page
Set up the new page-index array
NB: zFilename exists and remains valid until the file is closed
** according to requirement F11141. So we do not need to make a
** copy of the filename.
** End of interface to code in fts5.c.
*************************************************************************
non-decimal integer types. %x %o
** Added for 3.5.0
If non-zero, increment the row change counter
Step 5a.
Close a pragma virtual table cursor
same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2]
comment: The xBestIndex method of this virtual table requires an estimate of
** the number of rows in the virtual table to calculate the costs of
** various strategies. If possible, this estimate is loaded from the
** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
** Otherwise, if no sqlite_stat1 entry is available, use
** RTREE_DEFAULT_ROWEST.
label: code-design
explain ::= EXPLAIN
The prepared statement
This function (for internal use only) locates an element in an
** hash table that matches the given key. If no element is found,
** a pointer to a static null element with HashElem.data==0 is returned.
** If pH is not NULL, then the hash for this key is written to *pH.
** Field iChng of the index being scanned has changed. So at this point
** p->current contains a sample that reflects the previous row of the
** index. The value of anEq[iChng] and subsequent anEq[] elements are
** correct at this point.
An integer primary key. If the table has an explicit IPK, use
** its name. Otherwise, use "rbu_rowid".
Database
comment: Total of all malloc calls - includes internal frag
label: code-design
Number of sorting key columns, including OP_Sequence
A hidden column in a virtual table
If the "last page" field of the wal-index header snapshot is 0, then
** no data will be read from the wal under any circumstances. Return early
** in this case as an optimization. Likewise, if pWal->readLock==0,
** then the WAL is ignored by the reader so return early, as if the
** WAL were empty.
TK_GT
281
Associated database handle
Allocate and populate the array to return.
CURRENT_TIMESTAMP
Register for column value
** Set both the "read version" (single byte at byte offset 18) and
** "write version" (single byte at byte offset 19) fields in the database
** header to iVersion.
Number of references to columns in pSrcList
0: (end_constraints && !bRev && !endEq)
** Estimated quantities used for query planning are stored as 16-bit
** logarithms. For quantity X, the value stored is 10*log2(X). This
** gives a possible range of values of approximately 1.0e986 to 1e-986.
** But the allowed values are "grainy". Not every value is representable.
** For example, quantities 16 and 17 are both represented by a LogEst
** of 40. However, since LogEst quantities are suppose to be estimates,
** not exact values, this imprecision is not a problem.
**
** "LogEst" is short for "Logarithmic Estimate".
**
** Examples:
** 1 -> 0 20 -> 43 10000 -> 132
** 2 -> 10 25 -> 46 25000 -> 146
** 3 -> 16 100 -> 66 1000000 -> 199
** 4 -> 20 1000 -> 99 1048576 -> 200
** 10 -> 33 1024 -> 100 4294967296 -> 320
**
** The LogEst can be negative to indicate fractional values.
** Examples:
**
** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
fall-through
315
Double-check that the aSyscall[] array has been constructed
** correctly. See ticket [bb3a86e890c8e96ab]
Set useTempTable to TRUE if the result of the SELECT statement
** should be written into a temporary table (template 4). Set to
** FALSE if each output row of the SELECT can be written directly into
** the destination table (template 3).
**
** A temp table must be used if the table being updated is also one
** of the tables being read by the SELECT statement. Also use a
** temp table in the case of row triggers.
249
0x00 .. 0x0F
** This is the top-level implementation of sqlite3_step(). Call
** sqlite3Step() to do most of the work. If a schema error occurs,
** call sqlite3Reprepare() and try again.
Bind values to this statement
When the number of output rows reaches nRow, that means the
** listing has finished and sqlite3_step() should return SQLITE_DONE.
** nRow is the sum of the number of rows in the main program, plus
** the sum of the number of rows in all trigger subprograms encountered
** so far. The nRow value will increase as new trigger subprograms are
** encountered, but p->pc will eventually catch up to nRow.
Opcode: OpenWrite P1 P2 P3 P4 P5
** Synopsis: root=P2 iDb=P3
**
** Open a read/write cursor named P1 on the table or index whose root
** page is P2. Or if P5!=0 use the content of register P2 to find the
** root page.
**
** The P4 value may be either an integer (P4_INT32) or a pointer to
** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
** structure, then said structure defines the content and collating
** sequence of the index being opened. Otherwise, if P4 is an integer
** value, it is set to the number of columns in the table, or to the
** largest index of any column of the table that is actually used.
**
** This instruction works just like OpenRead except that it opens the cursor
** in read/write mode. For a given table, there can be one or more read-only
** cursors or a single read/write cursor but not both.
**
** See also OpenRead.
** This routine walks an expression tree and resolves references to
** table columns and result-set columns. At the same time, do error
** checking on function usage and set a flag if any aggregate functions
** are seen.
**
** To resolve table columns references we look for nodes (or subtrees) of the
** form X.Y.Z or Y.Z or just Z where
**
** X: The name of a database. Ex: "main" or "temp" or
** the symbolic name assigned to an ATTACH-ed database.
**
** Y: The name of a table in a FROM clause. Or in a trigger
** one of the special names "old" or "new".
**
** Z: The name of a column in table Y.
**
** The node at the root of the subtree is modified as follows:
**
** Expr.op Changed to TK_COLUMN
** Expr.pTab Points to the Table object for X.Y
** Expr.iColumn The column index in X.Y. -1 for the rowid.
** Expr.iTable The VDBE cursor number for X.Y
**
**
** To resolve result-set references, look for expression nodes of the
** form Z (with no X and Y prefix) where the Z matches the right-hand
** size of an AS clause in the result-set of a SELECT. The Z expression
** is replaced by a copy of the left-hand side of the result-set expression.
** Table-name and function resolution occurs on the substituted expression
** tree. For example, in:
**
** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY x;
**
** The "x" term of the order by is replaced by "a+b" to render:
**
** SELECT a+b AS x, c+d AS y FROM t1 ORDER BY a+b;
**
** Function calls are checked to make sure that the function is
** defined and that the correct number of arguments are specified.
** If the function is an aggregate function, then the NC_HasAgg flag is
** set and the opcode is changed from TK_FUNCTION to TK_AGG_FUNCTION.
** If an expression contains aggregate functions then the EP_Agg
** property on the expression is set.
**
** An error message is left in pParse if anything is amiss. The number
** if errors is returned.
Table into which to insert
All pages of the b-tree have been visited. Return successfully.
EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
** 61 74 20 33 00.
** Generate the end of the WHERE loop. See comments on
** sqlite3WhereBegin() for additional information.
new.* record for first change
Size of each page in pPage[]
** Allocate the index structure.
bCoreMutex
Number of entries in azCol[]
True if one or more PMAs created
table leaf
Used when p4type is P4_REAL
** The fsync() system call does not work as advertised on many
** unix systems. The following procedure is an attempt to make
** it work better.
**
** The SQLITE_NO_SYNC macro disables all fsync()s. This is useful
** for testing when we want to run through the test suite quickly.
** You are strongly advised *not* to deploy with SQLITE_NO_SYNC
** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
** or power failure will likely corrupt the database file.
**
** SQLite sets the dataOnly flag if the size of the file is unchanged.
** The idea behind dataOnly is that it should only write the file content
** to disk, not the inode. We only set dataOnly if the file size is
** unchanged since the file size is part of the inode. However,
** Ted Ts'o tells us that fdatasync() will also write the inode if the
** file size has changed. The only real difference between fdatasync()
** and fsync(), Ted tells us, is that fdatasync() will not flush the
** inode if the mtime or owner or other inode attributes have changed.
** We only care about the file size, not the other file attributes, so
** as far as SQLite is concerned, an fdatasync() is always adequate.
** So, we always use fdatasync() if it is available, regardless of
** the value of the dataOnly flag.
IMP: R-33038-09382
Fts5Storage object
** This function is the implementation of both the xConnect and xCreate
** methods of the FTS3 virtual table.
**
** The argv[] array contains the following:
**
** argv[0] -> module name ("fts5vocab")
** argv[1] -> database name
** argv[2] -> table name
**
** then:
**
** argv[3] -> name of fts5 table
** argv[4] -> type of fts5vocab table
**
** or, for tables in the TEMP schema only.
**
** argv[3] -> name of fts5 tables database
** argv[4] -> name of fts5 table
** argv[5] -> type of fts5vocab table
synopsis: key=r[P2@P3]
Size of the header
** Add term zTerm to the SegmentNode. It is guaranteed that zTerm is larger
** (according to memcmp) than the previous term.
** Reset the PRNG back to its uninitialized state. The next call
** to sqlite3_randomness() will reseed the PRNG using a single call
** to the xRandomness method of the default VFS.
Comparison result
comment: Special Comments:
**
** Some comments have special meaning to the tools that measure test
** coverage:
**
** NO_TEST - The branches on this line are not
** measured by branch coverage. This is
** used on lines of code that actually
** implement parts of coverage testing.
**
** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
** and the correct answer is still obtained,
** though perhaps more slowly.
**
** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
** and the correct answer is still obtained,
** though perhaps more slowly.
**
** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
** that would be harmless and undetectable
** if it did occur.
**
** In all cases, the special comment must be enclosed in the usual
** slash-asterisk...asterisk-slash comment marks, with no spaces between the
** asterisks and the comment text.
label: test
comment:
** The following parameters determine how many adjacent pages get involved
** in a balancing operation. NN is the number of neighbors on either side
** of the page that participate in the balancing operation. NB is the
** total number of pages that participate, including the target page and
** NN neighbors on either side.
**
** The minimum value of NN is 1 (of course). Increasing NN above 1
** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
** in exchange for a larger degradation in INSERT and UPDATE performance.
** The value of NN appears to give the best results overall.
label: code-design
Size of zName in bytes
synopsis: r[P3]=vcolumn(P2)
Unpacked record to return
Append cells to the end of the page
** Include the primary Windows SDK header file.
One past the last escaped input char
** Streaming version of sqlite3changeset_invert().
Num. bytes allocated for WhereInfo struct
If pVtab is already in the aVTrans array, return early
Top-level operator. pExpr->op
Maximum PMA size, in bytes. 0==no limit
True at EOF
GROUP
Iterator for looping through Pager.aSavepoint
Original value of pNew->nSkip
Any prepared statement that invokes this opcode will hold mutexes
** on every btree. This is a prerequisite for invoking
** sqlite3InitCallback().
Step 1b
Position list to iterate through
Column containing best snippet
Copy of pCsr->pKeyInfo with db==0
KEY
Temp file for level-0 PMAs
Absolute level just updated
** Clear the YMD and HMS and the TZ
uniqueflag ::=
Acquire a shared lock
The IN expression
Mask of FTS5_TOKEN_* flags
Size of buffer nBuf
Bytes of payload
Type of top-level element
** Potential values for BtCursor.eState.
**
** CURSOR_INVALID:
** Cursor does not point to a valid entry. This can happen (for example)
** because the table is empty or because BtreeCursorFirst() has not been
** called.
**
** CURSOR_VALID:
** Cursor points to a valid entry. getPayload() etc. may be called.
**
** CURSOR_SKIPNEXT:
** Cursor is valid except that the Cursor.skipNext field is non-zero
** indicating that the next sqlite3BtreeNext() or sqlite3BtreePrevious()
** operation should be a no-op.
**
** CURSOR_REQUIRESEEK:
** The table that this cursor was opened on still exists, but has been
** modified since the cursor was last used. The cursor position is saved
** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in
** this state, restoreCursorPosition() can be called to attempt to
** seek the cursor to the saved position.
**
** CURSOR_FAULT:
** An unrecoverable error (an I/O error or a malloc failure) has occurred
** on a different connection that shares the BtShared cache with this
** cursor. The error has left the cache in an inconsistent state.
** Do nothing else with this cursor. Any attempt to use the cursor
** should return the error code stored in BtCursor.skipNext
** Rewind the VDBE back to the beginning in preparation for
** running it.
Label to jump to if WHEN is false
comment:
** Deferred and Immediate FKs
** --------------------------
**
** Foreign keys in SQLite come in two flavours: deferred and immediate.
** If an immediate foreign key constraint is violated,
** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current
** statement transaction rolled back. If a
** deferred foreign key constraint is violated, no action is taken
** immediately. However if the application attempts to commit the
** transaction before fixing the constraint violation, the attempt fails.
**
** Deferred constraints are implemented using a simple counter associated
** with the database handle. The counter is set to zero each time a
** database transaction is opened. Each time a statement is executed
** that causes a foreign key violation, the counter is incremented. Each
** time a statement is executed that removes an existing violation from
** the database, the counter is decremented. When the transaction is
** committed, the commit fails if the current value of the counter is
** greater than zero. This scheme has two big drawbacks:
**
** * When a commit fails due to a deferred foreign key constraint,
** there is no way to tell which foreign constraint is not satisfied,
** or which row it is not satisfied for.
**
** * If the database contains foreign key violations when the
** transaction is opened, this may cause the mechanism to malfunction.
**
** Despite these problems, this approach is adopted as it seems simpler
** than the alternatives.
**
** INSERT operations:
**
** I.1) For each FK for which the table is the child table, search
** the parent table for a match. If none is found increment the
** constraint counter.
**
** I.2) For each FK for which the table is the parent table,
** search the child table for rows that correspond to the new
** row in the parent table. Decrement the counter for each row
** found (as the constraint is now satisfied).
**
** DELETE operations:
**
** D.1) For each FK for which the table is the child table,
** search the parent table for a row that corresponds to the
** deleted row in the child table. If such a row is not found,
** decrement the counter.
**
** D.2) For each FK for which the table is the parent table, search
** the child table for rows that correspond to the deleted row
** in the parent table. For each found increment the counter.
**
** UPDATE operations:
**
** An UPDATE command requires that all 4 steps above are taken, but only
** for FK constraints for which the affected columns are actually
** modified (values must be compared at runtime).
**
** Note that I.1 and D.1 are very similar operations, as are I.2 and D.2.
** This simplifies the implementation a bit.
**
** For the purposes of immediate FK constraints, the OR REPLACE conflict
** resolution is considered to delete rows before the new row is inserted.
** If a delete caused by OR REPLACE violates an FK constraint, an exception
** is thrown, even if the FK constraint would be satisfied after the new
** row is inserted.
**
** Immediate constraints are usually handled similarly. The only difference
** is that the counter used is stored as part of each individual statement
** object (struct Vdbe). If, after the statement has run, its immediate
** constraint counter is greater than zero,
** it returns SQLITE_CONSTRAINT_FOREIGNKEY
** and the statement transaction is rolled back. An exception is an INSERT
** statement that inserts a single row only (no triggers). In this case,
** instead of using a counter, an exception is thrown immediately if the
** INSERT violates a foreign key constraint. This is necessary as such
** an INSERT does not open a statement transaction.
**
** TODO: How should dropping a table be handled? How should renaming a
** table be handled?
**
**
** Query API Notes
** ---------------
**
** Before coding an UPDATE or DELETE row operation, the code-generator
** for those two operations needs to know whether or not the operation
** requires any FK processing and, if so, which columns of the original
** row are required by the FK processing VDBE code (i.e. if FKs were
** implemented using triggers, which of the old.* columns would be
** accessed). No information is required by the code-generator before
** coding an INSERT operation. The functions used by the UPDATE/DELETE
** generation code to query for this information are:
**
** sqlite3FkRequired() - Test to see if FK processing is required.
** sqlite3FkOldmask() - Query for the set of required old.* columns.
**
**
** Externally accessible module functions
** --------------------------------------
**
** sqlite3FkCheck() - Check for foreign key violations.
** sqlite3FkActions() - Code triggers for ON UPDATE/ON DELETE actions.
** sqlite3FkDelete() - Delete an FKey structure.
label: code-design
OUT: Total number of tokens in phrase.
** Handle a 'special' INSERT of the form:
**
** "INSERT INTO tbl(tbl) VALUES(<expr>)"
**
** Argument pVal contains the result of <expr>. Currently the only
** meaningful value to insert is the text 'optimize'.
Bytes written by each WriteFile() call
Jump instructions that get retargetted
IcuCursor
Parent page of siblings being balanced
Non-zero if the rowid or PRIMARY KEY changed
Current rolling back, so do not spill
Resize the hash table so that it cantains "new_size" buckets.
** "new_size" must be a power of 2. The hash table might fail
** to resize if sqliteMalloc() fails.
**
** Return non-zero if a memory allocation error occurs.
Foreign key index for pFKey
Restore the clients cache of the wal-index header to the state it
** was in before the client began writing to the database.
Flags this file was opened with
If the azData[] array contains more than one element, elements
** (azData[2]..azData[argc-1]) contain a new record to insert into
** the r-tree structure.
Dynamically allocated strings. %z
cmd ::= ANALYZE
** This vector defines all the methods that can operate on an
** sqlite3_file for win32 without performing any locking.
Guard word for sanity
Create a new entry if true
All keys of a UNIQUE index used
Current authentication level
Next on a list of sharable BtShared structs
Required space after adding zTerm
PRAGMA integrity_check
** PRAGMA integrity_check(N)
** PRAGMA quick_check
** PRAGMA quick_check(N)
**
** Verify the integrity of the database.
**
** The "quick_check" is reduced version of
** integrity_check designed to detect most database corruption
** without the overhead of cross-checking indexes. Quick_check
** is linear time wherease integrity_check is O(NlogN).
INSTEAD of triggers are only for views and views only support INSTEAD
** of triggers.
xClose
True for toupper(), false for tolower()
Result of special query
xFetch
same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2
comment: *****************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
** version 3.20.0. By combining all the individual C code files into this
** single large file, the entire code can be compiled as a single translation
** unit. This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately. Performance improvements
** of 5% or more are commonly seen when SQLite is compiled as a single
** translation unit.
**
** This file is all you need to compile SQLite. To use SQLite in other
** programs, you need this file and the "sqlite3.h" header file that defines
** the programming interface to the SQLite library. (If you do not have
** the "sqlite3.h" header file at hand, you will find a copy embedded within
** the text of this file. Search for "Begin file sqlite3.h" to find the start
** of the embedded sqlite3.h header file.) Additional code files may be needed
** if you want a wrapper to interface SQLite with your choice of programming
** language. The code for the "sqlite3" command-line shell is also in a
** separate file. This file contains only code for the core SQLite library.
label: code-design
SQLITE_OMIT_BETWEEN_OPTIMIZATION
** Implementation of the upper() and lower() SQL functions.
Total record (payload) size
True if outer SELECT uses aggregate functions
A table interior node. nPayload==0.
0x00
Destructor for the string
*************************************************************************
** Fields above must be initialized to zero. The fields that follow,
** down to the beginning of the recursive section, do not need to be
** initialized as they will be set before being used. The boundary is
** determined by offsetof(Parse,aColCache).
*************************************************************************
Next available select ID for EXPLAIN output
Maximum unsorted cost of a set of path
** The input pBlob is guaranteed to be a Blob that is not marked
** with MEM_Zero. Return true if it could be a zero-blob.
sqlite3OsRead() return code
Ephemeral table used to enforce DISTINCT
Buffer containing next term
'<'. Part of < or <= or <>
Maximum size of zOut
** Generate code that checks the left-most column of index table iCur to see if
** it contains any NULL entries. Cause the register at regHasNull to be set
** to a non-NULL value if iCur contains no NULLs. Cause register regHasNull
** to be set to NULL if iCur contains one or more NULL values.
SQLITE_OMIT_ANALYZE
expr ::= LP nexprlist COMMA expr RP
Single term in FROM clause
** Macros to compute minimum and maximum of two numbers.
The subexpression broken out
** Shutdown the page cache. Free all memory and close all files.
**
** If a transaction was in progress when this routine is called, that
** transaction is rolled back. All outstanding pages are invalidated
** and their memory is freed. Any attempt to use a page associated
** with this page cache after this function returns will likely
** result in a coredump.
**
** This function always succeeds. If a transaction is active an attempt
** is made to roll it back. If an error occurs during the rollback
** a hot journal may be left in the filesystem but no error is returned
** to the caller.
b.szCell
Index of term<=? value in apVal
************* Begin file vdbeapi.c ****************************************
Collating sequence. If NULL, use the default
If the bit corresponding to this variable in Vdbe.expmask is set, then
** binding a new value to this variable invalidates the current query plan.
**
** IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host
** parameter in the WHERE clause might influence the choice of query plan
** for a statement, then the statement will be automatically recompiled,
** as if there had been a schema change, on the first sqlite3_step() call
** following any change to the bindings of that parameter.
Number of columns in parent key
Current offset into pData
** Generate code for scalar subqueries used as a subquery expression, EXISTS,
** or IN operators. Examples:
**
** (SELECT a FROM b) -- subquery
** EXISTS (SELECT a FROM b) -- EXISTS subquery
** x IN (4,5,11) -- IN operator with list on right-hand side
** x IN (SELECT a FROM b) -- IN operator with subquery on the right
**
** The pExpr parameter describes the expression that contains the IN
** operator or subquery.
**
** If parameter isRowid is non-zero, then expression pExpr is guaranteed
** to be of the form "<rowid> IN (?, ?, ?)", where <rowid> is a reference
** to some integer key column of a table B-Tree. In this case, use an
** intkey B-Tree to store the set of IN(...) values instead of the usual
** (slower) variable length keys B-Tree.
**
** If rMayHaveNull is non-zero, that means that the operation is an IN
** (not a SELECT or EXISTS) and that the RHS might contains NULLs.
** All this routine does is initialize the register given by rMayHaveNull
** to NULL. Calling routines will take care of changing this register
** value to non-NULL if the RHS is NULL-free.
**
** For a SELECT or EXISTS operator, return the register that holds the
** result. For a multi-column SELECT, the result is stored in a contiguous
** array of registers and the return value is the register of the left-most
** result column. Return 0 for IN operators or if an error occurs.
comment:
** Do a deep comparison of two expression trees. Return 0 if the two
** expressions are completely identical. Return 1 if they differ only
** by a COLLATE operator at the top level. Return 2 if there are differences
** other than the top-level COLLATE operator.
**
** If any subelement of pB has Expr.iTable==(-1) then it is allowed
** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
**
** The pA side might be using TK_REGISTER. If that is the case and pB is
** not using TK_REGISTER but is otherwise equivalent, then still return 0.
**
** Sometimes this routine will return 2 even if the two expressions
** really are equivalent. If we cannot prove that the expressions are
** identical, we return 2 just to be safe. So if this routine
** returns 2, then you do not really know for certain if the two
** expressions are the same. But if you get a 0 or 1 return, then you
** can be sure the expressions are the same. In the places where
** this routine is used, it does not hurt to get an extra 2 - that
** just might result in some slightly slower code. But returning
** an incorrect 0 or 1 could lead to a malfunction.
**
** If pParse is not NULL then TK_VARIABLE terms in pA with bindings in
** pParse->pReprepare can be matched against literals in pB. The
** pParse->pVdbe->expmask bitmask is updated for each variable referenced.
** If pParse is NULL (the normal case) then any TK_VARIABLE term in
** Argument pParse should normally be NULL. If it is not NULL and pA or
** pB causes a return value of 2.
label: code-design
Info on how to code the DISTINCT keyword
Loop counter: Field of the foreign key
** All default VFSes for unix are contained in the following array.
**
** Note that the sqlite3_vfs.pNext field of the VFS object is modified
** by the SQLite core when the VFS is registered. So the following
** array cannot be const.
Minimum amount of incr-merge work to do
Schema to which this item is fixed
The x subexpression
Inputs
Address of ptr to next freeblock
Top of the loop for inserting rows
Vdbe is guaranteed to have been allocated by this stage.
Number of segment-iters in use
** Access routines. To delete, insert a NULL pointer.
Mark non-alphanumeric ASCII characters as delimiters
** Free any cursor components allocated by sqlite3VdbeSorterXXX routines.
** Check to see if the given expression is of the form
**
** column OP expr
**
** where OP is one of MATCH, GLOB, LIKE or REGEXP and "column" is a
** column of a virtual table.
**
** If it is then return TRUE. If not, return FALSE.
Opcode: Program P1 P2 P3 P4 P5
**
** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
**
** P1 contains the address of the memory cell that contains the first memory
** cell in an array of values used as arguments to the sub-program. P2
** contains the address to jump to if the sub-program throws an IGNORE
** exception using the RAISE() function. Register P3 contains the address
** of a memory cell in this (the parent) VM that is used to allocate the
** memory required by the sub-vdbe at runtime.
**
** P4 is a pointer to the VM containing the trigger program.
**
** If P5 is non-zero, then recursive program invocation is enabled.
Opcode: MemMax P1 P2 * * *
** Synopsis: r[P1]=max(r[P1],r[P2])
**
** P1 is a register in the root frame of this VM (the root frame is
** different from the current frame if this instruction is being executed
** within a sub-program). Set the value of register P1 to the maximum of
** its current value and the value in register P2.
**
** This instruction throws an error if the memory cell is not initially
** an integer.
The third parameter
FTS5 backend to iterate within
Journal file must be open.
Search for an existing table
Cursor returned by porterOpen
Figure out the node size to use.
When an OP_Program opcode is encounter (the only opcode that has
** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
** kept in p->aMem[9].z to hold the new program - assuming this subprogram
** has not already been seen.
Depth of tree according to TreeDepth()
Write number of bytes if zBuf[] used here
For sizes 2 through MX_SMALL, inclusive
Constant "k1" from BM25 formula
Maximum number of prepared UPDATE statements held by this module
** CAPI3REF: Delete A Session Object
**
** Delete a session object previously allocated using
** [sqlite3session_create()]. Once a session object has been deleted, the
** results of attempting to use pSession with any other session module
** function are undefined.
**
** Session objects must be deleted before the database handle to which they
** are attached is closed. Refer to the documentation for
** [sqlite3session_create()] for details.
Right input list
Size of leaf without page-index
** Enter the mutex on every Btree associated with a database
** connection. This is needed (for example) prior to parsing
** a statement since we will be comparing table and column names
** against all schemas and we do not want those schemas being
** reset out from under us.
**
** There is a corresponding leave-all procedures.
**
** Enter the mutexes in accending order by BtShared pointer address
** to avoid the possibility of deadlock when two threads with
** two or more btrees in common both try to lock all their btrees
** at the same instant.
comment:
** CAPI3REF: Deprecated Functions
** DEPRECATED
**
** These functions are [deprecated]. In order to maintain
** backwards compatibility with older code, these functions continue
** to be supported. However, new applications should avoid
** the use of these functions. To encourage programmers to avoid
** these functions, we will not explain what they do.
label: code-design
Pending terms table for this index
If pBuilder->pOrSet is defined, then only keep track of the costs
** and prereqs.
Array of Fts5DlidxWriter objects
Highwater mark for nCurrent
** Do a node lookup using zPath. Return a pointer to the node on success.
** Return NULL if not found or if there is an error.
**
** On an error, write an error message into pCtx and increment the
** pParse->nErr counter.
**
** If pApnd!=NULL then try to append missing nodes and set *pApnd = 1 if
** nodes are appended.
** Insert the sizes (in tokens) for each column of the document
** with docid equal to p->iPrevDocid. The sizes are encoded as
** a blob of varints.
(289) typetoken ::= typename
Truncate very long tokens to this many bytes. Hard limit is
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
** field that occurs at the start of each leaf page (see fts5_index.c).
0: module 1: schema 2: vtab name 3...: args
Name of the table or index to be reindexed
comment: The following are used internally by the fts5_index.c module. They are
** defined here only to make it easier to avoid clashes with the flags
** above.
label: code-design
With this option, sqlite3VtabSync() is defined to be simply
** SQLITE_OK so p is not used.
This block calculates the checksum according to the %_content table
** This function is similar to sqlite3Fts3ExprParse(), with the following
** differences:
**
** 1. It does not do expression rebalancing.
** 2. It does not check that the expression does not exceed the
** maximum allowable depth.
** 3. Even if it fails, *ppExpr may still be set to point to an
** expression tree. It should be deleted using sqlite3Fts3ExprFree()
** in this case.
New value for iStartBlock
If this loop satisfies a sort order (pOrderBy) request that
** was passed to this function to implement a "SELECT min(x) ..."
** query, then the caller will only allow the loop to run for
** a single iteration. This means that the first row returned
** should not have a NULL value stored in 'x'. If column 'x' is
** the first one after the nEq equality constraints in the index,
** this requires some special handling.
trigger_event
************* End of wherecode.c ******************************************
** Allocate a private rbu VFS for the rbu handle passed as the only
** argument. This VFS will be used unless the call to sqlite3rbu_open()
** specified a URI with a vfs=? option in place of a target database
** file name.
BY
Figure out how many bytes of space are required to store explicitly
** specified collation sequence names.
The glob pattern
Source database connection
ERROR: copy command not terminated by ','
aFile[0] for reading, [1] for writing
Advance each iterator that currently points to iRowid. Or, if iFrom
** is valid - each iterator that points to a rowid before iFrom.
Number of opcodes to add
** This is the function signature used for all extension entry points. It
** is also defined in the file "loadext.c".
Since nOpt is normally in single digits, a linear search is
** adequate. No need for a binary search.
Write the first index cursor number here
The minor token to shift in
** An instance of the following structure holds all information about a
** WHERE clause. Mostly this is a container for one or more WhereTerms.
**
** Explanation of pOuter: For a WHERE clause of the form
**
** a AND ((b AND c) OR (d AND e)) AND f
**
** There are separate WhereClause objects for the whole clause and for
** the subclauses "(b AND c)" and "(d AND e)". The pOuter field of the
** subclauses points to the WhereClause object for the whole clause.
Analyze the list of expressions that form the terms of the index and
** report any errors. In the common case where the expression is exactly
** a table column, store that column in aiColumn[]. For general expressions,
** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[].
**
** TODO: Issue a warning if two or more columns of the index are identical.
** TODO: Issue a warning if the table primary key is used as part of the
** index key.
OUT: Adjusted offset
Causes schema cookie check after an error
#include <assert.h>
************* Begin file bitvec.c *****************************************
Make sure the buffer contains at least 10 bytes of input data, or all
** remaining data if there are less than 10 bytes available. This is
** sufficient either for the 'T' or 'P' byte and the varint that follows
** it, or for the two single byte values otherwise.
Address of jump operation
Number of bytes in token
Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT
** Open an rbu file handle.
Set $p to point to the left-most leaf in the tree of eType nodes.
nearset
Max dlidx tree height of 32
Must be so if pLimit==0
Which coordinate to extract
** As part of a tokenchars= or separators= option, the CREATE VIRTUAL TABLE
** statement has specified that the tokenizer for this table shall consider
** all characters in string zIn/nIn to be separators (if bAlnum==0) or
** token characters (if bAlnum==1).
**
** For each codepoint in the zIn/nIn string, this function checks if the
** sqlite3FtsUnicodeIsalnum() function already returns the desired result.
** If so, no action is taken. Otherwise, the codepoint is added to the
** unicode_tokenizer.aiException[] array. For the purposes of tokenization,
** the return value of sqlite3FtsUnicodeIsalnum() is inverted for all
** codepoints in the aiException[] array.
**
** If a standalone diacritic mark (one that sqlite3FtsUnicodeIsdiacritic()
** identifies as a diacritic) occurs in the zIn/nIn string it is ignored.
** It is not possible to change the behavior of the tokenizer with respect
** to these codepoints.
** Ordinarily, if no value is explicitly provided, SQLite creates databases
** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain
** device characteristics (sector-size and atomic write() support),
** SQLite may choose a larger value. This constant is the maximum value
** SQLite will choose on its own.
820
Number of overflow pages to load doclist
** The number of levels of backtrace to save in new allocations.
ASC or DESC
We can reuse a temporary table generated by a SELECT to our
** right.
Current page of the b-tree
comment:
** NOTE: Windows CE is handled differently here due its lack of the Win32
** API LockFile.
label: test
Compressed expressions only appear when parsing the DEFAULT clause
** on a table column definition, and hence only when pCtx==0. This
** check ensures that an EP_TokenOnly expression is never passed down
** into valueFromFunction().
** Alternative compound select code generator for cases when there
** is an ORDER BY clause.
**
** We assume a query of the following form:
**
** <selectA> <operator> <selectB> ORDER BY <orderbylist>
**
** <operator> is one of UNION ALL, UNION, EXCEPT, or INTERSECT. The idea
** is to code both <selectA> and <selectB> with the ORDER BY clause as
** co-routines. Then run the co-routines in parallel and merge the results
** into the output. In addition to the two coroutines (called selectA and
** selectB) there are 7 subroutines:
**
** outA: Move the output of the selectA coroutine into the output
** of the compound query.
**
** outB: Move the output of the selectB coroutine into the output
** of the compound query. (Only generated for UNION and
** UNION ALL. EXCEPT and INSERTSECT never output a row that
** appears only in B.)
**
** AltB: Called when there is data from both coroutines and A<B.
**
** AeqB: Called when there is data from both coroutines and A==B.
**
** AgtB: Called when there is data from both coroutines and A>B.
**
** EofA: Called when data is exhausted from selectA.
**
** EofB: Called when data is exhausted from selectB.
**
** The implementation of the latter five subroutines depend on which
** <operator> is used:
**
**
** UNION ALL UNION EXCEPT INTERSECT
** ------------- ----------------- -------------- -----------------
** AltB: outA, nextA outA, nextA outA, nextA nextA
**
** AeqB: outA, nextA nextA nextA outA, nextA
**
** AgtB: outB, nextB outB, nextB nextB nextB
**
** EofA: outB, nextB outB, nextB halt halt
**
** EofB: outA, nextA outA, nextA outA, nextA halt
**
** In the AltB, AeqB, and AgtB subroutines, an EOF on A following nextA
** causes an immediate jump to EofA and an EOF on B following nextB causes
** an immediate jump to EofB. Within EofA and EofB, and EOF on entry or
** following nextX causes a jump to the end of the select processing.
**
** Duplicate removal in the UNION, EXCEPT, and INTERSECT cases is handled
** within the output subroutine. The regPrev register set holds the previously
** output value. A comparison is made against this value and the output
** is skipped if the next results would be the same as the previous.
**
** The implementation plan is to implement the two coroutines and seven
** subroutines first, then put the control logic at the bottom. Like this:
**
** goto Init
** coA: coroutine for left query (A)
** coB: coroutine for right query (B)
** outA: output one row of A
** outB: output one row of B (UNION and UNION ALL only)
** EofA: ...
** EofB: ...
** AltB: ...
** AeqB: ...
** AgtB: ...
** Init: initialize coroutine registers
** yield coA
** if eof(A) goto EofA
** yield coB
** if eof(B) goto EofB
** Cmpr: Compare A, B
** Jump AltB, AeqB, AgtB
** End: ...
**
** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
** actually called using Gosub and they do not Return. EofA and EofB loop
** until all data is exhausted then jump to the "end" labe. AltB, AeqB,
** and AgtB jump to either L2 or to one of EofA or EofB.
Now that the shift has been done, check if the initial "..." are
** required. They are required if (a) this is not the first fragment,
** or (b) this fragment does not begin at position 0 of its column.
The master-journal page number must never be used as a pointer map page
150
** Unlink the chunk at mem5.aPool[i] from list it is currently
** on. It should be found on mem5.aiFreelist[iLogsize].
These two variables are set by every call to backup_step(). They are
** read by calls to backup_remaining() and backup_pagecount().
Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
** register is initialized with value of LIMIT+OFFSET.) After the sorter
** fills up, delete the least entry in the sorter after each insert.
** Thus we never hold more than the LIMIT+OFFSET rows in memory at once
Table this info block refers to
WAL to write to
comment: WHERE clause term to check
label: code-design
** Reclaim the memory used by an index
P4 is a 64-bit floating point value
Number of names resolved by this context
** Report the current state of file logs for all databases
#ifdef SQLITE_DEBUG
Number of locks to hold
** Return the peak depth of the stack for a parser.
True to update the change-counter
path
Array of offset to rowid fields
Copy the result of the function into register P3
True if SQLITE_BUSY has been encountered
sqlite3SelectExpand() called on this
There exists an unusable MATCH constraint. This means that if
** the planner does elect to use the results of this call as part
** of the overall query plan the user will see an "unable to use
** function MATCH in the requested context" error. To discourage
** this, return a very high cost here.
106
Increment constraint counter by this
221
Statement used to insert the encoding
The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
** of the flags shown below.
**
** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
** indices.)
** Return a pointer to the appropriate hash function given the key class.
**
** For help in interpreted the obscure C code in the function definition,
** see the header comment on the previous function.
TUNING: If there is no likelihood() value, assume that a
** "col IS NULL" expression matches twice as many rows
** as (col=?).
True if integer overflow seen
The bytes to be written
Last byte of buffer to write
No progress was made on the last round.
Expression to iterate phrases of
************* End of mem0.c ***********************************************
Newly allocated page
Current token number of document
IMP: R-04780-55815
comment:
** The following global variables hold counters used for
** testing purposes only. These variables do not exist in
** a non-testing build. These variables are not thread-safe.
label: requirement
Node to return
** Implementation of the stat_init(N,K,C) SQL function. The three parameters
** are:
** N: The number of columns in the index including the rowid/pk (note 1)
** K: The number of columns in the index excluding the rowid/pk.
** C: The number of rows in the index (note 2)
**
** Note 1: In the special case of the covering index that implements a
** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
** total number of columns in the table.
**
** Note 2: C is only used for STAT3 and STAT4.
**
** For indexes on ordinary rowid tables, N==K+1. But for indexes on
** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
** PRIMARY KEY of the table. The covering index that implements the
** original WITHOUT ROWID table as N==K as a special case.
**
** This routine allocates the Stat4Accum object in heap memory. The return
** value is a pointer to the Stat4Accum object. The datatype of the
** return value is BLOB, but it is really just a pointer to the Stat4Accum
** object.
The length of the serialized data for the column
Log2 Size of this block
** Parameter zIn contains a rank() function specification. The format of
** this is:
**
** + Bareword (function name)
** + Open parenthesis - "("
** + Zero or more SQL literals in a comma separated list
** + Close parenthesis - ")"
comment:
** Return a pointer to a human readable string in a static buffer
** containing the state of the Pager object passed as an argument. This
** is intended to be used within debuggers. For example, as an alternative
** to "print *pPager" in gdb:
**
** (gdb) printf "%s", print_pager_state(pPager)
label: code-design
Return value for this function
Write head of the output list here
If true, fsync() directory after deleting file
Figure out the page-size for the database. This is required in order to
** estimate the cost of loading large doclists from the database.
This condition occurs when an earlier OOM in a call to
** sqlite3_value_text() or sqlite3_value_blob() (perhaps from within
** a conflict-handler) has zeroed the pVal->z pointer. Return NOMEM.
Database holding the object
For descending pending seg-readers only
New aiException[] array
List to which to add the span.
Reset schema after an error if positive
Connection mutex
** group_concat(EXPR, ?SEPARATOR?)
FTS table handle
The Parse structure
** Round up a number to the next larger multiple of 8. This is used
** to force 8-byte alignment on 64-bit architectures.
** Check invariants on a Mem object.
**
** This routine is intended for use inside of assert() statements, like
** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
Disable mutex on core
Null-terminated column definition
comment:
** CAPI3REF: Application Defined Page Cache.
** KEYWORDS: {page cache}
**
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
** register an alternative page cache implementation by passing in an
** instance of the sqlite3_pcache_methods2 structure.)^
** In many applications, most of the heap memory allocated by
** SQLite is used for the page cache.
** By implementing a
** custom page cache using this API, an application can better control
** the amount of memory consumed by SQLite, the way in which
** that memory is allocated and released, and the policies used to
** determine exactly which parts of a database file are cached and for
** how long.
**
** The alternative page cache mechanism is an
** extreme measure that is only needed by the most demanding applications.
** The built-in page cache is recommended for most uses.
**
** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
** the application may discard the parameter after the call to
** [sqlite3_config()] returns.)^
**
** [[the xInit() page cache method]]
** ^(The xInit() method is called once for each effective
** call to [sqlite3_initialize()])^
** (usually only once during the lifetime of the process). ^(The xInit()
** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
** The intent of the xInit() method is to set up global data structures
** required by the custom page cache implementation.
** ^(If the xInit() method is NULL, then the
** built-in default page cache is used instead of the application defined
** page cache.)^
**
** [[the xShutdown() page cache method]]
** ^The xShutdown() method is called by [sqlite3_shutdown()].
** It can be used to clean up
** any outstanding resources before process shutdown, if required.
** ^The xShutdown() method may be NULL.
**
** ^SQLite automatically serializes calls to the xInit method,
** so the xInit method need not be threadsafe. ^The
** xShutdown method is only called from [sqlite3_shutdown()] so it does
** not need to be threadsafe either. All other methods must be threadsafe
** in multithreaded applications.
**
** ^SQLite will never invoke xInit() more than once without an intervening
** call to xShutdown().
**
** [[the xCreate() page cache methods]]
** ^SQLite invokes the xCreate() method to construct a new cache instance.
** SQLite will typically create one cache instance for each open database file,
** though this is not guaranteed. ^The
** first parameter, szPage, is the size in bytes of the pages that must
** be allocated by the cache. ^szPage will always a power of two. ^The
** second parameter szExtra is a number of bytes of extra storage
** associated with each page cache entry. ^The szExtra parameter will
** a number less than 250. SQLite will use the
** extra szExtra bytes on each page to store metadata about the underlying
** database page on disk. The value passed into szExtra depends
** on the SQLite version, the target platform, and how SQLite was compiled.
** ^The third argument to xCreate(), bPurgeable, is true if the cache being
** created will be used to cache database pages of a file stored on disk, or
** false if it is used for an in-memory database. The cache implementation
** does not have to do anything special based with the value of bPurgeable;
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
** never invoke xUnpin() except to deliberately delete a page.
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
** false will always have the "discard" flag set to true.
** ^Hence, a cache created with bPurgeable false will
** never contain any unpinned pages.
**
** [[the xCachesize() page cache method]]
** ^(The xCachesize() method may be called at any time by SQLite to set the
** suggested maximum cache-size (number of pages stored by) the cache
** instance passed as the first argument. This is the value configured using
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
** parameter, the implementation is not required to do anything with this
** value; it is advisory only.
**
** [[the xPagecount() page cache methods]]
** The xPagecount() method must return the number of pages currently
** stored in the cache, both pinned and unpinned.
**
** [[the xFetch() page cache methods]]
** The xFetch() method locates a page in the cache and returns a pointer to
** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
** The pBuf element of the returned sqlite3_pcache_page object will be a
** pointer to a buffer of szPage bytes used to store the content of a
** single database page. The pExtra element of sqlite3_pcache_page will be
** a pointer to the szExtra bytes of extra storage that SQLite has requested
** for each entry in the page cache.
**
** The page to be fetched is determined by the key. ^The minimum key value
** is 1. After it has been retrieved using xFetch, the page is considered
** to be "pinned".
**
** If the requested page is already in the page cache, then the page cache
** implementation must return a pointer to the page buffer with its content
** intact. If the requested page is not already in the cache, then the
** cache implementation should use the value of the createFlag
** parameter to help it determined what action to take:
**
** <table border=1 width=85% align=center>
** <tr><th> createFlag <th> Behavior when page is not already in cache
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
** Otherwise return NULL.
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
** NULL if allocating a new page is effectively impossible.
** </table>
**
** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
** will only use a createFlag of 2 after a prior call with a createFlag of 1
** failed.)^ In between the to xFetch() calls, SQLite may
** attempt to unpin one or more cache pages by spilling the content of
** pinned pages to disk and synching the operating system disk cache.
**
** [[the xUnpin() page cache method]]
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
** as its second argument. If the third parameter, discard, is non-zero,
** then the page must be evicted from the cache.
** ^If the discard parameter is
** zero, then the page may be discarded or retained at the discretion of
** page cache implementation. ^The page cache implementation
** may choose to evict unpinned pages at any time.
**
** The cache must not perform any reference counting. A single
** call to xUnpin() unpins the page regardless of the number of prior calls
** to xFetch().
**
** [[the xRekey() page cache methods]]
** The xRekey() method is used to change the key value associated with the
** page passed as the second argument. If the cache
** previously contains an entry associated with newKey, it must be
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
** to be pinned.
**
** When SQLite calls the xTruncate() method, the cache must discard all
** existing cache entries with page numbers (keys) greater than or equal
** to the value of the iLimit parameter passed to xTruncate(). If any
** of these pages are pinned, they are implicitly unpinned, meaning that
** they can be safely discarded.
**
** [[the xDestroy() page cache method]]
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
** All resources associated with the specified cache should be freed. ^After
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
** handle invalid, and will not use it with any other sqlite3_pcache_methods2
** functions.
**
** [[the xShrink() page cache method]]
** ^SQLite invokes the xShrink() method when it wants the page cache to
** free up as much of heap memory as possible. The page cache implementation
** is not obligated to free any memory, but well-behaved implementations should
** do their best.
label: code-design
cmd ::= PRAGMA nm dbnm EQ minus_num
** Free all resources owned by the object indicated by argument pTask. All
** fields of *pTask are zeroed before returning.
Extract the rowid or primary key for the current row
** Implementation of the snippet() function for FTS3
Open proxy lock file
Parsing context. Leave error messages here
Invoke the tokenizer destructor to free the tokenizer.
We have successfully halted and closed the VM. Record this fact.
** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
** test is related to ticket #2565. See the discussion in the
** pager_playback() function for additional information.
** The default size of a database page.
Decrement the shared lock counter. Release the lock using an
** OS call only when all threads in this same process have released
** the lock.
Phrase number
Can be null despite NOT NULL constraint
The date/time value to be modified
Argument to xStress
eCreate value for for xFetch()
Advance past the POS_END terminator byte
Access the row with blockid=$iBlockid
The schema of the expression
Check for the following errors:
**
** * Too many attached databases,
** * Transaction currently open
** * Specified database name already being used.
Anything before the first 0x01 is col 0
Value for "start_block" field
Populate the OLD.* pseudo-table register array. These values will be
** used by any BEFORE and AFTER triggers that exist.
Bytes of data to read
Malloc'd output buffers
Text of MATCH query
State: ** SEMI WS OTHER
REINDEX => ID
Total bytes that could not be allocated
Check for immediate foreign key violations.
** The RBU handle passed as the only argument has just been opened and
** the state database is empty. If this RBU handle was opened for an
** RBU vacuum operation, create the schema in the target db.
300
780
porter rule condition: (*o)
113
Restrictions (8)(9)
Number of columns in the FTS table
************* End of mem3.c ***********************************************
** Each database connection is an instance of the following structure.
Index of database to analyze
** Implementation of fts5_source_id() function.
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
Generate a subroutine to run when the results from select A
** are exhausted and only data in select B remains.
skip non-significant significand digits
** (increase exponent by d to shift decimal left)
640
A NOTFOUND or DATA error. Search the table to see if it contains
** a row with a matching primary key. If so, this is a DATA conflict.
** Otherwise, if there is no primary key match, it is a NOTFOUND.
Opcode: EndCoroutine P1 * * * *
**
** The instruction at the address in register P1 is a Yield.
** Jump to the P2 parameter of that Yield.
** After the jump, register P1 becomes undefined.
**
** See also: InitCoroutine
Number of columns
True if RTree holds integer coordinates
5th argument to snippet()
Search through to find the first varint with value 1. This is the
** start of the next columns hits.
Set up the transaction-counter change checking flags when
** transitioning from a SHARED to a RESERVED lock. The change
** from SHARED to RESERVED marks the beginning of a normal
** write operation (not a hot journal rollback).
** Read data from an rbuVfs-file.
We are currently listing subprograms. Figure out which one and
** pick up the appropriate opcode.
Search the %_segdir table for the absolute level with the smallest
** relative level number that contains at least nMin segments, if any.
** If one is found, set iAbsLevel to the absolute level number and
** nSeg to nMin. If no level with at least nMin segments can be found,
** set nSeg to -1.
True if this is an UPDATE operation
The "NEAR" node (FTS5_STRING)
** For debugging purposes, record when the mutex subsystem is initialized
** and uninitialized so that we can assert() if there is an attempt to
** allocate a mutex while the system is uninitialized.
Opcode: Vacuum P1 * * * *
**
** Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
** for an attached database. The "temp" database may not be vacuumed.
Overflow payload available for local storage
***************************************************************************
** Aggregate SQL function implementations
***************************************************************************
Register in which Expr value is cached
If the header is read successfully, check the version number to make
** sure the wal-index was not constructed with some future format that
** this version of SQLite cannot understand.
** Make the JsonNode the return value of the function.
changeset_apply() context object
Successful result
Free any prepared statements held
Opcode: AggStep0 * P2 P3 P4 P5
** Synopsis: accum=r[P3] step(r[P2@P5])
**
** Execute the step function for an aggregate. The
** function has P5 arguments. P4 is a pointer to the FuncDef
** structure that specifies the function. Register P3 is the
** accumulator.
**
** The P5 arguments are taken from register P2 and its
** successors.
fts5YYFALLBACK
True if foreign key processing is required
Set to 1 after new rowid is determined
Iterator to read input data
** The start of buffer (a/n) contains the start of a doclist. The doclist
** may or may not finish within the buffer. This function appends a text
** representation of the part of the doclist that is present to buffer
** pBuf.
**
** The return value is the number of bytes read from the input buffer.
This object holds the prerequisites and the cost of running a
** subquery on one operand of an OR operator in the WHERE clause.
** See WhereOrSet for additional information
comment: Allocate a range of temporary registers and the KeyInfo needed
** for the logic that removes duplicate result rows when the
** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL).
label: code-design
IMMEDIATEJOINSERTMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMITWHEN
pcache2
Aggregate functions are allowed here
************* End of opcodes.h ********************************************
Total number of arguments
Output iterator
760
Information about how to do the compare
isMainJrnl is 0 or 1
Defer all FK constraints
Subfunction return code
(327) anylist ::= anylist LP anylist RP
** If compiling for a processor that lacks floating point support,
** substitute integer for floating-point.
** Undo a readlock
Sorter object
Number of arguments
** Change the value of a limit. Report the old value.
** If an invalid limit index is supplied, report -1.
** Make no changes but still report the old value if the
** new limit is negative.
**
** A new lower limit does not shrink existing constructs.
** It merely prevents new constructs that exceed the limit
** from forming.
A subquery used in place of a table name
For all pages in the cache that are currently dirty or have already
** been written (but not committed) to the log file, do one of the
** following:
**
** + Discard the cached page (if refcount==0), or
** + Reload page content from the database (if refcount>0).
Offset of free space in list.aMemory
Rowid of final leaf block to traverse
ORDER BY or GROUP BY or DISTINCT clause to check
** xClose - Close a cursor.
Default column to query
Address of OP_CreateTable opcode on CREATE TABLE
** Advance the changeset iterator to the next change.
**
** If both paRec and pnRec are NULL, then this function works like the public
** API sqlite3changeset_next(). If SQLITE_ROW is returned, then the
** sqlite3changeset_new() and old() APIs may be used to query for values.
**
** Otherwise, if paRec and pnRec are not NULL, then a pointer to the change
** record is written to *paRec before returning and the number of bytes in
** the record to *pnRec.
**
** Either way, this function returns SQLITE_ROW if the iterator is
** successfully advanced to the next change in the changeset, an SQLite
** error code if an error occurs, or SQLITE_DONE if there are no further
** changes in the changeset.
** Reset the automatic extension loading mechanism.
ROW => ID
Step 3
Undo any frames written (but not committed) to the log
Return 1 or 0.
Offset from the start of data to return bytes from.
** Free the space allocated for aOp and any p4 values allocated for the
** opcodes contained within. If aOp is not NULL it is assumed to contain
** nOp entries.
Free page blocks
The i-th cell pointer
256
** Obtain a complete parse of the JSON found in the first argument
** of the argv array. Use the sqlite3_get_auxdata() cache for this
** parse if it is available. If the cache is not available or if it
** is no longer valid, parse the JSON again and return the new parse,
** and also register the new parse so that it will be available for
** future sqlite3_get_auxdata() calls.
This variation on cellSizePtr() is used inside of assert() statements
** only.
Mask of locks held by siblings
** This structure is used to build up buffers containing segment b-tree
** nodes (blocks).
Register containing table name
The upper or lower bound just coded
This function (for internal use only) locates an element in an
** hash table that matches the given key. The hash for this key has
** already been computed and is passed as the 4th parameter.
Pointer to page data
If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a
** function that returns SQLITE_ERROR when passed the argument 200, that
** forces worker threads to run sequentially and deterministically
** (via the sqlite3FaultSim() term of the conditional) for testing
** purposes.
Advance the cursor to the next element for json_tree()
Bytes of data in aData
True for without rowid
Success code from a subroutine
xDlSym
** Each entry in the hash table is represented by an object of the
** following type. Each object, its key (a nul-terminated string) and
** its current data are stored in a single memory allocation. The
** key immediately follows the object in memory. The position list
** data immediately follows the key data in memory.
**
** The data that follows the key is in a similar, but not identical format
** to the doclist data stored in the database. It is:
**
** * Rowid, as a varint
** * Position list, without 0x00 terminator.
** * Size of previous position list and rowid, as a 4 byte
** big-endian integer.
**
** iRowidOff:
** Offset of last rowid written to data area. Relative to first byte of
** structure.
**
** nData:
** Bytes of data written since iRowidOff.
** Serialize a changeset (or patchset) based on all changesets (or patchsets)
** added to the changegroup object passed as the first argument.
**
** If xOutput is not NULL, then the changeset/patchset is returned to the
** user via one or more calls to xOutput, as with the other streaming
** interfaces.
**
** Or, if xOutput is NULL, then (*ppOut) is populated with a pointer to a
** buffer containing the output changeset before this function returns. In
** this case (*pnOut) is set to the size of the output buffer in bytes. It
** is the responsibility of the caller to free the output buffer using
** sqlite3_free() when it is no longer required.
**
** If successful, SQLITE_OK is returned. Or, if an error occurs, an SQLite
** error code. If an error occurs and xOutput is NULL, (*ppOut) and (*pnOut)
** are both set to 0 before returning.
** Return the serial-type for the value stored in pMem.
** A coordinate can be either a floating point number or a integer. All
** coordinates within a single R-Tree are always of the same time.
same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1]
** Allocate and return a new IncrMerger object to read data from pMerger.
**
** If an OOM condition is encountered, return NULL. In this case free the
** pMerger argument before returning.
If zTerm is not NULL, and this segment is not stored entirely on its
** root node, the range of leaves scanned can be reduced. Do this.
First sorted list to be merged
** Return a vector of device characteristics.
OUT: Write the thread object here
VIRTUAL
Pointer value
BEFORE => ID
This branch is taken when "%00" appears within the URI. In this
** case we ignore all text in the remainder of the path, name or
** value currently being parsed. So ignore the current character
** and skip to the next "?", "=" or "&", as appropriate.
Hint number of segments
Size of write ahead log header, including checksum.
fts5WriteInit() should have initialized the buffers to (most likely)
** the maximum space required.
Use this index for == or IN queries only
Iterator to return
** This function is used to add terms implied by JOIN syntax to the
** WHERE clause expression of a SELECT statement. The new term, which
** is ANDed with the existing WHERE clause, is of the form:
**
** (tab1.col1 = tab2.col2)
**
** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
** (iSrc+1)'th. Column col1 is column iColLeft of tab1, and col2 is
** column iColRight of tab2.
Expression encoding the function
autoinc ::=
** An instance of the virtual machine. This structure contains the complete
** state of the virtual machine.
**
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
** is really a pointer to an instance of this structure.
Open the journal file if it is not already open.
** Create the backing store tables (%_content, %_segments and %_segdir)
** required by the FTS3 table passed as the only argument. This is done
** as part of the vtab xCreate() method.
**
** If the p->bHasDocsize boolean is true (indicating that this is an
** FTS4 table, not an FTS3 table) then also create the %_docsize and
** %_stat tables required by FTS4.
comment: Database connection (for malloc())
label: code-design
VACUUMVIEWINITIALLY
Name of file to delete
SQLITE_ABORT
** Register the fts3aux module with database connection db. Return SQLITE_OK
** if successful or an error code if sqlite3_create_module() fails.
The permutation
End of the ephemeral table scan. Or, if using the onepass strategy,
** jump to here if the scan visited zero rows.
sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
**
** Set or clear a flag that indicates that the database file is always well-
** formed and never corrupt. This flag is clear by default, indicating that
** database files might have arbitrary corruption. Setting the flag during
** testing causes certain assert() statements in the code to be activated
** that demonstrat invariants on well-formed database files.
Creates a new file, only if it does not already exist.
Opcode: String P1 P2 P3 P4 P5
** Synopsis: r[P2]='P4' (len=P1)
**
** The string value P4 of length P1 (bytes) is stored in register P2.
**
** If P3 is not zero and the content of register P3 is equal to P5, then
** the datatype of the register P2 is converted to BLOB. The content is
** the same sequence of bytes, it is merely interpreted as a BLOB instead
** of a string, as if it had been CAST. In other words:
**
** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
Value to return via *pnPage
No error has occurred. Free the in-memory buffers.
** The following variable, if set to a non-zero value, is interpreted as
** the number of seconds since 1970 and is used to set the result of
** sqlite3OsCurrentTime() during testing.
If the column affinity is REAL but the number is an integer, then it
** might be stored in the table as an integer (using a compact
** representation) then converted to REAL by an OP_RealAffinity opcode.
** But we are getting ready to store this value back into an index, where
** it should be converted by to INTEGER again. So omit the OP_RealAffinity
** opcode if it is present
Pointer to first entry with this hash
Integer return code
** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z
** might refer to an result-set alias. This happens, for example, when
** we are resolving names in the WHERE clause of the following command:
**
** SELECT a+b AS x FROM table WHERE x<10;
**
** In cases like this, replace pExpr with a copy of the expression that
** forms the result set entry ("a+b" in the example) and return immediately.
** Note that the expression in the result set should have already been
** resolved by the time the WHERE clause is resolved.
**
** The ability to use an output result-set column in the WHERE, GROUP BY,
** or HAVING clauses, or as part of a larger expression in the ORDER BY
** clause is not standard SQL. This is a (goofy) SQLite extension, that
** is supported for backwards compatibility only. Hence, we issue a warning
** on sqlite3_log() whenever the capability is used.
** Attach PmaReader pReadr to file pFile (if it is not already attached to
** that file) and seek it to offset iOff within the file. Return SQLITE_OK
** if successful, or an SQLite error code if an error occurs.
** Advance the iterator to the next position.
**
** If no error occurs, SQLITE_OK is returned and the iterator is left
** pointing to the next entry. Otherwise, an error code and message is
** left in the RBU handle passed as the first argument. A copy of the
** error code is returned.
Check that each phrase in the nearset matches the current row.
** Populate the pPhrase->poslist buffers at the same time. If any
** phrase is not a match, break out of the loop early.
The original cursor to be duplicated
Next unixShm with the same unixShmNode
************* End of build.c **********************************************
The sign in front of the number
joinop ::= JOIN_KW JOIN
Generate code to take the intersection of the two temporary
** tables.
** Compute the set of tables that might satisfy cases 1 or 3.
The ExprSetVVAProperty() macro is used for Verification, Validation,
** and Accreditation only. It works like ExprSetProperty() during VVA
** processes but is a no-op for delivery.
Append the node to this object
wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP
Page number obtained
Verify that the WAL header checksum is correct
** This user-defined SQL function is invoked with a single argument - the
** name of a table expected to appear in the target database. It returns
** the number of auxilliary indexes on the table.
If page 1 was just written, update Pager.dbFileVers to match
** the value now stored in the database file. If writing this
** page caused the database file to grow, update dbFileSize.
where_opt ::= WHERE expr
#include "btreeInt.h"
Write a single frame for this page to the log.
Need to call Mem.xDel() on Mem.z
** Return the auxiliary data pointer, if any, for the iArg'th argument to
** the user-function defined by pCtx.
**
** The left-most argument is 0.
**
** Undocumented behavior: If iArg is negative then access a cache of
** auxiliary data pointers that is available to all functions within a
** single prepared statement. The iArg values must match.
All files and directories have already been synced, so the following
** calls to sqlite3BtreeCommitPhaseTwo() are only closing files and
** deleting or truncating journals. If something goes wrong while
** this is happening we don't really care. The integrity of the
** transaction is already guaranteed, but some stray 'cold' journals
** may be lying around. Returning an error code won't help matters.
Points to conflicting row, if any
Now search pTab for the exact column.
True if currently recording
Directory sync needed
This is the RFC 7396 MergePatch algorithm.
One of TK_UPDATE, TK_INSERT, TK_DELETE
** This routine handles sqlite3_file_control() calls that are specific
** to proxy locking.
EVIDENCE-OF: R-24078-09375 Value is a NULL.
** 2004 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements an external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
** Including a description of file format and an overview of operation.
nMax*9/10
330
First arg to comparison function
Dirty read
** Extra argument values from a PrintfArguments object
comment: Comparison information for duplicate removal
label: code-design
** Return true if the cursor has a hint specified. This routine is
** only used from within assert() statements
Regardless of whether this is a RELEASE or ROLLBACK, destroy all
** savepoints nested inside of the savepoint being operated on.
True if any page has PGHDR_NEED_SYNC
1's digit
Step 5b.
Pointer to buffer containing term
File descriptor object
** PRAGMA [schema.]cache_size
** PRAGMA [schema.]cache_size=N
**
** The first form reports the current local setting for the
** page cache size. The second form sets the local
** page cache size value. If N is positive then that is the
** number of pages in the cache. If N is negative, then the
** number of pages is adjusted so that the cache uses -N kibibytes
** of memory.
synopsis: rowset(P1)=r[P2]
** The public interface to sqlite3Realloc. Make sure that the memory
** subsystem is initialized prior to invoking sqliteRealloc.
First argument to xPreUpdateCallback
EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
** number of cells on the page.
** Return true if this pager uses a write-ahead log to read page pgno.
** Return false if the pager reads pgno directly from the database.
The database index number
Next registered tokenizer module
Storage handle
Need to free the WhereTerm.u.pAndInfo obj
Initialize memory locations used by GROUP BY aggregate processing
Term suffix
comment:
** The iterator passed as the first argument has the following fields set
** as follows. This function sets up the rest of the iterator so that it
** points to the first rowid in the doclist-index.
**
** pData:
** pointer to doclist-index record,
**
** When this function is called pIter->iLeafPgno is the page number the
** doclist is associated with (the one featuring the term).
label: code-design
1090
(291) signed ::= plus_num (OPTIMIZED OUT)
** This routine is the only routine in this file with external
** linkage. It returns a pointer to a static sqlite3_mem_methods
** struct populated with the memsys5 methods.
Name of attached database (e.g. "main")
** Set this global variable to 1 to enable tracing using the TRACE
** macro.
** Handler for proxy-locking file-control verbs. Defined below in the
** proxying locking division.
The file contains at most 1 b-tree
Invert the result for DESC sort order.
Output each row of result
The table that might be changing
'documents' values for current csr row
Jump here if true.
Opcode
TRUE after OP_ColumnName has been issued to pVdbe
** Set the ExprList.a[].zName element of the most recently added item
** on the expression list.
**
** pList might be NULL following an OOM error. But pName should never be
** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
** is set.
The index used to access the table
dbsize field from frame header
What version of GCC is being used. 0 means GCC is not being used .
** Note that the GCC_VERSION macro will also be set correctly when using
** clang, since clang works hard to be gcc compatible. So the gcc
** optimizations will also work when compiling with clang.
** A segment of size nByte bytes has just been written to absolute level
** iAbsLevel. Promote any segments that should be promoted as a result.
Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
** returned, clean-up the statement handle.
Jump here if database corruption is detected after m has been
** allocated. Free the m object and return SQLITE_CORRUPT.
Foreign key constraint
Index of last frame read
** Make sure the cursor p is ready to read or write the row to which it
** was last positioned. Return an error code if an OOM fault or I/O error
** prevents us from positioning the cursor to its correct position.
**
** If a MoveTo operation is pending on the given cursor, then do that
** MoveTo now. If no move is pending, check to see if the row has been
** deleted out from under the cursor and if it has, mark the row as
** a NULL row.
**
** If the cursor is already pointing to the correct row and that row has
** not been deleted out from under the cursor, then this routine is a no-op.
Info about the callback functions
expr ::= RAISE LP raisetype COMMA nm RP
If the response to a rowid conflict is REPLACE but the response
** to some other UNIQUE constraint is FAIL or IGNORE, then we need
** to defer the running of the rowid conflict checking until after
** the UNIQUE constraints have run.
Write and decode big-endian 32-bit integer values
The header was successfully read. Return zero.
neverCorrupt
If not at EOF but the current rowid occurs earlier than iFirst in
** the iteration order, move to document iFirst or later.
nMaxpage + 10 - nMinPage
xUpdate
First callback argument
Cursor for the main table
Number of locks to acquire or release
allocate a buffer and convert to UTF8
** Check the integrity of the freelist or of an overflow page list.
** Verify that the number of pages on the list is N.
REPLACE => ID
Overflows in sorted order
Object containing old values
Index for p->aIndex
** Extract the snippet text for fragment pFragment from cursor pCsr and
** append it to string buffer pOut.
** Return the currently defined page size
299
** Deregister and destroy an RBU vfs created by an earlier call to
** sqlite3rbu_create_vfs().
**
** VFS objects are not reference counted. If a VFS object is destroyed
** before all database handles that use it have been closed, the results
** are undefined.
TUNING: Slight bias in favor of no-sort plans
Newly allocated SegReader object
Rank callback (or NULL)
In case this cursor is being reused, close and zero it.
The pH to be searched
Allowed return values from sqlite3WhereIsDistinct()
Open a token cursor on the document.
** Clear all secondary memory allocations from the parser
SQLITE_UTF16NATIVE
** current_timestamp()
**
** This function returns the same value as datetime('now').
** 2001 September 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for the generic hash-table implementation
** used in SQLite.
Default ON CONFLICT policy for triggers
** Add a new element to the pAggInfo->aFunc[] array. Return the index of
** the new element. Return a negative number if malloc fails.
For a co-routine, change all OP_Column references to the table of
** the co-routine into OP_Copy of result contained in a register.
** OP_Rowid becomes OP_Null.
Free the session object itself.
We used to require that sqlite3_reset() be called before retrying
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
** with version 3.7.0, we changed this so that sqlite3_reset() would
** be called automatically instead of throwing the SQLITE_MISUSE error.
** This "automatic-reset" change is not technically an incompatibility,
** since any application that receives an SQLITE_MISUSE is broken by
** definition.
**
** Nevertheless, some published applications that were originally written
** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
** returns, and those were broken by the automatic-reset change. As a
** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
** legacy behavior of returning SQLITE_MISUSE for cases where the
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
** or SQLITE_BUSY error.
SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH
comment:
** All individual term iterators in pPhrase are guaranteed to be valid and
** pointing to the same rowid when this function is called. This function
** checks if the current rowid really is a match, and if so populates
** the pPhrase->poslist buffer accordingly. Output parameter *pbMatch
** is set to true if this is really a match, or false otherwise.
**
** SQLITE_OK is returned if an error occurs, or an SQLite error code
** otherwise. It is not considered an error code if the current rowid is
** not a match.
label: code-design
Should be prime
pColumns can only be NULL due to an OOM but an OOM will cause an
** exit prior to this routine being invoked
WAS: ino_t ino;
Column that is the INTEGER PRIMARY KEY
Set isHighlight to true if this term should be highlighted.
Destructor for the extra data
** The following routine implements the rough equivalent of localtime_r()
** using whatever operating-system specific localtime facility that
** is available. This routine returns 0 on success and
** non-zero on any kind of error.
**
** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
** routine will always fail.
**
** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
** library function localtime_r() is used to assist in the calculation of
** local time.
Number of cells on the page
Results of stat() call
** Erase all schema information from all attached databases (including
** "main" and "temp") for a single database connection.
Put saved Parse.zAuthContext here
A-overwrites-W
** Generate code to do an analysis of all indices associated with
** a single table.
SQLITE_OMIT_WSD
Extra zero data appended after pData,nData
Either the parent node or NULL
If not NULL, only analyze this one index
** Convert a UTF-8 filename into whatever form the underlying
** operating system wants filenames in. Space to hold the result
** is obtained from malloc and must be freed by the calling
** function.
The next routine used only within assert() statements
OUT: Set to malloced error message
SELECT may not be a compound query
Generate code to check constraints and generate index keys and
** do the insertion.
If this expression is a vector to the left or right of a
** inequality constraint (>, <, >= or <=), perform the processing
** on the first element of the vector.
Address register for the output-B subroutine
Value of nPos field
** PRAGMA soft_heap_limit
** PRAGMA soft_heap_limit = N
**
** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
** sqlite3_soft_heap_limit64() interface with the argument N, if N is
** specified and is a non-negative integer.
** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
** returns the same integer that would be returned by the
** sqlite3_soft_heap_limit64(-1) C-language function.
The memsys static mutex
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use only inside assert() statements.
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
**
** ^The sqlite3_compileoption_used() function returns 0 or 1
** indicating whether the specified option was defined at
** compile time. ^The SQLITE_ prefix may be omitted from the
** option name passed to sqlite3_compileoption_used().
**
** ^The sqlite3_compileoption_get() function allows iterating
** over the list of options that were defined at compile time by
** returning the N-th compile time option string. ^If N is out of range,
** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
** prefix is omitted from any strings returned by
** sqlite3_compileoption_get().
**
** ^Support for the diagnostic functions sqlite3_compileoption_used()
** and sqlite3_compileoption_get() may be omitted by specifying the
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
**
** See also: SQL functions [sqlite_compileoption_used()] and
** [sqlite_compileoption_get()] and the [compile_options pragma].
Merge the forest into a single sorted list on first call
Parse of the input JSON
Arguments for printf format string
Used reduced-size Expr nodes
************* Begin file wal.h ********************************************
** Add all changes in the changeset traversed by the iterator passed as
** the first argument to the changegroup hash tables.
ONEPASS_OFF or _SINGLE or _MULTI
Only one flag value allowed
Opcode: Count P1 P2 * * *
** Synopsis: r[P2]=count()
**
** Store the number of entries (an integer value) in the table or index
** opened by cursor P1 in register P2
1110
having_opt ::= HAVING expr
Opcode: Not P1 P2 * * *
** Synopsis: r[P2]= !r[P1]
**
** Interpret the value in register P1 as a boolean value. Store the
** boolean complement in register P2. If the value in register P1 is
** NULL, then a NULL is stored in P2.
** This function is a wrapper around sqlite3WalFrames(). As well as logging
** the contents of the list of pages headed by pList (connected by pDirty),
** this function notifies any active backup processes that the pages have
** changed.
**
** The list of pages passed into this routine is always sorted by page number.
** Hence, if page 1 appears anywhere on the list, it will be the first page.
** Initialize a WhereMaskSet object
The ORDER BY (or GROUP BY clause)
** Find the name of the index. Make sure there is not already another
** index or table with the same name.
**
** Exception: If we are reading the names of permanent indices from the
** sqlite_master table (because some other process changed the schema) and
** one of the index names collides with the name of a temporary table or
** index, then we will continue to process this index.
**
** If pName==0 it means that we are
** dealing with a primary key or UNIQUE constraint. We have to invent our
** own name.
FROM clause term being indexed
1210
Error message stored here
Last token in coalesced phrase instance
VM this frame belongs to
Return code
** Free the expression object passed as the only argument.
sqlite3_io_methods object name
Handle for accessing memory mapping
** The following code executes when the parse fails
Loop through the table columns, appending offset information to
** string-buffer res for each column.
Unless an error occurs, the following loop runs one iteration for each
** page in the B-Tree structure (not including overflow pages).
Current error code
** Each VDBE holds the result of the most recent sqlite3_step() call
** in p->rc. This routine sets that result back to SQLITE_OK.
comment:
** This function is called when an ICU function called from within
** the implementation of an SQL scalar function returns an error.
**
** The scalar function context passed as the first argument is
** loaded with an error message based on the following two args.
label: code-design
The record is corrupt if any of the following are true:
** (1) the bytes of the header extend past the declared header size
** (2) the entire header was used but not all data was used
** (3) the end of the data extends beyond the end of the record.
Maximum value for szMmap
.db =
Term to select leaves for
Number of previously allocated VDBE cursors
Opcode: Noop * * * * *
**
** Do nothing. This instruction is often useful as a jump
** destination.
The journal file into which to write
Various register numbers
True for a read-only database
If the shared-memory file has not yet been opened, open it now.
** END CODE GENERATED BY tool/mkctime.tcl
(293) carglist ::= carglist ccons
An internal query
Floating point. %f
8-byte alignment of pageSize
If the iterator is in the error-state, return immediately.
comment:
** CAPI3REF: Obtain new.* Values From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
** Furthermore, it may only be called if the type of change that the iterator
** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the vector of
** new row values stored as part of the UPDATE or INSERT change and
** returns SQLITE_OK. If the change is an UPDATE and does not include
** a new value for the requested column, *ppValue is set to NULL and
** SQLITE_OK returned. The name of the function comes from the fact that
** this is similar to the "new.*" columns available to update or delete
** triggers.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
** The buffer that the argument points to contains a serialized SQL value.
** Return the number of bytes of space occupied by the value (including
** the type byte).
Zero the output variable in case an error occurs.
If the LHS of the MATCH expression was a user column, apply the
** implicit column-filter.
Offset from the beginning of the file
** Version of sqlite3_free() that is always a function, never a macro.
True if I/O errors persist
** An array of the following structures is assembled as part of the process
** of selecting tokens to defer before the query starts executing (as part
** of the xFilter() method). There is one element in the array for each
** token in the FTS expression.
**
** Tokens are divided into AND/NEAR clusters. All tokens in a cluster belong
** to phrases that are connected only by AND and NEAR operators (not OR or
** NOT). When determining tokens to defer, each AND/NEAR cluster is considered
** separately. The root of a tokens AND/NEAR cluster is stored in
** Fts3TokenAndCost.pRoot.
** Return the mutex associated with a database connection.
268
Hash value for the element
xFilter - configure scan constraints
** Register a new auxiliary function with global context pGlobal.
One entry for each identifier on the list
The parse
Name of the term in the USING clause
** If it is not NULL, pTerm is a term that provides an upper or lower
** bound on a range scan. Without considering pTerm, it is estimated
** that the scan will visit nNew rows. This function returns the number
** estimated to be visited after taking pTerm into account.
**
** If the user explicitly specified a likelihood() value for this term,
** then the return value is the likelihood multiplied by the number of
** input rows. Otherwise, this function assumes that an "IS NOT NULL" term
** has a likelihood of 0.50, and any other term a likelihood of 0.25.
'&'
If the Fts3SegFilter defines a specific term (or term prefix) to search
** for, then advance each segment iterator until it points to a term of
** equal or greater value than the specified term. This prevents many
** unnecessary merge/sort operations for the case where single segment
** b-tree leaf nodes contain more than one term.
This should never happen. We should always be able to
** reacquire the read lock
cmd ::= DROP INDEX ifexists fullname
Level to read input from
Determine the maximum amount of space required.
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
** FUNCTION(zName, nArg, iArg, bNC, xFunc)
** Used to create a scalar function definition of a function zName
** implemented by C function xFunc that accepts nArg arguments. The
** value passed as iArg is cast to a (void*) and made available
** as the user-data (sqlite3_user_data()) for the function. If
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
**
** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
**
** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
** and functions like sqlite_version() that can change, but not during
** a single query. The iArg is ignored. The user-data is always set
** to a NULL pointer. The bNC parameter is not used.
**
** PURE_DATE(zName, nArg, iArg, bNC, xFunc)
** Used for "pure" date/time functions, this macro is like DFUNCTION
** except that it does set the SQLITE_FUNC_CONSTANT flags. iArg is
** ignored and the user-data for these functions is set to an
** arbitrary non-NULL pointer. The bNC parameter is not used.
**
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
** Used to create an aggregate function definition implemented by
** the C functions xStep and xFinal. The first four parameters
** are interpreted in the same way as the first 4 parameters to
** FUNCTION().
**
** LIKEFUNC(zName, nArg, pArg, flags)
** Used to create a scalar function definition of a function zName
** that accepts nArg arguments and is implemented by a call to C
** function likeFunc. Argument pArg is cast to a (void *) and made
** available as the function user-data (sqlite3_user_data()). The
** FuncDef.flags variable is set to the value passed as the flags
** parameter.
Check if this is a tokenizer specification
************* End of pcache1.c ********************************************
**** This function is only used as part of an assert() statement. ***
**
** Check to see if pBtree holds the required locks to read or write to the
** table with root page iRoot. Return 1 if it does and 0 if not.
**
** For example, when writing to a table with root-page iRoot via
** Btree connection pBtree:
**
** assert( hasSharedCacheTableLock(pBtree, iRoot, 0, WRITE_LOCK) );
**
** When writing to an index that resides in a sharable database, the
** caller should have first obtained a lock specifying the root page of
** the corresponding table. This makes things a bit more complicated,
** as this module treats each table as a separate structure. To determine
** the table corresponding to the index being written, this
** function has to search through the database schema.
**
** Instead of a lock on the table/index rooted at page iRoot, the caller may
** hold a write-lock on the schema table (root page 1). This is also
** acceptable.
Number of nested statement-transactions
fts5YYERRORSYMBOL is not defined
Transitive constraints
** Commit data to disk.
Register for new.* record
Size of the output buffer
Hint this end-of-scan boundary term if not NULL
comment:
** CAPI3REF: Setting The Result Of An SQL Function
** METHOD: sqlite3_context
**
** These routines are used by the xFunc or xFinal callbacks that
** implement SQL functions and aggregates. See
** [sqlite3_create_function()] and [sqlite3_create_function16()]
** for additional information.
**
** These functions work very much like the [parameter binding] family of
** functions used to bind values to host parameters in prepared statements.
** Refer to the [SQL parameter] documentation for additional information.
**
** ^The sqlite3_result_blob() interface sets the result from
** an application-defined function to be the BLOB whose content is pointed
** to by the second parameter and which is N bytes long where N is the
** third parameter.
**
** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
** interfaces set the result of the application-defined function to be
** a BLOB containing all zero bytes and N bytes in size.
**
** ^The sqlite3_result_double() interface sets the result from
** an application-defined function to be a floating point value specified
** by its 2nd argument.
**
** ^The sqlite3_result_error() and sqlite3_result_error16() functions
** cause the implemented SQL function to throw an exception.
** ^SQLite uses the string pointed to by the
** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
** as the text of an error message. ^SQLite interprets the error
** message string from sqlite3_result_error() as UTF-8. ^SQLite
** interprets the string from sqlite3_result_error16() as UTF-16 in native
** byte order. ^If the third parameter to sqlite3_result_error()
** or sqlite3_result_error16() is negative then SQLite takes as the error
** message all text up through the first zero character.
** ^If the third parameter to sqlite3_result_error() or
** sqlite3_result_error16() is non-negative then SQLite takes that many
** bytes (not characters) from the 2nd parameter as the error message.
** ^The sqlite3_result_error() and sqlite3_result_error16()
** routines make a private copy of the error message text before
** they return. Hence, the calling function can deallocate or
** modify the text after they return without harm.
** ^The sqlite3_result_error_code() function changes the error code
** returned by SQLite as a result of an error in a function. ^By default,
** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
**
** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
** error indicating that a string or BLOB is too long to represent.
**
** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
** error indicating that a memory allocation failed.
**
** ^The sqlite3_result_int() interface sets the return value
** of the application-defined function to be the 32-bit signed integer
** value given in the 2nd argument.
** ^The sqlite3_result_int64() interface sets the return value
** of the application-defined function to be the 64-bit signed integer
** value given in the 2nd argument.
**
** ^The sqlite3_result_null() interface sets the return value
** of the application-defined function to be NULL.
**
** ^The sqlite3_result_text(), sqlite3_result_text16(),
** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
** set the return value of the application-defined function to be
** a text string which is represented as UTF-8, UTF-16 native byte order,
** UTF-16 little endian, or UTF-16 big endian, respectively.
** ^The sqlite3_result_text64() interface sets the return value of an
** application-defined function to be a text string in an encoding
** specified by the fifth (and last) parameter, which must be one
** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
** ^SQLite takes the text result from the application from
** the 2nd parameter of the sqlite3_result_text* interfaces.
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
** is negative, then SQLite takes result text from the 2nd parameter
** through the first zero character.
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
** is non-negative, then as many bytes (not characters) of the text
** pointed to by the 2nd parameter are taken as the application-defined
** function result. If the 3rd parameter is non-negative, then it
** must be the byte offset into the string where the NUL terminator would
** appear if the string where NUL terminated. If any NUL characters occur
** in the string at a byte offset that is less than the value of the 3rd
** parameter, then the resulting string will contain embedded NULs and the
** result of expressions operating on strings with embedded NULs is undefined.
** ^If the 4th parameter to the sqlite3_result_text* interfaces
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
** function as the destructor on the text or BLOB result when it has
** finished using that result.
** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
** assumes that the text or BLOB result is in constant space and does not
** copy the content of the parameter nor call a destructor on the content
** when it has finished using that result.
** ^If the 4th parameter to the sqlite3_result_text* interfaces
** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
** then SQLite makes a copy of the result into space obtained
** from [sqlite3_malloc()] before it returns.
**
** ^The sqlite3_result_value() interface sets the result of
** the application-defined function to be a copy of the
** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
** so that the [sqlite3_value] specified in the parameter may change or
** be deallocated after sqlite3_result_value() returns without harm.
** ^A [protected sqlite3_value] object may always be used where an
** [unprotected sqlite3_value] object is required, so either
** kind of [sqlite3_value] object can be used with this interface.
**
** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
** SQL NULL value, just like [sqlite3_result_null(C)], except that it
** also associates the host-language pointer P or type T with that
** NULL value such that the pointer can be retrieved within an
** [application-defined SQL function] using [sqlite3_value_pointer()].
** ^If the D parameter is not NULL, then it is a pointer to a destructor
** for the P parameter. ^SQLite invokes D with P as its only argument
** when SQLite is finished with P. The T parameter should be a static
** string and preferably a string literal. The sqlite3_result_pointer()
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
**
** If these routines are called from within the different thread
** than the one containing the application-defined function that received
** the [sqlite3_context] pointer, the results are undefined.
label: code-design
Fill in the payload
Process NATURAL keywords, and ON and USING clauses of joins.
An operand of a comparison operator
comment: The entire output segment fits on a single node. Normally, this means
** the node would be stored as a blob in the "root" column of the %_segdir
** table. However, this is not permitted in this case. The problem is that
** space has already been reserved in the %_segments table, and so the
** start_block and end_block fields of the %_segdir table must be populated.
** And, by design or by accident, released versions of FTS cannot handle
** segments that fit entirely on the root node with start_block!=0.
**
** Instead, create a synthetic root node that contains nothing but a
** pointer to the single content node. So that the segment consists of a
** single leaf and a single interior (root) node.
**
** Todo: Better might be to defer allocating space in the %_segments
** table until we are sure it is needed.
label: code-design
Loop through all columns of the index and deal with the ones
** that are not constrained by == or IN.
A bunch of assert() statements to check the transaction state variables
** of handle p (type Btree*) are internally consistent.
Regardless of the current state, a temp-file connection always behaves
** as if it has an exclusive lock on the database file. It never updates
** the change-counter field, so the changeCountDone flag is always set.
The database encoding
Store a pointer to the memory block in global structure mem3.
** Default permissions when creating a new file
** Set a table filter on a Session Object.
CSE2 from below
The iCol-th column of the result set
See if we are dealing with a quoted phrase. If this is the case, then
** search for the closing quote and pass the whole string to getNextString()
** for processing. This is easy to do, as fts3 has no syntax for escaping
** a quote character embedded in a string.
comparison function
** The following constant value is used by the SQLITE_BIGENDIAN and
** SQLITE_LITTLEENDIAN macros.
OK to update SQLITE_MASTER
Bytes of header sector written
same as TK_BITOR, in1, in2, out3
Read the serial types for the next element in each key.
Resize the hash table so that it cantains "new_size" buckets.
**
** The hash table might fail to resize if sqlite3_malloc() fails or
** if the new size is the same as the prior size.
** Return TRUE if the resize occurs and false if not.
If EP_FromJoin, the right table of the join
serial type of first record field
Pointer to a static string
If everything has worked, invoke fts3DisconnectMethod() to free the
** memory associated with the Fts3Table structure and return SQLITE_OK.
** Otherwise, return an SQLite error code.
Column token appears in (-ve -> delete)
IMP: R-37514-35566
True if pStart obtained from sqlite3_malloc()
OUT: Extracted value
An instance of this object describes bulk memory available for use
** by subcomponents of a prepared statement. Space is allocated out
** of a ReusableSpace object by the allocSpace() routine below.
Number of VDBEs currently running
Depth of a subtree
If this is a "NEAR" keyword, check for an explicit nearness.
OUT: Frame associated with *paPgno[0]
sqlite3_mem_methods*
** Flags passed to the sqlite3ExprDup() function. See the header comment
** above sqlite3ExprDup() for details.
xPagecount
** The following structure contains information used by the sqliteFix...
** routines as they walk the parse tree to make database references
** explicit.
Remove the search point with the lowest current score.
Copy of flags byte
comment: The SQLITE_TEST_REALLOC_STRESS compile-time option is designed to force
** more frequent reallocs and hence provide more opportunities for
** simulated OOM faults. SQLITE_TEST_REALLOC_STRESS is generally used
** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
** by the minimum* amount required until the size reaches 512. Normal
** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
** size of the op array or add 1KB of space, whichever is smaller.
label: code-design
Database name
The database on which the SQL executes
Candidate unixInodeInfo object
The major token to shift in
Update the pointer-map and meta-data with the new root-page number.
SQLITE_PAGER_PRAGMAS
Select a master journal file name
Attempt to locate an existing hash entry
Left hand serial type
Silence a compiler warning
Sum of nMax for purgeable caches
UPDATE statement
** This function is called by the parser after the table-name in
** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument
** pSrc is the full-name of the table being altered.
**
** This routine makes a (partial) copy of the Table structure
** for the table being altered and sets Parse.pNewTable to point
** to it. Routines called by the parser as the column definition
** is parsed (i.e. sqlite3AddColumn()) add the new Column data to
** the copy. The copy of the Table structure is deleted by tokenize.c
** after parsing is finished.
**
** Routine sqlite3AlterFinishAddColumn() will be called to complete
** coding the "ALTER TABLE ... ADD" statement.
Memory register used by AUTOINC
305
** Analyze the ORDER BY clause in a compound SELECT statement. Modify
** each term of the ORDER BY clause is a constant integer between 1
** and N where N is the number of columns in the compound SELECT.
**
** ORDER BY terms that are already an integer between 1 and N are
** unmodified. ORDER BY terms that are integers outside the range of
** 1 through N generate an error. ORDER BY terms that are expressions
** are matched against result set expressions of compound SELECT
** beginning with the left-most SELECT and working toward the right.
** At the first match, the ORDER BY expression is transformed into
** the integer column number.
**
** Return the number of errors seen.
OUT: Size of doclist in bytes
True for FTS4, false for FTS3
Cannot be used with sqlite3RowSetText()
** Implementation of snippet() function.
Deallocates any cached error strings.
** Save the current state of the PRNG.
Second change operation
** If the SQLITE_ENABLE IOTRACE exists then the global variable
** sqlite3IoTrace is a pointer to a printf-like routine used to
** print I/O tracing messages.
comment:
** pX is the RHS of an IN operator. If pX is a SELECT statement
** that can be simplified to a direct table access, then return
** a pointer to the SELECT statement. If pX is not a SELECT statement,
** or if the SELECT statement needs to be manifested into a transient
** table, then return NULL.
label: code-design
140
Array of target column types
Open the sorter cursor if we are to use one.
** If pFile is currently larger than iSize bytes, then truncate it to
** exactly iSize bytes. If pFile is not larger than iSize bytes, then
** this function is a no-op.
**
** Return SQLITE_OK if everything is successful, or an SQLite error
** code if an error occurs.
Previous term written to new node
OUT: Docid and doclist for new entry
comment:
** The malloc.h header file is needed for malloc_usable_size() function
** on some systems (e.g. Linux).
label: code-design
Create the automatic index
276
Acquire the mutex
** Release a reference to a node. If the node is dirty and the reference
** count drops to zero, the node data is written to the database.
Language id to return cksum for
refact ::= RESTRICT
Pager associated with pBt
************* End of os.c *************************************************
One of the CURSOR_XXX constants (see below)
Offset to first byte to be locked/unlocked
True if a periodic sample
Address of jump instruction
Shared library endings to try if zFile cannot be loaded as written
isInit
Number of leaf pages written
The pager open on the database file
** Copy data from a buffer to a page, or from a page to a buffer.
**
** pPayload is a pointer to data stored on database page pDbPage.
** If argument eOp is false, then nByte bytes of data are copied
** from pPayload to the buffer pointed at by pBuf. If eOp is true,
** then sqlite3PagerWrite() is called on pDbPage and nByte bytes
** of data are copied from the buffer pBuf to pPayload.
**
** SQLITE_OK is returned on success, otherwise an error code.
WHERE clause of the UPDATE statement
Mask of old.* columns referenced
** Resolve names in expressions that can only reference a single table:
**
** * CHECK constraints
** * WHERE clauses on partial indices
**
** The Expr.iTable value for Expr.op==TK_COLUMN nodes of the expression
** is set to -1 and the Expr.iColumn value is set to the column number.
**
** Any errors cause an error message to be set in pParse.
** Function to query the hash-table of tokenizers (see README.tokenizers).
34
This file is used for Windows only
REPLACE_CONTENT
comment:
** Return a nul-terminated string containing the comma separated list of
** assignments that should be included following the "SET" keyword of
** an UPDATE statement used to update the table object that the iterator
** passed as the second argument currently points to if the rbu_control
** column of the data_xxx table entry is set to zMask.
**
** The memory for the returned string is obtained from sqlite3_malloc().
** It is the responsibility of the caller to eventually free it using
** sqlite3_free().
**
** If an OOM error is encountered when allocating space for the new
** string, an error code is left in the rbu handle passed as the first
** argument and NULL is returned. Or, if an error has already occurred
** when this function is called, NULL is returned immediately, without
** attempting the allocation or modifying the stored error code.
label: code-design
IN/OUT: Checksum value
P4 is a pointer to an sqlite3_context object
sqlite3Parser_ENGINEALWAYSONSTACK
System call return code
Node most recently inserted into the tree
The database has been modified
If argument zPath is a NULL pointer, this function is required to open
** a temporary file. Use this buffer to store the file name in.
Set the database size back to the value it was before the savepoint
** being reverted was opened.
Used to iterate through phrase terms
Input text being tokenized
End of interior node buffer
OUT: Sum of PCache1.nMin for purgeable caches
We have an equality constraint on the rowid. Use strategy 1.
** Test whether or not expression pExpr, which was part of a WHERE clause,
** should be included in the cursor-hint for a table that is on the rhs
** of a LEFT JOIN. Set Walker.eCode to non-zero before returning if the
** expression is not suitable.
**
** An expression is unsuitable if it might evaluate to non NULL even if
** a TK_COLUMN node that does affect the value of the expression is set
** to NULL. For example:
**
** col IS NULL
** col IS NOT NULL
** coalesce(col, 1)
** CASE WHEN col THEN 0 ELSE 1 END
ONEPASS valid for a single row update
Contains one or more aggregate functions
Second parameter (often the jump destination)
Next pattern and input string chars
If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error.
Invoke the coroutine to extract information from the SELECT
** and add it to a transient table srcTab. The code generated
** here is from the 4th template:
**
** B: open temp table
** L: yield X, goto M at EOF
** insert row from R..R+n into temp table
** goto L
** M: ...
** Move the seg-iter so that it points to the first rowid on page iLeafPgno.
** It is an error if leaf iLeafPgno does not exist or contains no rowids.
Append nodes to complete path if not NULL
Total number of pages to copy
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Header file for the Virtual DataBase Engine (VDBE)
**
** This header defines the interface to the virtual database engine
** or VDBE. The VDBE implements an abstract machine that runs a
** simple program to access and modify the underlying database.
Calling thread context
Hash table for functions
Number of reader locks obtained
20..27 !"#$%&'
IMP: R-31275-44060
FTS3/FTS4 require virtual tables
** Expression pExpr is a vector that has been used in a context where
** it is not permitted. If pExpr is a sub-select vector, this routine
** loads the Parse object with a message of the form:
**
** "sub-select returns N columns - expected 1"
**
** Or, if it is a regular scalar vector:
**
** "row value misused"
Iterator variable for various purposes
Query used to initialize the table
Write the revised row estimate here
************* Begin file build.c ******************************************
Number of bytes in term prefix
Object used to write to the file
0 for main database. 1 for TEMP, 2.. for ATTACHed
Pointer to one of the indices
(277) explain ::=
** Variables related to the accumulation of tokens and doclists within the
** in-memory hash tables before they are flushed to disk.
Pointer to Fts5IntegrityCtx object
Use covering indices for full-scans
** End of interface to code in fts5_vocab.c.
*************************************************************************
Original SQL values of parameters
** Return a string that describes the kind of error specified in the
** argument. For now, this simply calls the internal sqlite3ErrStr()
** function.
got it, set the type and return ok
First register in array assigned to each index
Used to iterate through memory cells
Count the token characters
** No-op.
SELECT statement
** Return a block of memory of at least nBytes in size.
** Return NULL if unable. Return NULL if nBytes==0.
**
** The caller guarantees that nByte is positive.
**
** The caller has obtained a mutex prior to invoking this
** routine so there is never any chance that two or more
** threads can be in this routine at the same time.
Offset on new first leaf page
** Always assert. This xSelectCallback2 implementation proves that the
** xSelectCallback2 is never invoked.
If the db->init.busy is 1 it means we are reading the SQL off the
** "sqlite_master" or "sqlite_temp_master" table on the disk.
** So do not write to the disk again. Extract the root page number
** for the table from the db->init.newTnum field. (The page number
** should have been put there by the sqliteOpenCb routine.)
**
** If the root page number is 1, that means this is the sqlite_master
** table itself. So mark it read-only.
First namecontext in the list
Input contains fewer than nChar chars
SQL_SEGMENT_IS_APPENDABLE
** Return a single row if the segment with end_block=? is appendable. Or
** no rows otherwise.
Context for fts3ExprIterate()
comment:
** Attempt the transfer optimization on INSERTs of the form
**
** INSERT INTO tab1 SELECT * FROM tab2;
**
** The xfer optimization transfers raw records from tab2 over to tab1.
** Columns are not decoded and reassembled, which greatly improves
** performance. Raw index records are transferred in the same way.
**
** The xfer optimization is only attempted if tab1 and tab2 are compatible.
** There are lots of rules for determining compatibility - see comments
** embedded in the code for details.
**
** This routine returns TRUE if the optimization is guaranteed to be used.
** Sometimes the xfer optimization will only work if the destination table
** is empty - a factor that can only be determined at run-time. In that
** case, this routine generates code for the xfer optimization but also
** does a test to see if the destination table is empty and jumps over the
** xfer optimization code if the test fails. In that case, this routine
** returns FALSE so that the caller will know to go ahead and generate
** an unoptimized transfer. This routine also returns FALSE if there
** is no chance that the xfer optimization can be applied.
**
** This optimization is particularly useful at making VACUUM run faster.
label: code-design
** Insert new entries into the FTS index and %_docsize table.
Name of master journal file if any
Index of column in child table
Do nothing. The work was all in the test
Abort the SQL statement with an error
Registers to hold a row from pTab
** CAPI3REF: Pseudo-Random Number Generator
**
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
** select random [ROWID | ROWIDs] when inserting new records into a table that
** already uses the largest possible [ROWID]. The PRNG is also used for
** the build-in random() and randomblob() SQL functions. This interface allows
** applications to access the same PRNG for other purposes.
**
** ^A call to this routine stores N bytes of randomness into buffer P.
** ^The P parameter can be a NULL pointer.
**
** ^If this routine has not been previously called or if the previous
** call had N less than one or a NULL pointer for P, then the PRNG is
** seeded using randomness obtained from the xRandomness method of
** the default [sqlite3_vfs] object.
** ^If the previous call to this routine had an N of 1 or more and a
** non-NULL P then the pseudo-randomness is generated
** internally and without recourse to the [sqlite3_vfs] xRandomness
** method.
Properties such as "out2" or "jump" that are specified in
** comments following the "case" for each opcode in the vdbe.c
** are encoded into bitvectors as follows:
Value returned by sqlite3_changes()
The page getter for when memory-mapped I/O is enabled
pnBlob must be non-NULL. paBlob may be NULL or non-NULL.
True for a prefix iterator
RP => nothing
comment: An aggregate function in the WHERE clause of a query means this must
** be a correlated sub-query, and expression pExpr is an aggregate from
** the parent context. Do not walk the function arguments in this case.
**
** todo: It should be possible to replace this node with a TK_REGISTER
** expression, as the result of the expression must be stored in a
** register at this point. The same holds for TK_AGG_COLUMN nodes.
label: code-design
addrBrk for the outermost loop
Takes the conch by taking a shared lock and read the contents conch, if
** lockPath is non-NULL, the host ID and lock file path must match. A NULL
** lockPath means that the lockPath in the conch file will be used if the
** host IDs match, or a new lock path will be generated automatically
** and written to the conch file.
Move the cursor so that it points to an entry near the key
** specified by pIdxKey or intKey. Return a success code.
**
** For INTKEY tables, the intKey parameter is used. pIdxKey
** must be NULL. For index tables, pIdxKey is used and intKey
** is ignored.
**
** If an exact match is not found, then the cursor is always
** left pointing at a leaf page which would hold the entry if it
** were present. The cursor might point to an entry that comes
** before or after the key.
**
** An integer is written into *pRes which is the result of
** comparing the key with the entry to which the cursor is
** pointing. The meaning of the integer written into
** *pRes is as follows:
**
** *pRes<0 The cursor is left pointing at an entry that
** is smaller than intKey/pIdxKey or if the table is empty
** and the cursor is therefore left point to nothing.
**
** *pRes==0 The cursor is left pointing at an entry that
** exactly matches intKey/pIdxKey.
**
** *pRes>0 The cursor is left pointing at an entry that
** is larger than intKey/pIdxKey.
**
** For index tables, the pIdxKey->eqSeen field is set to 1 if there
** exists an entry in the table that exactly matches pIdxKey.
The table containing the value
SELECT rowid ...
OUT: Bytes of string content
** Insert a new record into the BTree. The content of the new record
** is described by the pX object. The pCur cursor is used only to
** define what table the record should be inserted into, and is left
** pointing at a random location.
**
** For a table btree (used for rowid tables), only the pX.nKey value of
** the key is used. The pX.pKey value must be NULL. The pX.nKey is the
** rowid or INTEGER PRIMARY KEY of the row. The pX.nData,pData,nZero fields
** hold the content of the row.
**
** For an index btree (used for indexes and WITHOUT ROWID tables), the
** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
** pX.pData,nData,nZero fields must be zero.
**
** If the seekResult parameter is non-zero, then a successful call to
** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already
** been performed. In other words, if seekResult!=0 then the cursor
** is currently pointing to a cell that will be adjacent to the cell
** to be inserted. If seekResult<0 then pCur points to a cell that is
** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
** that is larger than (pKey,nKey).
**
** If seekResult==0, that means pCur is pointing at some unknown location.
** In that case, this routine must seek the cursor to the correct insertion
** point for (pKey,nKey) before doing the insertion. For index btrees,
** if pX->nMem is non-zero, then pX->aMem contains pointers to the unpacked
** key values and pX->aMem can be used instead of pX->pKey to avoid having
** to decode the key.
True if this is likely to be an append
** Check that:
**
** 1) All leaves of pSeg between iFirst and iLast (inclusive) exist and
** contain zero terms.
** 2) All leaves of pSeg between iNoRowid and iLast (inclusive) exist and
** contain zero rowids.
** Implementation of SQLite REGEXP operator. This scalar function takes
** two arguments. The first is a regular expression pattern to compile
** the second is a string to match against that pattern. If either
** argument is an SQL NULL, then NULL Is returned. Otherwise, the result
** is 1 if the string matches the pattern, or 0 otherwise.
**
** SQLite maps the regexp() function to the regexp() operator such
** that the following two are equivalent:
**
** zString REGEXP zPattern
** regexp(zPattern, zString)
**
** Uses the following ICU regexp APIs:
**
** uregex_open()
** uregex_matches()
** uregex_close()
This block calculates the checksum according to the FTS index.
Space for values for UPDATE inversion
Able to support an IN operator
Entries in aFrame[] array
If non-zero, replace first 4 bytes with this value
index entries counter
comment:
** The iterator object passed as the second argument currently contains
** no valid values except for the Fts5SegIter.pLeaf member variable. This
** function searches the leaf page for a term matching (pTerm/nTerm).
**
** If the specified term is found on the page, then the iterator is left
** pointing to it. If argument bGe is zero and the term is not found,
** the iterator is left pointing at EOF.
**
** If bGe is non-zero and the specified term is not found, then the
** iterator is left pointing to the smallest term in the segment that
** is larger than the specified term, even if this term is not on the
** current page.
label: code-design
Max tokens per snippet
The docid to be deleted
CREATE
Opcode: Function P1 P2 P3 P4 P5
** Synopsis: r[P3]=func(r[P2@P5])
**
** Invoke a user function (P4 is a pointer to an sqlite3_context object that
** contains a pointer to the function to be run) with P5 arguments taken
** from register P2 and successors. The result of the function is stored
** in register P3. Register P3 must not be one of the function inputs.
**
** P1 is a 32-bit bitmask indicating whether or not each argument to the
** function was determined to be constant at compile time. If the first
** argument was constant then bit 0 of P1 is set. This is used to determine
** whether meta data associated with a user function argument using the
** sqlite3_set_auxdata() API may be safely retained until the next
** invocation of this opcode.
**
** SQL functions are initially coded as OP_Function0 with P4 pointing
** to a FuncDef object. But on first evaluation, the P4 operand is
** automatically converted into an sqlite3_context object and the operation
** changed to this OP_Function opcode. In this way, the initialization of
** the sqlite3_context object occurs only once, rather than once for each
** evaluation of the function.
**
** See also: Function0, AggStep, AggFinal
Library used incorrectly
b: p3<<28 | p5<<14 | p7 (unmasked)
The format field code letter
IMP: R-51513-12026 The last_insert_rowid() SQL function is a
** wrapper around the sqlite3_last_insert_rowid() C/C++ interface
** function.
** Return the value of the integer key or "rowid" for a table btree.
** This routine is only valid for a cursor that is pointing into a
** ordinary table btree. If the cursor points to an index btree or
** is invalid, the result of this routine is undefined.
languageid=?
Content to be checksummed
Number of columns in zTab
** Return a pointer to payload information from the entry that the
** pCur cursor is pointing to. The pointer is to the beginning of
** the key if index btrees (pPage->intKey==0) and is the data for
** table btrees (pPage->intKey==1). The number of bytes of available
** key/data is written into *pAmt. If *pAmt==0, then the value
** returned will not be a valid pointer.
**
** This routine is an optimization. It is common for the entire key
** and data to fit on the local page and for there to be no overflow
** pages. When that is so, this routine can be used to access the
** key and data without making a copy. If the key and/or data spills
** onto overflow pages, then accessPayload() must be used to reassemble
** the key/data and copy it into a preallocated buffer.
**
** The pointer returned by this routine looks directly into the cached
** page of the database. The data might change or move the next time
** any btree routine is called.
Number of databases with an active write-transaction
** that are candidates for a two-phase commit using a
** master-journal
The bottom of the main insertion loop, if the data source
** is a SELECT statement.
** Add a whole list of operations to the operation stack. Return a
** pointer to the first operation inserted.
**
** Non-zero P2 arguments to jump instructions are automatically adjusted
** so that the jump target is relative to the first operation inserted.
Number of prior equality constraints on same index
If iPtr is another freeblock (that is, if iPtr is not the freelist
** pointer in the page header) then check to see if iStart should be
** coalesced onto the end of iPtr.
A Btree handle
**
** A database connection contains a pointer to an instance of
** this object for every database file that it has open. This structure
** is opaque to the database connection. The database connection cannot
** see the internals of this structure and only deals with pointers to
** this structure.
**
** For some database files, the same underlying database cache might be
** shared between multiple connections. In that case, each connection
** has it own instance of this object. But each instance of this object
** points to the same BtShared object. The database cache and the
** schema associated with the database file are all contained within
** the BtShared object.
**
** All fields in this structure are accessed under sqlite3.mutex.
** The pBt pointer itself may not be changed while there exists cursors
** in the referenced BtShared that point back to this Btree since those
** cursors have to go through this Btree to find their BtShared and
** they often do so without holding sqlite3.mutex.
Pointer to current file mapping
unlock failed with an error
** This function is a wrapper around the OS specific implementation of
** sqlite3_os_init(). The purpose of the wrapper is to provide the
** ability to simulate a malloc failure, so that the handling of an
** error in sqlite3_os_init() by the upper layers can be tested.
If there are now no dirty pages in the cache, set eCreate to 2.
** This is an optimization that allows sqlite3PcacheFetch() to skip
** searching for a dirty page to eject from the cache when it might
** otherwise have to.
Check to see if we should honor DESC requests on index columns
Pointer to sqlite3_int64 variable
Average size of database rows, in pages
The SELECT statement with the ORDER BY clause
** Set the EP_FromJoin property on all terms of the given expression.
** And set the Expr.iRightJoinTable to iTable for every term in the
** expression.
**
** The EP_FromJoin property is used on terms of an expression to tell
** the LEFT OUTER JOIN processing logic that this term is part of the
** join restriction specified in the ON or USING clause and not a part
** of the more general WHERE clause. These terms are moved over to the
** WHERE clause during join processing but we need to remember that they
** originated in the ON or USING clause.
**
** The Expr.iRightJoinTable tells the WHERE clause processing that the
** expression depends on table iRightJoinTable even if that table is not
** explicitly mentioned in the expression. That information is needed
** for cases like this:
**
** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
**
** The where clause needs to defer the handling of the t1.x=5
** term until after the t2 loop of the join. In that way, a
** NULL t2 row will be inserted whenever t1.x!=5. If we do not
** defer the handling of t1.x=5, it will be processed immediately
** after the t1 loop and rows with t1.x!=5 will never appear in
** the output, which is incorrect.
324
.eSubtype =
** Create a new cursor for the BTree whose root is on the page
** iTable. If a read-only cursor is requested, it is assumed that
** the caller already has at least a read-only transaction open
** on the database already. If a write-cursor is requested, then
** the caller is assumed to have an open write transaction.
**
** If the BTREE_WRCSR bit of wrFlag is clear, then the cursor can only
** be used for reading. If the BTREE_WRCSR bit is set, then the cursor
** can be used for reading or for writing if other conditions for writing
** are also met. These are the conditions that must be met in order
** for writing to be allowed:
**
** 1: The cursor must have been opened with wrFlag containing BTREE_WRCSR
**
** 2: Other database connections that share the same pager cache
** but which are not in the READ_UNCOMMITTED state may not have
** cursors open with wrFlag==0 on the same table. Otherwise
** the changes made by this write cursor would be visible to
** the read cursors in the other database connection.
**
** 3: The database must be writable (not on read-only media)
**
** 4: There must be an active transaction.
**
** The BTREE_FORDELETE bit of wrFlag may optionally be set if BTREE_WRCSR
** is set. If FORDELETE is set, that is a hint to the implementation that
** this cursor will only be used to seek to and delete entries of an index
** as part of a larger DELETE statement. The FORDELETE hint is not used by
** this implementation. But in a hypothetical alternative storage engine
** in which index entries are automatically deleted when corresponding table
** rows are deleted, the FORDELETE flag is a hint that all SEEK and DELETE
** operations on this cursor can be no-ops and all READ operations can
** return a null row (2-bytes: 0x01 0x00).
**
** No checking is done to make sure that page iTable really is the
** root page of a b-tree. If it is not, then the cursor acquired
** will not work correctly.
**
** It is assumed that the sqlite3BtreeCursorZero() has been called
** on pCur to initialize the memory space prior to invoking this routine.
Address of the OP_SorterOpen or OP_OpenEphemeral
** Append a message to the error message string.
First argument to xLog()
Truncate WAL to this size upon reset
** Print the value of a register for tracing purposes:
comment: The next four values are not used by PRAGMAs or by sqlite3_dbconfig() and
** could be factored out into a separate bit vector of the sqlite3 object.
label: code-design
0x0f
The pointer map page
14
Generate a coroutine to evaluate the SELECT statement on
** the right - the "B" select
33
At this point it must be known if the %_stat table exists or not.
** So bHasStat may not be 2.
Store the page number here
** If the argument is not NULL, it points to a Wal object that holds a
** read-lock. This function returns the database page-size if it is known,
** or zero if it is not (or if pWal is NULL).
WITHOUT => ID
Restore the pRec->nField value before returning.
Used in COMDB2 but not native SQLite
The table already exists. If zWhere is not NULL, delete all entries
** associated with the table zWhere. If zWhere is NULL, delete the
** entire contents of the table.
Leaf on which the required cell resides
EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
** and the reserved space is zero (the usual value for reserved space)
** then the cell content offset of an empty page wants to be 65536.
** However, that integer is too large to be stored in a 2-byte unsigned
** integer, so a value of 0 is used in its place.
First byte of the locking range
First arg to pass to pApi functions
uppercase equivalent to lowercase
ASC
Change the journal mode.
** A WhereTerm with eOperator==WO_AND has its u.pAndInfo pointer set to
** a dynamically allocated instance of the following structure.
Either CHANGESET_DATA or CONFLICT
Pager structure
comment: A complete hash table is an instance of the following structure.
** The internals of this structure are intended to be opaque -- client
** code should not attempt to access or modify the fields of this structure
** directly. Change this structure only by using the routines below.
** However, some of the "procedures" and "functions" for modifying and
** accessing this structure are really macros, so we can't really make
** this structure opaque.
**
** All elements of the hash table are on a single doubly-linked list.
** Hash.first points to the head of this list.
**
** There are Hash.htsize buckets. Each bucket points to a spot in
** the global doubly-linked list. The contents of the bucket are the
** element pointed to plus the next _ht.count-1 elements in the list.
**
** Hash.htsize and Hash.ht may be zero. In that case lookup is done
** by a linear search of the global list. For small tables, the
** Hash.ht table is never allocated because if there are few elements
** in the table, it is faster to do a linear search than to manage
** the hash table.
label: code-design
comment: If the SELECT statement has an ORDER BY clause, zero the
** iOrderByCol variables. These are set to non-zero when an
** ORDER BY term exactly matches one of the terms of the
** result-set. Since the result-set of the SELECT statement may
** have been modified or reordered, these variables are no longer
** set correctly. Since setting them is just an optimization,
** it's easiest just to zero them here.
label: code-design
comment:
** CAPI3REF: Destroy a snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
** The application must eventually free every [sqlite3_snapshot] object
** using this routine to avoid a memory leak.
**
** The [sqlite3_snapshot_free()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
label: code-design
SQLITE_MEMDEBUG
Call below is a no-op for NDEBUG builds
Sorter file to read from
** Merge all doclists in the TermSelect.aaOutput[] array into a single
** doclist stored in TermSelect.aaOutput[0]. If successful, delete all
** other doclists (except the aaOutput[0] one) and return SQLITE_OK.
**
** If an OOM error occurs, return SQLITE_NOMEM. In this case it is
** the responsibility of the caller to free any doclists left in the
** TermSelect.aaOutput[] array.
Context passed to xToken()
If there is a schema mismatch on the current table, proceed to the
** next change. A log message has already been issued.
The expression list to be coded
If all query phrases seen by fts3BestSnippet() are present in at least
** one of the nSnippet snippet fragments, break out of the loop.
nearphrases ::= phrase
significand
** End of interface to code in fts5_expr.c.
*************************************************************************
Table for TK_COLUMN expressions.
Column cache
column i is unchanged if aiChng[i]<0
RHS of LIKE/GLOB operator
** This routine is called to increment the value of the database file
** change-counter, stored as a 4-byte big-endian integer starting at
** byte offset 24 of the pager file. The secondary change counter at
** 92 is also updated, as is the SQLite version number at offset 96.
**
** But this only happens if the pPager->changeCountDone flag is false.
** To avoid excess churning of page 1, the update only happens once.
** See also the pager_write_changecounter() routine that does an
** unconditional update of the change counters.
**
** If the isDirectMode flag is zero, then this is done by calling
** sqlite3PagerWrite() on page 1, then modifying the contents of the
** page data. In this case the file will be updated when the current
** transaction is committed.
**
** The isDirectMode flag may only be non-zero if the library was compiled
** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
** if isDirect is non-zero, then the database file is updated directly
** by writing an updated version of page 1 using a call to the
** sqlite3OsWrite() function.
Number of entries in aTerm[]
Run a separate WHERE clause for each term of the OR clause. After
** eliminating duplicates from other WHERE clauses, the action for each
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
Opcode: Destroy P1 P2 P3 * *
**
** Delete an entire database table or index whose root page in the database
** file is given by P1.
**
** The table being destroyed is in the main database file if P3==0. If
** P3==1 then the table to be clear is in the auxiliary database file
** that is used to store tables create using CREATE TEMPORARY TABLE.
**
** If AUTOVACUUM is enabled then it is possible that another root page
** might be moved into the newly deleted root page in order to keep all
** root pages contiguous at the beginning of the database. The former
** value of the root page that moved - its value before the move occurred -
** is stored in register P2. If no page movement was required (because the
** table being dropped was already the last one in the database) then a
** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
** is stored in register P2.
**
** This opcode throws an error if there are any active reader VMs when
** it is invoked. This is done to avoid the difficulty associated with
** updating existing cursors when a root page is moved in an AUTOVACUUM
** database. This error is thrown even if the database is not an AUTOVACUUM
** db in order to avoid introducing an incompatibility between autovacuum
** and non-autovacuum modes.
**
** See also: Clear
** Estimate the number of rows that will be returned based on
** an IN constraint where the right-hand side of the IN operator
** is a list of values. Example:
**
** WHERE x IN (1,2,3,4)
**
** Write the estimated row count into *pnRow and return SQLITE_OK.
** If unable to make an estimate, leave *pnRow unchanged and return
** non-zero.
**
** This routine can fail if it is unable to load a collating sequence
** required for string comparison, or if unable to allocate memory
** for a UTF conversion required for comparison. The error is stored
** in the pParse structure.
defined(SQLITE_WIN32_HAS_WIDE)
An ordinary table or view name in the FROM clause
Extra information if (eOperator& WO_AND)!=0
Cache that currently owns this page
** This function is invoked by the parser to call the xConnect() method
** of the virtual table pTab. If an error occurs, an error code is returned
** and an error left in pParse.
**
** This call is a no-op if table pTab is not a virtual table.
Result pgno must be greater than iMin
Number of arguments to the module
Opcode: Copy P1 P2 P3 * *
** Synopsis: r[P2@P3+1]=r[P1@P3+1]
**
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
**
** This instruction makes a deep copy of the value. A duplicate
** is made of any string or blob constant. See also OP_SCopy.
For assigning database names to pTable
The VDBE we are building
** This function implements the FTS3_MATCHINFO_LCS matchinfo() flag.
**
** If the call is successful, the longest-common-substring lengths for each
** column are written into the first nCol elements of the pInfo->aMatchinfo[]
** array before returning. SQLITE_OK is returned in this case.
**
** Otherwise, if an error occurs, an SQLite error code is returned and the
** data written to the first nCol elements of pInfo->aMatchinfo[] is
** undefined.
Right side of comparison
Error msg written here
Path to state db (or NULL if zRbu)
having_opt
setlist ::= setlist COMMA nm EQ expr
comment: Overwrite freed memory with the 0x55 bit pattern to verify that it is
** not used after being freed
label: code-design
** Return the total number of entries read from the %_data table by
** this connection since it was created.
10
we could have it if we want it
iOnceResetThreshold
** Adjust the highwater mark if necessary.
** The caller must hold the appropriate mutex.
Source database name
SELECT
Launch a background thread for this operation
Value is a string
in case we need to retry the :auto: lock file -
** we should never get here except via the 'continue' call.
Current WhereLoop being processed.
zero or more SQLITE_TRACE flags
** The xDestroy() virtual table method.
Set $p to point to the next leaf in the tree of eType nodes
SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK
** Return the register of pOp->p2 after first preparing it to be
** overwritten with an integer value.
IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
** suggested cache size is set to N.
** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
** than 32767 we have to make it 32-bit. 16-bit is preferred because
** it uses less memory in the Expr object, which is a big memory user
** in systems with lots of prepared statements. And few applications
** need more than about 10 or 20 variables. But some extreme users want
** to have prepared statements with over 32767 variables, and for them
** the option is available (at compile-time).
** Argument eType must be one of RBU_INSERT, RBU_DELETE, RBU_IDX_INSERT or
** RBU_IDX_DELETE. This function performs the work of a single
** sqlite3rbu_step() call for the type of operation specified by eType.
True if decimal point should be shown
Buffer containing leaf data
Zero out anything following *ppList
Opcode: SeekRowid P1 P2 P3 * *
** Synopsis: intkey=r[P3]
**
** P1 is the index of a cursor open on an SQL table btree (with integer
** keys). If register P3 does not contain an integer or if P1 does not
** contain a record with rowid P3 then jump immediately to P2.
** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
** a record with rowid P3 then
** leave the cursor pointing at that record and fall through to the next
** instruction.
**
** The OP_NotExists opcode performs the same operation, but with OP_NotExists
** the P3 register must be guaranteed to contain an integer value. With this
** opcode, register P3 might not contain an integer.
**
** The OP_NotFound opcode performs the same operation on index btrees
** (with arbitrary multi-value keys).
**
** This opcode leaves the cursor in a state where it cannot be advanced
** in either direction. In other words, the Next and Prev opcodes will
** not work following this opcode.
**
** See also: Found, NotFound, NoConflict, SeekRowid
SQLITE_ALTER_TABLE
** Many system calls are accessed through pointer-to-functions so that
** they may be overridden at runtime to facilitate fault injection during
** testing and sandboxing. The following array holds the names and pointers
** to all overrideable system calls.
Number of extra registers to allocate
comment:
** Generate the beginning of the loop used for WHERE clause processing.
** The return value is a pointer to an opaque structure that contains
** information needed to terminate the loop. Later, the calling routine
** should invoke sqlite3WhereEnd() with the return value of this function
** in order to complete the WHERE clause processing.
**
** If an error occurs, this routine returns NULL.
**
** The basic idea is to do a nested loop, one loop for each table in
** the FROM clause of a select. (INSERT and UPDATE statements are the
** same as a SELECT with only a single table in the FROM clause.) For
** example, if the SQL is this:
**
** SELECT * FROM t1, t2, t3 WHERE ...;
**
** Then the code generated is conceptually like the following:
**
** foreach row1 in t1 do \ Code generated
** foreach row2 in t2 do |-- by sqlite3WhereBegin()
** foreach row3 in t3 do /
** ...
** end \ Code generated
** end |-- by sqlite3WhereEnd()
** end /
**
** Note that the loops might not be nested in the order in which they
** appear in the FROM clause if a different order is better able to make
** use of indices. Note also that when the IN operator appears in
** the WHERE clause, it might result in additional nested loops for
** scanning through all values on the right-hand side of the IN.
**
** There are Btree cursors associated with each table. t1 uses cursor
** number pTabList->a[0].iCursor. t2 uses the cursor pTabList->a[1].iCursor.
** And so forth. This routine generates code to open those VDBE cursors
** and sqlite3WhereEnd() generates the code to close them.
**
** The code that sqlite3WhereBegin() generates leaves the cursors named
** in pTabList pointing at their appropriate entries. The [...] code
** can use OP_Column and OP_Rowid opcodes on these cursors to extract
** data from the various tables of the loop.
**
** If the WHERE clause is empty, the foreach loops must each scan their
** entire tables. Thus a three-way join is an O(N^3) operation. But if
** the tables have indices and there are terms in the WHERE clause that
** refer to those indices, a complete table scan can be avoided and the
** code will run much faster. Most of the work of this routine is checking
** to see if there are indices that can be used to speed up the loop.
**
** Terms of the WHERE clause are also used to limit which rows actually
** make it to the "..." in the middle of the loop. After each "foreach",
** terms of the WHERE clause that use only terms in that loop and outer
** loops are evaluated and if false a jump is made around all subsequent
** inner loops (or around the "..." if the test occurs within the inner-
** most loop)
**
** OUTER JOINS
**
** An outer join of tables t1 and t2 is conceptally coded as follows:
**
** foreach row1 in t1 do
** flag = 0
** foreach row2 in t2 do
** start:
** ...
** flag = 1
** end
** if flag==0 then
** move the row2 cursor to a null row
** goto start
** fi
** end
**
** ORDER BY CLAUSE PROCESSING
**
** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
** if there is one. If there is no ORDER BY clause or if this routine
** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
**
** The iIdxCur parameter is the cursor number of an index. If
** WHERE_OR_SUBCLAUSE is set, iIdxCur is the cursor number of an index
** to use for OR clause processing. The WHERE clause should use this
** specific cursor. If WHERE_ONEPASS_DESIRED is set, then iIdxCur is
** the first cursor in an array of cursors for all indices. iIdxCur should
** be used to compute the appropriate cursor depending on which index is
** used.
label: code-design
comment: First unused byte of aSpace1[]
label: code-design
Step 1.
** pExpr is a CHECK constraint on a row that is being UPDATE-ed. The
** only columns that are modified by the UPDATE are those for which
** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true.
**
** Return true if CHECK constraint pExpr does not use any of the
** changing columns (or the rowid if it is changing). In other words,
** return true if this CHECK constraint can be skipped when validating
** the new row in the UPDATE statement.
sclp
Name of tokenizer
comment: FTS5INDEX_QUERY_XXX flags
label: code-design
Columns in the other table
LHS fields are not reordered
** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
** and the WhereInfo.wctrlFlags member.
**
** Value constraints (enforced via assert()):
** WHERE_USE_LIMIT == SF_FixedLimit
************* End of fts3_snippet.c ***************************************
Ephemeral table holding all primary key values
** An rtree virtual-table object.
Search strategy (see below)
pPage is a leaf node. This loop navigates the cursor so that it
** points to the first interior cell that it points to the parent of
** the next page in the tree that has not yet been visited. The
** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
** of the page, or to the number of cells in the page if the next page
** to visit is the right-child of its parent.
**
** If all pages in the tree have been visited, return SQLITE_OK to the
** caller.
278
increment the cell count
TEXT
Non-zero if an error has occurred
Number of PMAs to read
Bytes of prefix compression for term
Newly allocated session object
xRename
Table containing the REFERENCES clause (aka: Child)
Name of the table into which we insert
If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
** All the reasons those functions might return SQLITE_ERROR - missing
** table, missing row, non-blob/text in block column - indicate
** backing store corruption.
** This section provides definitions to allow the
** FTS3 extension to be compiled outside of the
** amalgamation.
New object
Counter variable
220
** Macros determining the rowids used by segment leaves and dlidx leaves
** and nodes. All nodes and leaves are stored in the %_data table with large
** positive rowids.
**
** Each segment has a unique non-zero 16-bit id.
**
** The rowid for each segment leaf is found by passing the segment id and
** the leaf page number to the FTS5_SEGMENT_ROWID macro. Leaves are numbered
** sequentially starting from 1.
27
synopsis: r[P2]=parameter(P1,P4)
comment:
** The pointer map is a lookup table that identifies the parent page for
** each child page in the database file. The parent page is the page that
** contains a pointer to the child. Every page in the database contains
** 0 or 1 parent pages. (In this context 'database page' refers
** to any page that is not part of the pointer map itself.) Each pointer map
** entry consists of a single byte 'type' and a 4 byte parent page number.
** The PTRMAP_XXX identifiers below are the valid types.
**
** The purpose of the pointer map is to facility moving pages from one
** position in the file to another as part of autovacuum. When a page
** is moved, the pointer in its parent must be updated to point to the
** new location. The pointer map is used to locate the parent page quickly.
**
** PTRMAP_ROOTPAGE: The database page is a root-page. The page-number is not
** used in this case.
**
** PTRMAP_FREEPAGE: The database page is an unused (free) page. The page-number
** is not used in this case.
**
** PTRMAP_OVERFLOW1: The database page is the first page in a list of
** overflow pages. The page number identifies the page that
** contains the cell with a pointer to this overflow page.
**
** PTRMAP_OVERFLOW2: The database page is the second or later page in a list of
** overflow pages. The page-number identifies the previous
** page in the overflow page list.
**
** PTRMAP_BTREE: The database page is a non-root btree page. The page number
** identifies the parent page in the btree.
label: code-design
The following line of code (and the "p++" below the while() loop) is
** normally all that is required to move pointer p to the desired
** position. The exception is if this node is being loaded from disk
** incrementally and pointer "p" now points to the first byte past
** the populated part of pReader->aNode[].
synopsis: iDb=P1 root=P2 write=P3
** INSERT STACK UNION HERE **
Maximum Sorter PMA size
SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE
If the file exists, it fails.
VdbeCursor row cache generation counter
First register in a range holding values to insert
Size in bytes of each node in the node table
Finish committing the transaction to the destination database.
(310) nmnum ::= nm (OPTIMIZED OUT)
** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
**
** Return a string described by FORMAT. Conversions as follows:
**
** %d day of month
** %f ** fractional seconds SS.SSS
** %H hour 00-24
** %j day of year 000-366
** %J ** julian day number
** %m month 01-12
** %M minute 00-59
** %s seconds since 1970-01-01
** %S seconds 00-59
** %w day of week 0-6 sunday==0
** %W week of year 00-53
** %Y year 0000-9999
** %% %
If this page has already been played back before during the current
** rollback, then don't bother to play it back again.
Position-list
246
Space for copies of dividers cells
Find the next row in the Queue and output that row
Insert the marker in the %_segments table to make sure nobody tries
** to steal the space just allocated. This is also used to identify
** appendable segments.
start_block
ccons ::= UNIQUE onconf
Null
If this is an UPDATE or DELETE, read the old.* record.
IMP: R-31676-45509 If X is the integer -9223372036854775808
** then abs(X) throws an integer overflow error since there is no
** equivalent positive 64-bit two complement value.
*************************************************************************
** Interface to code in fts5_tokenizer.c.
125
** This function allocates a new level iLevel index in the segdir table.
** Usually, indexes are allocated within a level sequentially starting
** with 0, so the allocated index is one greater than the value returned
** by:
**
** SELECT max(idx) FROM %_segdir WHERE level = :iLevel
**
** However, if there are already FTS3_MERGE_COUNT indexes at the requested
** level, they are merged into a single level (iLevel+1) segment and the
** allocated index is 0.
**
** If successful, *piIdx is set to the allocated index slot and SQLITE_OK
** returned. Otherwise, an SQLite error code is returned.
UTF16 with high-order bytes non-zero
rowid = ? expression (or NULL)
comment: Final cleanup
label: code-design
Register for rowset of rows to delete
Number of pages left to copy
Used when p4type is P4_INTARRAY
The database connection whose status is desired
comment:
** Change the "soft" limit on the number of pages in the cache.
** Unused and unmodified pages will be recycled when the number of
** pages in the cache exceeds this soft limit. But the size of the
** cache is allowed to grow larger than this limit if it contains
** dirty pages or pages still in active use.
label: code-design
xEof
Init nFree to non-freeblock free space
128
True if read-only
This routine is just a convenient place to set a breakpoint that will
** fire after each opcode is inserted and displayed using
** "PRAGMA vdbe_addoptrace=on".
If control flows to this point, then it was not possible to add the
** the page being freed as a leaf page of the first trunk in the free-list.
** Possibly because the free-list is empty, or possibly because the
** first trunk in the free-list is full. Either way, the page being freed
** will become the new first trunk page in the free-list.
Array of nodes containing the parse
The opcode to be commented
** When this function is called, *ppPoslist is assumed to point to the
** start of a position-list. After it returns, *ppPoslist points to the
** first byte after the position-list.
**
** A position list is list of positions (delta encoded) and columns for
** a single document record of a doclist. So, in other words, this
** routine advances *ppPoslist so that it points to the next docid in
** the doclist, or to the first byte past the end of the doclist.
**
** If pp is not NULL, then the contents of the position list are copied
** to *pp. *pp is set to point to the first byte past the last byte copied
** before this function returns.
Overwrite the old cell with the new if they are the same size.
** We could also try to do this if the old cell is smaller, then add
** the leftover space to the free list. But experiments show that
** doing that is no faster then skipping this optimization and just
** calling dropCell() and insertCell().
**
** This optimization cannot be used on an autovacuum database if the
** new entry uses overflow pages, as the insertCell() call below is
** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry.
Figure out the size of the output
Restore the original value of db->flags
A pending-terms seg-reader for an FTS4 table that uses order=desc.
** Pending-terms doclists are always built up in ascending order, so
** we have to iterate through them backwards here.
** Combinations of two or more EP_* flags
** CAPI3REF: Fundamental Datatypes
** KEYWORDS: SQLITE_TEXT
**
** ^(Every value in SQLite has one of five fundamental datatypes:
**
** <ul>
** <li> 64-bit signed integer
** <li> 64-bit IEEE floating point number
** <li> string
** <li> BLOB
** <li> NULL
** </ul>)^
**
** These constants are codes for each of those types.
**
** Note that the SQLITE_TEXT constant was also used in SQLite version 2
** for a completely different meaning. Software that links against both
** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
** SQLITE_TEXT.
Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
** handle rows (possibly in other tables) that refer via a foreign key
** to the row just deleted.
Set if thread is finished but not joined
The complete WHERE clause
Array to sort entries of
'@', '#', ':'. Alphabetic SQL variables
Now check that the iter.nEmpty leaves following the current leaf
** (a) exist and (b) contain no terms.
** End of the special code for wince
****************************************************************************
The aArg[] array needs to grow.
Hash of the name
An instance of the IdxExprTrans object carries information about a
** mapping from an expression on table columns into a column in an index
** down through the Walker.
If we reach this point, that means it is OK to perform the transformation
Cell pCell is destined for new sibling page pNew. Originally, it
** was either part of sibling page iOld (possibly an overflow cell),
** or else the divider cell to the left of sibling page iOld. So,
** if sibling page iOld had the same page number as pNew, and if
** pCell really was a part of sibling page iOld (not a divider or
** overflow cell), we can skip updating the pointer map entries.
Deal with as much of this write request as possible by transfering
** data from the memory mapping using memcpy().
comment: TODO: Check that zTarget and zRbu are non-NULL
label: requirement
If not NULL, info on how to process DISTINCT
Table we are trying to access
Set up appropriate ctrlFlags
comment:
** This function is called when initializing an FTS4 table that uses the
** content=xxx option. It determines the number of and names of the columns
** of the new FTS4 table.
**
** The third argument passed to this function is the value passed to the
** config=xxx option (i.e. "xxx"). This function queries the database for
** a table of that name. If found, the output variables are populated
** as follows:
**
** *pnCol: Set to the number of columns table xxx has,
**
** *pnStr: Set to the total amount of space required to store a copy
** of each columns name, including the nul-terminator.
**
** *pazCol: Set to point to an array of *pnCol strings. Each string is
** the name of the corresponding column in table xxx. The array
** and its contents are allocated using a single allocation. It
** is the responsibility of the caller to free this allocation
** by eventually passing the *pazCol value to sqlite3_free().
**
** If the table cannot be found, an error code is returned and the output
** variables are undefined. Or, if an OOM is encountered, SQLITE_NOMEM is
** returned (and the output variables are undefined).
label: code-design
True if rowid is UPDATEd
** Return the VDBE address or label to jump to in order to continue
** immediately with the next row of a WHERE clause.
Numeric type of right operand
Not an index on expressions
** Expand the space allocated for the given SrcList object by
** creating nExtra new slots beginning at iStart. iStart is zero based.
** New slots are zeroed.
**
** For example, suppose a SrcList initially contains two entries: A,B.
** To append 3 new entries onto the end, do this:
**
** sqlite3SrcListEnlarge(db, pSrclist, 3, 2);
**
** After the call above it would contain: A, B, nil, nil, nil.
** If the iStart argument had been 1 instead of 2, then the result
** would have been: A, nil, nil, nil, B. To prepend the new slots,
** the iStart value would be 0. The result then would
** be: nil, nil, nil, A, B.
**
** If a memory allocation fails the SrcList is unchanged. The
** db->mallocFailed flag will be set to true.
WHERE analyse context
************* End of fts3_tokenizer.h *************************************
selcollist ::= sclp nm DOT STAR
SQLITE_OMIT_CAST
Number of virtual machine steps
File handle
Offset of first byte to lock
For nVector==1, combine steps 6 and 7 by immediately returning
** FALSE if the first comparison is not NULL
145
Size of azCol[] and abPK[] arrays
Create/open the named mutex
Type of value (SQLITE_NULL, TEXT etc.)
** Delete a "porter" tokenizer.
Only the admin user is allowed to know that the sqlite_user table
** exists
This is the top of the main insertion loop
Index of %_segdir entry to delete
Find the start of the next token.
EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
** in the SQLITE_CHECKPOINT_PASSIVE mode.
Generate a single row of result
Position in FROM clause of table for this loop
fall through to real
266
** This routine is called to create a new foreign key on the table
** currently under construction. pFromCol determines which columns
** in the current table point to the foreign key. If pFromCol==0 then
** connect the key to the last column inserted. pTo is the name of
** the table referred to (a.k.a the "parent" table). pToCol is a list
** of tables in the parent pTo table. flags contains all
** information about the conflict resolution algorithms specified
** in the ON DELETE, ON UPDATE and ON INSERT clauses.
**
** An FKey structure is created and added to the table currently
** under construction in the pParse->pNewTable field.
**
** The foreign key is set for IMMEDIATE processing. A subsequent call
** to sqlite3DeferForeignKey() might change this to DEFERRED.
Delete the cell in question from the leaf node.
** Rtree virtual table module xEof method.
**
** Return non-zero if the cursor does not currently point to a valid
** record (i.e if the scan has finished), or zero otherwise.
LP => nothing
** Retrieve a pointer to a static mutex or allocate a new dynamic one.
sortlist ::= expr sortorder
Do not delete from this cursor
raisetype ::= ABORT
Log2 of iFullSz/POW2_MIN
Delete everything from the shadow tables. Except, leave %_content as
** is if bContent is false.
Begin the database scan.
**
** Do not consider a single-pass strategy for a multi-row update if
** there are any triggers or foreign keys to process, or rows may
** be deleted as a result of REPLACE conflict handling. Any of these
** things might disturb a cursor being used to scan through the table
** or index, causing a single-pass approach to malfunction.
refact ::= CASCADE
The parsing context. Error messages written here
Opcode: Last P1 P2 P3 * *
**
** The next use of the Rowid or Column or Prev instruction for P1
** will refer to the last entry in the database table or index.
** If the table or index is empty and P2>0, then jump immediately to P2.
** If P2 is 0 or if the table or index is not empty, fall through
** to the following instruction.
**
** This opcode leaves the cursor configured to move in reverse order,
** from the end toward the beginning. In other words, the cursor is
** configured to use Prev, not Next.
**
** If P3 is -1, then the cursor is positioned at the end of the btree
** for the purpose of appending a new entry onto the btree. In that
** case P2 must be 0. It is assumed that the cursor is used only for
** appending and so if the cursor is valid, then the cursor must already
** be pointing at the end of the btree and so no changes are made to
** the cursor.
Allocated size of aDlidx[] array
** If the source-list item passed as an argument was augmented with an
** INDEXED BY clause, then try to locate the specified index. If there
** was such a clause and the named index cannot be found, return
** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
** pFrom->pIndex and return SQLITE_OK.
multiselect_op ::= UNION ALL
** Given an expression list, generate a KeyInfo structure that records
** the collating sequence for each expression in that expression list.
**
** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
** KeyInfo structure is appropriate for initializing a virtual index to
** implement that clause. If the ExprList is the result set of a SELECT
** then the KeyInfo structure is appropriate for initializing a virtual
** index to implement a DISTINCT test.
**
** Space to hold the KeyInfo structure is obtained from malloc. The calling
** function is responsible for seeing that this structure is eventually
** freed.
Token to defer
** Buffer zInput, length nInput, contains the contents of a quoted string
** that appeared as part of an fts3 query expression. Neither quote character
** is included in the buffer. This function attempts to tokenize the entire
** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE
** containing the results.
**
** If successful, SQLITE_OK is returned and *ppExpr set to point at the
** allocated Fts3Expr structure. Otherwise, either SQLITE_NOMEM (out of memory
** error) or SQLITE_ERROR (tokenization error) is returned and *ppExpr set
** to 0.
OUT: Error code. SQLITE_OK or ERROR
Length of the keyword
** Return the affinity character for a single column of a table.
First PmaReader to compare
Register to hold temp table ROWID
increment entry count
Set up for cell analysis
** If *pRc is not SQLITE_OK, or if pExpr is not the root node of a NEAR
** cluster, then this function returns 1 immediately.
**
** Otherwise, it checks if the current row really does match the NEAR
** expression, using the data currently stored in the position lists
** (Fts3Expr->pPhrase.doclist.pList/nList) for each phrase in the expression.
**
** If the current row is a match, the position list associated with each
** phrase in the NEAR expression is edited in place to contain only those
** phrase instances sufficiently close to their peers to satisfy all NEAR
** constraints. In this case it returns 1. If the NEAR expression does not
** match the current row, 0 is returned. The position lists may or may not
** be edited if 0 is returned.
35
Base cursor number
Mask of shared locks held
Create the custom VFS.
** This routine converts the sqlite3_pcache_page object returned by
** sqlite3PcacheFetch() into an initialized PgHdr object. This routine
** must be called after sqlite3PcacheFetch() in order to get a usable
** result.
Values
Amount of usable space on each page
One of the COLNAME_* constants
** Create a "porter" tokenizer.
140
1010
Number of bytes to zero in aPgno[]
IMP: R-04922-24076 The sqlite_compileoption_get() SQL function
** is a wrapper around the sqlite3_compileoption_get() C/C++ function.
** Invoke open(). Do so multiple times, until it either succeeds or
** fails for some reason other than EINTR.
**
** If the file creation mode "m" is 0 then set it to the default for
** SQLite. The default is SQLITE_DEFAULT_FILE_PERMISSIONS (normally
** 0644) as modified by the system umask. If m is not 0, then
** make the file creation mode be exactly m ignoring the umask.
**
** The m parameter will be non-zero only when creating -wal, -journal,
** and -shm files. We want those files to have *exactly* the same
** permissions as their original database, unadulterated by the umask.
** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
** transaction crashes and leaves behind hot journals, then any
** process that is able to write to the database will also be able to
** recover the hot journals.
Heap that might have been lookaside
Shared memory instance
Name of file to be deleted
Wal to close
True (1) if tz is valid
select ::= with selectnowith
Restriction 20
Number of columns or fields in the key
Make sure it is not a system table being altered, or a reserved name
** that the table is being renamed to.
fts3_aux.c
EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
** interior table b-tree page.
The only possible error from InitPage
192
The Expr.x union is never used at the same time as Expr.pRight
FROM clause must have exactly one term
SQLITE_RANGE
Name of VFS module to use
** End of code taken from fossil.
************************************************************************
Size of phrase in terms
Call sqlite3_declare_vtab()
comment:
** This function is used to parse both URIs and non-URI filenames passed by the
** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
** URIs specified as part of ATTACH statements.
**
** The first argument to this function is the name of the VFS to use (or
** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
** query parameter. The second argument contains the URI (or non-URI filename)
** itself. When this function is called the *pFlags variable should contain
** the default flags to open the database handle with. The value stored in
** *pFlags may be updated before returning if the URI filename contains
** "cache=xxx" or "mode=xxx" query parameters.
**
** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
** the VFS that should be used to open the database file. *pzFile is set to
** point to a buffer containing the name of the file to open. It is the
** responsibility of the caller to eventually call sqlite3_free() to release
** this buffer.
**
** If an error occurs, then an SQLite error code is returned and *pzErrMsg
** may be set to point to a buffer containing an English language error
** message. It is the responsibility of the caller to eventually release
** this buffer by calling sqlite3_free().
label: code-design
For FTS5_STRING - cluster of phrases
3rd input operand
Update a row in a main table b-tree
Number of aMem[] value. Might be zero
case_exprlist
Column snippet is extracted from
** If pBt points to an empty file then convert that empty file
** into a new empty database by initializing the first page of
** the database.
** Translate UTF-8 to UTF-8.
**
** This has the effect of making sure that the string is well-formed
** UTF-8. Miscoded characters are removed.
**
** The translation is done in-place and aborted if the output
** overruns the input.
SQLITE_AMALGAMATION
** Maximum supported symbolic links
!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5)
1470
** This function is called to handle the SQLITE_FCNTL_SIZE_HINT
** file-control operation. Enlarge the database to nBytes in size
** (rounded up to the next chunk-size). If the database is already
** nBytes or larger, this routine is a no-op.
Pointer map page index
If this is a prefix-search, and if the term that apSegment[0] points
** to does not share a suffix with pFilter->zTerm/nTerm, then all
** required callbacks have been made. In this case exit early.
**
** Similarly, if this is a search for an exact match, and the first term
** of segment apSegment[0] is not a match, exit early.
porter rule condition: (m = 1)
True for statements that do not write
Part of the record being decoded
Columns etc. for shadow table
Size of array argv[]
Create a cursor to hold the database open
Number of "," to insert
Adjust ancestry of this node.
The next index associated with the same table
trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt
Success code
xCommit
If the destination is DistFifo, then cursor (iParm+1) is open
** on an ephemeral index. If the current row is already present
** in the index, do not write it to the output. If not, add the
** current row to the index and proceed with writing it to the
** output table as well.
** Free an outstanding memory allocation.
True to store descending indexes
Sort data from this cursor
Variables populated by statDecodePage():
** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
The next line of code computes as follows, only faster:
** if( oc==OP_SeekGT || oc==OP_SeekLE ){
** r.default_rc = -1;
** }else{
** r.default_rc = +1;
** }
Number of hidden columns
** Return the type of the argument.
Value is undefined
Database in which module is registered
Used when pWLoop->wsFlags&WHERE_IN_ABLE
1310
Maximum number of samples to accumulate
** Search the first N tables in pSrc, from left to right, looking for a
** table that has a column named zCol.
**
** When found, set *piTab and *piCol to the table index and column index
** of the matching column and return TRUE.
**
** If not found, return FALSE.
Split the master block. Return the tail.
** Return a pointer to the Table structure for the table that a trigger
** is set on.
SQLITE_PROTOCOL
pNew->aSeg[]
58..5f XYZ[\]^_
Add the term to each of the prefix indexes that it is not too
** short for.
When allocating a new Vdbe object, all of the fields below should be
** initialized to zero or NULL
Name of the new SQL function
** Attempt to memory map file pFile. If successful, set *pp to point to the
** new mapping and return SQLITE_OK. If the mapping is not attempted
** (because the file is too large or the VFS layer is configured not to use
** mmap), return SQLITE_OK and set *pp to NULL.
**
** Or, if an error occurs, return an SQLite error code. The final value of
** *pp is undefined in this case.
if not __APPLE__
These conditions have already been verified in btreeInitPage()
** if PRAGMA cell_size_check=ON.
Address of "OP_Rewind iIdxCur"
comment: Any of the WHERE_COLUMN_xxx values
label: code-design
If there are no aggregate functions in the result-set, and no GROUP BY
** expression, do not allow aggregates in any of the other expressions.
** SQLite calls this function immediately after a call to unixDlSym() or
** unixDlOpen() fails (returns a null pointer). If a more detailed error
** message is available, it is written to zBufOut. If no error message
** is available, zBufOut is left unmodified and SQLite uses a default
** error message.
OUT: Values appended to the record
The thread identifier
ANALYZE
Number of tokens in table
PRAGMA index_xinfo = ?
************* End of vdbemem.c ********************************************
** Implementation of the json_array(VALUE,...) function. Return a JSON
** array that contains all values given in arguments. Or if any argument
** is a BLOB, throw an error.
Address of test for empty pDest
comment:
** CAPI3REF: Attempt To Free Heap Memory
**
** ^The sqlite3_release_memory() interface attempts to free N bytes
** of heap memory by deallocating non-essential memory allocations
** held by the database library. Memory used to cache database
** pages to improve performance is an example of non-essential memory.
** ^sqlite3_release_memory() returns the number of bytes actually freed,
** which might be more or less than the amount requested.
** ^The sqlite3_release_memory() routine is a no-op returning zero
** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
**
** See also: [sqlite3_db_release_memory()]
label: code-design
True if "#" flag is present
If true, create page if it does not exist already
Minimum number of regions required to be mapped.
Lookup key for the unixInodeInfo
Check that the LHS of the comparison is a column reference to
** the right column of the right source table. And that the sort
** order of the index column is the same as the sort order of the
** leftmost index column.
The conditions tested below might not be true
** in a corrupt database
Buffer containing previous term on page
The Queue table
** This function is called when deleting or updating a row to implement
** any required CASCADE, SET NULL or SET DEFAULT actions.
Failed to find the required lock.
Calculate nLeafEst.
5 TRIGGER:
We know that the regSampleRowid row exists because it was read by
** the previous loop. Thus the not-found jump of seekOp will never
** be taken
comment:
** CAPI3REF: Define New Collating Sequences
** METHOD: sqlite3
**
** ^These functions add, remove, or modify a [collation] associated
** with the [database connection] specified as the first argument.
**
** ^The name of the collation is a UTF-8 string
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
** and a UTF-16 string in native byte order for sqlite3_create_collation16().
** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
** considered to be the same name.
**
** ^(The third argument (eTextRep) must be one of the constants:
** <ul>
** <li> [SQLITE_UTF8],
** <li> [SQLITE_UTF16LE],
** <li> [SQLITE_UTF16BE],
** <li> [SQLITE_UTF16], or
** <li> [SQLITE_UTF16_ALIGNED].
** </ul>)^
** ^The eTextRep argument determines the encoding of strings passed
** to the collating function callback, xCallback.
** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
** force strings to be UTF16 with native byte order.
** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
** on an even byte address.
**
** ^The fourth argument, pArg, is an application data pointer that is passed
** through as the first argument to the collating function callback.
**
** ^The fifth argument, xCallback, is a pointer to the collating function.
** ^Multiple collating functions can be registered using the same name but
** with different eTextRep parameters and SQLite will use whichever
** function requires the least amount of data transformation.
** ^If the xCallback argument is NULL then the collating function is
** deleted. ^When all collating functions having the same name are deleted,
** that collation is no longer usable.
**
** ^The collating function callback is invoked with a copy of the pArg
** application data pointer and with two strings in the encoding specified
** by the eTextRep argument. The collating function must return an
** integer that is negative, zero, or positive
** if the first string is less than, equal to, or greater than the second,
** respectively. A collating function must always return the same answer
** given the same inputs. If two or more collating functions are registered
** to the same collation name (using different eTextRep values) then all
** must give an equivalent answer when invoked with equivalent strings.
** The collating function must obey the following properties for all
** strings A, B, and C:
**
** <ol>
** <li> If A==B then B==A.
** <li> If A==B and B==C then A==C.
** <li> If A<B THEN B>A.
** <li> If A<B and B<C then A<C.
** </ol>
**
** If a collating function fails any of the above constraints and that
** collating function is registered and used, then the behavior of SQLite
** is undefined.
**
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
** with the addition that the xDestroy callback is invoked on pArg when
** the collating function is deleted.
** ^Collating functions are deleted when they are overridden by later
** calls to the collation creation functions or when the
** [database connection] is closed using [sqlite3_close()].
**
** ^The xDestroy callback is <u>not</u> called if the
** sqlite3_create_collation_v2() function fails. Applications that invoke
** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
** check the return code and dispose of the application data pointer
** themselves rather than expecting SQLite to deal with it for them.
** This is different from every other SQLite interface. The inconsistency
** is unfortunate but cannot be changed without breaking backwards
** compatibility.
**
** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
label: code-design
** CAPI3REF: Determine The Virtual Table Conflict Policy
**
** This function may only be called from within a call to the [xUpdate] method
** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
** of the SQL statement that triggered the call to the [xUpdate] method of the
** [virtual table].
Integrity checking context
Generic pointer
Table name
Current write offset in the journal file
Create the serialized output changeset based on the contents of the
** hash tables attached to the SessionTable objects in list p->pList.
comment:
** NOTE: Windows CE is handled differently here due its lack of the Win32
** API UnlockFile.
label: test
True if doclist is loaded incrementally
comment: *****************************************************************************
************************ Begin Named Semaphore Locking ************************
**
** Named semaphore locking is only supported on VxWorks.
**
** Semaphore locking is like dot-lock and flock in that it really only
** supports EXCLUSIVE locking. Only a single process can read or write
** the database file at a time. This reduces potential concurrency, but
** makes the lock implementation much easier.
label: code-design
An FTS3_EVAL_XX constant
The use of a character not in [a-zA-Z] means that we fallback
** to the copy stemmer
** Unlink the chunk at index i from
** whatever list is currently a member of.
Preserve the application id
** If X is a character that can be used in an identifier then
** IdChar(X) will be true. Otherwise it is false.
**
** For ASCII, any character with the high-order bit set is
** allowed in an identifier. For 7-bit characters,
** sqlite3IsIdChar[X] must be 1.
**
** For EBCDIC, the rules are more complex but have the same
** end result.
**
** Ticket #1066. the SQL standard does not allow '$' in the
** middle of identifiers. But many SQL implementations do.
** SQLite will allow '$' in identifiers for compatibility.
** But the feature is undocumented.
** Returns non-zero if the specified path name starts with a drive letter
** followed by a colon character.
Cx
Win32 last error
Do not spill the cache when non-zero
** Enable or disable the shared pager and schema features.
**
** This routine has no effect on existing database connections.
** The shared cache setting effects only future calls to
** sqlite3_open(), sqlite3_open16(), or sqlite3_open_v2().
Opcode: IfNullRow P1 P2 P3 * *
** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
**
** Check the cursor P1 to see if it is currently pointing at a NULL row.
** If it is, then set register P3 to NULL and jump immediately to P2.
** If P1 is not on a NULL row, then fall through without making any
** changes.
pTerm can be evaluated using just the index. So reduce
** the expected number of table lookups accordingly
48
Statement changes (Vdbe.nChange)
Index of constrained coordinate
xCreate
Origin of objects in apRankArg[]
90..97 ........
** The default value for the second argument to matchinfo().
239
PAGER_GET_NOCONTENT or PAGER_GET_READONLY
** This routine implements the xFindFunction method for the FTS3
** virtual table.
Opcode: RowSetAdd P1 P2 * * *
** Synopsis: rowset(P1)=r[P2]
**
** Insert the integer value held by register P2 into a RowSet object
** held in register P1.
**
** An assertion fails if P2 is not an integer.
The P2 operand
Initialize vdbe cursor object
These verifications occurs for the main database only
See if any siblings hold this same lock
comment:
** Like realloc(). Resize an allocation previously obtained from
** sqlite3MemMalloc().
**
** For this low-level interface, we know that pPrior!=0. Cases where
** pPrior==0 while have been intercepted by higher-level routine and
** redirected to xMalloc. Similarly, we know that nByte>0 because
** cases where nByte<=0 will have been intercepted by higher-level
** routines and redirected to xFree.
label: code-design
Session object already attached to db
If *pp1 is exactly nTokens before *pp2
Above do not own any resources. Must free those below
** Set the P4 on the most recently added opcode to the KeyInfo for the
** index given.
************* End of random.c *********************************************
** Close a connection to shared-memory. Delete the underlying
** storage if deleteFlag is true.
**
** If there is no shared memory associated with the connection then this
** routine is a harmless no-op.
Called by SQLite to clean up pUser
OP_Open** used to open bulk cursor
** The proxy locking style is intended for use with AFP filesystems.
** And since AFP is only supported on MacOSX, the proxy locking is also
** restricted to MacOSX.
**
**
******************* End of the proxy lock implementation **********************
*****************************************************************************
OUT: Number of frames in WAL
** This is a public wrapper for the winUtf8ToMbcs() function.
Error information
** If SQLite is compiled to support shared-cache mode and to be threadsafe,
** this routine obtains the mutex associated with each BtShared structure
** that may be accessed by the VM passed as an argument. In doing so it also
** sets the BtShared.db member of each of the BtShared structures, ensuring
** that the correct busy-handler callback is invoked if required.
**
** If SQLite is not threadsafe but does support shared-cache mode, then
** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
** of all of BtShared structures accessible via the database handle
** associated with the VM.
**
** If SQLite is not threadsafe and does not support shared-cache mode, this
** function is a no-op.
**
** The p->btreeMask field is a bitmask of all btrees that the prepared
** statement p will ever use. Let N be the number of bits in p->btreeMask
** corresponding to btrees that use shared cache. Then the runtime of
** this routine is N*N. But as N is rarely more than 1, this should not
** be a problem.
SQLITE_FORMAT
If the table being dropped is the table with the largest root-page
** number in the database, put the root page on the free list.
Total size in bytes of journal file pJrnl
Index of first cell to the left of right sibling
Opcode: ResultRow P1 P2 * * *
** Synopsis: output=r[P1@P2]
**
** The registers P1 through P1+P2-1 contain a single row of
** results. This opcode causes the sqlite3_step() call to terminate
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
** structure to provide access to the r(P1)..r(P1+P2-1) values as
** the result row.
KEY => ID
For a two-way OR, attempt to implementation case 2.
Special case: If db->aVTrans is NULL and db->nVTrans is greater
** than zero, then this function is being called from within a
** virtual module xSync() callback. It is illegal to write to
** virtual module tables in this case, so return SQLITE_LOCKED.
Stat4Accum.anLt
Input function
** The Win32 native heap cannot be modified because it may be in use.
comment: If the second argument to this function is NULL, generate a
** temporary file name to use
label: code-design
SQLITE_AMALGAMATION && SQLITE_BYTEORDER==0
Virtual table object to return
Dotfile locking uses the file path so it needs to be included in
** the dotlockLockingContext
Callback implementation user data
Hashing function for the aHash representation.
** Empirical testing showed that the *37 multiplier
** (an arbitrary prime)in the hash function provided
** no fewer collisions than the no-op *1.
Array of cells
OUT: List length pointer
** Must be first **
A table that describes the SELECT results
ABORT => ID
This branch happens only when content is on overflow pages
** The journal file must be open when this function is called.
**
** This function is a no-op if the journal file has not been written to
** within the current transaction (i.e. if Pager.journalOff==0).
**
** If doTruncate is non-zero or the Pager.journalSizeLimit variable is
** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
** zero the 28-byte header at the start of the journal file. In either case,
** if the pager is not in no-sync mode, sync the journal file immediately
** after writing or truncating it.
**
** If Pager.journalSizeLimit is set to a positive, non-zero value, and
** following the truncation or zeroing described above the size of the
** journal file in bytes is larger than this value, then truncate the
** journal file to Pager.journalSizeLimit bytes. The journal file does
** not need to be synced following this operation.
**
** If an IO error occurs, abandon processing and return the IO error code.
** Otherwise, return SQLITE_OK.
** Allocate nByte bytes of space using sqlite3Malloc(). If the
** allocation fails, call sqlite3_result_error_nomem() to notify
** the database handle that malloc() has failed and return NULL.
** If nByte is larger than the maximum string or blob length, then
** raise an SQLITE_TOOBIG exception and return NULL.
The return value is stored here
The Next opcode is only used after SeekGT, SeekGE, and Rewind.
** The Prev opcode is only used after SeekLT, SeekLE, and Last.
oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt
eidlist
** Checkpoint database zDb.
Offset in aData[] of current change
in1, jump
** Generate code to extract the value of the iCol-th column of a table.
Local size of all cells in apCell[]
Iterate through the phrases in the expression to count them. The same
** callback makes sure the doclists are loaded for each phrase.
Rowid for this leaf
Back out changes but do no rollback transaction
Most senior NEAR ancestor (or pExpr)
** Test the existence of or access permissions of file zPath. The
** test performed depends on the value of flags:
**
** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
**
** Otherwise return 0.
Expr to test. May or may not be root.
free the UTF8 buffer
Skip the OP_IdxLt or OP_IdxGT that follows
** 2015 May 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Routines for varint serialization and deserialization.
Deadlock detected.
** Specify the activation key for a CEROD database. Unless
** activated, none of the CEROD routines will work.
Do not copy the destructor
See above
IN/OUT: Stucture of index
*** whereLoopXfer() copies fields above **********************
Free the current contents of p->apValue[], if any.
Prepared statement under construction
b0..b7 ........
Format string
pageFindSlot() has already verified that free blocks are sorted
** in order of offset within the page, and that no block extends
** past the end of the page. Provided the two free slots do not
** overlap, this guarantees that the memmove() calls below will not
** overwrite the usableSize byte buffer, even if the database page
** is corrupt.
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
** utf-8 string describing the most recent error encountered associated
** with dynamic libraries.
Want to do one-pass UPDATE/DELETE
Flags that describe this loop
Cursor used to iterate through aRight
comment: The inability to allocates space for a larger hash table is
** a performance hit but it is not a fatal error. So mark the
** allocation as a benign. Use sqlite3Malloc()/memset(0) instead of
** sqlite3MallocZero() to make the allocation, as sqlite3MallocZero()
** only zeroes the requested number of bytes whereas this module will
** use the actual amount of space allocated for the hash table (which
** may be larger than the requested amount).
label: code-design
Write error messages here
** This routine is called prior to sqlite3PagerCommit when a transaction
** is committed for an auto-vacuum database.
**
** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages
** the database file should be truncated to during the commit process.
** i.e. the database has been reorganized so that only the first *pnTrunc
** pages are in use.
** Delete a "unicode61" tokenizer.
Add the default collation sequence BINARY. BINARY works for both UTF-8
** and UTF-16, so add a version for each to avoid any unnecessary
** conversions. The only error that can occur here is a malloc() failure.
**
** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
** functions:
** Extract the user data from a sqlite3_context structure and return a
** pointer to it.
Name of the constraint currently being parsed
Session object that owns SessionTable
0x30 .. 0x3F
Keyword code
The input value in P3 might be of any type: integer, real, string,
** blob, or NULL. But it needs to be an integer before we can do
** the seek, so convert it.
** CAPI3REF: Read Data From A BLOB Incrementally
** METHOD: sqlite3_blob
**
** ^(This function is used to read data from an open [BLOB handle] into a
** caller-supplied buffer. N bytes of data are copied into buffer Z
** from the open BLOB, starting at offset iOffset.)^
**
** ^If offset iOffset is less than N bytes from the end of the BLOB,
** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
** less than zero, [SQLITE_ERROR] is returned and no data is read.
** ^The size of the blob (and hence the maximum value of N+iOffset)
** can be determined using the [sqlite3_blob_bytes()] interface.
**
** ^An attempt to read from an expired [BLOB handle] fails with an
** error code of [SQLITE_ABORT].
**
** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
** Otherwise, an [error code] or an [extended error code] is returned.)^
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
**
** See also: [sqlite3_blob_write()].
Start of original out buffer
Length of token z
ifndef SQLITE_DISABLE_FTS3_UNICODE
** This routine is the same as the sqlite3_complete() routine described
** above, except that the parameter is required to be UTF-16 encoded, not
** UTF-8.
Pointer to position list following iDocid
Docid of row being written
Name of database containing r-tree table
Step 2: Check to see if the LHS contains any NULL columns. If the
** LHS does contain NULLs then the result must be either FALSE or NULL.
** We will then skip the binary search of the RHS.
Write index of pSrc->a[*piTab].pTab->aCol[] here
** Return TRUE if pFile has been renamed or unlinked since it was first opened.
** Vowel or consonant
Key for WITHOUT ROWID tables
** Delete any previous value and set the value stored in *pMem to val,
** manifest type REAL.
idlist_opt ::=
If the pager is configured to use locking_mode=exclusive, and an
** exclusive lock on the database is not already held, obtain it now.
Length of zTerm in bytes
Parsing context to record errors
comment: Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
** The value in regFree1 might get SCopy-ed into the file result.
** So make sure that the regFree1 register is not reused for other
** purposes and possibly overwritten.
label: code-design
The SELECT statement to be fixed to one database
If required, populate the output variables with a pointer to and the
** size of the previous offset-list.
** Tokenize using the porter tokenizer.
** This lookup table is used to help decode the first byte of
** a multi-byte UTF8 character. It is copied here from SQLite source
** code file utf8.c.
Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
** flag is set. See the sqlite3_enable_load_extension() API.
Minimum number of segments to merge
** 2010 February 1
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface to the write-ahead logging
** system. Refer to the comments below and the header comment attached to
** the implementation of each function in log.c for further details.
A syntax error has occurred.
** The response to an error depends upon whether or not the
** grammar defines an error token "ERROR".
**
** This is what we do if the grammar does define ERROR:
**
** * Call the %syntax_error function.
**
** * Begin popping the stack until we enter a state where
** it is legal to shift the error symbol, then shift
** the error symbol.
**
** * Set the error count to three.
**
** * Begin accepting and shifting new tokens. No new error
** processing will occur until three tokens have been
** shifted successfully.
**
Vector of values to consider
Create a divider cell to insert into pParent. The divider cell
** consists of a 4-byte page number (the page number of pPage) and
** a variable length key value (which must be the same value as the
** largest key on pPage).
**
** To find the largest key value on pPage, first find the right-most
** cell on pPage. The first two fields of this cell are the
** record-length (a variable length integer at most 32-bits in size)
** and the key value (a variable length integer, may have any value).
** The first of the while(...) loops below skips over the record-length
** field. The second while(...) loop copies the key value from the
** cell on pPage into the pSpace buffer.
Value returned by xInstCount()
Which metric to return
************* Begin file parse.c ******************************************
** NOTE: The WinRT sub-platform is always assumed to be based on the NT
** kernel.
LEFT
Size of allocated buffer
** Bind a text or BLOB value.
Do not save the results anywhere
Restriction (2b)
** Generate an expression tree to implement the WHERE, ORDER BY,
** and LIMIT/OFFSET portion of DELETE and UPDATE statements.
**
** DELETE FROM table_wxyz WHERE a<5 ORDER BY a LIMIT 1;
** \__________________________/
** pLimitWhere (pInClause)
end-of-error-codes
** 2007 August 27
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement mutexes on Btree objects.
** This code really belongs in btree.c. But btree.c is getting too
** big and we want to break it down some. This packaged seemed like
** a good breakout.
If the first byte was a '[', then the close-quote character is a ']'
** This function may only be called if the b-tree connection already
** has a read or write transaction open on the database.
**
** Read the meta-information out of a database file. Meta[0]
** is the number of free pages currently in the database. Meta[1]
** through meta[15] are available for use by higher layers. Meta[0]
** is read-only, the others are read/write.
**
** The schema layer numbers meta values differently. At the schema
** layer (and the SetCookie and ReadCookie opcodes) the number of
** free pages is not visible. So Cookie[0] is the same as Meta[1].
**
** This routine treats Meta[BTREE_DATA_VERSION] as a special case. Instead
** of reading the value out of the header, it instead loads the "DataVersion"
** from the pager. The BTREE_DATA_VERSION value is not actually stored in the
** database file. It is a number computed by the pager. But its access
** pattern is the same as header meta values, and so it is convenient to
** read it from this routine.
This particular expression does not need to be expanded.
This case should work for GCC
trigger_cmd_list
Number of elements left to test
** CAPI3REF: Source Of Data In A Query Result
** METHOD: sqlite3_stmt
**
** ^These routines provide a means to determine the database, table, and
** table column that is the origin of a particular result column in
** [SELECT] statement.
** ^The name of the database or table or column can be returned as
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
** the database name, the _table_ routines return the table name, and
** the origin_ routines return the column name.
** ^The returned string is valid until the [prepared statement] is destroyed
** using [sqlite3_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite3_step()] for a particular run
** or until the same information is requested
** again in a different encoding.
**
** ^The names returned are the original un-aliased names of the
** database, table, and column.
**
** ^The first argument to these interfaces is a [prepared statement].
** ^These functions return information about the Nth result column returned by
** the statement, where N is the second function argument.
** ^The left-most column is column 0 for these routines.
**
** ^If the Nth column returned by the statement is an expression or
** subquery and is not a column value, then all of these functions return
** NULL. ^These routine might also return NULL if a memory allocation error
** occurs. ^Otherwise, they return the name of the attached database, table,
** or column that query result column was extracted from.
**
** ^As with all other SQLite APIs, those whose names end with "16" return
** UTF-16 encoded strings and the other functions return UTF-8.
**
** ^These APIs are only available if the library was compiled with the
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
**
** If two or more threads call one or more of these routines against the same
** prepared statement and column at the same time then the results are
** undefined.
**
** If two or more threads call one or more
** [sqlite3_column_database_name | column metadata interfaces]
** for the same [prepared statement] and result column
** at the same time then the results are undefined.
Read-only HEADER_VALUE
init_deferred_pred_opt ::=
Automatically expire on reset
If the operating system support deletion of open files, then
** close the journal file when dropping the database lock. Otherwise
** another connection with journal_mode=delete might delete the file
** out from under us.
Code the SELECT statements to our left
Flags for Fts5IndexQuery
** Each database file to be accessed by the system is an instance
** of the following structure. There are normally two of these structures
** in the sqlite.aDb[] array. aDb[0] is the main database file and
** aDb[1] is the database file used to hold temporary tables. Additional
** databases may be attached.
** Return the size of the header on each page of this PCACHE implementation.
AFTER
EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
** mode:
Smallest power of two >= nReader
Extra bytes append to each in-memory page
Insert the new record into the r-tree
IN: Size of poslist in bytes
** When building up a FROM clause in the parser, the join operator
** is initially attached to the left operand. But the code generator
** expects the join operator to be on the right operand. This routine
** Shifts all join operators from left to right for an entire FROM
** clause.
**
** Example: Suppose the join is like this:
**
** A natural cross join B
**
** The operator is "natural cross join". The A and B operands are stored
** in p->a[0] and p->a[1], respectively. The parser initially stores the
** operator with A. This routine shifts that operator over to B.
If the bPreserve flag is set to true, then the cursor position must
** be preserved following this delete operation. If the current delete
** will cause a b-tree rebalance, then this is done by saving the cursor
** key and leaving the cursor in CURSOR_REQUIRESEEK state before
** returning.
**
** Or, if the current delete will not cause a rebalance, then the cursor
** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
** before or after the deleted entry. In this case set bSkipnext to true.
xColumn - read data
P4 is a pointer to a Mem* structure
** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
**
** This action provides a run-time test to see whether or not
** assert() was enabled at compile-time. If X is true and assert()
** is enabled, then the return value is true. If X is true and
** assert() is disabled, then the return value is zero. If X is
** false and assert() is enabled, then the assertion fires and the
** process aborts. If X is false and assert() is disabled, then the
** return value is zero.
Length of th name
Original name of the table
growing the file does not occur until
** the write succeeds
comment: Some terms not completely tested
label: test
OUT: Total number of pages available for recycling
Number of valid entries in aTo[] and aFrom[]
** Compute both YMD and HMS
Database idx for pTab
OUT: Returned database handle
** Add a lock on the table with root-page iTable to the shared-btree used
** by Btree handle p. Parameter eLock must be either READ_LOCK or
** WRITE_LOCK.
**
** This function assumes the following:
**
** (a) The specified Btree object p is connected to a sharable
** database (one with the BtShared.sharable flag set), and
**
** (b) No other Btree objects hold a lock that conflicts
** with the requested lock (i.e. querySharedCacheTableLock() has
** already been called and returned SQLITE_OK).
**
** SQLITE_OK is returned if the lock is added successfully. SQLITE_NOMEM
** is returned if a malloc attempt fails.
Set a flag that indicates we're the first to create the memory so it
** must be zero-initialized
** Initialize a SelectDest structure.
Transfer the next row in Queue over to Current
It is not possible for eType to be SQLITE_NULL here. The session
** module does not record changes for rows with NULL values stored in
** primary key columns.
** Clear the i-th bit.
**
** pBuf must be a pointer to at least BITVEC_SZ bytes of temporary storage
** that BitvecClear can use to rebuilt its hash table.
Number of bits in the bitmap array.
Start transaction here if not NULL
The code below is handling the return value of osFallocate()
** correctly. posix_fallocate() is defined to "returns zero on success,
** or an error number on failure". See the manpage for details.
Array with one element per query phrase
Save the current value of the database flags so that it can be
** restored before returning. Then set the writable-schema flag, and
** disable CHECK and foreign key constraints.
FTS5 mask for idxFlags
OUT: Frame number (or zero)
SQLITE_OMIT_QUICKBALANCE
Page is on the PCache.pDirty list
The pPg->nFree field is now set incorrectly. The caller will fix it.
** The following structure holds pointers to all of the SQLite API
** routines.
**
** WARNING: In order to maintain backwards compatibility, add new
** interfaces to the end of this structure only. If you insert new
** interfaces in the middle of this structure, then older different
** versions of SQLite will not be able to load each other's shared
** libraries!
#define TRANSLATE_TRACE 1
Cursor variable
comment:
** Return a pointer corresponding to database zDb (i.e. "main", "temp")
** in connection handle pDb. If such a database cannot be found, return
** a NULL pointer and write an error message to pErrorDb.
**
** If the "temp" database is requested, it may need to be opened by this
** function. If an error occurs while doing so, return 0 and write an
** error message to pErrorDb.
label: code-design
comment: How far to indent SELECTTRACE() output
label: code-design
Db handle used to check for interrupts
** Sync the database file for the pager pPager. zMaster points to the name
** of a master journal file that should be written into the individual
** journal file. zMaster may be NULL, which is interpreted as no master
** journal (a single database transaction).
**
** This routine ensures that:
**
** * The database file change-counter is updated,
** * the journal is synced (unless the atomic-write optimization is used),
** * all dirty pages are written to the database file,
** * the database file is truncated (if required), and
** * the database file synced.
**
** The only thing that remains to commit the transaction is to finalize
** (delete, truncate or zero the first part of) the journal file (or
** delete the master journal file if specified).
**
** Note that if zMaster==NULL, this does not overwrite a previous value
** passed to an sqlite3PagerCommitPhaseOne() call.
**
** If the final parameter - noSync - is true, then the database file itself
** is not synced. The caller must call sqlite3PagerSync() directly to
** sync the database file before calling CommitPhaseTwo() to delete the
** journal file in this case.
Opcode: Ge P1 P2 P3 P4 P5
** Synopsis: IF r[P3]>=r[P1]
**
** This works just like the Lt opcode except that the jump is taken if
** the content of register P3 is greater than or equal to the content of
** register P1. See the Lt opcode for additional information.
expr ::= expr ISNULL|NOTNULL
** Sizes and pointers of various parts of the Parse object.
IMP: R-22934-25134
************* End of fts3.h ***********************************************
** Move the page pPg to location pgno in the file.
**
** There must be no references to the page previously located at
** pgno (which we call pPgOld) though that page is allowed to be
** in cache. If the page previously located at pgno is not already
** in the rollback journal, it is not put there by by this routine.
**
** References to the page pPg remain valid. Updating any
** meta-data associated with pPg (i.e. data stored in the nExtra bytes
** allocated along with the page) is the responsibility of the caller.
**
** A transaction must be active when this routine is called. It used to be
** required that a statement transaction was not active, but this restriction
** has been removed (CREATE INDEX needs to move a page when a statement
** transaction is active).
**
** If the fourth argument, isCommit, is non-zero, then this page is being
** moved as part of a database reorganization just before the transaction
** is being committed. In this case, it is guaranteed that the database page
** pPg refers to will not be written to again within this transaction.
**
** This function may return SQLITE_NOMEM or an IO error code if an error
** occurs. Otherwise, it returns SQLITE_OK.
If the file was successfully opened for read/write access,
** choose a default page size in case we have to create the
** database file. The default page size is the maximum of:
**
** + SQLITE_DEFAULT_PAGE_SIZE,
** + The value returned by sqlite3OsSectorSize()
** + The largest page size that can be written atomically.
iLevel value for root of the tree
comment:
** CAPI3REF: Unlock Notification
** METHOD: sqlite3
**
** ^When running in shared-cache mode, a database operation may fail with
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
** individual tables within the shared-cache cannot be obtained. See
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
** ^This API may be used to register a callback that SQLite will invoke
** when the connection currently holding the required lock relinquishes it.
** ^This API is only available if the library was compiled with the
** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
**
** See Also: [Using the SQLite Unlock Notification Feature].
**
** ^Shared-cache locks are released when a database connection concludes
** its current transaction, either by committing it or rolling it back.
**
** ^When a connection (known as the blocked connection) fails to obtain a
** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
** identity of the database connection (the blocking connection) that
** has locked the required resource is stored internally. ^After an
** application receives an SQLITE_LOCKED error, it may call the
** sqlite3_unlock_notify() method with the blocked connection handle as
** the first argument to register for a callback that will be invoked
** when the blocking connections current transaction is concluded. ^The
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
** call that concludes the blocking connections transaction.
**
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
** there is a chance that the blocking connection will have already
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
** If this happens, then the specified callback is invoked immediately,
** from within the call to sqlite3_unlock_notify().)^
**
** ^If the blocked connection is attempting to obtain a write-lock on a
** shared-cache table, and more than one other connection currently holds
** a read-lock on the same table, then SQLite arbitrarily selects one of
** the other connections to use as the blocking connection.
**
** ^(There may be at most one unlock-notify callback registered by a
** blocked connection. If sqlite3_unlock_notify() is called when the
** blocked connection already has a registered unlock-notify callback,
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
** called with a NULL pointer as its second argument, then any existing
** unlock-notify callback is canceled. ^The blocked connections
** unlock-notify callback may also be canceled by closing the blocked
** connection using [sqlite3_close()].
**
** The unlock-notify callback is not reentrant. If an application invokes
** any sqlite3_xxx API functions from within an unlock-notify callback, a
** crash or deadlock may be the result.
**
** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
** returns SQLITE_OK.
**
** <b>Callback Invocation Details</b>
**
** When an unlock-notify callback is registered, the application provides a
** single void* pointer that is passed to the callback when it is invoked.
** However, the signature of the callback function allows SQLite to pass
** it an array of void* context pointers. The first argument passed to
** an unlock-notify callback is a pointer to an array of void* pointers,
** and the second is the number of entries in the array.
**
** When a blocking connections transaction is concluded, there may be
** more than one blocked connection that has registered for an unlock-notify
** callback. ^If two or more such blocked connections have specified the
** same callback function, then instead of invoking the callback function
** multiple times, it is invoked once with the set of void* context pointers
** specified by the blocked connections bundled together into an array.
** This gives the application an opportunity to prioritize any actions
** related to the set of unblocked database connections.
**
** <b>Deadlock Detection</b>
**
** Assuming that after registering for an unlock-notify callback a
** database waits for the callback to be issued before taking any further
** action (a reasonable assumption), then using this API may cause the
** application to deadlock. For example, if connection X is waiting for
** connection Y's transaction to be concluded, and similarly connection
** Y is waiting on connection X's transaction, then neither connection
** will proceed and the system may remain deadlocked indefinitely.
**
** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
** detection. ^If a given call to sqlite3_unlock_notify() would put the
** system in a deadlocked state, then SQLITE_LOCKED is returned and no
** unlock-notify callback is registered. The system is said to be in
** a deadlocked state if connection A has registered for an unlock-notify
** callback on the conclusion of connection B's transaction, and connection
** B has itself registered for an unlock-notify callback when connection
** A's transaction is concluded. ^Indirect deadlock is also detected, so
** the system is also considered to be deadlocked if connection B has
** registered for an unlock-notify callback on the conclusion of connection
** C's transaction, where connection C is waiting on connection A. ^Any
** number of levels of indirection are allowed.
**
** <b>The "DROP TABLE" Exception</b>
**
** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
** always appropriate to call sqlite3_unlock_notify(). There is however,
** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
** SQLite checks if there are any currently executing SELECT statements
** that belong to the same connection. If there are, SQLITE_LOCKED is
** returned. In this case there is no "blocking connection", so invoking
** sqlite3_unlock_notify() results in the unlock-notify callback being
** invoked immediately. If the application then re-attempts the "DROP TABLE"
** or "DROP INDEX" query, an infinite loop might be the result.
**
** One way around this problem is to check the extended error code returned
** by an sqlite3_step() call. ^(If there is a blocking connection, then the
** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
** the special "DROP TABLE/INDEX" case, the extended error code is just
** SQLITE_LOCKED.)^
label: code-design
Language id to use
same as TK_NOT, in1, out2
OUT: New value (or NULL pointer)
Advance to the next name context. The loop will exit when either
** we have a match (cnt>0) or when we run out of name contexts.
** Reclaim all memory of a Stat4Accum structure.
Index in aSample[] of test sample
************* Begin file callback.c ***************************************
** Return the number of bytes of payload for the entry that pCur is
** currently pointing to. For table btrees, this will be the amount
** of data. For index btrees, this will be the size of the key.
**
** The caller must guarantee that the cursor is pointing to a non-NULL
** valid entry. In other words, the calling procedure must guarantee
** that the cursor has Cursor.eState==CURSOR_VALID.
EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0).
** Implement a memory barrier or memory fence on shared memory.
**
** All loads and stores begun before the barrier must complete before
** any load or store begun after the barrier.
** Return true if the argument corresponds to a unicode codepoint
** classified as either a letter or a number. Otherwise false.
**
** The results are undefined if the value passed to this function
** is less than zero.
** A sub-routine used to implement a trigger program.
comment: SQLITE_DEBUG || SQLITE_COVERAGE_TEST
label: test
** Attempt an incremental merge that writes nMerge leaf blocks.
**
** Incremental merges happen nMin segments at a time. The segments
** to be merged are the nMin oldest segments (the ones with the smallest
** values for the _segdir.idx field) in the highest level that contains
** at least nMin segments. Multiple merges might occur in an attempt to
** write the quota of nMerge leaf blocks.
** The journal header size for this pager. This is usually the same
** size as a single disk sector. See also setSectorSize().
Make sure the schema version is at least 3. But do not upgrade
** from less than 3 to 4, as that will corrupt any preexisting DESC
** index.
If foreign-keys are disabled, this function is a no-op.
The requested data is available in the in-memory buffer. In this
** case there is no need to make a copy of the data, just return a
** pointer into the buffer to the caller.
Write the number of available bytes here
Sort order of primary key when pList==NULL
** Move the cursor to point to the root page of its b-tree structure.
**
** If the table has a virtual root page, then the cursor is moved to point
** to the virtual root page instead of the actual root page. A table has a
** virtual root page when the actual root page contains no cells and a
** single child page. This can only happen with the table rooted at page 1.
**
** If the b-tree structure is empty, the cursor state is set to
** CURSOR_INVALID. Otherwise, the cursor is set to point to the first
** cell located on the root (or virtual root) page and the cursor state
** is set to CURSOR_VALID.
**
** If this function returns successfully, it may be assumed that the
** page-header flags indicate that the [virtual] root-page is the expected
** kind of b-tree page (i.e. if when opening the cursor the caller did not
** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
** indicating a table b-tree, or if the caller did specify a KeyInfo
** structure the flags byte is set to 0x02 or 0x0A, indicating an index
** b-tree).
If this function is inside of a trigger, the register array in aMem[]
** might change from one evaluation to the next. The next block of code
** checks to see if the register array has changed, and if so it
** reinitializes the relavant parts of the sqlite3_context object
Increment the row counter
** fts3ExprIterate() callback used to collect the "local" part of the
** FTS3_MATCHINFO_HITS array. The local stats are those elements of the
** array that are different for each row returned by the query.
Valid if eType==FTSQUERY_PHRASE
Write values to this array
Context for the sanity check
** Flush any data stored in the in-memory hash tables to the database.
** Also close any open blob handles.
comment:
** Give a callback to the test harness that can be used to simulate faults
** in places where it is difficult or expensive to do so purely by means
** of inputs.
**
** The intent of the integer argument is to let the fault simulator know
** which of multiple sqlite3FaultSim() calls has been hit.
**
** Return whatever integer value the test callback returns, or return
** SQLITE_OK if no test callback is installed.
label: code-design
Open page to move
Next unread header byte
Integer value used when MEM_Int is set in flags
Establish a read-lock on the table at the shared-cache level.
** Open a read-only cursor on the table. Also allocate a cursor number
** to use for scanning indexes (iIdxCur). No index cursor is opened at
** this time though.
Release the locks
** This function determines whether or not the atomic-write optimization
** can be used with this pager. The optimization can be used if:
**
** (a) the value returned by OsDeviceCharacteristics() indicates that
** a database page may be written atomically, and
** (b) the value returned by OsSectorSize() is less than or equal
** to the page size.
**
** The optimization is also always enabled for temporary files. It is
** an error to call this function if pPager is opened on an in-memory
** database.
**
** If the optimization cannot be used, 0 is returned. If it can be used,
** then the value returned is the size of the journal file when it
** contains rollback data for exactly one page.
stl_prefix ::=
** Invoke this macro on memory cells just prior to changing the
** value of the cell. This macro verifies that shallow copies are
** not misused. A shallow copy of a string or blob just copies a
** pointer to the string or blob, not the content. If the original
** is changed while the copy is still in use, the string or blob might
** be changed out from under the copy. This macro verifies that nothing
** like that ever happens.
Position-list terminator
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that implements the sqlite3_complete() API.
** This code used to be part of the tokenizer.c source file. But by
** separating it out, the code will be automatically omitted from
** static links that do not use it.
Max cache entries for pcacheDump()
** Compare the values contained by the two memory cells, returning
** negative, zero or positive if pMem1 is less than, equal to, or greater
** than pMem2. Sorting order is NULL's first, followed by numbers (integers
** and reals) sorted numerically, followed by text ordered by the collating
** sequence pColl and finally blob's ordered by memcmp().
**
** Two NULL values are considered equal by this function.
defined(SQLITE_MUTEX_NOOP)
Number of segments in incr-merge
Name of new SQL function
** If a row with rowid iDel is present in the %_content table, add the
** delete-markers to the FTS index necessary to delete it. Do not actually
** remove the %_content row at this time though.
type of the next token
NULL set by OP_Null, not from data
Pull data from this table
A running thread
Expression for VALUE in the x=VALUE constraint
endif pExpr->iTable==pItem->iCursor
** CAPI3REF: Virtual Table Scan Flags
Sizes in bytes of nPrefix prefix indexes
Number of leaf pages per optimize step
16
An SQL table corresponding to zName
If the query was read-only and the error code is SQLITE_INTERRUPT,
** no rollback is necessary. Otherwise, at least a savepoint
** transaction must be rolled back to restore the database to a
** consistent state.
**
** Even if the statement is read-only, it is important to perform
** a statement or transaction rollback operation. If the error
** occurred while writing to the journal, sub-journal or database
** file as part of an effort to free up cache space (see function
** pagerStress() in pager.c), the rollback is required to restore
** the pager to a consistent state.
************* Begin file mem1.c *******************************************
Cursor number for current WhereLoop
expr ::= EXISTS LP select RP
No other row with the new.* primary key.
This call may return SQLITE_ABORT if there has been a savepoint
** rollback since it was last used. In this case a new blob handle
** is required.
** Load all automatic extensions.
**
** If anything goes wrong, set an error in the database connection.
** Wrapper around OS specific sqlite3_os_init() function.
Show short columns names
True if this frame is valid
btreeParseCell method
FOR => ID
Current UNION ALL term of the other query
** Free all resources currently held by the cursor passed as the only
** argument.
Argument passed into xTask()
** xOpen - Open a cursor.
************* Begin file pcache.c *****************************************
** Another built-in collating sequence: NOCASE.
**
** This collating sequence is intended to be used for "case independent
** comparison". SQLite's knowledge of upper and lower case equivalents
** extends only to the 26 characters used in the English language.
**
** At the moment there is only a UTF-8 implementation.
** A linked list of the following structures is stored at BtShared.pLock.
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
** is opened on the table with root page BtShared.iTable. Locks are removed
** from this list when a transaction is committed or rolled back, or when
** a btree handle is closed.
SQLITE_LOCKED
New value for pMem->flags
** This function returns a pointer to the array of opcodes associated with
** the Vdbe passed as the first argument. It is the callers responsibility
** to arrange for the returned array to be eventually freed using the
** vdbeFreeOpArray() function.
**
** Before returning, *pnOp is set to the number of entries in the returned
** array. Also, *pnMaxArg is set to the larger of its current value and
** the number of entries in the Vdbe.apArg[] array required to execute the
** returned program.
** Most queries use only a single table (they are not joins) and have
** simple == constraints against indexed fields. This routine attempts
** to plan those simple cases using much less ceremony than the
** general-purpose query planner, and thereby yield faster sqlite3_prepare()
** times for the common case.
**
** Return non-zero on success, if this query can be handled by this
** no-frills query planner. Return zero if this query needs the
** general-purpose query planner.
IN/OUT: Lastest rowid seen so far
If 8+3 names are possible, then the journal file might not contain
** a '-' character. So check for that case and return early.
Opcode: SorterSort P1 P2 * * *
**
** After all records have been inserted into the Sorter object
** identified by P1, invoke this opcode to actually do the sorting.
** Jump to P2 if there are no records to be sorted.
**
** This opcode is an alias for OP_Sort and OP_Rewind that is used
** for Sorter objects.
Value to return via *ppIdx
Change a page number. Used by incr-vacuum.
comment: PAGER_GET_XXX flags
label: code-design
64-bit position read from poslist
boundaries on sqlite3GlobalConfig.mnReq are enforced in sqlite3_config()
TRUNCATE
None of the existing best-so-far paths match the candidate.
** A specially optimized version of vdbeSorterCompare() that assumes that
** the first field of each key is an INTEGER value.
************* Begin file fts3_porter.c ************************************
Loop through all indices on the table, checking each to see if it makes
** the DISTINCT qualifier redundant. It does so if:
**
** 1. The index is itself UNIQUE, and
**
** 2. All of the columns in the index are either part of the pDistinct
** list, or else the WHERE clause contains a term of the form "col=X",
** where X is a constant value. The collation sequences of the
** comparison and select-list expressions must match those of the index.
**
** 3. All of those index columns for which the WHERE clause does not
** contain a "col=X" term are subject to a NOT NULL constraint.
!SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY
Callback info
If the createFlag parameter is true and the search did not reveal an
** exact match for the name, number of arguments and encoding, then add a
** new entry to the hash table and return it.
Argument to xTask
Copy of BtShared.minLocal or BtShared.minLeaf
An error has occurred. Return an error code.
1=rel to end of fork, 0=rel to start
** Trace output macros
** Return the rowid of the entry that the iterator currently points
** to. If the iterator points to EOF when this function is called the
** results are undefined.
Temp db schema
** This procedure generates VDBE code for a single invocation of either the
** sqlite_detach() or sqlite_attach() SQL user functions.
** Global data used by this cache.
init_deferred_pred_opt ::= INITIALLY DEFERRED
trigger_event ::= DELETE|INSERT
comment: The WhereLoop object being coded
label: code-design
E
P3
Used to allocate unique cursor ids
** The list of all registered VFS implementations.
** PRAGMA [schema.]default_cache_size
** PRAGMA [schema.]default_cache_size=N
**
** The first form reports the current persistent setting for the
** page cache size. The value returned is the maximum number of
** pages in the page cache. The second form sets both the current
** page cache size value and the persistent page cache size value
** stored in the database file.
**
** Older versions of SQLite would set the default cache size to a
** negative number to indicate synchronous=OFF. These days, synchronous
** is always on by default regardless of the sign of the default cache
** size. But continue to take the absolute value of the default cache
** size of historical compatibility.
Opcode: RowSetRead P1 P2 P3 * *
** Synopsis: r[P3]=rowset(P1)
**
** Extract the smallest value from the RowSet object in P1
** and put that value into register P3.
** Or, if RowSet object P1 is initially empty, leave P3
** unchanged and jump to instruction P2.
** This function is called by the parser when it parses a command to create,
** release or rollback an SQL savepoint.
This is an EOF condition
Current number of users of this structure
Length of a token prefix
Virtual table cursor handle
Maximum length of output string in bytes
******* End of sqlite3rtree.h ********
** CAPI3REF: Initialize The SQLite Library
**
** ^The sqlite3_initialize() routine initializes the
** SQLite library. ^The sqlite3_shutdown() routine
** deallocates any resources that were allocated by sqlite3_initialize().
** These routines are designed to aid in process initialization and
** shutdown on embedded systems. Workstation applications using
** SQLite normally do not need to invoke either of these routines.
**
** A call to sqlite3_initialize() is an "effective" call if it is
** the first time sqlite3_initialize() is invoked during the lifetime of
** the process, or if it is the first time sqlite3_initialize() is invoked
** following a call to sqlite3_shutdown(). ^(Only an effective call
** of sqlite3_initialize() does any initialization. All other calls
** are harmless no-ops.)^
**
** A call to sqlite3_shutdown() is an "effective" call if it is the first
** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
** an effective call to sqlite3_shutdown() does any deinitialization.
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
**
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
** is not. The sqlite3_shutdown() interface must only be called from a
** single thread. All open [database connections] must be closed and all
** other SQLite resources must be deallocated prior to invoking
** sqlite3_shutdown().
**
** Among other things, ^sqlite3_initialize() will invoke
** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
** will invoke sqlite3_os_end().
**
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
** ^If for some reason, sqlite3_initialize() is unable to initialize
** the library (perhaps it is unable to allocate a needed resource such
** as a mutex) it returns an [error code] other than [SQLITE_OK].
**
** ^The sqlite3_initialize() routine is called internally by many other
** SQLite interfaces so that an application usually does not need to
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
** calls sqlite3_initialize() so the SQLite library will be automatically
** initialized when [sqlite3_open()] is called if it has not be initialized
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
** compile-time option, then the automatic calls to sqlite3_initialize()
** are omitted and the application must call sqlite3_initialize() directly
** prior to using any other SQLite interface. For maximum portability,
** it is recommended that applications always invoke sqlite3_initialize()
** directly prior to using any other SQLite interface. Future releases
** of SQLite may require this. In other words, the behavior exhibited
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
** default behavior in some future release of SQLite.
**
** The sqlite3_os_init() routine does operating-system specific
** initialization of the SQLite library. The sqlite3_os_end()
** routine undoes the effect of sqlite3_os_init(). Typical tasks
** performed by these routines include allocation or deallocation
** of static resources, initialization of global variables,
** setting up a default [sqlite3_vfs] module, or setting up
** a default configuration using [sqlite3_config()].
**
** The application should never invoke either sqlite3_os_init()
** or sqlite3_os_end() directly. The application should only invoke
** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
** interface is called automatically by sqlite3_initialize() and
** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
** implementations for sqlite3_os_init() and sqlite3_os_end()
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
** When [custom builds | built for other platforms]
** (using the [SQLITE_OS_OTHER=1] compile-time
** option) the application must supply a suitable implementation for
** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
** implementation of sqlite3_os_init() or sqlite3_os_end()
** must return [SQLITE_OK] on success and some other [error code] upon
** failure.
Number of nested calls to sqlite3BtreeEnter()
Default value
Else this is a rollback operation, playback the specified savepoint.
** If this is a temp-file, it is possible that the journal file has
** not yet been opened. In this case there have been no changes to
** the database file, so the playback operation can be skipped.
If we are creating a set for an "expr IN (SELECT ...)".
Cost of running iterator
Where to write the extracted value
Second argument to pass to callback
The walker node callback used to transform matching expressions into
** a reference to an index column for an index on an expression.
**
** If pExpr matches, then transform it into a reference to the index column
** that contains the value of pExpr.
the complete WHERE clause
UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERECURSIVE
** Obtain the BtShared mutex associated with B-Tree handle p. Also,
** set BtShared.db to the database handle associated with p and the
** p->locked boolean to true.
0x12
Sort the list
Resolve names in table-valued-function arguments
173
** When the core wants to read from the virtual table, it creates a
** virtual table cursor (an instance of the following structure) using
** the xOpen method. Cursors are destroyed using the xClose method.
comment: Extra initialization needed
label: code-design
Used by readers to open (lock) and close (unlock) a snapshot. A
** snapshot is like a read-transaction. It is the state of the database
** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
** preserves the current state even if the other threads or processes
** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
** transaction and releases the lock.
Affinity for end of range constraint
** This function is only called for detail=columns tables.
** Push a new element onto the priority queue
Offset to read at
An empty option name. Ignore this option altogether.
The old rowid
int int
comment: #define sqliteHashKey(E) ((E)->pKey) // NOT USED
label: code-design
Append the new position offset, if necessary
Call fstat() to figure out the permissions on the database file. If
** a new *-shm file is created, an attempt will be made to create it
** with the same permissions.
out of memory
The index to be tested
Table Name Module Name
comment:
** Each instance of this object represents an algorithm for evaluating one
** term of a join. Every term of the FROM clause will have at least
** one corresponding WhereLoop object (unless INDEXED BY constraints
** prevent a query solution - which is an error) and many terms of the
** FROM clause will have multiple WhereLoop objects, each describing a
** potential way of implementing that FROM-clause term, together with
** dependencies and cost estimates for using the chosen algorithm.
**
** Query planning consists of building up a collection of these WhereLoop
** objects, then computing a particular sequence of WhereLoop objects, with
** one WhereLoop object per FROM clause term, that satisfy all dependencies
** and that minimize the overall cost.
label: code-design
** Given cursor id iId, return a pointer to the corresponding Fts5Index
** object. Or NULL If the cursor id does not exist.
**
** If successful, set *ppConfig to point to the associated config object
** before returning.
** If the reference count has reached zero, rollback any active
** transaction and unlock the pager.
**
** Except, in locking_mode=EXCLUSIVE when there is nothing to in
** the rollback journal, the unlock is not performed and there is
** nothing to rollback, so this routine is a no-op.
pBuf->p[pBuf->n++] = '\0';
comment:
** Macros to determine whether the machine is big or little endian,
** and whether or not that determination is run-time or compile-time.
**
** For best performance, an attempt is made to guess at the byte-order
** using C-preprocessor macros. If that is unsuccessful, or if
** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
** at run-time.
label: code-design
Move the cursor to the last entry in the table. Return SQLITE_OK
** on success. Set *pRes to 0 if the cursor actually points to something
** or set *pRes to 1 if the table is empty.
Correlated subq
Number of pointers to this Table
xShmMap
Left subtree
Number of times each op has been executed
A one-pass strategy that might update more than one row may not
** be used if any column of the index used for the scan is being
** updated. Otherwise, if there is an index on "b", statements like
** the following could create an infinite loop:
**
** UPDATE t1 SET b=b+1 WHERE b>?
**
** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
** strategy that uses an index for which one or more columns are being
** updated.
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
** Append the nul-terminated string zStr to the buffer pBuf. This function
** ensures that the byte following the buffer data is set to 0x00, even
** though this byte is not included in the pBuf->n count.
Result of prior seek or 0 if no USESEEKRESULT flag
orderby_opt ::=
** Attempt to take an exclusive lock on the database file. If a PENDING lock
** is obtained instead, immediately release it.
89
orderby_opt
*************************************************************************
** Interface to code in fts5_config.c. fts5_config.c contains contains code
** to parse the arguments passed to the CREATE VIRTUAL TABLE statement.
** Write the header information in pWal->hdr into the wal-index.
**
** The checksum on pWal->hdr is updated before it is written.
A positive nCol means the columns names for this view are
** already known.
SQLITE_TOOBIG
** If the pBase expression originated in the ON or USING clause of
** a join, then transfer the appropriate markings over to derived.
Index in aData of first cell pointer
** This following structure defines all the methods for the
** stmt virtual table.
Wait for writers, then checkpoint
Raw cell content
Byte offset at which to write
The prepared stmt under constructions
xEof
** Check that there are at least nSavepoint savepoints open. If there are
** currently less than nSavepoints open, then open one or more savepoints
** to make up the difference. If the number of savepoints is already
** equal to nSavepoint, then this function is a no-op.
**
** If a memory allocation fails, SQLITE_NOMEM is returned. If an error
** occurs while opening the sub-journal file, then an IO error code is
** returned. Otherwise, SQLITE_OK.
The aggregate function implementation
* An instance of struct TriggerStep is used to store a single SQL statement
* that is a part of a trigger-program.
*
* Instances of struct TriggerStep are stored in a singly linked list (linked
* using the "pNext" member) referenced by the "step_list" member of the
* associated struct Trigger instance. The first element of the linked list is
* the first step of the trigger-program.
*
* The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
* "SELECT" statement. The meanings of the other members is determined by the
* value of "op" as follows:
*
* (op == TK_INSERT)
* orconf -> stores the ON CONFLICT algorithm
* pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
* this stores a pointer to the SELECT statement. Otherwise NULL.
* zTarget -> Dequoted name of the table to insert into.
* pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
* this stores values to be inserted. Otherwise NULL.
* pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
* statement, then this stores the column-names to be
* inserted into.
*
* (op == TK_DELETE)
* zTarget -> Dequoted name of the table to delete from.
* pWhere -> The WHERE clause of the DELETE statement if one is specified.
* Otherwise NULL.
*
* (op == TK_UPDATE)
* zTarget -> Dequoted name of the table to update.
* pWhere -> The WHERE clause of the UPDATE statement if one is specified.
* Otherwise NULL.
* pExprList -> A list of the columns to update and the expressions to update
* them to. See sqlite3Update() documentation of "pChanges"
* argument.
*
Result of xTask
Enlarge the pWal->apWiData[] array if required
Pointer to top element of the stack
The table or view to which the trigger applies
The hash for this key.
APIs to grab new and old data with
Shortened table list or OR-clause generation
OUT: Page number
** Invoke the 'collation needed' callback to request a collation sequence
** in the encoding enc of name zName, length nName.
prepared statement under construction
ATTACH => ID
File handle open on target db
Name of the proxy lock file
comment: Conditionally this LIKE operator term
label: code-design
Partial Index Expression
191
** Walk an expression tree. Return non-zero if the expression is constant
** that does no originate from the ON or USING clauses of a join.
** Return 0 if it involves variables or function calls or terms from
** an ON or USING clause.
Pointer to allocated vtab
Number of non-benign errors
** CAPI3REF: Query Progress Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
** function X to be invoked periodically during long running calls to
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
** database connection D. An example use for this
** interface is to keep a GUI updated during a large query.
**
** ^The parameter P is passed through as the only parameter to the
** callback function X. ^The parameter N is the approximate number of
** [virtual machine instructions] that are evaluated between successive
** invocations of the callback X. ^If N is less than one then the progress
** handler is disabled.
**
** ^Only a single progress handler may be defined at one time per
** [database connection]; setting a new progress handler cancels the
** old one. ^Setting parameter X to NULL disables the progress handler.
** ^The progress handler is also disabled by setting N to a value less
** than 1.
**
** ^If the progress callback returns non-zero, the operation is
** interrupted. This feature can be used to implement a
** "Cancel" button on a GUI progress dialog box.
**
** The progress handler callback must not do anything that will modify
** the database connection that invoked the progress handler.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
Main VM
** Decode the flags byte (the first byte of the header) for a page
** and initialize fields of the MemPage structure accordingly.
**
** Only the following combinations are supported. Anything different
** indicates a corrupt database files:
**
** PTF_ZERODATA
** PTF_ZERODATA | PTF_LEAF
** PTF_LEAFDATA | PTF_INTKEY
** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF
** Close a connection to a log file.
pPager->nPage = 0;
Limit register for select-A
** GCC with -pedantic-errors says that C90 does not allow a void* to be
** cast into a pointer to a function. And yet the library dlsym() routine
** returns a void* which is really a pointer to a function. So how do we
** use dlsym() with -pedantic-errors?
**
** Variable x below is defined to be a pointer to a function taking
** parameters void* and const char* and returning a pointer to a function.
** We initialize x by assigning it a pointer to the dlsym() function.
** (That assignment requires a cast.) Then we call the function that
** x points to.
**
** This work-around is unlikely to work correctly on any system where
** you really cannot cast a function pointer into void*. But then, on the
** other hand, dlsym() will not work on such a system either, so we have
** not really lost anything.
comment:
** CAPI3REF: Memory Allocator Statistics
**
** SQLite provides these two interfaces for reporting on the status
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
** routines, which form the built-in memory allocation subsystem.
**
** ^The [sqlite3_memory_used()] routine returns the number of bytes
** of memory currently outstanding (malloced but not freed).
** ^The [sqlite3_memory_highwater()] routine returns the maximum
** value of [sqlite3_memory_used()] since the high-water mark
** was last reset. ^The values returned by [sqlite3_memory_used()] and
** [sqlite3_memory_highwater()] include any overhead
** added by SQLite in its implementation of [sqlite3_malloc()],
** but not overhead added by the any underlying system library
** routines that [sqlite3_malloc()] may call.
**
** ^The memory high-water mark is reset to the current value of
** [sqlite3_memory_used()] if and only if the parameter to
** [sqlite3_memory_highwater()] is true. ^The value returned
** by [sqlite3_memory_highwater(1)] is the high-water mark
** prior to the reset.
label: code-design
copy digits from after decimal to significand
** (decrease exponent by d to shift decimal right)
JSON formatted without any backslash-escapes
Mask of terms not to omit
One of the journals pointed to by the master journal exists.
** Open it and check if it points at the master journal. If
** so, return without deleting the master journal file.
Functions used to truncate the database file.
** Delete a linked list of TriggerStep structures.
Level offering the most input segments
Column names for INSERT
** Remember the current column cache context. Any new entries added
** added to the column cache after this call are removed when the
** corresponding pop occurs.
OUT: Number of bytes consumed
** Set all the parameters in the compiled SQL statement to NULL.
Expression to resolve. May be NULL.
ERROR: unknown delta operator
idlist ::= nm
The P1 index cursor
values
Exponentional notation. %e and %E
** Return true if it is necessary to write page *pPg into the sub-journal.
** A page needs to be written into the sub-journal if there exists one
** or more open savepoints for which:
**
** * The page-number is less than or equal to PagerSavepoint.nOrig, and
** * The bit corresponding to the page-number is not set in
** PagerSavepoint.pInSavepoint.
** Load the contents of the "averages" record from disk into the
** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
** argument bCache is true, set the p->bTotalsValid flag to indicate
** that the contents of aTotalSize[] and nTotalRow are valid until
** further notice.
**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
The parsing (and code generating) context
** Given the name of a compile-time option, return true if that option
** was used and false if not.
**
** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
** is not required for a match.
bUseCis
** PRAGMA [schema.]synchronous
** PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA
**
** Return or set the local value of the synchronous flag. Changing
** the local value does not make changes to the disk file and the
** default value will be restored the next time the database is
** opened.
** Arguments pLeft and pRight point to linked-lists of hash-entry objects,
** each sorted in key order. This function merges the two lists into a
** single list and returns a pointer to its first element.
Position of token in zText
If the bReplace flag is set, the change is an INSERT that has not
** been performed because the database already contains a row with the
** specified primary key and the conflict handler returned
** SQLITE_CHANGESET_REPLACE. In this case remove the conflicting row
** before reattempting the INSERT.
** The first argument points to a nul-terminated string containing a
** list of space separated integers. Read the first nOut of these into
** the array aOut[].
List of free nodes. Linked by pParent.
Flags originally passed to sqlite3WhereBegin()
Create new statistic tables if they do not exist, or clear them
** if they do already exist.
************* End of mutex_unix.c *****************************************
** Specify the activation key for a SEE database. Unless
** activated, none of the SEE routines will work.
An instance of the BtreePayload object describes the content of a single
** entry in either an index or table btree.
**
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
** an arbitrary key and no data. These btrees have pKey,nKey set to their
** key and pData,nData,nZero set to zero.
**
** Table btrees (used for rowid tables) contain an integer rowid used as
** the key and passed in the nKey field. The pKey field is zero.
** pData,nData hold the content of the new entry. nZero extra zero bytes
** are appended to the end of the content when constructing the entry.
**
** This object is used to pass information into sqlite3BtreeInsert(). The
** same information used to be passed as five separate parameters. But placing
** the information into this object helps to keep the interface more
** organized and understandable, and it also helps the resulting code to
** run a little faster by using fewer registers for parameter passing.
Output vars
************* End of dbstat.c *********************************************
True if "!" flag is present
OUT: Wal frame index of next page
Value of 'pageno' column
** Insert a new row into the FTS content table.
The thread handle
** If it has not already been allocated, allocate the UnpackedRecord
** structure at pTask->pUnpacked. Return SQLITE_OK if successful (or
** if no allocation was required), or SQLITE_NOMEM otherwise.
** Tokenizer callback used by implementation of highlight() function.
a: p2<<28 | p4<<14 | p6 (unmasked)
Register holding Current table
Initial number of pages on free-list
**********************************************************************
** The set of routines that implement the simple tokenizer
Index of next field to compare
comment:
** Defragment the page given. This routine reorganizes cells within the
** page so that there are no free-blocks on the free-block list.
**
** Parameter nMaxFrag is the maximum amount of fragmented space that may be
** present in the page after this routine returns.
**
** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
** b-tree page so that there are no freeblocks or fragment bytes, all
** unused bytes are contained in the unallocated space region, and all
** cells are packed tightly at the end of the page.
label: code-design
How to deal with SELECT result
** The expression object indicated by the second argument is guaranteed
** to be a scalar SQL function. If
**
** * all function arguments are SQL literals,
** * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
**
** then this routine attempts to invoke the SQL function. Assuming no
** error occurs, output parameter (*ppVal) is set to point to a value
** object containing the result before returning SQLITE_OK.
**
** Affinity aff is applied to the result of the function before returning.
** If the result is a text value, the sqlite3_value object uses encoding
** enc.
**
** If the conditions above are not met, this function returns SQLITE_OK
** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
** NULL and an SQLite error code returned.
Bitmask of phrases already covered
stl_prefix ::= seltablist joinop
comment:
** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument
** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
label: code-design
End of input
True if holding a checkpoint lock
Insert the new sample
Skip VIEWs or VIRTUAL TABLEs
The parsed WHERE clause
Special command to parse
** Advance the SegReader to point to the next docid in the doclist
** associated with the current term.
**
** If arguments ppOffsetList and pnOffsetList are not NULL, then
** *ppOffsetList is set to point to the first column-offset list
** in the doclist entry (i.e. immediately past the docid varint).
** *pnOffsetList is set to the length of the set of column-offset
** lists, not including the nul-terminator byte. For example:
Namespace to resolve expressions in.
Array of cell sizes
Xfer function arguments to here
186
LOOKUP
IMP: R-48725-32206
** Register an unlock-notify callback.
**
** This is called after connection "db" has attempted some operation
** but has received an SQLITE_LOCKED error because another connection
** (call it pOther) in the same process was busy using the same shared
** cache. pOther is found by looking at db->pBlockingConnection.
**
** If there is no blocking connection, the callback is invoked immediately,
** before this routine returns.
**
** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
** a deadlock.
**
** Otherwise, make arrangements to invoke xNotify when pOther drops
** its locks.
**
** Each call to this routine overrides any prior callbacks registered
** on the same "db". If xNotify==0 then any prior callbacks are immediately
** cancelled.
BTALLOC_EXACT, BTALLOC_LT, or BTALLOC_ANY
Number of errors encountered
Write the output into this preallocated buffer
** This C function implements an SQL user function that is used by SQL code
** generated by the ALTER TABLE ... RENAME command to modify the definition
** of any foreign key constraints that use the table being renamed as the
** parent table. It is passed three arguments:
**
** 1) The complete text of the CREATE TABLE statement being modified,
** 2) The old name of the table being renamed, and
** 3) The new name of the table being renamed.
**
** It returns the new CREATE TABLE statement. For example:
**
** sqlite_rename_parent('CREATE TABLE t1(a REFERENCES t2)', 't2', 't3')
** -> 'CREATE TABLE t1(a REFERENCES t3)'
Number of elements in aSample[]
SQLITE_STATUS_SCRATCH_SIZE
Case 2.
IN Loop terminator. OP_Next or OP_Prev
When the schema cookie changes, record the new cookie internally
** Parameter zName points to a UTF-8 encoded string nName bytes long.
** Return the CollSeq* pointer for the collation sequence named zName
** for the encoding 'enc' from the database 'db'.
**
** If the entry specified is not found and 'create' is true, then create a
** new entry. Otherwise return NULL.
**
** A separate function sqlite3LocateCollSeq() is a wrapper around
** this routine. sqlite3LocateCollSeq() invokes the collation factory
** if necessary and generates an error message if the collating sequence
** cannot be found.
**
** See also: sqlite3LocateCollSeq(), sqlite3GetCollSeq()
Right subtree (larger entries) or list
212
No. of ORDER BY terms
Number of tables in pSrc->a[] to search
Primary key flags array
comment: No memory allocation is ever used on mem1. Prove this using
** the following assert(). If the assert() fails, it indicates a
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
label: code-design
Write to the unixFile structure here
x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF
File to write into
** The maximum number of times that a statement will try to reparse
** itself before giving up and returning SQLITE_SCHEMA.
** Open the file indicated and write a log of all unfreed memory
** allocations into that log.
Figure out how much reusable memory is available at the end of the
** opcode array. This extra memory will be reallocated for other elements
** of the prepared statement.
1-byte (or larger) unsigned integer
Token counter
730
0x11
A character outside of the ascii range. Skip past it if it is
** a separator character. Or break out of the loop if it is not.
Stub function when INCRBLOB is omitted
comment:
** 2015-06-06
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.
**
** This file was split off from where.c on 2015-06-06 in order to reduce the
** size of where.c and make it easier to edit. This file contains the routines
** that actually generate the bulk of the WHERE loop code. The original where.c
** file retains the code that does query planning and analysis.
label: code-design
End the loop over all WhereLoops from outer-most down to inner-most
Write the master journal name into the journal file. If a master
** journal file name has already been written to the journal file,
** or if zMaster is NULL (no master journal), then this call is a no-op.
isPCacheInit
** Class derived from sqlite3_tokenizer
Return the value to pass to a sqlite3_wal_hook callback, the
** number of frames in the WAL at the point of the last commit since
** sqlite3WalCallback() was called. If no commits have occurred since
** the last call, then return 0.
** An instance of the following structure contains all information
** needed to generate code for a single SELECT statement.
**
** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0.
** If there is a LIMIT clause, the parser sets nLimit to the value of the
** limit and nOffset to the value of the offset (or 0 if there is not
** offset). But later on, nLimit and nOffset become the memory locations
** in the VDBE that record the limit and offset counters.
**
** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
** These addresses must be stored so that we can go back and fill in
** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor
** the number of columns in P2 can be computed at the same time
** as the OP_OpenEphm instruction is coded because not
** enough information about the compound query is known at that point.
** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
** sequences for the ORDER BY clause.
comment: TODO: This definition is just included so other modules compile. It
** needs to be revisited.
label: code-design
** Iterate forwards through a doclist.
The table pTrigger is attached to
New colset object to return
For each column used in source tables
Edit this page
** datetime( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD HH:MM:SS
** This method is called to "rewind" the stmt_cursor object back
** to the first row of output. This method is always called at least
** once prior to any call to stmtColumn() or stmtRowid() or
** stmtEof().
defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
** Set or release locks on the WAL. Locks are either shared or exclusive.
** A lock cannot be moved directly between shared and exclusive - it must go
** through the unlocked state first.
**
** In locking_mode=EXCLUSIVE, all of these routines become no-ops.
114
Version 3.20.0 and later
Figure out how many new bytes are in this term
** Drop all shadow tables. Return SQLITE_OK if successful or an SQLite error
** code otherwise.
If no error occurred, set the output variables.
Dequoted copy of token p
Changeset iterator
Store 1 if the result is not empty
The writer
Foreign key to find index for
RESTRICT
Sort order for each column.
TRANS_NONE, TRANS_READ or TRANS_WRITE
Text to add to EQP output
If a mutex is required for normal operation, allocate one
** The original API set ends here. All extensions can call any
** of the APIs above provided that the pointer is not NULL. But
** before calling APIs that follow, extension should check the
** sqlite3_libversion_number() to make sure they are dealing with
** a library that is new enough to support that API.
*************************************************************************
Token number of previous deferred token
comment: Go back under the static mutex and clean up the recursive
** mutex to prevent a resource leak.
label: code-design
Query for next idx at level iLevel
Noop
The code within this loop is run only once if the 'searchList' variable
** is not true. Otherwise, it runs once for each trunk-page on the
** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT)
** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
(320) database_kw_opt ::=
Columns of index used so far
Name of the conch file
Don't bother checking for NOT NULL on columns that do not change
** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
** which case memory allocation statistics are disabled by default.
** Determine if we are dealing with Windows CE - which has a much reduced
** API.
True if zTerm/nTerm is transient
** Streaming version of sqlite3changeset_concat().
BEFORE
** Extract a 2-byte big-endian integer from an array of unsigned bytes.
** But if the value is zero, make it 65536.
**
** This routine is used to extract the "offset to cell content area" value
** from the header of a btree page. If the page size is 65536 and the page
** is empty, the offset should be 65536, but the 2-byte value stores zero.
** This routine makes the necessary adjustment to 65536.
Input vars
term column
** Free all PgHdr objects stored in the Pager.pMmapFreelist list.
True to seek past initial nulls
Next winShm with the same winShmNode
************* End of mutex_noop.c *****************************************
The original LIKE operator
ORDER BY clause
** Figure out the number of pages needed to hold all b.nCell cells.
** Store this number in "k". Also compute szNew[] which is the total
** size of all cells on the i-th page and cntNew[] which is the index
** in b.apCell[] of the cell that divides page i from page i+1.
** cntNew[k] should equal b.nCell.
**
** Values computed by this block:
**
** k: The total number of sibling pages
** szNew[i]: Spaced used on the i-th sibling page.
** cntNew[i]: Index in b.apCell[] and b.szCell[] for the first cell to
** the right of the i-th sibling page.
** usableSpace: Number of bytes of space available on each sibling.
**
Opcode: IdxGT P1 P2 P3 P4 P5
** Synopsis: key=r[P3@P4]
**
** The P4 register values beginning with P3 form an unpacked index
** key that omits the PRIMARY KEY. Compare this key value against the index
** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
** fields at the end.
**
** If the P1 index entry is greater than the key value
** then jump to P2. Otherwise fall through to the next instruction.
If the CREATE VIRTUAL TABLE statement is being entered for the
** first time (in other words if the virtual table is actually being
** created now instead of just being read out of sqlite_master) then
** do additional initialization work and store the statement text
** in the sqlite_master table.
Locate the statement handle used to insert data into the %_content
** table. The SQL for this statement is:
**
** INSERT INTO %_content VALUES(?, ?, ?, ...)
**
** The statement features N '?' variables, where N is the number of user
** defined columns in the FTS3 table, plus one for the docid field.
Full-text index
The main db file
Bypass the creation of the PRIMARY KEY btree and the sqlite_master
** table entry. This is only required if currently generating VDBE
** code for a CREATE TABLE (not when parsing one as part of reading
** a database schema).
First argument to xCodec... methods
Delete after closing if true
True once an index has been found
** Set up the lookaside buffers for a database connection.
** Return SQLITE_OK on success.
** If lookaside is already active, return SQLITE_BUSY.
**
** The sz parameter is the number of bytes in each lookaside slot.
** The cnt parameter is the number of slots. If pStart is NULL the
** space for the lookaside memory is obtained from sqlite3_malloc().
** If pStart is not NULL then it is sz*cnt bytes of memory to use for
** the lookaside memory.
** If the expression passed as the second argument is a vector, generate
** code to write the first nReg elements of the vector into an array
** of registers starting with iReg.
**
** If the expression is not a vector, then nReg must be passed 1. In
** this case, generate code to evaluate the expression and leave the
** result in register iReg.
If the rhs of the LIKE expression is a variable, and the current
** value of the variable means there is no need to invoke the LIKE
** function, then no OP_Variable will be added to the program.
** This causes problems for the sqlite3_bind_parameter_name()
** API. To work around them, add a dummy OP_Variable here.
** The text of the conversion is pointed to by "bufpt" and is
** "length" characters long. The field width is "width". Do
** the output.
True if this is a commit
** CAPI3REF: Set Or Clear the Indirect Change Flag
**
** Each change recorded by a session object is marked as either direct or
** indirect. A change is marked as indirect if either:
**
** <ul>
** <li> The session object "indirect" flag is set when the change is
** made, or
** <li> The change is made by an SQL trigger or foreign key action
** instead of directly as a result of a users SQL statement.
** </ul>
**
** If a single row is affected by more than one operation within a session,
** then the change is considered indirect if all operations meet the criteria
** for an indirect change above, or direct otherwise.
**
** This function is used to set, clear or query the session object indirect
** flag. If the second argument passed to this function is zero, then the
** indirect flag is cleared. If it is greater than zero, the indirect flag
** is set. Passing a value less than zero does not modify the current value
** of the indirect flag, and may be used to query the current state of the
** indirect flag for the specified session object.
**
** The return value indicates the final state of the indirect flag: 0 if
** it is clear, or 1 if it is set.
** Delete a WhereLoop object
comment:
** Macro to return the number of elements in an array. SQLite has a
** similar macro called ArraySize(). Use a different name to avoid
** a collision when building an amalgamation with built-in FTS3.
label: code-design
True if this is a read-only file
comment:
** FTS4 is really an extension for FTS3. It is enabled using the
** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
label: code-design
Column token must occur in
"columnsize=" option value (dflt==1)
Page size for host database
If all of the OR-connected terms are optimized using the same
** index, and the index is opened using the same cursor number
** by each call to sqlite3WhereBegin() made by this loop, it may
** be possible to use that index as a covering index.
**
** If the call to sqlite3WhereBegin() above resulted in a scan that
** uses an index, and this is either the first OR-connected term
** processed or the index is the same as that used by all previous
** terms, set pCov to the candidate covering index. Otherwise, set
** pCov to NULL to indicate that no candidate covering index will
** be available.
1-byte unsigned integer
comment:
** Deserialize the data blob pointed to by buf as serial type serial_type
** and store the result in pMem. Return the number of bytes read.
**
** This function is implemented as two separate routines for performance.
** The few cases that require local variables are broken out into a separate
** routine so that in most cases the overhead of moving the stack pointer
** is avoided.
label: code-design
Bounding box for pNode
Bytes of payload stored locally
Index in p->aIndex[] to merge
** Return an approximation for the amount of memory currently used
** by all pagers associated with the given database connection. The
** highwater mark is meaningless and is returned as zero.
Behavioral bits. UNIXFILE_* flags
Get shared locks at the system level, if necessary
** Shorthand for starting a new tree item that consists of a single label
The key
Index of database housing pTab
Analyze the schema named as the argument
104
Root page of the open btree cursor
32
(325) vtabarg ::= vtabarg vtabargtoken
First argument to disposal method
** Configure the VM passed as the first argument with an
** sqlite3_stmt_scanstatus() entry corresponding to the scan used to
** implement level pLvl. Argument pSrclist is a pointer to the FROM
** clause that the scan reads data from.
**
** If argument addrExplain is not 0, it must be the address of an
** OP_Explain instruction that describes the same loop.
Language id to merge
comment: If no error has occurred and pPage has an overflow cell, call balance()
** to redistribute the cells within the tree. Since balance() may move
** the cursor, zero the BtCursor.info.nSize and BTCF_ValidNKey
** variables.
**
** Previous versions of SQLite called moveToRoot() to move the cursor
** back to the root page as balance() used to invalidate the contents
** of BtCursor.apPage[] and BtCursor.aiIdx[]. Instead of doing that,
** set the cursor state to "invalid". This makes common insert operations
** slightly faster.
**
** There is a subtle but important optimization here too. When inserting
** multiple records into an intkey b-tree using a single cursor (as can
** happen while processing an "INSERT INTO ... SELECT" statement), it
** is advantageous to leave the cursor pointing to the last entry in
** the b-tree if possible. If the cursor is left pointing to the last
** entry in the table, and the next row inserted has an integer key
** larger than the largest existing key, it is possible to insert the
** row without seeking the cursor. This can be a big performance boost.
label: code-design
wrFlag = (wrFlag ? 1 : 0);
The extra pAppData, if any.
A sub-task in the sort process
This branch is taken when committing a transaction in rollback-journal
** mode if the database file on disk is larger than the database image.
** At this point the journal has been finalized and the transaction
** successfully committed, but the EXCLUSIVE lock is still held on the
** file. So it is safe to truncate the database file to its minimum
** required size.
** CAPI3REF: Test if a changeset has recorded any changes.
**
** Return non-zero if no changes to attached tables have been recorded by
** the session object passed as the first argument. Otherwise, if one or
** more changes have been recorded, return zero.
**
** Even if this function returns zero, it is possible that calling
** [sqlite3session_changeset()] on the session handle may still return a
** changeset that contains no changes. This can happen when a row in
** an attached table is modified and then later on the original values
** are restored. However, if this function returns non-zero, then it is
** guaranteed that a call to sqlite3session_changeset() will return a
** changeset containing zero changes.
** The name of the schema table.
Acquire an EXCLUSIVE lock
The "OUTER" keyword is present
Offset of first type in header
Bitvec to ensure pages played back only once
synopsis: key=r[P3@P4]
Used to iterate from 0 to nCol
Index of first cell currently on page
Iterator variable
** Begin a read transaction on the database.
**
** This routine used to be called sqlite3OpenSnapshot() and with good reason:
** it takes a snapshot of the state of the WAL and wal-index for the current
** instant in time. The current thread will continue to use this snapshot.
** Other threads might append new content to the WAL and wal-index but
** that extra content is ignored by the current thread.
**
** If the database contents have changes since the previous read
** transaction, then *pChanged is set to 1 before returning. The
** Pager layer will use this to know that is cache is stale and
** needs to be flushed.
Index loop counter
True if the only wildcard is % in the last character
Offset within buffer to read from
TODO2: Doclist terminator written here.
Filter out attempts to run UPDATE or DELETE on contentless tables.
** This is not suported.
True if doclists are in reverse order
P5_ErrMsg type
comment: pRHS cannot be NULL because a malloc error would have been detected
** before now and control would have never reached this point
label: code-design
** Change the size of an existing memory allocation.
**
** The outer layer memory allocator prevents this routine from
** being called with pPrior==0.
**
** nBytes is always a value obtained from a prior call to
** memsys5Round(). Hence nBytes is always a non-negative power
** of two. If nBytes==0 that means that an oversize allocation
** (an allocation larger than 0x40000000) was requested and this
** routine should return 0 without freeing pPrior.
Affinity string for comparisons
If the tree is a leaf-data tree, and the siblings are leaves,
** then there is no divider cell in b.apCell[]. Instead, the divider
** cell consists of the integer key for the right-most cell of
** the sibling-page assembled above only.
lock semaphore now but bail out when already locked.
** Write an error message into pParse->zErrMsg that explains that the
** user-supplied authorization function returned an illegal value.
** Delete all the content of a Select structure. Deallocate the structure
** itself only if bFree is true.
************* Begin file sqlite3session.c *********************************
OUT: Byte offset of end of token in input buffer
Pointer to position list for phrase
Skip over multiple "*" characters in the pattern. If there
** are also "?" characters, skip those as well, but consume a
** single character of the input string for each "?" skipped
Deleting *pRowid leaves the table empty
Bit N (1<<N) set if column N of pTab is used
0x60..0x6F
** Indices of various locking bytes. WAL_NREADER is the number
** of available reader locks and should be at least 3. The default
** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5.
Key associated with this element
Key columns for SRT_Queue and SRT_DistQueue
SQLITE_BUSY
EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
** is the number of leaf page pointers to follow.
A table being constructed by CREATE TABLE
4-byte aligned
First element
NULL=NULL
Ensure the default expression is something that sqlite3ValueFromExpr()
** can handle (i.e. not CURRENT_TIME etc.)
comment:
** Create the byte sequence used to represent a cell on page pPage
** and write that byte sequence into pCell[]. Overflow pages are
** allocated and filled in as necessary. The calling procedure
** is responsible for making sure sufficient space has been allocated
** for pCell[].
**
** Note that pCell does not necessary need to point to the pPage->aData
** area. pCell might point to some temporary storage. The cell will
** be constructed in this temporary area then copied into pPage->aData
** later.
label: code-design
Array of SegReader objects
A SessionChange object never has a NULL value in a PK column
Next element in list of dirty pages
Operation terminated by sqlite3_interrupt()
Top of the step-6 loop
** This function is an xTokenize() callback used by the auxiliary snippet()
** function. Its job is to identify tokens that are the first in a sentence.
** For each such token, an entry is added to the SFinder.aFirst[] array.
Count the number of terms in the query
** Implementation of the special optimize() function for FTS3. This
** function merges all segments in the database to a single segment.
** Example usage is:
**
** SELECT optimize(t) FROM t LIMIT 1;
**
** where 't' is the name of an FTS3 table.
This function is always called by the main user thread.
**
** If this function is being called after SorterRewind() has been called,
** it is possible that thread pSorter->aTask[pSorter->nTask-1].pThread
** is currently attempt to join one of the other threads. To avoid a race
** condition where this thread also attempts to join the same object, join
** thread pSorter->aTask[pSorter->nTask-1].pThread first.
CLEAN pages not on dirty list
A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
** specified number of hours, minutes, seconds, and fractional seconds
** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
** omitted.
Recalculate checksums within the wal file if required.
When setting the auto_vacuum mode to either "full" or
** "incremental", write the value of meta[6] in the database
** file. Before writing to meta[6], check that meta[3] indicates
** that this really is an auto-vacuum capable database.
** CAPI3REF: Prepare Flags
**
** These constants define various flags that can be passed into
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
** [sqlite3_prepare16_v3()] interfaces.
**
** New flags may be added in future releases of SQLite.
**
** <dl>
** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
** that the prepared statement will be retained for a long time and
** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
** and [sqlite3_prepare16_v3()] assume that the prepared statement will
** be used just once or at most a few times and then destroyed using
** [sqlite3_finalize()] relatively soon. The current implementation acts
** on this hint by avoiding the use of [lookaside memory] so as not to
** deplete the limited store of lookaside memory. Future versions of
** SQLite may act on this hint differently.
** </dl>
** End of interface to code in fts5_unicode2.c.
*************************************************************************
0 1 2 3 4 5 6 7 8 9 A B C D E F
** Release an array of N Mem elements
Number of cols in current table
** When called, *ppPoslist must point to the byte immediately following the
** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function
** moves *ppPoslist so that it instead points to the first byte of the
** same position list.
Number of index columns including rowid
Nul-terminated UTF-8 string <value>, or NULL
************* Begin file notify.c *****************************************
EXPLAIN => ID
** CAPI3REF: Authorizer Return Codes
**
** The [sqlite3_set_authorizer | authorizer callback function] must
** return either [SQLITE_OK] or one of these two constants in order
** to signal SQLite whether or not the action is permitted. See the
** [sqlite3_set_authorizer | authorizer documentation] for additional
** information.
**
** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
** returned from the [sqlite3_vtab_on_conflict()] interface.
True if this is likely an append
The pragma virtual table object
SQLITE_READONLY
Database number to create the table in
** End of interface to code in fts5_storage.c.
*************************************************************************
Position of token within column
SQLITE_OMIT_FLAG_PRAGMAS
** A structure for holding a single date and time.
** The cursor "p" has a pending seek operation that has not yet been
** carried out. Seek the cursor now. If an error occurs, return
** the appropriate error code.
Next field of pPKey2 to compare
DATABASE
ignore IS [NOT] NULL constraints on NOT NULL columns
Figure out how many columns of data are supplied. If the data
** is coming from a SELECT statement, then generate a co-routine that
** produces a single row of the SELECT on each invocation. The
** co-routine is the common header to the 3rd and 4th templates.
Fts3SegReader object to return
c8..cf ........
The allocateSpace() routine guarantees the following properties
** if it returns successfully
8-byte unsigned integer
************* Begin file fts3.c *******************************************
comment:
* If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
* various Win32 API heap functions instead of our own.
label: code-design
True if we acquired a PENDING lock this time
Building an imposter table
Next phrase instance index
Ignore DESC
First allowable cell or freeblock offset
For looping over all siblings
EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
** compatibility for legacy applications, the URI filename capability is
** disabled by default.
**
** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
**
** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
** disabled. The default value may be changed by compiling with the
** SQLITE_USE_URI symbol defined.
**
** URI filenames are enabled by default if SQLITE_HAS_CODEC is
** enabled.
comment: Lookaside malloc configuration
label: code-design
SQLITE_STATUS_MEMORY_USED
Exactly one of regOld and regNew should be non-zero.
** Register the query expression parser test function fts3_exprtest()
** with database connection db.
SELECT rowid, * FROM ... ORDER BY 1 DESC
An offset into mem5.aCtrl[]
comment:
** When this is called the journal file for pager pPager must be open.
** This function attempts to read a master journal file name from the
** end of the file and, if successful, copies it into memory supplied
** by the caller. See comments above writeMasterJournal() for the format
** used to store a master journal file name at the end of a journal file.
**
** zMaster must point to a buffer of at least nMaster bytes allocated by
** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
** enough space to write the master journal name). If the master journal
** name in the journal is longer than nMaster bytes (including a
** nul-terminator), then this is handled as if no master journal name
** were present in the journal.
**
** If a master journal file name is present at the end of the journal
** file, then it is copied into the buffer pointed to by zMaster. A
** nul-terminator byte is appended to the buffer following the master
** journal file name.
**
** If it is determined that no master journal file name is present
** zMaster[0] is set to 0 and SQLITE_OK returned.
**
** If an error occurs while reading from the journal file, an SQLite
** error code is returned.
label: code-design
** An instance of this structure is used to create a segment b-tree in the
** database. The internal details of this type are only accessed by the
** following functions:
**
** fts3SegWriterAdd()
** fts3SegWriterFlush()
** fts3SegWriterFree()
FROM
** Allocate a new simple tokenizer. Return a pointer to the new
** tokenizer in *ppModule
SQLITE_OMIT_BTREECOUNT
** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
Characters. %c
** Add all WhereLoop objects for a single table of the join where the table
** is identified by pBuilder->pNew->iTab. That table is guaranteed to be
** a b-tree table, not a virtual table.
**
** The costs (WhereLoop.rRun) of the b-tree loops added by this function
** are calculated as follows:
**
** For a full scan, assuming the table (or index) contains nRow rows:
**
** cost = nRow * 3.0 // full-table scan
** cost = nRow * K // scan of covering index
** cost = nRow * (K+3.0) // scan of non-covering index
**
** where K is a value between 1.1 and 3.0 set based on the relative
** estimated average size of the index and table records.
**
** For an index scan, where nVisit is the number of index rows visited
** by the scan, and nSeek is the number of seek operations required on
** the index b-tree:
**
** cost = nSeek * (log(nRow) + K * nVisit) // covering index
** cost = nSeek * (log(nRow) + (K+3.0) * nVisit) // non-covering index
**
** Normally, nSeek is 1. nSeek values greater than 1 come about if the
** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
**
** The estimated values (nRow, nVisit, nSeek) often contain a large amount
** of uncertainty. For this reason, scoring is designed to pick plans that
** "do the least harm" if the estimates are inaccurate. For example, a
** log(nRow) factor is omitted from a non-covering index scan in order to
** bias the scoring in favor of using an index, since the worst-case
** performance of using an index is far better than the worst-case performance
** of a full table scan.
comment:
** An instance of the following object records the location of
** each unused scratch buffer.
label: code-design
LHS is entirely deferred. So we assume it matches every row.
** Advance the RHS iterator to find the next row visited.
File to read from
** If the numeric type of argument pVal is "integer", then return it
** converted to a 64-bit signed integer. Otherwise, return a copy of
** the second parameter, iDefault.
Default ON CONFLICT policy
Conversion paradigm
Size of aSeg[] array
************* Continuing where we left off in fts3Int.h *******************
** Factor out the code of the given expression to initialization time.
**
** If regDest>=0 then the result is always stored in that register and the
** result is not reusable. If regDest<0 then this routine is free to
** store the value whereever it wants. The register where the expression
** is stored is returned. When regDest<0, two identical expressions will
** code to the same register.
Mask of exclusive locks held
True for recursive reference in WITH
Underlying file handle
A-overwrites-R
comment: This case runs if the aggregate has no GROUP BY clause. The
** processing is much simpler since there is only a single row
** of output.
label: code-design
b.apCell
** Interface to the testing logic.
Variables used only by sqlite3Fts5PoslistIterXXX() functions.
nearphrases
** Add an entry for token pToken to the pCsr->pDeferred list.
Errno value from last system error
If the contents of this write should be stored in memory
If no zName is given, restore all system calls to their default
** settings and return NULL
INSERT + UPDATE
Use the LIMIT in cost estimates
Iterate through the contents of the WAL, copying data to the db file
** Deallocate all memory associated with a WhereOrInfo object.
Iterator used while populating OLD.*
60..67 `abcdefg
Task that owns this merger
** CAPI3REF: Virtual Table Cursor Object
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
**
** Every [virtual table module] implementation uses a subclass of the
** following structure to describe cursors that point into the
** [virtual table] and are used
** to loop through the virtual table. Cursors are created using the
** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
** by the [sqlite3_module.xClose | xClose] method. Cursors are used
** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
** of the module. Each module implementation will define
** the content of a cursor structure to suit its own needs.
**
** This superclass exists in order to define fields of the cursor that
** are common to all implementations.
Drop all triggers associated with the table being dropped. Code
** is generated to remove entries from sqlite_master and/or
** sqlite_temp_master if required.
** The next global variable is incremented each type the OP_Sort opcode
** is executed. The test procedures use this information to make sure that
** sorting is occurring or not occurring at appropriate times. This variable
** has no function other than to help verify the correct operation of the
** library.
300
Tokens count up to end of this phrase
Mapping of columns in pFrom to columns in zTo
String accumulator
** This is a utility routine, useful to VFS implementations, that checks
** to see if a database file was a URI that contained a specific query
** parameter, and if so obtains the value of the query parameter.
**
** The zFilename argument is the filename pointer passed into the xOpen()
** method of a VFS implementation. The zParam argument is the name of the
** query parameter we seek. This routine returns the value of the zParam
** parameter if it exists. If the parameter does not exist, this routine
** returns a NULL pointer.
OUT: stats written here
comment:
** Compute a string length that is limited to what can be stored in
** lower 30 bits of a 32-bit signed integer.
**
** The value returned will never be negative. Nor will it ever be greater
** than the actual length of the string. For very long strings (greater
** than 1GiB) the value returned might be less than the true string length.
label: code-design
If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
** then iDb is set to the index of the database identified by <db>.
** In this case, the integrity of database iDb only is verified by
** the VDBE created below.
**
** Otherwise, if the command was simply "PRAGMA integrity_check" (or
** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
** to -1 here, to indicate that the VDBE should verify the integrity
** of all attached databases.
** The output variable *ppExpr is populated with an allocated Fts3Expr
** structure, or set to 0 if the end of the input buffer is reached.
**
** Returns an SQLite error code. SQLITE_OK if everything works, SQLITE_NOMEM
** if a malloc failure occurs, or SQLITE_ERROR if a parse error is encountered.
** If SQLITE_ERROR is returned, pContext is populated with an error message.
Opcode: Once P1 P2 * * *
**
** Fall through to the next instruction the first time this opcode is
** encountered on each invocation of the byte-code program. Jump to P2
** on the second and all subsequent encounters during the same invocation.
**
** Top-level programs determine first invocation by comparing the P1
** operand against the P1 operand on the OP_Init opcode at the beginning
** of the program. If the P1 values differ, then fall through and make
** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are
** the same then take the jump.
**
** For subprograms, there is a bitmask in the VdbeFrame that determines
** whether or not the jump should be taken. The bitmask is necessary
** because the self-altering code trick does not work for recursive
** triggers.
mxPathname
Strings with '\'' doubled. %q
OUT: Best snippet found
** Walk an expression tree. Return non-zero if the expression is constant
** for any single row of the table with cursor iCur. In other words, the
** expression must not refer to any non-deterministic function nor any
** table other than iCur.
!SQLITE_OMIT_SHARED_CACHE
** Implementation of xCommit() method. This is a no-op. The contents of
** the pending-terms hash-table have already been flushed into the database
** by fts3SyncMethod().
Absolute level of segment to modify
Read in the complete content of the index entry
Opaque type used by code in vdbesort.c
Do extra syncs of the journal for robustness
Case 3: We have an inequality comparison against the ROWID field.
If this is an INSERT or UPDATE operation, insert the new record.
ifnotexists ::= IF NOT EXISTS
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
Pointer to the conversion buffer
Total number of ordered columns in the index
The number of tables in the FROM clause is limited by the number of
** bits in a Bitmask
Pointer to the index object
isSavepnt is 0 or 1
Size of zTerm in bytes
** Implementation of the non-aggregate min() and max() functions
** 2008 June 18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This module implements the sqlite3_status() interface and related
** functionality.
OP_OpenEphem opcodes related to this select
** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
**
** This function would be simpler if it recursively called itself. But
** that would mean passing a sufficiently large expression to ExprParse()
** could cause a stack overflow.
The "break" point is here, just past the end of the outer loop.
** Set it.
** Check if the program stored in the VM associated with pParse may
** throw an ABORT exception (causing the statement, but not entire transaction
** to be rolled back). This condition is true if the main program or any
** sub-programs contains any of the following:
**
** * OP_Halt with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
** * OP_Destroy
** * OP_VUpdate
** * OP_VRename
** * OP_FkCounter with P2==0 (immediate foreign key constraint)
** * OP_CreateTable and OP_InitCoroutine (for CREATE TABLE AS SELECT ...)
**
** Then check that the value of Parse.mayAbort is true if an
** ABORT may be thrown, or false otherwise. Return true if it does
** match, or false otherwise. This function is intended to be used as
** part of an assert statement in the compiler. Similar to:
**
** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
Fill in the Pager.zFilename and Pager.zJournal buffers, if required.
Do not discard pages from an in-memory database since we might
** need to rollback later. Just move the page out of the way.
Error messages will be written here
True to ignore empty segments
Name of database iDb
.z =
** Release a lock acquired by winceMutexAcquire()
Return value from subprocedures
One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT
1360
** Return true if the floating point value is Not a Number (NaN).
**
** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
** Otherwise, we have our own implementation that works on most systems.
** Return the size in bytes of a PCache object.
Constant inputs give a constant output
OUT: term (nul-terminated)
True if current term already output
New apRegion[] array
SQLITE_DEBUG
VACUUM => ID
Size of pKey for indexes. PRIMARY KEY for tabs
** "LIMIT -1" always shows all rows. There is some
** controversy about what the correct behavior should be.
** The current implementation interprets "LIMIT 0" to mean
** no rows.
Number of entries in aFunc[]
sqlite3_step() has another row ready
Best match found so far
Various flags
exponent
xRelease
Either:
**
** 1) an error has occurred, or
** 2) the iterator points to EOF, or
** 3) the iterator points to an entry with term (pTerm/nTerm), or
** 4) the FTS5INDEX_QUERY_SCAN flag was set and the iterator points
** to an entry with a term greater than or equal to (pTerm/nTerm).
Pointer to disk image of the page data
Accumulate the error message text here
The table we are writing to
Sanity checking on calling parameters
260
40
Used by: function_list
The trigger containing the target token
OK to factor out constants
One of the WHERE_DISTINCT_* operators
TRUE if currently initializing
comment: Number of temporary registers in aTempReg[]
label: code-design
Segment to iterate through
** Return the most recent error code generated by an SQLite routine. If NULL is
** passed to this function, we assume a malloc() failed during sqlite3_open().
Offset in CREATE TABLE stmt to add a new column
Name of the other table
** Functions for accessing sqlite3_file methods
Register all built-in functions, but do not attempt to read the
** database schema yet. This is delayed until the first time the database
** is accessed.
Database connection for this stmt vtab
Attempt to leave results in this register
conslist_opt ::=
Begin reading this far into payload
Base class containing output vars
comment: Also mutex, for redundancy
label: code-design
Absolute level containing segments
0x1c
Source database page to backup
If this is the initial CREATE INDEX statement (or CREATE TABLE if the
** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
** emit code to allocate the index rootpage on disk and make an entry for
** the index in the sqlite_master table and populate the index with
** content. But, do not do this if we are simply reading the sqlite_master
** table to parse the schema, or if this index is the PRIMARY KEY index
** of a WITHOUT ROWID table.
**
** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
** or UNIQUE index in a CREATE TABLE statement. Since the table
** has just been created, it contains no data and the index initialization
** step can be skipped.
First of nPk registers holding PRIMARY KEY value
** Check the existence and status of a file.
Size of aStat[] array
True if a transaction is opened
Index of first sample >= pRec
The aiRowLogEst[] value for the sPk index
The inode of fd
True if any part of database file changed
Object declarations
CURTYPE_VTAB. Vtab cursor
For looping over indices
Expression node to test
** The second argument points to an FKey object representing a foreign key
** for which pTab is the child table. An UPDATE statement against pTab
** is currently being processed. For each column of the table that is
** actually updated, the corresponding element in the aChange[] array
** is zero or greater (if a column is unmodified the corresponding element
** is set to -1). If the rowid column is modified by the UPDATE statement
** the bChngRowid argument is non-zero.
**
** This function returns true if any of the columns that are part of the
** child key for FK constraint *p are modified.
Start of code for Step 6
Index of first record in sub-journal
a pointer to a Token structure
At one time, code such as "SELECT new.x" within a trigger would
** cause this condition to run. Since then, we have restructured how
** trigger code is generated and so this condition is no longer
** possible. However, it can still be true for statements like
** the following:
**
** CREATE TABLE t1(col INTEGER);
** SELECT (SELECT t1.col) FROM FROM t1;
**
** when columnType() is called on the expression "t1.col" in the
** sub-select. In this case, set the column type to NULL, even
** though it should really be "INTEGER".
**
** This is not a problem, as the column type of "t1.col" is never
** used. When columnType() is called on the expression
** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
** branch below.
INDEXED
*************************************************************************
** Interface to code in fts5_expr.c.
zDb
Set content-flag (detail=none mode)
"Managed" code needs this. Ticket #3382.
comment: Silence some compiler warnings
label: code-design
Find modified rows
Read the value of meta[3] from the database to determine where the
** root page of the new table should go. meta[3] is the largest root-page
** created so far, so the new root-page is (meta[3]+1).
Parse a MATCH expression.
!defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
Text of the new string
0 INVALID:
Opcode: And P1 P2 P3 * *
** Synopsis: r[P3]=(r[P1] && r[P2])
**
** Take the logical AND of the values in registers P1 and P2 and
** write the result into register P3.
**
** If either P1 or P2 is 0 (false) then the result is 0 even if
** the other input is NULL. A NULL and true or two NULLs give
** a NULL output.
zNum is exactly 9223372036854775808. Fits if negative. The
** special case 2 overflow if positive
** Open a file.
** Sleep for nMicro microseconds. Return the number of microseconds
** actually slept.
Ignore COLLATE or affinity on this tree
Flags to sync db file with (or 0)
If the approximation iKey is larger than the actual real search
** term, substitute >= for > and < for <=. e.g. if the search term
** is 4.9 and the integer approximation 5:
**
** (x > 4.9) -> (x >= 5)
** (x <= 4.9) -> (x < 5)
Number of elements in the data array
** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
** existing data). Grow the buffer if required.
**
** If successful, return SQLITE_OK. Otherwise, if an OOM error is encountered
** trying to resize the buffer, return SQLITE_NOMEM.
Array of sub-lists
0 is not a legal page number and page 1 cannot be an
** overflow page. Therefore if ovflPgno<2 or past the end of the
** file the database must be corrupt.
Old value of pPg->pgno, if sync is required
** Name of the default collating sequence
** Restore the cursor to the position it was in (or as close to as possible)
** when saveCursorPosition() was called. Note that this call deletes the
** saved position info stored by saveCursorPosition(), so there can be
** at most one effective restoreCursorPosition() call after each
** saveCursorPosition().
Used to write the new, merged, segment
SQLITE_ENABLE_MEMORY_MANAGEMENT
** Delete an IdList.
Disable pWC->a[iParent] when this term disabled
The complete hash table
** Check to see if the i-th bit is set. Return true or false.
** If p is NULL (if the bitmap has not been created) or if
** i is out of range, then return false.
x=EXPR
** Set the pFile->lastErrno. Do this in a subroutine as that provides
** a convenient place to set a breakpoint.
State information for the randomness gatherer.
Page containing pPayload
Bytes in string, or negative
transtype ::= EXCLUSIVE
If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
** column of the parent table (table pTab).
!defined(SQLITE_OMIT_DATETIME_FUNCS)
Justification of ALWAYS(): A correct vtab constructor must allocate
** the sqlite3_vtab object if successful.
TK_GE
The index that might be used for coverage
Allocate an extra register for limit+offset
Jump here on any error
** Do a comparison between a 64-bit signed integer and a 64-bit floating-point
** number. Return negative, zero, or positive if the first (i64) is less than,
** equal to, or greater than the second (double).
Extra space associated with each page
Existing nearset, or NULL
Update the state of the lock has held in the file descriptor then
** return the appropriate result code.
SQLITE_OMIT_GET_TABLE
** By default, this module parses the legacy syntax that has been
** traditionally used by fts3. Or, if SQLITE_ENABLE_FTS3_PARENTHESIS
** is defined, then it uses the new syntax. The differences between
** the new and the old syntaxes are:
**
** a) The new syntax supports parenthesis. The old does not.
**
** b) The new syntax supports the AND and NOT operators. The old does not.
**
** c) The old syntax supports the "-" token qualifier. This is not
** supported by the new syntax (it is replaced by the NOT operator).
**
** d) When using the old syntax, the OR operator has a greater precedence
** than an implicit AND. When using the new, both implicity and explicit
** AND operators have a higher precedence than OR.
**
** If compiled with SQLITE_TEST defined, then this module exports the
** symbol "int sqlite3_fts3_enable_parentheses". Setting this variable
** to zero causes the module to use the old syntax. If it is set to
** non-zero the new syntax is activated. This is so both syntaxes can
** be tested using a single build of testfixture.
**
** The following describes the syntax supported by the fts3 MATCH
** operator in a similar format to that used by the lemon parser
** generator. This module does not use actually lemon, it uses a
** custom parser.
**
** query ::= andexpr (OR andexpr)*.
**
** andexpr ::= notexpr (AND? notexpr)*.
**
** notexpr ::= nearexpr (NOT nearexpr|-TOKEN)*.
** notexpr ::= LP query RP.
**
** nearexpr ::= phrase (NEAR distance_opt nearexpr)*.
**
** distance_opt ::= .
** distance_opt ::= / INTEGER.
**
** phrase ::= TOKEN.
** phrase ::= COLUMN:TOKEN.
** phrase ::= "TOKEN TOKEN TOKEN...".
comment: Opcode: IdxInsert P1 P2 P3 P4 P5
** Synopsis: key=r[P2]
**
** Register P2 holds an SQL index key made using the
** MakeRecord instructions. This opcode writes that key
** into the index P1. Data for the entry is nil.
**
** If P4 is not zero, then it is the number of values in the unpacked
** key of reg(P2). In that case, P3 is the index of the first register
** for the unpacked key. The availability of the unpacked key can sometimes
** be an optimization.
**
** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
** that this insert is likely to be an append.
**
** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
** then the change counter is unchanged.
**
** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
** run faster by avoiding an unnecessary seek on cursor P1. However,
** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
** seeks on the cursor or if the most recent seek used a key equivalent
** to P2.
**
** This instruction only works for indices. The equivalent instruction
** for tables is OP_Insert.
label: code-design
1st input operand
Used to convert UTF16 parameters into UTF8 for display
** The MSVC CRT on Windows CE may not have a localtime() function.
** So declare a substitute. The substitute function itself is
** defined in "os_win.c".
comment:
** Arguments aIdx, aDistance and aSpare all point to arrays of size
** nIdx. The aIdx array contains the set of integers from 0 to
** (nIdx-1) in no particular order. This function sorts the values
** in aIdx according to the indexed values in aDistance. For
** example, assuming the inputs:
**
** aIdx = { 0, 1, 2, 3 }
** aDistance = { 5.0, 2.0, 7.0, 6.0 }
**
** this function sets the aIdx array to contain:
**
** aIdx = { 0, 1, 2, 3 }
**
** The aSpare array is used as temporary working space by the
** sorting algorithm.
label: code-design
aSample[] for the lower bound
Total size of iBestCol in tokens
** Attempt to set a system-lock on the file pFile. The lock is
** described by pLock.
**
** If the pFile was opened read/write from unix-excl, then the only lock
** ever obtained is an exclusive lock, and it is obtained exactly once
** the first time any lock is attempted. All subsequent system locking
** operations become no-ops. Locking operations still happen internally,
** in order to coordinate access between separate database connections
** within this process, but all of that is handled in memory and the
** operating system does not participate.
**
** This function is a pass-through to fcntl(F_SETLK) if pFile is using
** any VFS other than "unix-excl" or if pFile is opened on "unix-excl"
** and is read-only.
**
** Zero is returned if the call completes successfully, or -1 if a call
** to fcntl() fails. In this case, errno is set appropriately (by fcntl()).
Error condition
comment:
** Add a new name/number pair to a VList. This might require that the
** VList object be reallocated, so return the new VList. If an OOM
** error occurs, the original VList returned and the
** db->mallocFailed flag is set.
**
** A VList is really just an array of integers. To destroy a VList,
** simply pass it to sqlite3DbFree().
**
** The first integer is the number of integers allocated for the whole
** VList. The second integer is the number of integers actually used.
** Each name/number pair is encoded by subsequent groups of 3 or more
** integers.
**
** Each name/number pair starts with two integers which are the numeric
** value for the pair and the size of the name/number pair, respectively.
** The text name overlays one or more following integers. The text name
** is always zero-terminated.
**
** Conceptually:
**
** struct VList {
** int nAlloc; // Number of allocated slots
** int nUsed; // Number of used slots
** struct VListEntry {
** int iValue; // Value for this entry
** int nSlot; // Slots used by this entry
** // ... variable name goes here
** } a[0];
** }
**
** During code generation, pointers to the variable names within the
** VList are taken. When that happens, nAlloc is set to zero as an
** indication that the VList may never again be enlarged, since the
** accompanying realloc() would invalidate the pointers.
label: code-design
sqlite3_free(pCur);
** Generate a single line of output for the tree, with a prefix that contains
** all the appropriate tree lines
** A specially optimized version of vdbeSorterCompare() that assumes that
** the first field of each key is a TEXT value and that the collation
** sequence to compare them with is BINARY.
** Interpret the given string as a boolean value.
All foreign keys by referenced table name
Consider tokens with this root node
!defined(SQLITE_OMIT_CTE)
** If pNode currently points to a match, this function returns SQLITE_OK
** without modifying it. Otherwise, pNode is advanced until it does point
** to a match or EOF is reached.
Thread procedure Win32 compatibility shim
For a WITHOUT ROWID table, create an ephemeral table used to
** hold all primary keys for rows to be deleted.
Open every index that needs updating.
** If the expression is always either TRUE or FALSE (respectively),
** then return 1. If one cannot determine the truth value of the
** expression at compile-time return 0.
**
** This is an optimization. If is OK to return 0 here even if
** the expression really is always false or false (a false negative).
** But it is a bug to return 1 if the expression might have different
** boolean values in different circumstances (a false positive.)
**
** Note that if the expression is part of conditional for a
** LEFT JOIN, then we cannot determine at compile-time whether or not
** is it true or false, so always return 0.
The size of a Mem5Link object must be a power of two. Verify that
** this is case.
** Creates the lock file and any missing directories in lockPath
True if attempting to delete from a view
** 2014 August 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the public interface for the RBU extension.
xDisconnect
FROM subqueries have Table metadata
** Configure an sqlite3_wal_hook() callback to automatically checkpoint
** a database after committing a transaction if there are nFrame or
** more frames in the log file. Passing zero or a negative value as the
** nFrame parameter disables automatic checkpoints entirely.
**
** The callback registered by this function replaces any existing callback
** registered using sqlite3_wal_hook(). Likewise, registering a callback
** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
** configured by this function.
4 -> ORDER
Comparison information for merging rows
Remove a single entry from the hash table given a pointer to that
** element and a hash on the element's key.
Opcode: Close P1 * * * *
**
** Close a cursor previously opened as P1. If P1 is not
** currently open, this instruction is a no-op.
comment: Clear the temporary register cache, thereby ensuring that each
** co-routine has its own independent set of registers, because co-routines
** might expect their registers to be preserved across an OP_Yield, and
** that could cause problems if two or more co-routines are using the same
** temporary register.
label: code-design
450
** Implementation of the sqlite3_pcache.xInit method.
The sqlite3BtreeCursor() routine can only fail for the first cursor
** opened for a database. Since there is already an open cursor when this
** opcode is run, the sqlite3BtreeCursor() cannot fail
Nesting level
** Implementation of the QUOTE() function. This function takes a single
** argument. If the argument is numeric, the return value is the same as
** the argument. If the argument is NULL, the return value is the string
** "NULL". Otherwise, the argument is enclosed in single quotes with
** single-quote escapes.
** Free any buffer allocated by pBuf. Zero the structure before returning.
If that was the last leaf node, break out of the loop
File handle here
adjust exponent for shifting decimal point
** 2008 May 26
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file is used by programs that want to link against the
** ICU extension. All it does is declare the sqlite3IcuInit() interface.
****************************************************************************
comment:
** This is the routine that actually formats the sqlite3_log() message.
** We house it in a separate routine from sqlite3_log() to avoid using
** stack space on small-stack systems when logging is disabled.
**
** sqlite3_log() must render into a static buffer. It cannot dynamically
** allocate memory because it might be called while the memory allocator
** mutex is held.
**
** sqlite3VXPrintf() might ask for *temporary* memory allocations for
** certain format characters (%q) or for very large precisions or widths.
** Care must be taken that any sqlite3_log() calls that occur while the
** memory mutex is held do not use these mechanisms.
label: code-design
pUserData
comment: Remove the xxx_node entry.
label: code-design
** Append the hash of the data type passed as the second argument to the
** hash-key value passed as the first. Return the new hash-key value.
** This routine is called by the parser while in the middle of
** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
** been seen on a column. This routine sets the notNull flag on
** the column currently under construction.
** Streaming version of sqlite3session_changeset().
Hash table for fast lookup by key
Number of header fields parsed so far
EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
** twos-complement integer.
************* Include opcodes.h in the middle of vdbe.h *******************
cmd ::= DETACH database_kw_opt expr
** Discard any data stored in the in-memory hash tables. Do not write it
** to the database. Additionally, assume that the contents of the %_data
** table may have changed on disk. So any in-memory caches of %_data
** records must be invalidated.
Keep running the loop until the Queue is empty
For looping over tables in pSrc
** The char() function takes zero or more arguments, each of which is
** an integer. It constructs a string where each character of the string
** is the unicode character for the corresponding integer argument.
Opcode: NullRow P1 * * * *
**
** Move the cursor P1 to a null row. Any OP_Column operations
** that occur while the cursor is on the null row will always
** write a NULL.
If pPayload is part of the data area of pPage, then make sure pPage
** is still writeable
Mapping from Index fields to RHS fields
Position list (no 0x00 term)
The VDBE has been deallocated
Sorter key to compare pVal with
The parser to be shifted
1.0e+22 is the largest power of 10 than can be
** represented exactly.
Local cache of pPage->aData
whereLoopAddBtree() always generates and inserts the automatic index
** case first. Hence compatible candidate WhereLoops never have a larger
** rSetup. Call this SETUP-INVARIANT
comment: In theory this code could just pass SQLITE_TRANSIENT as the final
** argument to sqlite3ValueSetStr() and have the copy created
** automatically. But doing so makes it difficult to detect any OOM
** error. Hence the code to create the copy externally.
label: code-design
If this phrase is applies specifically to some column other than
** column iCol, return a NULL pointer.
Byte offset within current leaf
True to extend file if necessary
Complete log message
** The proxy lock file path for the database at dbPath is written into lPath,
** which must point to valid, writable memory large enough for a maxLen length
** file path.
nearset ::= phrase
Opcode: ShiftLeft P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]<<r[P1]
**
** Shift the integer value in register P2 to the left by the
** number of bits specified by the integer in register P1.
** Store the result in register P3.
** If either input is NULL, the result is NULL.
cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist
Page number to fetch
ON CONFLICT algorithm.
Convert the ORDER BY term into an integer column number iCol,
** taking care to preserve the COLLATE clause if it exists
If auto-vacuum is disabled in this build and this is an auto-vacuum
** database, mark the database as read-only.
Child nodes. For a NOT node, this array always contains 2 entries. For
** AND or OR nodes, it contains 2 or more entries.
Number of entries in aMem
OUT: Return code
True to use OPFLAG_SEEKRESULT
** Check that the contents of the FTS index match that of the %_content
** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
** some other SQLite error code if an error occurs while attempting to
** determine this.
True to interpret filenames as URIs
Size of aDoclist in bytes
Cursor seek operation
248
Pointer to current term
** Decrement the r-tree reference count. When the reference count reaches
** zero the structure is deleted.
synopsis: r[P1@P3] <-> r[P2@P3]
Start of loop body
Argument to the thread
Aggregate function
Position of term for entry to add
If a term is the BETWEEN operator, create two new virtual terms
** that define the range that the BETWEEN implements. For example:
**
** a BETWEEN b AND c
**
** is converted into:
**
** (a BETWEEN b AND c) AND (a>=b) AND (a<=c)
**
** The two new terms are added onto the end of the WhereClause object.
** The new terms are "dynamic" and are children of the original BETWEEN
** term. That means that if the BETWEEN term is coded, the children are
** skipped. Or, if the children are satisfied by an index, the original
** BETWEEN term is skipped.
** CAPI3REF: Setting The Subtype Of An SQL Function
** METHOD: sqlite3_context
**
** The sqlite3_result_subtype(C,T) function causes the subtype of
** the result from the [application-defined SQL function] with
** [sqlite3_context] C to be the value T. Only the lower 8 bits
** of the subtype T are preserved in current versions of SQLite;
** higher order bits are discarded.
** The number of subtype bytes preserved by SQLite might increase
** in future releases of SQLite.
Move page iDbPage from its current location to page number iFreePage
** This function is used to merge two position lists into one. When it is
** called, *pp1 and *pp2 must both point to position lists. A position-list is
** the part of a doclist that follows each document id. For example, if a row
** contains:
**
** 'a b c'|'x y z'|'a b b a'
**
** Then the position list for this row for token 'b' would consist of:
**
** 0x02 0x01 0x02 0x03 0x03 0x00
**
** When this function returns, both *pp1 and *pp2 are left pointing to the
** byte following the 0x00 terminator of their respective position lists.
**
** If isSaveLeft is 0, an entry is added to the output position list for
** each position in *pp2 for which there exists one or more positions in
** *pp1 so that (pos(*pp2)>pos(*pp1) && pos(*pp2)-pos(*pp1)<=nToken). i.e.
** when the *pp1 token appears before the *pp2 token, but not more than nToken
** slots before it.
**
** e.g. nToken==1 searches for adjacent positions.
Array of Fts3SegReader objects
Generate auto-index WhereLoops
Needed for schema access
An instance of this object represents a JSON string
** under construction. Really, this is a generic string accumulator
** that can be and is used to create strings other than JSON.
39
comment:
** This function is called after an incrmental-merge operation has run to
** merge (or partially merge) two or more segments from absolute level
** iAbsLevel.
**
** Each input segment is either removed from the db completely (if all of
** its data was copied to the output segment by the incrmerge operation)
** or modified in place so that it no longer contains those entries that
** have been duplicated in the output segment.
label: code-design
Table change pertains to
** Advance the MergeEngine to its next entry.
** Set *pbEof to true there is no next entry because
** the MergeEngine has reached the end of all its inputs.
**
** Return SQLITE_OK if successful or an error code if an error occurs.
New list element
#include "windows.h"
Integer key for tables. Size of pKey for indices
***************************************************************************
** SQL functions used for testing and debugging
***************************************************************************
If none of the above, then the result destination must be
** SRT_Output. This routine is never called with any other
** destination other than the ones handled above or SRT_Output.
**
** For SRT_Output, results are stored in a sequence of registers.
** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
** return the next row of result.
Token value. Zero terminated and dequoted
CHECK constraint uses a changing column
Determine the BM25 score for the current row.
The name context of the SELECT statement
** Free all memory belonging to the PmaReader object passed as the
** argument. All structure fields are set to zero before returning.
Finite column numbers
Read the term data for the next term
160
comment:
** This routine is called to handle SQL of the following forms:
**
** insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
** insert into TABLE (IDLIST) select
** insert into TABLE (IDLIST) default values
**
** The IDLIST following the table name is always optional. If omitted,
** then a list of all (non-hidden) columns for the table is substituted.
** The IDLIST appears in the pColumn parameter. pColumn is NULL if IDLIST
** is omitted.
**
** For the pSelect parameter holds the values to be inserted for the
** first two forms shown above. A VALUES clause is really just short-hand
** for a SELECT statement that omits the FROM clause and everything else
** that follows. If the pSelect parameter is NULL, that means that the
** DEFAULT VALUES form of the INSERT statement is intended.
**
** The code generated follows one of four templates. For a simple
** insert with data coming from a single-row VALUES clause, the code executes
** once straight down through. Pseudo-code follows (we call this
** the "1st template"):
**
** open write cursor to <table> and its indices
** put VALUES clause expressions into registers
** write the resulting record into <table>
** cleanup
**
** The three remaining templates assume the statement is of the form
**
** INSERT INTO <table> SELECT ...
**
** If the SELECT clause is of the restricted form "SELECT * FROM <table2>" -
** in other words if the SELECT pulls all columns from a single table
** and there is no WHERE or LIMIT or GROUP BY or ORDER BY clauses, and
** if <table2> and <table1> are distinct tables but have identical
** schemas, including all the same indices, then a special optimization
** is invoked that copies raw records from <table2> over to <table1>.
** See the xferOptimization() function for the implementation of this
** template. This is the 2nd template.
**
** open a write cursor to <table>
** open read cursor on <table2>
** transfer all records in <table2> over to <table>
** close cursors
** foreach index on <table>
** open a write cursor on the <table> index
** open a read cursor on the corresponding <table2> index
** transfer all records from the read to the write cursors
** close cursors
** end foreach
**
** The 3rd template is for when the second template does not apply
** and the SELECT clause does not read from <table> at any time.
** The generated code follows this template:
**
** X <- A
** goto B
** A: setup for the SELECT
** loop over the rows in the SELECT
** load values into registers R..R+n
** yield X
** end loop
** cleanup after the SELECT
** end-coroutine X
** B: open write cursor to <table> and its indices
** C: yield X, at EOF goto D
** insert the select result into <table> from R..R+n
** goto C
** D: cleanup
**
** The 4th template is used if the insert statement takes its
** values from a SELECT but the data is being inserted into a table
** that is also read as part of the SELECT. In the third form,
** we have to use an intermediate table to store the results of
** the select. The template is like this:
**
** X <- A
** goto B
** A: setup for the SELECT
** loop over the tables in the SELECT
** load value into register R..R+n
** yield X
** end loop
** cleanup after the SELECT
** end co-routine R
** B: open temp table
** L: yield X, at EOF goto M
** insert row from R..R+n into temp table
** goto L
** M: open write cursor to <table> and its indices
** rewind temp table
** C: loop over rows of intermediate table
** transfer values form intermediate table into <table>
** end loop
** D: cleanup
label: code-design
Register to hold packed record
Saved values of p->nLimit and p->nOffset
Data comes from this temporary cursor if >=0
** An instance of the following structure can be declared on a stack and used
** to save the Parse.zAuthContext value so that it can be restored later.
** julianday( TIMESTRING, MOD, MOD, ...)
**
** Return the julian day number of the date specified in the arguments
User authentication information
Which column to return
SELECT from sessionSelectStmt()
** Lower the locking level on file descriptor id to locktype. locktype
** must be either NO_LOCK or SHARED_LOCK.
**
** If the locking level of the file descriptor is already at or below
** the requested locking level, this routine is a no-op.
**
** It is not possible for this routine to fail if the second argument
** is NO_LOCK. If the second argument is SHARED_LOCK then this routine
** might return SQLITE_IOERR;
Do not output
True if table-valued-function syntax
** Discard the contents of the pending-terms hash tables.
TO
CASE
263
Must be right after "base"
comment: Warnings from sqlite3_log()
label: code-design
Name of db (e.g. "main")
Unlink the session from the linked list of sessions attached to the
** database handle. Hold the db mutex while doing so.
** Close an iterator opened by sqlite3Fts5IndexQuery().
If shared memory could not be created, then close the mutex and fail
Size of pList in bytes
True to skip deleted entries
NOTE: Be sure to update mkopcodeh.tcl when adding or removing
** cases from this switch!
Invoke BEFORE DELETE trigger programs.
Hash score: 182
Compiled version of zSql
Language-id to search
tab2 must be NOT NULL if tab1 is
available free spot. check to see if this is going to
Non-threadsafe build, use strerror().
Remove any entries of the sqlite_sequence table associated with
** the table being dropped. This is done before the table is dropped
** at the btree level, in case the sqlite_sequence table needs to
** move as a result of the drop (can happen in auto-vacuum mode).
Opcode: VBegin * * * P4 *
**
** P4 may be a pointer to an sqlite3_vtab structure. If so, call the
** xBegin method for that table.
**
** Also, whether or not P4 is set, check that this is not being called from
** within a callback to a virtual table xSync() method. If it is, the error
** code will be set to SQLITE_LOCKED.
Total time spent executing this instruction
Prerequisites
Name of %_segments table
comment: The shared-lock has just been acquired then check to
** see if the database has been modified. If the database has changed,
** flush the cache. The hasHeldSharedLock flag prevents this from
** occurring on the very first access to a file, in order to save a
** single unnecessary sqlite3OsRead() call at the start-up.
**
** Database changes are detected by looking at 15 bytes beginning
** at offset 24 into the file. The first 4 of these 16 bytes are
** a 32-bit counter that is incremented with each change. The
** other bytes change randomly with each file change when
** a codec is in use.
**
** There is a vanishingly small chance that a change will not be
** detected. The chance of an undetected change is so small that
** it can be neglected.
label: code-design
Debug print SQL as it executes
Number of SQL function arguments
4,5
** Write data to a blob handle.
Index of candidate output segment
Wal connection
Invoke the authorization callback.
** Set the value stored in *pMem should already be a NULL.
** Also store a pointer to go with it.
UTF-16 Little-endian -> UTF-8
** Evaluate an expression (either a vector or a scalar expression) and store
** the result in continguous temporary registers. Return the index of
** the first register used to store the result.
**
** If the returned result register is a temporary scalar, then also write
** that register number into *piFreeable. If the returned result register
** is not a temporary or if the expression is a vector set *piFreeable
** to 0.
** Extract the next token from a tokenization cursor. The cursor must
** have been opened by a prior call to porterOpen().
If no destructor action specified: do nothing
LIMIT if wctrlFlags has WHERE_USE_LIMIT
Ptr to head of pagers backup list
Cursor to iterate through node
The VM that owns this context
Size of allocation rounded up to power of 2
** This function interprets the string at (*pp) as a non-negative integer
** value. It reads the integer and sets *pnOut to the value read, then
** sets *pp to point to the byte immediately following the last byte of
** the integer value.
**
** Only decimal digits ('0'..'9') may be part of an integer value.
**
** If *pp does not being with a decimal digit SQLITE_ERROR is returned and
** the output value undefined. Otherwise SQLITE_OK is returned.
**
** This function is used when parsing the "prefix=" FTS4 parameter.
Initialize the contents of sLocal to avoid a compiler warning.
Change in the number of documents
Argument
The first element of an INTARRAY is always the
** count of the number of elements to follow
True if key size is 2^32 or more
** Set the i-th bit. Return 0 on success and an error code if
** anything goes wrong.
**
** This routine might cause sub-bitmaps to be allocated. Failing
** to get the memory needed to hold the sub-bitmap is the only
** that can go wrong with an insert, assuming p and i are valid.
**
** The calling function must ensure that p is a valid Bitvec object
** and that the value for "i" is within range of the Bitvec object.
** Otherwise the behavior is undefined.
** A single step of an incremental checkpoint - frame iWalFrame of the wal
** file should be copied to page iDbPage of the database file.
Keyword text
OUT: Pointer to table name
An OOM - finalize() below returns S_NOMEM
If the query is DISTINCT with an ORDER BY but is not an aggregate, and
** if the select-list is the same as the ORDER BY list, then this query
** can be rewritten as a GROUP BY. In other words, this:
**
** SELECT DISTINCT xyz FROM ... ORDER BY xyz
**
** is transformed to:
**
** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
**
** The second form is preferred as a single index (or temp-table) may be
** used for both the ORDER BY and DISTINCT processing. As originally
** written the query must use a temp-table for at least one of the ORDER
** BY and DISTINCT, and an index or separate temp-table for the other.
Information about each nest loop in WHERE
If z is a NULL pointer, set pMem to contain an SQL NULL.
Size of aNode in bytes
** This variant of sqlite3BtreePayload() works even if the cursor has not
** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read()
** interface.
On the upwards pass, or...
Check that this node should not be FTS5_TERM
Estimated size of value in this column. sizeof(INT)==1
True for a "natural" join
If there are DELETE triggers on this table and the
** recursive-triggers flag is set, call GenerateRowDelete() to
** remove the conflicting row from the table. This will fire
** the triggers and remove both the table and index b-tree entries.
**
** Otherwise, if there are no triggers or the recursive-triggers
** flag is not set, but the table has one or more indexes, call
** GenerateRowIndexDelete(). This removes the index b-tree entries
** only. The table b-tree entry will be replaced by the new entry
** when it is inserted.
**
** If either GenerateRowDelete() or GenerateRowIndexDelete() is called,
** also invoke MultiWrite() to indicate that this VDBE may require
** statement rollback (if the statement is aborted after the delete
** takes place). Earlier versions called sqlite3MultiWrite() regardless,
** but being more selective here allows statements like:
**
** REPLACE INTO t(rowid) VALUES($newrowid)
**
** to run without a statement journal if there are no indexes on the
** table.
** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
** the F_FULLFSYNC macro is defined. F_FULLFSYNC is currently
** only available on Mac OS X. But that could change.
The MATCH or rowid constraint, if any
Index structure
Read the total number of levels and segments from the start of the
** structure record.
** Possible values for the sqlite.magic field.
** The numbers are obtained at random and have no special meaning, other
** than being distinct from one another.
xNext
This loop determines (a) if the commit hook should be invoked and
** (b) how many database files have open write transactions, not
** including the temp database. (b) is important because if more than
** one database file has an open write transaction, a master journal
** file is required for an atomic commit.
stmt_cursor is a subclass of sqlite3_vtab_cursor which will
** serve as the underlying representation of a cursor that scans
** over rows of the result
The minor type of the error token
Destructor for the data
Database is open
IN/OUT: Pointer to PendingList struct
If the column has REAL affinity, it may currently be stored as an
** integer. Use OP_RealAffinity to make sure it is really real.
**
** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
** floating point when extracting it from the record.
** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
** based on the sub-platform)?
Report an out-of-memory (OOM) condition
Make sure initialized even if FullPathname() fails
trigger_event ::= UPDATE
A
If the entry in aPgno[] is already set, then the previous writer
** must have exited unexpectedly in the middle of a transaction (after
** writing one or more dirty pages to the WAL to free up memory).
** Remove the remnants of that writers uncommitted transaction from
** the hash-table before writing any new entries.
Assert that the mutex (if any) associated with the BtShared database
** that contains table p is held by the caller. See header comments
** above function sqlite3VtabUnlockList() for an explanation of why
** this makes it safe to access the sqlite3.pDisconnect list of any
** database connection that may have an entry in the p->pVTable list.
amalgamator: keep
** 2008 October 07
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes.
**
** This implementation in this file does not provide any mutual
** exclusion and is thus suitable for use only in applications
** that use SQLite in a single thread. The routines defined
** here are place-holders. Applications can substitute working
** mutex routines at start-time using the
**
** sqlite3_config(SQLITE_CONFIG_MUTEX,...)
**
** interface.
**
** If compiled with SQLITE_DEBUG, then additional logic is inserted
** that does error checking on mutexes to make sure they are being
** called correctly.
Opcode: Compare P1 P2 P3 P4 P5
** Synopsis: r[P1@P3] <-> r[P2@P3]
**
** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
** the comparison for use by the next OP_Jump instruct.
**
** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is
** determined by the most recent OP_Permutation operator. If the
** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
** order.
**
** P4 is a KeyInfo structure that defines collating sequences and sort
** orders for the comparison. The permutation applies to registers
** only. The KeyInfo elements are used sequentially.
**
** The comparison is a sort comparison, so NULLs compare equal,
** NULLs are less than numbers, numbers are less than strings,
** and strings are less than blobs.
Page size according to the log
** Lock the file with the lock specified by parameter locktype - one
** of the following:
**
** (1) SHARED_LOCK
** (2) RESERVED_LOCK
** (3) PENDING_LOCK
** (4) EXCLUSIVE_LOCK
**
** Sometimes when requesting one lock state, additional lock states
** are inserted in between. The locking might fail on one of the later
** transitions leaving the lock state different from what it started but
** still short of its goal. The following chart shows the allowed
** transitions and the inserted intermediate states:
**
** UNLOCKED -> SHARED
** SHARED -> RESERVED
** SHARED -> (PENDING) -> EXCLUSIVE
** RESERVED -> (PENDING) -> EXCLUSIVE
** PENDING -> EXCLUSIVE
**
** This routine will only increase a lock. The winUnlock() routine
** erases all locks at once and returns us immediately to locking level 0.
** It is not possible to lower the locking level one step at a time. You
** must go straight to locking level 0.
OUT: Pointer to position list
Make sure a mutex is held on the table to be accessed
setlist
Check if there exists a MATCH constraint - even an unusable one. If there
** is, do not consider the lookup-by-rowid plan as using such a plan would
** require the VDBE to evaluate the MATCH constraint, which is not currently
** possible.
Check to see if the new rowid already exists in the table. Skip
** the following conflict logic if it does not.
Remove the shared lock before trying the range. we'll need to
** reestablish the shared lock if we can't get the afpUnlock
If only SQLITE_ENABLE_STAT3_OR_STAT4 is on, then the largest input
** possible to this routine is 310, resulting in a maximum x of 31
232
** The second argument, argv[], is an array of pointers to nul-terminated
** strings. This function makes a copy of the array and strings into a
** single block of memory. It then dequotes any of the strings that appear
** to be quoted.
**
** If successful, output parameter *pazDequote is set to point at the
** array of dequoted strings and SQLITE_OK is returned. The caller is
** responsible for eventually calling sqlite3_free() to free the array
** in this case. Or, if an error occurs, an SQLite error code is returned.
** The final value of *pazDequote is undefined in this case.
ATTACH
Temp space for PoslistNearMerge()
True if the GROUP BY and ORDER BY are the same
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
** if we run out of memory.
Conflict algorithm. (OE_Abort, etc)
(272) input ::= cmdlist
Generate code for an unconditional jump to instruction iDest
CSE1 from below
Set the threshold at which OP_Once counters reset back to zero.
** By default this is 0x7ffffffe (over 2 billion), but that value is
** too big to test in a reasonable amount of time, so this control is
** provided to set a small and easily reachable reset value.
Root page number of the table to be locked
a short read or version format mismatch means we need to create a new
** conch file.
** Try to read the wal-index header. Return 0 on success and 1 if
** there is a problem.
**
** The wal-index is in shared memory. Another thread or process might
** be writing the header at the same time this procedure is trying to
** read it, which might result in inconsistency. A dirty read is detected
** by verifying that both copies of the header are the same and also by
** a checksum on the header.
**
** If and only if the read is consistent and the header is different from
** pWal->hdr, then pWal->hdr is updated to the content of the new header
** and *pChanged is set to 1.
**
** If the checksum cannot be verified return non-zero. If the header
** is read successfully and the checksum verified, return zero.
Calculate the phrase frequency (symbol "f(qi,D)" in the documentation)
** for each phrase in the query for the current row.
First byte of the Cell
** Delete all entries in the %_segments table associated with the segment
** opened with seg-reader pSeg. This function does not affect the contents
** of the %_segdir table.
** Assuming mem5.zPool is divided up into an array of Mem5Link
** structures, return a pointer to the idx-th such link.
** For a compound SELECT statement, make sure p->pPrior->pNext==p for
** all elements in the list. And make sure list length does not exceed
** SQLITE_LIMIT_COMPOUND_SELECT.
Initialize the output buffer
FROM clause pLvl reads data from
For looping over existing file IDs
Disable the pCache->nPage validity check
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Main file for the SQLite library. The routines in this file
** implement the programmer interface to the library. Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
** Rtree virtual table module xBestIndex method. There are three
** table scan strategies to choose from (in order from most to
** least desirable):
**
** idxNum idxStr Strategy
** ------------------------------------------------
** 1 Unused Direct lookup by rowid.
** 2 See below R-tree query or full-table scan.
** ------------------------------------------------
**
** If strategy 1 is used, then idxStr is not meaningful. If strategy
** 2 is used, idxStr is formatted to contain 2 bytes for each
** constraint used. The first two bytes of idxStr correspond to
** the constraint in sqlite3_index_info.aConstraintUsage[] with
** (argvIndex==1) etc.
**
** The first of each pair of bytes in idxStr identifies the constraint
** operator as follows:
**
** Operator Byte Value
** ----------------------
** = 0x41 ('A')
** <= 0x42 ('B')
** < 0x43 ('C')
** >= 0x44 ('D')
** > 0x45 ('E')
** MATCH 0x46 ('F')
** ----------------------
**
** The second of each pair of bytes identifies the coordinate column
** to which the constraint applies. The leftmost coordinate column
** is 'a', the second from the left 'b' etc.
Operator(s) to scan for
!defined(SQLITE_HWTIME_H)
Unsigned integer types. These are already defined in the sqliteInt.h,
** but the definitions need to be repeated for separate compilation.
Many of the flag-pragmas modify the code generated by the SQL
** compiler (eg. count_changes). So add an opcode to expire all
** compiled SQL statements after modifying a pragma value.
************* End of wal.c ************************************************
Length of z in bytes
Segment id
Number of entries in argv[]
non-ASCII codepoint read from input
** Constructor for a new stmt_cursor object.
** Locate or create an AutoincInfo structure associated with table pTab
** which is in database iDb. Return the register number for the register
** that holds the maximum rowid. Return zero if pTab is not an AUTOINCREMENT
** table. (Also return zero when doing a VACUUM since we do not want to
** update the AUTOINCREMENT counters during a VACUUM.)
**
** There is at most one AutoincInfo structure per table even if the
** same table is autoincremented multiple times due to inserts within
** triggers. A new AutoincInfo structure is created if this is the
** first use of table pTab. On 2nd and subsequent uses, the original
** AutoincInfo structure is used.
**
** Three memory locations are allocated:
**
** (1) Register to hold the name of the pTab table.
** (2) Register to hold the maximum ROWID of pTab.
** (3) Register to hold the rowid in sqlite_sequence of pTab
**
** The 2nd register is the one that is returned. That is all the
** insert routine needs to know about.
** Destroy a tokenizer allocated by unicodeCreate().
Releasing a reserved lock
************* End of resolve.c ********************************************
** Advance the cursor to the next row in the table.
The top of the parser's stack
Make sure the allocated memory does not assume that it is set to zero
** or retains a value from a previous allocation
197
defer MT decisions to system malloc
Appended to wal file
Size of list.aMemory allocation in bytes
If the cursor is not at EOF, read the next character
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
**
** This test control is used to create imposter tables. "db" is a pointer
** to the database connection. dbName is the database name (ex: "main" or
** "temp") which will receive the imposter. "onOff" turns imposter mode on
** or off. "tnum" is the root page of the b-tree to which the imposter
** table should connect.
**
** Enable imposter mode only when the schema has already been parsed. Then
** run a single CREATE TABLE statement to construct the imposter table in
** the parsed schema. Then turn imposter mode back off again.
**
** If onOff==0 and tnum>0 then reset the schema for all databases, causing
** the schema to be reparsed the next time it is needed. This has the
** effect of erasing all imposter tables.
Index within level of segment to modify
State variables used for validating that the transaction control
** methods of the virtual table are called at appropriate times. These
** values do not contribute to FTS functionality; they are used for
** verifying the operation of the SQLite core.
Required lock type (READ_LOCK or WRITE_LOCK)
Foreign key for which pTab is the child
SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
** never use proxy, NULL means use proxy for non-local files only.
comment:
** Generate code to construct the Index object for an automatic index
** and to set up the WhereLevel object pLevel so that the code generator
** makes use of the automatic index.
label: code-design
For the purposes of this routine, disable the mutex
See if we are dealing with a keyword.
True if vacuuming a :memory: database
** Compare the key in memory cell pVal with the key that the sorter cursor
** passed as the first argument currently points to. For the purposes of
** the comparison, ignore the rowid field at the end of each record.
**
** If the sorter cursor key contains any NULL values, consider it to be
** less than pVal. Even if pVal also contains NULL values.
**
** If an error occurs, return an SQLite error code (i.e. SQLITE_NOMEM).
** Otherwise, set *pRes to a negative, zero or positive value if the
** key in pVal is smaller than, equal to or larger than the current sorter
** key.
**
** This routine forms the core of the OP_SorterCompare opcode, which in
** turn is used to verify uniqueness when constructing a UNIQUE INDEX.
Create the statement to insert index entries
Index of term=? value in apVal
Max rowid register
xRollback - rollback transaction
Non-negative integer value if EP_IntValue
Comparison collation sequence
OUT: Rowid value
Commit by deleting journal file
** The database opened by the first argument is an auto-vacuum database
** nOrig pages in size containing nFree free pages. Return the expected
** size of the database in pages following an auto-vacuum operation.
** Find the appropriate action for a parser given the non-terminal
** look-ahead token iLookAhead.
Vector to extract element from
Cursor number for the sorter
Source-file line number of first opcode
** This routine is called to do the work of a DROP TABLE statement.
** pName is the name of the table to be dropped.
Mask of bits to set or clear.
Memory mapped region
Sorting and partial sorting costs
** Return the name of a directory in which to put temporary files.
** If no suitable temporary file directory can be found, return NULL.
Page size can no longer be changed
The location to move pDbPage to
** Here ends the implementation of all sqlite3_file methods.
**
********************** End sqlite3_file Methods *******************************
*****************************************************************************
Used to iterate through p->apValue[]
230
Must be element [2]
UNCOMPRESS
Mask of columns used by this cursor
The SQL to be executed
If pIdx is an index on one or more expressions, then look through
** all the expressions in pWInfo and try to transform matching expressions
** into reference to index columns.
If this is a rollback of a savepoint and data was not written to
** the database and the page is not in-memory, there is a potential
** problem. When the page is next fetched by the b-tree layer, it
** will be read from the database file, which may or may not be
** current.
**
** There are a couple of different ways this can happen. All are quite
** obscure. When running in synchronous mode, this can only happen
** if the page is on the free-list at the start of the transaction, then
** populated, then moved using sqlite3PagerMovepage().
**
** The solution is to add an in-memory page to the cache containing
** the data just read from the sub-journal. Mark the page as dirty
** and if the pager requires a journal-sync, then mark the page as
** requiring a journal-sync before it is written.
The cursor pointing to the table
comment: If the FULLFSYNC failed, fall back to attempting an fsync().
** It shouldn't be possible for fullfsync to fail on the local
** file system (on OSX), so failure indicates that FULLFSYNC
** isn't supported for this file system. So, attempt an fsync
** and (for now) ignore the overhead of a superfluous fcntl call.
** It'd be better to detect fullfsync support once and avoid
** the fcntl call every time sync is called.
label: code-design
The VDBE cursor for the index
If SQLite is already completely initialized, then this call
** to sqlite3_initialize() should be a no-op. But the initialization
** must be complete. So isInit must not be set until the very end
** of this routine.
Allocate the TriggerPrg and SubProgram objects. To ensure that they
** are freed if an error occurs, link them into the Parse.pTriggerPrg
** list of the top-level Parse object sooner rather than later.
** Buffer object for the incremental building of string data.
** 2006 June 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to dynamically load extensions into
** the SQLite library.
'!'. Part of !=
** Register a callback to be invoked each time a transaction is rolled
** back by this database connection.
** Append N copies of character c to the given string buffer.
** Transfer eligible terms from the HAVING clause of a query, which is
** processed after grouping, to the WHERE clause, which is processed before
** grouping. For example, the query:
**
** SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
**
** can be rewritten as:
**
** SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
**
** A term of the HAVING expression is eligible for transfer if it consists
** entirely of constants and expressions that are also GROUP BY terms that
** use the "BINARY" collation sequence.
If the bRetry flag is set, the change has not been applied due to an
** SQLITE_CHANGESET_DATA problem (i.e. this is an UPDATE or DELETE and
** a row with the correct PK is present in the db, but one or more other
** fields do not contain the expected values) and the conflict handler
** returned SQLITE_CHANGESET_REPLACE. In this case retry the operation,
** but pass NULL as the final argument so that sessionApplyOneOp() ignores
** the SQLITE_CHANGESET_DATA problem.
** Flush any data currently held in-memory to disk.
** Set the safety_level and pager flags for pager iDb. Or if iDb<0
** set these values for all pagers.
An FTS5_CONTENT value
15-18
** Find the largest relative level number in the table. If successful, set
** *pnMax to this value and return SQLITE_OK. Otherwise, if an error occurs,
** set *pnMax to zero and return an SQLite error code.
OUT: Malloc'd doclist
970
Number of characters in zCharSet
case_operand
** This function is used to read or overwrite payload information
** for the entry that the pCur cursor is pointing to. The eOp
** argument is interpreted as follows:
**
** 0: The operation is a read. Populate the overflow cache.
** 1: The operation is a write. Populate the overflow cache.
**
** A total of "amt" bytes are read or written beginning at "offset".
** Data is read to or from the buffer pBuf.
**
** The content being read or written might appear on the main page
** or be scattered out on multiple overflow pages.
**
** If the current cursor entry uses one or more overflow pages
** this function may allocate space for and lazily populate
** the overflow page-list cache array (BtCursor.aOverflow).
** Subsequent calls use this cache to make seeking to the supplied offset
** more efficient.
**
** Once an overflow page-list cache has been allocated, it must be
** invalidated if some other cursor writes to the same table, or if
** the cursor is moved to a different row. Additionally, in auto-vacuum
** mode, the following events may invalidate an overflow page-list cache.
**
** * An incremental vacuum,
** * A commit in auto_vacuum="full" mode,
** * Creating a table (may require moving an overflow page).
Increase the size of the aTo set by one
** Initialize the first page of the database file (creating a database
** consisting of a single page and no schema objects). Return SQLITE_OK
** if successful, or an SQLite error code otherwise.
** Invoke the xCommit method of all virtual tables in the
** sqlite3.aVTrans array. Then clear the array itself.
** Begin a read transaction on the WAL.
**
** This routine used to be called "pagerOpenSnapshot()" because it essentially
** makes a snapshot of the database at the current point in time and preserves
** that snapshot for use by the reader in spite of concurrently changes by
** other writers or checkpointers.
** This routine checks if there is a RESERVED lock held on the specified
** file by this or any other process. If such a lock is held, set *pResOut
** to a non-zero value otherwise *pResOut is set to zero. The return value
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
**
** In dotfile locking, either a lock exists or it does not. So in this
** variation of CheckReservedLock(), *pResOut is set to true if any lock
** is held on the file and false if the file is unlocked.
** Possible error returns from patternMatch()
$ => nothing
BEGIN => ID
Quasi-random value added to every checksum
Internal-use-only converters allowed
222
P5 value for OP_Column + FLAGS
pScratch
Register for RowSet object
SQLITE_OS_WIN
Previous rowid written to current leaf
same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1]
SELECT statement from sessionSelectRow()
Bitmask of all WhereLoop objects in this path
If the allocation succeeded, populate the new object.
Level to merge
SQLITE_OMIT_INTEGRITY_CHECK
Record changes in the file format
sqlite3VdbeSetColName() installs column names as UTF8
** strings so there is no way for sqlite3_column_name() to fail.
Mem.z points to a static string
Fill in the azColumn array
Number of columns in the data
68
** This routine is used to allocate sufficient space for an UnpackedRecord
** structure large enough to be used with sqlite3VdbeRecordUnpack() if
** the first argument is a pointer to KeyInfo structure pKeyInfo.
**
** The space is either allocated using sqlite3DbMallocRaw() or from within
** the unaligned buffer passed via the second and third arguments (presumably
** stack space). If the former, then *ppFree is set to a pointer that should
** be eventually freed by the caller using sqlite3DbFree(). Or, if the
** allocation comes from the pSpace/szSpace buffer, *ppFree is set to NULL
** before returning.
**
** If an OOM error occurs, NULL is returned.
99
Verify that the cursor and the BtShared agree about what is the current
** database connetion. This is important in shared-cache mode. If the database
** connection pointers get out-of-sync, it is possible for routines like
** btreeInitPage() to reference an stale connection pointer that references a
** a connection that has already closed. This routine is used inside assert()
** statements only and for the purpose of double-checking that the btree code
** does keep the database connection pointers up-to-date.
** Cause any pending operation to stop at its earliest opportunity.
Current merge state (see above)
Pointer to hash table
5
Offset of this term from read positions
Matched CTE (or NULL if no match)
** The idea is that this function works like a combination of
** GetLastError() and FormatMessage() on Windows (or errno and
** strerror_r() on Unix). After an error is returned by an OS
** function, SQLite calls this function with zBuf pointing to
** a buffer of nBuf bytes. The OS layer should populate the
** buffer with a nul-terminated UTF-8 encoded error message
** describing the last IO error to have occurred within the calling
** thread.
**
** If the error message is too large for the supplied buffer,
** it should be truncated. The return value of xGetLastError
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated). If non-zero is returned,
** then it is not necessary to include the nul-terminator character
** in the output buffer.
**
** Not supplying an error message will have no adverse effect
** on SQLite. It is fine to have an implementation that never
** returns an error message:
**
** int xGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
** assert(zBuf[0]=='\0');
** return 0;
** }
**
** However if an error message is supplied, it will be incorporated
** by sqlite into the error message available to the user using
** sqlite3_errmsg(), possibly making IO errors easier to debug.
Virtual tables with open transactions
************* Begin file ctime.c ******************************************
** Set the pointer-map entries for all children of page pPage. Also, if
** pPage contains cells that point to overflow pages, set the pointer
** map entries for the overflow pages as well.
** Sync the file.
**
** If the real file has been created, call its xSync method. Otherwise,
** syncing an in-memory journal is a no-op.
** Defer sourcing vdbe.h and btree.h until after the "u8" and
** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
** pointer types (i.e. FuncDef) defined above.
The real implementation of xFetch and xUnfetch
Get the column number in the table (iColumn) and sort order
** (revIdx) for the j-th column of the index.
there was a collision, check to see if it's already
** This routine is called on a collation sequence before it is used to
** check that it is defined. An undefined collation sequence exists when
** a database is loaded that contains references to collation sequences
** that have not been defined by sqlite3_create_collation() etc.
**
** If required, this routine calls the 'collation needed' callback to
** request a definition of the collating sequence. If this doesn't work,
** an equivalent collating sequence that uses a text encoding different
** from the main database is substituted, if one is available.
comment: An error occurred. Delete the contents of the apLeaf[] array
** and pFree list. Everything else is cleaned up by the call to
** sqlite3Fts3ExprFree(pRoot) below.
label: code-design
comment:
** CAPI3REF: Tracing And Profiling Functions
** METHOD: sqlite3
**
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
** instead of the routines described here.
**
** These routines register callback functions that can be used for
** tracing and profiling the execution of SQL statements.
**
** ^The callback function registered by sqlite3_trace() is invoked at
** various times when an SQL statement is being run by [sqlite3_step()].
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
** SQL statement text as the statement first begins executing.
** ^(Additional sqlite3_trace() callbacks might occur
** as each triggered subprogram is entered. The callbacks for triggers
** contain a UTF-8 SQL comment that identifies the trigger.)^
**
** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
** the length of [bound parameter] expansion in the output of sqlite3_trace().
**
** ^The callback function registered by sqlite3_profile() is invoked
** as each SQL statement finishes. ^The profile callback contains
** the original statement text and an estimate of wall-clock time
** of how long that statement took to run. ^The profile callback
** time is in units of nanoseconds, however the current implementation
** is only capable of millisecond resolution so the six least significant
** digits in the time are meaningless. Future versions of SQLite
** might provide greater resolution on the profiler callback. The
** sqlite3_profile() function is considered experimental and is
** subject to change in future versions of SQLite.
label: code-design
Number of def. constraints when stmt started
Max page number of 2147483648
jump: P2 holds jmp target
The integer values
Write output here
Depth of the tree so far
243
ROWID of most recent insert (see above)
** Based on the contents of the AggInfo structure indicated by the first
** argument, this function checks if the following are true:
**
** * the query contains just a single aggregate function,
** * the aggregate function is either min() or max(), and
** * the argument to the aggregate function is a column value.
**
** If all of the above are true, then WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX
** is returned as appropriate. Also, *ppMinMax is set to point to the
** list of arguments passed to the aggregate before returning.
**
** Or, if the conditions above are not met, *ppMinMax is set to 0 and
** WHERE_ORDERBY_NORMAL is returned.
** Merge the doclist aDoclist/nDoclist into the TermSelect object passed
** as the first argument. The merge is an "OR" merge (see function
** fts3DoclistOrMerge() for details).
**
** This function is called with the doclist for each term that matches
** a queried prefix. It merges all these doclists into one, the doclist
** for the specified prefix. Since there can be a very large number of
** doclists to merge, the merging is done pair-wise using the TermSelect
** object.
**
** This function returns SQLITE_OK if the merge is successful, or an
** SQLite error code (SQLITE_NOMEM) if an error occurs.
star_opt ::= STAR
The value list on the RHS of "x IN (v1,v2,v3,...)"
************* Include rtree.h in the middle of main.c *********************
** Compare two UTF-8 strings for equality where the first string is
** a "LIKE" expression. Return true (1) if they are the same and
** false (0) if they are different.
Test if comparison i of pTerm is compatible with column (i+nEq)
** of the index. If not, exit the loop.
** This function is called when
** the transaction opened by database db has just finished. Locks held
** by database connection db have been released.
**
** This function loops through each entry in the blocked connections
** list and does the following:
**
** 1) If the sqlite3.pBlockingConnection member of a list entry is
** set to db, then set pBlockingConnection=0.
**
** 2) If the sqlite3.pUnlockConnection member of a list entry is
** set to db, then invoke the configured unlock-notify callback and
** set pUnlockConnection=0.
**
** 3) If the two steps above mean that pBlockingConnection==0 and
** pUnlockConnection==0, remove the entry from the blocked connections
** list.
123456789 123456
PRAGMA => ID
** Set output variable *ppStmt to point to an UPDATE statement that may
** be used to update the imposter table for the main table b-tree of the
** table object that pIter currently points to, assuming that the
** rbu_control column of the data_xyz table contains zMask.
**
** If the zMask string does not specify any columns to update, then this
** is not an error. Output variable *ppStmt is set to NULL in this case.
size of the BLOB
synopsis: r[P2]=cursor[P1].ctr++
Hash table of connection functions
** The common case is for a varint to be a single byte. They following
** macros handle the common case without a procedure call, but then call
** the procedure for larger varints.
** All current savepoints are stored in a linked list starting at
** sqlite3.pSavepoint. The first element in the list is the most recently
** opened savepoint. Savepoints are added to the list by the vdbe
** OP_Savepoint instruction.
Rows less than the upper bound
Output the single row in Current
Need to reorder the LHS fields according to aiMap
ON CONFLICT policy
** A write-transaction must be opened before calling this function.
** It performs a single unit of work towards an incremental vacuum.
**
** If the incremental vacuum is finished after this function has run,
** SQLITE_DONE is returned. If it is not finished, but no error occurred,
** SQLITE_OK is returned. Otherwise an SQLite error code.
OK to return IN_INDEX_NOOP
Name of the table into which we are inserting
Generate code to remove the table from the master table
** on disk.
The inner query or "subquery"
Scan definitions for sqlite3_stmt_scanstatus()
** Move the iterator to the next entry.
**
** If an error occurs, an error code is left in Fts5Index.rc. It is not
** considered an error if the iterator reaches EOF, or if it is already at
** EOF when this function is called.
************* End of vdbeblob.c *******************************************
Find the lowest cost path. pFrom will be left pointing to that path
** CAPI3REF: Commit And Rollback Notification Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_commit_hook() interface registers a callback
** function to be invoked whenever a transaction is [COMMIT | committed].
** ^Any callback set by a previous call to sqlite3_commit_hook()
** for the same database connection is overridden.
** ^The sqlite3_rollback_hook() interface registers a callback
** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
** ^Any callback set by a previous call to sqlite3_rollback_hook()
** for the same database connection is overridden.
** ^The pArg argument is passed through to the callback.
** ^If the callback on a commit hook function returns non-zero,
** then the commit is converted into a rollback.
**
** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
** return the P argument from the previous call of the same function
** on the same [database connection] D, or NULL for
** the first call for each function on D.
**
** The commit and rollback hook callbacks are not reentrant.
** The callback implementation must not do anything that will modify
** the database connection that invoked the callback. Any actions
** to modify the database connection must be deferred until after the
** completion of the [sqlite3_step()] call that triggered the commit
** or rollback hook in the first place.
** Note that running any other SQL statements, including SELECT statements,
** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
** the database connections for the meaning of "modify" in this paragraph.
**
** ^Registering a NULL function disables the callback.
**
** ^When the commit hook callback routine returns zero, the [COMMIT]
** operation is allowed to continue normally. ^If the commit hook
** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
** ^The rollback hook is invoked on a rollback that results from a commit
** hook returning non-zero, just as it would be with any other rollback.
**
** ^For the purposes of this API, a transaction is said to have been
** rolled back if an explicit "ROLLBACK" statement is executed, or
** an error or constraint causes an implicit rollback to occur.
** ^The rollback callback is not invoked if a transaction is
** automatically rolled back because the database connection is closed.
**
** See also the [sqlite3_update_hook()] interface.
0x18
SQL_SELECT_MXLEVEL
** Return the largest relative level in the FTS index or indexes.
Reduction in fragmentation
Pointer to term buffer
Base class. Must be first. pBuf & pExtra
Results stored in register inReg
Modify the page-size after the cache has been created.
** 2012 July 21
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file presents a simple cross-platform threading interface for
** use internally by SQLite.
**
** A "thread" can be created using sqlite3ThreadCreate(). This thread
** runs independently of its creator until it is joined using
** sqlite3ThreadJoin(), at which point it terminates.
**
** Threads do not have to be real. It could be that the work of the
** "thread" is done by the main thread at either the sqlite3ThreadCreate()
** or sqlite3ThreadJoin() call. This is, in fact, what happens in
** single threaded systems. Nothing in SQLite requires multiple threads.
** This interface exists so that applications that want to take advantage
** of multiple cores can do so, while also allowing applications to stay
** single-threaded if desired.
The FROM clause of the outer query
0 normally. Positive == commit flag
** Encode N integers as varints into a blob.
Opcode: Remainder P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]%r[P1]
**
** Compute the remainder after integer register P2 is divided by
** register P1 and store the result in register P3.
** If the value in register P1 is zero the result is NULL.
** If either operand is NULL, the result is NULL.
comment:
** 2007 August 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains low-level memory allocation drivers for when
** SQLite will use the standard C-library malloc/realloc/free interface
** to obtain the memory it needs while adding lots of additional debugging
** information to each allocation in order to help detect and fix memory
** leaks and memory usage errors.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
label: code-design
XOR next input into a[i]
Slots needed in p->azResult[]
Extra dependencies on LEFT JOIN
This OP_Insert is an sql UPDATE
1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX
End the database scan loop.
** Forward reference required as the vdbeIncrMergeInit() and
** vdbePmaReaderIncrInit() routines are called mutually recursively when
** building a merge tree.
** When doing a search of an r-tree, instances of the following structure
** record intermediate results from the tree walk.
**
** The id is always a node-id. For iLevel>=1 the id is the node-id of
** the node that the RtreeSearchPoint represents. When iLevel==0, however,
** the id is of the parent node and the cell that RtreeSearchPoint
** represents is the iCell-th entry in the parent node.
callback can use this, if desired
** 2007 May 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: icu.c,v 1.7 2007/12/13 21:54:11 drh Exp $
**
** This file implements an integration between the ICU library
** ("International Components for Unicode", an open-source library
** for handling unicode data) and SQLite. The integration uses
** ICU to provide the following to SQLite:
**
** * An implementation of the SQL regexp() function (and hence REGEXP
** operator) using the ICU uregex_XX() APIs.
**
** * Implementations of the SQL scalar upper() and lower() functions
** for case mapping.
**
** * Integration of ICU and SQLite collation sequences.
**
** * An implementation of the LIKE operator that uses ICU to
** provide case-independent matching.
Add the page to the PGroup LRU list.
No digits
** Remove entries from the hash table that point to WAL slots greater
** than pWal->hdr.mxFrame.
**
** This function is called whenever pWal->hdr.mxFrame is decreased due
** to a rollback or savepoint.
**
** At most only the hash table containing pWal->hdr.mxFrame needs to be
** updated. Any later hash tables will be automatically cleared when
** pWal->hdr.mxFrame advances to the point where those hash tables are
** actually needed.
Write search results here
If the update-hook or pre-update-hook will be invoked, set zDb to
** the name of the db to pass as to it. Also set local pTab to a copy
** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
** VdbeCursor.movetoTarget to the current rowid.
** Return true if the page is already in the journal file.
FTS5_STRING node this phrase is part of
Length of string argv[2]
** All code in this file should access the global structure above via the
** alias "pcache1". This ensures that the WSD emulation is used when
** compiling for systems that do not support real WSD.
** If any data has been written (but not committed) to the log file, this
** function moves the write-pointer back to the start of the transaction.
**
** Additionally, the callback function is invoked for each frame written
** to the WAL since the start of the transaction. If the callback returns
** other than SQLITE_OK, it is not invoked again and the error code is
** returned to the caller.
**
** Otherwise, if the callback function does not return an error, this
** function returns SQLITE_OK.
We only need to generate a select expression if there
** is a limit/offset term to enforce.
** Free the pBt->pTmpSpace allocation
EQ seeks only - no range seeks
Sorter cursor
The methods of the json_tree virtual table.
Lower bound on the range. ex: "x>123" Might be NULL
Length of the name
Where clause to locate temp triggers
** The following routines are implementations of the MemPage.xCellSize
** method.
**
** Compute the total number of bytes that a Cell needs in the cell
** data area of the btree-page. The return number includes the cell
** data header and the local payload, but not any overflow page or
** the space used by the cell pointer.
**
** cellSizePtrNoPayload() => table internal nodes
** cellSizePtr() => all index nodes & table leaf nodes
Set the variable isMemdb to true for an in-memory database, or
** false for a file-based database.
ON clause terms may not be used with an index
** on left table of a LEFT JOIN. Ticket #3015
file handle
Checksum used for sanity checking
Used to iterate through attached tables
See comment below
A table in the database is locked
Database filename (UTF-8)
0x1a
pTask->list.aMemory can only be non-zero if it was handed memory
** from the main thread. That only occurs SQLITE_MAX_WORKER_THREADS>0
** Insert a record into the %_docsize table. Specifically, do:
**
** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
**
** If there is no %_docsize table (as happens if the columnsize=0 option
** is specified when the FTS5 table is created), this function is a no-op.
** Check to ensure that the cursor is valid. Restore the cursor
** if need be. Return any I/O error from the restore operation.
The current column index in pp2
Flags passed through to the VFS
Used by: table_info
Length of the zJson string in bytes
** An rbu VFS is implemented using an instance of this structure.
Decoded coordinates
comment:
** The VdbeCoverage macros are used to set a coverage testing point
** for VDBE branch instructions. The coverage testing points are line
** numbers in the sqlite3.c source file. VDBE branch coverage testing
** only works with an amalagmation build. That's ok since a VDBE branch
** coverage build designed for testing the test suite only. No application
** should ever ship with VDBE branch coverage measuring turned on.
**
** VdbeCoverage(v) // Mark the previously coded instruction
** // as a branch
**
** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
**
** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
**
** VdbeCoverageNeverTaken(v) // Previous branch is never taken
**
** Every VDBE branch operation must be tagged with one of the macros above.
** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
** routine in vdbe.c, alerting the developer to the missed tag.
label: test
HAVE_LOCALTIME_R
SQLITE_IGNORE_AFP_LOCK_ERRORS
Patch with JsonNode.u.pPatch
If this is the first row, then generate an extra row containing
** the names of all columns.
Buffer used to hold a poslist
Database connection currently using this Btree
Counters used by sqlite3_stmt_status()
Check if the output file is full or if the input has been exhausted.
** In either case exit the loop.
comment:
** pExpr points to an expression which implements a function. If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and
** return TRUE. If the function is not a LIKE-style function then
** return FALSE.
**
** *pIsNocase is set to true if uppercase and lowercase are equivalent for
** the function (default for LIKE). If the function makes the distinction
** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
** false.
label: code-design
The database size was written into the offset 28 of the header
** when the transaction started, so we know that the value at offset
** 28 is nonzero.
Size of array aParam[]
0x0b
comment: *********************************************************************
** Elements above, except pCache, are public. All that follow are
** private to pcache.c and should not be accessed by other modules.
** pCache is grouped with the public elements for efficiency.
label: code-design
279
ORDER BY of joins via index
(290) typename ::= ID|STRING
Database pages read
Coordinate value convert to a double
Expr struct EXPR_TOKENONLYSIZE bytes only
The 2-byte case
** The xConnect() and xCreate() methods for the virtual table. All the
** work is done in function fts3InitVtab().
** Integers of known sizes. These typedefs might change for architectures
** where the sizes very. Preprocessor macros are available so that the
** types can be conveniently redefined at compile-type. Like this:
**
** cc '-DUINTPTR_TYPE=long long int' ...
comment:
** Execute SQL code. Return one of the SQLITE_ success/failure
** codes. Also write an error message into memory obtained from
** malloc() and make *pzErrMsg point to that message.
**
** If the SQL is a query, then for each row in the query result
** the xCallback() function is called. pArg becomes the first
** argument to xCallback(). If xCallback=NULL then no callback
** is invoked, even for queries.
label: code-design
we can skip these cause they were (effectively) done above
** while calculating s
Record pRec is equal to sample i
SQLITE_OMIT_SCHEMA_PRAGMAS
PRIMARY KEY array
** This constant determines the maximum depth of an FTS expression tree
** that the library will create and use. FTS uses recursion to perform
** various operations on the query tree, so the disadvantage of a large
** limit is that it may allow very large queries to use large amounts
** of stack space (perhaps causing a stack overflow).
** This function is called while writing an FTS segment each time a leaf o
** node is finished and written to disk. The key (zTerm/nTerm) is guaranteed
** to be greater than the largest key on the node just written, but smaller
** than or equal to the first key that will be written to the next leaf
** node.
**
** The block id of the leaf node just written to disk may be found in
** (pWriter->aNodeWriter[0].iBlock) when this function is called.
comment: Here is inserted the actions which take place when a
** terminal or non-terminal is destroyed. This can happen
** when the symbol is popped from the stack during a
** reduce or during error processing or when a parser is
** being destroyed before it is finished parsing.
**
** Note: during a reduce, the only symbols destroyed are those
** which appear on the RHS of the rule, but which are *not* used
** inside the C code.
label: code-design
The expression that defines the start bound
283
** Unlink a VFS from the linked list
First argument to compare function
************* End of fts3_tokenizer1.c ************************************
The cursor number for the corresponding table
Bytes of reserved space at the end of each page
If no database changes have been made, return early.
create_table ::= createkw temp TABLE ifnotexists nm dbnm
Index of VdbeCursor that writes the sqlite_stat1 table
** Default permissions when creating auto proxy dir
"idx" or "tbl"
** Break the OR clause into its separate subterms. The subterms are
** stored in a WhereClause structure containing within the WhereOrInfo
** object that is attached to the original OR clause term.
comment:
** Type SegmentNode is used by the following three functions to create
** the interior part of the segment b+-tree structures (everything except
** the leaf nodes). These functions and type are only ever used by code
** within the fts3SegWriterXXX() family of functions described above.
**
** fts3NodeAddTerm()
** fts3NodeWrite()
** fts3NodeFree()
**
** When a b+tree is written to the database (either as a result of a merge
** or the pending-terms table being flushed), leaves are written into the
** database file as soon as they are completely populated. The interior of
** the tree is assembled in memory and written out only once all leaves have
** been populated and stored. This is Ok, as the b+-tree fanout is usually
** very large, meaning that the interior of the tree consumes relatively
** little memory.
label: code-design
Which column of pTab is desired
OUT: Space to write result to
The prepared statement under construction
Cache is valid if this matches Vdbe.cacheCtr
Type of checkpoint
Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
** on a table.
Always instruction 0
** Make a new pointer to a KeyInfo object
ERROR: insert command gives an output larger than predicted
Invoke the xBegin method. If successful, add the vtab to the
** sqlite3.aVTrans[] array.
** An instance of the following data structure is used to build doclists
** incrementally. See function fts3PendingListAppend() for details.
The FROM clause of the recursive query
Special case of a FROM clause subquery implemented as a co-routine
Check that MEMDB implies noSync. And an in-memory journal. Since
** this means an in-memory pager performs no IO at all, it cannot encounter
** either SQLITE_IOERR or SQLITE_FULL during rollback or while finalizing
** a journal file. (although the in-memory journal implementation may
** return SQLITE_IOERR_NOMEM while the journal file is being written). It
** is therefore not possible for an in-memory pager to enter the ERROR
** state.
(292) signed ::= minus_num (OPTIMIZED OUT)
Offset to the page header
If the WAL is not empty, return the size of the database.
** Allocate a new RowSetEntry object that is associated with the
** given RowSet. Return a pointer to the new and completely uninitialized
** objected.
**
** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
** routine returns NULL.
Move existing slots that come after the newly inserted slots
** out of the way
Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW.
If the bPreserve flag is set to true, then the memory cell must already
** contain a valid string or blob value.
Start scanning the virtual table
Node must have already been started. There must be a doclist for a
** leaf node, and there must not be a doclist for an internal node.
** Create a new FTS5 expression by cloning phrase iPhrase of the
** expression passed as the second argument.
comment: Clean up and return
label: code-design
Database size before freeing
EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
** immediately follows the b-tree page header.
Start a write transaction on these databases
Playback and delete the journal. Drop the database write
** lock and reacquire the read lock. Purge the cache before
** playing back the hot-journal so that we don't end up with
** an inconsistent cache. Sync the hot journal before playing
** it back since the process that crashed and left the hot journal
** probably did not sync it and we are required to always sync
** the journal before playing it back.
Where to start scanning
If the calls to xBestIndex() have so far failed to find a plan
** that requires no source tables at all and does not use an IN(...)
** operator, make a final call to obtain one here.
Number of NULL aLTerm[] entries
Ephemeral. Delete with VDBE
Name of db (i.e. "main", "temp" etc.)
trigger_cmd ::= DELETE FROM trnm tridxby where_opt
Position list data following iTail
Number instances seen so far
** Global variables.
Default value of this column
comment: Column names are determined by the left-most term of a compound select
label: code-design
** Unbind the value bound to variable i in virtual machine p. This is the
** the same as binding a NULL value to the column. If the "i" parameter is
** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
**
** A successful evaluation of this routine acquires the mutex on p.
** the mutex is released if any kind of error occurs.
**
** The error code stored in database p->db is overwritten with the return
** value in any case.
** This function is called by the wal module when writing page content
** into the log file.
**
** This function returns a pointer to a buffer containing the encrypted
** page content. If a malloc fails, this function may return NULL.
6,7,8
** Call sqlite3_declare_vtab() based on the contents of the configuration
** object passed as the only argument. Return SQLITE_OK if successful, or
** an SQLite error code if an error occurs.
Number of retries
mxParserStack
Initialize the 4-byte leaf-page header to 0x00.
Figure out which index to search and set iIdx accordingly. If this
** is a prefix query for which there is no prefix index, set iIdx to
** greater than pConfig->nPrefix to indicate that the query will be
** satisfied by scanning multiple terms in the main index.
**
** If the QUERY_TEST_NOIDX flag was specified, then this must be a
** prefix-query. Instead of using a prefix-index (if one exists),
** evaluate the prefix query using the main FTS index. This is used
** for internal sanity checking by the integrity-check in debug
** mode only.
True if cache must be reset
Second key value passed to hook
Count the number of additional columns needed to create a
** covering index. A "covering index" is an index that contains all
** columns that are needed by the query. With a covering index, the
** original table never needs to be accessed. Automatic indices must
** be a covering index because the index will not be updated if the
** original table changes and the index and table cannot both be used
** if they go out of sync.
** Main sorter structure. A single instance of this is allocated for each
** sorter cursor created by the VDBE.
**
** mxKeysize:
** As records are added to the sorter by calls to sqlite3VdbeSorterWrite(),
** this variable is updated so as to be set to the size on disk of the
** largest record in the sorter.
endif aggregate query
Coordinates of node or entry to check
265
** Set *pnMax to the largest segment level in the database for the index
** iIndex.
**
** Segment levels are stored in the 'level' column of the %_segdir table.
**
** Return SQLITE_OK if successful, or an SQLite error code if not.
Unmap the database file. It is possible that external processes
** may have truncated the database file and then extended it back
** to its original size while this process was not holding a lock.
** In this case there may exist a Pager.pMap mapping that appears
** to be the right size but is not actually valid. Avoid this
** possibility by unmapping the db here.
The output line number is small enough that we are still in the
** main program.
** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
**
** This action provides a run-time test to see how the ALWAYS and
** NEVER macros were defined at compile-time.
**
** The return value is ALWAYS(X).
**
** The recommended test is X==2. If the return value is 2, that means
** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
** default setting. If the return value is 1, then ALWAYS() is either
** hard-coded to true or else it asserts if its argument is false.
** The first behavior (hard-coded to true) is the case if
** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
** behavior (assert if the argument to ALWAYS() is false) is the case if
** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
**
** The run-time test procedure might look something like this:
**
** if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
** // ALWAYS() and NEVER() are no-op pass-through macros
** }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
** // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
** }else{
** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
** }
Root BTree page for this table
Offset to the start of the cell pointer array
SELECT statement to encode
** The input pointer currently points to the first byte of the first field
** of a record consisting of nCol columns. This function ensures the entire
** record is buffered. It does not move the input pointer.
**
** If successful, SQLITE_OK is returned and *pnByte is set to the size of
** the record in bytes. Otherwise, an SQLite error code is returned. The
** final value of *pnByte is undefined in this case.
True if ok to populate
The unix errno from last I/O error
** x BETWEEN y AND z
**
** This is equivalent to
**
** x>=y AND x<=z
**
** X is stored in pExpr->pLeft.
** Y is stored in pExpr->pList->a[0].pExpr.
** Z is stored in pExpr->pList->a[1].pExpr.
The column that is wanted
sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
**
** If zWord is a keyword recognized by the parser, then return the
** number of keywords. Or if zWord is not a keyword, return 0.
**
** This test feature is only available in the amalgamation since
** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
** is built using separate source files.
Number of registers to allocate
comment: Initialized only to suppress erroneous warning from Clang
label: code-design
** Parse a timezone extension on the end of a date-time.
** The extension is of the form:
**
** (+/-)HH:MM
**
** Or the "zulu" notation:
**
** Z
**
** If the parse is successful, write the number of minutes
** of change in p->tz and return 0. If a parser error occurs,
** return non-zero.
**
** A missing specifier is not considered an error.
Output values used by 'row' and 'col' tables
Rowid changed in a normal table
comment: Cursor for the index, if pIdx!=0. Unused otherwise
label: code-design
comment: Case 4: A scan using an index.
**
** The WHERE clause may contain zero or more equality
** terms ("==" or "IN" operators) that refer to the N
** left-most columns of the index. It may also contain
** inequality constraints (>, <, >= or <=) on the indexed
** column that immediately follows the N equalities. Only
** the right-most column can be an inequality - the rest must
** use the "==" and "IN" operators. For example, if the
** index is on (x,y,z), then the following clauses are all
** optimized:
**
** x=5
** x=5 AND y=10
** x=5 AND y<10
** x=5 AND y>5 AND y<10
** x=5 AND y=5 AND z<=10
**
** The z<10 term of the following cannot be used, only
** the x=5 term:
**
** x=5 AND z<10
**
** N may be zero if there are inequality constraints.
** If there are no inequality constraints, then N is at
** least one.
**
** This case is also used when there are no WHERE clause
** constraints but an index is selected anyway, in order
** to force the output order to conform to an ORDER BY.
label: code-design
Encoding for the data
If this is an INSERT or UPDATE, read the new.* record.
OP_Found will use a composite key
Iterator error code
The various pragma types
0xff means setting unknown
If opening the main database, set ENC(db).
Special handling for a compound-select that originates as a VALUES clause.
** Create an Fts5Iter that iterates through the doclist provided
** as the second argument.
** Called by the parser to compile an ATTACH statement.
**
** ATTACH p AS pDbname KEY pKey
** Return the file handle for the journal file (if it exists).
** This will be either the rollback journal or the WAL file.
The base for radix conversion
157
same as TK_EQ, synopsis: IF r[P3]==r[P1]
** 2009 January 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_backup_XXX()
** API functions and the related features.
P1==1 for end-of-loop
Confirm that aiMap[] contains nVector integer values between 0 and
** nVector-1.
Append a comma separator to the output buffer, if the previous
** character is not '[' or '{'.
0x1b
List of indexed columns
ALWAYS() justification: eOp is an equality operator due to the
** j<pLoop->u.btree.nEq constraint above. Any equality other
** than WO_IN is captured by the previous "if". So this one
** always has to be WO_IN.
end Loop over all index columns
** Get a page from the pager. Initialize the MemPage.pBt and
** MemPage.aData elements if needed. See also: btreeGetUnusedPage().
**
** If the PAGER_GET_NOCONTENT flag is set, it means that we do not care
** about the content of the page at this time. So do not go to the disk
** to fetch the content. Just fill in the content with zeros for now.
** If in the future we call sqlite3PagerWrite() on this page, that
** means we have started to be concerned about content and the disk
** read should occur at that point.
** Available fault injectors. Should be numbered beginning with 0.
Size of record header in bytes
ORDERBY+LIMIT on the inner loop
Name of variables
.n =
17
Logarithm of table size
True if trailing zeros should be removed
The wal-index is divided into pages of WALINDEX_PGSZ bytes each.
Number of XOR operations done
The table does not exist.
Used when p4type is P4_KEYINFO
Assuming no error has occurred, run a "restart" checkpoint with the
** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
** special behaviour in the rbu VFS:
**
** * If the exclusive shm WRITER or READ0 lock cannot be obtained,
** the checkpoint fails with SQLITE_BUSY (normally SQLite would
** proceed with running a passive checkpoint instead of failing).
**
** * Attempts to read from the *-wal file or write to the database file
** do not perform any IO. Instead, the frame/page combinations that
** would be read/written are recorded in the sqlite3rbu.aFrame[]
** array.
**
** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
** READ0 and CHECKPOINT locks taken as part of the checkpoint are
** no-ops. These locks will not be released until the connection
** is closed.
**
** * Attempting to xSync() the database file causes an SQLITE_INTERNAL
** error.
**
** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
** checkpoint below fails with SQLITE_INTERNAL, and leaves the aFrame[]
** array populated with a set of (frame -> page) mappings. Because the
** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
** data from the wal file into the database file according to the
** contents of aFrame[].
Set to zero if any values are modified
Opcode: ReadCookie P1 P2 P3 * *
**
** Read cookie number P3 from database P1 and write it into register P2.
** P3==1 is the schema version. P3==2 is the database format.
** P3==3 is the recommended pager cache size, and so forth. P1==0 is
** the main database file and P1==1 is the database file used to store
** temporary tables.
**
** There must be a read-lock on the database (either a transaction
** must be started or there must be an open cursor) before
** executing this instruction.
** If the most recently coded instruction is a constant range constraint
** (a string literal) that originated from the LIKE optimization, then
** set P3 and P5 on the OP_String opcode so that the string will be cast
** to a BLOB at appropriate times.
**
** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
** expression: "x>='ABC' AND x<'abd'". But this requires that the range
** scan loop run twice, once for strings and a second time for BLOBs.
** The OP_String opcodes on the second pass convert the upper and lower
** bound string constants to blobs. This routine makes the necessary changes
** to the OP_String opcodes for that to happen.
**
** Except, of course, if SQLITE_LIKE_DOESNT_MATCH_BLOBS is defined, then
** only the one pass through the string space is required, so this routine
** becomes a no-op.
Cursor used for index scans (if any)
Size of apPhrase array
The above might be initialized to non-zero. The following need to always
** initially be zero, however.
** Append a rowid and position-list size field to the writers output.
Test if fcntl() is supported and use POSIX style locks.
** Otherwise fall back to the named semaphore method.
840
Register holding the offset counter
comment: If [0] is unused then [1] is also unused. So we can
** always safely abort as soon as the first unused slot is found
label: code-design
Next free argvIndex value
Full-text table
selectnowith
Connection handle
The 1-byte case. Overwhelmingly the most common.
Pointer to buffer containing changeset A
ONEPASS defaults to OFF
Encoding of z. 0 for BLOBs
defined(SQLITE_USE_MALLOC_H)
True if db currently has pBt locked
comment: LIMIT expression. NULL means not used.
label: code-design
** Read the next nByte bytes of data from the PMA p.
** If successful, set *ppOut to point to a buffer containing the data
** and return SQLITE_OK. Otherwise, if an error occurs, return an SQLite
** error code.
**
** The buffer returned in *ppOut is only valid until the
** next call to this function.
** The argument to this macro is a file descriptor (type sqlite3_file*).
** Return 0 if it is not open, or non-zero (but not 1) if it is.
**
** This is so that expressions can be written as:
**
** if( isOpen(pPager->jfd) ){ ...
**
** instead of
**
** if( pPager->jfd->pMethods ){ ...
Mark the expression is being from the ON or USING clause of a join
** so that the sqlite3ExprCodeTarget() routine will not attempt to move
** it into the Parse.pConstExpr list. We should use a new bit for this,
** for clarity, but we are out of bits in the Expr.flags field so we
** have to reuse the EP_FromJoin bit. Bummer.
The current schema
** Memory cell pMem contains the context of an aggregate function.
** This routine calls the finalize method for that function. The
** result of the aggregate is stored back into pMem.
**
** Return SQLITE_ERROR if the finalizer reports an error. SQLITE_OK
** otherwise.
Figure out if we have any triggers and if the table being
** inserted into is a view
Integer value if p4type==P4_INT32
Address of the A>B subroutine
Flags allowed as part of the 4th argument to SegmentReaderIterate()
SQLITE_IOERR
LIKE opt constraints
If the column value is a string, we need a persistent value, not
** a MEM_Ephem value. This branch is a fast short-cut that is equivalent
** to calling sqlite3VdbeSerialGet() and sqlite3VdbeDeephemeralize().
Release/Acquire the system-level lock
An unrecognized directive. Return an error message.
Function to possibly overload
If pFree is not NULL, it points to the pSpace buffer used
** by a previous call to balance_nonroot(). Its contents are
** now stored either on real database pages or within the
** new pSpace buffer, so it may be safely freed here.
A negative nCol is a special marker meaning that we are currently
** trying to compute the column names. If we enter this routine with
** a negative nCol, it means two or more views form a loop, like this:
**
** CREATE VIEW one AS SELECT * FROM two;
** CREATE VIEW two AS SELECT * FROM one;
**
** Actually, the error above is now caught prior to reaching this point.
** But the following test is still important as it does come up
** in the following:
**
** CREATE TABLE main.ex1(a);
** CREATE TEMP VIEW ex1 AS SELECT a FROM ex1;
** SELECT * FROM temp.ex1;
Segment id to load from
If the target table column is an "INTEGER PRIMARY KEY", add
** "PRIMARY KEY" to the imposter table column declaration.
same as TK_GE, synopsis: IF r[P3]>=r[P1]
SQLITE_OS_WIN_H
comment: The P4 parameter is not used
label: code-design
** Append a DELETE change to the buffer passed as the first argument. Use
** the changeset format if argument bPatchset is zero, or the patchset
** format otherwise.
Remove the FK from the fkeyHash hash table.
The first in an array of registers (see above)
** Compute the parentage of all nodes in a completed parse.
************* Begin file random.c *****************************************
116
** Rtree virtual table module xColumn method.
Since the names of named mutexes, semaphores, file mappings etc are
** case-sensitive, take advantage of that by uppercasing the mutex name
** and using that as the shared filemapping name.
Name of the table
231
Fill the index with data and reparse the schema. Code an OP_Expire
** to invalidate all pre-compiled statements.
REGEXP
Value to return in *pnEntry
The spec says there are three possible values for flags. But only
** two of them are actually used
Copy the b-tree node content from page pFrom to page pTo.
The parser action.
Sub-vdbe for trigger program
sqlite3_randomness()
#include "sqlite3.h"
Number of bytes in current term
Convert indexed expr to column
lock the RESERVED byte
A copy of pExpr is used instead of the original, as pExpr contains
** tokens that point to volatile memory. The 'span' of the expression
** is required by pragma table_info.
** pRoot is the root of an incremental merge-tree with depth nDepth (according
** to vdbeSorterTreeDepth()). pLeaf is the iSeq'th leaf to be added to the
** tree, counting from zero. This function adds pLeaf to the tree.
**
** If successful, SQLITE_OK is returned. If an error occurs, an SQLite error
** code is returned and pLeaf is freed.
SQLITE_INTERRUPT
** If a ReadFile() or WriteFile() error occurs, invoke this routine
** to see if it should be retried. Return TRUE to retry. Return FALSE
** to give up with an error.
There is no reason any cursor should have an outstanding reference
** to an overflow page belonging to a cell that is being deleted/updated.
** So if there exists more than one reference to this page, then it
** must not really be an overflow page and the database must be corrupt.
** It is helpful to detect this before calling freePage2(), as
** freePage2() may zero the page contents if secure-delete mode is
** enabled. If this 'overflow' page happens to be a page that the
** caller is iterating through or using in some other way, this
** can be problematic.
** If the following function pointer is not NULL and if
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
** I/O active are written using this function. These messages
** are intended for debugging activity only.
Number of loaded extensions
Cursor that holds the new sorter
Case-sensitive LIKE-type function
String, possibly obtained from sqlite3_malloc
Current checkout, including internal fragmentation
Rowid that P1 current points to
Make the IdChar function accessible from ctime.c
varintRecordCompareInt() and varintRecordCompareString() both assume
** that the size-of-header varint that occurs at the start of each record
** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
** also assumes that it is safe to overread a buffer by at least the
** maximum possible legal header size plus 8 bytes. Because there is
** guaranteed to be at least 74 (but not 136) bytes of padding following each
** buffer passed to varintRecordCompareInt() this makes it convenient to
** limit the size of the header to 64 bytes in cases where the first field
** is an integer.
**
** The easiest way to enforce this limit is to consider only records with
** 13 fields or less. If the first field is an integer, the maximum legal
** header size is (12*5 + 1 + 1) bytes.
** Destructor for a stmt_cursor.
** Return the size of an outstanding allocation, in bytes. The
** size returned omits the 8-byte header overhead. This only
** works for chunks that are currently checked out.
IN/OUT: Point to read varint from
Next session object on same db.
True if a plan with no prereqs seen
Figure out how many memory cells we will need then allocate them.
** We say the WhereLoop is "one-row" if it generates no more than one
** row of output. A WhereLoop is one-row if all of the following are true:
** (a) All index columns match with WHERE_COLUMN_EQ.
** (b) The index is unique
** Any WhereLoop with an WHERE_COLUMN_EQ constraint on the rowid is one-row.
** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
**
** We say the WhereLoop is "order-distinct" if the set of columns from
** that WhereLoop that are in the ORDER BY clause are different for every
** row of the WhereLoop. Every one-row WhereLoop is automatically
** order-distinct. A WhereLoop that has no columns in the ORDER BY clause
** is not order-distinct. To be order-distinct is not quite the same as being
** UNIQUE since a UNIQUE column or index can have multiple rows that
** are NULL and NULL values are equivalent for the purpose of order-distinct.
** To be order-distinct, the columns must be UNIQUE and NOT NULL.
**
** The rowid for a table is always UNIQUE and NOT NULL so whenever the
** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
** automatically order-distinct.
The Current table
<tbl> MATCH ?
Bytes consumed per cell
Column constrained. -1 for ROWID
comment: COVERAGE: The (pVal->z==0) branch is never true using current versions
** of SQLite. If a malloc fails in an sqlite3_value_xxx() function, either
** the (pVal->z) variable remains as it was or the type of the value is
** set to SQLITE_NULL.
label: code-design
Number of a[] slots allocated
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
** Those below are for version 3 and greater.
** Return the number of bytes currently allocated at address p.
** This object holds a record which has been parsed out into individual
** fields, for the purposes of doing a comparison.
**
** A record is an object that contains one or more fields of data.
** Records are used to store the content of a table row and to store
** the key of an index. A blob encoding of a record is created by
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
** OP_Column opcode.
**
** An instance of this object serves as a "key" for doing a search on
** an index b+tree. The goal of the search is to find the entry that
** is closed to the key described by this object. This object might hold
** just a prefix of the key. The number of fields is given by
** pKeyInfo->nField.
**
** The r1 and r2 fields are the values to return if this key is less than
** or greater than a key in the btree, respectively. These are normally
** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
** is in DESC order.
**
** The key comparison functions actually return default_rc when they find
** an equals comparison. default_rc can be -1, 0, or +1. If there are
** multiple entries in the b-tree with the same key (when only looking
** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to
** cause the search to find the last match, or +1 to cause the search to
** find the first match.
**
** The key comparison functions will set eqSeen to true if they ever
** get and equal results when comparing this structure to a b-tree record.
** When default_rc!=0, the search might end up on the record immediately
** before the first match or immediately after the last match. The
** eqSeen field will indicate whether or not an exact match exists in the
** b-tree.
The following table contains information about every rule that
** is used during the reduce.
IN: Elements in array *paLeft
Set up the required files for pIncr. A multi-theaded IncrMerge object
** requires two temp files to itself, whereas a single-threaded object
** only requires a region of pTask->file2.
If an error occurs during a ROLLBACK, we can no longer trust the pager
** cache. So call pager_error() on the way out to make any error persistent.
Used when p4type is P4_MEM
An SQLITE_MISUSE error occurred
1 -> main journal. 0 -> sub-journal.
OUT: Final number of checkpointed frames
Number of bytes in key
Address of subroutine to manifest a subquery
Length of the source file
Disable lookaside memory allocation
Generate a select expression tree to enforce the limit/offset
** term for the DELETE or UPDATE statement. For example:
** DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
** becomes:
** DELETE FROM table_a WHERE rowid IN (
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
** );
** Generate code for a boolean expression such that a jump is made
** to the label "dest" if the expression is true but execution
** continues straight thru if the expression is false.
**
** If the expression evaluates to NULL (neither true nor false), then
** take the jump if the jumpIfNull flag is SQLITE_JUMPIFNULL.
**
** This code depends on the fact that certain token values (ex: TK_EQ)
** are the same as opcode values (ex: OP_Eq) that implement the corresponding
** operation. Special comments in vdbe.c and the mkopcodeh.awk script in
** the make process cause these values to align. Assert()s in the code
** below verify that the numbers are aligned correctly.
Reserved space for locks
MEM cell holding key for the record
** Unless it is NULL, the argument must be an UnpackedRecord object returned
** by an earlier call to sqlite3Stat4ProbeSetValue(). This call deletes
** the object.
If the database supports auto-vacuum, write an entry in the pointer-map
** to indicate that the page is free.
EXISTS => nothing
OUT: Block number in next layer down
on_opt ::=
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use inside assert() statements.
Flags for the fsync
************* End of fts3_expr.c ******************************************
Index of iDelete cell in pLeaf
************* Include btree.h in the middle of sqliteInt.h ****************
Position just read from pList
Beginning of the header. 0 most pages. 100 page 1
Property flags associated with various pragma.
Matchinfo format string
Translate the schema name in zDb into a pointer to the corresponding
** schema. If not found, pSchema will remain NULL and nothing will match
** resulting in an appropriate error message toward the end of this routine
The "wsdAutoext" macro will resolve to the autoextension
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Autoext" state vector declared above.
** The file-handle passed as the only argument is open on a journal file.
** Return true if this "journal file" is currently stored in heap memory,
** or false otherwise.
** The json_parse(JSON) function returns a string which describes
** a parse of the JSON provided. Or it returns NULL if JSON is not
** well-formed.
True if rbu_count exists
comment: Use register aRegIdx[i] for index i. 0 for unused
label: code-design
eidlist ::= eidlist COMMA nm collate sortorder
If the current number of pages in the file is greater than the
** configured maximum pager number, increase the allowed limit so
** that the file can be read.
0x4
Size of doclist in current entry
** Populate the buffer pInfo->aMatchinfo[] with an array of integers to
** be returned by the matchinfo() function. Argument zArg contains the
** format string passed as the second argument to matchinfo (or the
** default value "pcx" if no second argument was specified). The format
** string has already been validated and the pInfo->aMatchinfo[] array
** is guaranteed to be large enough for the output.
**
** If bGlobal is true, then populate all fields of the matchinfo() output.
** If it is false, then assume that those fields that do not change between
** rows (i.e. FTS3_MATCHINFO_NPHRASE, NCOL, NDOC, AVGLENGTH and part of HITS)
** have already been populated.
**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs. If a value other than SQLITE_OK is returned, the state the
** pInfo->aMatchinfo[] buffer is left in is undefined.
** Initialize an array of N Mem element.
** When this function is called, *ppRec points to the start of a record
** that contains nCol values. This function advances the pointer *ppRec
** until it points to the byte immediately following that record.
IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
** pointer to a string constant whose value is the same as the
** SQLITE_SOURCE_ID C preprocessor macro.
nearphrases ::= nearphrases phrase
Largest payload of any cell on this page
A frame is only valid if the page number is creater than zero.
select
Callback for SELECTs
No-op versions of the explainXXX() functions and macros.
** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
** array so that an OP_VBegin will get generated for it. Add pTab to the
** array if it is missing. If pTab is already in the array, this routine
** is a no-op.
Opcode: NoConflict P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
** P4>0 then register P3 is the first of P4 registers that form an unpacked
** record.
**
** Cursor P1 is on an index btree. If the record identified by P3 and P4
** contains any NULL value, jump immediately to P2. If all terms of the
** record are not-NULL then a check is done to determine if any row in the
** P1 index btree has a matching key prefix. If there are no matches, jump
** immediately to P2. If there is a match, fall through and leave the P1
** cursor pointing to the matching row.
**
** This opcode is similar to OP_NotFound with the exceptions that the
** branch is always taken if any part of the search key input is NULL.
**
** This operation leaves the cursor in a state where it cannot be
** advanced in either direction. In other words, the Next and Prev
** opcodes do not work after this operation.
**
** See also: NotFound, Found, NotExists
ROWID value for this entry
If the above was successful, each component iterators now points
** to the first entry in its segment. In this case initialize the
** aFirst[] array. Or, if an error has occurred, free the iterator
** object and set the output variable to NULL.
Functions used to configure a Pager object.
** Return a 32-bit integer value extracted from a string. If the
** string is not an integer, just return 0.
If we succeeded in making the shared memory handle, map it.
If there is more header available for parsing in the record, try
** to extract additional fields up through the p2+1-th field
Callback function to invoke for phrases
** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
0x19
SQL used to determine first block
Number of args
** Set a flag in the vdbe to update the change counter when it is finalised
** or reset.
One of several kinds of errors
** Return the number of rows inserted. If this routine is
** generating code because of a call to sqlite3NestedParse(), do not
** invoke the callback function.
The following was already done in fts5WriteInit():
OUT: Hash value
Number of pages on the overflow chain
Shifts left before out of the error
Resolve names in all CHECK constraint expressions.
TRIGGER => ID
************* Include os_common.h in the middle of os_win.c ***************
comment: Cannot be both CLEAN and DIRTY
label: code-design
** This function is called to edit the position list associated with
** the phrase object passed as the fifth argument according to a NEAR
** condition. For example:
**
** abc NEAR/5 "def ghi"
**
** Parameter nNear is passed the NEAR distance of the expression (5 in
** the example above). When this function is called, *paPoslist points to
** the position list, and *pnToken is the number of phrase tokens in, the
** phrase on the other side of the NEAR operator to pPhrase. For example,
** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
** the position list associated with phrase "abc".
**
** All positions in the pPhrase position list that are not sufficiently
** close to a position in the *paPoslist position list are removed. If this
** leaves 0 positions, zero is returned. Otherwise, non-zero.
**
** Before returning, *paPoslist is set to point to the position lsit
** associated with pPhrase. And *pnToken is set to the number of tokens in
** pPhrase.
segdir.start_block
Structure of specific index
** Install the pre-update hooks on the session object passed as the only
** argument.
Size of argv array
Return the total number of outstanding page references
return if parameter is missing
** Delete a session object previously allocated using sqlite3session_create().
Update the private copy of the header.
** An object of this type is created for each virtual table present in
** the database schema.
**
** If the database schema is shared, then there is one instance of this
** structure for each database connection (sqlite3*) that uses the shared
** schema. This is because each database connection requires its own unique
** instance of the sqlite3_vtab* handle used to access the virtual table
** implementation. sqlite3_vtab* handles can not be shared between
** database connections, even when the rest of the in-memory database
** schema is shared, as the implementation often stores the database
** connection handle passed to it via the xConnect() or xCreate() method
** during initialization internally. This database connection handle may
** then be used by the virtual table implementation to access real tables
** within the database. So that they appear as part of the callers
** transaction, these accesses need to be made via the same database
** connection as that used to execute SQL operations on the virtual table.
**
** All VTable objects that correspond to a single table in a shared
** database schema are initially stored in a linked-list pointed to by
** the Table.pVTable member variable of the corresponding Table object.
** When an sqlite3_prepare() operation is required to access the virtual
** table, it searches the list for the VTable that corresponds to the
** database connection doing the preparing so as to use the correct
** sqlite3_vtab* handle in the compiled query.
**
** When an in-memory Table object is deleted (for example when the
** schema is being reloaded for some reason), the VTable objects are not
** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
** immediately. Instead, they are moved from the Table.pVTable list to
** another linked list headed by the sqlite3.pDisconnect member of the
** corresponding sqlite3 structure. They are then deleted/xDisconnected
** next time a statement is prepared using said sqlite3*. This is done
** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
** Refer to comments above function sqlite3VtabUnlockList() for an
** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
** list without holding the corresponding sqlite3.mutex mutex.
**
** The memory for objects of this type is always allocated by
** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
** the first argument.
Jump here if we hit the LIMIT
** Remove the cell with index iCell from node pNode.
** Initialize and deinitialize the operating system interface.
Malloc'd master-journal file descriptor
226
***************************************************************************
** The json_each virtual table
***************************************************************************
Jump here to skip this query
If work was actually accomplished...
** Set the busy handler function.
**
** The pager invokes the busy-handler if sqlite3OsLock() returns
** SQLITE_BUSY when trying to upgrade from no-lock to a SHARED lock,
** or when trying to upgrade from a RESERVED lock to an EXCLUSIVE
** lock. It does *not* invoke the busy handler when upgrading from
** SHARED to RESERVED, or when upgrading from SHARED to EXCLUSIVE
** (which occurs during hot-journal rollback). Summary:
**
** Transition | Invokes xBusyHandler
** --------------------------------------------------------
** NO_LOCK -> SHARED_LOCK | Yes
** SHARED_LOCK -> RESERVED_LOCK | No
** SHARED_LOCK -> EXCLUSIVE_LOCK | No
** RESERVED_LOCK -> EXCLUSIVE_LOCK | Yes
**
** If the busy-handler callback returns non-zero, the lock is
** retried. If it returns zero, then the SQLITE_BUSY error is
** returned to the caller of the pager API function.
At this point the client has a lock on an aReadMark[] slot holding
** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr
** is populated with the wal-index header corresponding to the head
** of the wal file. Verify that pSnapshot is still valid before
** continuing. Reasons why pSnapshot might no longer be valid:
**
** (1) The WAL file has been reset since the snapshot was taken.
** In this case, the salt will have changed.
**
** (2) A checkpoint as been attempted that wrote frames past
** pSnapshot->mxFrame into the database file. Note that the
** checkpoint need not have completed for this to cause problems.
Apply the requested affinity to all inputs
The cursor used for this query
Fall through into OP_Rewind
The value to apply affinity to
Term to search for
!defined(SQLITE_OMIT_VIRTUALTABLE)
This function is only called for rollback pagers in WRITER_DBMOD state.
If the DISTINCT keyword was present on the SELECT statement
** and this row has been seen before, then do not make this row
** part of the result.
Pointer to hash table to clear
The VDBE cursor number used to access this table
Generate code to evaluate all constraint terms using == or IN
** and store the values of those terms in an array of registers
** starting at regBase.
Populate the new SessionTable object and link it into the list.
** The new object must be linked onto the end of the list, not
** simply added to the start of it in order to ensure that tables
** appear in the correct order when a changeset or patchset is
** eventually generated.
Pointer to filter object
The node to render
Nr. of entries in aPgno[] and aIndex[]
True to run in heap-memory mode
RHS is null
0x03
** Write iAmt bytes of content into the WAL file beginning at iOffset.
** Do a sync when crossing the p->iSyncPoint boundary.
**
** In other words, if iSyncPoint is in between iOffset and iOffset+iAmt,
** first write the part before iSyncPoint, then sync, then write the
** rest.
(300) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT)
** The default size of a disk sector
Current ordered scan item
Initialize a term iterator for each term in the phrase
Available memory locations begin here
Cost of running each loop
** This routine is used for testing and analysis only.
If the PRIMARY KEY expression is NULL, then use OP_NewRowid
** to generate a unique primary key value.
9x
comment:
** This function is called after invoking an sqlite3_value_XXX function on a
** column value (i.e. a value returned by evaluating an SQL expression in the
** select list of a SELECT statement) that may cause a malloc() failure. If
** malloc() has failed, the threads mallocFailed flag is cleared and the result
** code of statement pStmt set to SQLITE_NOMEM.
**
** Specifically, this is called from within:
**
** sqlite3_column_int()
** sqlite3_column_int64()
** sqlite3_column_text()
** sqlite3_column_text16()
** sqlite3_column_real()
** sqlite3_column_bytes()
** sqlite3_column_bytes16()
** sqiite3_column_blob()
label: code-design
** This routine does per-connection function registration. Most
** of the built-in functions above are part of the global function set.
** This routine only deals with those that are not global.
comment:
** The following group of routines make deep copies of expressions,
** expression lists, ID lists, and select statements. The copies can
** be deleted (by being passed to their respective ...Delete() routines)
** without effecting the originals.
**
** The expression list, ID, and source lists return by sqlite3ExprListDup(),
** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded
** by subsequent calls to sqlite*ListAppend() routines.
**
** Any tables that the SrcList might point to are not duplicated.
**
** The flags parameter contains a combination of the EXPRDUP_XXX flags.
** If the EXPRDUP_REDUCE flag is set, then the structure returned is a
** truncated version of the usual Expr structure that will be stored as
** part of the in-memory representation of the database schema.
label: code-design
** This routine frees the space the sqlite3_get_table() malloced.
Allocated size of apCell, szCell, aFrom.
Append "UPDATE tbl SET "
Free a prior allocation
no, really, unlock.
Result returned from sqlite3_get_table()
Name assigned to this module
Check that the stack is large enough to grow by a single entry
** if the RHS of the rule is empty. This ensures that there is room
** enough on the stack to push the LHS value
Arguments to agg function
Round up request size to allocation size
zFilename encoded in UTF-8 instead of UTF-16
Operators and special symbols
Alphabetics or '_'. Usable in a keyword
UPDATE
** Unlink the chunk at mem3.aPool[i] from list it is currently
** on. *pRoot is the list that i is a member of.
#ifndef SQLITE_OMIT_WAL
The lookup key
Number of cells in apCell[]
One character past the end of input text
280
Return true if index X is a UNIQUE index
OOM will cause exit after sqlite3Select()
Size of buffer zDoc in bytes
If this was page 1, then restore the value of Pager.dbFileVers.
** Do this before any decoding.
Exit the mutexes and free the backup context structure.
Iterator object to initialize
************* Include pcache.h in the middle of sqliteInt.h ***************
Test all CHECK constraints
Add sign
When the new root page was allocated, page 1 was made writable in
** order either to increase the database filesize, or to decrement the
** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
Maximum bit index. Max iSize is 4,294,967,296.
The %p conversion
Try to match the ORDER BY expression against an expression
** in the result set. Return an 1-based index of the matching
** result-set entry.
Opcode: IncrVacuum P1 P2 * * *
**
** Perform a single step of the incremental vacuum procedure on
** the P1 database. If the vacuum has finished, jump to instruction
** P2. Otherwise, fall through to the next instruction.
Handle the common case of integer comparison here, as an
** optimization, to avoid a call to sqlite3MemCompare()
Content of the node, as should be on disk
Modify the sqlite_master table to use the new table name.
Previous index in the loop
IMP: R-49053-54554
105
** Free the phrase object passed as the second argument.
Initialize the shared memory if we're supposed to
Parse structure for main program (or NULL)
Length of the string so far
Enlarge pJson->zBuf so that it can hold at least N more bytes.
** Return zero on success. Return non-zero on an OOM error
** Check if another file-handle holds a RESERVED lock on an rbuVfs-file.
A stat() call may fail for various reasons. If this happens, it is
** almost certain that an open() call on the same path will also fail.
** For this reason, if an error occurs in the stat() call here, it is
** ignored and -1 is returned. The caller will try to open a new file
** descriptor on the same path, fail, and return an error to SQLite.
**
** Even if a subsequent open() call does succeed, the consequences of
** not searching for a reusable file descriptor are not dire.
Populate the output variable and return success.
The page size
Opcode: CreateTable P1 P2 * * *
** Synopsis: r[P2]=root iDb=P1
**
** Allocate a new table in the main database file if P1==0 or in the
** auxiliary database file if P1==1 or in an attached database if
** P1>1. Write the root page number of the new table into
** register P2
**
** The difference between a table and an index is this: A table must
** have a 4-byte integer key and can have arbitrary data. An index
** has an arbitrary key but no data.
**
** See also: CreateIndex
True while initialization in progress
** If cursors, triggers, views and subqueries are all omitted from
** the build, then none of the following routines, except for
** sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes
** called with a NULL argument.
** Return a simple checksum value based on the arguments.
comment:
** CAPI3REF: Finalize A Changeset Iterator
**
** This function is used to finalize an iterator allocated with
** [sqlite3changeset_start()].
**
** This function should only be called on iterators created using the
** [sqlite3changeset_start()] function. If an application calls this
** function with an iterator passed to a conflict-handler by
** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
** call has no effect.
**
** If an error was encountered within a call to an sqlite3changeset_xxx()
** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
** to that error is returned by this function. Otherwise, SQLITE_OK is
** returned. This is to allow the following pattern (pseudo-code):
**
** sqlite3changeset_start();
** while( SQLITE_ROW==sqlite3changeset_next() ){
** // Do something with change.
** }
** rc = sqlite3changeset_finalize();
** if( rc!=SQLITE_OK ){
** // An error has occurred
** }
label: code-design
** Allocate nByte bytes of memory.
** This function is called from within the xConnect() or xCreate() method to
** determine the node-size used by the rtree table being created or connected
** to. If successful, pRtree->iNodeSize is populated and SQLITE_OK returned.
** Otherwise, an SQLite error code is returned.
**
** If this function is being called as part of an xConnect(), then the rtree
** table already exists. In this case the node-size is determined by inspecting
** the root node of the tree.
**
** Otherwise, for an xCreate(), use 64 bytes less than the database page-size.
** This ensures that each node is stored on a single database page. If the
** database page-size is so large that more than RTREE_MAXCELLS entries
** would fit in a single node, use a smaller node-size.
680
File handle for the database file
Generate code that will load into register regOut a value that is
** appropriate for the iIdxCol-th column of index pIdx.
Check for the rbu_count table. If it does not exist, or if an error
** occurs, nPhaseOneStep will be left set to -1.
List of tables in current patch
aiRowLogEst values come from sqlite_stat1
All nFrom paths at the previous level
Information about each column
There already exists a WhereLoop on the list that is better
** than pTemplate, so just ignore pTemplate
Buffer containing string or blob data
IMP: R-61914-48074
Btree
** Disable MMAP on platforms where it is known to not work
The ram filesystem has no write behind
** so it is ordered
Canonical filename
Opcode: Concat P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]+r[P1]
**
** Add the text in register P1 onto the end of the text in
** register P2 and store the result in register P3.
** If either the P1 or P2 text are NULL then store NULL in P3.
**
** P3 = P2 || P1
**
** It is illegal for P1 and P3 to be the same register. Sometimes,
** if P3 is the same register as P2, the implementation is able
** to avoid a memcpy().
7 -> NOTINDEXED
Number of dimensions
** Clear the column names from every VIEW in database idx.
** Return true if it desirable to avoid allocating a new page cache
** entry.
**
** If memory was allocated specifically to the page cache using
** SQLITE_CONFIG_PAGECACHE but that memory has all been used, then
** it is desirable to avoid allocating a new page cache entry because
** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
** for all page cache needs and we should not need to spill the
** allocation onto the heap.
**
** Or, the heap is used for all page cache memory but the heap is
** under memory pressure, then again it is desirable to avoid
** allocating a new page cache entry in order to avoid stressing
** the heap even further.
** Streaming version of sqlite3changeset_start().
The Btree to which this cursor belongs
Forward references to VFS methods
Figure out the name of the primary key index for the current table.
** This is needed for the argument to "PRAGMA index_xinfo". Set
** zIdx to point to a nul-terminated string containing this name.
** Add a single new WhereTerm entry to the WhereClause object pWC.
** The new WhereTerm object is constructed from Expr p and with wtFlags.
** The index in pWC->a[] of the new WhereTerm is returned on success.
** 0 is returned if the new WhereTerm could not be added due to a memory
** allocation error. The memory allocation failure will be recorded in
** the db->mallocFailed flag so that higher-level functions can detect it.
**
** This routine will increase the size of the pWC->a[] array as necessary.
**
** If the wtFlags argument includes TERM_DYNAMIC, then responsibility
** for freeing the expression p is assumed by the WhereClause object pWC.
** This is true even if this routine fails to allocate a new WhereTerm.
**
** WARNING: This routine might reallocate the space used to store
** WhereTerms. All pointers to WhereTerms should be invalidated after
** calling this routine. Such pointers may be reinitialized by referencing
** the pWC->a[] array.
SQL_CHOMP_SEGDIR
** Update the start_block (:1) and root (:2) fields of the %_segdir
** entry located on absolute level :3 with index :4.
pPager->errMask = 0;
For looping over existing elements
** Values used as part of the flags argument passed to IndexQuery().
** Return the size of a pcache allocation
Top of the loop
************* End of treeview.c *******************************************
os_win.c
pC->aRow does not have to hold the entire row, but it does at least
** need to cover the header of the record. If pC->aRow does not contain
** the complete header, then set it to zero, forcing the header to be
** dynamically allocated.
idx = (lwr+upr)/2
** Close the dynamic library handle pHandle.
** This function is used to create delta-encoded serialized lists of FTS3
** varints. Each call to this function appends a single varint to a list.
Check that the wal file has not been wrapped. Assuming that it has
** not, also check that no checkpointer has attempted to checkpoint any
** frames beyond pSnapshot->mxFrame. If either of these conditions are
** true, return SQLITE_BUSY_SNAPSHOT. Otherwise, overwrite pWal->hdr
** with *pSnapshot and set *pChanged as appropriate for opening the
** snapshot.
Add a field to the old.* record. This is omitted if this modules is
** currently generating a patchset.
expr ::= expr IS expr
Offsets of each character in utf-8 input
Restriction (2a)
** Return the pPager->iDataVersion value
For a LEFT OUTER JOIN, generate code that will record the fact that
** at least one row of the right table has matched the left table.
If there is a doclist-index
** The mutex object
Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
** 6 and each subsequent value (if any) is 5.
Defer right-most ORDER BY of a compound
Show full column names on SELECT
Invoke the pre-update-hook if required.
** Generate VDBE code for a BEGIN statement.
** The implementation of user-defined scalar function fts5_rowid().
If rowid is changing, make sure the new rowid does not previously
** exist in the table.
** Generate code to evaluate an expression and store the results
** into a register. Return the register number where the results
** are stored.
**
** If the register is a temporary register that can be deallocated,
** then write its number into *pReg. If the result register is not
** a temporary, then set *pReg to zero.
**
** If pExpr is a constant, then this routine might generate this
** code to fill the register in the initialization section of the
** VDBE program, in order to factor it out of the evaluation loop.
comment: Clean up and report errors.
label: code-design
i0, i1, i2... such that aPgno[iN] ascend
** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that
** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true,
** make it true by defining or undefining NDEBUG.
**
** Setting NDEBUG makes the code smaller and faster by disabling the
** assert() statements in the code. So we want the default action
** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG
** is set. Thus NDEBUG becomes an opt-in rather than an opt-out
** feature.
The SQLITE_ColumnCache flag disables the column cache. This is used
** for testing only - to verify that SQLite always gets the same answer
** with and without the column cache.
Sizeof aRowid[]
comment: TUNING: Because uncertainties in the estimates for skip-scan queries,
** add a 1.375 fudge factor to make skip-scan slightly less likely.
label: code-design
Value of 'pagetype' column
The state-number, or reduce action in SHIFTREDUCE
Value for 'level' column of %_segdir
** If the subquery is the right operand of a LEFT JOIN, then the
** subquery may not be a join itself. Example of why this is not allowed:
**
** t1 LEFT OUTER JOIN (t2 JOIN t3)
**
** If we flatten the above, we would get
**
** (t1 LEFT OUTER JOIN t2) JOIN t3
**
** which is not at all the same thing.
**
** If the subquery is the right operand of a LEFT JOIN, then the outer
** query cannot be an aggregate. This is an artifact of the way aggregates
** are processed - there is no mechanism to determine if the LEFT JOIN
** table should be all-NULL.
**
** See also tickets #306, #350, and #3300.
The eMode parameter is always valid
comment:
** CAPI3REF: Mutex Types
**
** The [sqlite3_mutex_alloc()] interface takes a single argument
** which is one of these integer constants.
**
** The set of static mutexes may change from one SQLite release to the
** next. Applications that override the built-in mutex logic must be
** prepared to accommodate additional static mutexes.
label: code-design
** Compare two search points. Return negative, zero, or positive if the first
** is less than, equal to, or greater than the second.
**
** The rScore is the primary key. Smaller rScore values come first.
** If the rScore is a tie, then use iLevel as the tie breaker with smaller
** iLevel values coming first. In this way, if rScore is the same for all
** SearchPoints, then iLevel becomes the deciding factor and the result
** is a depth-first search, which is the desired default behavior.
** One object per %_data table.
comment: For a long-term use prepared statement avoid the use of
** lookaside memory.
label: code-design
Shadow table to create (e.g. "content")
** CAPI3REF: Virtual Table Instance Object
** KEYWORDS: sqlite3_vtab
**
** Every [virtual table module] implementation uses a subclass
** of this object to describe a particular instance
** of the [virtual table]. Each subclass will
** be tailored to the specific needs of the module implementation.
** The purpose of this superclass is to define certain fields that are
** common to all module implementations.
**
** ^Virtual tables methods can set an error message by assigning a
** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
** take care that any prior string is freed by a call to [sqlite3_free()]
** prior to assigning a new string to zErrMsg. ^After the error message
** is delivered up to the client application, the string will be automatically
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
Scan multiple terms in the main index
Outer conjunction
Incremental merger
Dummy parameter to exprCodeVector()
#include "sqliteInt.h" ** Requires access to internal data structures **
Remove the cell from the node. This call just moves bytes around
** the in-memory node image, so it cannot fail.
1350
synopsis: if r[P1]!=0 then r[P1]--, goto P2
The OP_OpenEphemeral for the sorting index
If the parent table is the same as the child table, and we are about
** to increment the constraint-counter (i.e. this is an INSERT operation),
** then check if the row being inserted matches itself. If so, do not
** increment the constraint-counter.
comment: Rowid for current doc being written
label: documentation
same as TK_AND, in1, in2, out3
77
0xffff
Memory cell used for change counting
** Extract the next token from a tokenization cursor.
Used only when flags==MEM_RowSet
synopsis: affinity(r[P1])
If another database handle has already opened a write transaction
** on this shared-btree structure and a second write transaction is
** requested, return SQLITE_LOCKED.
If there is a GROUP BY clause we might need a sorting index to
** implement it. Allocate that sorting index now. If it turns out
** that we do not need it after all, the OP_SorterOpen instruction
** will be converted into a Noop.
** The following are used as the second parameter to sqlite3Savepoint(),
** and as the P1 argument to the OP_Savepoint instruction.
A record to be insert into the new table
Maximum number of simultaneous paths tracked
iAuxArg is always set if to a positive value if ONEPASS is possible
CURTYPE_PSEUDO. Reg holding content.
** Free all allocations associated with the iterator passed as the
** second argument.
** Pragma virtual table module xFilter method.
SCAN
** FTS3 and FTS4 both require virtual table support
Database connection associated with this table
Page number for this page
comment: Not needed. Only to silence a warning.
label: requirement
composite PRIMARY KEY value
** A "phrase" is a sequence of one or more tokens that must match in
** sequence. A single token is the base case and the most common case.
** For a sequence of tokens contained in double-quotes (i.e. "one two three")
** nToken will be the number of tokens in the string.
xfer opt does not play well with PRAGMA count_changes
Function arguments
What to do in case of uniqueness conflict on iPKey
Restriction (23)
OUT: SegReader for pending-terms
The journal file exists and no other connection has a reserved
** or greater lock on the database file. Now check that there is
** at least one non-zero bytes at the start of the journal file.
** If there is, then we consider this journal to be hot. If not,
** it can be ignored.
PARTLY_WITHIN or FULLY_WITHIN
User visible part of object (see fts5.h)
** Implementation of randomblob(N). Return a random blob
** that is N bytes long.
The "rows less-than" for the rowid column must be greater than that
** for the last sample in the p->a[] array. Otherwise, the samples would
** be out of order.
OR
SQLITE_MUTEX_PTHREADS
Used to get maximum path length and AppData
For the OP_NoConflict opcode, take the jump if any of the
** input fields are NULL, since any key with a NULL will not
** conflict
In-memory database
EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
** Multi-thread.
Check to see if a partial index with pPartIndexWhere can be used
** in the current query. Return true if it can be and false if not.
SQL function call context
Set of contexts for which prohibited
If true, discard no data
Attach the hook to this db handle
Function to invoke on each commit
sqlite3BtreeOpen()
space allocated to zToken buffer
Return results here
Do not do auto-vacuum
OUT: Write new node image here
Possible if pIn1==pIn3
Must be UNION ALL
ON DELETE
Node ID
11
selcollist
Column expressions
** Initialize API pointer table, if required.
Look for an existing WhereLoop to replace with pTemplate
Query planner decisions affected by
** Index.aiRowLogEst[] values
comment:
**
** This function - winLogErrorAtLine() - is only ever called via the macro
** winLogError().
**
** This routine is invoked after an error occurs in an OS function.
** It logs a message using sqlite3_log() containing the current value of
** error code and, if possible, the human-readable equivalent from
** FormatMessage.
**
** The first argument passed to the macro should be the error code that
** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
** The two subsequent arguments should be the name of the OS function that
** failed and the associated file-system path, if any.
label: code-design
SQL statement, UTF-16 encoded
IN/OUT: Increment by bytes written
Index of the parameter to bind
** Return the size of an outstanding allocation, in bytes.
** This only works for chunks that are currently checked out.
PGroup this cache belongs to
Array of remaining idx values
phrase ::= STRING star_opt
** Structure containing global configuration data for the SQLite library.
**
** This structure also contains some state information.
No error if the table already exists
** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due
** do a memory allocation failure) then delete the pSelect object.
Explicit use of the CROSS keyword
Max level number for this index/langid
comment:
** This function is called as part of the transition from PAGER_OPEN
** to PAGER_READER state to determine the size of the database file
** in pages (assuming the page size currently stored in Pager.pageSize).
**
** If no error occurs, SQLITE_OK is returned and the size of the database
** in pages is stored in *pnPage. Otherwise, an error code (perhaps
** SQLITE_IOERR_FSTAT) is returned and *pnPage is left unmodified.
label: code-design
Pointer to list of ongoing backup processes
** A pointer to a structure of the following type is passed as the first
** argument to callbacks registered using rtree_geometry_callback().
deprecated names
Term to seek to
FULL
One of PASSIVE, FULL or RESTART
comment: If the read is unsuccessful, set the dbFileVers[] to something
** that will never be a valid file version. dbFileVers[] is a copy
** of bytes 24..39 of the database. Bytes 28..31 should always be
** zero or the size of the database in page. Bytes 32..35 and 35..39
** should be page numbers which are never 0xffffffff. So filling
** pPager->dbFileVers[] with all 0xff bytes should suffice.
**
** For an encrypted database, the situation is more complex: bytes
** 24..39 of the database are white noise. But the probability of
** white noise equaling 16 bytes of 0xff is vanishingly small so
** we should still be ok.
label: code-design
Allocate memory from the gap in between the cell pointer array
** and the cell content area. The btreeInitPage() call has already
** validated the freelist. Given that the freelist is valid, there
** is no way that the allocation can extend off the end of the page.
** The assert() below verifies the previous sentence.
comment: Allocate and initialize the WhereInfo structure that will become the
** return value. A single allocation is used to store the WhereInfo
** struct, the contents of WhereInfo.a[], the WhereClause structure
** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
** field (type Bitmask) it must be aligned on an 8-byte boundary on
** some architectures. Hence the ROUND8() below.
label: code-design
DELETE + INSERT
beginning-of-error-codes
Filename argument to pass to BtreeOpen()
** By default, allocate this many bytes of memory for each FileChunk object.
Record that this module has started
Number of phrases seen so far
Cursor id
comment: OUT: Pointer to unused portion of zSql
label: code-design
Jump to the end of the loop if the LIMIT is reached. Except, if
** there is a sorter, in which case the sorter has already limited
** the output for us.
Abort due to constraint violation
AFP locking uses the file path so it needs to be included in
** the afpLockingContext.
SET
Pre-allocated buffer
** Return a pointer to an sqlite3_value structure containing the value bound
** parameter iVar of VM v. Except, if the value is an SQL NULL, return
** 0 instead. Unless it is NULL, apply affinity aff (one of the SQLITE_AFF_*
** constants) to the value before returning it.
**
** The returned value must be freed by the caller using sqlite3ValueFree().
Name of the column of the table
No commit or rollback needed if the program never started or if the
** SQL statement does not read or write a database file.
****************************************************************************
** Implementation of an eponymous virtual table that runs a pragma.
**
Offset in zDoc of end of token
21
comment: Check to see if another process is holding the dead-man switch.
** If not, truncate the file to zero length.
label: code-design
51
** Prepare to begin tokenizing a particular string. The input
** string to be tokenized is zInput[0..nInput-1]. A cursor
** used to incrementally tokenize this string is returned in
** *ppCursor.
Optional WHERE clause to be added
comment:
** This function is an optimized version of sqlite3VdbeRecordCompare()
** that (a) the first field of pPKey2 is an integer, and (b) the
** size-of-header varint at the start of (pKey1/nKey1) fits in a single
** byte (i.e. is less than 128).
**
** To avoid concerns about buffer overreads, this routine is only used
** on schemas where the maximum valid header size is 63 bytes or less.
label: code-design
** If the argument is a codepoint corresponding to a lowercase letter
** in the ASCII range with a diacritic added, return the codepoint
** of the ASCII letter only. For example, if passed 235 - "LATIN
** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER
** E"). The resuls of passing a codepoint that corresponds to an
** uppercase letter are undefined.
The list of freeblocks must be in ascending order. Find the
** spot on the list where iStart should be inserted.
Used by extra internal tests only run if NDEBUG is not defined
True if blob 'hint' has been modified
Decomposition of the entire WHERE clause
Find the value object that holds the new rowid value.
Check sanity of left child page for internal pages
Array of "seen instance" flags
Used by PRAGMA temp_store_directory
** Initialize the operating system interface.
**
** This routine registers all VFS implementations for unix-like operating
** systems. This routine, and the sqlite3_os_end() routine that follows,
** should be the only routines in this file that are visible from other
** files.
**
** This routine is called once during SQLite initialization and by a
** single thread. The memory allocation and mutex subsystems have not
** necessarily been initialized when this routine is called, and so they
** should not be used.
** The stmtConnect() method is invoked to create a new
** stmt_vtab that describes the stmt virtual table.
**
** Think of this routine as the constructor for stmt_vtab objects.
**
** All this routine needs to do is:
**
** (1) Allocate the stmt_vtab object and initialize all fields.
**
** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
** result set of queries against stmt will look like.
SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
If opening a non-empty database, check the text encoding. For the
** main database, set sqlite3.enc to the encoding of the main database.
** For an attached db, it is an error if the encoding is not the same
** as sqlite3.enc.
cmd ::= REINDEX
** Obtain a pointer to a mapping of a single 32KiB page of the *-shm file.
Restriction (1)
IMP: R-07272-22309
** Append N bytes of text from z to the StrAccum object. Increase the
** size of the memory allocation for StrAccum if necessary.
Path to rbu db
How often to do a periodic sample
Handle negative integers in a single step. This is needed in the
** case when the value is -9223372036854775808.
6
Create a single sqlite_stat1 entry containing NULL as the index
** name and the row count as the content.
The expression of the term
The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
** Multiplying this by 86400000 gives 464269060799999 as the maximum value
** for DateTime.iJD.
**
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
** such a large integer literal, so we have to encode it.
Advance pointer p1 or p2 (whichever corresponds to the smaller of
** iCol1 and iCol2) so that it points to either the 0x00 that marks the
** end of the position list, or the 0x01 that precedes the next
** column-number in the position list.
OUT: Malloc'd array of column names
nfs lockd on OSX 10.3+ doesn't clear write locks when a read lock is set
92
These constants specify the various numeric values for terminal symbols
** in a format understandable to "makeheaders". This section is blank unless
** "lemon" is run with the "-m" command-line option.
***************** Begin makeheaders token definitions ************************
OUT: Allocated seg-reader cursor
Increase the total number of bytes written to account for the new entry.
comment: This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
** in the style of sqlite3_trace()
label: code-design
** Default span for NEAR operators.
** Allocate a two-slot MatchinfoBuffer object.
Number of cursors required
Multiple by log(M) where M is the number of output rows.
** Use the LIMIT for M if it is smaller
This indicates that no database name was specified as part
** of the PRAGMA command. In this case the locking-mode must be
** set on all attached databases, as well as the main db file.
**
** Also, the sqlite3.dfltLockMode variable is set so that
** any subsequently attached databases also use the specified
** locking mode.
Reclaim all memory used by the VDBE
Discard the contents of the cache
** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
Write result here
Initial number of leaf cells on trunk page
Like FULL but wait for for readers
comment: The following goto is an optimization. It can be omitted and
** everything will still work. But OP_Column is measurably faster
** by skipping the subsequent conditional, which is always true.
label: code-design
Size of the rowid
'~'
Extracted Key value
Because P2 is always a static string, it is impossible for the
** sqlite3VdbeMemCopy() to fail
0x20..0x2F
Largest valid xSavepoint integer
Type of node in this tree
True if there is a trailing "*"
True if plan uses IN(...) operator
Ignore TEMP and :memory: databases
The next iteration of the do-loop balances the parent page.
880
Query the value of journalmode
** Return the current time for a statement. If the current time
** is requested more than once within the same run of a single prepared
** statement, the exact same time is returned for each invocation regardless
** of the amount of time that elapses between invocations. In other words,
** the time returned is always the time of the first call.
** Return the number of bytes that will be needed to store the given
** 64-bit integer.
.pFiller =
** Compute and return a new Expr object which when passed to
** sqlite3ExprCode() will generate all necessary code to compute
** the iField-th column of the vector expression pVector.
**
** It is ok for pVector to be a scalar (as long as iField==0).
** In that case, this routine works like sqlite3ExprDup().
**
** The caller owns the returned Expr object and is responsible for
** ensuring that the returned value eventually gets freed.
**
** The caller retains ownership of pVector. If pVector is a TK_SELECT,
** then the returned object will reference pVector and so pVector must remain
** valid for the life of the returned object. If pVector is a TK_VECTOR
** or a scalar expression, then it can be deleted as soon as this routine
** returns.
**
** A trick to cause a TK_SELECT pVector to be deleted together with
** the returned Expr object is to attach the pVector to the pRight field
** of the returned TK_SELECT_COLUMN Expr object.
reg[1] holds errors left
** Interchange two search points in a cursor.
ccons ::= PRIMARY KEY sortorder onconf autoinc
Search backwards for a varint with value zero (the end of the previous
** poslist). This is an 0x00 byte preceded by some byte that does not
** have the 0x80 bit set.
** If the argument p points to a MemJournal structure that is not an
** in-memory-only journal file (i.e. is one that was opened with a +ve
** nSpill parameter), and the underlying file has not yet been created,
** create it now.
Save the positions of any other cursors open on this table.
**
** In some cases, the call to btreeMoveto() below is a no-op. For
** example, when inserting data into a table with auto-generated integer
** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
** integer key to use. It then calls this function to actually insert the
** data into the intkey B-Tree. In this case btreeMoveto() recognizes
** that the cursor is already where it needs to be and returns without
** doing any work. To avoid thwarting these optimizations, it is important
** not to clear the cursor here.
All fields above are zeroed when the cursor is allocated. See
** sqlite3BtreeCursorZero(). Fields that follow must be manually
** initialized.
This loop terminates either when a readJournalHdr() or
** pager_playback_one_page() call returns SQLITE_DONE or an IO error
** occurs.
Error state.
No overflow pages. Return without doing anything
this happens for a comment or white-space
** Return the ON CONFLICT resolution mode in effect for the virtual
** table update operation currently in progress.
**
** The results of this routine are undefined unless it is called from
** within an xUpdate method.
247
SQLITE_ZERO_MALLOC
comment: Set the output variable to NULL in case an error occurs.
label: code-design
Collating sequence with native encoding, or NULL
The following three functions, heightOfExpr(), heightOfExprList()
** and heightOfSelect(), are used to determine the maximum height
** of any expression tree referenced by the structure passed as the
** first argument.
**
** If this maximum height is greater than the current value pointed
** to by pnHeight, the second parameter, then set *pnHeight to that
** value.
Restriction (21)
Loop counters
The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
** structure. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdHooks can refer directly
** to the "sqlite3Hooks" state vector declared above.
First call xBestIndex() with all constraints usable.
Index of docid>=x constraint, if present
Size of allocation at aData
** CAPI3REF: OS Interface Open File Handle
**
** An [sqlite3_file] object represents an open file in the
** [sqlite3_vfs | OS interface layer]. Individual OS interface
** implementations will
** want to subclass this object by appending additional fields
** for their own use. The pMethods entry is a pointer to an
** [sqlite3_io_methods] object that defines methods for performing
** I/O operations on the open file.
SQL used to determine iAbsLevel
** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
**
** * A b-tree cursor
** - In the main database or in an ephemeral database
** - On either an index or a table
** * A sorter
** * A virtual table
** * A one-row "pseudotable" stored in a single register
* The extra flags to use in calls to the Win32 heap APIs. This value may be
* zero for the default behavior.
** The xConnect() and xCreate() methods for the virtual table. All the
** work is done in function fts5VocabInitVtab().
List of operands to the LIKE operator
It is not possible to create a database for which the final page
** is either a pointer-map page or the pending-byte page. If one
** is encountered, this indicates corruption.
** Check if the *-wal file that corresponds to the database opened by pPager
** exists if the database is not empy, or verify that the *-wal file does
** not exist (by deleting it) if the database file is empty.
**
** If the database is not empty and the *-wal file exists, open the pager
** in WAL mode. If the database is empty or if no *-wal file exists and
** if no error occurs, make sure Pager.journalMode is not set to
** PAGER_JOURNALMODE_WAL.
**
** Return SQLITE_OK or an error code.
**
** The caller must hold a SHARED lock on the database file to call this
** function. Because an EXCLUSIVE lock on the db file is required to delete
** a WAL on a none-empty database, this ensures there is no race condition
** between the xAccess() below and an xDelete() being executed by some
** other connection.
** Return the search point with the lowest current score.
************* Begin file vdbe.c *******************************************
The bottom of the loop
** CAPI3REF: Finding The Subtype Of SQL Values
** METHOD: sqlite3_value
**
** The sqlite3_value_subtype(V) function returns the subtype for
** an [application-defined SQL function] argument V. The subtype
** information can be used to pass a limited amount of context from
** one SQL function to another. Use the [sqlite3_result_subtype()]
** routine to set the subtype for the return value of an SQL function.
Offset into aKey[] of next header element
Any read-only or read-write transaction implies a read-lock on
** page 1. So if some other shared-cache client already has a write-lock
** on page 1, the transaction cannot be opened.
** The token *pName contains the name of a database (either "main" or
** "temp" or the name of an attached db). This routine returns the
** index of the named database in db->aDb[], or -1 if the named db
** does not exist.
Locate the end of the CREATE VIEW statement. Make sEnd point to
** the end.
Otherwise useTempTable is true
1 for the "l" flag, 2 for "ll", 0 by default
Delete a row from a main table b-tree
List of all unixInodeInfo objects
Also store the SQLite version number in bytes 96..99 and in
** bytes 92..95 store the change counter for which the version number
** is valid.
If this is an insert into a table b-tree, invalidate any incrblob
** cursors open on the row being replaced
comment: For temporary filename, if necessary.
label: code-design
** If a write transaction is open, then all changes made within the
** transaction are reverted and the current write-transaction is closed.
** The pager falls back to PAGER_READER state if successful, or PAGER_ERROR
** state if an error occurs.
**
** If the pager is already in PAGER_ERROR state when this function is called,
** it returns Pager.errCode immediately. No work is performed in this case.
**
** Otherwise, in rollback mode, this function performs two functions:
**
** 1) It rolls back the journal file, restoring all database file and
** in-memory cache pages to the state they were in when the transaction
** was opened, and
**
** 2) It finalizes the journal file, so that it is not used for hot
** rollback at any point in the future.
**
** Finalization of the journal file (task 2) is only performed if the
** rollback is successful.
**
** In WAL mode, all cache-entries containing data modified within the
** current transaction are either expelled from the cache or reverted to
** their pre-transaction state by re-reading data from the database or
** WAL files. The WAL transaction is then closed.
.enc =
LIKE pattern
At first glance you would think we could optimize out the
** ORDER BY in this case since the order of entries in the set
** does not matter. But there might be a LIMIT clause, in which
** case the order does matter
LHS values prior to reordering by aiMap[]
Cursor of table to get the new rowid
Has no GROUP BY clause
Number of bytes of prefix compression
!defined(SQLITE_OMIT_TRIGGER)
The three function arguments
Partial index inappropriate for this query
Jump to the appropriate pragma handler
** The following are allowed values for Vdbe.magic
Use native byte order
Column index on lhs of IN operator
** Look up an index by name. Or, if the name of a WITHOUT ROWID table
** is supplied instead, find the PRIMARY KEY index for that table.
SQLite assumes that xFullPathname() nul-terminates the output buffer
** even if it returns an error.
Table holding the result of the SELECT
** The most recently coded instruction was an OP_Column to retrieve the
** i-th column of table pTab. This routine sets the P4 parameter of the
** OP_Column to the default value, if any.
**
** The default value of a column is specified by a DEFAULT clause in the
** column definition. This was either supplied by the user when the table
** was created, or added later to the table definition by an ALTER TABLE
** command. If the latter, then the row-records in the table btree on disk
** may not contain a value for the column and the default value, taken
** from the P4 parameter of the OP_Column instruction, is returned instead.
** If the former, then all row-records are guaranteed to include a value
** for the column and the P4 value is not required.
**
** Column definitions created by an ALTER TABLE command may only have
** literal default values specified: a number, null or a string. (If a more
** complicated default expression value was provided, it is evaluated
** when the ALTER TABLE is executed and one of the literal values written
** into the sqlite_master table.)
**
** Therefore, the P4 parameter is only required if the default value for
** the column is a literal number, string or null. The sqlite3ValueFromExpr()
** function is capable of transforming these types of expressions into
** sqlite3_value objects.
**
** If parameter iReg is not negative, code an OP_RealAffinity instruction
** on register iReg. This is used when an equivalent integer value is
** stored in place of an 8-byte floating point value in order to save
** space.
Ticket 2ea2425d34be
** The following macro defines an initializer for an sqlite3_vfs object.
** The name of the VFS is NAME. The pAppData is a pointer to a pointer
** to the "finder" function. (pAppData is a pointer to a pointer because
** silly C90 rules prohibit a void* from being cast to a function pointer
** and so we have to go through the intermediate pointer to avoid problems
** when compiling with -pedantic-errors on GCC.)
**
** The FINDER parameter to this macro is the name of the pointer to the
** finder-function. The finder-function returns a pointer to the
** sqlite_io_methods object that implements the desired locking
** behaviors. See the division above that contains the IOMETHODS
** macro for addition information on finder-functions.
**
** Most finders simply return a pointer to a fixed sqlite3_io_methods
** object. But the "autolockIoFinder" available on MacOSX does a little
** more than that; it looks at the filesystem type that hosts the
** database file and tries to choose an locking method appropriate for
** that filesystem time.
Number of significant digits returned
True after mutexes are initialized
Index of the first hidden column
Define the yytestcase() macro to be a no-op if is not already defined
** otherwise.
**
** Applications can choose to define yytestcase() in the %include section
** to a macro that can assist in verifying code coverage. For production
** code the yytestcase() macro should be turned off. But it is useful
** for testing.
comment: Smallest sample not yet tested
label: test
0x10..0x1F
** The maximum length of a TEXT or BLOB in bytes. This also
** limits the size of a row in a table or index.
**
** The hard limit is the ability of a 32-bit signed integer
** to count the size: 2^31-1 or 2147483647.
Length in bytes of zFrom
920
Manufactured x>NULL or x<=NULL term
if we succeeded in taking the reserved lock, unlock it to restore
** the original state
The assumed sector size for this process
comment:
** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
** arguments are the usual subsitution values. This function performs
** the printf() style substitutions and executes the result as an SQL
** statement on the RBU handles database.
**
** If an error occurs, an error code and error message is stored in the
** RBU handle. If an error has already occurred when this function is
** called, it is a no-op.
label: code-design
Top of the index fill loop
Size of prefix shared with previous term
Analyze the min-heap looking for overlap between cells and/or
** freeblocks, and counting the number of untracked bytes in nFrag.
**
** Each min-heap entry is of the form: (start_address<<16)|end_address.
** There is an implied first entry the covers the page header, the cell
** pointer index, and the gap between the cell pointer index and the start
** of cell content.
**
** The loop below pulls entries from the min-heap in order and compares
** the start_address against the previous end_address. If there is an
** overlap, that means bytes are used multiple times. If there is a gap,
** that gap is added to the fragmentation count.
groupby_opt ::= GROUP BY nexprlist
Find the sibling pages to balance. Also locate the cells in pParent
** that divide the siblings. An attempt is made to find NN siblings on
** either side of pPage. More siblings are taken from one side, however,
** if there are fewer than NN siblings on the other side. If pParent
** has NB or fewer children then all children of pParent are taken.
**
** This loop also drops the divider cells from the parent page. This
** way, the remainder of the function does not have to deal with any
** overflow cells in the parent page, since if any existed they will
** have already been removed.
Pre-allocated UnixUnusedFd
Database was empty at trans start
Because pFile->pInode is shared across threads
Increment the "number of sequential leaves without a term" counter.
assert( p->id==GetCurrentThreadId() );
** Additional non-public SQLITE_PREPARE_* flags
xCheckReservedLock
Token text (not NULL terminated)
** Return UTF-16 encoded English language explanation of the most recent
** error.
Default values must be the same for all columns
************* Begin file sqliteLimit.h ************************************
Content of OLD.* table in triggers
SQL statement, UTF-8 encoded
unixInodeInfo that owns this SHM node
Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert()
Substitute the rowid (column -1) for the INTEGER PRIMARY KEY
Locate the table which we want to update.
** Make a transient copy of expression pExpr and then code it using
** sqlite3ExprCode(). This routine works just like sqlite3ExprCode()
** except that the input expression is guaranteed to be unchanged.
An INDEXED BY clause specifies a particular index to use
** Prepare the SQL statement in buffer zSql against database handle db.
** If successful, set *ppStmt to point to the new statement and return
** SQLITE_OK.
**
** Otherwise, if an error does occur, set *ppStmt to NULL and return
** an SQLite error code. Additionally, set output variable *pzErrmsg to
** point to a buffer containing an error message. It is the responsibility
** of the caller to (eventually) free this buffer using sqlite3_free().
** The interface to the LEMON-generated parser
** The "context" argument for an installable function. A pointer to an
** instance of this structure is the first argument to the routines used
** implement the SQL functions.
**
** There is a typedef for this structure in sqlite.h. So all routines,
** even the public interface to SQLite, can use a pointer to this structure.
** But this file is the only place where the internal details of this
** structure are known.
**
** This structure is defined inside of vdbeInt.h because it uses substructures
** (Mem) which are only defined there.
***************************** End Single-Threaded ************************
xUpdate
comment:
** Temporary files are named starting with this prefix followed by 16 random
** alphanumeric characters, and no file extension. They are stored in the
** OS's standard temporary file directory, and are deleted prior to exit.
** If sqlite is being embedded in another program, you may wish to change the
** prefix to reflect your program's name, so that if your program exits
** prematurely, old temporary files can be easily identified. This can be done
** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
**
** 2006-10-31: The default prefix used to be "sqlite_". But then
** Mcafee started using SQLite in their anti-virus product and it
** started putting files with the "sqlite" name in the c:/temp folder.
** This annoyed many windows users. Those users would then do a
** Google search for "sqlite", find the telephone numbers of the
** developers and call to wake them up at night and complain.
** For this reason, the default name prefix is changed to be "sqlite"
** spelled backwards. So the temp files are still identified, but
** anybody smart enough to figure out the code is also likely smart
** enough to know that calling the developer will not help get rid
** of the file.
label: code-design
** Meanings of bits in of pWalker->eCode for checkConstraintUnchanged()
Add "LIMIT -1 OFFSET $nOffset" to SELECT
Device characteristics
Name of this virtual file system
Uses an ephemeral index
Obtain the page from this cache
Record the number of times that we do a normal fsync() and
** FULLSYNC. This is used during testing to verify that this procedure
** gets called with the correct arguments.
Number of rows in table
The entry into which pNew is inserted
SetEndOfFile() returns non-zero when successful, or zero when it fails.
Key value (page number)
Number of slots allocated for Vdbe.aOp[]
** Create a new sqlite3_value object.
Name of file to delete when closing
Database holding shared memory
Size increases
Gather the schema version number for checking:
** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
** version is checked to ensure that the schema has not changed since the
** SQL statement was prepared.
The requested region is not mapped into this processes address space.
** Check to see if it has been allocated (i.e. if the wal-index file is
** large enough to contain the requested region).
String inserted after highlighted term
extended error code
Check the number of columns in this xPreUpdate call matches the
** number of columns in the table.
Expression to return via *ppNew
Next on the Parse.pZombieTab list
** This routine is a copy of the sqlite3FileSuffix3() routine from the core.
** It is a no-op unless SQLITE_ENABLE_8_3_NAMES is defined.
**
** If SQLITE_ENABLE_8_3_NAMES is set at compile-time and if the database
** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
** three characters, then shorten the suffix on z[] to be the last three
** characters of the original suffix.
**
** If SQLITE_ENABLE_8_3_NAMES is set to 2 at compile-time, then always
** do the suffix shortening regardless of URI parameter.
**
** Examples:
**
** test.db-journal => test.nal
** test.db-wal => test.wal
** test.db-shm => test.shm
** test.db-mj7f3319fa => test.9fa
Use index only - omit table
First byte of available memory space
synopsis: intkey=r[P3]
** Append a function parameter value to the JSON string under
** construction.
term sans prefix-byte
Start at the inner-most context and move outward until a match is found
Set to true when merge is finished
True if this is a TEMP table
D
** Maximum nesting depth of JSON for this implementation.
**
** This limit is needed to avoid a stack overflow in the recursive
** descent parser. A depth of 2000 is far deeper than any sane JSON
** should go.
Round the union size down to the nearest pointer boundary, since that's how
** it will be aligned within the Bitvec struct.
** xRowid - Return the current rowid for the cursor.
** Run a checkpoint on database iDb. This is a no-op if database iDb is
** not currently open in WAL mode.
**
** If a transaction is open on the database being checkpointed, this
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
** an error occurs while running the checkpoint, an SQLite error code is
** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
**
** The mutex on database handle db should be held by the caller. The mutex
** associated with the specific b-tree being checkpointed is taken by
** this function while the checkpoint is running.
**
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
** checkpointed. If an error is encountered it is returned immediately -
** no attempt is made to checkpoint any remaining databases.
**
** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
FuncDef wrapper for detachFunc() or attachFunc()
#include <stddef.h>
Number of remaining savepoints after this op.
** Start a statement subtransaction. The subtransaction can be rolled
** back independently of the main transaction. You must start a transaction
** before starting a subtransaction. The subtransaction is ended automatically
** if the main transaction commits or rolls back.
**
** Statement subtransactions are used around individual SQL statements
** that are contained within a BEGIN...COMMIT block. If a constraint
** error occurs within the statement, the effect of that one statement
** can be rolled back without having to rollback the entire transaction.
**
** A statement sub-transaction is implemented as an anonymous savepoint. The
** value passed as the second parameter is the total number of savepoints,
** including the new anonymous savepoint, open on the B-Tree. i.e. if there
** are no active savepoints and no other statement-transactions open,
** iStatement is 1. This anonymous savepoint can be released or rolled back
** using the sqlite3BtreeSavepoint() function.
Whenever Mem contains a valid string or blob representation, one of
** the following flags must be set to determine the memory management
** policy for Mem.z. The MEM_Term flag tells us whether or not the
** string is \000 or \u0000 terminated
** Systems that support the isnan() library function should probably
** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have
** found that many systems do not have a working isnan() function so
** this implementation is provided as an alternative.
**
** This NaN test sometimes fails if compiled on GCC with -ffast-math.
** On the other hand, the use of -ffast-math comes with the following
** warning:
**
** This option [-ffast-math] should never be turned on by any
** -O option since it can result in incorrect output for programs
** which depend on an exact implementation of IEEE or ISO
** rules/specifications for math functions.
**
** Under MSVC, this NaN test may fail if compiled with a floating-
** point precision mode other than /fp:precise. From the MSDN
** documentation:
**
** The compiler [with /fp:precise] will properly handle comparisons
** involving NaN. For example, x != x evaluates to true if x is NaN
** ...
** 2005 May 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the implementation of the sqlite3_prepare()
** interface, and routines that contribute to loading the database schema
** from disk.
with ::=
Opcode: Affinity P1 P2 * P4 *
** Synopsis: affinity(r[P1@P2])
**
** Apply affinities to a range of P2 registers starting with P1.
**
** P4 is a string that is P2 characters long. The N-th character of the
** string indicates the column affinity that should be used for the N-th
** memory cell in the range.
Only mark the value as an integer if
**
** (1) the round-trip conversion real->int->real is a no-op, and
** (2) The integer is neither the largest nor the smallest
** possible integer (ticket #3922)
**
** The second and third terms in the following conditional enforces
** the second condition under the assumption that addition overflow causes
** values to wrap around.
143
** Obtain a lock on the table whose root page is iTab. The
** lock is a write lock if isWritelock is true or a read lock
** if it is false.
Type code for object to destroy
Catch the case where the destination is an in-memory database and the
** page sizes of the source and destination differ.
Result accumulator
comment: The following "ifdef/elif/else/" block has the same structure as
** the one below. It is replicated here solely to avoid cluttering
** up the real code with the UNUSED_PARAMETER() macros.
label: code-design
Iterator to seek
Locale identifier - (eg. "jp_JP")
** This function is designed to be called from within a pre-update callback
** only. It returns zero if the change that caused the callback was made
** immediately by a user SQL statement. Or, if the change was made by a
** trigger program, it returns the number of trigger programs currently
** on the stack (1 for a top-level trigger, 2 for a trigger fired by a
** top-level trigger etc.).
**
** For the purposes of the previous paragraph, a foreign key CASCADE, SET NULL
** or SET DEFAULT action is considered a trigger.
Calculate the first block to use in the output segment
An SQL statement being run
All tables in the FROM clause
Number of table columns
Saved value of db->nTotalChange
Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
** is using a regular VFS, it is called after the corresponding
** transaction has been committed. Injecting a fault at this point
** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
** but the transaction is committed anyway.
**
** The core must call OsFileControl() though, not OsFileControlHint(),
** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
** means the commit really has failed and an error should be returned
** to the user.
Positions cannot be negative; we use -1 as a terminator internally.
** Tokens must have a non-zero length.
Check to see if flattening is permitted. Return 0 if not.
Ignore the MSVC warning about no initializer
If true, bias the search to the high end
Pointer to data for pPg
** 2008 Jan 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code to support the concept of "benign"
** malloc failures (when the xMalloc() or xRealloc() method of the
** sqlite3_mem_methods structure fails to allocate a block of memory
** and returns 0).
**
** Most malloc failures are non-benign. After they occur, SQLite
** abandons the current operation and returns an error code (usually
** SQLITE_NOMEM) to the user. However, sometimes a fault is not necessarily
** fatal. For example, if a malloc fails while resizing a hash table, this
** is completely recoverable simply by not carrying out the resize. The
** hash table will continue to function normally. So a malloc failure
** during a hash table resize is a benign fault.
Number of open cursors
Need to free the WhereTerm.u.pOrInfo object
Current value of the system call
xUnfetch
comment: Bytes of memory needed
label: code-design
Append a new column value, if necessary
** On systems with ample stack space and that support alloca(), make
** use of alloca() to obtain space for large automatic objects. By default,
** obtain space from malloc().
**
** The alloca() routine never returns NULL. This will cause code paths
** that deal with sqlite3StackAlloc() failures to be unreachable.
SQLITE_CONSTRAINT
refargs ::= refargs refarg
** This routine does the first phase of a two-phase commit. This routine
** causes a rollback journal to be created (if it does not already exist)
** and populated with enough information so that if a power loss occurs
** the database can be restored to its original state by playing back
** the journal. Then the contents of the journal are flushed out to
** the disk. After the journal is safely on oxide, the changes to the
** database are written into the database file and flushed to oxide.
** At the end of this call, the rollback journal still exists on the
** disk and we are still holding all locks, so the transaction has not
** committed. See sqlite3BtreeCommitPhaseTwo() for the second phase of the
** commit process.
**
** This call is a no-op if no write-transaction is currently active on pBt.
**
** Otherwise, sync the database file for the btree pBt. zMaster points to
** the name of a master journal file that should be written into the
** individual journal file, or is NULL, indicating no master journal file
** (single database transaction).
**
** When this is called, the master journal should already have been
** created, populated with this journal pointer and synced to disk.
**
** Once this is routine has returned, the only thing required to commit
** the write-transaction for this database file is to delete the journal.
Maximum allowed size of the database
Size in bytes
************* End of global.c *********************************************
Add the "COLLATE" clause to this expression
Non-zero to append " AND "
pNew->aFirst[]
Column to extract
comment: The busy callback
label: requirement
comment: Number of unused pcache slots
label: code-design
Duplicate of trigger WHEN expression
Jump here if LHS is not contained in the RHS
Index of aTree[] to recalculate
Cursor open on the btree to be searched
Unreachable
Cost of running this subquery
Unlock-notify cb to invoke
Information about an AUTOINCREMENT
comment:
** This version of balance() handles the common special case where
** a new entry is being inserted on the extreme right-end of the
** tree, in other words, when the new entry will become the largest
** entry in the tree.
**
** Instead of trying to balance the 3 right-most leaf pages, just add
** a new page to the right-hand side and put the one new entry in
** that page. This leaves the right side of the tree somewhat
** unbalanced. But odds are that we will be inserting new entries
** at the end soon afterwards so the nearly empty page will quickly
** fill up. On average.
**
** pPage is the leaf page which is the right-most page in the tree.
** pParent is its parent. pPage must have a single overflow entry
** which is also the right-most entry on the page.
**
** The pSpace buffer is used to store a temporary copy of the divider
** cell that will be inserted into pParent. Such a cell consists of a 4
** byte page number followed by a variable length integer. In other
** words, at most 13 bytes. Hence the pSpace buffer must be at
** least 13 bytes in size.
label: code-design
RHS always has 2 or more terms... The parser
** changes "x IN (?)" into "x=?".
** The set of routines that implement the porter-stemmer tokenizer
The page data
Reset the return code so as not to report a checkpoint failure
** just because there are active readers.
Open existing file, or create if it doesn't exist
** Add an INDEXED BY or NOT INDEXED clause to the most recently added
** element of the source-list passed as the second argument.
** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
** non-zero if there is no match.
Destination journal mode
Sorter for "ORDER BY rank" queries
Number of non-transaction savepoints
Variable iNewStart now contains the first valid leaf node.
Number of rows in the table
Value to append to data
Call the parser to process a CREATE TABLE, INDEX or VIEW.
** But because db->init.busy is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
** structures that describe the table, index, or view.
The underlying database file
comment: FIXME: If Windows truly always prevents truncating or deleting a
** file while a mapping is held, then the following winUnmapfile() call
** is unnecessary can be omitted - potentially improving
** performance.
label: code-design
234
Largest block id written to database
** Free all resources associated with the IncrMerger object indicated by
** the first argument.
Add any overflow cells
** Allowed values for Index.idxType
Opcode: IsNull P1 P2 * * *
** Synopsis: if r[P1]==NULL goto P2
**
** Jump to P2 if the value in register P1 is NULL.
The results of parsing supported FTS4 key=value options:
But not in this one
** Given the page number of an overflow page in the database (parameter
** ovfl), this function finds the page number of the next page in the
** linked list of overflow pages. If possible, it uses the auto-vacuum
** pointer-map data instead of reading the content of page ovfl to do so.
**
** If an error occurs an SQLite error code is returned. Otherwise:
**
** The page number of the next overflow page in the linked list is
** written to *pPgnoNext. If page ovfl is the last page in its linked
** list, *pPgnoNext is set to zero.
**
** If ppPage is not NULL, and a reference to the MemPage object corresponding
** to page number pOvfl was obtained, then *ppPage is set to point to that
** reference. It is the responsibility of the caller to call releasePage()
** on *ppPage to free the reference. In no reference was obtained (because
** the pointer-map was used to obtain the value for *pPgnoNext), then
** *ppPage is set to zero.
The replacement string C
Current innermost WITH clause
Database handle doing sort
New tokenizer object
0 means "unknown at compile-time"
** The following are special cases for mutex enter routines for use
** in single threaded applications that use shared cache. Except for
** these two routines, all mutex operations are no-ops in that case and
** are null #defines in btree.h.
**
** If shared cache is disabled, then all btree mutex routines, including
** the ones below, are no-ops and are null #defines in btree.h.
Compiled "PRAGMA %Q.page_size" statement
Dummy argument used with xNext()
Number of subqueries
Restriction (14)
Largest aReadMark[] value
This module is only called on query plans that use an index.
As it happens, the pending terms table is always empty here. This is
** because an "ALTER TABLE RENAME TABLE" statement inside a transaction
** always opens a savepoint transaction. And the xSavepoint() method
** flushes the pending terms table. But leave the (no-op) call to
** PendingTermsFlush() in in case that changes.
Value of 'unused' column
If none of the above worked, then we fail.
Add the entry to the stat1 table.
Expected number of pages in the list
Bit values for the JsonNode.jnFlag field
** WinCE lacks native support for file locking so we have to fake it
** with some code of our own.
** Compute the column names for a SELECT statement.
**
** The only guarantee that SQLite makes about column names is that if the
** column has an AS clause assigning it a name, that will be the name used.
** That is the only documented guarantee. However, countless applications
** developed over the years have made baseless assumptions about column names
** and will break if those assumptions changes. Hence, use extreme caution
** when modifying this routine to avoid breaking legacy.
**
** See Also: sqlite3ColumnsFromExprList()
**
** The PRAGMA short_column_names and PRAGMA full_column_names settings are
** deprecated. The default setting is short=ON, full=OFF. 99.9% of all
** applications should operate this way. Nevertheless, we need to support the
** other modes for legacy:
**
** short=OFF, full=OFF: Column name is the text of the expression has it
** originally appears in the SELECT statement. In
** other words, the zSpan of the result expression.
**
** short=ON, full=OFF: (This is the default setting). If the result
** refers directly to a table column, then the result
** column name is just the table column name: COLUMN.
** Otherwise use zSpan.
**
** full=ON, short=ANY: If the result refers directly to a table column,
** then the result column name with the table name
** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.
** PRAGMA [schema.]journal_mode
** PRAGMA [schema.]journal_mode =
** (delete|persist|off|truncate|memory|wal|off)
A list of all open cursors
The next table maps tokens (terminal symbols) into fallback tokens.
** If a construct like the following:
**
** %fallback ID X Y Z.
**
** appears in the grammar, then ID becomes a fallback token for X, Y,
** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
** but it does not parse, the type of the token is changed to ID and
** the parse is retried before an error is thrown.
**
** This feature can be used, for example, to cause some keywords in a language
** to revert to identifiers if they keyword does not apply in the context where
** it appears.
** Token types used by the sqlite3_complete() routine. See the header
** comments on that procedure for additional information.
Jump here to continue with next record
Add the "eNNN" suffix
Pointer type when MEM_Term|MEM_Subtype|MEM_Null
Register holding an index key
Number of pages still on the free-list
The VDBE cursor for the table
One byte past the end of usable data
A view
Dummy argument used with tokenizer
Buffer to load data from wal file into
** Return the length of the data corresponding to the supplied serial-type.
True if statement may throw an ABORT exception
Remove the node from the in-memory hash table and link it into
** the Rtree.pDeleted list. Its contents will be re-inserted later on.
Number of elements in argv[]
Pointer to write buffer
Current offset within aInput[]
** The default MMAP_SIZE is zero on all platforms. Or, even if a larger
** default MMAP_SIZE is specified at compile-time, make sure that it does
** not exceed the maximum mmap size.
Called during startup to register a UDF with SQLite
deadman switch
True to use xFetch()
Token pList/nList corresponds to
Opcode: VCreate P1 P2 * * *
**
** P2 is a register that holds the name of a virtual table in database
** P1. Call the xCreate method for that table.
Index structure corresponding to u1.zIndexedBy
Database Name Table Name
First argument passed to xFilter
The whole SELECT statement
Page iter.iLeaf must now be the rightmost leaf-page in the segment
** Return the number of cursors open on pBt. This is for use
** in assert() expressions, so it is only compiled if NDEBUG is not
** defined.
**
** Only write cursors are counted if wrOnly is true. If wrOnly is
** false then all cursors are counted.
**
** For the purposes of this routine, a cursor is any cursor that
** is capable of reading or writing to the database. Cursors that
** have been tripped into the CURSOR_FAULT state are not counted.
Opcode: IdxRowid P1 P2 * * *
** Synopsis: r[P2]=rowid
**
** Write into register P2 an integer which is the last entry in the record at
** the end of the index key pointed to by cursor P1. This integer should be
** the rowid of the table entry to which this index entry points.
**
** See also: Rowid, MakeRecord.
Number of fragments in this snippet
FROM clause does not contain a real table
** An object of this type is used internally as an abstraction for
** input data. Input data may be supplied either as a single large buffer
** (e.g. sqlite3changeset_start()) or using a stream function (e.g.
** sqlite3changeset_start_strm()).
(316) foreach_clause ::= FOR EACH ROW
The "real" underlying VFS
This is either a full-table scan (ePlan==FTS5_PLAN_SCAN) or a lookup
** by rowid (ePlan==FTS5_PLAN_ROWID).
In this case, the RHS is the ROWID of table b-tree and so we also
** know that the RHS is non-NULL. Hence, we combine steps 3 and 4
** into a single opcode.
One or both operands are NULL
Name of the file containing the BTree database
pParent->pLeft==this or pParent->pRight==this
** Bits that make up the "idxNum" parameter passed indirectly by
** xBestIndex() to xFilter().
comment:
** A version of printf() that understands %lld. Used for debugging.
** The printf() built into some versions of windows does not understand %lld
** and segfaults if you give it a long long int.
label: code-design
One for every 32KB page in the wal-index
At least one of the two values is a number
** Return the total number of segments in index structure pStruct. This
** function is only ever used as part of assert() conditions.
Obscure case for non-leaf-data trees: If the cell at pCell was
** previously stored on a leaf node, and its reported size was 4
** bytes, then it may actually be smaller than this
** (see btreeParseCellPtr(), 4 bytes is the minimum size of
** any cell). But it is important to pass the correct size to
** insertCell(), so reparse the cell now.
**
** This can only happen for b-trees used to evaluate "IN (SELECT ...)"
** and WITHOUT ROWID tables with exactly one column which is the
** primary key.
FTS Table pointer
The last prior entry
** Load the sqlite3.iSysErrno field if that is an appropriate thing
** to do based on the SQLite error code in rc.
294
EVIDENCE-OF: R-08404-60887 There are three arguments to
** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
** which the scratch allocations will be drawn, the size of each scratch
** allocation (sz), and the maximum number of scratch allocations (N).
comment: The following macro is used to suppress compiler warnings.
label: code-design
Size of the database file
Information about this WHERE
** Given that zWal points to a buffer containing a wal file name passed to
** either the xOpen() or xAccess() VFS method, return a pointer to the
** file-handle opened by the same database connection on the corresponding
** database file.
39==sqlite3LogEst(15)
** Head and tail of a linked list of all outstanding allocations
Number of open savepoints (0 -> none)
Raw hash value of the key
** Write the supplied master journal name into the journal file for pager
** pPager at the current location. The master journal name must be the last
** thing written to a journal file. If the pager is in full-sync mode, the
** journal file descriptor is advanced to the next sector boundary before
** anything is written. The format is:
**
** + 4 bytes: PAGER_MJ_PGNO.
** + N bytes: Master journal filename in utf-8.
** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
** + 4 bytes: Master journal name checksum.
** + 8 bytes: aJournalMagic[].
**
** The master journal page checksum is the sum of the bytes in the master
** journal name, where each byte is interpreted as a signed 8-bit integer.
**
** If zMaster is a NULL pointer (occurs for a single database transaction),
** this call is a no-op.
Second sorted list to be merged
ESCAPE
** Historically, SQLite has used both the LockFile and LockFileEx functions.
** When the LockFile function was used, it was always expected to fail
** immediately if the lock could not be obtained. Also, it always expected to
** obtain an exclusive lock. These flags are used with the LockFileEx function
** and reflect those expectations; therefore, they should not be changed.
IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
** built-in default page cache is used instead of the application defined
** page cache.
Less than 19 digits, so we know that it fits in 64 bits
The principle used to locate the table name in the CREATE TABLE
** statement is that the table name is the first non-space token that
** is immediately followed by a TK_LP or TK_USING token.
comment: #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED
label: code-design
The result set must be the special operator "*"
** The following structure describes the FROM clause of a SELECT statement.
** Each table or subquery in the FROM clause is a separate element of
** the SrcList.a[] array.
**
** With the addition of multiple database support, the following structure
** can also be used to describe a particular table such as the table that
** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
** such a table must be a simple name: ID. But in SQLite, the table can
** now be identified by a database name, a dot, then the table name: ID.ID.
**
** The jointype starts out showing the join type between the current table
** and the next table on the list. The parser builds the list this way.
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
** jointype expresses the join between the table and the previous table.
**
** In the colUsed field, the high-order bit (bit 63) is set if the table
** contains more than 63 columns and the 64-th or later column is used.
Term.pExpr contains a correlated sub-query
If a prior error occurred, report that error again.
comment:
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
** afterward. Having this macro allows us to cause the C compiler
** to omit code used by TEMP tables without messy #ifndef statements.
label: code-design
Total number of tokens in cluster
Update statements used while promoting segments
** Delete an entire SrcList including all its substructure.
1300
Maximum value
If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
** new terms for each component comparison - "a = ?" and "b = ?". The
** new terms completely replace the original vector comparison, which is
** no longer used.
**
** This is only required if at least one side of the comparison operation
** is not a sub-select.
comment:
** Routine needed to support the testcase() macro.
label: test
Incremental vacuum
** Implementation of the sqlite3_pcache.xPagecount method.
Size of suffix (nTerm - nPrefix)
Find a node to store this cell in. pNode->iNode currently contains
** the height of the sub-tree headed by the cell.
Number of entrances
(286) nm ::= ID|INDEXED
comment:
** The following macros are used to suppress compiler warnings and to
** make it clear to human readers when a function parameter is deliberately
** left unused within the body of a function. This usually happens when
** a function is called via a function pointer. For example the
** implementation of an SQL aggregate step callback may not use the
** parameter indicating the number of arguments passed to the aggregate,
** if it knows that this is enforced elsewhere.
**
** When a function parameter is not used at all within the body of a function,
** it is generally named "NotUsed" or "NotUsed2" to make things even clearer.
** However, these macros may also be used to suppress warnings related to
** parameters that may or may not be used depending on compilation options.
** For example those parameters only used in assert() statements. In these
** cases the parameters are named as per the usual conventions.
label: code-design
Different columns indexed
** Routines used to compute the sum, average, and total.
**
** The SUM() function follows the (broken) SQL standard which means
** that it returns NULL if it sums over no inputs. TOTAL returns
** 0.0 in that case. In addition, TOTAL always returns a float where
** SUM might return an integer if it never encounters a floating point
** value. TOTAL never fails, but SUM might through an exception if
** it overflows an integer.
** Allocate and return an RBU handle with all fields zeroed except for the
** error code, which is set to SQLITE_MISUSE.
The uptr type is an unsigned integer large enough to hold a pointer
** This function is called for each Fts3Phrase in a full-text query
** expression to initialize the mechanism for returning rows. Once this
** function has been called successfully on an Fts3Phrase, it may be
** used with fts3EvalPhraseNext() to iterate through the matching docids.
**
** If parameter bOptOk is true, then the phrase may (or may not) use the
** incremental loading strategy. Otherwise, the entire doclist is loaded into
** memory within this call.
**
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
File handle we are reading from
Size of this allocation
The new AtoF never returns NaN
The PRIMARY KEY index on the table
Set properties of a table column based on the (magical)
** name of the column.
If it has not already been created, create the rbu_state table
The default collating sequence (BINARY)
SQLITE_OMIT_INCRBLOB
** Allocate a new MergeEngine object to merge the contents of nPMA level-0
** PMAs from pTask->file. If no error occurs, set *ppOut to point to
** the new object and return SQLITE_OK. Or, if an error does occur, set *ppOut
** to NULL and return an SQLite error code.
**
** When this function is called, *piOffset is set to the offset of the
** first PMA to read from pTask->file. Assuming no error occurs, it is
** set to the offset immediately following the last byte of the last
** PMA before returning. If an error does occur, then the final value of
** *piOffset is undefined.
The key to seek for
Array of segments. aSeg[0] is oldest.
******** Begin destructor definitions **************************************
minus_num ::= MINUS INTEGER|FLOAT
** Parameter zName is the name of a table that is about to be altered
** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).
** If the table is a system table, this function leaves an error message
** in pParse->zErr (system tables may not be altered) and returns non-zero.
**
** Or, if zName is not a system table, zero is returned.
** CAPI3REF: Enable Or Disable Shared Pager Cache
**
** ^(This routine enables or disables the sharing of the database cache
** and schema data structures between [database connection | connections]
** to the same database. Sharing is enabled if the argument is true
** and disabled if the argument is false.)^
**
** ^Cache sharing is enabled and disabled for an entire process.
** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
** In prior versions of SQLite,
** sharing was enabled or disabled for each thread separately.
**
** ^(The cache sharing mode set by this interface effects all subsequent
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
** Existing database connections continue use the sharing mode
** that was in effect at the time they were opened.)^
**
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
** successfully. An [error code] is returned otherwise.)^
**
** ^Shared cache is disabled by default. But this might change in
** future releases of SQLite. Applications that care about shared
** cache setting should set it explicitly.
**
** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
** and will always return SQLITE_MISUSE. On those systems,
** shared cache mode should be enabled per-database connection via
** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
**
** This interface is threadsafe on processors where writing a
** 32-bit integer is atomic.
**
** See Also: [SQLite Shared-Cache Mode]
296
For looping through pKeyInfo->aColl[]
314
242
Make the new connection a child of the winShmNode
Update anDLt[], anLt[] and anEq[] to reflect the values that apply
** to the current row of the index.
Number of function arguments
** Process an UPDATE statement.
**
** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL;
** \_______/ \________/ \______/ \________________/
* onError pTabList pChanges pWhere
Opcode: Real * P2 * P4 *
** Synopsis: r[P2]=P4
**
** P4 is a pointer to a 64-bit floating point value.
** Write that value into register P2.
The boolean index is empty
Number of users of this page
Do not allow IS constraints from the WHERE clause to be used by the
** right table of a LEFT JOIN. Only constraints in the ON clause are
** allowed
** The following global variable is incremented whenever the library
** attempts to open a temporary file. This information is used for
** testing and analysis only.
** 2008 August 16
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for walking the parser tree for
** an SQL statement.
comment:
** CAPI3REF: Invert A Changeset
**
** This function is used to "invert" a changeset object. Applying an inverted
** changeset to a database reverses the effects of applying the uninverted
** changeset. Specifically:
**
** <ul>
** <li> Each DELETE change is changed to an INSERT, and
** <li> Each INSERT change is changed to a DELETE, and
** <li> For each UPDATE change, the old.* and new.* values are exchanged.
** </ul>
**
** This function does not change the order in which changes appear within
** the changeset. It merely reverses the sense of each individual change.
**
** If successful, a pointer to a buffer containing the inverted changeset
** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
** zeroed and an SQLite error code returned.
**
** It is the responsibility of the caller to eventually call sqlite3_free()
** on the *ppOut pointer to free the buffer allocation following a successful
** call to this function.
**
** WARNING/TODO: This function currently assumes that the input is a valid
** changeset. If it is not, the results are undefined.
label: code-design
Append the new shared library handle to the db->aExtension array.
Key information
69
If no error has occurred so far, check if the "number of entries"
** field on the node is too large. If so, set the return code to
** SQLITE_CORRUPT_VTAB.
** Open a new iterator to iterate though all rowid that match the
** specified token or token prefix.
Extra bits for pNew->eOperator
Loop through the elements that will make up the record to figure
** out how much space is required for the new record.
EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
** an error.
SQLITE_CORRUPT
1480
012345678901234567
Indicate VList may no longer be enlarged
Memory cell used for the row counter
Argument to the deferred sqlite3BtreeMoveto()
Is an alias for a result set column
Unique index on parent key columns in pTab
0
comment:
** Try to obtain a page from the cache.
**
** This routine returns a pointer to an sqlite3_pcache_page object if
** such an object is already in cache, or if a new one is created.
** This routine returns a NULL pointer if the object was not in cache
** and could not be created.
**
** The createFlags should be 0 to check for existing pages and should
** be 3 (not 1, but 3) to try to create a new page.
**
** If the createFlag is 0, then NULL is always returned if the page
** is not already in the cache. If createFlag is 1, then a new page
** is created only if that can be done without spilling dirty pages
** and without exceeding the cache size limit.
**
** The caller needs to invoke sqlite3PcacheFetchFinish() to properly
** initialize the sqlite3_pcache_page object and convert it into a
** PgHdr object. The sqlite3PcacheFetch() and sqlite3PcacheFetchFinish()
** routines are split this way for performance reasons. When separated
** they can both (usually) operate without having to push values to
** the stack on entry and pop them back off on exit, which saves a
** lot of pushing and popping.
label: code-design
************* Begin file fts3_hash.c **************************************
** Return the affinity for a single column of an index.
(282) savepoint_opt ::=
Any kind of inner or cross join
A minimum of one cursor is required if autoincrement is used
* See ticket [a696379c1f08866]
350
Tokenizer implementation
PRIMARY KEY changed in a WITHOUT ROWID table
Values extracted from pExpr
227
Bitmask of phrases seen by BestSnippet()
True for a >= search
comment:
** Run the parser on the given SQL string. The parser structure is
** passed in. An SQLITE_ status code is returned. If an error occurs
** then an and attempt is made to write an error message into
** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
** error message.
label: code-design
Only a BTREE_SINGLE database can be BTREE_UNORDERED
expr ::= expr in_op LP exprlist RP
** The implementation of an SQLite user-defined-function that accepts a
** single integer as an argument. If the integer is an alpha-numeric
** unicode code point, 1 is returned. Otherwise 0.
System page size
comment: Assigned value is never used
label: code-design
** Takes an open conch file, copies the contents to a new path and then moves
** it back. The newly created file's file descriptor is assigned to the
** conch file structure and finally the original conch file descriptor is
** closed. Returns zero if successful.
Wait a little before trying again
Check the content overflow list
Try to open on pSnapshot when the next read-transaction starts
** Implementation of the sqlite_log() function. This is a wrapper around
** sqlite3_log(). The return value is NULL. The function exists purely for
** its side-effects.
idx = biasRight ? upr : (lwr+upr)/2;
** Generate deferred-doclists for all tokens in the pCsr->pDeferred list
** based on the row that pCsr currently points to.
**
** A deferred-doclist is like any other doclist with position information
** included, except that it only contains entries for a single row of the
** table, not for all rows.
** Number of freelist hash slots
pLoop->nOut should not exceed nRow-iReduce
SQL_SHIFT_SEGDIR_ENTRY
** Modify the idx value for the segment with idx=:3 on absolute level :2
** to :1.
EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
** unsigned integer value that specifies the maximum size of the created
** heap.
Label resolved to end of generated code
Loop counter: Foreign key number for pTab
** If possible, return a pointer to a mapping of file fd starting at offset
** iOff. The mapping must be valid for at least nAmt bytes.
**
** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
** Finally, if an error does occur, return an SQLite error code. The final
** value of *pp is undefined in this case.
**
** If this function does return a pointer, the caller must eventually
** release the reference by calling winUnfetch().
******************************* End Win32 Threads ************************
Constraint operator
cmd ::= ALTER TABLE fullname RENAME TO nm
Load the lowest cost path into pWInfo
************* Begin file stmt.c *******************************************
Release the array of temp registers
comment: It is possible that there is a checkpointer thread running
** concurrent with this code. If this is the case, it may be that the
** checkpointer has already determined that it will checkpoint
** snapshot X, where X is later in the wal file than pSnapshot, but
** has not yet set the pInfo->nBackfillAttempted variable to indicate
** its intent. To avoid the race condition this leads to, ensure that
** there is no checkpointer process by taking a shared CKPT lock
** before checking pInfo->nBackfillAttempted.
**
** TODO: Does the aReadMark[] lock prevent a checkpointer from doing
** this already?
label: code-design
The VDBE cursor that implements the sort
Jump to this label on an OE_Ignore resolution
Index of the term to be analyzed
Top of the rowid change constraint check
Arg passed to comparison function
STRACCUM_NOMEM or STRACCUM_TOOBIG
defined(_MSC_VER)
#include <string.h>
Number of CTEs in the WITH clause
pageno
The user should invoke this in one of two forms:
**
** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table);
** CREATE VIRTUAL TABLE xxx USING fts4aux(fts4-table-db, fts4-table);
Bytes allocated at pCsr->apSegment[]
Writer object
10
Opcode: Lt P1 P2 P3 P4 P5
** Synopsis: IF r[P3]<r[P1]
**
** Compare the values in register P1 and P3. If reg(P3)<reg(P1) then
** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5 store
** the result of comparison (0 or 1 or NULL) into register P2.
**
** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
** reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
** bit is clear then fall through if either operand is NULL.
**
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
** to coerce both inputs according to this affinity before the
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
** affinity is used. Note that the affinity conversions are stored
** back into the input registers P1 and P3. So this opcode can cause
** persistent changes to registers P1 and P3.
**
** Once any conversions have taken place, and neither value is NULL,
** the values are compared. If both values are blobs then memcmp() is
** used to determine the results of the comparison. If both values
** are text, then the appropriate collating function specified in
** P4 is used to do the comparison. If P4 is not specified then
** memcmp() is used to compare text string. If both values are
** numeric, then a numeric comparison is used. If the two values
** are of different types, then numbers are considered less than
** strings and strings are considered less than blobs.
Distance from left to right (1=adjacent)
same as TK_NOT, synopsis: r[P2]= !r[P1]
620
Size of buffer zRoot
Number of bytes in header
** Triggers may access values stored in the old.* or new.* pseudo-table.
** This function returns a 32-bit bitmask indicating which columns of the
** old.* or new.* tables actually are used by triggers. This information
** may be used by the caller, for example, to avoid having to load the entire
** old.* record into memory when executing an UPDATE or DELETE command.
**
** Bit 0 of the returned mask is set if the left-most column of the
** table may be accessed using an [old|new].<col> reference. Bit 1 is set if
** the second leftmost column value is required, and so on. If there
** are more than 32 columns in the table, and at least one of the columns
** with an index greater than 32 may be accessed, 0xffffffff is returned.
**
** It is not possible to determine if the old.rowid or new.rowid column is
** accessed by triggers. The caller must always assume that it is.
**
** Parameter isNew must be either 1 or 0. If it is 0, then the mask returned
** applies to the old.* table. If 1, the new.* table.
**
** Parameter tr_tm must be a mask with one or both of the TRIGGER_BEFORE
** and TRIGGER_AFTER bits set. Values accessed by BEFORE triggers are only
** included in the returned mask if the TRIGGER_BEFORE bit is set in the
** tr_tm parameter. Similarly, values accessed by AFTER triggers are only
** included in the returned mask if the TRIGGER_AFTER bit is set in tr_tm.
Original number of pages in file
If pList==0, it means this routine was called to make a primary
** key out of the last column added to the table under construction.
** So create a fake list to simulate this.
Register holding NULL status. See notes
comment:
** 2007 August 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains low-level memory allocation drivers for when
** SQLite will use the standard C-library malloc/realloc/free interface
** to obtain the memory it needs.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object. The content of
** this file is only used if SQLITE_SYSTEM_MALLOC is defined. The
** SQLITE_SYSTEM_MALLOC macro is defined automatically if neither the
** SQLITE_MEMDEBUG nor the SQLITE_WIN32_MALLOC macros are defined. The
** default configuration is to use memory allocation routines in this
** file.
**
** C-preprocessor macro summary:
**
** HAVE_MALLOC_USABLE_SIZE The configure script sets this symbol if
** the malloc_usable_size() interface exists
** on the target platform. Or, this symbol
** can be set manually, if desired.
** If an equivalent interface exists by
** a different name, using a separate -D
** option to rename it.
**
** SQLITE_WITHOUT_ZONEMALLOC Some older macs lack support for the zone
** memory allocator. Set this symbol to enable
** building on older macs.
**
** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of
** _msize() on windows systems. This might
** be necessary when compiling for Delphi,
** for example.
label: code-design
** Check that argument nHeight is less than or equal to the maximum
** expression depth allowed. If it is not, leave an error message in
** pParse.
** Interpret the given string as a temp db location. Return 1 for file
** backed temporary databases, 2 for the Red-Black tree in memory database
** and 0 to use the compile-time default.
** This routine sets the state to CURSOR_FAULT and the error
** code to errCode for every cursor on any BtShared that pBtree
** references. Or if the writeOnly flag is set to 1, then only
** trip write cursors and leave read cursors unchanged.
**
** Every cursor is a candidate to be tripped, including cursors
** that belong to other database connections that happen to be
** sharing the cache with pBtree.
**
** This routine gets called when a rollback occurs. If the writeOnly
** flag is true, then only write-cursors need be tripped - read-only
** cursors save their current positions so that they may continue
** following the rollback. Or, if writeOnly is false, all cursors are
** tripped. In general, writeOnly is false if the transaction being
** rolled back modified the database schema. In this case b-tree root
** pages may be moved or deleted from the database altogether, making
** it unsafe for read cursors to continue.
**
** If the writeOnly flag is true and an error is encountered while
** saving the current position of a read-only cursor, all cursors,
** including all read-cursors are tripped.
**
** SQLITE_OK is returned if successful, or if an error occurs while
** saving a cursor position, an SQLite error code.
Set rCostIdx to the cost of visiting selected rows in index. Add
** it to pNew->rRun, which is currently set to the cost of the index
** seek only. Then, if this is a non-covering index, add the cost of
** visiting the rows in the main table.
nothing to do if the path is NULL, :auto: or matches the existing path
Number of key columns in pIndex
min(maxLocal,127)
We should never write to the journal file the page that
** contains the database locks. The following assert verifies
** that we do not.
Free memory immediately, rather than waiting on sqlite3_finalize()
** Move the write position of the WAL back to the point identified by
** the values in the aWalData[] array. aWalData must point to an array
** of WAL_SAVEPOINT_NDATA u32 values that has been previously populated
** by a call to WalSavepoint().
The trigger that this step is a part of
Cannot have C without B
True if nTotalRow/aTotalSize[] are valid
Current index in aLeft
** Table p is a virtual table. This function moves all elements in the
** p->pVTable list to the sqlite3.pDisconnect lists of their associated
** database connections to be disconnected at the next opportunity.
** Except, if argument db is not NULL, then the entry associated with
** connection db is left in the p->pVTable list.
Insert into rbu_tmp_$zDataTbl
Normally sqlite3SelectExpand() will be called first and will have
** already expanded this SELECT. However, if this is a subquery within
** an expression, sqlite3ResolveExprNames() will be called without a
** prior call to sqlite3SelectExpand(). When that happens, let
** sqlite3SelectPrep() do all of the processing for this SELECT.
** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
** this routine in the correct order.
WAL savepoint context
Token:
Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
** each VDBE opcode.
**
** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
** comments in VDBE programs that show key decision points in the code
** generator.
52
Upper bound on the range. ex: "x<455" Might be NULL
The virtual database engine
Index of langid=x constraint, if present
** Set the bit number pgno in the PagerSavepoint.pInSavepoint
** bitvecs of all open savepoints. Return SQLITE_OK if successful
** or SQLITE_NOMEM if a malloc failure occurs.
0x7FFFFFFF is the hard limit for the number of pages in a database
** file. By passing this as the number of pages to copy to
** sqlite3_backup_step(), we can guarantee that the copy finishes
** within a single call (unless an error occurs). The assert() statement
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
** or an error code.
Get the database meta information.
**
** Meta values are as follows:
** meta[0] Schema cookie. Changes with each schema change.
** meta[1] File format of schema layer.
** meta[2] Size of the page cache.
** meta[3] Largest rootpage (auto/incr_vacuum mode)
** meta[4] Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
** meta[5] User version
** meta[6] Incremental vacuum mode
** meta[7] unused
** meta[8] unused
** meta[9] unused
**
** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4].
1st argument to callback
Make a copy of an sqlite3_value object
** This routine deletes the RtreeGeomCallback object that was attached
** one of the SQL functions create by sqlite3_rtree_geometry_callback()
** or sqlite3_rtree_query_callback(). In other words, this routine is the
** destructor for an RtreeGeomCallback objecct. This routine is called when
** the corresponding SQL function is deleted.
Mutex configuration options are only available in a threadsafe
** compile.
Right hand side of comparison
Type of the new cursor
SQLITE_OMIT_VIRTUALTABLE
First byte of token
************* Begin file backup.c *****************************************
** The rbu_state table is used to save the state of a partially applied
** update so that it can be resumed later. The table consists of integer
** keys mapped to values as follows:
**
** RBU_STATE_STAGE:
** May be set to integer values 1, 2, 4 or 5. As follows:
** 1: the *-rbu file is currently under construction.
** 2: the *-rbu file has been constructed, but not yet moved
** to the *-wal path.
** 4: the checkpoint is underway.
** 5: the rbu update has been checkpointed.
**
** RBU_STATE_TBL:
** Only valid if STAGE==1. The target database name of the table
** currently being written.
**
** RBU_STATE_IDX:
** Only valid if STAGE==1. The target database name of the index
** currently being written, or NULL if the main table is currently being
** updated.
**
** RBU_STATE_ROW:
** Only valid if STAGE==1. Number of rows already processed for the current
** table/index.
**
** RBU_STATE_PROGRESS:
** Trbul number of sqlite3rbu_step() calls made so far as part of this
** rbu update.
**
** RBU_STATE_CKPT:
** Valid if STAGE==4. The 64-bit checksum associated with the wal-index
** header created by recovering the *-wal file. This is used to detect
** cases when another client appends frames to the *-wal file in the
** middle of an incremental checkpoint (an incremental checkpoint cannot
** be continued if this happens).
**
** RBU_STATE_COOKIE:
** Valid if STAGE==1. The current change-counter cookie value in the
** target db file.
**
** RBU_STATE_OALSZ:
** Valid if STAGE==1. The size in bytes of the *-oal file.
The subquery
True for "patchset", 0 for "changeset"
Current number of cells in pNode
from vdbeSortSubtaskMain()
Language id to query
185
** CAPI3REF: Find the next prepared statement
** METHOD: sqlite3
**
** ^This interface returns a pointer to the next [prepared statement] after
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
** then this interface returns a pointer to the first prepared statement
** associated with the database connection pDb. ^If no prepared statement
** satisfies the conditions of this routine, it returns NULL.
**
** The [database connection] pointer D in a call to
** [sqlite3_next_stmt(D,S)] must refer to an open database
** connection and in particular must not be a NULL pointer.
Length of the next token token
Zero the output variables in case an error occurs. If this session
** object is already in the error state (sqlite3_session.rc != SQLITE_OK),
** this call will be a no-op.
Which columns are used by this index. 1st is 0
Array of flags, set on NOT NULL columns
1500
** End of MatchinfoBuffer code.
************************************************************************
Log the error, but continue normal operation using xRead/xWrite
** Return a static string containing the name corresponding to the error code
** specified in the argument.
480
0x20 .. 0x2F
De-reference and close our copy of the shared memory handle
comment: Sync the journal file and write all dirty pages to the database.
** If the atomic-update optimization is being used, this sync will not
** create the journal file or perform any real IO.
**
** Because the change-counter page was just modified, unless the
** atomic-update optimization is used it is almost certain that the
** journal requires a sync here. However, in locking_mode=exclusive
** on a system under memory pressure it is just possible that this is
** not the case. In this case it is likely enough that the redundant
** xSync() call will be changed to a no-op by the OS anyhow.
label: code-design
The cursor to seek
*********** End %parse_failure code ****************************************
Cached OP_Column parse information is only valid if cacheStatus matches
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
** the cache is out of date.
The P3 operand
Old value for iStartBlock
Argument set
For looping over result columns
Write all frames into the log file exactly once
comment:
** The "printf" code that follows dates from the 1980's. It is in
** the public domain.
**
**************************************************************************
**
** This file contains code for a set of "printf"-like routines. These
** routines format strings much like the printf() from the standard C
** library, though the implementation here has enhancements to support
** SQLite.
label: code-design
Remove all pages with pgno>x. Reset the cache if x==0
comment: Return TRUE if Mem X contains dynamically allocated content - anything
** that needs to be deallocated to avoid a leak.
label: code-design
** An instance of this function is used to merge together the (potentially
** large number of) doclists for each term that matches a prefix query.
** See function fts3TermSelectMerge() for details.
200
Allocated entries
Retrieve matchinfo() data.
Number of rows for a single term
Canonical data cursor (main table or PK index)
Opcode: OffsetLimit P1 P2 P3 * *
** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
**
** This opcode performs a commonly used computation associated with
** LIMIT and OFFSET process. r[P1] holds the limit counter. r[P3]
** holds the offset counter. The opcode computes the combined value
** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
** value computed is the total number of rows that will need to be
** visited in order to complete the query.
**
** If r[P3] is zero or negative, that means there is no OFFSET
** and r[P2] is set to be the value of the LIMIT, r[P1].
**
** if r[P1] is zero or negative, that means there is no LIMIT
** and r[P2] is set to -1.
**
** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
The database being vacuumed
same as TK_CONCAT, in1, in2, out3
In case an error occurs
iCol must be less than p->pEList->nExpr. Otherwise an error would
** have been thrown during name resolution and we would not have gotten
** this far
SQLITE_OMIT_LOAD_EXTENSION
75
** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
** Attempt to read the database schema and initialize internal
** data structures for a single database file. The index of the
** database file is given by iDb. iDb==0 is used for the main
** database. iDb==1 should never be used. iDb>=2 is used for
** auxiliary databases. Return one of the SQLITE_ error codes to
** indicate success or failure.
Database name or NULL
expr ::= LP expr RP
Fts3 table cursor
NO => ID
seltablist
******************************************
** The fts5_expr.c API above this point is used by the other hand-written
** C code in this module. The interfaces below this point are called by
** the parser code in fts5parse.y.
Local reference to page 1
IN/OUT: Pointer into position-list buffer
A frame is only valid if the salt values in the frame-header
** match the salt values in the wal-header.
Check that there isn't an ORDER BY without a LIMIT clause.
Affinity string to return
** Save the current cursor position in the variables BtCursor.nKey
** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
**
** The caller must ensure that the cursor is valid (has eState==CURSOR_VALID)
** prior to calling this routine.
Max seg id number 65535
** Parse a single JSON value which begins at pParse->zJson[i]. Return the
** index of the first character past the end of the value parsed.
**
** Return negative for a syntax error. Special cases: return -2 if the
** first non-whitespace character is '}' and return -3 if the first
** non-whitespace character is ']'.
37
Enforce foreign key constraints
First leaf to traverse
EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
** integer (sqlite3_int64) values that are the default mmap size limit
** (the default setting for PRAGMA mmap_size) and the maximum allowed
** mmap size limit.
To iterate through builtin functions
Complete information about the WHERE clause
NULL-terminated version of pName
Return code from sqlite3_reset()
Do full auto-vacuum
************************************************************************
**************************************************************************
** Below this point is the implementation of the integrity-check
** functionality.
Program implementing pTrigger/orconf
INSERT INTO %_content VALUES(...)
Return the value to store in the "stat" column of the sqlite_stat1
** table for this index.
**
** The value is a string composed of a list of integers describing
** the index. The first integer in the list is the total number of
** entries in the index. There is one additional integer in the list
** for each indexed column. This additional integer is an estimate of
** the number of rows matched by a stabbing query on the index using
** a key with the corresponding number of fields. In other words,
** if the index is on columns (a,b) and the sqlite_stat1 value is
** "100 10 2", then SQLite estimates that:
**
** * the index contains 100 rows,
** * "WHERE a=?" matches 10 rows, and
** * "WHERE a=? AND b=?" matches 2 rows.
**
** If D is the count of distinct values and K is the total number of
** rows, then each estimate is computed as:
**
** I = (K+D-1)/D
SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORK
Btree with currently open write transaction
** Return the file handle for the database file associated
** with the pager. This might return NULL if the file has
** not yet been opened.
Initialize the counter of the number of rows deleted, if
** we are counting rows.
** 2015 January 12
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code that is specific to MSVC.
Iterate through tables
** Fill a buffer with pseudo-random bytes. This is used to preset
** the content of a new memory allocation to unpredictable values and
** to clear the content of a freed allocation to unpredictable values.
** CAPI3REF: Zero Scan-Status Counters
** METHOD: sqlite3_stmt
**
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
**
** This API is only available if the library is built with pre-processor
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
Routine to run in a separate thread
6 SEMI:
# include "sqliteInt.h"
** Load the doclists for each phrase in the query associated with FTS3 cursor
** pCsr.
**
** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable
** phrases in the expression (all phrases except those directly or
** indirectly descended from the right-hand-side of a NOT operator). If
** pnToken is not NULL, then it is set to the number of tokens in all
** matchable phrases of the expression.
Allocate space for the previous row
Address of the i-th cell
Byte offset of blob in cursor data
The database of pSrc
** 2004 May 26
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code use to implement APIs that are part of the
** VDBE.
Check for interrupts on this handle
Ensure that v is greater than zero
Look to see if there is an existing winShmNode that can be used.
** If no matching winShmNode currently exists, create a new one.
If true, pretend pTab contains all NULL values
The BETWEEN expression
User data parameter
For iterating through doclist index
ALL
** CAPI3REF: Obtain The Primary Key Definition Of A Table
**
** For each modified table, a changeset includes the following:
**
** <ul>
** <li> The number of columns in the table, and
** <li> Which of those columns make up the tables PRIMARY KEY.
** </ul>
**
** This function is used to find which columns comprise the PRIMARY KEY of
** the table modified by the change that iterator pIter currently points to.
** If successful, *pabPK is set to point to an array of nCol entries, where
** nCol is the number of columns in the table. Elements of *pabPK are set to
** 0x01 if the corresponding column is part of the tables primary key, or
** 0x00 if it is not.
**
** If argument pnCol is not NULL, then *pnCol is set to the number of columns
** in the table.
**
** If this function is called when the iterator does not point to a valid
** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
** SQLITE_OK is returned and the output variables populated as described
** above.
Full size
** Find the current time (in Universal Coordinated Time). Write into *piNow
** the current time and date as a Julian Day number times 86_400_000. In
** other words, write into *piNow the number of milliseconds since the Julian
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
** proleptic Gregorian calendar.
**
** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
** cannot be found.
Compute the comparison permutation and keyinfo that is used with
** the permutation used to determine if the next
** row of results comes from selectA or selectB. Also add explicit
** collations to the ORDER BY clause terms so that when the subqueries
** to the right and the left are evaluated, they use the correct
** collation.
** Restore the state of the PRNG to the last state saved using
** PRNG_SAVE. If PRNG_SAVE has never before been called, then
** this verb acts like PRNG_RESET.
Left-most of SELECT of a compound
************* Begin file pragma.h *****************************************
** Free a single node of an expression tree.
Last chance verification. If the sector size isn't a multiple of 512
** then it isn't valid.
comment:
** Disable a term in the WHERE clause. Except, do not disable the term
** if it controls a LEFT OUTER JOIN and it did not originate in the ON
** or USING clause of that join.
**
** Consider the term t2.z='ok' in the following queries:
**
** (1) SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x WHERE t2.z='ok'
** (2) SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.x AND t2.z='ok'
** (3) SELECT * FROM t1, t2 WHERE t1.a=t2.x AND t2.z='ok'
**
** The t2.z='ok' is disabled in the in (2) because it originates
** in the ON clause. The term is disabled in (3) because it is not part
** of a LEFT OUTER JOIN. In (1), the term is not disabled.
**
** Disabling a term causes that term to not be tested in the inner loop
** of the join. Disabling is an optimization. When terms are satisfied
** by indices, we disable them to prevent redundant tests in the inner
** loop. We would get the correct results if nothing were ever disabled,
** but joins might run a little slower. The trick is to disable as much
** as we can without disabling too much. If we disabled in (1), we'd get
** the wrong answer. See ticket #813.
**
** If all the children of a term are disabled, then that term is also
** automatically disabled. In this way, terms get disabled if derived
** virtual terms are tested first. For example:
**
** x GLOB 'abc*' AND x>='abc' AND x<'acd'
** \___________/ \______/ \_____/
** parent child1 child2
**
** Only the parent term was in the original WHERE clause. The child1
** and child2 terms were added by the LIKE optimization. If both of
** the virtual child terms are valid, then testing of the parent can be
** skipped.
**
** Usually the parent term is marked as TERM_CODED. But if the parent
** term was originally TERM_LIKE, then the parent gets TERM_LIKECOND instead.
** The TERM_LIKECOND marking indicates that the term should be coded inside
** a conditional such that is only evaluated on the second pass of a
** LIKE-optimization loop, when scanning BLOBs instead of strings.
label: code-design
cmd ::= RELEASE savepoint_opt nm
Root of the input tree
Next value for iLoop
A memory allocation error has occurred
Root node of the tree.
The following fields are only available in 3.8.11 and later
The controlling WhereLoop object
Subquery id 1
** The TESTONLY macro is used to enclose variable declarations or
** other bits of code that are needed to support the arguments
** within testcase() and assert() macros.
value returned by declare_vtab()
** Resolve names in the SELECT statement p and all of its descendants.
Test the storage function
Original, innermost WhereClause
List of SQL indexes on this table.
** Write a nice string representation of the contents of cell pMem
** into buffer zBuf, length nBuf.
Record the instruction used to terminate the loop.
Copy of initial value of pIn1->flags
Restriction (13)
************* Include btreeInt.h in the middle of btmutex.c ***************
** sqlite3WalkExpr() callback used by havingToWhere().
**
** If the node passed to the callback is a TK_AND node, return
** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
**
** Otherwise, return WRC_Prune. In this case, also check if the
** sub-expression matches the criteria for being moved to the WHERE
** clause. If so, add it to the WHERE clause and replace the sub-expression
** within the HAVING expression with a constant "1".
Jump to the end of the loop if the LIMIT is reached.
SQLITE_MISMATCH
Populate the StatCursor fields with the values to be returned
** by the xColumn() and xRowid() methods.
Original lockingcontext to restore on close
** Free all structures in the Pager.aSavepoint[] array and set both
** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
** if it is open and the pager is not in exclusive mode.
IMP: R-48699-48617 This function is an SQL wrapper around the
** sqlite3_libversion() C-interface.
P4
Loop termination point for the schema loop
** typedef for the authorization callback function.
Where to write the frame
** NOTES ON TRANSACTIONS:
**
** SQLite invokes the following virtual table methods as transactions are
** opened and closed by the user:
**
** xBegin(): Start of a new transaction.
** xSync(): Initial part of two-phase commit.
** xCommit(): Final part of two-phase commit.
** xRollback(): Rollback the transaction.
**
** Anything that is required as part of a commit that may fail is performed
** in the xSync() callback. Current versions of SQLite ignore any errors
** returned by xCommit().
**
** And as sub-transactions are opened/closed:
**
** xSavepoint(int S): Open savepoint S.
** xRelease(int S): Commit and close savepoint S.
** xRollbackTo(int S): Rollback to start of savepoint S.
**
** During a write-transaction the fts5_index.c module may cache some data
** in-memory. It is flushed to disk whenever xSync(), xRelease() or
** xSavepoint() is called. And discarded whenever xRollback() or xRollbackTo()
** is called.
**
** Additionally, if SQLITE_DEBUG is defined, an instance of the following
** structure is used to record the current transaction state. This information
** is not required, but it is used in the assert() statements executed by
** function fts5CheckTransactionState() (see below).
78
First Mem address for storing current GROUP BY
************* Begin file insert.c *****************************************
If we are trying to delete from a view, realize that view into
** an ephemeral table.
Check if this call is removing or replacing an existing collation
** sequence. If so, and there are active VMs, return busy. If there
** are no active VMs, invalidate any pre-compiled statements.
It is not possible for a REDUCE to be followed by an error
Pager object associated with page pPg
Otherwise, the argument is a column name.
Buffer to deserialize from
comment: *************************************************************************
** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
** of a standard VFS in the following ways:
**
** 1. Whenever the first page of a main database file is read or
** written, the value of the change-counter cookie is stored in
** rbu_file.iCookie. Similarly, the value of the "write-version"
** database header field is stored in rbu_file.iWriteVer. This ensures
** that the values are always trustworthy within an open transaction.
**
** 2. Whenever an SQLITE_OPEN_WAL file is opened, the (rbu_file.pWalFd)
** member variable of the associated database file descriptor is set
** to point to the new file. A mutex protected linked list of all main
** db fds opened using a particular RBU VFS is maintained at
** rbu_vfs.pMain to facilitate this.
**
** 3. Using a new file-control "SQLITE_FCNTL_RBU", a main db rbu_file
** object can be marked as the target database of an RBU update. This
** turns on the following extra special behaviour:
**
** 3a. If xAccess() is called to check if there exists a *-wal file
** associated with an RBU target database currently in RBU_STAGE_OAL
** stage (preparing the *-oal file), the following special handling
** applies:
**
** * if the *-wal file does exist, return SQLITE_CANTOPEN. An RBU
** target database may not be in wal mode already.
**
** * if the *-wal file does not exist, set the output parameter to
** non-zero (to tell SQLite that it does exist) anyway.
**
** Then, when xOpen() is called to open the *-wal file associated with
** the RBU target in RBU_STAGE_OAL stage, instead of opening the *-wal
** file, the rbu vfs opens the corresponding *-oal file instead.
**
** 3b. The *-shm pages returned by xShmMap() for a target db file in
** RBU_STAGE_OAL mode are actually stored in heap memory. This is to
** avoid creating a *-shm file on disk. Additionally, xShmLock() calls
** are no-ops on target database files in RBU_STAGE_OAL mode. This is
** because assert() statements in some VFS implementations fail if
** xShmLock() is called before xShmMap().
**
** 3c. If an EXCLUSIVE lock is attempted on a target database file in any
** mode except RBU_STAGE_DONE (all work completed and checkpointed), it
** fails with an SQLITE_BUSY error. This is to stop RBU connections
** from automatically checkpointing a *-wal (or *-oal) file from within
** sqlite3_close().
**
** 3d. In RBU_STAGE_CAPTURE mode, all xRead() calls on the wal file, and
** all xWrite() calls on the target database file perform no IO.
** Instead the frame and page numbers that would be read and written
** are recorded. Additionally, successful attempts to obtain exclusive
** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
** database file are recorded. xShmLock() calls to unlock the same
** locks are no-ops (so that once obtained, these locks are never
** relinquished). Finally, calls to xSync() on the target database
** file fail with SQLITE_INTERNAL errors.
label: code-design
Size of the record in bytes
** Clean up the VM after a single run.
SQL statement 2 (see above)
EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
** can be changed at start-time using the
** sqlite3_config(SQLITE_CONFIG_URI,1) or
** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
** Look through the list of open database files in db->aDb[] and if
** any have been closed, remove them from the list. Reallocate the
** db->aDb[] structure to a smaller size, if possible.
**
** Entry 0 (the "main" database) and entry 1 (the "temp" database)
** are never candidates for being collapsed.
Either X and Y both have COLLATE operator or neither do
The table whose content is at r[regBase]...
430
** The following structure keeps track of state information for the
** count() aggregate function.
Add pVtab to the end of sqlite3.aVTrans
If we reach this point, it means that execution is finished with
** an error of some kind.
** This "finder" function for VxWorks checks to see if posix advisory
** locking works. If it does, then that is what is used. If it does not
** work, then fallback to named semaphore locking.
Columns of the index used
** Extract all tokens from hash table iHash and link them into a list
** in sorted order. The hash table is cleared before returning. It is
** the responsibility of the caller to free the elements of the returned
** list.
** The PmaReader passed as the first argument is guaranteed to be an
** incremental-reader (pReadr->pIncr!=0). This function serves to open
** and/or initialize the temp file related fields of the IncrMerge
** object at (pReadr->pIncr).
**
** If argument eMode is set to INCRINIT_NORMAL, then all PmaReaders
** in the sub-tree headed by pReadr are also initialized. Data is then
** loaded into the buffers belonging to pReadr and it is set to point to
** the first key in its range.
**
** If argument eMode is set to INCRINIT_TASK, then pReadr is guaranteed
** to be a multi-threaded PmaReader and this function is being called in a
** background thread. In this case all PmaReaders in the sub-tree are
** initialized as for INCRINIT_NORMAL and the aFile[1] buffer belonging to
** pReadr is populated. However, pReadr itself is not set up to point
** to its first key. A call to vdbePmaReaderNext() is still required to do
** that.
**
** The reason this function does not call vdbePmaReaderNext() immediately
** in the INCRINIT_TASK case is that vdbePmaReaderNext() assumes that it has
** to block on thread (pTask->thread) before accessing aFile[1]. But, since
** this entire function is being run by thread (pTask->thread), that will
** lead to the current background thread attempting to join itself.
**
** Finally, if argument eMode is set to INCRINIT_ROOT, it may be assumed
** that pReadr->pIncr is a multi-threaded IncrMerge objects, and that all
** child-trees have already been initialized using IncrInit(INCRINIT_TASK).
** In this case vdbePmaReaderNext() is called on all child PmaReaders and
** the current PmaReader set to point to the first key in its range.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
True if uppercase is equivalent to lowercase
Size of azNotindexed[] array
Figure out how large an allocation is required
Full table scan
Bounds of global page cache memory
comment:
** Copy the error code and error message belonging to the VDBE passed
** as the first argument to its database handle (so that they will be
** returned by calls to sqlite3_errcode() and sqlite3_errmsg()).
**
** This function does not clear the VDBE error code or message, just
** copies them to the database handle.
label: code-design
Cursor number of X in "X <op> <expr>"
EVIDENCE-OF: R-18761-36601 There are three arguments to
** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
** the size of each page cache line (sz), and the number of cache lines
** (N).
comment: For following code (kept for historical record only) shows an
** unrolling for the 3- and 4-byte varint cases. This code is
** slightly faster, but it is also larger and much harder to test.
label: code-design
152
The affinity of the column or 0 if not a column
Instruction to jump to for RAISE(IGNORE)
Opens a file, only if it exists.
** The code in this file is only used if we are compiling threadsafe
** under unix with pthreads.
**
** Note that this implementation requires a version of pthreads that
** supports recursive mutexes.
register holding first column to insert
Put a copy of the Table struct in Parse.pNewTable for the
** sqlite3AddColumn() function and friends to modify. But modify
** the name by adding an "sqlite_altertab_" prefix. By adding this
** prefix, we insure that the name will not collide with an existing
** table because user table are not allowed to have the "sqlite_"
** prefix on their name.
136
Figure out the root-page that the lock should be held on. For table
** b-trees, this is just the root page of the b-tree being read or
** written. For index b-trees, it is the root page of the associated
** table.
comment: FTS5_STMT_XXX constant
label: code-design
SQLITE_CHECK_PAGES
** Implementation of the json_QUOTE(VALUE) function. Return a JSON value
** corresponding to the SQL value input. Mostly this means putting
** double-quotes around strings and returning the unquoted string "null"
** when given a NULL input.
Score of best match
** TRUE if p is a lookaside memory allocation from db
Instance of shared memory on this file
Update contents of aTree[]
Second disjunct
VFS to use with this b-tree
Total number of allocations
Append the number of bytes of new data, then the term data itself
** to the page.
comment:
** This function returns true if main-memory should be used instead of
** a temporary file for transient pager files and statement journals.
** The value returned depends on the value of db->temp_store (runtime
** parameter) and the compile time value of SQLITE_TEMP_STORE. The
** following table describes the relationship between these two values
** and this functions return value.
**
** SQLITE_TEMP_STORE db->temp_store Location of temporary database
** ----------------- -------------- ------------------------------
** 0 any file (return 0)
** 1 1 file (return 0)
** 1 2 memory (return 1)
** 1 0 file (return 0)
** 2 1 file (return 0)
** 2 2 memory (return 1)
** 2 0 memory (return 1)
** 3 any memory (return 1)
label: code-design
** Implementation of the sqlite_compileoption_used() function.
** The result is an integer that identifies if the compiler option
** was used to build SQLite.
** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
Replace Isalnum() return value with this
If this is a commit, update the wal-index header too.
Register pRt is used to store the memory required to save the state
** of the current program, and the memory required at runtime to execute
** the trigger program. If this trigger has been fired before, then pRt
** is already allocated. Otherwise, it must be initialized.
** The parser calls this routine for each token after the first token
** in an argument to the module name in a CREATE VIRTUAL TABLE statement.
** 2005 November 29
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains OS interface code that is common to all
** architectures.
If no entry point was specified and the default legacy
** entry point name "sqlite3_extension_init" was not found, then
** construct an entry point name "sqlite3_X_init" where the X is
** replaced by the lowercase value of every ASCII alphabetic
** character in the filename after the last "/" upto the first ".",
** and eliding the first three characters if they are "lib".
** Examples:
**
** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
Rtree handle
OUT: Data for root node
Index of the cell within the node
166
** Legal values for BtCursor.curFlags
Current 'token' value
For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
** as if it does not exist.
"view" or "table"
# include "vdbeInt.h"
comment:
** Clean up and delete a VDBE after execution. Return an integer which is
** the result code. Write any error message text into *pzErrMsg.
label: code-design
** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
Number of pending entries in the queue
synopsis: r[P2]='P4' (len=P1)
cmd ::= with insert_cmd INTO fullname idlist_opt select
Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc.
1450
If pTab is really a view, make sure it has been initialized.
** ViewGetColumnNames() is a no-op if pTab is not a view.
Buffer for matchinfo data
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
Begin by generating some termination code at the end of the
** vdbe program
** PRAGMA [schema.]mmap_size(N)
**
** Used to set mapping size limit. The mapping size limit is
** used to limit the aggregate size of all memory mapped regions of the
** database file. If this parameter is set to zero, then memory mapping
** is not used at all. If N is negative, then the default memory map
** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
** The parameter N is measured in bytes.
**
** This value is advisory. The underlying VFS is free to memory map
** as little or as much as it wants. Except, if N is set to 0 then the
** upper layers will never invoke the xFetch interfaces to the VFS.
ccons ::= NOT NULL onconf
The following assert statements verify that if this is a sharable
** b-tree database, the connection is holding the required table locks,
** and that no other connection has any open cursor that conflicts with
** this lock.
INSERT
Invoke the pre-update hook, if any
Score for the new search point
Pointer to shared header
Parser context
The affinity string for the record
exprlist ::= cnearset
Search for the required lock. Either a write-lock on root-page iTab, a
** write-lock on the schema table, or (if the client is reading) a
** read-lock on iTab will suffice. Return 1 if any of these are found.
** This function is called to allocate an array of Fts3Index structures
** representing the indexes maintained by the current FTS table. FTS tables
** always maintain the main "terms" index, but may also maintain one or
** more "prefix" indexes, depending on the value of the "prefix=" parameter
** (if any) specified as part of the CREATE VIRTUAL TABLE statement.
**
** Argument zParam is passed the value of the "prefix=" option if one was
** specified, or NULL otherwise.
**
** If no error occurs, SQLITE_OK is returned and *apIndex set to point to
** the allocated array. *pnIndex is set to the number of elements in the
** array. If an error does occur, an SQLite error code is returned.
**
** Regardless of whether or not an error is returned, it is the responsibility
** of the caller to call sqlite3_free() on the output array to free it.
Local name of table
Space for other PMAs
Reinitialize the %_data table. This call creates the initial structure
** and averages records.
comment: If the expression is not constant then we will need to
** disable the test that was generated above that makes sure
** this code only executes once. Because for a non-constant
** expression we need to rerun this code each time.
label: code-design
comment: If all readers are using WAL_READ_LOCK(0) (in other words if no
** readers are currently using the WAL), then the transactions
** frames will overwrite the start of the existing log. Update the
** wal-index header to reflect this.
**
** In theory it would be Ok to update the cache of the header only
** at this point. But updating the actual wal-index header is also
** safe and means there is no special case for sqlite3WalUndo()
** to handle if this transaction is rolled back.
label: code-design
if !OS_VXWORKS
See the tool/mkopcodec.tcl script for details.
Index to cksum (0..p->nIndex-1)
comment:
** The select statement passed as the second parameter is a compound SELECT
** with an ORDER BY clause. This function allocates and returns a KeyInfo
** structure suitable for implementing the ORDER BY.
**
** Space to hold the KeyInfo structure is obtained from malloc. The calling
** function is responsible for ensuring that this structure is eventually
** freed.
label: code-design
Hash key
indexed_opt ::= INDEXED BY nm
Zero the first nEqZero entries in the anEq[] array.
**** This function may be used as part of assert() statements only. ****
**
** Return true if it would be illegal for pBtree to write into the
** table or index rooted at iRoot because other shared connections are
** simultaneously reading that same table or index.
**
** It is illegal for pBtree to write if some other Btree object that
** shares the same BtShared object is currently reading or writing
** the iRoot table. Except, if the other Btree object has the
** read-uncommitted flag set, then it is OK for the other object to
** have a read cursor.
**
** For example, before writing to any part of the table or index
** rooted at page iRoot, one should call:
**
** assert( !hasReadConflicts(pBtree, iRoot) );
** Remove the memory data structures associated with the given
** Table. No changes are made to disk by this routine.
**
** This routine just deletes the data structure. It does not unlink
** the table data structure from the hash table. But it does destroy
** memory structures of the indices and foreign keys associated with
** the table.
**
** The db parameter is optional. It is needed if the Table object
** contains lookaside memory. (Table objects in the schema do not use
** lookaside memory, but some ephemeral Table objects do.) Or the
** db parameter can be used with db->pnBytesFreed to measure the memory
** used by the Table object.
key_opt
Set the flag to indicate that at least one PMA has been written.
** Or will be, anyhow.
** Walk the expression tree passed as the first argument. Return non-zero
** if the expression consists entirely of constants or copies of terms
** in pGroupBy that sort with the BINARY collation sequence.
**
** This routine is used to determine if a term of the HAVING clause can
** be promoted into the WHERE clause. In order for such a promotion to work,
** the value of the HAVING clause term must be the same for all members of
** a "group". The requirement that the GROUP BY term must be BINARY
** assumes that no other collating sequence will have a finer-grained
** grouping than binary. In other words (A=B COLLATE binary) implies
** A=B in every other collating sequence. The requirement that the
** GROUP BY be BINARY is stricter than necessary. It would also work
** to promote HAVING clauses that use the same alternative collating
** sequence as the GROUP BY term, but that is much harder to check,
** alternative collating sequences are uncommon, and this is only an
** optimization, so we take the easy way out and simply require the
** GROUP BY to use the BINARY collating sequence.
Input string
80
synopsis: r[P2]=rowid
Jump to here if the sqlite3_interrupt() API sets the interrupt
** flag.
************* End of update.c *********************************************
BLOB
Number of leaves on the trunk of the freelist
If a non-unique index is used, or if a prefix of the key for
** unique index is used (making the index functionally non-unique)
** then the sqlite_stat1 data becomes important for scoring the
** plan
Comparison of term and split-key
lru page list
STEP 2:
** Try to satisfy the allocation by carving a piece off of the end
** of the master chunk. This step usually works if step 1 fails.
Header in shared memory
End of processing for this SELECT
Mutex for accessing the following:
** Reclaim all memory allocated by a JsonParse object. But do not
** delete the JsonParse object itself.
The thread that will be using the new IncrMerger
Opcode: Ne P1 P2 P3 P4 P5
** Synopsis: IF r[P3]!=r[P1]
**
** This works just like the Eq opcode except that the jump is taken if
** the operands in registers P1 and P3 are not equal. See the Eq opcode for
** additional information.
**
** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
** content of r[P2] is only changed if the new value is NULL or 1 (true).
** In other words, a prior r[P2] value will not be overwritten by 0 (false).
** Check invariants on a PgHdr entry. Return true if everything is OK.
** Return false if any invariant is violated.
**
** This routine is for use inside of assert() statements only. For
** example:
**
** assert( sqlite3PcachePageSanity(pPg) );
** Grow the pWriter->aDlidx[] array to at least nLvl elements in size.
** Any new array elements are zeroed before returning.
************* Include sqlite3rbu.h in the middle of sqlite3rbu.c **********
Has no INDEXED BY clause
comment: Text of document to be inserted
label: documentation
Estimated size of each table row in bytes
* This is the maximum possible initial size of the Win32-specific heap, in
* bytes.
Array of trailing arguments
The index entry must begin with a header size
In-memory journal file
The major token code number
** CAPI3REF: Maximum xShmLock index
**
** The xShmLock method on [sqlite3_io_methods] may use values
** between 0 and this upper bound as its "offset" argument.
** The SQLite core will never attempt to acquire or release a
** lock outside of this range
Name of table or index being scanned
** This function does the work for the xUpdate method of FTS3 virtual
** tables. The schema of the virtual table being:
**
** CREATE TABLE <table name>(
** <user columns>,
** <table name> HIDDEN,
** docid HIDDEN,
** <langid> HIDDEN
** );
**
**
This call is to merge all segments at level iLevel. find the next
** available segment index at level iLevel+1. The call to
** fts3AllocateSegdirIdx() will merge the segments at level iLevel+1 to
** a single iLevel+2 segment if necessary.
The BtShared this cursor points to
Initialize the state of the random number generator once,
** the first time this routine is called. The seed value does
** not need to contain a lot of randomness since we are not
** trying to do secure encryption or anything like that...
**
** Nothing in this file or anywhere else in SQLite does any kind of
** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
** number generator) not as an encryption device.
Used to loop thru the element list
************* End of expr.c ***********************************************
** Do both phases of a commit.
comment:
** Allocate and initialize a new Pager object and put a pointer to it
** in *ppPager. The pager should eventually be freed by passing it
** to sqlite3PagerClose().
**
** The zFilename argument is the path to the database file to open.
** If zFilename is NULL then a randomly-named temporary file is created
** and used as the file to be cached. Temporary files are be deleted
** automatically when they are closed. If zFilename is ":memory:" then
** all information is held in cache. It is never written to disk.
** This can be used to implement an in-memory database.
**
** The nExtra parameter specifies the number of bytes of space allocated
** along with each page reference. This space is available to the user
** via the sqlite3PagerGetExtra() API. When a new page is allocated, the
** first 8 bytes of this space are zeroed but the remainder is uninitialized.
** (The extra space is used by btree as the MemPage object.)
**
** The flags argument is used to specify properties that affect the
** operation of the pager. It should be passed some bitwise combination
** of the PAGER_* flags.
**
** The vfsFlags parameter is a bitmask to pass to the flags parameter
** of the xOpen() method of the supplied VFS when opening files.
**
** If the pager object is allocated and the specified file opened
** successfully, SQLITE_OK is returned and *ppPager set to point to
** the new pager object. If an error occurs, *ppPager is set to NULL
** and error code returned. This function may return SQLITE_NOMEM
** (sqlite3Malloc() is used to allocate memory), SQLITE_CANTOPEN or
** various SQLITE_IO_XXX errors.
label: code-design
Deferred token object for this token
** 2003 September 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used for creating, destroying, and populating
** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.)
Pointer to output buffer
** Collation sequence comparison function. The pCtx argument points to
** a UCollator structure previously allocated using ucol_open().
xWrite
Shared locks never span more than one byte
Report errors here
Number of entries on one ptrmap page
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
If no row was found and no error has occurred, then the %_content
** table is missing a row that is present in the full-text index.
** The data structures are corrupt.
having_opt ::=
Verify CHECK constraints
Normal read/write connection
** Walk an expression tree. Return non-zero if the expression is constant
** and 0 if it involves variables or function calls.
**
** For the purposes of this function, a double-quoted string (ex: "abc")
** is considered a variable but a single-quoted string (ex: 'abc') is
** a constant.
** Return a pointer to the collation sequence that should be used by
** a binary comparison operator comparing pLeft and pRight.
**
** If the left hand expression has a collating sequence type, then it is
** used. Otherwise the collation sequence for the right hand expression
** is used, or the default (BINARY) if neither expression has a collating
** type.
**
** Argument pRight (but not pLeft) may be a null pointer. In this case,
** it is not considered.
same as TK_ESCAPE, jump
Index of right-most cell in left sibling
True if the leaf of an intKey table
comment:
** Adjust settings of the pager to those specified in the pgFlags parameter.
**
** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness
** of the database to damage due to OS crashes or power failures by
** changing the number of syncs()s when writing the journals.
** There are four levels:
**
** OFF sqlite3OsSync() is never called. This is the default
** for temporary and transient files.
**
** NORMAL The journal is synced once before writes begin on the
** database. This is normally adequate protection, but
** it is theoretically possible, though very unlikely,
** that an inopertune power failure could leave the journal
** in a state which would cause damage to the database
** when it is rolled back.
**
** FULL The journal is synced twice before writes begin on the
** database (with some additional information - the nRec field
** of the journal header - being written in between the two
** syncs). If we assume that writing a
** single disk sector is atomic, then this mode provides
** assurance that the journal will not be corrupted to the
** point of causing damage to the database during rollback.
**
** EXTRA This is like FULL except that is also syncs the directory
** that contains the rollback journal after the rollback
** journal is unlinked.
**
** The above is for a rollback-journal mode. For WAL mode, OFF continues
** to mean that no syncs ever occur. NORMAL means that the WAL is synced
** prior to the start of checkpoint and that the database file is synced
** at the conclusion of the checkpoint if the entire content of the WAL
** was written back into the database. But no sync operations occur for
** an ordinary commit in NORMAL mode with WAL. FULL means that the WAL
** file is synced following each commit operation, in addition to the
** syncs associated with NORMAL. There is no difference between FULL
** and EXTRA for WAL mode.
**
** Do not confuse synchronous=FULL with SQLITE_SYNC_FULL. The
** SQLITE_SYNC_FULL macro means to use the MacOSX-style full-fsync
** using fcntl(F_FULLFSYNC). SQLITE_SYNC_NORMAL means to do an
** ordinary fsync() call. There is no difference between SQLITE_SYNC_FULL
** and SQLITE_SYNC_NORMAL on platforms other than MacOSX. But the
** synchronous=FULL versus synchronous=NORMAL setting determines when
** the xSync primitive is called and is relevant to all platforms.
**
** Numeric values associated with these states are OFF==1, NORMAL=2,
** and FULL=3.
label: code-design
Legacy behavior (sqlite3_close() behavior) is to return
** SQLITE_BUSY if the connection can not be closed immediately.
xSectorSize
EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
** works for years between 1970 and 2037. For dates outside this range,
** SQLite attempts to map the year into an equivalent year within this
** range, do the calculation, then map the year back.
Jump to this label to skip a row
Set nLoad4 to the value of (4^nOther) for the next iteration of the
** for-loop. Except, limit the value to 2^24 to prevent it from
** overflowing the 32-bit integer it is stored in.
The simple case - no more than one database file (not counting the
** TEMP database) has a transaction active. There is no need for the
** master-journal.
**
** If the return value of sqlite3BtreeGetFilename() is a zero length
** string, it means the main database is :memory: or a temp file. In
** that case we do not support atomic multi-file commits, so use the
** simple case then too.
1220
Affinity must be the same on all columns
OUT: True if change is indirect
At this point, okToChngToIN is true if original pTerm satisfies
** case 1. In that case, construct a new virtual term that is
** pTerm converted into an IN operator.
Write the new expression node here
Maximum of 4 fragments per snippet
The first to increment to 1 does actual initialization
#include "fts3Int.h"
Only sort the current set of entiries if they need it
171
default size is approx 4 bytes
Size of each scratch buffer
** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
** or WinCE. Return false (zero) for Win95, Win98, or WinME.
**
** Here is an interesting observation: Win95, Win98, and WinME lack
** the LockFileEx() API. But we can still statically link against that
** API as long as we don't call it when running Win95/98/ME. A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
Expression list to resolve. May be NUL.
Token:
** Deserialize and return the structure record currently stored in serialized
** form within buffer pData/nData.
**
** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
** are over-allocated by one slot. This allows the structure contents
** to be more easily edited.
**
** If an error occurs, *ppOut is set to NULL and an SQLite error code
** returned. Otherwise, *ppOut is set to point to the new object and
** SQLITE_OK returned.
** Helper function for fts3ExprIterate() (see below).
** Convert a schema pointer into the iDb index that indicates
** which database file in db->aDb[] the schema refers to.
**
** If the same database is attached more than once, the first
** attached database is returned.
FTS index to query
** This function is a helper function for sqlite3Fts3EvalTestDeferred().
** Assuming no error occurs or has occurred, It returns non-zero if the
** expression passed as the second argument matches the row that pCsr
** currently points to, or zero if it does not.
**
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
** If an error occurs during execution of this function, *pRc is set to
** the appropriate SQLite error code. In this case the returned value is
** undefined.
** Expression pExpr is one operand of a comparison operator that might
** be useful for indexing. This routine checks to see if pExpr appears
** in any index. Return TRUE (1) if pExpr is an indexed term and return
** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
** number of the table that is indexed and aiCurCol[1] to the column number
** of the column that is indexed, or XN_EXPR (-2) if an expression is being
** indexed.
**
** If pExpr is a TK_COLUMN column reference, then this routine always returns
** true even if that particular column is not indexed, because the column
** might be added to an automatic index later.
IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
** "checkpoint" lock on the database file.
** Set the "type" of an allocation.
** Print a single opcode. This routine is used for debugging only.
Update or delete the input segments
WinCE has no concept of a relative pathname, or so I am told.
comment: As the winMutexInit() and winMutexEnd() functions are called as part
** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
** "interlocked" magic used here is probably not strictly necessary.
label: code-design
Current entry in aPage[]
No affinity ever needs to be (or should be) applied to a value
** from the RHS of an "? IN (SELECT ...)" expression. The
** sqlite3FindInIndex() routine has already ensured that the
** affinity of the comparison has been applied to the value.
Depth of the SAVEPOINT stack
True if the transaction counter changed
An AS clause always takes first priority
comment: Set the text that the regular expression operates on to a NULL
** pointer. This is not really necessary, but it is tidier than
** leaving the regular expression object configured with an invalid
** pointer after this function returns.
label: code-design
Number of columns in pIdx. "N"
Key content for indexes. NULL for tables
The key we are searching for
_FTSINT_H
** Allocate an instance of the default tokenizer ("simple") at
** Fts5Config.pTokenizer. Return SQLITE_OK if successful, or an SQLite error
** code if an error occurs.
result set is empty
** Return the pager associated with a BTree. This routine is used for
** testing and debugging only.
comment: If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
** statement to populate the new table. The root-page number for the
** new table is in register pParse->regRoot.
**
** Once the SELECT has been coded by sqlite3Select(), it is in a
** suitable state to query for the column names and types to be used
** by the new table.
**
** A shared-cache write-lock is not required to write to the new table,
** as a schema-lock must have already been obtained to create it. Since
** a schema-lock excludes all other database users, the write-lock would
** be redundant.
label: code-design
Open the master journal.
If true, write dlidx to disk
Opcode: Multiply P1 P2 P3 * *
** Synopsis: r[P3]=r[P1]*r[P2]
**
**
** Multiply the value in register P1 by the value in register P2
** and store the result in register P3.
** If either input is NULL, the result is NULL.
Schema containing the trigger
Rebalance the expression. And check that its depth does not exceed
** SQLITE_FTS3_MAX_EXPR_DEPTH.
** Macros to enter and leave the PCache LRU mutex.
attempt to get the lock
Opcode: PrevIfOpen P1 P2 P3 P4 P5
**
** This opcode works just like Prev except that if cursor P1 is not
** open it behaves a no-op.
IN/OUT: Output pointer
The database
Callback function
** Delete any previous value and set the value stored in *pMem to NULL.
**
** This routine calls the Mem.xDel destructor to dispose of values that
** require the destructor. But it preserves the Mem.zMalloc memory allocation.
** To free all resources, use sqlite3VdbeMemRelease(), which both calls this
** routine to invoke the destructor and deallocates Mem.zMalloc.
**
** Use this routine to reset the Mem prior to insert a new value.
**
** Use sqlite3VdbeMemRelease() to complete erase the Mem prior to abandoning it.
cnearset ::= nearset
CHAR
************* Continuing where we left off in wherecode.c *****************
** Convert pMem so that it has types MEM_Real or MEM_Int or both.
** Invalidate any prior representations.
**
** Every effort is made to force the conversion, even if the input
** is a string that does not look completely like a number. Convert
** as much of the string as we can and ignore the rest.
Grave-accent quoted symbols used by MySQL
If a column is marked as 'hidden', omit it from the expanded
** result-set list unless the SELECT has the SF_IncludeHidden
** bit set.
Prepared statement
** Add an opcode that includes the p4 value as an integer.
xRename - rename the table
Advance pChild until it points to iLast or laster
Fall thru into the next case
For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
** string representation of the value. Then, if the required encoding
** is UTF-16le or UTF-16be do a translation.
**
** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
Add a single new term to an ExprList that is used to store a
** list of identifiers. Report an error if the ID list contains
** a COLLATE clause or an ASC or DESC keyword, except ignore the
** error while parsing a legacy schema.
1440
** 2006 Oct 10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file is used by programs that want to link against the
** FTS3 library. All it does is declare the sqlite3Fts3Init() interface.
When a new VdbeCursor is allocated, only the fields above are zeroed.
** The fields that follow are uninitialized, and must be individually
** initialized prior to first use.
Number of locks in aTableLock
Built-in unlikely() function
OUT: uid to set on the file
The fixer to be initialized
size of db file in pages
File handle for WAL file
** Argument pIn points to a character that is part of a nul-terminated
** string. Return a pointer to the first character following *pIn in
** the string that is not a white-space character.
Disconnect these in next sqlite3_prepare()
SELECT statement to query table pTab
If we are creating a set for an "expr IN (SELECT ...)" construct,
** then there should be a single item on the stack. Write this
** item into the set table with bogus data.
Used when p4type is P4_TABLE
Number of children that must disable us
Object fully contained within query region
Initialize the upper limit on the number of worker threads
WHERE analysis context
** This function may only be called from within a pre-update callback.
** It calculates a hash based on the primary key values of the old.* or
** new.* row currently available and, assuming no error occurs, writes it to
** *piHash before returning. If the primary key contains one or more NULL
** values, *pbNullPK is set to true before returning.
**
** If an error occurs, an SQLite error code is returned and the final values
** of *piHash asn *pbNullPK are undefined. Otherwise, SQLITE_OK is returned
** and the output variables are set as described above.
273
idx = (lwr+upr)/2;
OUT: Expression element
Special processing to add years
At this point local variable rc holds the value that should be
** returned if this statement was compiled using the legacy
** sqlite3_prepare() interface. According to the docs, this can only
** be one of the values in the first assert() below. Variable p->rc
** contains the value that would be returned if sqlite3_finalize()
** were called on statement p.
Set the limiting size of a WAL file.
** Assert that column iCol of statement pStmt is named zName.
True for highlighted terms
!defined(SQLITE_THREADS_IMPLEMENTED)
** CAPI3REF: Flags for the xShmLock VFS method
**
** These integer constants define the various locking operations
** allowed by the xShmLock method of [sqlite3_io_methods]. The
** following are the only legal combinations of flags to the
** xShmLock method:
**
** <ul>
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
** </ul>
**
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
** was given on the corresponding lock.
**
** The xShmLock method can transition between unlocked and SHARED or
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
** and EXCLUSIVE.
Needed for the definition of va_list
Extract snippet from this column
** Read, deserialize and return the structure record.
**
** The Fts5Structure.aLevel[] and each Fts5StructureLevel.aSeg[] array
** are over-allocated as described for function fts5StructureDecode()
** above.
**
** If an error occurs, NULL is returned and an error code left in the
** Fts5Index handle. If an error has already occurred when this function
** is called, it is a no-op.
Phrase object to advance to next docid
************* Begin file fts3_write.c *************************************
Generate code to handle collisions
Write the unqualified object name here
Enable to print out how the built-in functions are hashed
(275) ecmd ::= SEMI
If another connection has written to the database file since the
** time the read transaction on this connection was started, then
** the write is disallowed.
Index of a host parameter
** Allocate a single new register for use to hold some intermediate result.
True if %_stat table exists (2==unknown)
************* End of fts3_tokenizer.c *************************************
comment: not used 0x0010 // Was: SQLITE_IdxRealAsInt
label: code-design
Invoke any destructors registered for collation sequence user data.
** Invoke the xFileControl method on a particular database.
Declarations for functions in fkey.c. All of these are replaced by
** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
** key functionality is available. If OMIT_TRIGGER is defined but
** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
** this case foreign keys are parsed, but no other functionality is
** provided (enforcement of FK constraints requires the triggers sub-system).
The cost of visiting the index rows is N*K, where K is
** between 1.1 and 3.0, depending on the relative sizes of the
** index and table rows.
286
Name of database (e.g. "main", "temp")
SQLITE_OMIT_VIEW
The triggered program
Maximum instantaneous currentOut
(295) ccons ::= NULL onconf
the WHERE clause to be analyzed
bOpenUri
groupby_opt ::=
Original list of tables
** Acquire a reader lock.
** Different API routines are called depending on whether or not this
** is Win9x or WinNT.
Add the output column list to the name-context before parsing the
** other expressions in the SELECT statement. This is so that
** expressions in the WHERE clause (etc.) can refer to expressions by
** aliases in the result set.
**
** Minor point: If this is the case, then the expression will be
** re-evaluated for each reference to it.
Is the PRIMARY KEY for the table
************* End of os_setup.h *******************************************
comment: The SELECT has been coded. If there is an error in the Parse structure,
** set the return code to 1. Otherwise 0.
label: code-design
Draw vertical in column i if bLine[i] is true
** Restart the backup process. This is called when the pager layer
** detects that the database has been modified by an external database
** connection. In this case there is no way of knowing which of the
** pages that have been copied into the destination database are still
** valid and which are not, so the entire process needs to be restarted.
**
** It is assumed that the mutex associated with the BtShared object
** corresponding to the source database is held when this function is
** called.
Allocated size of buffer zOut
** This is the xColumn method, called by SQLite to request a value from
** the row that the supplied cursor currently points to.
Leaf cursor in SKIPNEXT state
** All token types in the generated fts5parse.h file are greater than 0.
** The afpLockingContext structure contains all afp lock specific state
Slots used in azResult[]. (nRow+1)*nColumn
Value to compare to current sorter key
Address of the initialization bypass jump
** The schema for each SQL table and view is represented in memory
** by an instance of the following structure.
** Flush any data stored in the in-memory hash tables to the database.
comment:
** CAPI3REF: Open A BLOB For Incremental I/O
** METHOD: sqlite3
** CONSTRUCTOR: sqlite3_blob
**
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
** in row iRow, column zColumn, table zTable in database zDb;
** in other words, the same BLOB that would be selected by:
**
** <pre>
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
** </pre>)^
**
** ^(Parameter zDb is not the filename that contains the database, but
** rather the symbolic name of the database. For attached databases, this is
** the name that appears after the AS keyword in the [ATTACH] statement.
** For the main database file, the database name is "main". For TEMP
** tables, the database name is "temp".)^
**
** ^If the flags parameter is non-zero, then the BLOB is opened for read
** and write access. ^If the flags parameter is zero, the BLOB is opened for
** read-only access.
**
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
** in *ppBlob. Otherwise an [error code] is returned and, unless the error
** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
** the API is not misused, it is always safe to call [sqlite3_blob_close()]
** on *ppBlob after this function it returns.
**
** This function fails with SQLITE_ERROR if any of the following are true:
** <ul>
** <li> ^(Database zDb does not exist)^,
** <li> ^(Table zTable does not exist within database zDb)^,
** <li> ^(Table zTable is a WITHOUT ROWID table)^,
** <li> ^(Column zColumn does not exist)^,
** <li> ^(Row iRow is not present in the table)^,
** <li> ^(The specified column of row iRow contains a value that is not
** a TEXT or BLOB value)^,
** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
** constraint and the blob is being opened for read/write access)^,
** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
** column zColumn is part of a [child key] definition and the blob is
** being opened for read/write access)^.
** </ul>
**
** ^Unless it returns SQLITE_MISUSE, this function sets the
** [database connection] error code and message accessible via
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
**
** A BLOB referenced by sqlite3_blob_open() may be read using the
** [sqlite3_blob_read()] interface and modified by using
** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
** different row of the same table using the [sqlite3_blob_reopen()]
** interface. However, the column, table, or database of a [BLOB handle]
** cannot be changed after the [BLOB handle] is opened.
**
** ^(If the row that a BLOB handle points to is modified by an
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
** then the BLOB handle is marked as "expired".
** This is true if any column of the row is changed, even a column
** other than the one the BLOB handle is open on.)^
** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
** ^(Changes written into a BLOB prior to the BLOB expiring are not
** rolled back by the expiration of the BLOB. Such changes will eventually
** commit if the transaction continues to completion.)^
**
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
** the opened blob. ^The size of a blob may not be changed by this
** interface. Use the [UPDATE] SQL command to change the size of a
** blob.
**
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
** and the built-in [zeroblob] SQL function may be used to create a
** zero-filled blob to read or write using the incremental-blob interface.
**
** To avoid a resource leak, every open [BLOB handle] should eventually
** be released by a call to [sqlite3_blob_close()].
**
** See also: [sqlite3_blob_close()],
** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
label: code-design
Illegal character
as ::= AS nm
Size of index key in bytes
************* Begin file keywordhash.h ************************************
Figure out what action to take in case of a rowid collision
Generate a subroutine to run when the results from select B
** are exhausted and only data in select A remains.
Make sure the column name is unique. If the name is not unique,
** append an integer to the name so that it becomes unique.
250
VDBE_DISPLAY_P4
Result code form Lock/UnlockFileEx()
The table from which we should delete things
Delete the contents of the %_data and %_docsize tables.
Control characters are not allowed in strings
** Check to see if the GetVersionEx[AW] functions are deprecated on the
** target system. GetVersionEx was first deprecated in Win8.1.
Structure version number (currently 3)
** Change the size to which the WAL file is trucated on each reset.
** Reset the schema for the database at index iDb. Also reset the
** TEMP schema.
If we reach this point it means that either p[] should be overwritten
** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
** WhereLoop and insert it.
Range of registers allocated for aCol and aFunc
If there is no statement handle, then the blob-handle has
** already been invalidated. Return SQLITE_ABORT in this case.
No longer required OpenEphemeral instr.
** For the index called zIdxName which is found in the database iDb,
** unlike that index from its Table then remove the index from
** the index hash table and free all memory structures associated
** with the index.
Associated database connection
102
Check that pIter->iSwitchRowid is set correctly.
(iCol<<32) + iPos
If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
** as substr(X,1,N) - it returns the first N characters of X. This
** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
** from 2009-02-02 for compatibility of applications that exploited the
** old buggy behavior.
Absolute level to repack
First byte of gap between cell pointers and cell content
comment:
** A copy of the following object occurs in the wal-index immediately
** following the second copy of the WalIndexHdr. This object stores
** information used by checkpoint.
**
** nBackfill is the number of frames in the WAL that have been written
** back into the database. (We call the act of moving content from WAL to
** database "backfilling".) The nBackfill number is never greater than
** WalIndexHdr.mxFrame. nBackfill can only be increased by threads
** holding the WAL_CKPT_LOCK lock (which includes a recovery thread).
** However, a WAL_WRITE_LOCK thread can move the value of nBackfill from
** mxFrame back to zero when the WAL is reset.
**
** nBackfillAttempted is the largest value of nBackfill that a checkpoint
** has attempted to achieve. Normally nBackfill==nBackfillAtempted, however
** the nBackfillAttempted is set before any backfilling is done and the
** nBackfill is only set after all backfilling completes. So if a checkpoint
** crashes, nBackfillAttempted might be larger than nBackfill. The
** WalIndexHdr.mxFrame must never be less than nBackfillAttempted.
**
** The aLock[] field is a set of bytes used for locking. These bytes should
** never be read or written.
**
** There is one entry in aReadMark[] for each reader lock. If a reader
** holds read-lock K, then the value in aReadMark[K] is no greater than
** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
** for any aReadMark[] means that entry is unused. aReadMark[0] is
** a special case; its value is never used and it exists as a place-holder
** to avoid having to offset aReadMark[] indexs by one. Readers holding
** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
** directly from the database.
**
** The value of aReadMark[K] may only be changed by a thread that
** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of
** aReadMark[K] cannot changed while there is a reader is using that mark
** since the reader will be holding a shared lock on WAL_READ_LOCK(K).
**
** The checkpointer may only transfer frames from WAL to database where
** the frame numbers are less than or equal to every aReadMark[] that is
** in use (that is, every aReadMark[j] for which there is a corresponding
** WAL_READ_LOCK(j)). New readers (usually) pick the aReadMark[] with the
** largest value and will increase an unused aReadMark[] to mxFrame if there
** is not already an aReadMark[] equal to mxFrame. The exception to the
** previous sentence is when nBackfill equals mxFrame (meaning that everything
** in the WAL has been backfilled into the database) then new readers
** will choose aReadMark[0] which has value 0 and hence such reader will
** get all their all content directly from the database file and ignore
** the WAL.
**
** Writers normally append new frames to the end of the WAL. However,
** if nBackfill equals mxFrame (meaning that all WAL content has been
** written back into the database) and if no readers are using the WAL
** (in other words, if there are no WAL_READ_LOCK(i) where i>0) then
** the writer will first "reset" the WAL back to the beginning and start
** writing new content beginning at frame 1.
**
** We assume that 32-bit loads are atomic and so no locks are needed in
** order to read from any aReadMark[] entries.
label: code-design
** Functions to deserialize a 16 bit integer, 32 bit real number and
** 64 bit integer. The deserialized value is returned.
Discard the scheme and authority segments of the URI.
700
SQLITE_UNTESTABLE
Minimum legal index key size
** PRAGMA busy_timeout
** PRAGMA busy_timeout = N
**
** Call sqlite3_busy_timeout(db, N). Return the current timeout value
** if one is set. If no busy handler or a different busy handler is set
** then 0 is returned. Setting the busy_timeout to 0 or negative
** disables the timeout.
The cursor of the corresponding table
comment: A place to hold %extra_argument
label: code-design
340
** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback()
** at the conclusion of a transaction.
** Run the integrity-check. If no error occurs and the current contents of
** the FTS index are correct, return SQLITE_OK. Or, if the contents of the
** FTS index are incorrect, return SQLITE_CORRUPT_VTAB.
**
** Or, if an error (e.g. an OOM or IO error) occurs, return an SQLite
** error code.
**
** The integrity-check works as follows. For each token and indexed token
** prefix in the document set, a 64-bit checksum is calculated (by code
** in fts3ChecksumEntry()) based on the following:
**
** + The index number (0 for the main index, 1 for the first prefix
** index etc.),
** + The token (or token prefix) text itself,
** + The language-id of the row it appears in,
** + The docid of the row it appears in,
** + The column it appears in, and
** + The tokens position within that column.
**
** The checksums for all entries in the index are XORed together to create
** a single checksum for the entire index.
**
** The integrity-check code calculates the same checksum in two ways:
**
** 1. By scanning the contents of the FTS index, and
** 2. By scanning and tokenizing the content table.
**
** If the two checksums are identical, the integrity-check is deemed to have
** passed.
Sizes of deleted documents
end of the 'extern "C"' block
Array of registers where record is assembled
ePragFlg:
The cell index. First cell is 0
Opcode: ParseSchema P1 * * P4 *
**
** Read and parse all entries from the SQLITE_MASTER table of database P1
** that match the WHERE clause P4.
**
** This opcode invokes the parser to create a new virtual machine,
** then runs the new virtual machine. It is thus a re-entrant opcode.
Cursor open on index being analyzed
** This macro evaluates to true if either the update hook or the preupdate
** hook are enabled for database connect DB.
************* Begin file opcodes.h ****************************************
RENAME => ID
Check to see if the column is in one of the tables in the FROM
** clause of the aggregate query
comment: Number of pages per doc loaded
label: documentation
************* End of fts3_aux.c *******************************************
** The input pointer currently points to the second byte of a table-header.
** Specifically, to the following:
**
** + number of columns in table (varint)
** + array of PK flags (1 byte per column),
** + table name (nul terminated).
**
** This function ensures that all of the above is present in the input
** buffer (i.e. that it can be accessed without any calls to xInput()).
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code.
** The input pointer is not moved.
An ORDER BY (or GROUP BY) clause, or NULL
A malformed database page might cause us to read past the end
** of page when parsing a cell.
**
** The following block of code checks early to see if a cell extends
** past the end of a page boundary and causes SQLITE_CORRUPT to be
** returned if it does.
OP_DeferredSeek always uses a single rowid
The reference count on pShmNode has already been incremented under
** the cover of the unixEnterMutex() mutex and the pointer from the
** new (struct unixShm) object to the pShmNode has been set. All that is
** left to do is to link the new object into the linked list starting
** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
** mutex.
True if pSub is the right side of a LEFT JOIN
** Table *p is a virtual table. This function removes the VTable object
** for table *p associated with database connection db from the linked
** list in p->pVTab. It also decrements the VTable ref count. This is
** used when closing database connection db to free all of its VTable
** objects without disturbing the rest of the Schema object (which may
** be being used by other shared-cache connections).
ONEPASS_OFF, _SINGLE, or _MULTI. See above
179
SQL statement used to access %_content
** Call sqlite3WalOpen() to open the WAL handle. If the pager is in
** exclusive-locking mode when this function is called, take an EXCLUSIVE
** lock on the database file and use heap-memory to store the wal-index
** in. Otherwise, use the normal shared-memory.
If the cursor cache is stale (meaning it is not currently point at
** the correct row) then bring it up-to-date by doing the necessary
** B-Tree seek.
True if a write cursor
Store the result in pMerger->aTree[iOut]
** Get/set the locking-mode for this pager. Parameter eMode must be one
** of PAGER_LOCKINGMODE_QUERY, PAGER_LOCKINGMODE_NORMAL or
** PAGER_LOCKINGMODE_EXCLUSIVE. If the parameter is not _QUERY, then
** the locking-mode is set to the value specified.
**
** The returned value is either PAGER_LOCKINGMODE_NORMAL or
** PAGER_LOCKINGMODE_EXCLUSIVE, indicating the current (possibly updated)
** locking-mode.
comment: SQLITE_VDBE_COVERAGE
label: test
Lock the destination database, if it is not locked already.
Make sure this is not an attempt to ALTER a view.
SQLITE_OMIT_EXPLAIN
If there is insufficient space allocated at StrBuffer.z, use realloc()
** to grow the buffer until so that it is big enough to accomadate the
** appended data.
A table in the database
Parent tokenizer instance
Set the pointer-map entry for the new sibling page.
70
** End of the routinely-changing class members
**************************************************************************
** Record the fact that the schema cookie will need to be verified
** for database iDb. The code to actually verify the schema cookie
** will occur at the end of the top-level VDBE and will be generated
** later, by sqlite3FinishCoding().
Nothing to do at end-of-loop for a single-pass
Acquire a RESERVED lock
True if a shared lock has ever been held
** Convert pMem so that it is of type MEM_Real.
** Invalidate any prior representations.
Number of leaf pages left to write
Complete SELECT tree
SQLITE_OMIT_UTF16
If the parent table is the same as the child table, and we are about
** to increment the constraint-counter (i.e. this is an INSERT operation),
** then check if the row being inserted matches itself. If so, do not
** increment the constraint-counter.
**
** If any of the parent-key values are NULL, then the row cannot match
** itself. So set JUMPIFNULL to make sure we do the OP_Found if any
** of the parent-key values are NULL (at this point it is known that
** none of the child key values are).
** The following is executed when the parser accepts
Number of buckets in the hash table
** Generate code for an UPDATE of a virtual table.
**
** There are two possible strategies - the default and the special
** "onepass" strategy. Onepass is only used if the virtual table
** implementation indicates that pWhere may match at most one row.
**
** The default strategy is to create an ephemeral table that contains
** for each row to be changed:
**
** (A) The original rowid of that row.
** (B) The revised rowid for the row.
** (C) The content of every column in the row.
**
** Then loop through the contents of this ephemeral table executing a
** VUpdate for each row. When finished, drop the ephemeral table.
**
** The "onepass" strategy does not use an ephemeral table. Instead, it
** stores the same values (A, B and C above) in a register array and
** makes a single invocation of VUpdate.
Set idxFlags flags for the ORDER BY clause
Resolve names in the result set.
** Add seg-reader objects to the Fts3MultiSegReader object passed as the
** 8th argument.
**
** This function returns SQLITE_OK if successful, or an SQLite error code
** otherwise.
raisetype ::= ROLLBACK
** CAPI3REF: Run-Time Limit Categories
** KEYWORDS: {limit category} {*limit categories}
**
** These constants define various performance limits
** that can be lowered at run-time using [sqlite3_limit()].
** The synopsis of the meanings of the various limits is shown below.
** Additional information is available at [limits | Limits in SQLite].
**
** <dl>
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
**
** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
**
** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
** <dd>The maximum number of columns in a table definition or in the
** result set of a [SELECT] or the maximum number of columns in an index
** or in an ORDER BY or GROUP BY clause.</dd>)^
**
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
**
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
**
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
** <dd>The maximum number of instructions in a virtual machine program
** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
** the equivalent tries to allocate space for more than this many opcodes
** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
**
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
** <dd>The maximum number of arguments on a function.</dd>)^
**
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
**
** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
** <dd>The maximum length of the pattern argument to the [LIKE] or
** [GLOB] operators.</dd>)^
**
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
**
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
** <dd>The maximum depth of recursion for triggers.</dd>)^
**
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
** <dd>The maximum number of auxiliary worker threads that a single
** [prepared statement] may start.</dd>)^
** </dl>
the FROM clause
True if this is an OUTER join
OUT: Size of WAL log in frames
** Close an existing SQLite database
Loop through all candidate snippets. Store the best snippet in
** *pFragment. Store its associated 'score' in iBestScore.
If sqlite3FindInIndex() did not find or create an index that is
** suitable for evaluating the IN operator, then evaluate using a
** sequence of comparisons.
**
** This is step (1) in the in-operator.md optimized algorithm.
comment: Comparison against ArraySize-1 since we hold back one extra slot
** as a contingency. In other words, never need more than 3 overflow
** slots but 4 are allocated, just to be safe.
label: code-design
If this is a non-composite (single column) foreign key, check if it
** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
** and *paiCol set to zero and return early.
**
** Otherwise, for a composite foreign key (more than one column), allocate
** space for the aiCol array (returned via output parameter *paiCol).
** Non-composite foreign keys do not require the aiCol array.
20
FTS5_TOKENIZE_* flags
Analyze a term that is composed of two or more subterms connected by
** an OR operator.
Check that the CTE name is unique within this WITH clause. If
** not, store an error in the Parse structure.
Create new entry if true and does not otherwise exist
************* End of vdbeInt.h ********************************************
Index of required stats in anEq[] etc.
Name passed to create_module()
SQL used to determine nLeafEst
** If a Win32 native heap has been configured, this function will attempt to
** destroy and recreate it. If the Win32 native heap is not isolated and/or
** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
** be returned and no changes will be made to the Win32 native heap.
The WAL file is readonly
** 2007 June 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This is part of an SQLite module implementing full-text search.
** This particular file implements the generic tokenizer interface.
30
Use full fsync on the backend
comment: Prevent endless loops on corrupt database files
label: code-design
with ::= WITH RECURSIVE wqlist
Initial key value
Run through the tokenchars. Fold them into the output buffer along
** the way.
The two journal files
Iterator to skip through changeset
An non-ascii-range character. Fold it into the output buffer if
** it is a token character, or break out of the loop if it is not.
Write index of pSrc->a[] here
Loop counter
One for each phrase
25
Initialize the local lockdata
True if low on PAGECACHE memory
Net deferred constraints this transaction.
Name of database file to open
162
** Mark a data page as writeable. This routine must be called before
** making changes to a page. The caller must check the return value
** of this function and be careful not to change any page data unless
** this routine returns SQLITE_OK.
**
** The difference between this function and pager_write() is that this
** function also deals with the special case where 2 or more pages
** fit on a single disk sector. In this case all co-resident pages
** must have been written to the journal file before returning.
**
** If an error occurs, SQLITE_NOMEM or an IO error code is returned
** as appropriate. Otherwise, SQLITE_OK.
Second change record
Remove pParent from the original tree.
0x000008 // available for use
Iterator to run through pList with.
The page and offset from which the current term was read. The offset
** is the offset of the first rowid in the current doclist.
Allocated cursor
Pragma Name 1st arg or NULL
OUT: Set to true if PK row is found
If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y
** Then for every term xN, evaluate as the subexpression: xN AND z
** That way, terms in y that are factored into the disjunction will
** be picked up by the recursive calls to sqlite3WhereBegin() below.
**
** Actually, each subexpression is converted to "xN AND w" where w is
** the "interesting" terms of z - terms that did not originate in the
** ON or USING clause of a LEFT JOIN, and terms that are usable as
** indices.
**
** This optimization also only applies if the (x1 OR x2 OR ...) term
** is not contained in the ON clause of a LEFT JOIN.
** See ticket http://www.sqlite.org/src/info/f2369304e4
Get a NULL terminated version of the new table name.
Create a new pager cache.
** Under memory stress, invoke xStress to try to make pages clean.
** Only clean and unpinned pages can be reclaimed.
If true, jump if either operand is NULL
Set up the local name-context to pass to sqlite3ResolveExprNames() to
** resolve the result-set expression list.
True to dequote
Case 1.
EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
** that is more than 6 times the database page size.
** This routine generates VDBE code that causes a single row of a
** single table to be deleted. Both the original table entry and
** all indices are removed.
**
** Preconditions:
**
** 1. iDataCur is an open cursor on the btree that is the canonical data
** store for the table. (This will be either the table itself,
** in the case of a rowid table, or the PRIMARY KEY index in the case
** of a WITHOUT ROWID table.)
**
** 2. Read/write cursors for all indices of pTab must be open as
** cursor number iIdxCur+i for the i-th index.
**
** 3. The primary key for the row to be deleted must be stored in a
** sequence of nPk memory cells starting at iPk. If nPk==0 that means
** that a search record formed from OP_MakeRecord is contained in the
** single memory location iPk.
**
** eMode:
** Parameter eMode may be passed either ONEPASS_OFF (0), ONEPASS_SINGLE, or
** ONEPASS_MULTI. If eMode is not ONEPASS_OFF, then the cursor
** iDataCur already points to the row to delete. If eMode is ONEPASS_OFF
** then this function must seek iDataCur to the entry identified by iPk
** and nPk before reading from it.
**
** If eMode is ONEPASS_MULTI, then this call is being made as part
** of a ONEPASS delete that affects multiple rows. In this case, if
** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
** iDataCur, then its position should be preserved following the delete
** operation. Or, if iIdxNoSeek is not a valid cursor number, the
** position of iDataCur should be preserved instead.
**
** iIdxNoSeek:
** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
** then it identifies an index cursor (from within array of cursors
** starting at iIdxCur) that already points to the index entry to be deleted.
** Except, this optimization is disabled if there are BEFORE triggers since
** the trigger body might have moved the cursor.
** Turn parser tracing on by giving a stream to which to write the trace
** and a prompt to preface each trace message. Tracing is turned off
** by making either argument NULL
**
** Inputs:
** <ul>
** <li> A FILE* to which trace output should be written.
** If NULL, then tracing is turned off.
** <li> A prefix string written at the beginning of every
** line of trace output. If NULL, then tracing is
** turned off.
** </ul>
**
** Outputs:
** None.
Unable to open the database file
Schema containing the table
1150
This statement is used to determine which level to read the input from
** when performing an incremental merge. It returns the absolute level number
** of the oldest level in the db that contains at least ? segments. Or,
** if no level in the FTS index contains more than ? segments, the statement
** returns zero rows.
** The TableLock structure is only used by the sqlite3TableLock() and
** codeTableLocks() functions.
OUT: Error message, if any
************* Begin file sqliteicu.h **************************************
for auto-named local lock file, just check the host ID and we'll
** use the local lock file path that's already in there
Context used by sqlite3WhereXXX()
SQLITE_STATUS_MALLOC_COUNT
Name of ICU function that failed
Prevents a race condition. Ticket #3537
** Return the number of rows that were changed. If this routine is
** generating code because of a call to sqlite3NestedParse(), do not
** invoke the callback function.
Number of scratch buffers
Use a rollback journal on this file
Mask of WO_xx values describing operator
** Extract a value from the supplied expression in the manner described
** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
** using valueNew().
**
** If pCtx is NULL and an error occurs after the sqlite3_value object
** has been allocated, it is freed before returning. Or, if pCtx is not
** NULL, it is assumed that the caller will free any allocated object
** in all cases.
Status verb
** Allocate nByte bytes of space from within the B-Tree page passed
** as the first argument. Write into *pIdx the index into pPage->aData[]
** of the first byte of allocated space. Return either SQLITE_OK or
** an error code (usually SQLITE_CORRUPT).
**
** The caller guarantees that there is sufficient space to make the
** allocation. This routine might need to defragment in order to bring
** all the space together, however. This routine will avoid using
** the first two bytes past the cell pointer area since presumably this
** allocation is being made in order to insert a new cell, so we will
** also end up needing a new cell pointer.
************* Continuing where we left off in fts3.c **********************
Error message from sqlite3ParseUri()
If memory status is enabled, then the malloc.c wrapper will already
** hold the STATIC_MEM mutex when the routines here are invoked.
Comparison function
Last possible cell or freeblock offset
IN/OUT: Right input list
Expression opcode
** Return the number of pages still to be backed up as of the most recent
** call to sqlite3_backup_step().
** Invoke sqlite3_declare_vtab() to declare the schema for the FTS3 table
** passed as the first argument. This is done as part of the xConnect()
** and xCreate() methods.
**
** If *pRc is non-zero when this function is called, it is a no-op.
** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
** before returning.
Arguments to table-valued-function
Set zIn to point at the start of the input buffer and zTerm to point 1
** byte past the end.
**
** Variable zOut is set to point at the output buffer, space obtained
** from sqlite3_malloc().
** Destroy the private VFS created for the rbu handle passed as the only
** argument by an earlier call to rbuCreateVfs().
Name of a table or index
Both or neither are NULL
Destructor function
When to reset OP_Once counters
How to handle constraint errors
Size of all column names (incl. 0x00)
Index (main or aPrefix[] entry)
If the statement is of the form
**
** INSERT INTO <table1> SELECT * FROM <table2>;
**
** Then special optimizations can be applied that make the transfer
** very fast and which reduce fragmentation of indices.
**
** This is the 2nd template.
comment: If pSchema is NULL, then return -1000000. This happens when code in
** expr.c is trying to resolve a reference to a transient table (i.e. one
** created by a sub-select). In this case the return value of this
** function should never be used.
**
** We return -1000000 instead of the more usual -1 simply because using
** -1000000 as the incorrect index into db->aDb[] is much
** more likely to cause a segfault than -1 (of course there are assert()
** statements too, but it never hurts to play the odds).
label: code-design
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** in order to generate code for DELETE FROM statements.
Flags to pass to open()
xCreate - create a table
Pointer to array of page numbers
comment:
** Create a new PCache object. Storage space to hold the object
** has already been allocated and is passed in as the p pointer.
** The caller discovers how much space needs to be allocated by
** calling sqlite3PcacheSize().
**
** szExtra is some extra space allocated for each page. The first
** 8 bytes of the extra space will be zeroed as the page is allocated,
** but remaining content will be uninitialized. Though it is opaque
** to this module, the extra space really ends up being the MemPage
** structure in the pager.
label: code-design
The index of the database the expression refers to
Fsync at this offset
If this is an INSERT operation, or an UPDATE that modifies the rowid
** value, then this operation requires constraint handling.
**
** If the on-conflict mode is REPLACE, this means that the existing row
** should be deleted from the database before inserting the new row. Or,
** if the on-conflict mode is other than REPLACE, then this method must
** detect the conflict and return SQLITE_CONSTRAINT before beginning to
** modify the database file.
True if this change is "indirect"
We are trying for an exclusive lock but another thread in this
** same process is still holding a shared lock.
560
** Insert cell pCell into node pNode. Node pNode is the head of a
** subtree iHeight high (leaf nodes have iHeight==0).
This happens if the segment is being used as an input to an incremental
** merge and all data has already been "trimmed". See function
** fts5TrimSegments() for details. In this case leave the iterator empty.
** The caller will see the (pIter->pLeaf==0) and assume the iterator is
** at EOF already.
(283) cmd ::= create_table create_table_args
** Implementation of the last_insert_rowid() SQL function. The return
** value is the same as the sqlite3_last_insert_rowid() API function.
Source table
Covering index scans
Percent symbol. %%
Opening a db handle. Fourth parameter is passed 0.
If the caller is an UPDATE or DELETE statement that is requesting
** to use a one-pass algorithm, determine if this is appropriate.
** Compute the Year, Month, and Day from the julian day number.
** The first argument passed to this function is a serial-type that
** corresponds to an integer - all values between 1 and 9 inclusive
** except 7. The second points to a buffer containing an integer value
** serialized according to serial_type. This function deserializes
** and returns the value.
** Allowed values for et_info.flags
VDBE has completed execution
Allocate a new SessionChange object. Ensure that the aRecord[]
** buffer of the new object is large enough to hold any record that
** may be generated by combining the input records.
** Set the bit in the IntegrityCk.aPgRef[] array that corresponds to page iPg.
Next info block in a list of them all
** Apply the changeset passed via xInput/pIn to the main database
** attached to handle "db". Invoke the supplied conflict handler callback
** to resolve any conflicts encountered while applying the change.
DELETE_CONTENT
Acquire an EXCLUSIVE lock
209
Are LHS fields reordered?
** Return a pointer to the Pager.nExtra bytes of "extra" space
** allocated along with the specified page.
** Mark a single data page as writeable. The page is written into the
** main journal or sub-journal as required. If the page is written into
** one of the journals, the corresponding bit is set in the
** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
** of any open savepoints as appropriate.
** Forward declaration to account for the circular dependency between
** functions fts3SegmentMerge() and fts3AllocateSegdirIdx().
INITIALLY
DEBUG and TESTING functions
User is requesting the value of the special column with the same name
** as the table. Return the cursor integer id number. This value is only
** useful in that it may be passed as the first argument to an FTS5
** auxiliary function.
** Determine if any of the arguments to the pExpr Function reference
** pSrcList. Return true if they do. Also return true if the function
** has no arguments or has only constant arguments. Return false if pExpr
** references columns but not columns of tables found in pSrcList.
Wal file descriptor for this main db
sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
**
** Pass pFree into sqlite3ScratchFree().
** If sz>0 then allocate a scratch buffer into pNew.
OUT: Pointer to page number array
****************************************** 3rd ************ 4th **********
Discard the contents of the pending-terms hash table.
** Deallocate all chunks from a RowSet. This frees all memory that
** the RowSet has allocated over its lifetime. This routine is
** the destructor for the RowSet.
** If there is a "*-oal" file in the file-system corresponding to the
** target database in the file-system, delete it. If an error occurs,
** leave an error code and error message in the rbu handle.
Insert is likely an append
** CAPI3REF: Virtual Table Indexing Information
** KEYWORDS: sqlite3_index_info
**
** The sqlite3_index_info structure and its substructures is used as part
** of the [virtual table] interface to
** pass information into and receive the reply from the [xBestIndex]
** method of a [virtual table module]. The fields under **Inputs** are the
** inputs to xBestIndex and are read-only. xBestIndex inserts its
** results into the **Outputs** fields.
**
** ^(The aConstraint[] array records WHERE clause constraints of the form:
**
** <blockquote>column OP expr</blockquote>
**
** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is
** stored in aConstraint[].op using one of the
** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
** ^(The index of the column is stored in
** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
** expr on the right-hand side can be evaluated (and thus the constraint
** is usable) and false if it cannot.)^
**
** ^The optimizer automatically inverts terms of the form "expr OP column"
** and makes other simplifications to the WHERE clause in an attempt to
** get as many WHERE clause terms into the form shown above as possible.
** ^The aConstraint[] array only reports WHERE clause terms that are
** relevant to the particular virtual table being queried.
**
** ^Information about the ORDER BY clause is stored in aOrderBy[].
** ^Each term of aOrderBy records a column of the ORDER BY clause.
**
** The colUsed field indicates which columns of the virtual table may be
** required by the current scan. Virtual table columns are numbered from
** zero in the order in which they appear within the CREATE TABLE statement
** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
** the corresponding bit is set within the colUsed mask if the column may be
** required by SQLite. If the table has at least 64 columns and any column
** to the right of the first 63 is required, then bit 63 of colUsed is also
** set. In other words, column iCol may be required if the expression
** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
** non-zero.
**
** The [xBestIndex] method must fill aConstraintUsage[] with information
** about what parameters to pass to xFilter. ^If argvIndex>0 then
** the right-hand side of the corresponding aConstraint[] is evaluated
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
** is true, then the constraint is assumed to be fully handled by the
** virtual table and is not checked again by SQLite.)^
**
** ^The idxNum and idxPtr values are recorded and passed into the
** [xFilter] method.
** ^[sqlite3_free()] is used to free idxPtr if and only if
** needToFreeIdxPtr is true.
**
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
** the correct order to satisfy the ORDER BY clause so that no separate
** sorting step is required.
**
** ^The estimatedCost value is an estimate of the cost of a particular
** strategy. A cost of N indicates that the cost of the strategy is similar
** to a linear scan of an SQLite table with N rows. A cost of log(N)
** indicates that the expense of the operation is similar to that of a
** binary search on a unique indexed field of an SQLite table with N rows.
**
** ^The estimatedRows value is an estimate of the number of rows that
** will be returned by the strategy.
**
** The xBestIndex method may optionally populate the idxFlags field with a
** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
** assumes that the strategy may visit at most one row.
**
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
** SQLite also assumes that if a call to the xUpdate() method is made as
** part of the same statement to delete or update a virtual table row and the
** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
** any database changes. In other words, if the xUpdate() returns
** SQLITE_CONSTRAINT, the database contents must be exactly as they were
** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
** the xUpdate method are automatically rolled back by SQLite.
**
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
** If a virtual table extension is
** used with an SQLite version earlier than 3.8.2, the results of attempting
** to read or write the estimatedRows field are undefined (but are likely
** to included crashing the application). The estimatedRows field should
** therefore only be used if [sqlite3_libversion_number()] returns a
** value greater than or equal to 3008002. Similarly, the idxFlags field
** was added for [version 3.9.0] ([dateof:3.9.0]).
** It may therefore only be used if
** sqlite3_libversion_number() returns a value greater than or equal to
** 3009000.
OK to spill pager cache
Expression tree height of current sub-select
xShmMap method
Blob handle open on %_segments table
** Step the cursor to the back to the previous entry in the database.
** Return values:
**
** SQLITE_OK success
** SQLITE_DONE the cursor is already on the first element of the table
** otherwise some kind of error occurred
**
** The main entry point is sqlite3BtreePrevious(). That routine is optimized
** for the common case of merely decrementing the cell counter BtCursor.aiIdx
** to the previous cell on the current page. The (slower) btreePrevious()
** helper routine is called when it is necessary to move to a different page
** or to restore the cursor.
**
** If bit 0x01 of the F argument to sqlite3BtreePrevious(C,F) is 1, then
** the cursor corresponds to an SQL index and this routine could have been
** skipped if the SQL index had been a unique index. The F argument is a
** hint to the implement. The native SQLite btree implementation does not
** use this hint, but COMDB2 does.
Level for the new search point
98
PRAGMA synchronous=FULL
Buffer to write page data to
Register any built-in FTS5 module before loading the automatic
** extensions. This allows automatic extensions to register FTS5
** tokenizers and auxiliary functions.
name
Create a label to jump to when we want to abort the query
The Index
Parent row data starts here
OUT: Columns for imposter table
Id of cursor to find
comment:
** Return TRUE if the innermost loop of the WHERE clause implementation
** returns rows in ORDER BY order for complete run of the inner loop.
**
** Across multiple iterations of outer loops, the output rows need not be
** sorted. As long as rows are sorted for just the innermost loop, this
** routine can return TRUE.
label: code-design
Function context
TK_LT
Opcode: NotNull P1 P2 * * *
** Synopsis: if r[P1]!=NULL goto P2
**
** Jump to P2 if the value in register P1 is not NULL.
************* End of rowset.c *********************************************
Preallocated, blank file handle
** Create a new virtual database engine.
** An instance of the following structure is used to hold information
** about a cell. The parseCellPtr() function fills in this structure
** based on information extract from the raw disk page.
Get the local shared locks
Height of the tree headed by this node
Array of page numbers
Result returned by the thread
Delete the index entries associated with the current record.
Must be element [3]
HAVE_ISNAN
The column the token must match
Size of buffer z in bytes
OP_Column only used for length()
comment:
** Attempt to reduce the value of the WalCkptInfo.nBackfillAttempted
** variable so that older snapshots can be accessed. To do this, loop
** through all wal frames from nBackfillAttempted to (nBackfill+1),
** comparing their content to the corresponding page with the database
** file, if any. Set nBackfillAttempted to the frame number of the
** first frame for which the wal file content matches the db file.
**
** This is only really safe if the file-system is such that any page
** writes made by earlier checkpointers were atomic operations, which
** is not always true. It is also possible that nBackfillAttempted
** may be left set to a value larger than expected, if a wal frame
** contains content that duplicate of an earlier version of the same
** page.
**
** SQLITE_OK is returned if successful, or an SQLite error code if an
** error occurs. It is not an error if nBackfillAttempted cannot be
** decreased at all.
label: code-design
Note: this cast is safe, because the origin data point was an int
** that was cast to a (const char *).
First register holding data before packing
Nul-terminated string containing boolean
Handle compound SELECT statements using the separate multiSelect()
** procedure.
LCS for the current iterator positions
230
Added by 3.4.1
Tokenizer name
OUT: Configuration object
argv[0] passed to function
Size of the current data field
** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS
** or CACHE_WRITE to sqlite3_db_status().
Array of subprograms
Generate code to report an FK violation to the caller.
** The minimum amount of free space that we have seen.
Generate a subroutine that outputs the current row of the B
** select as the next output row of the compound select.
Permissions to create file with
** The main routine for vdbePmaReaderIncrMergeInit() operations run in
** background threads.
Vdbe pre-update hook is invoked by
MATCHINFO
All prior WhereLoops are order-distinct
EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
** twos-complement integer.
Hash of page content
Cursor for a table whose size needs checking
same as TK_NOTNULL, jump, in1
Error code from preupdate_new/old
Fsync the WAL header if true
** No-op versions of all memory allocation routines
EQP id of right-hand query
Result of prior MovetoUnpacked() call
IN/OUT: Increment this value by PMA size
Opcode of pRight
** Create a temporary file name and store the resulting pointer into pzBuf.
** The pointer returned in pzBuf must be freed via sqlite3_free().
Bytes of PMA space required
aLevel[] array
** Allocate and return new r-tree node. Initially, (RtreeNode.iNode==0),
** indicating that node has not yet been assigned a node number. It is
** assigned a node number when nodeWrite() is called to write the
** node contents out to the database.
Name of database containing pTab
Indexes with default row estimates should not have stat1 data
The wrFlag argument to sqlite3BtreeCursor()
PRAGMA secure_delete is enabled
The main parser program.
** The first argument is a pointer to a structure obtained from
** "sqlite3ParserAlloc" which describes the current state of the parser.
** The second argument is the major token number. The third is
** the minor token. The fourth optional argument is whatever the
** user wants (and specified in the grammar) and is available for
** use by the action routines.
**
** Inputs:
** <ul>
** <li> A pointer to the parser (an opaque structure.)
** <li> The major token number.
** <li> The minor token number.
** <li> An option argument of a grammar-specified type.
** </ul>
**
** Outputs:
** None.
BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1)
** Create a new symbolic label for an instruction that has yet to be
** coded. The symbolic label is really just a negative number. The
** label can be used as the P2 value of an operation. Later, when
** the label is resolved to a specific address, the VDBE will scan
** through its operation list and change all values of P2 which match
** the label into the resolved address.
**
** The VDBE knows that a P2 value is a label because labels are
** always negative and P2 values are suppose to be non-negative.
** Hence, a negative P2 value is a label that has yet to be resolved.
**
** Zero is returned if a malloc() fails.
op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
** a TK_COLUMN but was previously evaluated and cached in a register
Values to bind to statement
Mask of configuration flags
comment: Size of temporary buffer
label: code-design
Entry point. Use "sqlite3_extension_init" if 0
Seed the search with a single WherePath containing zero WhereLoops.
**
** TUNING: Do not let the number of iterations go above 28. If the cost
** of computing an automatic index is not paid back within the first 28
** rows, then do not use the automatic index.
z[] is now the stemmed word in reverse order. Flip it back
** around into forward order and return.
Storage module to write to
** CUSTOM AUXILIARY FUNCTIONS
************************************************************************
FTS5 backend
** Implementation of FTS5 xRename method. Rename an fts5 table.
Offset of first rowid on leaf
** CAPI3REF: Changeset Iterator Handle
Held in memory not obtained from malloc()
Restriction (5)
Authenticated as an administrator
** Create a "unicode61" tokenizer.
Allocate space for the Fts3MultiSegReader.aCsr[] array
Write the extra pages and truncate the database file as required
** Return true if the current thread holds the database connection
** mutex and all required BtShared mutexes.
**
** This routine is used inside assert() statements only.
Special case - the last token of the snippet is also the last token
** of the column. Append any punctuation that occurred between the end
** of the previous token and the end of the document to the output.
** Then break out of the loop.
** CAPI3REF: Enable Or Disable Extension Loading
** METHOD: sqlite3
**
** ^So as not to open security holes in older applications that are
** unprepared to deal with [extension loading], and as a means of disabling
** [extension loading] while evaluating user-entered SQL, the following API
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
**
** ^Extension loading is off by default.
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
** to turn extension loading on and call it with onoff==0 to turn
** it back off again.
**
** ^This interface enables or disables both the C-API
** [sqlite3_load_extension()] and the SQL function [load_extension()].
** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
** to enable or disable only the C-API.)^
**
** <b>Security warning:</b> It is recommended that extension loading
** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
** rather than this interface, so the [load_extension()] SQL function
** remains disabled. This will prevent SQL injections from giving attackers
** access to extension loading capabilities.
** Delete the named file.
**
** Note that Windows does not allow a file to be deleted if some other
** process has it open. Sometimes a virus scanner or indexing program
** will open a journal file shortly after it is created in order to do
** whatever it does. While this other process is holding the
** file open, we will be unable to delete it. To work around this
** problem, we delay 100 milliseconds and try to delete again. Up
** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
** up and returning an error.
** Bind a blob value to an SQL statement variable.
** CAPI3REF: Impose A Limit On Heap Size
**
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
** soft limit on the amount of heap memory that may be allocated by SQLite.
** ^SQLite strives to keep heap memory utilization below the soft heap
** limit by reducing the number of pages held in the page cache
** as heap memory usages approaches the limit.
** ^The soft heap limit is "soft" because even though SQLite strives to stay
** below the limit, it will exceed the limit rather than generate
** an [SQLITE_NOMEM] error. In other words, the soft heap limit
** is advisory only.
**
** ^The return value from sqlite3_soft_heap_limit64() is the size of
** the soft heap limit prior to the call, or negative in the case of an
** error. ^If the argument N is negative
** then no change is made to the soft heap limit. Hence, the current
** size of the soft heap limit can be determined by invoking
** sqlite3_soft_heap_limit64() with a negative argument.
**
** ^If the argument N is zero then the soft heap limit is disabled.
**
** ^(The soft heap limit is not enforced in the current implementation
** if one or more of following conditions are true:
**
** <ul>
** <li> The soft heap limit is set to zero.
** <li> Memory accounting is disabled using a combination of the
** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
** <li> An alternative page cache implementation is specified using
** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
** <li> The page cache allocates from its own memory pool supplied
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
** from the heap.
** </ul>)^
**
** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]),
** the soft heap limit is enforced
** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
** the soft heap limit is enforced on every memory allocation. Without
** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
** when memory is allocated by the page cache. Testing suggests that because
** the page cache is the predominate memory user in SQLite, most
** applications will achieve adequate soft heap limit enforcement without
** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
**
** The circumstances under which SQLite will enforce the soft heap limit may
** changes in future releases of SQLite.
UNION
Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
** because they could be computed at compile-time. But when LIMIT and OFFSET
** became arbitrary expressions, we were forced to add restrictions (13)
** and (14).
** Constant tokens for values 0 and 1.
*****************************************************************************
****************** Begin Unique File ID Utility Used By VxWorks ***************
**
** On most versions of unix, we can get a unique ID for a file by concatenating
** the device number and the inode number. But this does not work on VxWorks.
** On VxWorks, a unique file id must be based on the canonical filename.
**
** A pointer to an instance of the following structure can be used as a
** unique file ID in VxWorks. Each instance of this structure contains
** a copy of the canonical filename. There is also a reference count.
** The structure is reclaimed when the number of pointers to it drops to
** zero.
**
** There are never very many files open at one time and lookups are not
** a performance-critical path, so it is sufficient to put these
** structures on a linked list.
Miscellaneous flags. See below
String pointer
SQLITE_OMIT_SUBQUERY
only re-establish the shared lock if necessary
** Attempt to reallocate p. If the reallocation fails, then free p
** and set the mallocFailed flag in the database connection.
phrase
Size of scratch memory requested
** Maximum depth of an SQLite B-Tree structure. Any B-Tree deeper than
** this will be declared corrupt. This value is calculated based on a
** maximum database size of 2^31 pages a minimum fanout of 2 for a
** root-node and 3 for all other internal nodes.
**
** If a tree that appears to be taller than this is encountered, it is
** assumed that the database is corrupt.
** If FTS_LOG_MERGES is defined, call sqlite3_log() to report each automatic
** and incremental merge operation that takes place. This is used for
** debugging FTS only, it should not usually be turned on in production
** systems.
End non-truncate path
Register holding results
OUT: changeset (left <concat> right)
flags controlling this file
Program Counter in parent (calling) frame
Cell content
Pointer map page data
** Flush any data in the pending-terms hash table to disk. If successful,
** merge all segments in the database (including the new segment, if
** there was any data to flush) into a single segment.
If there is both a GROUP BY and an ORDER BY clause and they are
** identical, then it may be possible to disable the ORDER BY clause
** on the grounds that the GROUP BY will cause elements to come out
** in the correct order. It also may not - the GROUP BY might use a
** database index that causes rows to be grouped together as required
** but not actually sorted. Either way, record the fact that the
** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
** variable.
** Get/set the size-limit used for persistent journal files.
**
** Setting the size limit to -1 means no limit is enforced.
** An attempt to set a limit smaller than -1 is a no-op.
These routines are used inside assert() statements only.
** Return non-zero if a read (or write) transaction is active.
Preference to built-in funcs
Case 4.
Do not create or use a rollback journal
True to iterate in reverse order
** Walk an expression tree. Return 1 if the expression contains a
** subquery of some kind. Return 0 if there are no subqueries.
Remove the table entry from SQLite's internal schema and modify
** the schema cookie.
Check if the requested node is already in the hash table. If so,
** increase its reference count and return it.
Real value of left operand
Memory cell to set to string value
comment: Grow the two buffers to pgsz + padding bytes in size.
label: code-design
Info on how to code the ORDER BY clause
************* End of printf.c *********************************************
Figure out the ON CONFLICT policy that will be used for this step
** of the trigger program. If the statement that caused this trigger
** to fire had an explicit ON CONFLICT, then use it. Otherwise, use
** the ON CONFLICT policy that was specified as part of the trigger
** step statement. Example:
**
** CREATE TRIGGER AFTER INSERT ON t1 BEGIN;
** INSERT OR REPLACE INTO t2 VALUES(new.a, new.b);
** END;
**
** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
"VIEW" or "TABLE"
20
Plan with no prereqs and no IN(...) seen
Expression text
OUT: Result of comparison
#ifndef SQLITE_OMIT_SUBQUERY
!defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
Information on the ORDER BY clause
Load the extension into this database connection
Index of column in pTab
180
The name context
SelectDest targetting the Queue table
** Check to make sure the temporary directory ends with an appropriate
** separator. If it does not and there is not enough space left to add
** one, fail.
If the ending matches this... (Reversed)
Read the database schema. If an error occurs, leave an error message
** and code in pParse and return NULL.
** Remove all records associated with segment iSegid.
Tables have different CHECK constraints. Ticket #2252
synopsis: r[P2]=r[P1]
OUT: Value read from the nRec field
If an existing hash entry cannot be found, create a new one.
Name of the VFS to use
Initialize any AUTOINCREMENT data structures required.
** Gather the results for matchinfo directives 'y' and 'b'.
Array to populate
All SELECT results must be columns.
** The expression is the default value for the most recently added column
** of the table currently under construction.
**
** Default value expressions must be constant. Raise an exception if this
** is not the case.
**
** This routine is called by the parser while in the middle of
** parsing a CREATE TABLE statement.
************* Begin file sqlite3rbu.h *************************************
If the xMutexAlloc method has not been set, then the user did not
** install a mutex implementation via sqlite3_config() prior to
** sqlite3_initialize() being called. This block copies pointers to
** the default implementation into the sqlite3GlobalConfig structure.
Number of the page to fetch
NOT
Current value
TUNING: unlikely() probability is 0.0625. likely() is 0.9375
Value of the argument and schema
Path of file (possibly) being created
First replace any existing entry.
**
** Actually, the way the column cache is currently used, we are guaranteed
** that the object will never already be in cache. Verify this guarantee.
comment:
** Change the P2 operand of instruction addr so that it points to
** the address of the next instruction to be coded.
label: documentation
Number of pending OP_SqlExec opcodes
If zName is the not the name of a table in the schema created using
** CREATE, then check to see if it is the name of an virtual table that
** can be an eponymous virtual table.
Offset to write
Always returns pCsr->sPoint
** This routine is called once for each row in the result table. Its job
** is to fill in the TabResult structure appropriately, allocating new
** memory as necessary.
size of the input
Schema of database iDb
Passing NULL to HeapFree is undefined.
Statement to query %_docsize
sqlite3_mutex_methods*
** At least one instance of the following structure is created for each
** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
** statement. All such objects are stored in the linked list headed at
** Parse.pTriggerPrg and deleted once statement compilation has been
** completed.
**
** A Vdbe sub-program that implements the body and WHEN clause of trigger
** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of
** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable.
** The Parse.pTriggerPrg list never contains two entries with the same
** values for both pTrigger and orconf.
**
** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns
** accessed (or set to 0 for triggers fired as a result of INSERT
** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to
** a mask of new.* columns used by the program.
True for patchsets
Offset of header on pPg
Number of pointers to this structure
Value of P1 operand
Pointer to the cell text.
Instruction pcx is the OP_Program that invoked the sub-program
** currently being halted. If the p2 instruction of this OP_Halt
** instruction is set to OE_Ignore, then the sub-program is throwing
** an IGNORE exception. In this case jump to the address specified
** as the p2 of the calling OP_Program.
** CAPI3REF: User Data For Functions
** METHOD: sqlite3_context
**
** ^The sqlite3_user_data() interface returns a copy of
** the pointer that was the pUserData parameter (the 5th parameter)
** of the [sqlite3_create_function()]
** and [sqlite3_create_function16()] routines that originally
** registered the application defined function.
**
** This routine must be called from the same thread in which
** the application-defined function is running.
The number of == or IN constraints to code
Size of term suffix
Allocate a new page. This page will become the right-sibling of
** pPage. Make the parent page writable, so that the new divider cell
** may be inserted. If both these operations are successful, proceed.
rc==0 here means that one or both of the keys ran out of fields and
** all the fields up to that point were equal. Return the default_rc
** value.
Increment the xRowid value
Index of the database to use
** Interpret the argument as a unicode codepoint. If the codepoint
** is an upper case character that has a lower case equivalent,
** return the codepoint corresponding to the lower case version.
** Otherwise, return a copy of the argument.
**
** The results are undefined if the value passed to this function
** is less than zero.
Also used in P2 (not P5) of OP_Delete
comment:
** Parameter zMaster is the name of a master journal file. A single journal
** file that referred to the master journal file has just been rolled back.
** This routine checks if it is possible to delete the master journal file,
** and does so if it is.
**
** Argument zMaster may point to Pager.pTmpSpace. So that buffer is not
** available for use within this function.
**
** When a master journal file is created, it is populated with the names
** of all of its child journals, one after another, formatted as utf-8
** encoded text. The end of each child journal file is marked with a
** nul-terminator byte (0x00). i.e. the entire contents of a master journal
** file for a transaction involving two databases might be:
**
** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
**
** A master journal file may only be deleted once all of its child
** journals have been rolled back.
**
** This function reads the contents of the master-journal file into
** memory and loops through each of the child journal names. For
** each child journal, it checks if:
**
** * if the child journal exists, and if so
** * if the child journal contains a reference to master journal
** file zMaster
**
** If a child journal can be found that matches both of the criteria
** above, this function returns without doing anything. Otherwise, if
** no such child journal can be found, file zMaster is deleted from
** the file-system using sqlite3OsDelete().
**
** If an IO error within this function, an error code is returned. This
** function allocates memory by calling sqlite3Malloc(). If an allocation
** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors
** occur, SQLITE_OK is returned.
**
** TODO: This function allocates a single block of memory to load
** the entire contents of the master journal file. This could be
** a couple of kilobytes or so - potentially larger than the page
** size.
label: code-design
Pointer to sub-list content
Database file handle
EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
** be less than 480. In other words, if the page size is 512, then the
** reserved space size cannot exceed 32.
64
313
store the result
Opcode: Integer P1 P2 * * *
** Synopsis: r[P2]=P1
**
** The 32-bit integer value P1 is written into register P2.
** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
** attached database. Otherwise, invoke it for the database named zDb only.
If there is no %_docsize table, there should be no requests for
** statements to operate on it.
0x10
Temp area for cell content
Might happen if EMPTY_RESULT_CALLBACKS are on
** If the TEMP database is open, close it and mark the database schema
** as needing reloading. This must be done when using the SQLITE_TEMP_STORE
** or DEFAULT_TEMP_STORE pragmas.
This routine is a no-op for virtual tables. Leave the output
** variables *piDataCur and *piIdxCur uninitialized so that valgrind
** can detect if they are used by mistake in the caller.
160
** Read bytes from *pz and convert them into a positive integer. When
** finished, leave *pz pointing to the first character past the end of
** the integer. The *pLen parameter holds the length of the string
** in *pz and is decremented once for each character in the integer.
Temp space used by merge-sort
Clear flags from pages of the page cache
Update any backup objects copying the contents of this pager.
If it is not a BLOB literal, then it must be an ID, since no
** SQL keywords start with the letter 'x'. Fall through
Suppress duplicates for UNION, EXCEPT, and INTERSECT
High accuracy coordinate
EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
** is stored in the fifth field of the b-tree page header.
** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
** number of fragmented free bytes within the cell content area.
The current SQL statement
IMP: R-24505-23230
** Read data from the in-memory journal file. This is the implementation
** of the sqlite3_vfs.xRead method.
DESC
Loop counter over the terms of the join
The table key
Optional column name list for the table
Query column to extract text from
Level of current node or entry
Remove connection p from the blocked connections list.
Loop over the tables in the join, from left to right
If we survive all prior tests, that means this term is worth hinting
Compute and store the full pathname in an allocated buffer pointed
** to by zPathname, length nPathname. Or, if this is a temporary file,
** leave both nPathname and zPathname set to 0.
Append content to the JSON parse
The open cursor on the table
Opcode: IntCopy P1 P2 * * *
** Synopsis: r[P2]=r[P1]
**
** Transfer the integer value held in register P1 into register P2.
**
** This is an optimized version of SCopy that works only for integer
** values.
comment: The following constant maps TK_xx codes into corresponding
** seek opcodes. It depends on a particular ordering of TK_xx
label: code-design
Constraining operation
Number of references to this one
Test that the "totals" (sometimes called "averages") record looks Ok
Increment the free page count on pPage1
The auto-commit flag.
UPDATE + UPDATE
First position in position-list
Temp space sufficient to hold a single cell
If no match, return 0.
Count of the number of search attempts
************* End of fkey.c ***********************************************
A sub-query in the FROM clause of a SELECT
Cursor to scan b-tree
comment: ERROR: bad checksum
label: code-design
After pStmt has returned SQLITE_DONE
Notifications from sqlite3_log()
Number of slots in apCsr[]
** Open a read-transaction on the snapshot idendified by pSnapshot.
The table being indexed
** Release a reference to page pPg. pPg must have been returned by an
** earlier call to pagerAcquireMapPage().
** Generate code that pushes the value of every element of the given
** expression list into a sequence of registers beginning at target.
**
** Return the number of elements evaluated.
**
** The SQLITE_ECEL_DUP flag prevents the arguments from being
** filled using OP_SCopy. OP_Copy must be used instead.
**
** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
** factored out into initialization code.
**
** The SQLITE_ECEL_REF flag means that expressions in the list with
** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
** in registers at srcReg, and so the value can be copied from there.
Opcode: RowData P1 P2 P3 * *
** Synopsis: r[P2]=data
**
** Write into register P2 the complete row content for the row at
** which cursor P1 is currently pointing.
** There is no interpretation of the data.
** It is just copied onto the P2 register exactly as
** it is found in the database file.
**
** If cursor P1 is an index, then the content is the key of the row.
** If cursor P2 is a table, then the content extracted is the data.
**
** If the P1 cursor must be pointing to a valid row (not a NULL row)
** of a real table, not a pseudo-table.
**
** If P3!=0 then this opcode is allowed to make an ephermeral pointer
** into the database page. That means that the content of the output
** register will be invalidated as soon as the cursor moves - including
** moves caused by other cursors that "save" the the current cursors
** position in order that they can write to the same table. If P3==0
** then a copy of the data is made into memory. P3!=0 is faster, but
** P3==0 is safer.
**
** If P3!=0 then the content of the P2 register is unsuitable for use
** in OP_Result and any OP_Result will invalidate the P2 register content.
** The P2 register content is invalidated by opcodes like OP_Function or
** by any use of another cursor pointing to the same table.
** Free a doclist-index iterator object allocated by fts5DlidxIterInit().
iColumn matches a term of the ORDER BY clause
-1: before desired location +1: after
Ensure the %_content statement is reset.
41
Not allowed on leftward elements
** Round down to the nearest multiple of 8
Root node of rtree structure
Zero the output value in case an error occurs.
Description of content to append
Even though this opcode does not use dynamic strings for
** the result, result columns may become dynamic if the user calls
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
sqlite_stat4.nEq
This checks any of the "extra" bytes allocated due
** to rounding up to an 8 byte boundary to ensure
** they haven't been overwritten.
Btree this cursor belongs to
** This routine generates code that opens the sqlite_statN tables.
** The sqlite_stat1 table is always relevant. sqlite_stat2 is now
** obsolete. sqlite_stat3 and sqlite_stat4 are only opened when
** appropriate compile-time options are provided.
**
** If the sqlite_statN tables do not previously exist, it is created.
**
** Argument zWhere may be a pointer to a buffer containing a table name,
** or it may be a NULL pointer. If it is not NULL, then all entries in
** the sqlite_statN tables associated with the named table are deleted.
** If zWhere==0, then code is generated to delete all stat table entries.
Fts3MultiSegReader to modify
Set to true if at least one expr. value extracted
Sort in ascending order
Tokenizer argument strings
Decomposition into subterms
The sqlite_sequence table used by AUTOINCREMENT
Bytes of local payload
Obtain the page at pgnoRoot
** Implementation of offsets() function.
** This function may only be called when a read-transaction is open on
** the pager. It returns the total number of pages in the database.
**
** However, if the file is between 1 and <page-size> bytes in size, then
** this is considered a 1 page file.
If the attempt to grab the exclusive lock failed, release the
** pending lock that may have been obtained instead.
** Return the current state of the RBU vacuum or update operation.
Check if this page has already been written into the wal file by
** the current transaction. If so, overwrite the existing frame and
** set Wal.writeLock to WAL_WRITELOCK_RECKSUM - indicating that
** checksums must be recomputed when the transaction is committed.
User pointer passed to xCreate()
Number of SELECT statements seen
Seg-reader is at EOF. Remove the entire input segment.
************** End of Unique File ID Utility Used By VxWorks ****************
*****************************************************************************
259
** CAPI3REF: Database Connection Configuration Options
**
** These constants are the available integer configuration options that
** can be passed as the second argument to the [sqlite3_db_config()] interface.
**
** New configuration options may be added in future releases of SQLite.
** Existing configuration options might be discontinued. Applications
** should check the return code from [sqlite3_db_config()] to make sure that
** the call worked. ^The [sqlite3_db_config()] interface will return a
** non-zero [error code] if a discontinued or unsupported configuration option
** is invoked.
**
** <dl>
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
** <dd> ^This option takes three additional arguments that determine the
** [lookaside memory allocator] configuration for the [database connection].
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
** pointer to a memory buffer to use for lookaside memory.
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
** may be NULL in which case SQLite will allocate the
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
** size of each lookaside buffer slot. ^The third argument is the number of
** slots. The size of the buffer in the first argument must be greater than
** or equal to the product of the second and third arguments. The buffer
** must be aligned to an 8-byte boundary. ^If the second argument to
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
** rounded down to the next smaller multiple of 8. ^(The lookaside memory
** configuration for a database connection can only be changed when that
** connection is not currently using lookaside memory, or in other words
** when the "current value" returned by
** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
** Any attempt to change the lookaside memory configuration when lookaside
** memory is in use leaves the configuration unchanged and returns
** [SQLITE_BUSY].)^</dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
** <dd> ^This option is used to enable or disable the enforcement of
** [foreign key constraints]. There should be two additional arguments.
** The first argument is an integer which is 0 to disable FK enforcement,
** positive to enable FK enforcement or negative to leave FK enforcement
** unchanged. The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether FK enforcement is off or on
** following this call. The second parameter may be a NULL pointer, in
** which case the FK enforcement setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
** There should be two additional arguments.
** The first argument is an integer which is 0 to disable triggers,
** positive to enable triggers or negative to leave the setting unchanged.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether triggers are disabled or enabled
** following this call. The second parameter may be a NULL pointer, in
** which case the trigger setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
** <dd> ^This option is used to enable or disable the two-argument
** version of the [fts3_tokenizer()] function which is part of the
** [FTS3] full-text search engine extension.
** There should be two additional arguments.
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
** positive to enable fts3_tokenizer() or negative to leave the setting
** unchanged.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
** following this call. The second parameter may be a NULL pointer, in
** which case the new setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
** interface independently of the [load_extension()] SQL function.
** The [sqlite3_enable_load_extension()] API enables or disables both the
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
** There should be two additional arguments.
** When the first argument to this interface is 1, then only the C-API is
** enabled and the SQL function remains disabled. If the first argument to
** this interface is 0, then both the C-API and the SQL function are disabled.
** If the first argument is -1, then no changes are made to state of either the
** C-API or the SQL function.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
** is disabled or enabled following this call. The second parameter may
** be a NULL pointer, in which case the new setting is not reported back.
** </dd>
**
** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
** <dd> ^This option is used to change the name of the "main" database
** schema. ^The sole argument is a pointer to a constant UTF8 string
** which will become the new schema name in place of "main". ^SQLite
** does not make a copy of the new main schema name string, so the application
** must ensure that the argument passed into this DBCONFIG option is unchanged
** until after the database connection closes.
** </dd>
**
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
** <dd> Usually, when a database in wal mode is closed or detached from a
** database handle, SQLite checks if this will mean that there are now no
** connections at all to the database. If so, it performs a checkpoint
** operation before closing the connection. This option may be used to
** override this behaviour. The first parameter passed to this operation
** is an integer - non-zero to disable checkpoints-on-close, or zero (the
** default) to enable them. The second parameter is a pointer to an integer
** into which is written 0 or 1 to indicate whether checkpoints-on-close
** have been disabled - 0 if they are not disabled, 1 if they are.
** </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
** a single SQL query statement will always use the same algorithm regardless
** of values of [bound parameters].)^ The QPSG disables some query optimizations
** that look at the values of bound parameters, which can make some queries
** slower. But the QPSG has the advantage of more predictable behavior. With
** the QPSG active, SQLite will always use the same query plan in the field as
** was used during testing in the lab.
** </dd>
**
** </dl>
************* End of btmutex.c ********************************************
** This function is used to change the actual size of the database
** file in the file-system. This only happens when committing a transaction,
** or rolling back a transaction (including rolling back a hot-journal).
**
** If the main database file is not open, or the pager is not in either
** DBMOD or OPEN state, this function is a no-op. Otherwise, the size
** of the file is changed to nPage pages (nPage*pPager->pageSize bytes).
** If the file on disk is currently larger than nPage pages, then use the VFS
** xTruncate() method to truncate it.
**
** Or, it might be the case that the file on disk is smaller than
** nPage pages. Some operating system implementations can get confused if
** you try to truncate a file to some size that is larger than it
** currently is, so detect this case and write a single zero byte to
** the end of the new file instead.
**
** If successful, return SQLITE_OK. If an IO error occurs while modifying
** the database file, return the error code to the caller.
Mask of new.* columns referenced
NodeWriter for root node
The DISTINCT marking is pointless. Ignore it.
CREATE VIEW name(arglist) AS ...
** The names of the columns in the table are taken from
** arglist which is stored in pTable->pCheck. The pCheck field
** normally holds CHECK constraints on an ordinary table, but for
** a VIEW it holds the list of column names.
Cache of overflow page locations
OUT: Size of buffer at *ppChangeset
** CAPI3REF: Create A New Changegroup Object
**
** An sqlite3_changegroup object is used to combine two or more changesets
** (or patchsets) into a single changeset (or patchset). A single changegroup
** object may combine changesets or patchsets, but not both. The output is
** always in the same format as the input.
**
** If successful, this function returns SQLITE_OK and populates (*pp) with
** a pointer to a new sqlite3_changegroup object before returning. The caller
** should eventually free the returned object using a call to
** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
**
** The usual usage pattern for an sqlite3_changegroup object is as follows:
**
** <ul>
** <li> It is created using a call to sqlite3changegroup_new().
**
** <li> Zero or more changesets (or patchsets) are added to the object
** by calling sqlite3changegroup_add().
**
** <li> The result of combining all input changesets together is obtained
** by the application via a call to sqlite3changegroup_output().
**
** <li> The object is deleted using a call to sqlite3changegroup_delete().
** </ul>
**
** Any number of calls to add() and output() may be made between the calls to
** new() and delete(), and in any order.
**
** As well as the regular sqlite3changegroup_add() and
** sqlite3changegroup_output() functions, also available are the streaming
** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
A WHERE clause term
** Candidate values for Wal.exclusiveMode.
OUT: Array of booleans - true for PK col
Loop through all of the arguments passed by the user to the FTS3/4
** module (i.e. all the column names and special arguments). This loop
** does the following:
**
** + Figures out the number of columns the FTSX table will have, and
** the number of bytes of space that must be allocated to store copies
** of the column names.
**
** + If there is a tokenizer specification included in the arguments,
** initializes the tokenizer pTokenizer.
EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
** callback are either NULL pointers or zero-terminated strings that
** contain additional details about the action to be authorized.
**
** The following testcase() macros show that any of the 3rd through 6th
** parameters can be either NULL or a string.
Last synced page in dirty page list
Test the query function
** These file mapping APIs are common to both Win32 and WinRT.
Total number of tokens in row
The value return
The VFS for which this is the xOpen method
Original KeyInfo on the sorter table
EACH
comment:
** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
** as VDBE code so that unused argument values do not have to be computed.
** However, we still need some kind of function implementation for this
** routines in the function table. The noopFunc macro provides this.
** noopFunc will never be called so it doesn't matter what the implementation
** is. We might as well use the "version()" function as a substitute.
label: code-design
Number of u32 values in hash table.
comment:
** If required, grow the hash table used to store changes on table pTab
** (part of the session pSession). If a fatal OOM error occurs, set the
** session object to failed and return SQLITE_ERROR. Otherwise, return
** SQLITE_OK.
**
** It is possible that a non-fatal OOM error occurs in this function. In
** that case the hash-table does not grow, but SQLITE_OK is returned anyway.
** Growing the hash table in this case is a performance optimization only,
** it is not required for correct operation.
label: code-design
** Register the built-in LIKE and GLOB functions. The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive. GLOB is always case sensitive.
s: p0<<14 | p2 (masked)
Make sure the mutex subsystem is initialized. If unable to
** initialize the mutex subsystem, return early with the error.
** If the system is so sick that we are unable to allocate a mutex,
** there is not much SQLite is going to be able to do.
**
** The mutex subsystem must take care of serializing its own
** initialization.
** eType:
** Expression node type. Always one of:
**
** FTS5_AND (nChild, apChild valid)
** FTS5_OR (nChild, apChild valid)
** FTS5_NOT (nChild, apChild valid)
** FTS5_STRING (pNear valid)
** FTS5_TERM (pNear valid)
** Initialize the contents of the unixFile structure pointed to by pId.
Make a copy of the second argument (a blob) in aBlob[]. The aBlob[]
** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
** buffer overreads even if the record is corrupt.
comment:
** If we are to be thread-safe, include the pthreads header and define
** the SQLITE_UNIX_THREADS macro.
label: requirement
The span to be added
EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
** number of bytes in fragments may not exceed 60.
Column to search
Number of frames in pFrame list
Statement under construction
synopsis: accum=r[P3] step(r[P2@P5])
Column to read value from
Space for new cursor
sqlite3_reset() return code
comment:
** The first argument is a file-handle open on a temporary file. The file
** is guaranteed to be nByte bytes or smaller in size. This function
** attempts to extend the file to nByte bytes in size and to ensure that
** the VFS has memory mapped it.
**
** Whether or not the file does end up memory mapped of course depends on
** the specific VFS implementation.
label: code-design
Opcode: Function0 P1 P2 P3 P4 P5
** Synopsis: r[P3]=func(r[P2@P5])
**
** Invoke a user function (P4 is a pointer to a FuncDef object that
** defines the function) with P5 arguments taken from register P2 and
** successors. The result of the function is stored in register P3.
** Register P3 must not be one of the function inputs.
**
** P1 is a 32-bit bitmask indicating whether or not each argument to the
** function was determined to be constant at compile time. If the first
** argument was constant then bit 0 of P1 is set. This is used to determine
** whether meta data associated with a user function argument using the
** sqlite3_set_auxdata() API may be safely retained until the next
** invocation of this opcode.
**
** See also: Function, AggStep, AggFinal
Update the anEq[] fields of any samples already collected.
Content of the NEW.* table in triggers
Top of the input loop
Segid to write to
If non-zero free this temporary register
** This function is used by changeset_concat() to merge two UPDATE changes
** on the same row.
INDEX
in1, in2
Allocate the new entry in the db->aDb[] array and initialize the schema
** hash tables.
not a system error
comment: Even if an IO or diskfull error occurs while journalling the
** page in the block above, set the need-sync flag for the page.
** Otherwise, when the transaction is rolled back, the logic in
** playback_one_page() will think that the page needs to be restored
** in the database file. And if an IO error occurs while doing so,
** then corruption may follow.
label: code-design
Buffer in which to accumlate changeset
True if the terms are equal
** The table object reference passed as the second argument to this function
** must represent a virtual table. This function invokes the xBestIndex()
** method of the virtual table with the sqlite3_index_info object that
** comes in as the 3rd argument to this function.
**
** If an error occurs, pParse is populated with an error message and a
** non-zero value is returned. Otherwise, 0 is returned and the output
** part of the sqlite3_index_info structure is left populated.
**
** Whether or not an error is returned, it is the responsibility of the
** caller to eventually free p->idxStr if p->needToFreeIdxStr indicates
** that this is required.
Pointer to rbu object (rbu target only)
** Helper function used by the implementation of the overloaded snippet(),
** offsets() and optimize() SQL functions.
**
** If the value passed as the third argument is a blob of size
** sizeof(Fts3Cursor*), then the blob contents are copied to the
** output variable *ppCsr and SQLITE_OK is returned. Otherwise, an error
** message is written to context pContext and SQLITE_ERROR returned. The
** string passed via zFunc is used as part of the error message.
Access authorization function
Find a dirty page to write-out and recycle. First try to find a
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
** cleared), but if that is not possible settle for any other
** unreferenced dirty page.
**
** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
** flag is currently referenced, then the following may leave pSynced
** set incorrectly (pointing to other than the LRU page with NEED_SYNC
** cleared). This is Ok, as pSynced is just an optimization.
BY => ID
** This is an fts3ExprIterate() callback used while loading the doclists
** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
** fts3ExprLoadDoclists().
Collating sequence name
Dummy variables
Step 1C.
Byte available in aRow
IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
** TRUNCATE modes also obtain the exclusive "writer" lock on the database
** file.
**
** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
** immediately, and a busy-handler is configured, it is invoked and the
** writer lock retried until either the busy-handler returns 0 or the
** lock is successfully obtained.
** Delete the file located at zPath.
The underlying file iNode
Current offset in pgidx
pIdx is usable
In the IEEE 754 standard, zero is signed.
The following testcase is true for indices with redundant columns.
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0;
SQLITE_OMIT_TRACE
List of statements inside the trigger body
Rowid from %_data table
Destructor for pUserData
** This function returns a pointer to a blob of memory associated with
** a single shared-btree. The memory is used by client code for its own
** purposes (for example, to store a high-level schema associated with
** the shared-btree). The btree layer manages reference counting issues.
**
** The first time this is called on a shared-btree, nBytes bytes of memory
** are allocated, zeroed, and returned to the caller. For each subsequent
** call the nBytes parameter is ignored and a pointer to the same blob
** of memory returned.
**
** If the nBytes parameter is 0 and the blob of memory has not yet been
** allocated, a null pointer is returned. If the blob has already been
** allocated, it is returned as normal.
**
** Just before the shared-btree is closed, the function passed as the
** xFree argument when the memory allocation was made is invoked on the
** blob of allocated memory. The xFree function should not call sqlite3_free()
** on the memory, the btree layer does that.
Make sure the results of the current row are \000 terminated
** and have an assigned type. The results are de-ephemeralized as
** a side effect.
If we have any lock, then the lock file already exists. All we have
** to do is adjust our internal record of the lock level.
colset
** This routine is called the when a VDBE tries to halt. If the VDBE
** has made changes and is in autocommit mode, then commit those
** changes. If a rollback is needed, then do the rollback.
**
** This routine is the only way to move the state of a VM from
** SQLITE_MAGIC_RUN to SQLITE_MAGIC_HALT. It is harmless to
** call this on a VM that is in the SQLITE_MAGIC_HALT state.
**
** Return an error code. If the commit could not complete because of
** lock contention, return SQLITE_BUSY. If SQLITE_BUSY is returned, it
** means the close did not happen and needs to be repeated.
True for ORDER BY ASC
Rare case of a really large header
240
Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
** from the ReusableSpace object. Return a pointer to the allocated
** memory on success. If insufficient memory is available in the
** ReusableSpace object, increase the ReusableSpace.nNeeded
** value by the amount needed and return NULL.
**
** If pBuf is not initially NULL, that means that the memory has already
** been allocated by a prior call to this routine, so just return a copy
** of pBuf and leave ReusableSpace unchanged.
**
** This allocator is employed to repurpose unused slots at the end of the
** opcode array of prepared state for other memory needs of the prepared
** statement.
If this index contains every column of its table, then mark
** it as a covering index
** Used to pass information from the analyzer reader through to the
** callback routine.
Register to copy to
** Return true if the correct mutexes are held for accessing the
** db->aDb[iDb].pSchema structure. The mutexes required for schema
** access are:
**
** (1) The mutex on db
** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt.
**
** If pSchema is not NULL, then iDb is computed from pSchema and
** db using sqlite3SchemaToIndex().
Remove result from a UNION index
** If we are on an architecture with mixed-endian floating
** points (ex: ARM7) then swap the lower 4 bytes with the
** upper 4 bytes. Return the result.
**
** For most architectures, this is a no-op.
**
** (later): It is reported to me that the mixed-endian problem
** on ARM7 is an issue with GCC, not with the ARM7 chip. It seems
** that early versions of GCC stored the two words of a 64-bit
** float in the wrong order. And that error has been propagated
** ever since. The blame is not necessarily with GCC, though.
** GCC might have just copying the problem from a prior compiler.
** I am also told that newer versions of GCC that follow a different
** ABI get the byte order right.
**
** Developers using SQLite on an ARM7 should compile and run their
** application using -DSQLITE_DEBUG=1 at least once. With DEBUG
** enabled, some asserts below will ensure that the byte order of
** floating point values is correct.
**
** (2007-08-30) Frank van Vugt has studied this problem closely
** and has send his findings to the SQLite developers. Frank
** writes that some Linux kernels offer floating point hardware
** emulation that uses only 32-bit mantissas instead of a full
** 48-bits as required by the IEEE standard. (This is the
** CONFIG_FPE_FASTFPE option.) On such systems, floating point
** byte swapping becomes very complicated. To avoid problems,
** the necessary byte swapping is carried out using a 64-bit integer
** rather than a 64-bit float. Frank assures us that the code here
** works for him. We, the developers, have no way to independently
** verify this, but Frank seems to know what he is talking about
** so we trust him.
If an OOM occurs, set to SQLITE_NOMEM
Reserved: 0x00F00000
Never set both isSaveLeft and isExact for the same invocation.
The next sections is a series of control #defines.
** various aspects of the generated parser.
** fts5YYCODETYPE is the data type used to store the integer codes
** that represent terminal and non-terminal symbols.
** "unsigned char" is used if there are fewer than
** 256 symbols. Larger types otherwise.
** fts5YYNOCODE is a number of type fts5YYCODETYPE that is not used for
** any terminal or nonterminal symbol.
** fts5YYFALLBACK If defined, this indicates that one or more tokens
** (also known as: "terminal symbols") have fall-back
** values which should be used if the original symbol
** would not parse. This permits keywords to sometimes
** be used as identifiers, for example.
** fts5YYACTIONTYPE is the data type used for "action codes" - numbers
** that indicate what to do in response to the next
** token.
** sqlite3Fts5ParserFTS5TOKENTYPE is the data type used for minor type for terminal
** symbols. Background: A "minor type" is a semantic
** value associated with a terminal or non-terminal
** symbols. For example, for an "ID" terminal symbol,
** the minor type might be the name of the identifier.
** Each non-terminal can have a different minor type.
** Terminal symbols all have the same minor type, though.
** This macros defines the minor type for terminal
** symbols.
** fts5YYMINORTYPE is the data type used for all minor types.
** This is typically a union of many types, one of
** which is sqlite3Fts5ParserFTS5TOKENTYPE. The entry in the union
** for terminal symbols is called "fts5yy0".
** fts5YYSTACKDEPTH is the maximum depth of the parser's stack. If
** zero the stack is dynamically sized using realloc()
** sqlite3Fts5ParserARG_SDECL A static variable declaration for the %extra_argument
** sqlite3Fts5ParserARG_PDECL A parameter declaration for the %extra_argument
** sqlite3Fts5ParserARG_STORE Code to store %extra_argument into fts5yypParser
** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from fts5yypParser
** fts5YYERRORSYMBOL is the code number of the error symbol. If not
** defined, then do no error processing.
** fts5YYNSTATE the combined number of states.
** fts5YYNRULE the number of rules in the grammar
** fts5YY_MAX_SHIFT Maximum value for shift actions
** fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
** fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
** fts5YY_MIN_REDUCE Maximum value for reduce actions
** fts5YY_ERROR_ACTION The fts5yy_action[] code for syntax error
** fts5YY_ACCEPT_ACTION The fts5yy_action[] code for accept
** fts5YY_NO_ACTION The fts5yy_action[] code for no-op
Maximum local payload in a LEAFDATA table
Free-list trunk page
** Attach a table to a session. All subsequent changes made to the table
** while the session object is enabled will be recorded.
**
** Only tables that have a PRIMARY KEY defined may be attached. It does
** not matter if the PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias)
** or not.
Symbolic ID of this loop for debugging use
comment:
** The "winIoerrCanRetry1" macro is used to determine if a particular I/O
** error code obtained via GetLastError() is eligible to be retried. It
** must accept the error code DWORD as its only argument and should return
** non-zero if the error code is transient in nature and the operation
** responsible for generating the original error might succeed upon being
** retried. The argument to this macro should be a variable.
**
** Additionally, a macro named "winIoerrCanRetry2" may be defined. If it
** is defined, it will be consulted only when the macro "winIoerrCanRetry1"
** returns zero. The "winIoerrCanRetry2" macro is completely optional and
** may be used to include additional error codes in the set that should
** result in the failing I/O operation being retried by the caller. If
** defined, the "winIoerrCanRetry2" macro must exhibit external semantics
** identical to those of the "winIoerrCanRetry1" macro.
label: code-design
0x1e
Update the PCache1.pSynced variable if necessary.
Check that the affinity that will be used to perform each
** comparison is the same as the affinity of each column in table
** on the RHS of the IN operator. If it not, it is not possible to
** use any index of the RHS table.
(2c)
Checkpoint sequence counter in the wal-header
********* End reduce actions ***********************************************
Begin reading at this offset
If the sub-query is a compound SELECT statement, then (by restrictions
** 17 and 18 above) it must be a UNION ALL and the parent query must
** be of the form:
**
** SELECT <expr-list> FROM (<sub-query>) <where-clause>
**
** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
** OFFSET clauses and joins them to the left-hand-side of the original
** using UNION ALL operators. In this case N is the number of simple
** select statements in the compound sub-query.
**
** Example:
**
** SELECT a+1 FROM (
** SELECT x FROM tab
** UNION ALL
** SELECT y FROM tab
** UNION ALL
** SELECT abs(z*2) FROM tab2
** ) WHERE a!=5 ORDER BY 1
**
** Transformed into:
**
** SELECT x+1 FROM tab WHERE x+1!=5
** UNION ALL
** SELECT y+1 FROM tab WHERE y+1!=5
** UNION ALL
** SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
** ORDER BY 1
**
** We call this the "compound-subquery flattening".
comment:
** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
** on the cache using a hash function. This is used for testing
** and debugging only.
label: code-design
Look up every table named in the FROM clause of the select. If
** an entry of the FROM clause is a subquery instead of a table or view,
** then create a transient table structure to describe the subquery.
True if must seek pStmt to %_content row
** xSetOutputs callback used by detail=none tables.
** Free the phrase object passed as the only argument.
xDlClose
Omit constant folding optimizations
P4 is a pointer to a CollSeq structure
** Drop a page from the cache. There must be exactly one reference to the
** page. This function deletes that reference, so after it returns the
** page pointed to by p is invalid.
Transform expressions in this WHERE clause
** This function returns a linked list of FKey objects (connected by
** FKey.pNextTo) holding all children of table pTab. For example,
** given the following schema:
**
** CREATE TABLE t1(a PRIMARY KEY);
** CREATE TABLE t2(b REFERENCES t1(a);
**
** Calling this function with table "t1" as an argument returns a pointer
** to the FKey structure representing the foreign key constraint on table
** "t2". Calling this function with "t2" as the argument would return a
** NULL pointer (as there are no FK constraints for which t2 is the parent
** table).
String to tokenize
Test for EOF.
OUT: WHERE clause
xNext
Write the node-id here
The handle to our heap.
Number of entries without a matching leave
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements. This module is responsible for
** generating the code that loops through a table looking for applicable
** rows. Indices are selected and used to speed the search when doing
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
** Close all cursors.
**
** Also release any dynamic memory held by the VM in the Vdbe.aMem memory
** cell array. This is necessary as the memory cell array may contain
** pointers to VdbeFrame objects, which may in turn contain pointers to
** open cursors.
** Initialize all database files - the main database file, the file
** used to store temporary tables, and any additional database files
** created using ATTACH statements. Return a success code. If an
** error occurs, write an error message into *pzErrMsg.
**
** After a database is initialized, the DB_SchemaLoaded bit is set
** bit is set in the flags field of the Db structure. If the database
** file was of zero-length, then the DB_Empty flag is also set.
Rowid for the inserted record
** start of TTTTT
**
** Move the date backwards to the beginning of the current day,
** or month or year.
Reserved for future use
** Construct a trigger step that implements a DELETE statement and return
** a pointer to that trigger step. The parser calls this routine when it
** sees a DELETE statement inside the body of a CREATE TRIGGER.
If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
** DML statements invoke this opcode to return the number of rows
** modified to the user. This is the only way that a VM that
** opens a statement transaction may invoke this opcode.
**
** In case this is such a statement, close any statement transaction
** opened by this VM before returning control to the user. This is to
** ensure that statement-transactions are always nested, not overlapping.
** If the open statement-transaction is not closed here, then the user
** may step another VM that opens its own statement transaction. This
** may lead to overlapping statement transactions.
**
** The statement transaction is never a top-level transaction. Hence
** the RELEASE call below can never fail.
For json_each() path and root are the same so fall through
** into the root case
Check that the results returned for ASC and DESC queries are
** the same. If not, call this corruption.
Column-list terminator
Allocated size of aIdx[]
trigger_time ::= BEFORE|AFTER
Address of test for empty pSrc
The call to execSql() to attach the temp database has left the file
** locked (as there was more than one active statement when the transaction
** to read the schema was concluded. Unlock it here so that this doesn't
** cause problems for the call to BtreeSetPageSize() below.
expr ::= expr IS NOT expr
Number of constraint terms
List of all chunk allocations
natural
Value of 'payload' column
Size of a cell
Used by: module_list pragma_list
These macros are provided to "stringify" the value of the define
** for those options in which the value is meaningful.
Update the aggregate accumulators based on the content of
** the current row
Advance the current PmaReader
Space allocated for leaf blocks
expr ::= expr between_op expr AND expr
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "unix" VFSes. Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
** system call named zName.
** Search for an auxiliary function named zName that can be used with table
** pTab. If one is found, return a pointer to the corresponding Fts5Auxiliary
** structure. Otherwise, if no such function exists, return NULL.
** Helper function for printing out trace information from debugging
** binaries. This returns the string representation of the supplied
** integer lock-type.
Btree database to read cookie from
Serial type of the rowid
0x000004 // available for use
** Rtree virtual table module xRowid method.
Byte-length of string zStop
Version 3.9.0 and later
The underlying winShmNode object
Pointer to previous term buffer
** Deinitialize the memory allocation subsystem.
If the value is being opened for writing, check that the
** column is not indexed, and that it is not part of a foreign key.
Mem address holding flag indicating that at least
** one row of the input to the aggregator has been
** processed
** Initialize the iterator structure passed as the second argument.
**
** If no error occurs, SQLITE_OK is returned and the iterator is left
** pointing to the first entry. Otherwise, an error code and message is
** left in the RBU handle passed as the first argument. A copy of the
** error code is returned.
Parsing and code generating context
** Each session object maintains a set of the following structures, one
** for each table the session object is monitoring. The structures are
** stored in a linked list starting at sqlite3_session.pTable.
**
** The keys of the SessionTable.aChange[] hash table are all rows that have
** been modified in any way since the session object was attached to the
** table.
**
** The data associated with each hash-table entry is a structure containing
** a subset of the initial values that the modified row contained at the
** start of the session. Or no initial values if the row was inserted.
>=2
** Name of the connection operator, used for error messages.
Low-level page-cache interface
All ram filesystem writes are atomic
The GROUP BY clause
************* Begin file hwtime.h *****************************************
Array of objects. Might be reallocated
Opcode: AggStep * P2 P3 P4 P5
** Synopsis: accum=r[P3] step(r[P2@P5])
**
** Execute the step function for an aggregate. The
** function has P5 arguments. P4 is a pointer to an sqlite3_context
** object that is used to run the function. Register P3 is
** as the accumulator.
**
** The P5 arguments are taken from register P2 and its
** successors.
**
** This opcode is initially coded as OP_AggStep0. On first evaluation,
** the FuncDef stored in P4 is converted into an sqlite3_context and
** the opcode is changed. In this way, the initialization of the
** sqlite3_context only happens once, instead of on each call to the
** step function.
87
Number of purgeable pages allocated
Never spill cache. Set via pragma
SELECT rowid, * FROM ... ORDER BY 1 ASC
Number of bytes of data to be bound
Last position from pp2
Make *pzErr point to any syntax error in zPath
Used to iterate through FKs
fts3 query parse context
Initialize and fill this JsonParse object
Original value of pNew->nLTerm
Initialize the JsonString object
Cursor pointing to a table row
Assert that the upper layer has set one of the "file-type" flags.
Mutex to serialize access
Always update the timestamp on the old file
B
Cursor for this UNIQUE index
** This function is only ever called on iterators created by calls to
** Fts5IndexQuery() with the FTS5INDEX_QUERY_DESC flag set.
**
** The iterator is in an unusual state when this function is called: the
** Fts5SegIter.iLeafOffset variable is set to the offset of the start of
** the position-list size field for the first relevant rowid on the page.
** Fts5SegIter.rowid is set, but nPos and bDel are not.
**
** This function advances the iterator so that it points to the last
** relevant rowid on the page and, if necessary, initializes the
** aRowidOffset[] and iRowidOffset variables. At this point the iterator
** is in its regular state - Fts5SegIter.iLeafOffset points to the first
** byte of the position list content associated with said rowid.
old.* record for first change
Convert the lower bound to upper-case and the upper bound to
** lower-case (upper-case is less than lower-case in ASCII) so that
** the range constraints also work for BLOBs
IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
** largest possible integer (9223372036854775807) then the database
** engine starts picking positive candidate ROWIDs at random until
** it finds one that is not previously used.
PRAGMA index_list = (pIter->zTbl)
Allocate space for both the pJournal and pMaster file descriptors.
** If successful, open the master journal file for reading.
** Argument pList points to a position list nList bytes in size. This
** function checks to see if the position list contains any entries for
** a token in position 0 (of any column). If so, it writes argument iDelta
** to the output buffer pOut, followed by a position list consisting only
** of the entries from pList at position 0, and terminated by an 0x00 byte.
** The value returned is the number of bytes written to pOut (if any).
If foreign-key support is enabled, iterate through all FKs that
** refer to table pTab. If there is an action associated with the FK
** for this operation (either update or delete), invoke the associated
** trigger sub-program.
comment: The right-most of SELECTs to be coded
label: code-design
comment: If this playback is happening automatically as a result of an IO or
** malloc error that occurred after the change-counter was updated but
** before the transaction was committed, then the change-counter
** modification may just have been reverted. If this happens in exclusive
** mode, then subsequent transactions performed by the connection will not
** update the change-counter at all. This may lead to cache inconsistency
** problems for other processes at some point in the future. So, just
** in case this has happened, clear the changeCountDone flag now.
label: code-design
Cursor to iterate through aLeft
If we are rereading the sqlite_master table create the in-memory
** record of the table. The xConnect() method is not called until
** the first time the virtual table is used in an SQL statement. This
** allows a schema that contains virtual tables to be loaded before
** the required virtual table implementations are registered.
Digits prior to the decimal point
For leaf pages, the coverage check will occur in the same loop
** as the other cell checks, so initialize the heap.
The real indices of the table are only considered if the
** NOT INDEXED qualifier is omitted from the FROM clause
Load the value for the inequality constraint at the end of the
** range (if any).
** Provide the ability to override linkage features of the interface.
Create the whole "CREATE TABLE" statement to pass to SQLite
The CREATE token that begins the statement
Unrecognized argument
** Return the value of the iSize parameter specified when Bitvec *p
** was created.
True if rev is known
** 2014 August 11
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
Set the first entry (number of rows in the index) to the estimated
** number of rows in the table, or half the number of rows in the table
** for a partial index. But do not let the estimate drop below 10.
1: file 2: memory 0: default
** This function may only be called with a changeset iterator that has been
** passed to an SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT
** conflict-handler function. Otherwise, SQLITE_MISUSE is returned.
**
** If successful, *ppValue is set to point to an sqlite3_value structure
** containing the iVal'th value of the conflicting record.
**
** If value iVal is out-of-range or some other error occurs, an SQLite error
** code is returned. Otherwise, SQLITE_OK.
Generate code into this VM
292
eCreate defines what to do if the page does not exist.
** 0 Do not allocate a new page. (createFlag==0)
** 1 Allocate a new page if doing so is inexpensive.
** (createFlag==1 AND bPurgeable AND pDirty)
** 2 Allocate a new page even it doing so is difficult.
** (createFlag==1 AND !(bPurgeable AND pDirty)
** CAPI3REF: Determine if a database is read-only
** METHOD: sqlite3
**
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
** the name of a database on connection D.
The opcodes to be added
Table being altered
The nTo best paths at the current level
Size of journal file on disk
Value for real types
** If possible, return a pointer to a mapping of file fd starting at offset
** iOff. The mapping must be valid for at least nAmt bytes.
**
** If such a pointer can be obtained, store it in *pp and return SQLITE_OK.
** Or, if one cannot but no error occurs, set *pp to 0 and return SQLITE_OK.
** Finally, if an error does occur, return an SQLite error code. The final
** value of *pp is undefined in this case.
**
** If this function does return a pointer, the caller must eventually
** release the reference by calling unixUnfetch().
Existing change
** The datatype used to store estimates of the number of rows in a
** table or index. This is an unsigned integer type. For 99.9% of
** the world, a 32-bit integer is sufficient. But a 64-bit integer
** can be used at compile-time if desired.
** Set result column names for a pragma.
True if next term will be first in leaf
on_opt ::= ON expr
Number of bytes in aPoslist
comment: TUNING: Estimated cost of a full external sort, where N is
** the number of rows to sort is:
**
** cost = (3.0 * N * log(N)).
**
** Or, if the order-by clause has X terms but only the last Y
** terms are out of order, then block-sorting will reduce the
** sorting cost to:
**
** cost = (3.0 * N * log(N)) * (Y/X)
**
** The (Y/X) term is implemented using stack variable rScale
** below.
label: code-design
** Return SQLITE_ERROR if the maximum depth of the expression tree passed
** as the only argument is more than nMaxDepth.
Serial type
Make sure mem5.aiFreelist[iLogsize] contains at least one free
** block. If not, then split a block of the next larger power of
** two in order to create a new free block of size iLogsize.
** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
**
** One is tempted to try to add a and b to combine the limits. But this
** does not work if either limit is negative.
END
synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
True for DESCENDING sort order
Temporary registers
Size of pData. 0 if none.
83
** Allowed values for the eMode parameter to vdbeMergeEngineInit()
** and vdbePmaReaderIncrMergeInit().
**
** Only INCRINIT_NORMAL is valid in single-threaded builds (when
** SQLITE_MAX_WORKER_THREADS==0). The other values are only used
** when there exists one or more separate worker threads.
** Register a 2nd-generation geometry callback named zScore that can be
** used as part of an R-Tree geometry query as follows:
**
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
** 2006 Oct 10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This is an SQLite module implementing full-text search.
** Create and populate a new TriggerPrg object with a sub-program
** implementing trigger pTrigger with ON CONFLICT policy orconf.
Bind values to the UPDATE statement.
** This routine does the work of opening a database on behalf of
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
** is UTF-8 encoded.
comment:
** Obtain an indication as to the current stage of an RBU update or vacuum.
** This function always returns one of the SQLITE_RBU_STATE_XXX constants
** defined in this file. Return values should be interpreted as follows:
**
** SQLITE_RBU_STATE_OAL:
** RBU is currently building a *-oal file. The next call to sqlite3rbu_step()
** may either add further data to the *-oal file, or compute data that will
** be added by a subsequent call.
**
** SQLITE_RBU_STATE_MOVE:
** RBU has finished building the *-oal file. The next call to sqlite3rbu_step()
** will move the *-oal file to the equivalent *-wal path. If the current
** operation is an RBU update, then the updated version of the database
** file will become visible to ordinary SQLite clients following the next
** call to sqlite3rbu_step().
**
** SQLITE_RBU_STATE_CHECKPOINT:
** RBU is currently performing an incremental checkpoint. The next call to
** sqlite3rbu_step() will copy a page of data from the *-wal file into
** the target database file.
**
** SQLITE_RBU_STATE_DONE:
** The RBU operation has finished. Any subsequent calls to sqlite3rbu_step()
** will immediately return SQLITE_DONE.
**
** SQLITE_RBU_STATE_ERROR:
** An error has occurred. Any subsequent calls to sqlite3rbu_step() will
** immediately return the SQLite error code associated with the error.
label: code-design
** Make sure that the compiler intrinsics we desire are enabled when
** compiling with an appropriate version of MSVC unless prevented by
** the SQLITE_DISABLE_INTRINSIC define.
True if REPLACE conflict resolution might happen
Release the reference to the root node.
** The first two arguments are a pointer to and the size of a segment b-tree
** node. The node may be a leaf or an internal node.
**
** This function creates a new node image in blob object *pNew by copying
** all terms that are greater than or equal to zTerm/nTerm (for leaf nodes)
** or greater than zTerm/nTerm (for internal nodes) from aNode/nNode.
Try to find the next page in the overflow list using the
** autovacuum pointer-map pages. Guess that the next page in
** the overflow list is page number (ovfl+1). If that guess turns
** out to be wrong, fall back to loading the data of page
** number ovfl to determine the next page number.
Clear the TEMP schema separately and last
** Bits of the sqlite3.dbOptFlags field that are used by the
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
** selectively disable various optimizations.
490
The new sorter
Set the foreign key value to NULL
New column to add to colset object
Current state, using numbers defined in header comment
True if a '-' sign preceded <value>
** Release all dynamic resources held by node-reader object *p.
** This function is called whenever an IOERR or FULL error that requires
** the pager to transition into the ERROR state may ahve occurred.
** The first argument is a pointer to the pager structure, the second
** the error-code about to be returned by a pager API function. The
** value returned is a copy of the second argument to this function.
**
** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the
** IOERR sub-codes, the pager enters the ERROR state and the error code
** is stored in Pager.errCode. While the pager remains in the ERROR state,
** all major API calls on the Pager will immediately return Pager.errCode.
**
** The ERROR state indicates that the contents of the pager-cache
** cannot be trusted. This state can be cleared by completely discarding
** the contents of the pager-cache. If a transaction was active when
** the persistent error occurred, then the rollback journal may need
** to be replayed to restore the contents of the database file (as if
** it were a hot-journal).
************* Include parse.h in the middle of sqliteInt.h ****************
comment:
** This function is called by the pcache layer when it has reached some
** soft memory limit. The first argument is a pointer to a Pager object
** (cast as a void*). The pager is always 'purgeable' (not an in-memory
** database). The second argument is a reference to a page that is
** currently dirty but has no outstanding references. The page
** is always associated with the Pager object passed as the first
** argument.
**
** The job of this function is to make pPg clean by writing its contents
** out to the database file, if possible. This may involve syncing the
** journal file.
**
** If successful, sqlite3PcacheMakeClean() is called on the page and
** SQLITE_OK returned. If an IO error occurs while trying to make the
** page clean, the IO error code is returned. If the page cannot be
** made clean for some other reason, but no error occurs, then SQLITE_OK
** is returned by sqlite3PcacheMakeClean() is not called.
label: code-design
202
Generate code for all sub-queries in the FROM clause
The text expression being built
Tokenizer cursor
** Recompute all indices of all tables in all databases where the
** indices use the collating sequence pColl. If pColl==0 then recompute
** all indices everywhere.
The table with the non-unique rowid
The parent or outer SELECT statement
** Advance PmaReader pReadr to the next key in its PMA. Return SQLITE_OK if
** no error occurs, or an SQLite error code if one does.
First WhereLoop to compare
** Convert bulk memory into a valid WhereLoop that can be passed
** to whereLoopClear harmlessly.
Fall through into OP_Halt
** CAPI3REF: Name Of A Host Parameter
** METHOD: sqlite3_stmt
**
** ^The sqlite3_bind_parameter_name(P,N) interface returns
** the name of the N-th [SQL parameter] in the [prepared statement] P.
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
** respectively.
** In other words, the initial ":" or "$" or "@" or "?"
** is included as part of the name.)^
** ^Parameters of the form "?" without a following integer have no name
** and are referred to as "nameless" or "anonymous parameters".
**
** ^The first host parameter has an index of 1, not 0.
**
** ^If the value N is out of range or if the N-th parameter is
** nameless, then NULL is returned. ^The returned string is
** always in UTF-8 encoding even if the named parameter was
** originally specified as UTF-16 in [sqlite3_prepare16()],
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_count()], and
** [sqlite3_bind_parameter_index()].
Column to return position list for
WHERE_* flags describing the plan
Size of WAL
** Decrement the reference count on a page. If the page is clean and the
** reference count drops to 0, then it is made eligible for recycling.
fdatasync() on HFS+ doesn't yet flush the file size if it changed correctly
** so currently we default to the macro that redefines fdatasync to fsync
Do nothing if the pager does not have an open write transaction
** or at least a RESERVED lock. This function may be called when there
** is no write-transaction active but a RESERVED or greater lock is
** held under two circumstances:
**
** 1. After a successful hot-journal rollback, it is called with
** eState==PAGER_NONE and eLock==EXCLUSIVE_LOCK.
**
** 2. If a connection with locking_mode=exclusive holding an EXCLUSIVE
** lock switches back to locking_mode=normal and then executes a
** read-transaction, this function is called with eState==PAGER_READER
** and eLock==EXCLUSIVE_LOCK when the read-transaction is closed.
The node containing the cell to be read
** Check to see if index pSrc is compatible as a source of data
** for index pDest in an insert transfer optimization. The rules
** for a compatible index:
**
** * The index is over the same set of columns
** * The same DESC and ASC markings occurs on all columns
** * The same onError processing (OE_Abort, OE_Ignore, etc)
** * The same collating sequence on each column
** * The index has the exact same WHERE clause
'*'
pPage and up to two siblings
Maximum instantaneous currentCount
************* Begin file vdbeaux.c ****************************************
selcollist ::= sclp STAR
Search the list for a matching table
A SELECT statement that will become the new view
xCurrentTimeInt64
The SET clause: list of column and new values
Resolve function names
** PRAGMA temp_store
** PRAGMA temp_store = "default"|"memory"|"file"
**
** Return or set the local value of the temp_store flag. Changing
** the local value does not make changes to the disk file and the default
** value will be restored the next time the database is opened.
**
** Note that it is possible for the library compile-time options to
** override this setting
Valid entries in aIdx[]
Number of errors encountered while resolving names
sortorder ::= ASC
Current token offset in zIn[]
This block codes the top of loop only. The complete loop is the
** following pseudocode (template 4):
**
** rewind temp table, if empty goto D
** C: loop over rows of intermediate table
** transfer values form intermediate table into <table>
** end loop
** D: ...
If the cursor already points to the last entry, this is a no-op.
** One or more phrases that must appear within a certain token distance of
** each other within each matching document.
Verify that all NOT NULL columns really are NOT NULL
ID of current select for EXPLAIN output
synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
Index of docid<=x constraint, if present
This error is now caught by the caller.
** Search for "xBestIndex malfunction" below
** Rounding constants for float->double conversion.
where_opt ::=
115
Numeric type of left operand
the hash of the key modulo hash table size
Opcode: Or P1 P2 P3 * *
** Synopsis: r[P3]=(r[P1] || r[P2])
**
** Take the logical OR of the values in register P1 and P2 and
** store the answer in register P3.
**
** If either P1 or P2 is nonzero (true) then the result is 1 (true)
** even if the other input is NULL. A NULL and false or two NULLs
** give a NULL output.
Call balance_quick() to create a new sibling of pPage on which
** to store the overflow cell. balance_quick() inserts a new cell
** into pParent, which may cause pParent overflow. If this
** happens, the next iteration of the do-loop will balance pParent
** use either balance_nonroot() or balance_deeper(). Until this
** happens, the overflow cell is stored in the aBalanceQuickSpace[]
** buffer.
**
** The purpose of the following assert() is to check that only a
** single call to balance_quick() is made for each call to this
** function. If this were not verified, a subtle bug involving reuse
** of the aBalanceQuickSpace[] might sneak in.
Write JSON here
************************************************************************
** Start of MatchinfoBuffer code.
COLLATE function from an ORDER BY clause term
OUT: Docid value
** Print into memory obtained from sqlite3_malloc()(). Omit the internal
** %-conversion extensions.
Open mode flags
OUT: Old value (or NULL pointer)
** This function sets the data directory or the temporary directory based on
** the provided arguments. The type argument must be 1 in order to set the
** data directory or 2 in order to set the temporary directory. The zValue
** argument is the name of the directory to use. The return value will be
** SQLITE_OK if successful.
A frame is only valid if a checksum of the WAL header,
** all prior frams, the first 16 bytes of this frame-header,
** and the frame-data matches the checksum in the last 8
** bytes of this frame-header.
fts3_unicode2.c (functions generated by parsing unicode text files)
** Determine whether or not a cursor has moved from the position where
** it was last placed, or has been invalidated for any other reason.
** Cursors can move when the row they are pointing at is deleted out
** from under them, for example. Cursor might also move if a btree
** is rebalanced.
**
** Calling this routine with a NULL cursor pointer returns false.
**
** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
** back to where it ought to be if this routine returns true.
The vm under construction
Write content into this buffer
Required table locks for shared-cache mode
Iterate through all dirty pages currently stored in the cache. This
** interface is only available if SQLITE_CHECK_PAGES is defined when the
** library is built.
Source database page data
** Test to see whether or not a table is a virtual table. This is
** done as a macro so that it will be optimized out when virtual
** table support is omitted from the build.
Pointer to the appropriate info structure
Condition 5
Size of buffer pBuf in bytes
Pointer to buffer containing root node
Size of aFold[] in bytes
************* End of util.c ***********************************************
Statement for DELETE ops
comment:
** Generate a human-readable explanation of an expression tree.
label: code-design
same as TK_STAR, in1, in2, out3
Find the Fts3SegReader object with Fts3SegReader.iIdx==i. It is hiding
** somewhere in the pCsr->apSegment[] array.
Fold to lower case
position-list size field value
** Remember the SQL string for a prepared statement.
Argument to xCommitCallback()
If the table is not located in the temp-db (in which case NULL is
** returned, loop through the tables list of triggers. For each trigger
** that is not part of the temp-db schema, add a clause to the WHERE
** expression being built up in zWhere.
Deinitialize the memory allocator
** Finish off a string by making sure it is zero-terminated.
** Return a pointer to the resulting string. Return a NULL
** pointer if any kind of error was encountered.
Fetch the info entry for the field
IMP: R-42420-56072
Opcode: SorterCompare P1 P2 P3 P4
** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
**
** P1 is a sorter cursor. This instruction compares a prefix of the
** record blob in register P3 against a prefix of the entry that
** the sorter cursor currently points to. Only the first P4 fields
** of r[P3] and the sorter record are compared.
**
** If either P3 or the sorter contains a NULL in one of their significant
** fields (not counting the P4 fields at the end which are ignored) then
** the comparison is assumed to be equal.
**
** Fall through to next instruction if the two records compare equal to
** each other. Jump to P2 if they are different.
Build the Trigger object
Amount to increment deferred counter by
Index in pTabList->a[] of table being read
Iterate through levels, segments
************* End of func.c ***********************************************
Cursor to scan for
stl_prefix
IDF for each phrase
************* Begin file fts3Int.h ****************************************
** This function is called to change the WAL subsystem into or out
** of locking_mode=EXCLUSIVE.
**
** If op is zero, then attempt to change from locking_mode=EXCLUSIVE
** into locking_mode=NORMAL. This means that we must acquire a lock
** on the pWal->readLock byte. If the WAL is already in locking_mode=NORMAL
** or if the acquisition of the lock fails, then return 0. If the
** transition out of exclusive-mode is successful, return 1. This
** operation must occur while the pager is still holding the exclusive
** lock on the main database file.
**
** If op is one, then change from locking_mode=NORMAL into
** locking_mode=EXCLUSIVE. This means that the pWal->readLock must
** be released. Return 1 if the transition is made and 0 if the
** WAL is already in exclusive-locking mode - meaning that this
** routine is a no-op. The pager must already hold the exclusive lock
** on the main database file before invoking this operation.
**
** If op is negative, then do a dry-run of the op==1 case but do
** not actually change anything. The pager uses this to see if it
** should acquire the database exclusive lock prior to invoking
** the op==1 case.
Either SQLITE_ATTACH or SQLITE_DETACH
** Count the number of fields (a.k.a. columns) in the record given by
** pKey,nKey. The verify that this count is less than or equal to the
** limit given by pKeyInfo->nField + pKeyInfo->nXField.
**
** If this constraint is not satisfied, it means that the high-speed
** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
** not work correctly. If this assert() ever fires, it probably means
** that the KeyInfo.nField or KeyInfo.nXField values were computed
** incorrectly.
************* Begin file mem5.c *******************************************
Pointer to new Btree object written here
** At this point, there should be no outstanding memory allocations on
** the heap. Also, since both the master and memsys locks are currently
** being held by us, no other function (i.e. from another thread) should
** be able to even access the heap. Attempt to destroy and recreate our
** isolated Win32 native heap now.
Length of the zCanonicalName[] string
Values for parameters to the SQL function
Generate code to handle the case of A==B
Do nothing
Check to see if pWLoop should be added to the set of
** mxChoice best-so-far paths.
**
** First look for an existing path among best-so-far paths
** that covers the same set of loops and has the same isOrdered
** setting as the current path candidate.
**
** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
** of legal values for isOrdered, -1..64.
** Return the database handle used by pRbu.
** This function is responsible for invoking the collation factory callback
** or substituting a collation sequence of a different encoding when the
** requested collation sequence is not available in the desired encoding.
**
** If it is not NULL, then pColl must point to the database native encoding
** collation sequence with name zName, length nName.
**
** The return value is either the collation sequence to be used in database
** db for collation type name zName, length nName, or NULL, if no collation
** sequence can be found. If no collation is found, leave an error message.
**
** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
** This function is called during initialization if a static buffer is
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
** enough to contain 'n' buffers of 'sz' bytes each.
**
** This routine is called from sqlite3_initialize() and so it is guaranteed
** to be serialized already. There is no need for further mutexing.
OUT: Acquired node
The data is distributed over two or more pages. Copy it into the
** Fts5Iter.poslist buffer and then set the output pointer to point
** to this buffer.
Level to select (relative level)
True if argument iFrom is valid
NC_IsCheck or NC_PartIdx or NC_IdxExpr
Object reference count
Do not allow any kind of write-lock on a read-only database
DO NOT EDIT!
** This file is automatically generated by the script at
** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
** that script and rerun it.
************* Include msvc.h in the middle of sqliteInt.h *****************
No duplicates
** A wrapper around sqlite3_bind_value() that detects an extra problem.
** See comments in the body of this function for details.
** Try to increase the size of the parser stack. Return the number
** of errors. Return 0 on success.
WHERE clause of trigger step
Restriction (16)
Payload with which to construct the cell
Space to hold the Lemon-generated Parser object
Pointer to BtShared that this page is part of
True if uppercase==lowercase
Name of the table or view
Index of new output segment
True if current change was indirect
!SQLITE_OMIT_TRACE && SQLITE_ENABLE_IOTRACE
Parameters to CREATE TABLE statement
Maximum allowed page size
SQLITE_OMIT_AUTOINCREMENT
defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
** Expression pRight, which is the RHS of a comparison operation, is
** either a vector of n elements or, if n==1, a scalar expression.
** Before the comparison operation, affinity zAff is to be applied
** to the pRight values. This function modifies characters within the
** affinity string to SQLITE_AFF_BLOB if either:
**
** * the comparison will be performed with no affinity, or
** * the affinity change in zAff is guaranteed not to change the value.
TODO1: Can use (writer.pgidx.n==0) instead of bFirstTermInPage
True after initialization has finished
** Determine the average document (row) size in pages. If successful,
** write this value to *pnPage and return SQLITE_OK. Otherwise, return
** an SQLite error code.
**
** The average document size in pages is calculated by first calculating
** determining the average size in bytes, B. If B is less than the amount
** of data that will fit on a single leaf page of an intkey table in
** this database, then the average docsize is 1. Otherwise, it is 1 plus
** the number of overflow pages consumed by a record B bytes in size.
Merge engine thread reads data from
Finally, rollback pages from the sub-journal. Page that were
** previously rolled back out of the main journal (and are hence in pDone)
** will be skipped. Out-of-range pages are also skipped.
Cache for fts3CursorSeekStmt()
term ::= INTEGER
Sanity check: Assert that the IntValue is non-negative if it exists
** If pExpr is an ASC iterator, this function returns a value with the
** same sign as:
**
** (iLhs - iRhs)
**
** Otherwise, if this is a DESC iterator, the opposite is returned:
**
** (iRhs - iLhs)
Mask of cursors that are not available
** Called when a page of data is written to offset iOff of the database
** file while the rbu handle is in capture mode. Record the page number
** of the page being written in the aFrame[] array.
Connections from one process only
explicit IPK column
Input changeset
!defined(SQLITE_TEST) && !defined(SQLITE_OMIT_RANDOMNESS)
This undoes the effect of the HintPop() above - so that no entry
** is removed from the hint blob.
ON CONFLICT strategy
Pages of work to do
If p==0 (unmap the entire file) then there must be no outstanding
** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
** then there must be at least one outstanding.
Pointer to virtual tables needing locking
An index to being analyzed
************* Begin file vdbeblob.c ***************************************
Number of bytes in input
Ignore terms with these prereqs
** This is the xFilter interface for the virtual table. See
** the virtual table xFilter method documentation for additional
** information.
**
** If idxNum==FTS3_FULLSCAN_SEARCH then do a full table scan against
** the %_content table.
**
** If idxNum==FTS3_DOCID_SEARCH then do a docid lookup for a single entry
** in the %_content table.
**
** If idxNum>=FTS3_FULLTEXT_SEARCH then use the full text index. The
** column on the left-hand side of the MATCH operator is column
** number idxNum-FTS3_FULLTEXT_SEARCH, 0 indexed. argv[0] is the right-hand
** side of the MATCH operator.
no-op
40..47 @ABCDEFG
comment: Verify that no more than two scratch allocation per thread
** is outstanding at one time. (This is only checked in the
** single-threaded case since checking in the multi-threaded case
** would be much more complicated.)
label: code-design
** Iterator pIter was used to iterate through the input segments of on an
** incremental merge operation. This function is called if the incremental
** merge step has finished but the input has not been completely exhausted.
Request permission to read the parent key columns. If the
** authorization callback returns SQLITE_IGNORE, behave as if any
** values read from the parent table are NULL.
Write the hash value here
************* End of fts3_unicode2.c **************************************
** CAPI3REF: The pre-update hook.
**
** ^These interfaces are only available if SQLite is compiled using the
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
**
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
** on a database table.
** ^At most one preupdate hook may be registered at a time on a single
** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
** the previous setting.
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
** with a NULL pointer as the second parameter.
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
** the first parameter to callbacks.
**
** ^The preupdate hook only fires for changes to real database tables; the
** preupdate hook is not invoked for changes to [virtual tables] or to
** system tables like sqlite_master or sqlite_stat1.
**
** ^The second parameter to the preupdate callback is a pointer to
** the [database connection] that registered the preupdate hook.
** ^The third parameter to the preupdate callback is one of the constants
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
** kind of update operation that is about to occur.
** ^(The fourth parameter to the preupdate callback is the name of the
** database within the database connection that is being modified. This
** will be "main" for the main database or "temp" for TEMP tables or
** the name given after the AS keyword in the [ATTACH] statement for attached
** databases.)^
** ^The fifth parameter to the preupdate callback is the name of the
** table that is being modified.
**
** For an UPDATE or DELETE operation on a [rowid table], the sixth
** parameter passed to the preupdate callback is the initial [rowid] of the
** row being modified or deleted. For an INSERT operation on a rowid table,
** or any operation on a WITHOUT ROWID table, the value of the sixth
** parameter is undefined. For an INSERT or UPDATE on a rowid table the
** seventh parameter is the final rowid value of the row being inserted
** or updated. The value of the seventh parameter passed to the callback
** function is not defined for operations on WITHOUT ROWID tables, or for
** INSERT operations on rowid tables.
**
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
** provide additional information about a preupdate event. These routines
** may only be called from within a preupdate callback. Invoking any of
** these routines from outside of a preupdate callback or with a
** [database connection] pointer that is different from the one supplied
** to the preupdate callback results in undefined and probably undesirable
** behavior.
**
** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
** in the row that is being inserted, updated, or deleted.
**
** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row before it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed when the preupdate callback returns.
**
** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row after it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed when the preupdate callback returns.
**
** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
** callback was invoked as a result of a direct insert, update, or delete
** operation; or 1 for inserts, updates, or deletes invoked by top-level
** triggers; or 2 for changes resulting from triggers called by top-level
** triggers; and so forth.
**
** See also: [sqlite3_update_hook()]
The first page of the wal-index must be mapped at this point.
Copy entry from i2
** Initialize a WHERE clause scanner object. Return a pointer to the
** first match. Return NULL if there are no matches.
**
** The scanner will be searching the WHERE clause pWC. It will look
** for terms of the form "X <op> <expr>" where X is column iColumn of table
** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
** must be one of the indexes of table iCur.
**
** The <op> must be one of the operators described by opMask.
**
** If the search is for X and the WHERE clause contains terms of the
** form X=Y then this routine might also return terms of the form
** "Y <op> <expr>". The number of levels of transitivity is limited,
** but is enough to handle most commonly occurring SQL statements.
**
** If X is not the INTEGER PRIMARY KEY then X must be compatible with
** index pIdx.
** This function is called as part of sqlite3rbu_open() when initializing
** an rbu handle in OAL stage. If the rbu update has not started (i.e.
** the rbu_state table was empty) it is a no-op. Otherwise, it arranges
** things so that the next call to sqlite3rbu_step() continues on from
** where the previous rbu handle left off.
**
** If an error occurs, an error code and error message are left in the
** rbu handle passed as the first argument.
IN/OUT: Number of elements in aList[]
Bytes of space to allocate for this node
Pointer to the root node of a tree
The database file to check
The key for INTKEY tables, or nPayload otherwise
Parsing context
** The code above is the AFP lock implementation. The code is specific
** to MacOSX and does not work on other unix platforms. No alternative
** is available. If you don't compile for a mac, then the "unix-afp"
** VFS is not available.
**
********************* End of the AFP lock implementation **********************
*****************************************************************************
Merge PMAs together
Write the number of columns of result here
Prior index
xCheckReservedLock method
** Code an output subroutine for a coroutine implementation of a
** SELECT statment.
**
** The data to be output is contained in pIn->iSdst. There are
** pIn->nSdst columns to be output. pDest is where the output should
** be sent.
**
** regReturn is the number of the register holding the subroutine
** return address.
**
** If regPrev>0 then it is the first register in a vector that
** records the previous output. mem[regPrev] is a flag that is false
** if there has been no previous output. If regPrev>0 then code is
** generated to suppress duplicates. pKeyInfo is used for comparing
** keys.
**
** If the LIMIT found in p->iLimit is reached, jump immediately to
** iBreak.
input
Column ref to child table
Address of top of loop
Number of bytes in lhs input
Return a pointer to the enlarged SrcList
End of first segment of main-journal records
Poslist buffer to iterate through
159
170
Skip this term for now. We revisit it when we process the
** corresponding TERM_VIRTUAL term
** Do the comparison necessary to populate pIter->aFirst[iOut].
**
** If the returned value is non-zero, then it is the index of an entry
** in the pIter->aSeg[] array that is (a) not at EOF, and (b) pointing
** to a key that is a duplicate of another, higher priority,
** segment-iterator in the pSeg->aSeg[] array.
** If the library is compiled to omit the full-scale date and time
** handling (to get a smaller binary), the following minimal version
** of the functions current_time(), current_date() and current_timestamp()
** are included instead. This is to support column declarations that
** include "DEFAULT CURRENT_TIME" etc.
**
** This function uses the C-library functions time(), gmtime()
** and strftime(). The format string to pass to strftime() is supplied
** as the user-data for the function.
Argument to SQLITE_FCNTL_PRAGMA
#include "fts5parse.h"
Level/index to create new segment at
198
Buffer to serialize record into
** xColumn - Return a column value.
Columns that change in an UPDATE statement
Callback return code
** Implementation of the matchinfo() function for FTS3
comment: Serial types 12 or greater are strings and blobs (greater than
** numbers). Types 10 and 11 are currently "reserved for future
** use", so it doesn't really matter what the results of comparing
** them to numberic values are.
label: code-design
Busy handler timeout, in msec
257
Current parent of p
Error code
!SQLITE_OMIT_TRIGGER
** This version of the memory allocator is the default. It is
** used when no other memory allocator is specified using compile-time
** macros.
Date at which to calculate offset
* This is cache size used in the calculation of the initial size of the
* Win32-specific heap. It cannot be negative.
NULL for tables. Points to definition if a view.
Make sure every page in the file is referenced
(313) nmnum ::= DEFAULT
** Return the number of terms in the iPhrase'th phrase in pExpr.
Acts as query when no argument
217
synopsis: if( cursor[P1].ctr++ ) pc = P2
Records with omitted columns are only allowed for schema format
** version 2 and later (SQLite version 3.1.4, 2005-02-20).
a: p0<<14 | p2 (unmasked)
** Release a page reference.
**
** If the number of references to the page drop to zero, then the
** page is added to the LRU list. When all references to all pages
** are released, a rollback occurs and the lock on the database is
** removed.
Number of bytes of space to allocate
Next registered auxiliary function
** 2007 October 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The application gives SQLite a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
**
** This memory allocator uses the following algorithm:
**
** 1. All memory allocation sizes are rounded up to a power of 2.
**
** 2. If two adjacent free blocks are the halves of a larger block,
** then the two blocks are coalesced into the single larger block.
**
** 3. New memory is allocated from the first available free block.
**
** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
** Concerning Dynamic Storage Allocation". Journal of the Association for
** Computing Machinery, Volume 21, Number 8, July 1974, pages 491-499.
**
** Let n be the size of the largest allocation divided by the minimum
** allocation size (after rounding all sizes up to a power of 2.) Let M
** be the maximum amount of memory ever outstanding at one time. Let
** N be the total amount of memory available for allocation. Robson
** proved that this memory allocator will never breakdown due to
** fragmentation as long as the following constraint holds:
**
** N >= M*(1 + log2(n)/2) - n + 1
**
** The sqlite3_status() logic tracks the maximum values of n and M so
** that an application can, at any time, verify this constraint.
FROM clause cannot contain a subquery
comment:
** CAPI3REF: Formatted String Printing Functions
**
** These routines are work-alikes of the "printf()" family of functions
** from the standard C library.
** These routines understand most of the common K&R formatting options,
** plus some additional non-standard formats, detailed below.
** Note that some of the more obscure formatting options from recent
** C-library standards are omitted from this implementation.
**
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
** results into memory obtained from [sqlite3_malloc()].
** The strings returned by these two routines should be
** released by [sqlite3_free()]. ^Both routines return a
** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
** memory to hold the resulting string.
**
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
** the standard C library. The result is written into the
** buffer supplied as the second parameter whose size is given by
** the first parameter. Note that the order of the
** first two parameters is reversed from snprintf().)^ This is an
** historical accident that cannot be fixed without breaking
** backwards compatibility. ^(Note also that sqlite3_snprintf()
** returns a pointer to its buffer instead of the number of
** characters actually written into the buffer.)^ We admit that
** the number of characters written would be a more useful return
** value but we cannot change the implementation of sqlite3_snprintf()
** now without breaking compatibility.
**
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
** guarantees that the buffer is always zero-terminated. ^The first
** parameter "n" is the total size of the buffer, including space for
** the zero terminator. So the longest string that can be completely
** written will be n-1 characters.
**
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
**
** These routines all implement some additional formatting
** options that are useful for constructing SQL statements.
** All of the usual printf() formatting options apply. In addition, there
** is are "%q", "%Q", "%w" and "%z" options.
**
** ^(The %q option works like %s in that it substitutes a nul-terminated
** string from the argument list. But %q also doubles every '\'' character.
** %q is designed for use inside a string literal.)^ By doubling each '\''
** character it escapes that character and allows it to be inserted into
** the string.
**
** For example, assume the string variable zText contains text as follows:
**
** <blockquote><pre>
** char *zText = "It's a happy day!";
** </pre></blockquote>
**
** One can use this text in an SQL statement as follows:
**
** <blockquote><pre>
** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
** sqlite3_exec(db, zSQL, 0, 0, 0);
** sqlite3_free(zSQL);
** </pre></blockquote>
**
** Because the %q format string is used, the '\'' character in zText
** is escaped and the SQL generated is as follows:
**
** <blockquote><pre>
** INSERT INTO table1 VALUES('It''s a happy day!')
** </pre></blockquote>
**
** This is correct. Had we used %s instead of %q, the generated SQL
** would have looked like this:
**
** <blockquote><pre>
** INSERT INTO table1 VALUES('It's a happy day!');
** </pre></blockquote>
**
** This second example is an SQL syntax error. As a general rule you should
** always use %q instead of %s when inserting text into a string literal.
**
** ^(The %Q option works like %q except it also adds single quotes around
** the outside of the total string. Additionally, if the parameter in the
** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
** single quotes).)^ So, for example, one could say:
**
** <blockquote><pre>
** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
** sqlite3_exec(db, zSQL, 0, 0, 0);
** sqlite3_free(zSQL);
** </pre></blockquote>
**
** The code above will render a correct SQL statement in the zSQL
** variable even if the zText variable is a NULL pointer.
**
** ^(The "%w" formatting option is like "%q" except that it expects to
** be contained within double-quotes instead of single quotes, and it
** escapes the double-quote character instead of the single-quote
** character.)^ The "%w" formatting option is intended for safely inserting
** table and column names into a constructed SQL statement.
**
** ^(The "%z" formatting option works like "%s" but with the
** addition that after the string has been read and copied into
** the result, [sqlite3_free()] is called on the input string.)^
label: code-design
Array of mxSample Stat4Sample objects
Either DELETE or UPDATE. For err msgs.
288
OF
1 if the conch is held, -1 if lockless
WRITEABLE implies DIRTY
If there are outstanding sqlite3_stmt or sqlite3_backup objects
** or if the connection has not yet been closed by sqlite3_close_v2(),
** then just leave the mutex and return.
An array of root pages numbers for individual trees
jump here if parent key found
For looping over indices of the table
** The maximum number of arguments to an SQL function.
Grow the sqlite3.aVTrans array if required
The first fields of the two keys are equal and there are no trailing
** fields. Return pPKey2->default_rc in this case.
Bytes of data before flushing
** Allowed values for BtShared.btsFlags
271
** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case a
** default entry point name (sqlite3_extension_init) is used. Use
** of the default name is recommended.
**
** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
**
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
** error message text. The calling function should free this memory
** by calling sqlite3DbFree(db, ).
a &= (0x7f<<28)|(0x7f<<14)|(0x7f);
Write the BLOB here
Condition is always true or false
** 2008 October 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains a no-op memory allocation drivers for use when
** SQLITE_ZERO_MALLOC is defined. The allocation drivers implemented
** here always fail. SQLite will not operate with these drivers. These
** are merely placeholders. Real drivers must be substituted using
** sqlite3_config() before SQLite will operate.
** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
More terms for ARRAY and OBJECT
EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
** is the page number of the next freelist trunk page in the list or
** zero if this is the last freelist trunk page.
Database containing the table being updated
The end of the for(;;) loop the loops through opcodes
Default ON CONFLICT policy for trigger steps
True if sqlite3RowSetNext() has been called
Array of values to insert
IMP: R-39564-36305 The sqlite_compileoption_used() SQL
** function is a wrapper around the sqlite3_compileoption_used() C/C++
** function.
ccons ::= REFERENCES nm eidlist_opt refargs
Level to iterate (-1 for all)
Do allow the journalmode of an in-memory database to be set to
** anything other than MEMORY or OFF
If the right-hand side is also a column, then the affinities
** of both right and left sides must be such that no type
** conversions are required on the right. (Ticket #2249)
** The cache of the wal-index header must be valid to call this function.
** Return the page-size in bytes used by the database.
If there is more than one table or sub-select in the FROM clause of
** this query, then it will not be possible to show that the DISTINCT
** clause is redundant.
** Advance the cursor to the next row in the %_content table that
** matches the search criteria. For a MATCH search, this will be
** the next row that matches. For a full-table scan, this will be
** simply the next row in the %_content table. For a docid lookup,
** this routine simply sets the EOF flag.
**
** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
** even if we reach end-of-file. The fts3EofMethod() will be called
** subsequently to determine whether or not an EOF was hit.
pNew
TRUE for a TEMPORARY view
FTS3 Cursor
Database key for encryption extension
OUT: Array of boolean - true for PK cols
comment: FTS5_PLAN_XXX value
label: code-design
Do a binary search to find the first sample greater than or equal
** to pRec. If pRec contains a single field, the set of samples to search
** is simply the aSample[] array. If the samples in aSample[] contain more
** than one fields, all fields following the first are ignored.
**
** If pRec contains N fields, where N is more than one, then as well as the
** samples in aSample[] (truncated to N fields), the search also has to
** consider prefixes of those samples. For example, if the set of samples
** in aSample is:
**
** aSample[0] = (a, 5)
** aSample[1] = (a, 10)
** aSample[2] = (b, 5)
** aSample[3] = (c, 100)
** aSample[4] = (c, 105)
**
** Then the search space should ideally be the samples above and the
** unique prefixes [a], [b] and [c]. But since that is hard to organize,
** the code actually searches this set:
**
** 0: (a)
** 1: (a, 5)
** 2: (a, 10)
** 3: (a, 10)
** 4: (b)
** 5: (b, 5)
** 6: (c)
** 7: (c, 100)
** 8: (c, 105)
** 9: (c, 105)
**
** For each sample in the aSample[] array, N samples are present in the
** effective sample array. In the above, samples 0 and 1 are based on
** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
**
** Often, sample i of each block of N effective samples has (i+1) fields.
** Except, each sample may be extended to ensure that it is greater than or
** equal to the previous sample in the array. For example, in the above,
** sample 2 is the first sample of a block of N samples, so at first it
** appears that it should be 1 field in size. However, that would make it
** smaller than sample 1, so the binary search would not work. As a result,
** it is extended to two fields. The duplicates that this creates do not
** cause any problems.
Buffer containing position list
IS
Number of extra registers before regResult
True for a freelist. False for overflow page list
A column of pTab
Name context for resolving pE
First disjunct
If there are TEMP triggers on this table, modify the sqlite_temp_master
** table. Don't do this if the table being ALTERed is itself located in
** the temp database.
Name of content table
Height of sub-tree rooted at pCell
IMP: R-00293-64994
** Make sure the hard limits are set to reasonable values
comment: TODO: Is it safe to use Pager.dbFileSize here?
label: code-design
** Determine whether triggers are recursive by default. This can be
** changed at run-time using a pragma.
Pointer to the start of payload
Free the position-lists accumulated for each deferred token above.
Read the PK into an array of temp registers.
Rows come from source in GROUP BY order
The table to be updated
Cursor to iterate through aRight
SQLITE_OMIT_AUTOMATIC_INDEX
** Release all resources associated with an sqlite3_backup* handle.
** Change the lock state for a shared-memory segment.
**
** Note that the relationship between SHAREd and EXCLUSIVE locks is a little
** different here than in posix. In xShmLock(), one can go from unlocked
** to shared and back or from unlocked to exclusive and back. But one may
** not go from shared to exclusive or from exclusive to shared.
True if compound joined by UNION [ALL]
Finish the loop through table entries that match term pOrTerm.
comment:
** Initialize the object pIter to point to term pTerm/nTerm within the
** in-memory hash table. If there is no such term in the hash-table, the
** iterator is set to EOF.
**
** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
** an error has already occurred when this function is called, it is a no-op.
label: code-design
tcons ::= UNIQUE LP sortlist RP onconf
pgsize
Number of nested calls to VdbeExec()
Name of the file
** An instance of this structure holds information about the
** LIMIT clause of a SELECT statement.
At this point p points to that preceding byte without the 0x80 bit
** set. So to find the start of the poslist, skip forward 2 bytes then
** over a varint.
**
** Normally. The other case is that p==pStart and the poslist to return
** is the first in the doclist. In this case do not skip forward 2 bytes.
** The second part of the if condition (c==0 && *ppPoslist>&p[2])
** is required for cases where the first byte of a doclist and the
** doclist is empty. For example, if the first docid is 10, a doclist
** that begins with:
**
** 0x0A 0x00 <next docid delta varint>
Acquire a PENDING lock
Keep track of the number of rows to be deleted
For DOCID_CMP macro
No table available. Use comparisons
P1
Neither table may have __hidden__ columns
** Implementation of the xBestIndex method.
Db object for the newly attached database
xGetLastError
** Lock the file with the lock specified by parameter eFileLock - one
** of the following:
**
** (1) SHARED_LOCK
** (2) RESERVED_LOCK
** (3) PENDING_LOCK
** (4) EXCLUSIVE_LOCK
**
** Sometimes when requesting one lock state, additional lock states
** are inserted in between. The locking might fail on one of the later
** transitions leaving the lock state different from what it started but
** still short of its goal. The following chart shows the allowed
** transitions and the inserted intermediate states:
**
** UNLOCKED -> SHARED
** SHARED -> RESERVED
** SHARED -> (PENDING) -> EXCLUSIVE
** RESERVED -> (PENDING) -> EXCLUSIVE
** PENDING -> EXCLUSIVE
**
** This routine will only increase a lock. Use the sqlite3OsUnlock()
** routine to lower a locking level.
If not in RBU_STAGE_OAL, allow this call to pass through. Or, if this
** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
** instead of a file on disk.
!defined(SQLITE_OMIT_CHECK)
Page obtained by prior PcacheFetch() call
************* End of vdbesort.c *******************************************
If the cache has been modified but the savepoint cannot be rolled
** back journal_mode=off, put the pager in the error state. This way,
** if the VFS used by this pager includes ZipVFS, the entire transaction
** can be rolled back at the ZipVFS level.
Otherwise see if some other process holds it.
Check that malloc() has not failed. If it has, return early.
Docid to add or remove data from
Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
** it from sqlite3Malloc instead.
Locate the required virtual table module
** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
** must be either NO_LOCK or SHARED_LOCK.
**
** If the locking level of the file descriptor is already at or below
** the requested locking level, this routine is a no-op.
Estimated number of rows in this table
Next slot in aIndex[] not yet returned
comment: Malloc must have failed inside HashInsert()
label: code-design
** Numeric constants that encode the journalmode.
**
** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
** are exposed in the API via the "PRAGMA journal_mode" command and
** therefore cannot be changed without a compatibility break.
** Apply advisory locks for all n bytes beginning at ofst.
** An instance of the following structure is used to store state while
** iterating through a multi-column position-list corresponding to the
** hits for a single phrase on a single row in order to calculate the
** values for a matchinfo() FTS3_MATCHINFO_LCS request.
Number of pages to use in the cache
** Make sure pBt->pTmpSpace points to an allocation of
** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
** pointer.
True to trace changes
** Find (an approximate) sum of two LogEst values. This computation is
** not a simple "+" operator because LogEst is stored as a logarithmic
** value.
**
Root of NEAR expression
comment: If this scan uses an index, make VDBE code substitutions to read data
** from the index instead of from the table where possible. In some cases
** this optimization prevents the table from ever being read, which can
** yield a significant performance boost.
**
** Calls to the code generator in between sqlite3WhereBegin and
** sqlite3WhereEnd will have created code that references the table
** directly. This loop scans all that code looking for opcodes
** that reference the table and converts them into opcodes that
** reference the index.
label: code-design
Temp storage space for pCell, if needed
Value returned by sqlite3OsAccess()
Opcode: Permutation * * * P4 *
**
** Set the permutation used by the OP_Compare operator in the next
** instruction. The permutation is stored in the P4 operand.
**
** The permutation is only valid until the next OP_Compare that has
** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
** occur immediately prior to the OP_Compare.
**
** The first integer in the P4 integer array is the length of the array
** and does not become part of the permutation.
const char*
The p2 value always comes from a prior OP_CreateTable opcode and
** that opcode will always set the p2 value to 2 or more or else fail.
** If there were a failure, the prepared statement would have halted
** before reaching this instruction.
OUT: New sqlite3_vtab object
** Close the mutex on database connection db.
**
** Furthermore, if database connection db is a zombie (meaning that there
** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
** every sqlite3_stmt has now been finalized and every sqlite3_backup has
** finished, then free all resources.
View definition
Get a pointer the VDBE under construction, allocating a new VDBE if one
** does not already exist
USING
Pager object to allocate and return
expr ::= ID|INDEXED
comment: TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
** have been deleted? This API will need to change to return an error code
** as well as the boolean result value.
label: code-design
Maximum docid to return
comment: This block handles pages with two or fewer free blocks and nMaxFrag
** or fewer fragmented bytes. In this case it is faster to move the
** two (or one) blocks of cells using memmove() and add the required
** offsets to each pointer in the cell-pointer array than it is to
** reconstruct the entire page.
label: code-design
Enforced by btreeInitPage()
The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
** is disabled
Drop and reload the internal table schema.
1530
** The maximum allowed sector size. 64KiB. If the xSectorsize() method
** returns a value larger than this, then MAX_SECTOR_SIZE is used instead.
** This could conceivably cause corruption following a power failure on
** such a system. This is currently an undocumented limit.
Need to call sqlite3ExprDelete(db, pExpr)
The WhereOrSet to be updated
STEP 1:
** Look for an entry of the correct size in either the small
** chunk table or in the large chunk hash table. This is
** successful most of the time (about 9 times out of 10).
This loop runs once for each leaf in the tree of eType nodes.
Mapping from table to index column numbers
Index of first table to join in pSrc
xSync
Find the ORDER BY term that corresponds to the j-th column
** of the index and mark that ORDER BY term off
** A search constraint.
Check that the values read from the page-size and sector-size fields
** are within range. To be 'in range', both values need to be a power
** of two greater than or equal to 512 or 32, and not greater than their
** respective compile time maximum limits.
vtabargtoken ::= lp anylist RP
The converted number is in buf[] and zero terminated. Output it.
** Note that the number is in the usual order, not reversed as with
** integer conversions.
Number of active VDBEs that read or write
No. of ORDER BY terms satisfied. -1 for unknown
The results are stored in a sequence of registers
** starting at pDest->iSdst. Then the co-routine yields.
Check to see if an existing table or index can be used to
** satisfy the query. This is preferable to generating a new
** ephemeral table.
** 2015-08-12
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This SQLite extension implements JSON functions. The interface is
** modeled after MySQL JSON functions:
**
** https://dev.mysql.com/doc/refman/5.7/en/json.html
**
** For the time being, all JSON is stored as pure text. (We might add
** a JSONB type in the future which stores a binary encoding of JSON in
** a BLOB, but there is no support for JSONB in the current implementation.
** This implementation parses JSON text at 250 MB/s, so it is hard to see
** how JSONB might improve on that.)
** Link the SubProgram object passed as the second argument into the linked
** list at Vdbe.pSubProgram. This list is used to delete all sub-program
** objects when the VM is no longer required.
b: p1<<28 | p3<<14 | p5 (unmasked)
213
Modified table
Opcode: BitAnd P1 P2 P3 * *
** Synopsis: r[P3]=r[P1]&r[P2]
**
** Take the bit-wise AND of the values in register P1 and P2 and
** store the result in register P3.
** If either input is NULL, the result is NULL.
189
** Each file opened by an rbu VFS is represented by an instance of
** the following structure.
Jump here to continue next step of UPDATE loop
** Each recursive mutex is an instance of the following structure.
************************ End of sqlite3_vfs methods ***************************
*****************************************************************************
The conflict algorithm (OE_Abort, OE_Replace, etc.)
Value of RBU_STATE_STAGE field
** Join all outstanding threads launched by SorterWrite() to create
** level-0 PMAs.
text of name of TABLE
Attempt the match
A transient duplicate expression
** The Fts3Cursor.eSearch member is always set to one of the following.
** Actualy, Fts3Cursor.eSearch can be greater than or equal to
** FTS3_FULLTEXT_SEARCH. If so, then Fts3Cursor.eSearch - 2 is the index
** of the column to be searched. For example, in
**
** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
** SELECT docid FROM ex1 WHERE b MATCH 'one two three';
**
** Because the LHS of the MATCH operator is 2nd column "b",
** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1"
** indicating that all columns should be searched,
** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4.
The trigger step be fixed to one database
SYNC_NORMAL or SYNC_FULL for checkpoint
Offset from start of page to first cell pointer
Pointer to vfs object
** Attempt to extract a value from expression pExpr using the methods
** as described for sqlite3Stat4ProbeSetValue() above.
**
** If successful, set *ppVal to point to a new value object and return
** SQLITE_OK. If no value can be extracted, but no other error occurs
** (e.g. OOM), return SQLITE_OK and set *ppVal to NULL. Or, if an error
** does occur, return an SQLite error code. The final value of *ppVal
** is undefined in this case.
Next chunk on list of them all
Name of FTS index
The underlying shared-memory file
IcuCursor.aOffset[]
Hint to COMDB2
** Each auxiliary data pointer stored by a user defined function
** implementation calling sqlite3_set_auxdata() is stored in an instance
** of this structure. All such structures associated with a single VM
** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
** when the VM is halted (if not before).
List of entries using pRight
Number of tokens in extracted snippet
If there are no active statements, clear the interrupt flag at this
** point.
*************************************************************************
** Interface to code in fts5_index.c. fts5_index.c contains contains code
** to access the data stored in the %_data table.
** The code in this file is only compiled if:
**
** * The FTS3 module is being built as an extension
** (in which case SQLITE_CORE is not defined), or
**
** * The FTS3 module is being built into the core of
** SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
On the first call to sqlite3_step(), pSub will hold a NULL. It is
** initialized to a BLOB by the P4_SUBPROGRAM processing logic below
Buffer to read data from
Size of changeset blob in bytes
OUT: Allocated Fts3SegReader
** Verify that at least N opcode slots are available in p without
** having to malloc for more space (except when compiled using
** SQLITE_TEST_REALLOC_STRESS). This interface is used during testing
** to verify that certain calls to sqlite3VdbeAddOpList() can never
** fail due to a OOM fault and hence that the return value from
** sqlite3VdbeAddOpList() will always be non-NULL.
Opcode: InsertInt P1 P2 P3 P4 P5
** Synopsis: intkey=P3 data=r[P2]
**
** This works exactly like OP_Insert except that the key is the
** integer value P3, not the value of the integer stored in register P3.
update conch with host and path (this will fail if other process
** has a shared lock already), if the host id matches, use the big
** stick.
Cursor of the index itself
Used to move bytes around within data[]
** 2007 August 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for Win32.
Buffer used to hold most recent term
GOTO label for end of CASE stmt
** Return a pointer to a TriggerPrg object containing the sub-program for
** trigger pTrigger with default ON CONFLICT algorithm orconf. If no such
** TriggerPrg object exists, a new object is allocated and populated before
** being returned.
** Update the contents of the rbu_state table within the rbu database. The
** value stored in the RBU_STATE_STAGE column is eStage. All other values
** are determined by inspecting the rbu handle passed as the first argument.
synopsis: key=r[P2]
Only flags that can be set are SAVEPOISTION and AUXDELETE
comment: The following describes the implementation of the various locks and
** lock transitions in terms of the POSIX advisory shared and exclusive
** lock primitives (called read-locks and write-locks below, to avoid
** confusion with SQLite lock names). The algorithms are complicated
** slightly in order to be compatible with Windows95 systems simultaneously
** accessing the same database file, in case that is ever required.
**
** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
** byte', each single bytes at well known offsets, and the 'shared byte
** range', a range of 510 bytes at a well known offset.
**
** To obtain a SHARED lock, a read-lock is obtained on the 'pending
** byte'. If this is successful, 'shared byte range' is read-locked
** and the lock on the 'pending byte' released. (Legacy note: When
** SQLite was first developed, Windows95 systems were still very common,
** and Widnows95 lacks a shared-lock capability. So on Windows95, a
** single randomly selected by from the 'shared byte range' is locked.
** Windows95 is now pretty much extinct, but this work-around for the
** lack of shared-locks on Windows95 lives on, for backwards
** compatibility.)
**
** A process may only obtain a RESERVED lock after it has a SHARED lock.
** A RESERVED lock is implemented by grabbing a write-lock on the
** 'reserved byte'.
**
** A process may only obtain a PENDING lock after it has obtained a
** SHARED lock. A PENDING lock is implemented by obtaining a write-lock
** on the 'pending byte'. This ensures that no new SHARED locks can be
** obtained, but existing SHARED locks are allowed to persist. A process
** does not have to obtain a RESERVED lock on the way to a PENDING lock.
** This property is used by the algorithm for rolling back a journal file
** after a crash.
**
** An EXCLUSIVE lock, obtained after a PENDING lock is held, is
** implemented by obtaining a write-lock on the entire 'shared byte
** range'. Since all other locks require a read-lock on one of the bytes
** within this range, this ensures that no other locks are held on the
** database.
label: code-design
No way this can happen
Version 3.14.0 and later
errcode set by sqlite3_result_error_code()
If the EP_Reduced flag is set in the Expr.flags mask, then no
** space is allocated for the fields below this point. An attempt to
** access them will result in a segfault or malfunction.
********************************************************************
** 2007 May 1
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement incremental BLOB I/O.
Register used with OP_Gosub
** The code above is the NFS lock implementation. The code is specific
** to MacOSX and does not work on other unix platforms. No alternative
** is available.
**
********************* End of the NFS lock implementation **********************
*****************************************************************************
** Structure used internally by this VFS to record the state of an
** open shared memory connection.
**
** The following fields are initialized when this object is created and
** are read-only thereafter:
**
** winShm.pShmNode
** winShm.id
**
** All other fields are read/write. The winShm.pShmNode->mutex must be held
** while accessing any read/write fields.
AND
Use the original text of the column expression as its name
************* End of delete.c *********************************************
** CAPI3REF: Find The Database Handle Of A Prepared Statement
** METHOD: sqlite3_stmt
**
** ^The sqlite3_db_handle interface returns the [database connection] handle
** to which a [prepared statement] belongs. ^The [database connection]
** returned by sqlite3_db_handle is the same [database connection]
** that was the first argument
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
** create the statement in the first place.
15
"[" or 0
trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI
** The following variable is (normally) set once and never changes
** thereafter. It records whether the operating system is Win9x
** or WinNT.
**
** 0: Operating system unknown.
** 1: Operating system is Win9x.
** 2: Operating system is WinNT.
**
** In order to facilitate testing on a WinNT system, the test fixture
** can manually set this value to 1 to emulate Win98 behavior.
Keyinfo for scanned index
Wildcard characters
Process the LIMIT and OFFSET clauses, if they exist
At this point, we know the candidate directory exists and should
** be used. However, we may need to convert the string containing
** its name into UTF-8 (i.e. if it is UTF-16 right now).
** CAPI3REF: Retrieve the mutex for a database connection
** METHOD: sqlite3
**
** ^This interface returns a pointer the [sqlite3_mutex] object that
** serializes access to the [database connection] given in the argument
** when the [threading mode] is Serialized.
** ^If the [threading mode] is Single-thread or Multi-thread then this
** routine returns a NULL pointer.
Count down to first I/O error
** Access the static variable through a macro for SQLITE_OMIT_WSD.
comment: Check to see if we need to simulate an interrupt. This only happens
** if we have a special test build.
label: test
Coding an expression that is part of an index where column names
** in the index refer to the table to which the index belongs
Object to allocate and return
Name of rbu db table (or null)
Like mgt0 above except we are looking for a value of m which is
** exactly 1
************* Begin file main.c *******************************************
Registers for holding the start boundary
** This function queries the database for the names of the columns of table
** zThis, in schema zDb. It is expected that the table has nCol columns. If
** not, SQLITE_SCHEMA is returned and none of the output variables are
** populated.
**
** Otherwise, if they are not NULL, variable *pnCol is set to the number
** of columns in the database table and variable *pzTab is set to point to a
** nul-terminated copy of the table name. *pazCol (if not NULL) is set to
** point to an array of pointers to column names. And *pabPK (again, if not
** NULL) is set to point to an array of booleans - true if the corresponding
** column is part of the primary key.
**
** For example, if the table is declared as:
**
** CREATE TABLE tbl1(w, x, y, z, PRIMARY KEY(w, z));
**
** Then the four output variables are populated as follows:
**
** *pnCol = 4
** *pzTab = "tbl1"
** *pazCol = {"w", "x", "y", "z"}
** *pabPK = {1, 0, 0, 1}
**
** All returned buffers are part of the same single allocation, which must
** be freed using sqlite3_free() by the caller. If pazCol was not NULL, then
** pointer *pazCol should be freed to release all memory. Otherwise, pointer
** *pabPK. It is illegal for both pazCol and pabPK to be NULL.
Full path to database file
Jump from here if number of rows is zero
grab an exclusive lock
** Return true if the given Btree is read-only.
comment: Fails on a lookaside memory leak
label: code-design
comment:
** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy"
** command.
label: code-design
************* Begin file mutex.h ******************************************
Debug listings of VDBE programs
** Forward references to structures
Est. number of rows where the key equals this sample
The error context into which to write the error
comment:
** If they are not already populated, populate the pIter->azTblCol[],
** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
** the table (not index) that the iterator currently points to.
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise. If
** an error does occur, an error code and error message are also left in
** the RBU handle.
label: code-design
comment: These look like magic numbers. But they are stable, as they are part
** of the definition of the SQLite file format, which may not change.
label: code-design
** Name of the master database table. The master database table
** is a special table that holds the names and attributes of all
** user tables and indices.
** Write a 32-bit integer into the given file descriptor. Return SQLITE_OK
** on success or an error code is something goes wrong.
comment: ************************************************************************
** CUSTOM TOKENIZERS
**
** Applications may also register custom tokenizer types. A tokenizer
** is registered by providing fts5 with a populated instance of the
** following structure. All structure methods must be defined, setting
** any member of the fts5_tokenizer struct to NULL leads to undefined
** behaviour. The structure methods are expected to function as follows:
**
** xCreate:
** This function is used to allocate and initialize a tokenizer instance.
** A tokenizer instance is required to actually tokenize text.
**
** The first argument passed to this function is a copy of the (void*)
** pointer provided by the application when the fts5_tokenizer object
** was registered with FTS5 (the third argument to xCreateTokenizer()).
** The second and third arguments are an array of nul-terminated strings
** containing the tokenizer arguments, if any, specified following the
** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
** to create the FTS5 table.
**
** The final argument is an output variable. If successful, (*ppOut)
** should be set to point to the new tokenizer handle and SQLITE_OK
** returned. If an error occurs, some value other than SQLITE_OK should
** be returned. In this case, fts5 assumes that the final value of *ppOut
** is undefined.
**
** xDelete:
** This function is invoked to delete a tokenizer handle previously
** allocated using xCreate(). Fts5 guarantees that this function will
** be invoked exactly once for each successful call to xCreate().
**
** xTokenize:
** This function is expected to tokenize the nText byte string indicated
** by argument pText. pText may or may not be nul-terminated. The first
** argument passed to this function is a pointer to an Fts5Tokenizer object
** returned by an earlier call to xCreate().
**
** The second argument indicates the reason that FTS5 is requesting
** tokenization of the supplied text. This is always one of the following
** four values:
**
** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
** or removed from the FTS table. The tokenizer is being invoked to
** determine the set of tokens to add to (or delete from) the
** FTS index.
**
** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
** against the FTS index. The tokenizer is being called to tokenize
** a bareword or quoted string specified as part of the query.
**
** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
** followed by a "*" character, indicating that the last token
** returned by the tokenizer will be treated as a token prefix.
**
** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
** satisfy an fts5_api.xTokenize() request made by an auxiliary
** function. Or an fts5_api.xColumnSize() request made by the same
** on a columnsize=0 database.
** </ul>
**
** For each token in the input string, the supplied callback xToken() must
** be invoked. The first argument to it should be a copy of the pointer
** passed as the second argument to xTokenize(). The third and fourth
** arguments are a pointer to a buffer containing the token text, and the
** size of the token in bytes. The 4th and 5th arguments are the byte offsets
** of the first byte of and first byte immediately following the text from
** which the token is derived within the input.
**
** The second argument passed to the xToken() callback ("tflags") should
** normally be set to 0. The exception is if the tokenizer supports
** synonyms. In this case see the discussion below for details.
**
** FTS5 assumes the xToken() callback is invoked for each token in the
** order that they occur within the input text.
**
** If an xToken() callback returns any value other than SQLITE_OK, then
** the tokenization should be abandoned and the xTokenize() method should
** immediately return a copy of the xToken() return value. Or, if the
** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
** if an error occurs with the xTokenize() implementation itself, it
** may abandon the tokenization and return any error code other than
** SQLITE_OK or SQLITE_DONE.
**
** SYNONYM SUPPORT
**
** Custom tokenizers may also support synonyms. Consider a case in which a
** user wishes to query for a phrase such as "first place". Using the
** built-in tokenizers, the FTS5 query 'first + place' will match instances
** of "first place" within the document set, but not alternative forms
** such as "1st place". In some applications, it would be better to match
** all instances of "first place" or "1st place" regardless of which form
** the user specified in the MATCH query text.
**
** There are several ways to approach this in FTS5:
**
** <ol><li> By mapping all synonyms to a single token. In this case, the
** In the above example, this means that the tokenizer returns the
** same token for inputs "first" and "1st". Say that token is in
** fact "first", so that when the user inserts the document "I won
** 1st place" entries are added to the index for tokens "i", "won",
** "first" and "place". If the user then queries for '1st + place',
** the tokenizer substitutes "first" for "1st" and the query works
** as expected.
**
** <li> By adding multiple synonyms for a single term to the FTS index.
** In this case, when tokenizing query text, the tokenizer may
** provide multiple synonyms for a single term within the document.
** FTS5 then queries the index for each synonym individually. For
** example, faced with the query:
**
** <codeblock>
** ... MATCH 'first place'</codeblock>
**
** the tokenizer offers both "1st" and "first" as synonyms for the
** first token in the MATCH query and FTS5 effectively runs a query
** similar to:
**
** <codeblock>
** ... MATCH '(first OR 1st) place'</codeblock>
**
** except that, for the purposes of auxiliary functions, the query
** still appears to contain just two phrases - "(first OR 1st)"
** being treated as a single phrase.
**
** <li> By adding multiple synonyms for a single term to the FTS index.
** Using this method, when tokenizing document text, the tokenizer
** provides multiple synonyms for each token. So that when a
** document such as "I won first place" is tokenized, entries are
** added to the FTS index for "i", "won", "first", "1st" and
** "place".
**
** This way, even if the tokenizer does not provide synonyms
** when tokenizing query text (it should not - to do would be
** inefficient), it doesn't matter if the user queries for
** 'first + place' or '1st + place', as there are entires in the
** FTS index corresponding to both forms of the first token.
** </ol>
**
** Whether it is parsing document or query text, any call to xToken that
** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
** is considered to supply a synonym for the previous token. For example,
** when parsing the document "I won first place", a tokenizer that supports
** synonyms would call xToken() 5 times, as follows:
**
** <codeblock>
** xToken(pCtx, 0, "i", 1, 0, 1);
** xToken(pCtx, 0, "won", 3, 2, 5);
** xToken(pCtx, 0, "first", 5, 6, 11);
** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);
** xToken(pCtx, 0, "place", 5, 12, 17);
**</codeblock>
**
** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
** xToken() is called. Multiple synonyms may be specified for a single token
** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
** There is no limit to the number of synonyms that may be provided for a
** single token.
**
** In many cases, method (1) above is the best approach. It does not add
** extra data to the FTS index or require FTS5 to query for multiple terms,
** so it is efficient in terms of disk space and query speed. However, it
** does not support prefix queries very well. If, as suggested above, the
** token "first" is subsituted for "1st" by the tokenizer, then the query:
**
** <codeblock>
** ... MATCH '1s*'</codeblock>
**
** will not match documents that contain the token "1st" (as the tokenizer
** will probably not map "1s" to any prefix of "first").
**
** For full prefix support, method (3) may be preferred. In this case,
** because the index contains entries for both "first" and "1st", prefix
** queries such as 'fi*' or '1s*' will match correctly. However, because
** extra entries are added to the FTS index, this method uses more space
** within the database.
**
** Method (2) offers a midpoint between (1) and (3). Using this method,
** a query such as '1s*' will match documents that contain the literal
** token "1st", but not "first" (assuming the tokenizer is not able to
** provide synonyms for prefixes). However, a non-prefix query like '1st'
** will match against "1st" and "first". This method does not require
** extra disk space, as no extra entries are added to the FTS index.
** On the other hand, it may require more CPU cycles to run MATCH queries,
** as separate queries of the FTS index are required for each synonym.
**
** When using methods (2) or (3), it is important that the tokenizer only
** provide synonyms when tokenizing document text (method (2)) or query
** text (method (3)), not both. Doing so will not cause any errors, but is
** inefficient.
label: code-design
Query Planner Stability Guarantee
The database connection
IN: Pointer to the SQLiteThread structure
PRAGMA index_info (legacy version)
A counter
************* Include sqliteLimit.h in the middle of sqliteInt.h **********
All winShm objects pointing to this
** Run internal checks to ensure that the FTS index (a) is internally
** consistent and (b) contains entries for which the XOR of the checksums
** as calculated by sqlite3Fts5IndexEntryCksum() is cksum.
**
** Return SQLITE_CORRUPT if any of the internal checks fail, or if the
** checksum does not match. Return SQLITE_OK if all checks pass without
** error, or some other SQLite error code if another error (e.g. OOM)
** occurs.
!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB)
pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c
Cursor used for virtual table scan
Read the header. This might happen concurrently with a write to the
** same area of shared memory on a different CPU in a SMP,
** meaning it is possible that an inconsistent snapshot is read
** from the file. If this happens, return non-zero.
**
** There are two copies of the header at the beginning of the wal-index.
** When reading, read [0] first then [1]. Writes are in the reverse order.
** Memory barriers are used to prevent the compiler or the hardware from
** reordering the reads and writes.
If the old.* record has not yet been loaded into memory, do so now.
Argument to profile function
comment:
** Column affinity types.
**
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve
** the speed a little by numbering the values consecutively.
**
** But rather than start with 0 or 1, we begin with 'A'. That way,
** when multiple affinity types are concatenated into a string and
** used as the P4 operand, they will be more readable.
**
** Note also that the numeric types are grouped together so that testing
** for a numeric type is a single comparison. And the BLOB type is first.
label: code-design
Quote character (if any )
** 2007 May 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file defines various limits of what SQLite can process.
Pointer to wal-index content in memory
4: (start_constraints && !startEq && !bRev)
String to return via *pzWhere
comment: Tokens are never deferred for FTS tables created using the content=xxx
** option. The reason being that it is not guaranteed that the content
** table actually contains the same data as the index. To prevent this from
** causing any problems, the deferred token optimization is completely
** disabled for content=xxx tables.
label: code-design
Bytes of space required for argv[0]
True if pStmt is a seek
The node into which the cell is to be written
comment: This term is already coded
label: code-design
szLookaside, nLookaside
320
Return the Rtree of a RtreeCursor
Enable fts3_tokenizer(2)
Previous value written into pgidx
Copy as much data as is available in the buffer into the start of
** p->aAlloc[].
3: (!start_constraints && startEq && bRev)
Docid for current row.
** Read a 32-bit variable-length integer from memory starting at p[0].
** Return the number of bytes read. The value is stored in *v.
**
** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
** integer, then set *v to 0xffffffff.
**
** A MACRO version, getVarint32, is provided which inlines the
** single-byte case. All code should use the MACRO version as
** this function assumes the single-byte case has already been handled.
** Destroy a tokenizer
LANGUAGEID
True if all rows are being deleted
Initialize the next page.
comment:
** CAPI3REF: Memory Allocation Routines
**
** An instance of this object defines the interface between SQLite
** and low-level memory allocation routines.
**
** This object is used in only one place in the SQLite interface.
** A pointer to an instance of this object is the argument to
** [sqlite3_config()] when the configuration option is
** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
** By creating an instance of this object
** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
** during configuration, an application can specify an alternative
** memory allocation subsystem for SQLite to use for all of its
** dynamic memory needs.
**
** Note that SQLite comes with several [built-in memory allocators]
** that are perfectly adequate for the overwhelming majority of applications
** and that this object is only useful to a tiny minority of applications
** with specialized memory allocation requirements. This object is
** also used during testing of SQLite in order to specify an alternative
** memory allocator that simulates memory out-of-memory conditions in
** order to verify that SQLite recovers gracefully from such
** conditions.
**
** The xMalloc, xRealloc, and xFree methods must work like the
** malloc(), realloc() and free() functions from the standard C library.
** ^SQLite guarantees that the second argument to
** xRealloc is always a value returned by a prior call to xRoundup.
**
** xSize should return the allocated size of a memory allocation
** previously obtained from xMalloc or xRealloc. The allocated size
** is always at least as big as the requested size but may be larger.
**
** The xRoundup method returns what would be the allocated size of
** a memory allocation given a particular requested size. Most memory
** allocators round up memory allocations at least to the next multiple
** of 8. Some allocators round up to a larger multiple or to a power of 2.
** Every memory allocation request coming in through [sqlite3_malloc()]
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
** that causes the corresponding memory allocation to fail.
**
** The xInit method initializes the memory allocator. For example,
** it might allocate any require mutexes or initialize internal data
** structures. The xShutdown method is invoked (indirectly) by
** [sqlite3_shutdown()] and should deallocate any resources acquired
** by xInit. The pAppData pointer is used as the only parameter to
** xInit and xShutdown.
**
** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
** the xInit method, so the xInit method need not be threadsafe. The
** xShutdown method is only called from [sqlite3_shutdown()] so it does
** not need to be threadsafe either. For all other methods, SQLite
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
** it is by default) and so the methods are automatically serialized.
** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
** methods must be threadsafe or else make their own arrangements for
** serialization.
**
** SQLite will never invoke xInit() more than once without an intervening
** call to xShutdown().
label: code-design
** Create a new BTree table. Write into *piTable the page
** number for the root page of the new table.
**
** The type of type is determined by the flags parameter. Only the
** following values of flags are currently in use. Other values for
** flags might not work:
**
** BTREE_INTKEY|BTREE_LEAFDATA Used for SQL tables with rowid keys
** BTREE_ZERODATA Used for SQL indices
Fill in the pNew->x.pSelect or pNew->x.pList member.
Expression list contaning only pSelectRowid
Iterator pointer
Assume this many buckets in hash table
If pDbPage was a btree-page, then it may have child pages and/or cells
** that point to overflow pages. The pointer map entries for all these
** pages need to be changed.
**
** If pDbPage is an overflow page, then the first 4 bytes may store a
** pointer to a subsequent overflow page. If this is the case, then
** the pointer map needs to be updated for the subsequent overflow page.
The pager state may be changed from PAGER_ERROR to PAGER_OPEN here
** without clearing the error code. This is intentional - the error
** code is cleared and the cache reset in the block below.
** CAPI3REF: Load The Difference Between Tables Into A Session
**
** If it is not already attached to the session object passed as the first
** argument, this function attaches table zTbl in the same manner as the
** [sqlite3session_attach()] function. If zTbl does not exist, or if it
** does not have a primary key, this function is a no-op (but does not return
** an error).
**
** Argument zFromDb must be the name of a database ("main", "temp" etc.)
** attached to the same database handle as the session object that contains
** a table compatible with the table attached to the session by this function.
** A table is considered compatible if it:
**
** <ul>
** <li> Has the same name,
** <li> Has the same set of columns declared in the same order, and
** <li> Has the same PRIMARY KEY definition.
** </ul>
**
** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
** are compatible but do not have any PRIMARY KEY columns, it is not an error
** but no changes are added to the session object. As with other session
** APIs, tables without PRIMARY KEYs are simply ignored.
**
** This function adds a set of changes to the session object that could be
** used to update the table in database zFrom (call this the "from-table")
** so that its content is the same as the table attached to the session
** object (call this the "to-table"). Specifically:
**
** <ul>
** <li> For each row (primary key) that exists in the to-table but not in
** the from-table, an INSERT record is added to the session object.
**
** <li> For each row (primary key) that exists in the to-table but not in
** the from-table, a DELETE record is added to the session object.
**
** <li> For each row (primary key) that exists in both tables, but features
** different non-PK values in each, an UPDATE record is added to the
** session.
** </ul>
**
** To clarify, if this function is called and then a changeset constructed
** using [sqlite3session_changeset()], then after applying that changeset to
** database zFrom the contents of the two compatible tables would be
** identical.
**
** It an error if database zFrom does not exist or does not contain the
** required compatible table.
**
** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
** may be set to point to a buffer containing an English language error
** message. It is the responsibility of the caller to free this buffer using
** sqlite3_free().
The methods above are in version 1 of the sqlite_module object. Those
** below are for version 2 and greater.
Loop through all entries in the %_segdir table corresponding to
** segments in this index on levels greater than iAbsLevel. If there is
** at least one such segment, and it is possible to determine that all
** such segments are smaller than nLimit bytes in size, they will be
** promoted to level iAbsLevel.
240
Input path
What to do with the query results
** CAPI3REF: Database Connection Handle
** KEYWORDS: {database connection} {database connections}
**
** Each open SQLite database is represented by a pointer to an instance of
** the opaque structure named "sqlite3". It is useful to think of an sqlite3
** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
** and [sqlite3_close_v2()] are its destructors. There are many other
** interfaces (such as
** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
** [sqlite3_busy_timeout()] to name but three) that are methods on an
** sqlite3 object.
Start writing at this offset
Make sure the number of columns in the source data matches the number
** of columns to be inserted into the table.
SQLITE_OMIT_WAL
** Delete a changegroup object.
comment:
** Measure the number of characters needed to output the given
** identifier. The number returned includes any quotes used
** but does not include the null terminator.
**
** The estimate is conservative. It might be larger that what is
** really needed.
label: code-design
if we failed to get the lock then someone else must have it
comment: Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
** where possible
label: code-design
The SET expressions are not actually used inside the WHERE loop.
** So reset the colUsed mask. Unless this is a virtual table. In that
** case, set all bits of the colUsed mask (to ensure that the virtual
** table implementation makes all columns available).
Loop exits by "break"
** Invoke the given busy handler.
**
** This routine is called when an operation failed with a lock.
** If this routine returns non-zero, the lock is retried. If it
** returns 0, the operation aborts with an SQLITE_BUSY error.
** Move the content of pSrc into pDest
Default mmap_size setting
Number of columns beyond the key columns
registers holding insert rowid
If the btree is already in a write-transaction, or it
** is already in a read-transaction and a read-transaction
** is requested, this is a no-op.
comment:
** PRAGMA optimize
** PRAGMA optimize(MASK)
** PRAGMA schema.optimize
** PRAGMA schema.optimize(MASK)
**
** Attempt to optimize the database. All schemas are optimized in the first
** two forms, and only the specified schema is optimized in the latter two.
**
** The details of optimizations performed by this pragma are expected
** to change and improve over time. Applications should anticipate that
** this pragma will perform new optimizations in future releases.
**
** The optional argument is a bitmask of optimizations to perform:
**
** 0x0001 Debugging mode. Do not actually perform any optimizations
** but instead return one line of text for each optimization
** that would have been done. Off by default.
**
** 0x0002 Run ANALYZE on tables that might benefit. On by default.
** See below for additional information.
**
** 0x0004 (Not yet implemented) Record usage and performance
** information from the current session in the
** database file so that it will be available to "optimize"
** pragmas run by future database connections.
**
** 0x0008 (Not yet implemented) Create indexes that might have
** been helpful to recent queries
**
** The default MASK is and always shall be 0xfffe. 0xfffe means perform all
** of the optimizations listed above except Debug Mode, including new
** optimizations that have not yet been invented. If new optimizations are
** ever added that should be off by default, those off-by-default
** optimizations will have bitmasks of 0x10000 or larger.
**
** DETERMINATION OF WHEN TO RUN ANALYZE
**
** In the current implementation, a table is analyzed if only if all of
** the following are true:
**
** (1) MASK bit 0x02 is set.
**
** (2) The query planner used sqlite_stat1-style statistics for one or
** more indexes of the table at some point during the lifetime of
** the current connection.
**
** (3) One or more indexes of the table are currently unanalyzed OR
** the number of rows in the table has increased by 25 times or more
** since the last time ANALYZE was run.
**
** The rules for when tables are analyzed are likely to change in
** future releases.
label: code-design
Which nested loop of the FROM we are coding
OFF
** Append buffer nData/pData to buffer pBuf. If an OOM error occurs, set
** the error code in p. If an error has already occurred when this function
** is called, it is a no-op.
comment: Before setting pChild->pParent, test that we are not creating a
** loop of references (as we would if, say, pChild==pParent). We don't
** want to do this as it leads to a memory leak when trying to delete
** the referenced counted node structures.
label: code-design
Do not bother with a bulk allocation if the cache size very small
Append to this JSON string
** State information local to the memory allocation subsystem.
Register in which to assemble record
** Three SQL functions - stat_init(), stat_push(), and stat_get() -
** share an instance of the following structure to hold their state
** information.
OUT: True for an 'indirect' change
0x60 .. 0x6F
************ End control #defines ******************************************
EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
** buffers per thread.
**
** This can only be checked in single-threaded mode.
Number of instance matches this row
First of nMem value in the unpacked pKey
trigger_cmd ::= select
Next method
Populate the Select.zSelName[] string that is used to help with
** query planner debugging, to differentiate between multiple Select
** objects in a complex query.
**
** If the SELECT keyword is immediately followed by a C-style comment
** then extract the first few alphanumeric characters from within that
** comment to be the zSelName value. Otherwise, the label is #N where
** is an integer that is incremented with each SELECT statement seen.
same as TK_BITNOT, in1, out2
RIGHT JOIN not (yet) supported
** Every page in the cache is controlled by an instance of the following
** structure.
Pick rows in this db only
Next trigger associated with the table
pgnoRoot is the page that will be used for the root-page of
** the new table (assuming an error did not occur). But we were
** allocated pgnoMove. If required (i.e. if it was not allocated
** by extending the file), the current page at position pgnoMove
** is already journaled.
VALUES
Argument to the trace function
Memory available to be allocated
Upon reaching the end of input, call the parser two more times
** with tokens TK_SEMI and 0, in that order.
** Disable all error recovery processing in the parser push-down
** automaton.
307
Create a new savepoint structure.
Columns of %_content table
Display all of the WhereLoop objects
** Initialize this module.
case_exprlist ::= case_exprlist WHEN expr THEN expr
** Move to the next matching term/rowid. Used by the fts5vocab module.
If there are two or more cursors on the same btree, then all such
** cursors *must* have the BTCF_Multiple flag set.
Used in RBU vacuum mode only
** 2012 May 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
on no off false yes true extra full
** Each token coming out of the lexer is an instance of
** this structure. Tokens are also used as part of an expression.
**
** Note if Token.z==0 then Token.dyn and Token.n are undefined and
** may contain random values. Do not make any assumptions about Token.dyn
** and Token.n when Token.z==0.
SQLITE_STATUS_SCRATCH_OVERFLOW
(326) anylist ::=
expr ::= expr LT|GT|GE|LE expr
** CAPI3REF: Set A Busy Timeout
** METHOD: sqlite3
**
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
** for a specified amount of time when a table is locked. ^The handler
** will sleep multiple times until at least "ms" milliseconds of sleeping
** have accumulated. ^After at least "ms" milliseconds of sleeping,
** the handler returns 0 which causes [sqlite3_step()] to return
** [SQLITE_BUSY].
**
** ^Calling this routine with an argument less than or equal to zero
** turns off all busy handlers.
**
** ^(There can only be a single busy handler for a particular
** [database connection] at any given moment. If another busy handler
** was defined (using [sqlite3_busy_handler()]) prior to calling
** this routine, that other busy handler is cleared.)^
**
** See also: [PRAGMA busy_timeout]
** Run the parser and code generator recursively in order to generate
** code for the SQL statement given onto the end of the pParse context
** currently under construction. When the parser is run recursively
** this way, the final OP_Halt is not appended and other initialization
** and finalization steps are omitted because those are handling by the
** outermost parser.
**
** Not everything is nestable. This facility is designed to permit
** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use
** care if you decide to try to use this routine for some other purposes.
Page number of the next source page to copy
comment: Opcode: Clear P1 P2 P3
**
** Delete all contents of the database table or index whose root page
** in the database file is given by P1. But, unlike Destroy, do not
** remove the table or index from the database file.
**
** The table being clear is in the main database file if P2==0. If
** P2==1 then the table to be clear is in the auxiliary database file
** that is used to store tables create using CREATE TEMPORARY TABLE.
**
** If the P3 value is non-zero, then the table referred to must be an
** intkey table (an SQL table, not an index). In this case the row change
** count is incremented by the number of rows in the table being cleared.
** If P3 is greater than zero, then the value stored in register P3 is
** also incremented by the number of rows in the table being cleared.
**
** See also: Destroy
label: code-design
** Remove a trigger from the hash tables of the sqlite* pointer.
** Create an "ascii" tokenizer.
If it is a RELEASE, then destroy the savepoint being operated on
** too. If it is a ROLLBACK TO, then set the number of deferred
** constraint violations present in the database to the value stored
** when the savepoint was created.
The first cursor that needs saving
not the primary delete operation
Name of current table
Buffer containing token
If the mmap() above failed, assume that all subsequent mmap() calls
** will probably fail too. Fall back to using xRead/xWrite exclusively
** in this case.
** Generate VDBE code that prepares for doing an operation that
** might change the database.
**
** This routine starts a new transaction if we are not already within
** a transaction. If we are already within a transaction, then a checkpoint
** is set if the setStatement parameter is true. A checkpoint should
** be set for operations that might fail (due to a constraint) part of
** the way through and which will need to undo some writes without having to
** rollback the whole transaction. For operations where all constraints
** can be checked before any changes are made to the database, it is never
** necessary to undo a write and the checkpoint should not be set.
If this frame set completes the first transaction in the WAL and
** if PRAGMA journal_size_limit is set, then truncate the WAL to the
** journal size limit, if possible.
OP_Delete does pre-update-hook only
Cursor
The WHERE clause for DELETE or UPDATE steps
dot lock style uses the locking context to store the dot lock
** file path
The incremental merge did not copy all the data from this
** segment to the upper level. The segment is modified in place
** so that it contains no keys smaller than zTerm/nTerm.
If there is an ORDER BY clause, then create an ephemeral index to
** do the sorting. But this sorting ephemeral index might end up
** being unused if the data can be extracted in pre-sorted order.
** If that is the case, then the OP_OpenEphemeral instruction will be
** changed to an OP_Noop once we figure out that the sorting index is
** not needed. The sSort.addrSortIndex variable is used to facilitate
** that change.
Do the b-tree integrity checks
Program instructions for parent frame
** If argument pNear is NULL, then a new Fts5ExprNearset object is allocated
** and populated with pPhrase. Or, if pNear is not NULL, phrase pPhrase is
** appended to it and the results returned.
**
** If an OOM error occurs, both the pNear and pPhrase objects are freed and
** NULL returned.
First argument to xCallback()
cmd ::= ANALYZE nm dbnm
Number of terms
NO
Transient storage for serial_type in OP_MakeRecord
SQLite function call context
Mem.i contains count of 0s appended to blob
The new opcode
SQLITE_AUTH
122
Use unixClose to clean up the resources added in fillInUnixFile
** and clear all the structure's references. Specifically,
** pFile->pMethods will be NULL so sqlite3OsClose will be a no-op
** The first parameter (pDef) is a function implementation. The
** second parameter (pExpr) is the first argument to this function.
** If pExpr is a column in a virtual table, then let the virtual
** table implementation have an opportunity to overload the function.
**
** This routine is used to allow virtual table implementations to
** overload MATCH, LIKE, GLOB, and REGEXP operators.
**
** Return either the pDef argument (indicating no change) or a
** new FuncDef structure that is marked as ephemeral using the
** SQLITE_FUNC_EPHEM flag.
Generate column names for this SELECT statement
xBegin
** This function is called when initializing an incremental-merge operation.
** It checks if the existing segment with index value iIdx at absolute level
** (iAbsLevel+1) can be appended to by the incremental merge. If it can, the
** merge-writer object *pWriter is initialized to write to it.
**
** An existing segment can be appended to by an incremental merge if:
**
** * It was initially created as an appendable segment (with all required
** space pre-allocated), and
**
** * The first key read from the input (arguments zKey and nKey) is
** greater than the largest key currently stored in the potential
** output segment.
Input buffer
Number of times this instruction was executed
Index of root page
Set nNewSize to the size allocated for the structure pointed to
** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
** by the copy of the p->u.zToken string (if any).
WAL connection
0x0e
** This routine sets up a SELECT statement for processing. The
** following is accomplished:
**
** * VDBE Cursor numbers are assigned to all FROM-clause terms.
** * Ephemeral Table objects are created for all FROM-clause subqueries.
** * ON and USING clauses are shifted into WHERE statements
** * Wildcards "*" and "TABLE.*" in result sets are expanded.
** * Identifiers in expression are matched to tables.
**
** This routine acts recursively on all subqueries within the SELECT.
Number of records written to sub-journal
Previous with the same zTo
The P2 table cursor (OP_DeferredSeek only)
For looping over compound SELECTs in pSubq
Cursor to read old values from
Current number of savepoints
** Report the wrong number of arguments for json_insert(), json_replace()
** or json_set().
occur in pairs
** The Vdbe.aColName array contains 5n Mem structures, where n is the
** number of columns of data returned by the statement.
Connection to watch for unlock
Delete the transient table structure associated with the
** subquery
Free this when deleting the vdbe
Do some checking to help insure the file we opened really is
** a valid database file.
using_opt
RHS is a blob
Incremented with each busy call
** Allowed values for the flags parameter to sqlite3PagerOpen().
**
** NOTE: These values must match the corresponding BTREE_ values in btree.h.
Check if pExpr is a sub-select. If so, consider it variable.
Opcode: String8 * P2 * P4 *
** Synopsis: r[P2]='P4'
**
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
** into a String opcode before it is executed for the first time. During
** this transformation, the length of string P4 is computed and stored
** as the P1 parameter.
*************************************************************************
** Interface to code in fts5_varint.c.
Set to true when thread finishes
** Collation sequence destructor function. The pCtx argument points to
** a UCollator structure previously allocated using ucol_open().
** Open a new Fts5Index handle. If the bCreate argument is true, create
** and initialize the underlying tables
**
** If successful, set *pp to point to the new object and return SQLITE_OK.
** Otherwise, set *pp to NULL and return an SQLite error code.
Buffer to load terms into
Set the usable flag on the subset of constraints identified by
** arguments mUsable and mExclude.
Seek cursor iCur to the row to delete. If this row no longer exists
** (this can happen if a trigger program has already deleted it), do
** not attempt to delete it or fire any DELETE triggers.
153
Construct the Index object to describe this index
True after i'th new page is populated
Open the connection to the log file. If this operation fails,
** (e.g. due to malloc() failure), return an error code.
Common features
The FROM clause term to search
Size of term prefix in bytes
Copy original pages out of the journal and back into the
** database file and/or page cache.
** Return the 'affinity' of the expression pExpr if any.
**
** If pExpr is a column, a reference to a column via an 'AS' alias,
** or a sub-select with a column as the return value, then the
** affinity of that column is returned. Otherwise, 0x00 is returned,
** indicating no affinity for the expression.
**
** i.e. the WHERE clause expressions in the following statements all
** have an affinity:
**
** CREATE TABLE t1(a);
** SELECT * FROM t1 WHERE a;
** SELECT a AS b FROM t1 WHERE b;
** SELECT * FROM t1 WHERE (select a from t1);
A correlated subquery has been seen
Allocated size of buffer z in bytes
************* End of utf.c ************************************************
comment: Unused opcode memory
label: code-design
** The DJGPP compiler environment looks mostly like Unix, but it
** lacks the fcntl() system call. So redefine fcntl() to be something
** that always succeeds. This means that locking does not occur under
** DJGPP. But it is DOS - what did you expect?
Session object pTab is attached to
setlist ::= LP idlist RP EQ expr
A completely parsed JSON string
** Return the depth of a tree comprising nPMA PMAs, assuming a fanout of
** SORTER_MAX_MERGE_COUNT. The returned value does not include leaf nodes.
**
** i.e.
**
** nPMA<=16 -> TreeDepth() == 0
** nPMA<=256 -> TreeDepth() == 1
** nPMA<=65536 -> TreeDepth() == 2
** Kinds of hints that can be passed into the sqlite3BtreeCursorHint()
** interface.
**
** BTREE_HINT_RANGE (arguments: Expr*, Mem*)
**
** The first argument is an Expr* (which is guaranteed to be constant for
** the lifetime of the cursor) that defines constraints on which rows
** might be fetched with this cursor. The Expr* tree may contain
** TK_REGISTER nodes that refer to values stored in the array of registers
** passed as the second parameter. In other words, if Expr.op==TK_REGISTER
** then the value of the node is the value in Mem[pExpr.iTable]. Any
** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th
** column of the b-tree of the cursor. The Expr tree will not contain
** any function calls nor subqueries nor references to b-trees other than
** the cursor being hinted.
**
** The design of the _RANGE hint is aid b-tree implementations that try
** to prefetch content from remote machines - to provide those
** implementations with limits on what needs to be prefetched and thereby
** reduce network bandwidth.
**
** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
** standard SQLite. The other hints are provided for extentions that use
** the SQLite parser and code generator but substitute their own storage
** engine.
pSlot and pCArray->apCell[i] will never overlap on a well-formed
** database. But they might for a corrupt database. Hence use memmove()
** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD
Format string for SQL
resolvetype ::= REPLACE
Minimum file format for writable database files
LOCATE_VIEW or LOCATE_NOERR
Add the table to the in-memory representation of the database.
OUT: First token of proposed snippet
fts5YYNOERRORRECOVERY
Return the sqlite3_file object for the WAL file
Precomputed device characteristics
Object to pass to xBestIndex()
This is what we do if the grammar does not define ERROR:
**
** * Report an error message, and throw away the input token.
**
** * If the input token is $, then fail the parse.
**
** As before, subsequent error messages are suppressed until
** three input tokens have been successfully shifted.
** Convert an ANSI string to Microsoft Unicode, using the ANSI or OEM
** code page.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
Mask of the bit in sqlite3.flags to set/clear
Comparison operator
** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
** should be one of the following values. The integer values are assigned
** to constants so that the offset of the corresponding field in an
** SQLite database header may be found using the following formula:
**
** offset = 36 + (idx * 4)
**
** For example, the free-page-count field is located at byte offset 36 of
** the database file header. The incr-vacuum-flag field is located at
** byte offset 64 (== 36+4*7).
**
** The BTREE_DATA_VERSION value is not really a value stored in the header.
** It is a read-only number computed by the pager. But we merge it with
** the header value access routines since its access pattern is the same.
** Call it a "virtual meta value".
Run the program
If this is an INSERT into a table b-tree and the table has an
** explicit INTEGER PRIMARY KEY, check that this is not an attempt
** to write a NULL into the IPK column. That is not permitted.
Current tree root
** Return true if the p->aiException[] array contains the value iCode.
Create a record from the argument register contents and insert it into
** the ephemeral table.
List of dirty pages in LRU order
** CAPI3REF: Custom Page Cache Object
**
** The sqlite3_pcache type is opaque. It is implemented by
** the pluggable module. The SQLite core has no knowledge of
** its size or internal structure and never deals with the
** sqlite3_pcache object except by holding and passing pointers
** to the object.
**
** See [sqlite3_pcache_methods2] for additional information.
** This function is called while stepping or preparing a statement
** associated with connection db. The operation will return SQLITE_LOCKED
** to the user because it requires a lock that will not be available
** until connection pBlocker concludes its current transaction.
** The json_test1(JSON) function return true (1) if the input is JSON
** text generated by another json function. It returns (0) if the input
** is not known to be JSON.
Do not write content to disk
old.* record for second change
Saved syscall error number
Index of the column to extract
148
Try to ORDER BY the result set to make distinct processing easier
** Close an open wal-index.
Array of arguments
Underlying VFS
Saved value of p->iOffset
Pseudo-random number used for sampling
Value to return from this function
True to run the ORDER BY search loop
EXCLUSIVE
Delete the index records
Allocated size of aBuffer[] in bytes
Number of slots in apHash[]
"PRAGMA encoding"
The database structure
Tokenizer module
The SQLITE_EXTRA_DURABLE compile-time option used to set the default
** synchronous setting to EXTRA. It is no longer supported.
The expression mask set
Year, month, and day
Fire BEFORE or INSTEAD OF triggers
xEof - check for end of scan
xRowid - read data
jump, in1
** Grow the db->aVTrans[] array so that there is room for at least one
** more v-table. Return SQLITE_NOMEM if a malloc fails, or SQLITE_OK otherwise.
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
** two-byte aligned address. get2bytea() is only used for accessing the
** cell addresses in a btree header.
The "wsdStat" macro will resolve to the status information
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdStat can refer directly
** to the "sqlite3Stat" state vector declared above.
830
** Execute zSql on database db.
**
** If zSql returns rows, then each row will have exactly one
** column. (This will only happen if zSql begins with "SELECT".)
** Take each row of result and call execSql() again recursively.
**
** The execSqlF() routine does the same thing, except it accepts
** a format string as its third argument
The flattened query is distinct if either the inner or the
** outer query is distinct.
Pager.pageSize bytes of space for tmp use
Identify the output register
Expression for MATCH queries
** The maximum number of attached databases. This must be between 0
** and 125. The upper bound of 125 is because the attached databases are
** counted using a signed 8-bit integer which has a maximum value of 127
** and we have to allow 2 extra counts for the "main" and "temp" databases.
Used to iterate through pTrigger list
One or more of FLAG_ constants below
** Free up as much memory as possible from the page cache.
132
** Flush the contents of in-memory hash table iHash to a new level-0
** segment on disk. Also update the corresponding structure record.
**
** If an error occurs, set the Fts5Index.rc error code. If an error has
** already occurred, this function is a no-op.
** END OF CUSTOM TOKENIZERS
************************************************************************
Set up a new SrcList in pOrTab containing the table being scanned
** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
Set len to the maximum number of bytes required in the output buffer.
The file descriptor for pFile
If there were no rowids on the leaf page either and the doclist-index
** has already been started, append an 0x00 byte to it.
Mask of TF_* values
Opcode: IfNotZero P1 P2 * * *
** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
**
** Register P1 must contain an integer. If the content of register P1 is
** initially greater than zero, then decrement the value in register P1.
** If it is non-zero (negative or positive) and then also jump to P2.
** If register P1 is initially zero, leave it unchanged and fall through.
Value returned by sqlite3_total_changes()
** Turn bulk memory into a RowSet object. N bytes of memory
** are available at pSpace. The db pointer is used as a memory context
** for any subsequent allocations that need to occur.
** Return a pointer to the new RowSet object.
**
** It must be the case that N is sufficient to make a Rowset. If not
** an assertion fault occurs.
**
** If N is larger than the minimum, use the surplus as an initial
** allocation of entries available to be filled.
Index of first token in snippet
Release the reader lock held while backfilling
Number of bits that are set - only valid for aHash
** element. Max is BITVEC_NINT. For BITVEC_SZ of 512,
** this would be 125.
CAST => ID
text encoding
sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
number of named columns in virtual table
** Retrieve a page from the pager cache. If the requested page is not
** already in the pager cache return NULL. Initialize the MemPage.pBt and
** MemPage.aData elements if needed.
Forward references to VFS helper methods used for temporary files
** This routine restores a cursor back to its original position after it
** has been moved by some outside activity (such as a btree rebalance or
** a row having been deleted out from under the cursor).
**
** On success, the *pDifferentRow parameter is false if the cursor is left
** pointing at exactly the same row. *pDifferntRow is the row the cursor
** was pointing to has been deleted, forcing the cursor to point to some
** nearby row.
**
** This routine should only be called for a cursor that just returned
** TRUE from sqlite3BtreeCursorHasMoved().
expr ::= expr EQ|NE expr
The data for the record immediately follows this header
Calling function guarantees this much
Empty output segment. This is a no-op.
** Sync an rbuVfs-file.
b
Starter space for aArg[]. No malloc required
Allocate space for the WalIterator object.
refarg ::= ON DELETE refact
INNER
typename ::= typename ID|STRING
Zero or more SQLITE_PREPARE_* flags
To avoid deadlock, first release all locks with a larger
** BtShared address. Then acquire our lock. Then reacquire
** the other BtShared locks that we used to hold in ascending
** order.
testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL
In test mode, increase the size of this structure a bit so that
** it is larger than the struct CrashFile defined in test6.c.
IN/OUT: Readr offset in pTask->file
** Close a connection to shared-memory. Delete the underlying
** storage if deleteFlag is true.
now generate the new WHERE rowid IN clause for the DELETE/UDPATE
** CAPI3REF: Virtual Table Configuration Options
**
** These macros define the various options to the
** [sqlite3_vtab_config()] interface that [virtual table] implementations
** can use to customize and optimize their behavior.
**
** <dl>
** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
** <dd>Calls of the form
** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
** where X is an integer. If X is zero, then the [virtual table] whose
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
** support constraints. In this configuration (which is the default) if
** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
** specified as part of the users SQL statement, regardless of the actual
** ON CONFLICT mode specified.
**
** If X is non-zero, then the virtual table implementation guarantees
** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
** any modifications to internal or persistent data structures have been made.
** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
** is able to roll back a statement or database transaction, and abandon
** or continue processing the current SQL statement as appropriate.
** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
** had been ABORT.
**
** Virtual table implementations that are required to handle OR REPLACE
** must do so within the [xUpdate] method. If a call to the
** [sqlite3_vtab_on_conflict()] function indicates that the current ON
** CONFLICT policy is REPLACE, the virtual table implementation should
** silently replace the appropriate rows within the xUpdate callback and
** return SQLITE_OK. Or, if this is not possible, it may return
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
** constraint handling.
** </dl>
SQLITE_STMTSTATUS_VM_STEP
Set the WHERE_ONEROW flag if the xBestIndex() method indicated
** that the scan will visit at most one row. Clear it otherwise.
** Code an OP_Halt due to non-unique rowid.
The BtShared object that owns pPage
Make sure the ordering..
** The sqlite3KeywordCode function looks up an identifier to determine if
** it is a keyword. If it is a keyword, the token code of that keyword is
** returned. If the input is not a keyword, TK_ID is returned.
**
** The implementation of this routine was generated by a program,
** mkkeywordhash.c, located in the tool subdirectory of the distribution.
** The output of the mkkeywordhash.c program is written into a file
** named keywordhash.h and then included into this source file by
** the #include below.
Called only by OP_MaxPgcnt
xSetSystemCall
Address of the OP_Jump opcode
** Stub routines for all mutex methods.
**
** This routines provide no mutual exclusion or error checking.
** The sqlite3ValueBytes() routine returns the number of bytes in the
** sqlite3_value object assuming that it uses the encoding "enc".
** The valueBytes() routine is a helper function.
** Assign VdbeCursor index numbers to all tables in a SrcList
SQLITE_ENABLE_DBSTAT_VTAB
Busy callback
List of global functions to be inserted
************* End of where.c **********************************************
comment: Processing for aggregates with GROUP BY is very different and
** much more complex than aggregates without a GROUP BY.
label: code-design
** Return TRUE if the pager is in a state where it is OK to change the
** journalmode. Journalmode changes can only happen when the database
** is unmodified.
** Link the chunk at mem5.aPool[i] so that is on the iLogsize
** free list.
** This function is the implementation of the xUpdate callback used by
** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
** inserted, updated or deleted.
Destructor for the aux data
Skip past any whitespace
comment: First register in temporary register block
label: code-design
One usually wants to use hw.acctivecpu for MT decisions, but not here
Add this many bytes to each in-memory page
If the first page of the wal-index has been mapped, try to read the
** wal-index header immediately, without holding any lock. This usually
** works, but may fail if the wal-index header is corrupt or currently
** being modified by another thread or process.
** These macros define the location of the pointer-map entry for a
** database page. The first argument to each is the number of usable
** bytes on each page of the database (often 1024). The second is the
** page number to look up in the pointer map.
**
** PTRMAP_PAGENO returns the database page number of the pointer-map
** page that stores the required pointer. PTRMAP_PTROFFSET returns
** the offset of the requested map entry.
**
** If the pgno argument passed to PTRMAP_PAGENO is a pointer-map page,
** then pgno is returned. So (pgno==PTRMAP_PAGENO(pgsz, pgno)) can be
** used to test if pgno is a pointer-map page. PTRMAP_ISPAGE implements
** this test.
comment: The following loop copies up to p->nBuffer bytes per iteration into
** the p->aAlloc[] buffer.
label: code-design
Index of the OR-term to be analyzed
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains macros and a little bit of code that is common to
** all of the platform-specific files (os_*.c) and is #included into those
** files.
**
** This file should be #included by the os_*.c files only. It is not a
** general purpose header file.
Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
** vector, then it is stored in an array of nVector registers starting
** at r1.
**
** sqlite3FindInIndex() might have reordered the fields of the LHS vector
** so that the fields are in the same order as an existing index. The
** aiMap[] array contains a mapping from the original LHS field order to
** the field order that matches the RHS index.
Value of db->nChange
** Clear (destroy) the BtShared.pHasContent bitvec. This should be
** invoked at the conclusion of each write-transaction.
The VDBE already created by calling function
Number of result columns
The database file is locked
Handle extra flags for this index, if not NULL
SQLITE_OMIT_PRAGMA
If the existing change is considered "indirect", but this current
** change is "direct", mark the change object as direct.
No-op stubs to use when memory-mapped I/O is disabled
Unix cannot, but some systems may return SQLITE_FULL from here. This
** line is to test that doing so does not cause any problems.
Add an entry to each output position list
** Merge the two sorted lists p1 and p2 into a single list.
EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
** point number string BLOB NULL
PRIMARY KEY array
** Convert a UTF-8 string to a multi-byte character string.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
expr ::= nm DOT nm DOT nm
Root of the new tree
If control gets to this point, then actually go ahead and make
** operating system calls for the specified lock.
Read in the WAL header.
** Return one of the WHERE_DISTINCT_xxxxx values to indicate how this
** WHERE clause returns outputs for DISTINCT processing.
If the destination is an EXISTS(...) expression, the actual
** values returned by the SELECT are not required.
xLock
If bSkip is true, then the caller has already determined that the first
** two elements in the keys are equal. Fix the various stack variables so
** that this routine begins comparing at the second field.
** Attempt to move the phrase iterator to point to the next matching docid.
** If an error occurs, return an SQLite error code. Otherwise, return
** SQLITE_OK.
**
** If there is no "next" entry and no error occurs, then *pbEof is set to
** 1 before returning. Otherwise, if no error occurs and the iterator is
** successfully advanced, *pbEof is set to 0.
Assume 32-bit assignment is atomic
** Each thread may only have a single outstanding allocation from
** xScratchMalloc(). We verify this constraint in the single-threaded
** case by setting scratchAllocOut to 1 when an allocation
** is outstanding clearing it when the allocation is freed.
327
xRelease
** Search the wal file for page pgno. If found, set *piRead to the frame that
** contains the page. Otherwise, if pgno is not in the wal file, set *piRead
** to zero.
**
** Return SQLITE_OK if successful, or an error code if an error occurs. If an
** error does occur, the final value of *piRead is undefined.
xCurrentTime
Column number within the source table
"ORDER" or "GROUP"
** 2001-09-15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs. If a C-function, structure, datatype,
** or constant definition does not appear in this file, then it is
** not a published API of SQLite, is subject to change without
** notice, and should not be referenced by programs that use SQLite.
**
** Some of the definitions that are in this file are marked as
** "experimental". Experimental interfaces are normally new
** features recently added to SQLite. We do not anticipate changes
** to experimental interfaces but reserve the right to make minor changes
** if experience from use "in the wild" suggest such changes are prudent.
**
** The official C-language API documentation for SQLite is derived
** from comments in this file. This file is the authoritative source
** on how SQLite interfaces are supposed to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
dbnm ::=
2x
from ::=
#ifndef SQLITE_UNTESTABLE
** This function invokes either the xRollback or xCommit method
** of each of the virtual tables in the sqlite3.aVTrans array. The method
** called is identified by the second argument, "offset", which is
** the offset of the method to call in the sqlite3_module structure.
**
** The array is cleared after invoking the callbacks.
** Query the database. But instead of invoking a callback for each row,
** malloc() for space to hold the result and return the entire results
** at the conclusion of the call.
**
** The result that is written to ***pazResult is held in memory obtained
** from malloc(). But the caller cannot free this memory directly.
** Instead, the entire table should be passed to sqlite3_free_table() when
** the calling procedure is finished using it.
** The following code executes when a syntax error first occurs.
** Close a file that uses proxy locks.
** Btree.inTrans may take one of the following values.
**
** If the shared-data extension is enabled, there may be multiple users
** of the Btree structure. At most one of these may open a write transaction,
** but any number may have active read transactions.
OUT: Ending offset of token
Phrase to append to
Number of columns in the recursive table
NULLs can be safely trimmed from the end of the record, as long as
** as the schema format is 2 or more and none of the omitted columns
** have a non-NULL default value. Also, the record must be left with
** at least one field. If P5>0 then it will be one more than the
** index of the right-most column with a non-NULL default value
Return code from service routines
A single term of the WHERE clause
Initial static space
OUTPUT: Declared data type
280
comment: If using the content=xxx option, assume the table is never empty
label: code-design
** Formulate and prepare an INSERT statement to add a record to table zTab.
** For example:
**
** INSERT INTO main."zTab" VALUES(?1, ?2, ?3 ...);
**
** If successful, SQLITE_OK is returned and SessionApplyCtx.pInsert is left
** pointing to the prepared version of the SQL statement.
Array of primary key flags
Add an entry in sqlite_master for this index
False to omit journal
Restrict matches to this column
Def. collation for column
For tracing reduce actions, the names of all rules are required.
If there are no more entries in the doclist, set pOffsetList to
** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
** Fts3SegReader.pOffsetList to point to the next offset list before
** returning.
Used to divy up the pSpace memory
30
Text of the token. Not NULL-terminated!
Set the cursor upper and lower rowid limits. Only some strategies
** actually use them. This is ok, as the xBestIndex() method leaves the
** sqlite3_index_constraint.omit flag clear for range constraints
** on the rowid field.
UTF-16 Big-endian -> UTF-8
118
ifndef _SQLITE3RTREE_H_
Return the value of a column
** Allocate a KeyInfo object sufficient for an index of N key columns and
** X extra columns.
(278) trans_opt ::=
Compare this many columns
Counter for apVal[]
comment:
** Make sure the page is marked as clean. If it isn't clean already,
** make it so.
label: code-design
OUT: Malloced result buffer
The commit flag. Usually 0. >0 for commit
DETACH => ID
Discard the candidate path from further consideration
************* End of os.h *************************************************
Expression to be appended. Might be NULL
comment: TODO: Check there is no doclist index
label: requirement
Cursor of table holding data.
True if in a write transaction
Pointer to child node
comment:
** Return a human-readable name for a constraint resolution action.
label: code-design
** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
** The HH, MM, and SS must each be exactly 2 digits. The
** fractional seconds FFFF can be one or more digits.
**
** Return 1 if there is a parsing error and 0 on success.
** Load the content from either the sqlite_stat4 or sqlite_stat3 table
** into the relevant Index.aSample[] arrays.
**
** Arguments zSql1 and zSql2 must point to SQL statements that return
** data equivalent to the following (statements are different for stat3,
** see the caller of this function for details):
**
** zSql1: SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx
** zSql2: SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4
**
** where %Q is replaced with the database name before the SQL is executed.
** This function is similar to sqlite3BtreeGetReserve(), except that it
** may only be called if it is guaranteed that the b-tree mutex is already
** held.
**
** This is useful in one special case in the backup API code where it is
** known that the shared b-tree mutex is held, but the mutex on the
** database handle that owns *p is not. In this case if sqlite3BtreeEnter()
** were to be called, it might collide with some other operation on the
** database handle that owns *p, causing undefined behavior.
Resolve the column names in the WHERE clause.
Add TK_IF_NULL_ROW opcodes on each replacement
comment: Suppress warning about unused %extra_argument var
label: code-design
Generate the code to do the search. Each iteration of the for
** loop below generates code for a single nested loop of the VM
** program.
** Release all of the apPage[] pages for a cursor.
fts3_tokenizer.c
True if journal page is synced
Est number of iterations of a query (10*log2(N))
Advance the 'head' iterator of each phrase to the first offset that
** is greater than or equal to (iNext+nSnippet).
Block id of next free slot in %_segments
** This function is used to copy the contents of the b-tree node stored
** on page pFrom to page pTo. If page pFrom was not a leaf page, then
** the pointer-map entries for each child page are updated so that the
** parent page stored in the pointer map is page pTo. If pFrom contained
** any cells with overflow page pointers, then the corresponding pointer
** map entries are also updated so that the parent page is page pTo.
**
** If pFrom is currently carrying any overflow cells (entries in the
** MemPage.apOvfl[] array), they are not copied to pTo.
**
** Before returning, page pTo is reinitialized using btreeInitPage().
**
** The performance of this function is not critical. It is only used by
** the balance_shallower() and balance_deeper() procedures, neither of
** which are called often under normal circumstances.
True to truncate db on commit
One of UPDATE, DELETE, INSERT
True if remove_diacritics=1 is set
comment: OFFSET expression. NULL means not used.
label: code-design
Used to iterate through non-root layers
Bulk memory available for allocation
SQL text "PRAGMA %Q.page_size"
Mutex used by sqlite3_initialize()
Right outer join
A MATCH operator. The right-hand-side must be a blob that
** can be cast into an RtreeMatchArg object. One created using
** an sqlite3_rtree_geometry_callback() SQL user function.
*****************************************************************************
*************************** Begin NFS Locking *******************************
Now check that the iter.nEmpty leaves following the current leaf
** (a) exist and (b) contain no terms.
comment: Temporary buffer to use
label: code-design
Copy of pParse->pNewTable
OUT: Pointer to hash index
Write the path here
Nesting should only be of limited depth
Database page number to read data for
Scratch allocations
Verify that no lookaside memory was used by schema tables
** information about each column of an SQL table is held in an instance
** of this structure.
4x
A boolean value
Number of enterances
Index of column in table
** An instance of this structure can hold a simple list of identifiers,
** such as the list "a,b,c" in the following statements:
**
** INSERT INTO t(a,b,c) VALUES ...;
** CREATE INDEX idx ON t(a,b,c);
** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;
**
** The IdList.a.idx field is used when the IdList represents the list of
** column names after a table name in an INSERT statement. In the statement
**
** INSERT INTO t(a,b,c) ...
**
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
Next are the tables used to determine what action to take based on the
** current state and lookahead token. These tables are used to implement
** functions that take a state number and lookahead value and return an
** action integer.
**
** Suppose the action integer is N. Then the action is determined as
** follows
**
** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
** token onto the stack and goto state N.
**
** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
**
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
** and YY_MAX_REDUCE
**
** N == YY_ERROR_ACTION A syntax error has occurred.
**
** N == YY_ACCEPT_ACTION The parser accepts its input.
**
** N == YY_NO_ACTION No such action. Denotes unused
** slots in the yy_action[] table.
**
** The action table is constructed as a single large table named yy_action[].
** Given state S and lookahead X, the action is computed as either:
**
** (A) N = yy_action[ yy_shift_ofst[S] + X ]
** (B) N = yy_default[S]
**
** The (A) formula is preferred. The B formula is used instead if:
** (1) The yy_shift_ofst[S]+X value is out of range, or
** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
** Hence only tests (1) and (2) need to be evaluated.)
**
** The formulas above are for computing the action when the lookahead is
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
** a reduce action) then the yy_reduce_ofst[] array is used in place of
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
** YY_SHIFT_USE_DFLT.
**
** The following are the tables generated in this section:
**
** yy_action[] A single table containing all actions.
** yy_lookahead[] A table containing the lookahead for each entry in
** yy_action. Used to detect hash collisions.
** yy_shift_ofst[] For each state, the offset into yy_action for
** shifting terminals.
** yy_reduce_ofst[] For each state, the offset into yy_action for
** shifting non-terminals after a reduce.
** yy_default[] Default action for each state.
**
*********** Begin parsing tables *********************************************
** Advance the iterator passed as the second argument until it is at or
** past rowid iFrom. Regardless of the value of iFrom, the iterator is
** always advanced at least once.
Checksum based on %_content contents
If the TERM_LIKECOND flag is set, that means that the range search
** is sufficient to guarantee that the LIKE operator is true, so we
** can skip the call to the like(A,B) function. But this only works
** for strings. So do not skip the call to the function on the pass
** that compares BLOBs.
Opcode: Eq P1 P2 P3 P4 P5
** Synopsis: IF r[P3]==r[P1]
**
** Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
** jump to address P2. Or if the SQLITE_STOREP2 flag is set in P5, then
** store the result of comparison in register P2.
**
** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
** to coerce both inputs according to this affinity before the
** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
** affinity is used. Note that the affinity conversions are stored
** back into the input registers P1 and P3. So this opcode can cause
** persistent changes to registers P1 and P3.
**
** Once any conversions have taken place, and neither value is NULL,
** the values are compared. If both values are blobs then memcmp() is
** used to determine the results of the comparison. If both values
** are text, then the appropriate collating function specified in
** P4 is used to do the comparison. If P4 is not specified then
** memcmp() is used to compare text string. If both values are
** numeric, then a numeric comparison is used. If the two values
** are of different types, then numbers are considered less than
** strings and strings are considered less than blobs.
**
** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
** true or false and is never NULL. If both operands are NULL then the result
** of comparison is true. If either operand is NULL then the result is false.
** If neither operand is NULL the result is the same as it would be if
** the SQLITE_NULLEQ flag were omitted from P5.
**
** If both SQLITE_STOREP2 and SQLITE_KEEPNULL flags are set then the
** content of r[P2] is only changed if the new value is NULL or 0 (false).
** In other words, a prior r[P2] value will not be overwritten by 1 (true).
** Initialize a PMA-writer object.
Required mapping size
First field to be combined into the record
Buffer to hold apValue/zTab/abPK/
** Free an allocated buffer obtained from sqlite3PageMalloc().
Object to populate
************* End of fts3.c ***********************************************
Character iIn was the close quote.
Leave STATIC_MASTER mutex
Array of term hash entries to scan
** End of interface to code in fts5_hash.c.
*************************************************************************
Array of page numbers.
First search for an existing entry. If one is found, this call is
** a no-op. Return early.
Different conflict resolution strategies
The new trigger
OP_Open** cursor uses EQ seek only
** Return the size of an outstanding allocation, in bytes.
A region of shared-memory
This call is to merge all segments in the database to a single
** segment. The level of the new segment is equal to the numerically
** greatest segment level currently present in the database for this
** index. The idx of the new segment is always 0.
"main" is always an acceptable alias for the primary database
** even if it has been renamed using SQLITE_DBCONFIG_MAINDBNAME.
If the first integer value is followed by a ',', read the second
** integer value.
nul-terminated term
Database header content
50
** The phrase iterator passed as the second argument:
**
** * features at least one token that uses an incremental doclist, and
**
** * does not contain any deferred tokens.
**
** Advance it to the next matching documnent in the database and populate
** the Fts3Doclist.pList and nList fields.
**
** If there is no "next" entry and no error occurs, then *pbEof is set to
** 1 before returning. Otherwise, if no error occurs and the iterator is
** successfully advanced, *pbEof is set to 0.
**
** If an error occurs, return an SQLite error code. Otherwise, return
** SQLITE_OK.
Name of collating sequence
Field in (?,?,?) IN (SELECT...) vector
** Append the current term and doclist pointed to by cursor pCsr to the
** appendable b-tree segment opened for writing by pWriter.
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise.
Number of output leaves just written
Buffer containing old.* record
comment: FTS5_DETAIL_XXX value
label: code-design
Pcache object page handle
39
Set appropriate defaults on all indexes not in the sqlite_stat1 table
If the path starts with a drive letter followed by the colon
** character, assume it is already a native Win32 path; otherwise,
** it must be converted to a native Win32 path via the Cygwin API
** prior to using it.
4x the size of current chunk in Mem3Block elements
** Generate code that evaluates the given expression and puts the result
** in register target.
**
** Also make a copy of the expression results into another "cache" register
** and modify the expression so that the next time it is evaluated,
** the result is a copy of the cache register.
**
** This routine is used for expressions that are used multiple
** times. They are evaluated once and the results of the expression
** are reused.
Size of token in bytes
nOut before IN() and WHERE adjustments
Level of segments to scan
Nothing to do
Number of fields in PRIMARY KEY. 1 for ROWID tables
** CAPI3REF: Result Codes
** KEYWORDS: {result code definitions}
**
** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure.
**
** New error codes may be added in future versions of SQLite.
**
** See also: [extended result code definitions]
comment:
** The following routines are convenience wrappers around methods
** of the sqlite3_file object. This is mostly just syntactic sugar. All
** of this would be completely automatic if SQLite were coded using
** C++ instead of plain old C.
label: code-design
Check if any parent key columns are being modified.
** This type is used as an fts3ExprIterate() context object while
** accumulating the data returned by the matchinfo() function.
Event counters from parent frame
Saved xAuth pointer
64-bit only if requested at compile-time
ifndef SQLITE_OMIT_INCRBLOB
Sign-extend on a right shift of a negative number
OUT: Unique index on parent table
** CAPI3REF: Mutex Verification Routines
**
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
** are intended for use inside assert() statements. The SQLite core
** never uses these routines except inside an assert() and applications
** are advised to follow the lead of the core. The SQLite core only
** provides implementations for these routines when it is compiled
** with the SQLITE_DEBUG flag. External mutex implementations
** are only required to provide these routines if SQLITE_DEBUG is
** defined and if NDEBUG is not defined.
**
** These routines should return true if the mutex in their argument
** is held or not held, respectively, by the calling thread.
**
** The implementation is not required to provide versions of these
** routines that actually work. If the implementation does not provide working
** versions of these routines, it should at least provide stubs that always
** return true so that one does not get spurious assertion failures.
**
** If the argument to sqlite3_mutex_held() is a NULL pointer then
** the routine should return 1. This seems counter-intuitive since
** clearly the mutex cannot be held if it does not exist. But
** the reason the mutex does not exist is because the build is not
** using mutexes. And we do not want the assert() containing the
** call to sqlite3_mutex_held() to fail, so a non-zero return is
** the appropriate thing to do. The sqlite3_mutex_notheld()
** interface should also return 1 when given a NULL pointer.
A SELECT statement to use as the data source
Size limit for persistent journal files
** Added for 3.7.4
Array of first token in each sentence
Cursor of the canonical data source
181
** Locate and return an entry from the db.aCollSeq hash table. If the entry
** specified by zName and nName is not found and parameter 'create' is
** true, then create a new entry. Otherwise return NULL.
**
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
** array of three CollSeq structures. The first is the collation sequence
** preferred for UTF-8, the second UTF-16le, and the third UTF-16be.
**
** Stored immediately after the three collation sequences is a copy of
** the collation sequence name. A pointer to this string is stored in
** each collation sequence structure.
A no-op destructor
iVersion
Otherwise, flush the current node of layer iLayer to disk.
** Then allocate a new, empty sibling node. The key will be written
** into the parent of this node.
Begin scanning through hash table entries. This loop runs once for each
** term/doclist currently stored within the hash table.
Do nothing if table already exists
Clear all content from pragma virtual table cursor.
jumps if either operand is NULL
** Manage pPage's participation on the dirty list. Bits of the addRemove
** argument determines what operation to do. The 0x01 bit means first
** remove pPage from the dirty list. The 0x02 means add pPage back to
** the dirty list. Doing both moves pPage to the front of the dirty list.
Raw numeric value stored in s
EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
** option takes a single integer argument which is interpreted as a
** boolean in order to enable or disable the use of covering indices for
** full table scans in the query optimizer.
The vector. List of expressions or a sub-SELECT
** Take actions at the end of an API call to indicate an OOM error
** Advance to the next element in the sorter. Return value:
**
** SQLITE_OK success
** SQLITE_DONE end of data
** otherwise some kind of error.
Invoke AFTER DELETE trigger programs.
Back pointer of the same list
This branch causes a *balanced* tree to be generated. A valid tree
** is still generated without this branch, but the tree is wildly
** unbalanced and inefficient.
Mark off any ORDER BY term X that is a column in the table of
** the current loop for which there is term in the WHERE
** clause of the form X IS NULL or X=? that reference only outer
** loops.
comment: Read the next journal header from the journal file. If there are
** not enough bytes left in the journal file for a complete header, or
** it is corrupted, then a process must have failed while writing it.
** This indicates nothing more needs to be rolled back.
label: code-design
Enter STATIC_MASTER mutex
Generate a subroutine that outputs the current row of the A
** select as the next output row of the compound select.
comment: An unused file descriptor
label: code-design
comment:
** chngToIN holds a set of tables that *might* satisfy case 1. But
** we have to do some additional checking to see if case 1 really
** is satisfied.
**
** chngToIN will hold either 0, 1, or 2 bits. The 0-bit case means
** that there is no possibility of transforming the OR clause into an
** IN operator because one or more terms in the OR clause contain
** something other than == on a column in the single table. The 1-bit
** case means that every term of the OR clause is of the form
** "table.column=expr" for some single table. The one bit that is set
** will correspond to the common table. We still need to check to make
** sure the same column is used on all terms. The 2-bit case is when
** the all terms are of the form "table1.column=table2.column". It
** might be possible to form an IN operator with either table1.column
** or table2.column as the LHS if either is common to every term of
** the OR clause.
**
** Note that terms of the form "table.column1=table.column2" (the
** same table on both sizes of the ==) cannot be optimized.
label: code-design
An expression being tested
True for native byte-order, false for non-native
INT
Allocate any page
** Record the fact that an affinity change has occurred on iCount
** registers starting with iStart.
Pages in wal - keys for the sort
It may be that this trigger has already been coded (or is in the
** process of being coded). If this is the case, then an entry with
** a matching TriggerPrg.pTrigger field will be present somewhere
** in the Parse.pTriggerPrg list. Search for such an entry.
Register holding previous generated key
True to inhibit all file I/O
** Close an open database and invalidate all cursors.
** Try to obtain a lock of type locktype on the database file. If
** a similar or greater lock is already held, this function is a no-op
** (returning SQLITE_OK immediately).
**
** Otherwise, attempt to obtain the lock using sqlite3OsLock(). Invoke
** the busy callback if the lock is currently not available. Repeat
** until the busy callback returns false or until the attempt to
** obtain the lock succeeds.
**
** Return SQLITE_OK on success and an error code if we cannot obtain
** the lock. If the lock is obtained successfully, set the Pager.state
** variable to locktype before returning.
It is an error to call this function if the page is already
** part of the PGroup LRU list.
This branch loads the value of a column that will not be changed
** into a register. This is done if there are no BEFORE triggers, or
** if there are one or more BEFORE triggers that use this value via
** a new.* reference in a trigger program.
comment:
** hwtime.h contains inline assembler code for implementing
** high-performance timing routines.
label: code-design
Bytes of content, or number of sub-nodes
One entry for each of nCol columns
205
The name of the trigger
Invalidate all prepared statements whenever the TEMP database
** schema is changed. Ticket #1644
** Delete any previous value and set the value of pMem to be an
** empty boolean index.
Figure out how much space is required for each journal file-handle
** (there are two of them, the main journal and the sub-journal).
For leaf pages, the min-heap has already been initialized and the
** cells have already been inserted. But for internal pages, that has
** not yet been done, so do it now
** Commit the transaction currently in progress.
**
** This routine implements the second phase of a 2-phase commit. The
** sqlite3BtreeCommitPhaseOne() routine does the first phase and should
** be invoked prior to calling this routine. The sqlite3BtreeCommitPhaseOne()
** routine did all the work of writing information out to disk and flushing the
** contents so that they are written onto the disk platter. All this
** routine has to do is delete or truncate or zero the header in the
** the rollback journal (which causes the transaction to commit) and
** drop locks.
**
** Normally, if an error occurs while the pager layer is attempting to
** finalize the underlying journal file, this function returns an error and
** the upper layer will attempt a rollback. However, if the second argument
** is non-zero then this b-tree transaction is part of a multi-file
** transaction. In this case, the transaction has already been committed
** (by deleting a master journal file) and the caller will ignore this
** functions return code. So, even if an error occurs in the pager layer,
** reset the b-tree objects internal state to indicate that the write
** transaction has been closed. This is quite safe, as the pager will have
** transitioned to the error state.
**
** This will release the write lock on the database file. If there
** are no active cursors, it also releases the read lock.
0
"INSERT ... %_idx VALUES(?,?,?,?)"
Delete shared-memory if true
EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
** Serialized.
The new table
** Perhaps the name is a reference to the ROWID
Mask of tokens to highlight in snippet
** This function is called to generate code that runs when table pTab is
** being dropped from the database. The SrcList passed as the second argument
** to this function contains a single entry guaranteed to resolve to
** table pTab.
**
** Normally, no code is required. However, if either
**
** (a) The table is the parent table of a FK constraint, or
** (b) The table is the child table of a deferred FK constraint and it is
** determined at runtime that there are outstanding deferred FK
** constraint violations in the database,
**
** then the equivalent of "DELETE FROM <tbl>" is executed before dropping
** the table from the database. Triggers are disabled while running this
** DELETE, but foreign key actions are not.
colsetlist
comment: These look like magic numbers. But they are stable, as they are part
** of the definition of the SQLite file format, which may not change.
label: code-design
same as TK_PLUS, in1, in2, out3
Opcode: Move P1 P2 P3 * *
** Synopsis: r[P2@P3]=r[P1@P3]
**
** Move the P3 values in register P1..P1+P3-1 over into
** registers P2..P2+P3-1. Registers P1..P1+P3-1 are
** left holding a NULL. It is an error for register ranges
** P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
** for P3 to be less than 1.
** xSetOutputs callback used by detail=col when there is a column filter
** and there are 100 or more columns. Also called as a fallback from
** fts5IterSetOutputs_Col100 if the column-list spans more than one page.
** The argument is the first in a linked list of dirty pages connected
** by the PgHdr.pDirty pointer. This function writes each one of the
** in-memory pages in the list to the database file. The argument may
** be NULL, representing an empty list. In this case this function is
** a no-op.
**
** The pager must hold at least a RESERVED lock when this function
** is called. Before writing anything to the database file, this lock
** is upgraded to an EXCLUSIVE lock. If the lock cannot be obtained,
** SQLITE_BUSY is returned and no data is written to the database file.
**
** If the pager is a temp-file pager and the actual file-system file
** is not yet open, it is created and opened before any data is
** written out.
**
** Once the lock has been upgraded and, if necessary, the file opened,
** the pages are written out to the database file in list order. Writing
** a page is skipped if it meets either of the following criteria:
**
** * The page number is greater than Pager.dbSize, or
** * The PGHDR_DONT_WRITE flag is set on the page.
**
** If writing out a page causes the database file to grow, Pager.dbFileSize
** is updated accordingly. If page 1 is written out, then the value cached
** in Pager.dbFileVers[] is updated to match the new value stored in
** the database file.
**
** If everything is successful, SQLITE_OK is returned. If an IO error
** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
** be obtained, SQLITE_BUSY is returned.
DELETE
xClose
The collation sequence must be defined at this point, even if
** the user deletes the collation sequence after the vdbe program is
** compiled (this was not always the case).
OUT: Pointer to current position-list
True to count changes
OUT: Map of index columns in pFKey
Search the rowid of the table
comment:
** All individual term iterators in pNear are guaranteed to be valid when
** this function is called. This function checks if all term iterators
** point to the same rowid, and if not, advances them until they do.
** If an EOF is reached before this happens, *pbEof is set to true before
** returning.
**
** SQLITE_OK is returned if an error occurs, or an SQLite error code
** otherwise. It is not considered an error code if an iterator reaches
** EOF.
label: code-design
EACH => ID
Address of opcode that determines the IN is true
If the temp database has been explicitly named as part of the
** pragma, make sure it is open.
** The maximum number of opcodes in a VDBE program.
** Not currently enforced.
WHERE clause on PK columns
Compensate for pPager->iDataVersion++;
Copy of pStr1 - RHS of LIKE/GLOB operator
Generate code that executes if the new index entry is not unique
Skip leading zeros.
Pointer to a new child page
If the user has configured a chunk-size for this file, truncate the
** file so that it consists of an integer number of chunks (i.e. the
** actual file size after the operation may be larger than the requested
** size).
Total number of I/O Errors
IGNORE => ID
Object to return
Create an Expr object representing an SQL expression like:
**
** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
**
** The collation sequence used for the comparison should be that of
** the parent key columns. The affinity of the parent key column should
** be applied to each child key value before the comparison takes place.
Result written here
** Return the page number associated with frame iFrame in this WAL.
** This is called when the database connection passed as an argument is
** being closed. The connection is removed from the blocked list.
The point is to increment the last character before the first
** wildcard. But if we increment '@', that will push it into the
** alphabetic range where case conversions will mess up the
** inequality. To avoid this, make sure to also run the full
** LIKE on all candidate expressions by clearing the isComplete flag
Remove trailing zeros and the "." if no digits follow the "."
Mask of events to be traced
Current lock held on database file
__QNXNTO__
Insert on a main table b-tree
** CAPI3REF: Obtaining SQL Values
** METHOD: sqlite3_value
**
** <b>Summary:</b>
** <blockquote><table border=0 cellpadding=0 cellspacing=0>
** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value
** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value
** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value
** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value
** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value
** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value
** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in
** the native byteorder
** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value
** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value
** <tr><td> <td> <td>
** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB
** or a UTF-8 TEXT in bytes
** <tr><td><b>sqlite3_value_bytes16 </b>
** <td>→ <td>Size of UTF-16
** TEXT in bytes
** <tr><td><b>sqlite3_value_type</b><td>→<td>Default
** datatype of the value
** <tr><td><b>sqlite3_value_numeric_type </b>
** <td>→ <td>Best numeric datatype of the value
** </table></blockquote>
**
** <b>Details:</b>
**
** These routines extract type, size, and content information from
** [protected sqlite3_value] objects. Protected sqlite3_value objects
** are used to pass parameter information into implementation of
** [application-defined SQL functions] and [virtual tables].
**
** These routines work only with [protected sqlite3_value] objects.
** Any attempt to use these routines on an [unprotected sqlite3_value]
** is not threadsafe.
**
** ^These routines work just like the corresponding [column access functions]
** except that these routines take a single [protected sqlite3_value] object
** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
**
** ^The sqlite3_value_text16() interface extracts a UTF-16 string
** in the native byte-order of the host machine. ^The
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
** extract UTF-16 strings as big-endian and little-endian respectively.
**
** ^If [sqlite3_value] object V was initialized
** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
** and if X and Y are strings that compare equal according to strcmp(X,Y),
** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
**
** ^(The sqlite3_value_type(V) interface returns the
** [SQLITE_INTEGER | datatype code] for the initial datatype of the
** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
** Other interfaces might change the datatype for an sqlite3_value object.
** For example, if the datatype is initially SQLITE_INTEGER and
** sqlite3_value_text(V) is called to extract a text value for that
** integer, then subsequent calls to sqlite3_value_type(V) might return
** SQLITE_TEXT. Whether or not a persistent internal datatype conversion
** occurs is undefined and may change from one release of SQLite to the next.
**
** ^(The sqlite3_value_numeric_type() interface attempts to apply
** numeric affinity to the value. This means that an attempt is
** made to convert the value to an integer or floating point. If
** such a conversion is possible without loss of information (in other
** words, if the value is a string that looks like a number)
** then the conversion is performed. Otherwise no conversion occurs.
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
**
** Please pay particular attention to the fact that the pointer returned
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
** or [sqlite3_value_text16()].
**
** These routines must be called from the same thread as
** the SQL function that supplied the [sqlite3_value*] parameters.
Number of cells
** Close an RBU handle.
**
** If the RBU update has been completely applied, mark the RBU database
** as fully applied. Otherwise, assuming no error has occurred, save the
** current state of the RBU update appliation to the RBU database.
**
** If an error has already occurred as part of an sqlite3rbu_step()
** or sqlite3rbu_open() call, or if one occurs within this function, an
** SQLite error code is returned. Additionally, if pzErrmsg is not NULL,
** *pzErrmsg may be set to point to a buffer containing a utf-8 formatted
** English language error message. It is the responsibility of the caller to
** eventually free any such buffer using sqlite3_free().
**
** Otherwise, if no error occurs, this function returns SQLITE_OK if the
** update has been partially applied, or SQLITE_DONE if it has been
** completely applied.
** An array of names of all compile-time options. This array should
** be sorted A-Z.
**
** This array looks large, but in a typical installation actually uses
** only a handful of compile-time options, so most times this array is usually
** rather short and uses little memory space.
Number of fields in the table or index
Unpacked version of new.* record
LIKE_KW => ID
Jump here to exit loop
Single VALUES term with multiple rows
Changes whenever database content changes
Size of vectors for this IN operator
0x16
Output string - not real JSON
** Calling this function indicates that subsequent calls to
** fts3PendingTermsAdd() are to add term/position-list pairs for the
** contents of the document with docid iDocid.
If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL.
xFunc, void*
EVIDENCE-OF: R-19854-42126 There are three arguments to
** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
** number of bytes in the memory buffer, and the minimum allocation size.
** This routine takes the module argument that has been accumulating
** in pParse->zArg[] and appends it to the list of arguments on the
** virtual table currently under construction in pParse->pTable.
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
Index into mem5.aiFreelist[]
Value to bind
Append the position lists
Above requires no mutex. Use mutex below for variable that follow.
** Convert a DbPage obtained from the pager into a MemPage used by
** the btree layer.
True if we are at the end of input
Estimated rows returned by this scan
Cannot start a write transaction without first holding a read
** transaction.
Cursor used to scan change record
Function name (nul-terminated)
Table columns
** This function returns a pointer to a nul-terminated string in memory
** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the
** string contains a copy of zRawSql but with host parameters expanded to
** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1,
** then the returned string holds a copy of zRawSql with "-- " prepended
** to each line of text.
**
** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then
** then long strings and blobs are truncated to that many bytes. This
** can be used to prevent unreasonably large trace strings when dealing
** with large (multi-megabyte) strings and blobs.
**
** The calling function is responsible for making sure the memory returned
** is eventually freed.
**
** ALGORITHM: Scan the input string looking for host parameters in any of
** these forms: ?, ?N, $A, @A, :A. Take care to avoid text within
** string literals, quoted identifier names, and comments. For text forms,
** the host parameter index is found by scanning the prepared
** statement for the corresponding OP_Variable opcode. Once the host
** parameter index is known, locate the value in p->aVar[]. Then render
** the value as a literal in place of the host parameter name.
Rowid in main table of the key
If the RHS begins with a digit or a minus sign, then the LHS must
** be an ordinary column (not a virtual table column) with TEXT affinity.
** Otherwise the LHS might be numeric and "lhs >= rhs" would be false
** even though "lhs LIKE rhs" is true. But if the RHS does not start
** with a digit or '-', then "lhs LIKE rhs" will always be false if
** the LHS is numeric and so the optimization still works.
** Free memory.
**
** The outer layer memory allocator prevents this routine from
** being called with pPrior==0.
** Set the "use-threads" flag on object pIncr.
ALTER
The escape char (LIKE) or '[' (GLOB)
Pointer to buffer containing string
Attempt to write a readonly database
_PCACHE_H_
Page to edit
If unable to open an sqlite3_blob on the desired row, that can only
** be because the shadow tables hold erroneous data.
Handle that must hold lock
Mask of TRIGGER_BEFORE|TRIGGER_AFTER
************* End of btreeInt.h *******************************************
Forward Declarations
True for json_tree(). False for json_each()
comment:
** The fts3BestSnippet() function often selects snippets that end with a
** query term. That is, the final term of the snippet is always a term
** that requires highlighting. For example, if 'X' is a highlighted term
** and '.' is a non-highlighted term, BestSnippet() may select:
**
** ........X.....X
**
** This function "shifts" the beginning of the snippet forward in the
** document so that there are approximately the same number of
** non-highlighted terms to the right of the final highlighted term as there
** are to the left of the first highlighted term. For example, to this:
**
** ....X.....X....
**
** This is done as part of extracting the snippet text, not when selecting
** the snippet. Snippet selection is done based on doclists only, so there
** is no way for fts3BestSnippet() to know whether or not the document
** actually contains terms that follow the final highlighted term.
label: documentation
SQLITE_STATUS_PAGECACHE_USED
Cache zFilename in the locking context (AFP and dotlock override) for
** proxyLock activation is possible (remote proxy is based on db name)
** zFilename remains valid until file is closed, to support
Write-ahead log connection
content=? parameter (or NULL)
The proposed effective sample is a prefix of sample aSample[iSamp].
** Specifically, the shortest prefix of at least (1 + iTest%nField)
** fields that is greater than the previous effective sample.
Mem address which causes query abort if positive
Copy entry from i1
Data associated with this element
comment: A complete hash table is an instance of the following structure.
** The internals of this structure are intended to be opaque -- client
** code should not attempt to access or modify the fields of this structure
** directly. Change this structure only by using the routines below.
** However, many of the "procedures" and "functions" for modifying and
** accessing this structure are really macros, so we can't really make
** this structure opaque.
label: code-design
Add all table columns to the PRIMARY KEY index
** Cancel a prior call to sqlite3_auto_extension. Remove xInit from the
** set of routines that is invoked for each new database connection, if it
** is currently on the list. If xInit is not on the list, then this
** routine is a no-op.
**
** Return 1 if xInit was found on the list and removed. Return 0 if xInit
** was not on the list.
Value to associate with zName
Address of regReturn init
** This function is used to help iterate through a position-list. A position
** list is a list of unique integers, sorted from smallest to largest. Each
** element of the list is represented by an FTS3 varint that takes the value
** of the difference between the current element and the previous one plus
** two. For example, to store the position-list:
**
** 4 9 113
**
** the three varints:
**
** 6 7 106
**
** are encoded.
**
** When this function is called, *pp points to the start of an element of
** the list. *piPos contains the value of the previous entry in the list.
** After it returns, *piPos contains the value of the next element of the
** list and *pp is advanced to the following varint.
True for 'notindexed' columns
2 -> COMPRESS
The constraint to test
First search the list for an existing lock on this table.
Number of columns in index
comment: Which level of pWInfo->a[] should be coded
label: code-design
synopsis: r[P3]=mkrec(r[P1@P2])
Ignore tables with no primary keys
Drop the WAL write-lock, if any. Also, if the connection was in
** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
** lock held on the database file.
** An in-memory list of objects to be sorted.
**
** If aMemory==0 then each object is allocated separately and the objects
** are connected using SorterRecord.u.pNext. If aMemory!=0 then all objects
** are stored in the aMemory[] bulk memory, one right after the other, and
** are connected using SorterRecord.u.iNext.
Number of slots of aNode[] used
Existing WITH clause, or NULL
<rdar://problem/6778339>
comment: ONEPASS_XXX value from where.c
label: code-design
EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
** single argument which is a pointer to an instance of the
** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
** filled with the currently defined memory allocation routines.
(<tbl> MATCH ?)
Size of buffer zNext in bytes
Done with the mutex
Flags that may be passed by the tokenizer implementation back to FTS5
** as the third argument to the supplied xToken callback.
Largest iWalFrame value in aFrame[]
** Close a file. Make sure the lock has been released before closing.
OUT: Set to point to affinity string
The Pager.sectorSize variable may have been updated while rolling
** back a journal created by a process with a different sector size
** value. Reset it to the correct value for this process.
** Return permyriadage progress indications for the two main stages of
** an RBU update.
Used to iterate through instances
See note about index shifting on OP_ReadCookie
43
Number of bytes written
85
The database schema changed
defined(SQLITE_TEST)
IN/OUT: Elements in *paRight
Do not lock (except in WAL mode)
** Given a SELECT statement, generate a Table structure that describes
** the result set of that SELECT.
Configuration cookie
** The ctype.h header is needed for non-ASCII systems. It is also
** needed by FTS3 when FTS3 is included in the amalgamation.
pPage and up to NB siblings after balancing
Collation and sort-order information
Step 1: Search the hash table for an existing entry.
Read the page number and page data from the journal or sub-journal
** file. Return an error code to the caller if an IO error occurs.
Pointer to phrase expression
Zero the newly allocated slots
** Allowed values for winFile.ctrlFlags
Size of log file
ncell
comment: F: Old-style sqlite3_rtree_geometry_callback()
label: code-design
No aggregate functions and no GROUP BY clause
Value of 'mx_payload' column
1 -> PREFIX
Used to loop through terms
IMP: R-47871-25994
Probability of truth for this expression
For a virtual table, or a table with no primary key, the
** SELECT statement is:
**
** SELECT <cols>, rbu_control, rbu_rowid FROM ....
**
** Hence column_value(pIter->nCol+1).
Fill in this structure
Use of ONEPASS not allowed
SQLITE_SOUNDEX
*************************************************************************
** Interface to code in fts5_storage.c. fts5_storage.c contains contains
** code to access the data stored in the %_content and %_docsize tables.
The specific ORDER BY term
Copy data from this buffer to the file
Ran out of input before finding an opening bracket. Return NULL.
The columns of the result set
SQLITE_PAGER_H
isMallocInit
** A connection to a fulltext index is an instance of the following
** structure. The xCreate and xConnect methods create an instance
** of this structure and xDestroy and xDisconnect free that instance.
** All other methods receive a pointer to the structure as one of their
** arguments.
Number of args (always 2)
Address of OP_OpenEphemeral
Code the OP_Affinity opcode if there is anything left to do.
FTS5_STRING, AND, OR or NOT
Decrement the free-list count by 1. Set iTrunk to the index of the
** first free-list trunk page. iPrevTrunk is initially 1.
OP_MaxPgcnt enforces this
Number of full pages written to DB
Return the page in this parameter
synopsis: fkctr[P1]+=P2
Write result boolean here
New db size (or 0 for non-commit frames)
got the lock, unlock it
One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT
Current WITH clause, or NULL
name of the database file
True if no such function exists
comment:
** Malloc function used within this file to allocate space from the buffer
** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no
** such buffer exists or there is no space left in it, this function falls
** back to sqlite3Malloc().
**
** Multiple threads can run this routine at the same time. Global variables
** in pcache1 need to be protected via mutex.
label: code-design
Content of the row to be inserted
CASCADE
Names of result columns
** Disconnect from or destroy a statvfs virtual table.
** Return TRUE if the mask of type in eType matches the type of the
** allocation p. Also return true if p==NULL.
**
** This routine is designed for use within an assert() statement, to
** verify the type of an allocation. For example:
**
** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
** Read a 32-bit integer from the given file descriptor. Store the integer
** that is read in *pRes. Return SQLITE_OK if everything worked, or an
** error code is something goes wrong.
**
** All values are stored on disk as big-endian.
Value to return via *pnBind
defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
&& !defined(SQLITE_OMIT_SUBQUERY)
Create the expression "OLD.zToCol = zFromCol". It is important
** that the "OLD.zToCol" term is on the LHS of the = operator, so
** that the affinity and collation sequence associated with the
** parent table are used for the comparison.
Cost multiplier for using this table
1160
orderby_opt ::= ORDER BY sortlist
Breakup of pTerm into subterms
If the wal-index header is still malformed even while holding
** a WRITE lock, it can only mean that the header is corrupted and
** needs to be reconstructed. So run recovery to do exactly that.
State 0. In this state the integer just read was a docid.
** Parameter aData must point to a buffer of pPager->pageSize bytes
** of data. Compute and return a checksum based ont the contents of the
** page of data and the current value of pPager->cksumInit.
**
** This is not a real checksum. It is really just the sum of the
** random initial value (pPager->cksumInit) and every 200th byte
** of the page data, starting with byte offset (pPager->pageSize%200).
** Each byte is interpreted as an 8-bit unsigned integer.
**
** Changing the formula used to compute this checksum results in an
** incompatible journal file format.
**
** If journal corruption occurs due to a power failure, the most likely
** scenario is that one end or the other of the record will be changed.
** It is much less likely that the two ends of the journal record will be
** correct and the middle be corrupt. Thus, this "checksum" scheme,
** though fast and simple, catches the mostly likely kind of corruption.
Size of aInst[] array (entries / 3)
comment: Remove harmful bits from the flags parameter
**
** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
** dealt with in the previous code block. Besides these, the only
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
** off all other flags.
label: code-design
In order to be able to rollback, an in-memory database must journal
** the page we are moving from.
** Routines to read and write variable-length integers. These used to
** be defined locally, but now we use the varint routines in the util.c
** file.
Values between 268435456 and 34359738367
xRollback
** Open a database file.
**
** zFilename is the name of the database file. If zFilename is NULL
** then an ephemeral database is created. The ephemeral database might
** be exclusively in memory, or it might use a disk-based memory cache.
** Either way, the ephemeral database will be automatically deleted
** when sqlite3BtreeClose() is called.
**
** If zFilename is ":memory:" then an in-memory database is created
** that is automatically destroyed when it is closed.
**
** The "flags" parameter is a bitmask that might contain bits like
** BTREE_OMIT_JOURNAL and/or BTREE_MEMORY.
**
** If the database is already opened in the same database connection
** and we are in shared cache mode, then the open will fail with an
** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
** objects in the same database connection since doing so will lead
** to problems with locking.
OUT: Final number of frames in log
Array of mapped shared-memory regions
This branch is needed to avoid a (harmless) buffer overread. The
** special comment alerts the mutation tester that the correct answer
** is obtained even if the branch is omitted
One of the WhereLoop objects
** True for an RBU vacuum handle, or false otherwise.
comment: Number of unused bytes on the page
label: code-design
** Indicate that the accumulator load should be skipped on this
** iteration of the aggregate loop.
Do not defer seeks on main table
1 for 'tokenchars', 0 for 'separators'
Cursor assigned to each bit
Size of buffer aBuf
Actual size of mapping at pMapRegion
Iterator to read from
** Make a full copy of pFrom into pTo. Prior contents of pTo are
** freed before the copy is made.
** Sleep for a little while. Return the amount of time slept.
** The argument is the number of microseconds we want to sleep.
** The return value is the number of microseconds of sleep actually
** requested from the underlying operating system, a number which
** might be greater than or equal to the argument, but not less
** than the argument.
** Link the chunk at index i into either the appropriate
** small chunk list, or into the large chunk hash table.
Potential covering index (or NULL)
If not negative, use aCol[iPKey] as the rowid
comment: Advance to the next document
label: documentation
One element of this array for each open cursor
Sanity check: For a non-corrupt database file one of the follwing
** must be true:
** (1) We found one or more cells (cntNew[0])>0), or
** (2) pPage is a virtual root page. A virtual root page is when
** the real root page is page 1 and we are the only child of
** that page.
** Implementation of the printf() function.
Copy of 2nd argument to xTokenize()
Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).
** Restart interation for expression pExpr so that the next call to
** fts3EvalNext() visits the first row. Do not allow incremental
** loading or merging of phrase doclists for this iteration.
**
** If *pRc is other than SQLITE_OK when this function is called, it is
** a no-op. If an error occurs within this function, *pRc is set to an
** SQLite error code before returning.
Number of entries in apCsr
This is a pointer type. There may be a flag to indicate what to
** do with the pointer.
ccons ::= DEFAULT PLUS term
NATURAL
** The following routine destroys a virtual machine that is created by
** the sqlite3_compile() routine. The integer returned is an SQLITE_
** success/failure code that describes the result of executing the virtual
** machine.
**
** This routine sets the error code and string returned by
** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
index leaf
Mutex controlling the lock
** Query the size of the file in bytes.
The full-text index is stored in a series of b+tree (-like)
** structures called segments which map terms to doclists. The
** structures are like b+trees in layout, but are constructed from the
** bottom up in optimal fashion and are not updatable. Since trees
** are built from the bottom up, things will be described from the
** bottom up.
**
**
**** Varints ****
** The basic unit of encoding is a variable-length integer called a
** varint. We encode variable-length integers in little-endian order
** using seven bits * per byte as follows:
**
** KEY:
** A = 0xxxxxxx 7 bits of data and one flag bit
** B = 1xxxxxxx 7 bits of data and one flag bit
**
** 7 bits - A
** 14 bits - BA
** 21 bits - BBA
** and so on.
**
** This is similar in concept to how sqlite encodes "varints" but
** the encoding is not the same. SQLite varints are big-endian
** are are limited to 9 bytes in length whereas FTS3 varints are
** little-endian and can be up to 10 bytes in length (in theory).
**
** Example encodings:
**
** 1: 0x01
** 127: 0x7f
** 128: 0x81 0x00
**
**
**** Document lists ****
** A doclist (document list) holds a docid-sorted list of hits for a
** given term. Doclists hold docids and associated token positions.
** A docid is the unique integer identifier for a single document.
** A position is the index of a word within the document. The first
** word of the document has a position of 0.
**
** FTS3 used to optionally store character offsets using a compile-time
** option. But that functionality is no longer supported.
**
** A doclist is stored like this:
**
** array {
** varint docid; (delta from previous doclist)
** array { (position list for column 0)
** varint position; (2 more than the delta from previous position)
** }
** array {
** varint POS_COLUMN; (marks start of position list for new column)
** varint column; (index of new column)
** array {
** varint position; (2 more than the delta from previous position)
** }
** }
** varint POS_END; (marks end of positions for this document.
** }
**
** Here, array { X } means zero or more occurrences of X, adjacent in
** memory. A "position" is an index of a token in the token stream
** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
** in the same logical place as the position element, and act as sentinals
** ending a position list array. POS_END is 0. POS_COLUMN is 1.
** The positions numbers are not stored literally but rather as two more
** than the difference from the prior position, or the just the position plus
** 2 for the first position. Example:
**
** label: A B C D E F G H I J K
** value: 123 5 9 1 1 14 35 0 234 72 0
**
** The 123 value is the first docid. For column zero in this document
** there are two matches at positions 3 and 10 (5-2 and 9-2+3). The 1
** at D signals the start of a new column; the 1 at E indicates that the
** new column is column number 1. There are two positions at 12 and 45
** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
** 234 at I is the delta to next docid (357). It has one position 70
** (72-2) and then terminates with the 0 at K.
**
** A "position-list" is the list of positions for multiple columns for
** a single docid. A "column-list" is the set of positions for a single
** column. Hence, a position-list consists of one or more column-lists,
** a document record consists of a docid followed by a position-list and
** a doclist consists of one or more document records.
**
** A bare doclist omits the position information, becoming an
** array of varint-encoded docids.
**
**** Segment leaf nodes ****
** Segment leaf nodes store terms and doclists, ordered by term. Leaf
** nodes are written using LeafWriter, and read using LeafReader (to
** iterate through a single leaf node's data) and LeavesReader (to
** iterate through a segment's entire leaf layer). Leaf nodes have
** the format:
**
** varint iHeight; (height from leaf level, always 0)
** varint nTerm; (length of first term)
** char pTerm[nTerm]; (content of first term)
** varint nDoclist; (length of term's associated doclist)
** char pDoclist[nDoclist]; (content of doclist)
** array {
** (further terms are delta-encoded)
** varint nPrefix; (length of prefix shared with previous term)
** varint nSuffix; (length of unshared suffix)
** char pTermSuffix[nSuffix];(unshared suffix of next term)
** varint nDoclist; (length of term's associated doclist)
** char pDoclist[nDoclist]; (content of doclist)
** }
**
** Here, array { X } means zero or more occurrences of X, adjacent in
** memory.
**
** Leaf nodes are broken into blocks which are stored contiguously in
** the %_segments table in sorted order. This means that when the end
** of a node is reached, the next term is in the node with the next
** greater node id.
**
** New data is spilled to a new leaf node when the current node
** exceeds LEAF_MAX bytes (default 2048). New data which itself is
** larger than STANDALONE_MIN (default 1024) is placed in a standalone
** node (a leaf node with a single term and doclist). The goal of
** these settings is to pack together groups of small doclists while
** making it efficient to directly access large doclists. The
** assumption is that large doclists represent terms which are more
** likely to be query targets.
**
** TODO(shess) It may be useful for blocking decisions to be more
** dynamic. For instance, it may make more sense to have a 2.5k leaf
** node rather than splitting into 2k and .5k nodes. My intuition is
** that this might extend through 2x or 4x the pagesize.
**
**
**** Segment interior nodes ****
** Segment interior nodes store blockids for subtree nodes and terms
** to describe what data is stored by the each subtree. Interior
** nodes are written using InteriorWriter, and read using
** InteriorReader. InteriorWriters are created as needed when
** SegmentWriter creates new leaf nodes, or when an interior node
** itself grows too big and must be split. The format of interior
** nodes:
**
** varint iHeight; (height from leaf level, always >0)
** varint iBlockid; (block id of node's leftmost subtree)
** optional {
** varint nTerm; (length of first term)
** char pTerm[nTerm]; (content of first term)
** array {
** (further terms are delta-encoded)
** varint nPrefix; (length of shared prefix with previous term)
** varint nSuffix; (length of unshared suffix)
** char pTermSuffix[nSuffix]; (unshared suffix of next term)
** }
** }
**
** Here, optional { X } means an optional element, while array { X }
** means zero or more occurrences of X, adjacent in memory.
**
** An interior node encodes n terms separating n+1 subtrees. The
** subtree blocks are contiguous, so only the first subtree's blockid
** is encoded. The subtree at iBlockid will contain all terms less
** than the first term encoded (or all terms if no term is encoded).
** Otherwise, for terms greater than or equal to pTerm[i] but less
** than pTerm[i+1], the subtree for that term will be rooted at
** iBlockid+i. Interior nodes only store enough term data to
** distinguish adjacent children (if the rightmost term of the left
** child is "something", and the leftmost term of the right child is
** "wicked", only "w" is stored).
**
** New data is spilled to a new interior node at the same height when
** the current node exceeds INTERIOR_MAX bytes (default 2048).
** INTERIOR_MIN_TERMS (default 7) keeps large terms from monopolizing
** interior nodes and making the tree too skinny. The interior nodes
** at a given height are naturally tracked by interior nodes at
** height+1, and so on.
**
**
**** Segment directory ****
** The segment directory in table %_segdir stores meta-information for
** merging and deleting segments, and also the root node of the
** segment's tree.
**
** The root node is the top node of the segment's tree after encoding
** the entire segment, restricted to ROOT_MAX bytes (default 1024).
** This could be either a leaf node or an interior node. If the top
** node requires more than ROOT_MAX bytes, it is flushed to %_segments
** and a new root interior node is generated (which should always fit
** within ROOT_MAX because it only needs space for 2 varints, the
** height and the blockid of the previous root).
**
** The meta-information in the segment directory is:
** level - segment level (see below)
** idx - index within level
** - (level,idx uniquely identify a segment)
** start_block - first leaf node
** leaves_end_block - last leaf node
** end_block - last block (including interior nodes)
** root - contents of root node
**
** If the root node is a leaf node, then start_block,
** leaves_end_block, and end_block are all 0.
**
**
**** Segment merging ****
** To amortize update costs, segments are grouped into levels and
** merged in batches. Each increase in level represents exponentially
** more documents.
**
** New documents (actually, document updates) are tokenized and
** written individually (using LeafWriter) to a level 0 segment, with
** incrementing idx. When idx reaches MERGE_COUNT (default 16), all
** level 0 segments are merged into a single level 1 segment. Level 1
** is populated like level 0, and eventually MERGE_COUNT level 1
** segments are merged to a single level 2 segment (representing
** MERGE_COUNT^2 updates), and so on.
**
** A segment merge traverses all segments at a given level in
** parallel, performing a straightforward sorted merge. Since segment
** leaf nodes are written in to the %_segments table in order, this
** merge traverses the underlying sqlite disk structures efficiently.
** After the merge, all segment blocks from the merged level are
** deleted.
**
** MERGE_COUNT controls how often we merge segments. 16 seems to be
** somewhat of a sweet spot for insertion performance. 32 and 64 show
** very similar performance numbers to 16 on insertion, though they're
** a tiny bit slower (perhaps due to more overhead in merge-time
** sorting). 8 is about 20% slower than 16, 4 about 50% slower than
** 16, 2 about 66% slower than 16.
**
** At query time, high MERGE_COUNT increases the number of segments
** which need to be scanned and merged. For instance, with 100k docs
** inserted:
**
** MERGE_COUNT segments
** 16 25
** 8 12
** 4 10
** 2 6
**
** This appears to have only a moderate impact on queries for very
** frequent terms (which are somewhat dominated by segment merge
** costs), and infrequent and non-existent terms still seem to be fast
** even with many segments.
**
** TODO(shess) That said, it would be nice to have a better query-side
** argument for MERGE_COUNT of 16. Also, it is possible/likely that
** optimizations to things like doclist merging will swing the sweet
** spot around.
**
**
**
**** Handling of deletions and updates ****
** Since we're using a segmented structure, with no docid-oriented
** index into the term index, we clearly cannot simply update the term
** index when a document is deleted or updated. For deletions, we
** write an empty doclist (varint(docid) varint(POS_END)), for updates
** we simply write the new doclist. Segment merges overwrite older
** data for a particular docid with newer data, so deletes or updates
** will eventually overtake the earlier data and knock it out. The
** query logic likewise merges doclists so that newer data knocks out
** older data.
Number of extra columns needed
** No-op routine for the parse-tree walker.
**
** When this routine is the Walker.xExprCallback then expression trees
** are walked without any actions being taken at each node. Presumably,
** when this routine is used for Walker.xExprCallback then
** Walker.xSelectCallback is set to do something useful for every
** subquery in the parser tree.
The SQLite database connection
Use the built-in recursive mutexes if they are available.
** Added for 3.5.8
& result codes with this before returning
Array of cells and sizes
First instruction of interior of the loop
Global (connection wide) data
Pages in wal
** Turn a relative pathname into a full pathname. The relative path
** is stored as a nul-terminated string in the buffer pointed to by
** zPath.
**
** zOut points to a buffer of at least sqlite3_vfs.mxPathname bytes
** (in this case, MAX_PATHNAME bytes). The full-path is written to
** this buffer before returning.
If nSeg is less that zero, then there is no level with at least
** nMin segments and no hint in the %_stat table. No work to do.
** Exit early in this case.
************* Begin file pager.c ******************************************
Number of compound terms processed so far
If there are outstanding locks, do not actually close the file just
** yet because that would clear those locks. Instead, add the file
** descriptor to pInode->pUnused list. It will be automatically closed
** when the last lock is cleared.
** An rtree cursor object.
When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments
** to VACUUM are silently ignored. This is a back-out of a bug fix that
** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270).
** The buggy behavior is required for binary compatibility with some
** legacy applications.
Before the first write, give the VFS a hint of what the final
** file size will be.
** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
** the Select query generator tracing logic is turned on.
The cell to be inserted
aSample[] for the upper bound
One of PASSIVE, FULL and RESTART
** If an SQLITE_CONFIG_SQLLOG hook is registered and the VM has been run,
** invoke it.
Opcode: IntegrityCk P1 P2 P3 P4 P5
**
** Do an analysis of the currently open database. Store in
** register P1 the text of an error message describing any problems.
** If no problems are found, store a NULL in register P1.
**
** The register P3 contains one less than the maximum number of allowed errors.
** At most reg(P3) errors will be reported.
** In other words, the analysis stops as soon as reg(P1) errors are
** seen. Reg(P1) is updated with the number of errors remaining.
**
** The root page numbers of all tables in the database are integers
** stored in P4_INTARRAY argument.
**
** If P5 is not zero, the check is done on the auxiliary database
** file, not the main database file.
**
** This opcode is used to implement the integrity_check pragma.
Buffer to append text to
The new key
Grow the Fts5Hash.aSlot[] array if necessary.
If any BEFORE triggers were coded, then seek the cursor to the
** row to be deleted again. It may be that the BEFORE triggers moved
** the cursor or already deleted the row that the cursor was
** pointing to.
**
** Also disable the iIdxNoSeek optimization since the BEFORE trigger
** may have moved that cursor.
Table into which text will be inserted
Number of columns that show through to the output.
** Additional columns are used only as parameters to
** aggregate functions
Block of regs holding rowid+data being inserted
This table is not a VIEW
Index of rbu_control column
** Write a 64-bit variable-length integer to memory starting at p[0].
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
** The number of bytes written is returned.
** Render a string given by "fmt" into the StrAccum object.
Forward declarations
Used by TK_AGG_COLUMN and TK_AGG_FUNCTION
ifexists ::= IF EXISTS
comment: Prevent unnecessary deep recursion when we run out of entries
label: code-design
Set after incrementing the change-counter
** Implementation of the NULLIF(x,y) function. The result is the first
** argument if the arguments are different. The result is NULL if the
** arguments are equal to each other.
0x30..0x3F
#include "vdbeInt.h"
Return true if the argument is non-NULL and the WAL module is using
** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
** WAL module is using shared-memory, return false.
cmd ::= VACUUM nm
Amount to increment (*pHash->pnByte) by
"INSERT ... %_data VALUES(?,?)"
Number of columns in the constructed index
** The first parameter is a pointer to an output buffer. The second
** parameter is a pointer to an integer that contains the offset at
** which to write into the output buffer. This function copies the
** nul-terminated string pointed to by the third parameter, zSignedIdent,
** to the specified offset in the buffer and updates *pIdx to refer
** to the first byte after the last byte written before returning.
**
** If the string zSignedIdent consists entirely of alpha-numeric
** characters, does not begin with a digit and is not an SQL keyword,
** then it is copied to the output buffer exactly as it is. Otherwise,
** it is quoted using double-quotes.
Database of the table
Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
** a journal header to be written between the pages journaled by
** this function.
** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON
** object that is the result of running the RFC 7396 MergePatch() algorithm
** on the two arguments.
column names. malloced
Check to see the left operand is a column in a virtual table
** Context object passed to the fts5SentenceFinderCb() function.
The roles of pLower and pUpper are swapped for a DESC index
2nd and subsequent times through the loop
comment: OUT: sqlite3_malloc'd error message
label: code-design
Currently this interface is only called by the OP_IfSmaller
** opcode, and it that case the cursor will always be valid and
** will always point to a leaf node.
String defining the affinity of each column
If this is a virtual table, invoke the xRename() function if
** one is defined. The xRename() callback will modify the names
** of any resources used by the v-table implementation (including other
** SQLite tables) that are identified by the name of the virtual table.
An overflow has occurred
** Change the maximum size of any memory mapping made of the database file.
Make sure page is marked dirty
** This is a variant of sqlite3PagerWrite() that runs when the sector size
** is larger than the page size. SQLite makes the (reasonable) assumption that
** all bytes of a sector are written together by hardware. Hence, all bytes of
** a sector need to be journalled in case of a power loss in the middle of
** a write.
**
** Usually, the sector size is less than or equal to the page size, in which
** case pages can be individually written. This routine only runs in the
** exceptional case where the page size is smaller than the sector size.
570
comment: TODO(shess) Delimiters need to remain the same from run to run,
** else we need to reindex. One solution would be a meta-table to
** track such information in the database, then we'd only want this
** information on the initial create.
label: code-design
If SQLITE_UTF16 is specified as the encoding type, transform this
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
**
** If SQLITE_ANY is specified, add three versions of the function
** to the hash table.
Check cell size
The pager being played back
Candidate for the LIKE optimization
sclp ::=
Saved key that was cursor last known position
Table has keys only - no data
Attempt to reduce exponent.
**
** Branches that are not required for the correct answer but which only
** help to obtain the correct answer faster are marked with special
** comments, as a hint to the mutation tester.
OUT: True if iterator is at EOF
xFinalize
** Return the offset of the sector boundary at or immediately
** following the value in pPager->journalOff, assuming a sector
** size of pPager->sectorSize bytes.
**
** i.e for a sector size of 512:
**
** Pager.journalOff Return value
** ---------------------------------------
** 0 0
** 512 512
** 100 512
** 2000 2048
**
comment: Connection to notify of malloc failures
label: code-design
** Rerun the compilation of a statement after a schema change.
**
** If the statement is successfully recompiled, return SQLITE_OK. Otherwise,
** if the statement cannot be recompiled because another connection has
** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
** occurs, return SQLITE_SCHEMA.
** This routine frees the BLOB that is returned by geomCallback().
** Free a JsonParse object that was obtained from sqlite3_malloc().
** Maximum segments permitted in a single index
************* Begin file os.c *********************************************
Duplicates are scattered
0 -> copy from page, 1 -> copy to page
ASCII range token characters
True to omit locking primitives
If nSize==0, then the %_segdir.end_block field does not not
** contain a size value. This happens if it was written by an
** old version of FTS. In this case it is not possible to determine
** the size of the segment, and so segment promotion does not
** take place.
Number of bytes in aData
VDBE under constrution
IMP: R-64894-50321 The string "?000" is returned if the argument
** is NULL or contains no ASCII alphabetic characters.
CONFLICT => ID
Check if this is a recursive CTE.
Full-text index search
** There is no "best-index". This virtual table always does a linear
** scan. However, a schema=? constraint should cause this table to
** operate on a different database schema, so check for it.
**
** idxNum is normally 0, but will be 1 if a schema=? constraint exists.
** Advance the iterator object passed as the only argument. Return true
** if the iterator reaches EOF, or false otherwise.
** isNot:
** This variable is used by function getNextNode(). When getNextNode() is
** called, it sets ParseContext.isNot to true if the 'next node' is a
** FTSQUERY_PHRASE with a unary "-" attached to it. i.e. "mysql" in the
** FTS3 query "sqlite -mysql". Otherwise, ParseContext.isNot is set to
** zero.
** Move the iterator to the next entry at or following iMatch.
zero to read. non-zero to write.
SQLITE_OMIT_SHARED_CACHE
** Merge all level iLevel segments in the database into a single
** iLevel+1 segment. Or, if iLevel<0, merge all segments into a
** single segment with a level equal to the numerically largest level
** currently present in the database.
**
** If this function is called with iLevel<0, but there is only one
** segment in the database, SQLITE_DONE is returned immediately.
** Otherwise, if successful, SQLITE_OK is returned. If an error occurs,
** an SQLite error code is returned.
Maximum number of values to append
The escape character string must consist of a single UTF-8 character.
** Otherwise, return an error.
Sharable content of this btree
All SQL text past the last semicolon parsed
Map the requested memory region into this processes address space.
comment:
** Attempt to apply the change that the iterator passed as the first argument
** currently points to to the database. If a conflict is encountered, invoke
** the conflict handler callback.
**
** If argument pbRetry is NULL, then ignore any CHANGESET_DATA conflict. If
** one is encountered, update or delete the row with the matching primary key
** instead. Or, if pbRetry is not NULL and a CHANGESET_DATA conflict occurs,
** invoke the conflict handler. If it returns CHANGESET_REPLACE, set *pbRetry
** to true before returning. In this case the caller will invoke this function
** again, this time with pbRetry set to NULL.
**
** If argument pbReplace is NULL and a CHANGESET_CONFLICT conflict is
** encountered invoke the conflict handler with CHANGESET_CONSTRAINT instead.
** Or, if pbReplace is not NULL, invoke it with CHANGESET_CONFLICT. If such
** an invocation returns SQLITE_CHANGESET_REPLACE, set *pbReplace to true
** before retrying. In this case the caller attempts to remove the conflicting
** row before invoking this function again, this time with pbReplace set
** to NULL.
**
** If any conflict handler returns SQLITE_CHANGESET_ABORT, this function
** returns SQLITE_ABORT. Otherwise, if no error occurs, SQLITE_OK is
** returned.
label: code-design
Cursor number of the temporary table holding result
Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
** connection. If it returns SQLITE_OK, then assume that the VFS
** handled the pragma and generate a no-op prepared statement.
**
** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
** object corresponding to the database file to which the pragma
** statement refers.
**
** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
** file control is an array of pointers to strings (char**) in which the
** second element of the array is the name of the pragma and the third
** element is the argument to the pragma or NULL if the pragma has no
** argument.
Number of bytes in buffer zRoot
nArg of -2 is a special case
Indicates a reserved lock has been obtained
************* Begin file func.c *******************************************
Number of values in record
TUNING: If both iUpper and iLower are derived from the same
** sample, then assume they are 4x more selective. This brings
** the estimated selectivity more in line with what it would be
** if estimated without the use of STAT3/4 tables.
Unlock the system-level locks
Must be a compound subquery
158
101
Variable iLower will be set to the estimate of the number of rows in
** the index that are less than the lower bound of the range query. The
** lower bound being the concatenation of $P and $L, where $P is the
** key-prefix formed by the nEq values matched against the nEq left-most
** columns of the index, and $L is the value in pLower.
**
** Or, if pLower is NULL or $L cannot be extracted from it (because it
** is not a simple variable or literal value), the lower bound of the
** range is $P. Due to a quirk in the way whereKeyStats() works, even
** if $L is available, whereKeyStats() is called for both ($P) and
** ($P:$L) and the larger of the two returned values is used.
**
** Similarly, iUpper is to be set to the estimate of the number of rows
** less than the upper bound of the range query. Where the upper bound
** is either ($P) or ($P:$U). Again, even if $U is available, both values
** of iUpper are requested of whereKeyStats() and the smaller used.
**
** The number of rows between the two bounds is then just iUpper-iLower.
pInitMutex
** A "Collating Sequence" is defined by an instance of the following
** structure. Conceptually, a collating sequence consists of a name and
** a comparison routine that defines the order of that sequence.
**
** If CollSeq.xCmp is NULL, it means that the
** collating sequence is undefined. Indices built on an undefined
** collating sequence may not be read or written.
** Return the total number of pages in the cache.
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*************************************************************************
** Start of ascii tokenizer implementation.
Checksum based on FTS index contents
True if all changes are indirect
Link pNew element into the hash table pH. If pEntry!=0 then also
** insert pNew into the pEntry hash bucket.
#include "fts5.h"
Name of column in child table
comment: Make sure a corrupt database has not given us an oversize header.
** Do this now to avoid an oversize memory allocation.
**
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
** types use so much data space that there can only be 4096 and 32 of
** them, respectively. So the maximum header length results from a
** 3-byte type for each of the maximum of 32768 columns plus three
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
label: code-design
************* Begin file btree.c ******************************************
Memory register holding the rowid counter
If the file was opened successfully, read the schema for the new database.
** If this fails, or if opening the file failed, then close the file and
** remove the entry from the db->aDb[] array. i.e. put everything back the way
** we found it.
24
"neq" column of stat[34] entry
Total number of bytes in the record
OUT: Permissions to open file with
It is safe to always return here, but the resulting tree
** would be unbalanced
Iterator for this term
The rtree may have between 1 and RTREE_MAX_DIMENSIONS dimensions.
Load doclist-index for this leaf
Memory cell used to store aggregate context
Last character before the first wildcard
** Argument pTerm must be a synonym iterator.
** Wrapper around the pluggable caches xUnpin method. If the cache is
** being used for an in-memory database, this function is a no-op.
Value returned by SetFilePointer()
** Valid values for the second argument to fts3SqlStmt().
If this is an RBU vacuum operation and the state table was empty
** when this handle was opened, create the target database schema.
** Return the number of phrases in expression pExpr.
** The MergeEngine object is used to combine two or more smaller PMAs into
** one big PMA using a merge operation. Separate PMAs all need to be
** combined into one big PMA in order to be able to step through the sorted
** records in order.
**
** The aReadr[] array contains a PmaReader object for each of the PMAs being
** merged. An aReadr[] object either points to a valid key or else is at EOF.
** ("EOF" means "End Of File". When aReadr[] is at EOF there is no more data.)
** For the purposes of the paragraphs below, we assume that the array is
** actually N elements in size, where N is the smallest power of 2 greater
** to or equal to the number of PMAs being merged. The extra aReadr[] elements
** are treated as if they are empty (always at EOF).
**
** The aTree[] array is also N elements in size. The value of N is stored in
** the MergeEngine.nTree variable.
**
** The final (N/2) elements of aTree[] contain the results of comparing
** pairs of PMA keys together. Element i contains the result of
** comparing aReadr[2*i-N] and aReadr[2*i-N+1]. Whichever key is smaller, the
** aTree element is set to the index of it.
**
** For the purposes of this comparison, EOF is considered greater than any
** other key value. If the keys are equal (only possible with two EOF
** values), it doesn't matter which index is stored.
**
** The (N/4) elements of aTree[] that precede the final (N/2) described
** above contains the index of the smallest of each block of 4 PmaReaders
** And so on. So that aTree[1] contains the index of the PmaReader that
** currently points to the smallest key value. aTree[0] is unused.
**
** Example:
**
** aReadr[0] -> Banana
** aReadr[1] -> Feijoa
** aReadr[2] -> Elderberry
** aReadr[3] -> Currant
** aReadr[4] -> Grapefruit
** aReadr[5] -> Apple
** aReadr[6] -> Durian
** aReadr[7] -> EOF
**
** aTree[] = { X, 5 0, 5 0, 3, 5, 6 }
**
** The current element is "Apple" (the value of the key indicated by
** PmaReader 5). When the Next() operation is invoked, PmaReader 5 will
** be advanced to the next key in its segment. Say the next key is
** "Eggplant":
**
** aReadr[5] -> Eggplant
**
** The contents of aTree[] are updated first by comparing the new PmaReader
** 5 key to the current key of PmaReader 4 (still "Grapefruit"). The PmaReader
** 5 value is still smaller, so aTree[6] is set to 5. And so on up the tree.
** The value of PmaReader 6 - "Durian" - is now smaller than that of PmaReader
** 5, so aTree[3] is set to 6. Key 0 is smaller than key 6 (Banana<Durian),
** so the value written into element 1 of the array is 0. As follows:
**
** aTree[] = { X, 0 0, 6 0, 3, 5, 6 }
**
** In other words, each time we advance to the next sorter element, log2(N)
** key comparison operations are required, where N is the number of segments
** being merged (rounded up to the next power of 2).
** This routine runs an extensive test of the Bitvec code.
**
** The input is an array of integers that acts as a program
** to test the Bitvec. The integers are opcodes followed
** by 0, 1, or 3 operands, depending on the opcode. Another
** opcode follows immediately after the last operand.
**
** There are 6 opcodes numbered from 0 through 5. 0 is the
** "halt" opcode and causes the test to end.
**
** 0 Halt and return the number of errors
** 1 N S X Set N bits beginning with S and incrementing by X
** 2 N S X Clear N bits beginning with S and incrementing by X
** 3 N Set N randomly chosen bits
** 4 N Clear N randomly chosen bits
** 5 N S X Set N bits from S increment X in array only, not in bitvec
**
** The opcodes 1 through 4 perform set and clear operations are performed
** on both a Bitvec object and on a linear array of bits obtained from malloc.
** Opcode 5 works on the linear array only, not on the Bitvec.
** Opcode 5 is used to deliberately induce a fault in order to
** confirm that error detection works.
**
** At the conclusion of the test the linear array is compared
** against the Bitvec object. If there are any differences,
** an error is returned. If they are the same, zero is returned.
**
** If a memory allocation error occurs, return -1.
Content for INT, REAL, and STRING
************* Begin file tokenize.c ***************************************
term
** Set the LIKEOPT flag on the 2-argument function with the given name.
If we reach this point, it means that the database connection has
** closed all sqlite3_stmt and sqlite3_backup objects and has been
** passed to sqlite3_close (meaning that it is a zombie). Therefore,
** go ahead and free all resources.
Bytes of available memory
nRowLogEst set from sqlite_stat1
Maximum first byte of cell for a 1-byte payload
233
** Return values of columns for the row at which the stmt_cursor
** is currently pointing.
OUT: Trbul number of columns
The size of a single frame
Add opcodes to the prepared statement
** Do an authorization check using the code and arguments given. Return
** either SQLITE_OK (zero) or SQLITE_IGNORE or SQLITE_DENY. If SQLITE_DENY
** is returned, then the error count and error message in pParse are
** modified appropriately.
Enter the mutexes
Most sig. 32 bits of new offset
Evaluate the equality constraints
True to accumulate patchsets
** Flush any data cached by the writer object to the database. Free any
** allocations associated with the writer.
** Obtain a changeset object containing all changes recorded by the
** session object passed as the first argument.
**
** It is the responsibility of the caller to eventually free the buffer
** using sqlite3_free().
Index of new.* value to retrieve
Value returned by system call
DISTINCT using indexes
** Return true (non-zero) if the input is an integer that is too large
** to fit in 32-bits. This macro is used inside of various testcase()
** macros to verify that we have tested SQLite for large-file support.
Check to see if we need to create an sqlite_sequence table for
** keeping track of autoincrement keys.
No candidate table+column was found. This can only occur
** on the second iteration
** Make sure the Tcl calling convention macro is defined. This macro is
** only used by test code and Tcl integration code.
** PRAGMA [schema.]lock_proxy_file
** PRAGMA [schema.]lock_proxy_file = ":auto:"|"lock_file_path"
**
** Return or set the value of the lock_proxy_file flag. Changing
** the value sets a specific file to be used for database access locks.
**
** A read-lock must be held on the pager when this function is called. If
** the pager is in WAL mode and the WAL file currently contains one or more
** frames, return the size in bytes of the page images stored within the
** WAL frames. Otherwise, if this is not a WAL database or the WAL file
** is empty, return 0.
Opcode: Yield P1 P2 * * *
**
** Swap the program counter with the value in register P1. This
** has the effect of yielding to a coroutine.
**
** If the coroutine that is launched by this instruction ends with
** Yield or Return then continue to the next instruction. But if
** the coroutine launched by this instruction ends with
** EndCoroutine, then jump to P2 rather than continuing with the
** next instruction.
**
** See also: InitCoroutine
Size of BTM vector
** Extract the next token from a tokenization cursor. The cursor must
** have been opened by a prior call to simpleOpen().
Split operator. TK_AND or TK_OR
Result of last comparison
Address of the select-B coroutine
The rowid we are to seek to
Thread holding this mutex
At this point this is probably a keyword. But for that to be true,
** the next byte must contain either whitespace, an open or close
** parenthesis, a quote character, or EOF.
** Enlarge the memory allocation on a StrAccum object so that it is
** able to accept at least N more bytes of text.
**
** Return the number of bytes of text that StrAccum is able to accept
** after the attempted enlargement. The value returned might be zero.
There is now an entry for pExpr in pAggInfo->aCol[] (either
** because it was there before or because we just created it).
** Convert the pExpr to be a TK_AGG_COLUMN referring to that
** pAggInfo->aCol[] entry.
** This function is called by the VDBE to adjust the internal schema
** used by SQLite when the btree layer moves a table root page. The
** root-page of a table or index in database iDb has changed from iFrom
** to iTo.
**
** Ticket #1728: The symbol table might still contain information
** on tables and/or indices that are the process of being deleted.
** If you are unlucky, one of those deleted indices or tables might
** have the same rootpage number as the real table or index that is
** being moved. So we cannot stop searching after the first match
** because the first match might be for one of the deleted indices
** or tables and not the table/index that is actually being moved.
** We must continue looping until all tables and indices with
** rootpage==iFrom have been converted to have a rootpage of iTo
** in order to be certain that we got the right one.
** Read a single page from either the journal file (if isMainJrnl==1) or
** from the sub-journal (if isMainJrnl==0) and playback that page.
** The page begins at offset *pOffset into the file. The *pOffset
** value is increased to the start of the next page in the journal.
**
** The main rollback journal uses checksums - the statement journal does
** not.
**
** If the page number of the page record read from the (sub-)journal file
** is greater than the current value of Pager.dbSize, then playback is
** skipped and SQLITE_OK is returned.
**
** If pDone is not NULL, then it is a record of pages that have already
** been played back. If the page at *pOffset has already been played back
** (if the corresponding pDone bit is set) then skip the playback.
** Make sure the pDone bit corresponding to the *pOffset page is set
** prior to returning.
**
** If the page record is successfully read from the (sub-)journal file
** and played back, then SQLITE_OK is returned. If an IO error occurs
** while reading the record from the (sub-)journal file or while writing
** to the database file, then the IO error code is returned. If data
** is successfully read from the (sub-)journal file but appears to be
** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
** two circumstances:
**
** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
** * If the record is being rolled back from the main journal file
** and the checksum field does not match the record content.
**
** Neither of these two scenarios are possible during a savepoint rollback.
**
** If this is a savepoint rollback, then memory may have to be dynamically
** allocated by this function. If this is the case and an allocation fails,
** SQLITE_NOMEM is returned.
************ Begin control #defines ****************************************
** Two variations on the public interface for closing a database
** connection. The sqlite3_close() version returns SQLITE_BUSY and
** leaves the connection option if there are unfinalized prepared
** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
** version forces the connection to become a zombie if there are
** unclosed resources, and arranges for deallocation when the last
** prepare statement or sqlite3_backup closes.
** Rtree virtual table module xCreate method.
Get the results of the thread
A-overwrites-T
Next outer name context. NULL for outermost
All cells begin balanced
** A lists of all unixInodeInfo objects.
All mutexes are required for schema access. Make sure we hold them.
If we are doing a reverse order scan on an ascending index, or
** a forward order scan on a descending index, interchange the
** start and end terms (pRangeStart and pRangeEnd).
Page to delete cell from
Page number for first page in the list
Number of columns of data
** Only one of SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4 can be defined.
** Priority is given to SQLITE_ENABLE_STAT4. If either are defined, also
** define SQLITE_ENABLE_STAT3_OR_STAT4
Linked list of all foreign keys in this table
** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
** The Name context of the SELECT statement is pNC. zType is either
** "ORDER" or "GROUP" depending on which type of clause pOrderBy is.
**
** This routine resolves each term of the clause into an expression.
** If the order-by term is an integer I between 1 and N (where N is the
** number of columns in the result set of the SELECT) then the expression
** in the resolution is a copy of the I-th result-set expression. If
** the order-by term is an identifier that corresponds to the AS-name of
** a result-set expression, then the term resolves to a copy of the
** result-set expression. Otherwise, the expression is resolved in
** the usual way - using sqlite3ResolveExprNames().
**
** This routine returns the number of errors. If errors occur, then
** an appropriate error message might be left in pParse. (OOM errors
** excepted.)
** Add code that will check to make sure the N registers starting at iMem
** form a distinct entry. iTab is a sorting index that holds previously
** seen combinations of the N values. A new entry is made in iTab
** if the current N values are new.
**
** A jump to addrRepeat is made and the N+1 values are popped from the
** stack if the top N elements are not distinct.
Number of memory cells in the row key
Profiling function
ccons ::= COLLATE ID|STRING
** Move the iterator passed as the first argument to the next term in the
** segment. If successful, SQLITE_OK is returned. If there is no next term,
** SQLITE_DONE. Otherwise, an SQLite error code.
Used to iterate through aTask[]
** Read the content for page pPg out of the database file and into
** pPg->pData. A shared lock or greater must be held on the database
** file before this function is called.
**
** If page 1 is read, then the value of Pager.dbFileVers[] is set to
** the value read from the database file.
**
** If an IO error occurs, then the IO error is returned to the caller.
** Otherwise, SQLITE_OK is returned.
Bucket of terms object used by the integrity-check in offsets=0 mode.
** Return the number of the variable named zName, if it is in VList.
** or return 0 if there is no such variable.
RHS is real
** Convert an integer into a LogEst. In other words, compute an
** approximation for 10*log2(x).
True if a journal file is present
Methods for an open file
expr ::= RAISE LP IGNORE RP
Index of current page in apPage
** If this is a WAL database, obtain a snapshot handle for the snapshot
** currently open. Otherwise, return an error.
Form 1: Analyze everything
Set stack variable q to the close-quote character
Array of active savepoints
True if the previous character was uEsc
** Set the sort order for the last element on the given ExprList.
380
** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
** Purge the range of registers from the column cache.
Rows processed for current object
when_clause ::=
id value
Index to read column names from
tridxby ::= INDEXED BY nm
** Minimum chunk size used by streaming versions of functions.
OUTPUT: True if NOT NULL constraint exists
comment: This is a helper function for sqlite3BtreeLock(). By moving
** complex, but seldom used logic, out of sqlite3BtreeLock() and
** into this routine, we avoid unnecessary stack pointer changes
** and thus help the sqlite3BtreeLock() routine to run much faster
** in the common case.
label: code-design
Number of memory locations currently allocated
Initialize a lookahead iterator for each phrase. After passing the
** buffer and buffer size to the lookaside-reader init function, zero
** the phrase poslist buffer. The new poslist for the phrase (containing
** the same entries as the original with some entries removed on account
** of the NEAR constraint) is written over the original even as it is
** being read. This is safe as the entries for the new poslist are a
** subset of the old, so it is not possible for data yet to be read to
** be overwritten.
List of frame objects to free on VM reset
Output poslist
Run the BEFORE and INSTEAD OF triggers, if there are any
Number of valid entries in array aNew[]
The name of the trigger
** Discard all data currently cached in the hash-tables.
OUT: Visiblity
Used to iterate through constraint array
Arguments to the format string
Trace function
** Close a tokenization cursor previously opened by a call to icuOpen().
sqlite3GetVdbe cannot fail: VDBE already allocated
Number of usable bytes on each page
** Query the hash table for a doclist associated with term pTerm/nTerm.
Free up the array of auxiliary databases
** Flush all unreferenced dirty pages to disk.
OUT: Set to true if really a match
Input JSON text to be parsed
Next with a different name but the same hash
Set nByte to the number of bytes required to store the expanded blob.
True if a warnning has been issued
comment: G: New-style sqlite3_rtree_query_callback()
label: code-design
** For chunk size nChunkSize, return the number of bytes that should
** be allocated for each FileChunk structure.
Opcode: CreateIndex P1 P2 * * *
** Synopsis: r[P2]=root iDb=P1
**
** Allocate a new index in the main database file if P1==0 or in the
** auxiliary database file if P1==1 or in an attached database if
** P1>1. Write the root page number of the new table into
** register P2.
**
** See documentation on OP_CreateTable for additional information.
Allocate a buffer in which to accumulate data
All other Windows platforms expect GetProcAddress() to take
** an ANSI string regardless of the _UNICODE setting
Real value used when MEM_Real is set in flags
SQLITE_OMIT_HEX_INTEGER
** The journal file must be open when this routine is called. A journal
** header (JOURNAL_HDR_SZ bytes) is written into the journal file at the
** current location.
**
** The format for the journal header is as follows:
** - 8 bytes: Magic identifying journal format.
** - 4 bytes: Number of records in journal, or -1 no-sync mode is on.
** - 4 bytes: Random number used for page hash.
** - 4 bytes: Initial database page count.
** - 4 bytes: Sector size used by the process that wrote this journal.
** - 4 bytes: Database page size.
**
** Followed by (JOURNAL_HDR_SZ - 28) bytes of unused space.
This vtab delivers always results in "ORDER BY term ASC" order.
EVIDENCE-OF: R-18143-12121 Value is the integer 1.
the hash table
Bytes to read from disk
sqlite3_user_data() context
Begin by rolling back records from the main journal starting at
** PagerSavepoint.iOffset and continuing to the next journal header.
** There might be records in the main journal that have a page number
** greater than the current database size (pPager->dbSize) but those
** will be skipped automatically. Pages are added to pDone as they
** are played back.
comment: Allocated size of a[] (nAlloc>=n)
label: code-design
** Return non-zero if a transaction is active.
Type of file to open
<0 means "need to query"
aKWNext[] forms the hash collision chain. If aKWHash[i]==0
** then the i-th keyword has no more hash collisions. Otherwise,
** the next keyword with the same hash is aKWHash[i]-1.
Currently always set to 3
Write the new column list here
** Convert an sqlite3_value into an RtreeValue (presumably a float)
** while taking care to round toward negative or positive, respectively.
End of {...}
Use this case if we have ANSI headers
comment:
** The database page the PENDING_BYTE occupies. This page is never used.
label: code-design
Extension to which this belongs
Split the WHERE clause into separate subexpressions where each
** subexpression is separated by an AND operator.
If this is a release of the outermost savepoint, truncate
** the sub-journal to zero bytes in size.
The page number of a page in journal
Reinitialize page pTo so that the contents of the MemPage structure
** match the new data. The initialization of pTo can actually fail under
** fairly obscure circumstances, even though it is a copy of initialized
** page pFrom.
ICU library collation object
cmd ::= with DELETE FROM fullname indexed_opt where_opt
Configure the text that the regular expression operates on.
The VFS that created this unixFile
** Return a copy of input string zInput enclosed in double-quotes (") and
** with all double quote characters escaped. For example:
**
** fts3QuoteId("un \"zip\"") -> "un \"\"zip\"\""
**
** The pointer returned points to memory obtained from sqlite3_malloc(). It
** is the callers responsibility to call sqlite3_free() to release this
** memory.
defined(SQLITE_ENABLE_ICU)
Next with the same zTo. Next child of zTo.
Create other tables
Size of pList as PMA in bytes
** Read a 64-bit big-endian integer value from buffer aRec[]. Return
** the value read.
comment: It's odd to simulate an io-error here, but really this is just
** using the io-error infrastructure to test that SQLite handles this
** function failing.
label: code-design
First part of index name. May be NULL
comment:
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
label: code-design
Register to hold Stat4Accum object
Root page of b-tree
The cursor to compare against
comment: Opcode: DeferredSeek P1 * P3 P4 *
** Synopsis: Move P3 to P1.rowid if needed
**
** P1 is an open index cursor and P3 is a cursor on the corresponding
** table. This opcode does a deferred seek of the P3 table cursor
** to the row that corresponds to the current row of P1.
**
** This is a deferred seek. Nothing actually happens until
** the cursor is used to read a record. That way, if no reads
** occur, no unnecessary I/O happens.
**
** P4 may be an array of integers (type P4_INTARRAY) containing
** one entry for each column in the P3 table. If array entry a(i)
** is non-zero, then reading column a(i)-1 from cursor P3 is
** equivalent to performing the deferred seek and then reading column i
** from P1. This information is stored in P3 and used to redirect
** reads against P3 over to P1, thus possibly avoiding the need to
** seek and read cursor P3.
label: code-design
True -> read/write access, false -> read-only
iVersion
Generate code to destroy the database record of the trigger.
Use STAT3 or STAT4 data
Get the precision
If at least one field has been modified, this is not a no-op.
If table pTab has not been used in a way that would benefit from
** having analysis statistics during the current session, then skip it.
** This also has the effect of skipping virtual tables and views
comment: It's odd to simulate an io-error here, but really this is just
** using the io-error infrastructure to test that SQLite handles this
** function failing.
label: code-design
OUT: Size of output buffer in bytes
** Open and return a new RBU handle.
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append a string to the buffer. All bytes in the string
** up to (but not including) the nul-terminator are written to the buffer.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
This trick assumes that both the page-size and sector-size are
** an integer power of 2. It sets variable pg1 to the identifier
** of the first page of the sector pPg is located on.
** PRAGMA [schema.]secure_delete
** PRAGMA [schema.]secure_delete=ON/OFF/FAST
**
** The first form reports the current setting for the
** secure_delete flag. The second form changes the secure_delete
** flag setting and reports the new value.
960
** pEList is a list of expressions which are really the result set of the
** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
** This routine checks to see if pE is a simple identifier which corresponds
** to the AS-name of one of the terms of the expression list. If it is,
** this routine return an integer between 1 and N where N is the number of
** elements in pEList, corresponding to the matching entry. If there is
** no match, or if pE is not a simple identifier, then this routine
** return 0.
**
** pEList has been resolved. pE has not.
Check if data must be read/written to/from the btree page itself.
Next entry in Parse.pTriggerPrg list
** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T
** define is required to maintain binary compatibility with the MSVC runtime
** library in use (e.g. for Windows XP).
** Clear all column cache entries.
0x02
Save profiling information from this VDBE run.
Column to extract from poslist
OUT: Docid for row just inserted
The VFS used to open this file
IMP: R-29431-39229
Text encoding handled by xCmp()
** The ISAUTOVACUUM macro is used within balance_nonroot() to determine
** if the database supports auto-vacuum or not. Because it is used
** within an expression that is an argument to another macro
** (sqliteMallocRaw), it is not possible to use conditional compilation.
** So, this macro is defined instead.
pPage->aData
** Each SQL function is defined by an instance of the following
** structure. For global built-in functions (ex: substr(), max(), count())
** a pointer to this structure is held in the sqlite3BuiltinFunctions object.
** For per-connection application-defined functions, a pointer to this
** structure is held in the db->aHash hash table.
**
** The u.pHash field is used by the global built-ins. The u.pDestructor
** field is used by per-connection app-def functions.
zKWText[] encodes 834 bytes of keyword text in 554 bytes
Return value
If this is an RBU vacuum operation and this is the target database,
** pretend that it has at least one page. Otherwise, SQLite will not
** check for the existance of a *-wal file. rbuVfsRead() contains
** similar logic.
Always cast the getpid() return type for compatibility with
** kernel modules in VxWorks.
Existing index ASCENDING
Array of nLevel level objects
The program counter
Create a snapshot object. The content of a snapshot is opaque to
** every other subsystem, so the WAL module can put whatever it needs
** in the object.
Pointer to the rbu_vfs object
Function name
** The next group of routines are convenience wrappers around the
** VFS methods.
** An implementation of a min-heap.
**
** aHeap[0] is the number of elements on the heap. aHeap[1] is the
** root element. The daughter nodes of aHeap[N] are aHeap[N*2]
** and aHeap[N*2+1].
**
** The heap property is this: Every node is less than or equal to both
** of its daughter nodes. A consequence of the heap property is that the
** root node aHeap[1] is always the minimum value currently in the heap.
**
** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto
** the heap, preserving the heap property. The btreeHeapPull() routine
** removes the root element from the heap (the minimum value in the heap)
** and then moves other nodes around as necessary to preserve the heap
** property.
**
** This heap is used for cell overlap and coverage testing. Each u32
** entry represents the span of a cell or freeblock on a btree page.
** The upper 16 bits are the index of the first byte of a range and the
** lower 16 bits are the index of the last byte of that range.
First operand
comment:
** FTS4 is really an extension for FTS3. It is enabled using the
** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call
** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3.
label: code-design
The column value supplied by SQLite must be in range.
Next divider slot in pParent->aCell[]
Skip over any TK_COLLATE nodes
IMP: R-26507-47431
Next backup associated with source pager
** Insert the contents of cell pCell into node pNode. If the insert
** is successful, return SQLITE_OK.
**
** If there is not enough free space in pNode, return SQLITE_FULL.
** Return the name of the i-th column of the pIdx index.
** The pMem is known to contain content that needs to be destroyed prior
** to a value change. So invoke the destructor, then set the value to
** a 64-bit integer.
The file I/O methods to use.
Pointer to one byte after EOF
For looping over all elements of the table
Bitvec of pages already played back
Delete existing record, then do INSERT or UPDATE
************* End of complete.c *******************************************
This block deals with an obscure problem. If the last connection
** that wrote to this database was operating in persistent-journal
** mode, then the journal file may at this point actually be larger
** than Pager.journalOff bytes. If the next thing in the journal
** file happens to be a journal-header (written as part of the
** previous connection's transaction), and a crash or power-failure
** occurs after nRec is updated but before this connection writes
** anything else to the journal file (or commits/rolls back its
** transaction), then SQLite may become confused when doing the
** hot-journal rollback following recovery. It may roll back all
** of this connections data, then proceed to rolling back the old,
** out-of-date data that follows it. Database corruption.
**
** To work around this, if the journal file does appear to contain
** a valid header following Pager.journalOff, then write a 0x00
** byte to the start of it to prevent it from being recognized.
**
** Variable iNextHdrOffset is set to the offset at which this
** problematic header will occur, if it exists. aMagic is used
** as a temporary buffer to inspect the first couple of bytes of
** the potential journal header.
Alternatively, if bExtend is true, extend the file. Do this by
** writing a single byte to the end of each (OS) page being
** allocated or extended. Technically, we need only write to the
** last page in order to extend the file. But writing to all new
** pages forces the OS to allocate them immediately, which reduces
** the chances of SIGBUS while accessing the mapped region later on.
"0" digits after the decimal point but before the first
** significant digit of the number
** Include code that is common to all os_*.c files
Used to iterate through segment-readers
BLOB returned by geometry function
on_opt
** Return true if pNew is to be preferred over pOld.
**
** This function assumes that for each argument sample, the contents of
** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid.
comment: Term iterator to advance
label: code-design
Cursor used to iterate through aDoclist
Incrementally write one PMA
Check that the internal nodes of each segment match the leaves
** This function is called after an "ALTER TABLE ... ADD" statement
** has been parsed. Argument pColDef contains the text of the new
** column definition.
**
** The Table structure pParse->pNewTable was extended to include
** the new column during parsing.
Allocate temporary working space.
synopsis: nColumn=P2
'automerge' setting
Register to copy from
** Resolve all names in all expressions of a SELECT and in all
** decendents of the SELECT, including compounds off of p->pPrior,
** subqueries in expressions, and subqueries used as FROM clause
** terms.
**
** See sqlite3ResolveExprNames() for a description of the kinds of
** transformations that occur.
**
** All SELECT statements should have been expanded using
** sqlite3SelectExpand() prior to invoking this routine.
Cascade the changes
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append a single byte to the buffer.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
Make the page containing the entry to be deleted writable. Then free any
** overflow pages associated with the entry and finally remove the cell
** itself from within the page.
Term to iterate through a doclist for
Create the virtual table wrapper around the hash-table and overload
** the four scalar functions. If this is successful, register the
** module with sqlite.
Value of each argument
************* Begin file fts3_snippet.c ***********************************
0: Acquire a read or write lock
The child table to be scanned
Individual characters in zCharSet
** Read data from a file into a buffer. Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
** wrong.
Check if pExpr is identical to any GROUP BY term. If so, consider
** it constant.
1260
Drop the table and index from the internal schema.
aOffset[i] is offset to start of data for i-th column
*************************************************************************
** Interface to code in fts5.c.
Opcode: Transaction P1 P2 P3 P4 P5
**
** Begin a transaction on database P1 if a transaction is not already
** active.
** If P2 is non-zero, then a write-transaction is started, or if a
** read-transaction is already active, it is upgraded to a write-transaction.
** If P2 is zero, then a read-transaction is started.
**
** P1 is the index of the database file on which the transaction is
** started. Index 0 is the main database file and index 1 is the
** file used for temporary tables. Indices of 2 or more are used for
** attached databases.
**
** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
** true (this flag is set if the Vdbe may modify more than one row and may
** throw an ABORT exception), a statement transaction may also be opened.
** More specifically, a statement transaction is opened iff the database
** connection is currently not in autocommit mode, or if there are other
** active statements. A statement transaction allows the changes made by this
** VDBE to be rolled back after an error without having to roll back the
** entire transaction. If no error is encountered, the statement transaction
** will automatically commit when the VDBE halts.
**
** If P5!=0 then this opcode also checks the schema cookie against P3
** and the schema generation counter against P4.
** The cookie changes its value whenever the database schema changes.
** This operation is used to detect when that the cookie has changed
** and that the current process needs to reread the schema. If the schema
** cookie in P3 differs from the schema cookie in the database header or
** if the schema generation counter in P4 differs from the current
** generation counter, then an SQLITE_SCHEMA error is raised and execution
** halts. The sqlite3_step() wrapper function might then reprepare the
** statement and rerun it from the beginning.
What to do with a uniqueness conflict
** While a SrcList can in general represent multiple tables and subqueries
** (as in the FROM clause of a SELECT statement) in this case it contains
** the name of a single table, as one might find in an INSERT, DELETE,
** or UPDATE statement. Look up that table in the symbol table and
** return a pointer. Set an error message and return NULL if the table
** name is not found or if any other error occurs.
**
** The following fields are initialized appropriate in pSrc:
**
** pSrc->a[0].pTab Pointer to the Table object
** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one
**
Temporary buffer space
** Create an RBU VFS named zName that accesses the underlying file-system
** via existing VFS zParent. The new object is registered as a non-default
** VFS with SQLite before returning.
If this process is running as root, make sure that the SHM file
** is owned by the same user that owns the original database. Otherwise,
** the original owner will not be able to connect.
** Arguments aIdx, aCell and aSpare all point to arrays of size
** nIdx. The aIdx array contains the set of integers from 0 to
** (nIdx-1) in no particular order. This function sorts the values
** in aIdx according to dimension iDim of the cells in aCell. The
** minimum value of dimension iDim is considered first, the
** maximum used to break ties.
**
** The aSpare array is used as temporary working space by the
** sorting algorithm.
Closing highlight
** Default maximum size for persistent journal files. A negative
** value means no limit. This value may be overridden using the
** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit".
If p2 is at EOF
Terms that make up this phrase
Value is a real number
(284) columnlist ::= columnlist COMMA columnname carglist
One of the RTREE_COORD_* constants
Used to test for reference loops
Set the szLeaf header field.
** CAPI3REF: String LIKE Matching
*
** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
** string X matches the [LIKE] pattern P with escape character E.
** ^The definition of [LIKE] pattern matching used in
** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without
** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
** insensitive - equivalent upper and lower case ASCII characters match
** one another.
**
** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
** only ASCII characters are case folded.
**
** Note that this routine returns zero on a match and non-zero if the strings
** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
**
** See also: [sqlite3_strglob()].
A row is being removed from the child table. Search for the parent.
** If the parent does not exist, removing the child row resolves an
** outstanding foreign key constraint violation.
Complete text of a module argument
Initialize the BLOB value of a ROWID
Size of master journal file
** Append term pTerm/nTerm to the segment being written by the writer passed
** as the second argument.
**
** If an error occurs, set the Fts5Index.rc error code. If an error has
** already occurred, this function is a no-op.
True if an error has been encountered
Grab the index number and argc parameters
** Each cursor has a (possibly empty) linked list of the following objects.
Set a SQLITE_TOOBIG error if no NULL
!defined(SQLITE_OMIT_FOREIGN_KEY)
** Interpret the given string as an auto-vacuum mode value.
**
** The following strings, "none", "full" and "incremental" are
** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
Translate from this opcode to the end
** Permitted values of the SrcList.a.jointype field
Offset of journal header being read
An index is used
Case 2: We can directly reference a single row using an
** equality comparison against the ROWID field. Or
** we reference multiple rows using a "rowid IN (...)"
** construct.
** Purge the unixShmNodeList list of all entries with unixShmNode.nRef==0.
**
** This is not a VFS shared-memory method; it is a utility function called
** by VFS shared-memory methods.
Default case. Handles, amongst others, "nfs".
** Test byte-range lock using fcntl(). If the call succeeds,
** assume that the file-system supports POSIX style locks.
** Generate code to do constraint checks prior to an INSERT or an UPDATE
** on table pTab.
**
** The regNewData parameter is the first register in a range that contains
** the data to be inserted or the data after the update. There will be
** pTab->nCol+1 registers in this range. The first register (the one
** that regNewData points to) will contain the new rowid, or NULL in the
** case of a WITHOUT ROWID table. The second register in the range will
** contain the content of the first table column. The third register will
** contain the content of the second table column. And so forth.
**
** The regOldData parameter is similar to regNewData except that it contains
** the data prior to an UPDATE rather than afterwards. regOldData is zero
** for an INSERT. This routine can distinguish between UPDATE and INSERT by
** checking regOldData for zero.
**
** For an UPDATE, the pkChng boolean is true if the true primary key (the
** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
** might be modified by the UPDATE. If pkChng is false, then the key of
** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
**
** For an INSERT, the pkChng boolean indicates whether or not the rowid
** was explicitly specified as part of the INSERT statement. If pkChng
** is zero, it means that the either rowid is computed automatically or
** that the table is a WITHOUT ROWID table and has no rowid. On an INSERT,
** pkChng will only be true if the INSERT statement provides an integer
** value for either the rowid column or its INTEGER PRIMARY KEY alias.
**
** The code generated by this routine will store new index entries into
** registers identified by aRegIdx[]. No index entry is created for
** indices where aRegIdx[i]==0. The order of indices in aRegIdx[] is
** the same as the order of indices on the linked list of indices
** at pTab->pIndex.
**
** The caller must have already opened writeable cursors on the main
** table and all applicable indices (that is to say, all indices for which
** aRegIdx[] is not zero). iDataCur is the cursor for the main table when
** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
** index when operating on a WITHOUT ROWID table. iIdxCur is the cursor
** for the first index in the pTab->pIndex list. Cursors for other indices
** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
**
** This routine also generates code to check constraints. NOT NULL,
** CHECK, and UNIQUE constraints are all checked. If a constraint fails,
** then the appropriate action is performed. There are five possible
** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
**
** Constraint type Action What Happens
** --------------- ---------- ----------------------------------------
** any ROLLBACK The current transaction is rolled back and
** sqlite3_step() returns immediately with a
** return code of SQLITE_CONSTRAINT.
**
** any ABORT Back out changes from the current command
** only (do not do a complete rollback) then
** cause sqlite3_step() to return immediately
** with SQLITE_CONSTRAINT.
**
** any FAIL Sqlite3_step() returns immediately with a
** return code of SQLITE_CONSTRAINT. The
** transaction is not rolled back and any
** changes to prior rows are retained.
**
** any IGNORE The attempt in insert or update the current
** row is skipped, without throwing an error.
** Processing continues with the next row.
** (There is an immediate jump to ignoreDest.)
**
** NOT NULL REPLACE The NULL value is replace by the default
** value for that column. If the default value
** is NULL, the action is the same as ABORT.
**
** UNIQUE REPLACE The other row that conflicts with the row
** being inserted is removed.
**
** CHECK REPLACE Illegal. The results in an exception.
**
** Which action to take is determined by the overrideError parameter.
** Or if overrideError==OE_Default, then the pParse->onError parameter
** is used. Or if pParse->onError==OE_Default then the onError value
** for the constraint is used.
comment:
** Assert that the pointer X is aligned to an 8-byte boundary. This
** macro is used only within assert() to verify that the code gets
** all alignment restrictions correct.
**
** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the
** underlying malloc() implementation might return us 4-byte aligned
** pointers. In that case, only verify 4-byte alignment.
label: code-design
x<EXPR and/or x>EXPR
Pointer to first byte after the header
Argument to the function
comment:
** Change the P4 operand of the most recently coded instruction
** to the value defined by the arguments. This is a high-speed
** version of sqlite3VdbeChangeP4().
**
** The P4 operand must not have been previously defined. And the new
** P4 must not be P4_INT32. Use sqlite3VdbeChangeP4() in either of
** those cases.
label: code-design
************************************************************************
** FTS5 EXTENSION REGISTRATION API
** Return the collation sequence for the expression pExpr. If
** there is no defined collating sequence, return NULL.
**
** The collating sequence might be determined by a COLLATE operator
** or by the presence of a column with a defined collating sequence.
** COLLATE operators take first precedence. Left operands take
** precedence over right operands.
The computed hash
Condition 2
187
paren_exprlist ::=
Allocate an array and populate it with a copy of pCell and
** all cells from node pLeft. Then zero the original node.
Determine whether or not this is a transaction savepoint. If so,
** and this is a RELEASE command, then the current transaction
** is committed.
Increment the value just read and write it back to byte 24.
** The root-page of the master database table.
In theory, the call to unixFileLock() cannot fail because another
** process is holding an incompatible lock. If it does, this
** indicates that the other process is not following the locking
** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning
** SQLITE_BUSY would confuse the upper layer (in practice it causes
** an assert to fail).
The first to decrement to 0 does actual shutdown
** (which should be the last to shutdown.)
Number of columns must be the same in tab1 and tab2
Compare against this WhereLoop
trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause
The element that matches key (if any)
content table
Next in list of all winShmNode objects
Drop any table triggers from the internal schema.
** The second argument to this function, op, is always SAVEPOINT_ROLLBACK
** or SAVEPOINT_RELEASE. This function either releases or rolls back the
** savepoint identified by parameter iSavepoint, depending on the value
** of op.
**
** Normally, iSavepoint is greater than or equal to zero. However, if op is
** SAVEPOINT_ROLLBACK, then iSavepoint may also be -1. In this case the
** contents of the entire transaction are rolled back. This is different
** from a normal transaction rollback, as no locks are released and the
** transaction remains open.
Total cache hits, misses and writes
Affinity to use for comparison
cmd ::= SAVEPOINT nm
Possible covering index for WHERE_MULTI_OR
************* Begin file fts3_unicode2.c **********************************
** Return the minimum number of 32KB shm regions that should be mapped at
** a time, assuming that each mapping must be an integer multiple of the
** current system page-size.
**
** Usually, this is 1. The exception seems to be systems that are configured
** to use 64KB pages - in this case each mapping must cover at least two
** shm regions.
Allowed values for Column.colFlags:
** Candidate values for Fts3Query.eType. Note that the order of the first
** four values is in order of precedence when parsing expressions. For
** example, the following:
**
** "a OR b AND c NOT d NEAR e"
**
** is equivalent to:
**
** "a OR (b AND (c NOT (d NEAR e)))"
The pointer map page number
** Parameter eMode must be one of the PAGER_JOURNALMODE_XXX constants
** defined in pager.h. This function returns the associated lowercase
** journal-mode name.
Allocate and initialize the iterator structure.
Matchinfo context object
True if resolved to a trigger column
Index used by loop (if any)
238
The julian day number times 86400000
Result code from subroutine call
** Explicitly call the 64-bit version of lseek() on Android. Otherwise, lseek()
** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
Wildcard of the form "?". Assign the next variable number
FTS Cursor handle
xOpen flags
** Implementation of xCommit() method. This is a no-op. The contents of
** the pending-terms hash-table have already been flushed into the database
** by fts5SyncMethod().
************* Include vdbeInt.h in the middle of status.c *****************
Forward references to VFS helper methods used for memory mapped files
Neither operand is NULL. Do a comparison.
trigger_cmd_list ::= trigger_cmd SEMI
Used to iterate through change record
comment:
** Remove all redundant columns from the PRIMARY KEY. For example, change
** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
** code assumes the PRIMARY KEY contains no repeated columns.
label: code-design
Fall through into the next case
Opcode: ColumnsUsed P1 * * P4 *
**
** This opcode (which only exists if SQLite was compiled with
** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
** table or index for cursor P1 are used. P4 is a 64-bit integer
** (P4_INT64) in which the first 63 bits are one for each of the
** first 63 columns of the table or index that are actually used
** by the cursor. The high-order bit is set if any column after
** the 64th is used.
shared memory is disabled
New estimate of the number of rows
Mask against sqlite3_index_constraint.op
If the requested key is one more than the previous key, then
** try to get there using sqlite3BtreeNext() rather than a full
** binary search. This is an optimization only. The correct answer
** is still obtained without this case, only a little more slowely
Cursors from source and destination
OUTPUT: True if column part of PK
OUT: bm25-data object for this query
'('
** Characters that can be part of a token. We assume any character
** whose value is greater than 0x80 (any UTF character) can be
** part of a token. In other words, delimiters all must have
** values of 0x7f or lower.
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
** Otherwise, append an entry to the hint stored in blob *pHint. Each entry
** consists of two varints, the absolute level number of the input segments
** and the number of input segments.
**
** If successful, leave *pRc set to SQLITE_OK and return. If an error occurs,
** set *pRc to an SQLite error code before returning.
Number of rows in index
Enable mutex on connections
This savepoint was opened immediately after the write-transaction
** was started. Right after that, the writer decided to wrap around
** to the start of the log. Update the savepoint values to match.
** Number of entries in the cursor RtreeNode cache. The first entry is
** used to cache the RtreeNode for RtreeCursor.sPoint. The remaining
** entries cache the RtreeNode for the first elements of the priority queue.
restrictions (1) and (2)
Size of term on leaf in bytes
** Close a cursor. The read lock on the database file is released
** when the last cursor is closed.
** Allocate a new RtreeSearchPoint and return a pointer to it. Return
** NULL if malloc fails.
Info about index keys needed by index cursors
Pointer to space allocated by sqlite3BtreeSchema()
True if last operation was a delete
Largest leaf block id written to db
Set up a loop over the rowids/primary-keys that were found in the
** where-clause loop above.
Store the result as data using a unique key.
A type code from the record header
setlist ::= nm EQ expr
List of tables to select from
Opcode: LoadAnalysis P1 * * * *
**
** Read the sqlite_stat1 table for database P1 and load the content
** of that table into the internal index hash table. This will cause
** the analysis to be used when preparing all subsequent queries.
** Return the current value of a status parameter. The caller must
** be holding the appropriate mutex.
** Zero the iterator passed as the only argument.
** Return TRUE if the name zCol occurs anywhere in the USING clause.
**
** Return FALSE if the USING clause is NULL or if it does not contain
** zCol.
** apCell[] and szCell[] contains pointers to and sizes of all cells in the
** pages being balanced. The current page, pPg, has pPg->nCell cells starting
** with apCell[iOld]. After balancing, this page should hold nNew cells
** starting at apCell[iNew].
**
** This routine makes the necessary adjustments to pPg so that it contains
** the correct cells after being balanced.
**
** The pPg->nFree field is invalid when this function returns. It is the
** responsibility of the caller to set it correctly.
** Locate the in-memory structure that describes
** a particular index given the name of that index
** and the name of the database that contains the index.
** Return NULL if not found.
**
** If zDatabase is 0, all databases are searched for the
** table and the first matching index is returned. (No checking
** for duplicate index names is done.) The search order is
** TEMP first, then MAIN, then any auxiliary databases added
** using the ATTACH command.
** Record in the column cache that a particular column from a
** particular table is stored in a particular register.
Restriction (11)
The docid column
EVIDENCE-OF: R-38229-40159 If the callback function to
** sqlite3_exec() returns non-zero, then sqlite3_exec() will
** return SQLITE_ABORT.
Pointer to entire doclist
virtual table name
SQLITE_FULL
Pointer to the subexpression that is this term
Temporary file object wrapper
************* End of mutex.c **********************************************
** An objected used to accumulate the text of a string where we
** do not necessarily know how big the string will be in the end.
comment:
** The dupedExpr*Size() routines each return the number of bytes required
** to store a copy of an expression or expression tree. They differ in
** how much of the tree is measured.
**
** dupedExprStructSize() Size of only the Expr structure
** dupedExprNodeSize() Size of Expr + space for token
** dupedExprSize() Expr + token + subtree components
**
***************************************************************************
**
** The dupedExprStructSize() function returns two values OR-ed together:
** (1) the space required for a copy of the Expr structure only and
** (2) the EP_xxx flags that indicate what the structure size should be.
** The return values is always one of:
**
** EXPR_FULLSIZE
** EXPR_REDUCEDSIZE | EP_Reduced
** EXPR_TOKENONLYSIZE | EP_TokenOnly
**
** The size of the structure can be found by masking the return value
** of this routine with 0xfff. The flags can be found by masking the
** return value with EP_Reduced|EP_TokenOnly.
**
** Note that with flags==EXPRDUP_REDUCE, this routines works on full-size
** (unreduced) Expr objects as they or originally constructed by the parser.
** During expression analysis, extra information is computed and moved into
** later parts of teh Expr object and that extra information might get chopped
** off if the expression is reduced. Note also that it does not work to
** make an EXPRDUP_REDUCE copy of a reduced expression. It is only legal
** to reduce a pristine expression tree from the parser. The implementation
** of dupedExprStructSize() contain multiple assert() statements that attempt
** to enforce this constraint.
label: code-design
Session table handle
** VDBE_DISPLAY_P4 is true or false depending on whether or not the
** "explain" P4 display logic is enabled.
************* Begin file select.c *****************************************
1100
** Make sure the page is marked as dirty. If it isn't dirty already,
** make it so.
** 2006 Oct 10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Implementation of the "simple" full-text-search tokenizer.
comment: *****************************************************************************
*************************** Posix Advisory Locking ****************************
**
** POSIX advisory locks are broken by design. ANSI STD 1003.1 (1996)
** section 6.5.2.2 lines 483 through 490 specify that when a process
** sets or clears a lock, that operation overrides any prior locks set
** by the same process. It does not explicitly say so, but this implies
** that it overrides locks set by the same process using a different
** file descriptor. Consider this test case:
**
** int fd1 = open("./file1", O_RDWR|O_CREAT, 0644);
** int fd2 = open("./file2", O_RDWR|O_CREAT, 0644);
**
** Suppose ./file1 and ./file2 are really the same file (because
** one is a hard or symbolic link to the other) then if you set
** an exclusive lock on fd1, then try to get an exclusive lock
** on fd2, it works. I would have expected the second lock to
** fail since there was already a lock on the file due to fd1.
** But not so. Since both locks came from the same process, the
** second overrides the first, even though they were on different
** file descriptors opened on different file names.
**
** This means that we cannot use POSIX locks to synchronize file access
** among competing threads of the same process. POSIX locks will work fine
** to synchronize access for threads in separate processes, but not
** threads within the same process.
**
** To work around the problem, SQLite has to manage file locks internally
** on its own. Whenever a new database is opened, we have to find the
** specific inode of the database file (the inode is determined by the
** st_dev and st_ino fields of the stat structure that fstat() fills in)
** and check for locks already existing on that inode. When locks are
** created or removed, we have to look at our own internal record of the
** locks to see if another thread has previously set a lock on that same
** inode.
**
** (Aside: The use of inode numbers as unique IDs does not work on VxWorks.
** For VxWorks, we have to use the alternative unique ID system based on
** canonical filename and implemented in the previous division.)
**
** The sqlite3_file structure for POSIX is no longer just an integer file
** descriptor. It is now a structure that holds the integer file
** descriptor and a pointer to a structure that describes the internal
** locks on the corresponding inode. There is one locking structure
** per inode, so if the same inode is opened twice, both unixFile structures
** point to the same locking structure. The locking structure keeps
** a reference count (so we will know when to delete it) and a "cnt"
** field that tells us its internal lock status. cnt==0 means the
** file is unlocked. cnt==-1 means the file has an exclusive lock.
** cnt>0 means there are cnt shared locks on the file.
**
** Any attempt to lock or unlock a file first checks the locking
** structure. The fcntl() system call is only invoked to set a
** POSIX lock if the internal lock structure transitions between
** a locked and an unlocked state.
**
** But wait: there are yet more problems with POSIX advisory locks.
**
** If you close a file descriptor that points to a file that has locks,
** all locks on that file that are owned by the current process are
** released. To work around this problem, each unixInodeInfo object
** maintains a count of the number of pending locks on tha inode.
** When an attempt is made to close an unixFile, if there are
** other unixFile open on the same inode that are holding locks, the call
** to close() the file descriptor is deferred until all of the locks clear.
** The unixInodeInfo structure keeps a list of file descriptors that need to
** be closed and that list is walked (and cleared) when the last lock
** clears.
**
** Yet another problem: LinuxThreads do not play well with posix locks.
**
** Many older versions of linux use the LinuxThreads library which is
** not posix compliant. Under LinuxThreads, a lock created by thread
** A cannot be modified or overridden by a different thread B.
** Only thread A can modify the lock. Locking behavior is correct
** if the appliation uses the newer Native Posix Thread Library (NPTL)
** on linux - with NPTL a lock created by thread A can override locks
** in thread B. But there is no way to know at compile-time which
** threading library is being used. So there is no way to know at
** compile-time whether or not thread A can override locks on thread B.
** One has to do a run-time check to discover the behavior of the
** current process.
**
** SQLite used to support LinuxThreads. But support for LinuxThreads
** was dropped beginning with version 3.7.0. SQLite will still work with
** LinuxThreads provided that (1) there is no more than one connection
** per database file in the same process and (2) database connections
** do not move across threads.
label: code-design
synopsis: iplan=r[P3] zplan='P4'
** Virtual table structure.
Number of entries in array
The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
** following values.
**
** NOTE: These values must match the corresponding PAGER_ values in
** pager.h.
All tables indexed by name
Mark every PRIMARY KEY column as NOT NULL (except for imposter tables)
** If the cell pCell, part of page pPage contains a pointer
** to an overflow page, insert an entry into the pointer-map
** for the overflow page.
Write the database source cursor number here
One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT
True to omit the xSync on the db file
Base cost: N*3
YYDEBUG
First doclist
Table has a primary key
Mapping from ORDER BY terms to result set columns
Control reaches here if the candidate path is better than the
** pTo path. Replace pTo with the candidate.
This branch happens for multiple negative signs. Ex: -(-5)
Name context for container
Next cursor in Fts5Cursor.pCsr list
Connection holding shared memory
SQLITE_OMIT_TRIGGER
If the source page-size is smaller than the destination page-size,
** two extra things may need to happen:
**
** * The destination may need to be truncated, and
**
** * Data stored on the pages immediately following the
** pending-byte page in the source database may need to be
** copied into the destination database.
comment: WAL magic value. Either this value, or the same value with the least
** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
** big-endian format in the first 4 bytes of a WAL file.
**
** If the LSB is set, then the checksums for each frame within the WAL
** file are calculated by treating all data as an array of 32-bit
** big-endian words. Otherwise, they are calculated by interpreting
** all data as 32-bit little-endian words.
label: code-design
** Return the number of bytes required to store a JournalFile that uses vfs
** pVfs to create the underlying on-disk files.
Negative of the number of RHS symbols in the rule
** CAPI3REF: Prepared Statement Scan Status Opcodes
** KEYWORDS: {scanstatus options}
**
** The following constants can be used for the T parameter to the
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
** different metric for sqlite3_stmt_scanstatus() to return.
**
** When the value returned to V is a string, space to hold that string is
** managed by the prepared statement S and will be automatically freed when
** S is finalized.
**
** <dl>
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
** set to the total number of times that the X-th loop has run.</dd>
**
** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
** to the total number of rows examined by all iterations of the X-th loop.</dd>
**
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
** <dd>^The "double" variable pointed to by the T parameter will be set to the
** query planner's estimate for the average number of rows output from each
** iteration of the X-th loop. If the query planner's estimates was accurate,
** then this value will approximate the quotient NVISIT/NLOOP and the
** product of this value for all prior loops with the same SELECTID will
** be the NLOOP value for the current loop.
**
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
** <dd>^The "const char *" variable pointed to by the T parameter will be set
** to a zero-terminated UTF-8 string containing the name of the index or table
** used for the X-th loop.
**
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
** <dd>^The "const char *" variable pointed to by the T parameter will be set
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
** description for the X-th loop.
**
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
** <dd>^The "int" variable pointed to by the T parameter will be set to the
** "select-id" for the X-th loop. The select-id identifies which query or
** subquery the loop is part of. The main query has a select-id of zero.
** The select-id is the same value as is output in the first column
** of an [EXPLAIN QUERY PLAN] query.
** </dl>
** Lock the file with the lock specified by parameter eFileLock - one
** of the following:
**
** (1) SHARED_LOCK
** (2) RESERVED_LOCK
** (3) PENDING_LOCK
** (4) EXCLUSIVE_LOCK
**
** Sometimes when requesting one lock state, additional lock states
** are inserted in between. The locking might fail on one of the later
** transitions leaving the lock state different from what it started but
** still short of its goal. The following chart shows the allowed
** transitions and the inserted intermediate states:
**
** UNLOCKED -> SHARED
** SHARED -> RESERVED
** SHARED -> (PENDING) -> EXCLUSIVE
** RESERVED -> (PENDING) -> EXCLUSIVE
** PENDING -> EXCLUSIVE
**
** flock() only really support EXCLUSIVE locks. We track intermediate
** lock states in the sqlite3_file structure, but all locks SHARED or
** above are really EXCLUSIVE locks and exclude all other processes from
** access the file.
**
** This routine will only increase a lock. Use the sqlite3OsUnlock()
** routine to lower a locking level.
** Allowed return values from sqlite3FindInIndex()
Index.azColl
sign of significand
0 for normal table. 1 for WITHOUT ROWID table
Number of bytes in pList
nRefInitMutex
670
Frame data
Index of current sample accessed by stat_get()
OUT: Store cursor handle here
languageid=xxx option, or NULL
nexprlist
Table <table>.
Size of buffer pData in bytes
** Create and return a deep copy of the object passed as the second
** argument. If an OOM condition is encountered, NULL is returned
** and the db->mallocFailed flag set.
SQL Collation sequence name (eg. "japanese")
** True if heap is nearly "full" where "full" is defined by the
** sqlite3_soft_heap_limit() setting.
************* Begin file mutex.c ******************************************
Functions used to obtain and release page references.
** Maximum number of tokens a phrase may have to be considered for the
** incremental doclists strategy.
fall through
First arg for xInput
Open connection to the WAL file
Next free slot
PRAGMA index_xinfo (newer version with more rows and columns)
Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...)
Map from vector field to index column
True if a new wal-index header is loaded
** Virtual-table object.
** Apply the changeset passed via pChangeset/nChangeset to the main database
** attached to handle "db". Invoke the supplied conflict handler callback
** to resolve any conflicts encountered while applying the change.
VFS flags returned by xOpen()
If the source pager is currently in a write-transaction, return
** SQLITE_BUSY immediately.
IN/OUT: Previous value written to list
** The WHERE clause processing routine has two halves. The
** first part does the start of the WHERE loop and the second
** half does the tail of the WHERE loop. An instance of
** this structure is returned by the first half and passed
** into the second half to give some continuity.
**
** An instance of this object holds the complete state of the query
** planner.
** Rowid iRowid has just been appended to the current leaf page. It is the
** first on the page. This function appends an appropriate entry to the current
** doclist-index.
** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are
** numbered from zero.
**
** If this call is successful, *ppPage is set to point to the wal-index
** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
** then an SQLite error code is returned and *ppPage is set to 0.
Current overflow page number
Index to search (from 0 to p->nIndex-1)
Check that the doclist does not appear to extend past the end of the
** b-tree node. And that the final byte of the doclist is 0x00. If either
** of these statements is untrue, then the data structure is corrupt.
comment:
** This structure is used to implement an iterator that loops through
** all frames in the WAL in database page order. Where two or more frames
** correspond to the same database page, the iterator visits only the
** frame most recently written to the WAL (in other words, the frame with
** the largest index).
**
** The internals of this structure are only accessed by:
**
** walIteratorInit() - Create a new iterator,
** walIteratorNext() - Step an iterator,
** walIteratorFree() - Free an iterator.
**
** This functionality is used by the checkpoint code (see walCheckpoint()).
label: code-design
Register(s) holding the LHS values
True to truncate WAL file on commit
docid<=?
** Close all open savepoints. This function only manipulates fields of the
** database handle object, it does not close any savepoints that may be open
** at the b-tree/pager level.
** Skip over any TK_COLLATE operators and any unlikely()
** or likelihood() function at the root of an expression.
Invoked to set output variables.
Number of users of pInitMutex
** Object for iterating through the merged results of one or more segments,
** visiting each term/rowid pair in the merged data.
**
** nSeg is always a power of two greater than or equal to the number of
** segments that this object is merging data from. Both the aSeg[] and
** aFirst[] arrays are sized at nSeg entries. The aSeg[] array is padded
** with zeroed objects - these are handled as if they were iterators opened
** on empty segments.
**
** The results of comparing segments aSeg[N] and aSeg[N+1], where N is an
** even number, is stored in aFirst[(nSeg+N)/2]. The "result" of the
** comparison in this context is the index of the iterator that currently
** points to the smaller term/rowid combination. Iterators at EOF are
** considered to be greater than all other iterators.
**
** aFirst[1] contains the index in aSeg[] of the iterator that points to
** the smallest key overall. aFirst[0] is unused.
**
** poslist:
** Used by sqlite3Fts5IterPoslist() when the poslist needs to be buffered.
** There is no way to tell if this is populated or not.
True if not checked out
comment:
** This function is called whenever processing of the doclist for the
** last term on leaf page (pWriter->iBtPage) is completed.
**
** The doclist-index for that term is currently stored in-memory within the
** Fts5SegWriter.aDlidx[] array. If it is large enough, this function
** writes it out to disk. Or, if it is too small to bother with, discards
** it.
**
** Fts5SegWriter.btterm currently contains the first term on page iBtPage.
label: code-design
The ORDER BY clause or NULL
** Check the RTree node or entry given by pCellData and p against the MATCH
** constraint pConstraint.
** Allocate an Expr node which joins as many as two subtrees.
**
** One or both of the subtrees can be NULL. Return a pointer to the new
** Expr node. Or, if an OOM error occurs, set pParse->db->mallocFailed,
** free the subtrees and return NULL.
Only one writer allowed at a time. Get the write lock. Return
** SQLITE_BUSY if unable.
comment:
** Shutdown the operating system interface.
**
** Some operating systems might need to do some cleanup in this routine,
** to release dynamically allocated objects. But not on unix.
** This routine is a no-op for unix.
label: code-design
** CAPI3REF: String Globbing
*
** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
** string X matches the [GLOB] pattern P.
** ^The definition of [GLOB] pattern matching used in
** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function
** is case sensitive.
**
** Note that this routine returns zero on a match and non-zero if the strings
** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
**
** See also: [sqlite3_strlike()].
** Return coordinate iCoord from cell iCell in node pNode.
** Invoke this routine to register the "dbstat" virtual table module
Affinity for start of range constraint
Consider functions to be constant if all their arguments are constant
** and either pWalker->eCode==4 or 5 or the function has the
** SQLITE_FUNC_CONST flag.
Allocate space for the cursor, filter and writer objects
If required, populate the overflow page-list cache.
comment:
** This function is part of the fts5_decode() debugging function. It is
** only ever used with detail=none tables.
**
** Buffer (pData/nData) contains a doclist in the format used by detail=none
** tables. This function appends a human-readable version of that list to
** buffer pBuf.
**
** If *pRc is other than SQLITE_OK when this function is called, it is a
** no-op. If an OOM or other error occurs within this function, *pRc is
** set to an SQLite error code before returning. The final state of buffer
** pBuf is undefined in this case.
label: code-design
Start of BEFORE trigger programs
Read blob data into this buffer
OP_Destroy stores an in integer r1. If this integer
** is non-zero, then it is the root page number of a table moved to
** location iTable. The following code modifies the sqlite_master table to
** reflect this.
**
** The "#NNN" in the SQL is a special constant that means whatever value
** is in register NNN. See grammar rules associated with the TK_REGISTER
** token for additional information.
xDisconnect - Disconnect from a table
Range of registers holding conflicting PK
xLog
Do not sync the journal if true
context in which to report errors
Construct an expression node for a unary prefix operator
comment:
** Journal files begin with the following magic string. The data
** was obtained from /dev/random. It is used only as a sanity check.
**
** Since version 2.8.0, the journal format contains additional sanity
** checking information. If the power fails while the journal is being
** written, semi-random garbage data might appear in the journal
** file after power is restored. If an attempt is then made
** to roll the journal back, the database could be corrupted. The additional
** sanity checking data is an attempt to discover the garbage in the
** journal and ignore it.
**
** The sanity checking information for the new journal format consists
** of a 32-bit checksum on each page of data. The checksum covers both
** the page number and the pPager->pageSize bytes of data for the page.
** This cksum is initialized to a 32-bit random value that appears in the
** journal file right after the header. The random initializer is important,
** because garbage data that appears at the end of a journal is likely
** data that was once in other files that have now been deleted. If the
** garbage data came from an obsolete journal file, the checksums might
** be correct. But by initializing the checksum to random value which
** is different for every journal, we minimize that risk.
label: code-design
** Resolve all names for all expression in an expression list. This is
** just like sqlite3ResolveExprNames() except that it works for an expression
** list rather than a single expression.
Size of aInput[] in bytes
AUTOINCREMENT
** The winVfsAppData structure is used for the pAppData member for all of the
** Win32 VFS variants.
Used when flags==MEM_Frame
** The iterator currently points to a table (not index) of type
** RBU_PK_WITHOUT_ROWID. This function creates the PRIMARY KEY
** declaration for the corresponding imposter table. For example,
** if the iterator points to a table created as:
**
** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, a DESC)) WITHOUT ROWID
**
** this function returns:
**
** PRIMARY KEY("b", "a" DESC)
Identifiers have been resolved
aCell array
The first 8 memory cells are used for the result set. So we will
** commandeer the 9th cell to use as storage for an array of pointers
** to trigger subprograms. The VDBE is guaranteed to have at least 9
** cells.
EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
** twos-complement integer.
PK array for current table
** Figure out if we are dealing with Unix, Windows, or some other operating
** system.
**
** After the following block of preprocess macros, all of SQLITE_OS_UNIX,
** SQLITE_OS_WIN, and SQLITE_OS_OTHER will defined to either 1 or 0. One of
** the three will be 1. The other two will be 0.
** Close a statvfs cursor.
1
between_op ::= NOT BETWEEN
Bx
Destination for coroutine B
********************************* Linked List Management *******************
Language id used with tokenizer
** Extract the next token from buffer z (length n) using the tokenizer
** and other information (column names etc.) in pParse. Create an Fts3Expr
** structure of type FTSQUERY_PHRASE containing a phrase consisting of this
** single token and set *ppExpr to point to it. If the end of the buffer is
** reached before a token is found, set *ppExpr to zero. It is the
** responsibility of the caller to eventually deallocate the allocated
** Fts3Expr structure (if any) by passing it to sqlite3_free().
**
** Return SQLITE_OK if successful, or SQLITE_NOMEM if a memory allocation
** fails.
_SQLITE3RBU_H
... also used as column name list in a VIEW
Address of the select-B-exhausted subroutine
NEAR distance. As in "NEAR/nNear".
** Remove connection db from the blocked connections list. If connection
** db is not currently a part of the list, this function is a no-op.
SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE
Page to add cells to
** Build a trigger step out of an INSERT statement. Return a pointer
** to the new trigger step.
**
** The parser calls this routine when it sees an INSERT inside the
** body of a trigger.
Used to find the beginnings of sentences
random NFS retry error, unless during file system support
* introspection, in which it actually means what it says
Determine iLower and iUpper using ($P) only.
** Compare the term in buffer zLhs (size in bytes nLhs) with that in
** zRhs (size in bytes nRhs) using memcmp. If one term is a prefix of
** the other, it is considered to be smaller than the other.
**
** Return -ve if zLhs is smaller than zRhs, 0 if it is equal, or +ve
** if it is greater.
IN/OUT: Page content -area pointer
An index on pSrc
** Implementation of the scalar function icu_load_collation().
**
** This scalar function is used to add ICU collation based collation
** types to an SQLite database connection. It is intended to be called
** as follows:
**
** SELECT icu_load_collation(<locale>, <collation-name>);
**
** Where <locale> is a string containing an ICU locale identifier (i.e.
** "en_AU", "tr_TR" etc.) and <collation-name> is the name of the
** collation sequence to create.
** Space for tracking which blocks are checked out and the size
** of each block. One byte per block.
20
Some kind of disk I/O error occurred
The SELECT statement containing the ORDER BY
There should be at least one opcode.
Result is an aggregate
************* End of pcache.c *********************************************
comment: Database connection malloc context
label: code-design
Maximum JUMP opcode
Pointer to where zName will be stored
Jump here to break out of the loop
pOrderby is really a DISTINCT clause
TK_REGISTER: original value of Expr.op
** TK_COLUMN: the value of p5 for OP_Column
** TK_AGG_FUNCTION: nesting depth
comment:
** RowSetEntry objects are allocated in large chunks (instances of the
** following structure) to reduce memory allocation overhead. The
** chunks are kept on a linked list so that they can be deallocated
** when the RowSet is destroyed.
label: code-design
comment: The index to be tested for coverage
label: test
cellSizePtr method
Call stat() on path zIn. Set bLink to true if the path is a symbolic
** link, or false otherwise.
Reset and ready to run again
** This routine implements the OP_Vacuum opcode of the VDBE.
WhereClause currently being scanned
This column is allowed to be NULL
The AFFINITY() function evaluates to a string that describes
** the type affinity of the argument. This is used for testing of
** the SQLite type logic.
0x05
comment:
** This function is called on a MultiSegReader that has been started using
** sqlite3Fts3MsrIncrStart(). One or more calls to MsrIncrNext() may also
** have been made. Calling this function puts the MultiSegReader in such
** a state that if the next two calls are:
**
** sqlite3Fts3SegReaderStart()
** sqlite3Fts3SegReaderStep()
**
** then the entire doclist for the term is available in
** MultiSegReader.aDoclist/nDoclist.
label: code-design
Construct a new Expr object from a single identifier. Use the
** new Expr to populate pOut. Set the span of pOut to be the identifier
** that created the expression.
Unqualified name of the table to create
The average document size, which is required to calculate the cost
** of each doclist, has not yet been determined. Read the required
** data from the %_stat table to calculate it.
**
** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3
** varints, where nCol is the number of columns in the FTS3 table.
** The first varint is the number of documents currently stored in
** the table. The following nCol varints contain the total amount of
** data stored in all rows of each column of the table, from left
** to right.
If pReadr1 contained the smaller value, set aTree[i] to its index.
** Then set pReadr2 to the next PmaReader to compare to pReadr1. In this
** case there is no cache of pReadr2 in pTask->pUnpacked, so set
** pKey2 to point to the record belonging to pReadr2.
**
** Alternatively, if pReadr2 contains the smaller of the two values,
** set aTree[i] to its index and update pReadr1. If vdbeSorterCompare()
** was actually called above, then pTask->pUnpacked now contains
** a value equivalent to pReadr2. So set pKey2 to NULL to prevent
** vdbeSorterCompare() from decoding pReadr2 again.
**
** If the two values were equal, then the value from the oldest
** PMA should be considered smaller. The VdbeSorter.aReadr[] array
** is sorted from oldest to newest, so pReadr1 contains older values
** than pReadr2 iff (pReadr1<pReadr2).
ShallowCopy only needs to copy the information above
** The MSVCRT has malloc_usable_size(), but it is called _msize(). The
** use of _msize() is automatic, but can be disabled by compiling with
** -DSQLITE_WITHOUT_MSIZE. Using the _msize() function also requires
** the malloc.h header file.
fullname
Length of string zMaster
pParse->nQueryLoop outside the WHERE loop
Description of the substitution
Various PAGER_* flags
************* Begin file sqlite3.h ****************************************
************* Begin file wherecode.c **************************************
** Free all components of the Fts3Phrase structure that were allocated by
** the eval module. Specifically, this means to free:
**
** * the contents of pPhrase->doclist, and
** * any Fts3MultiSegReader objects held by phrase tokens.
COLUMN or TABLE.COLUMN if no AS clause and is direct
Index of column this phrase must match
Drop the temporary PENDING lock
aLoop[]s that should be reversed for ORDER BY
Number of elements in aList
** Memory available for allocation. nPool is the size of the array
** (in Mem3Blocks) pointed to by aPool less 2.
One for each column cache entry
** Obtain a reference to a memory mapped page object for page number pgno.
** The new object will use the pointer pData, obtained from xFetch().
** If successful, set *ppPage to point to the new page reference
** and return SQLITE_OK. Otherwise, return an SQLite error code and set
** *ppPage to zero.
**
** Page references obtained by calling this function should be released
** by calling pagerReleaseMapPage().
** Show the complete content of a WhereClause
53
The trunk page is required by the caller but it contains
** pointers to free-list leaves. The first leaf becomes a trunk
** page in this case.
tFromCol = OLD.tToCol
Prepared statement being queried
.uTemp =
** This function is used to write a single varint to a buffer. The varint
** is written to *pp. Before returning, *pp is set to point 1 byte past the
** end of the value written.
**
** If *pbFirst is zero when this function is called, the value written to
** the buffer is that of parameter iVal.
**
** If *pbFirst is non-zero when this function is called, then the value
** written is either (iVal-*piPrev) (if bDescIdx is zero) or (*piPrev-iVal)
** (if bDescIdx is non-zero).
**
** Before returning, this function always sets *pbFirst to 1 and *piPrev
** to the value of parameter iVal.
Must be count()
Array of OP_Once flags
Text of the CREATE TABLE or CREATE VIEW statement
A-overwrites-C
comment: Sizes of inserted documents
label: documentation
.... doubly linked
Amount to pop the stack
Both are UTF16, but with different byte orders
ONEPASS is valid for multiple rows
The memory locations
sqlite3_file methods
0123456789 123456789 123456789 123
IN/OUT: Mask of tokens to highlight
Buffer containing current poslist
Binding to these vars invalidates VM
comment:
** When a cached column is reused, make sure that its register is
** no longer available as a temp register. ticket #3879: that same
** register might be in the cache in multiple places, so be sure to
** get them all.
label: code-design
** CAPI3REF: Checkpoint a database
** METHOD: sqlite3
**
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
** operation on database X of [database connection] D in mode M. Status
** information is written back into integers pointed to by L and C.)^
** ^(The M parameter must be a valid [checkpoint mode]:)^
**
** <dl>
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
** ^Checkpoint as many frames as possible without waiting for any database
** readers or writers to finish, then sync the database file if all frames
** in the log were checkpointed. ^The [busy-handler callback]
** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
** ^On the other hand, passive mode might leave the checkpoint unfinished
** if there are concurrent readers or writers.
**
** <dt>SQLITE_CHECKPOINT_FULL<dd>
** ^This mode blocks (it invokes the
** [sqlite3_busy_handler|busy-handler callback]) until there is no
** database writer and all readers are reading from the most recent database
** snapshot. ^It then checkpoints all frames in the log file and syncs the
** database file. ^This mode blocks new database writers while it is pending,
** but new database readers are allowed to continue unimpeded.
**
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
** that after checkpointing the log file it blocks (calls the
** [busy-handler callback])
** until all readers are reading from the database file only. ^This ensures
** that the next writer will restart the log file from the beginning.
** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
** database writer attempts while it is pending, but does not impede readers.
**
** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
** addition that it also truncates the log file to zero bytes just prior
** to a successful return.
** </dl>
**
** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
** the log file or to -1 if the checkpoint could not run because
** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
** log file (including any that were already checkpointed before the function
** was called) or to -1 if the checkpoint could not run due to an error or
** because the database is not in WAL mode. ^Note that upon successful
** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
**
** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
** any other process is running a checkpoint operation at the same time, the
** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
** busy-handler configured, it will not be invoked in this case.
**
** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
** exclusive "writer" lock on the database file. ^If the writer lock cannot be
** obtained immediately, and a busy-handler is configured, it is invoked and
** the writer lock retried until either the busy-handler returns 0 or the lock
** is successfully obtained. ^The busy-handler is also invoked while waiting for
** database readers as described above. ^If the busy-handler returns 0 before
** the writer lock is obtained or while waiting for database readers, the
** checkpoint operation proceeds from that point in the same way as
** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
** without blocking any further. ^SQLITE_BUSY is returned in this case.
**
** ^If parameter zDb is NULL or points to a zero length string, then the
** specified operation is attempted on all WAL databases [attached] to
** [database connection] db. In this case the
** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
** an SQLITE_BUSY error is encountered when processing one or more of the
** attached WAL databases, the operation is still attempted on any remaining
** attached databases and SQLITE_BUSY is returned at the end. ^If any other
** error occurs while processing an attached database, processing is abandoned
** and the error code is returned to the caller immediately. ^If no error
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
** databases, SQLITE_OK is returned.
**
** ^If database zDb is the name of an attached database that is not in WAL
** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
** zDb is not NULL (or a zero length string) and is not the name of any
** attached database, SQLITE_ERROR is returned to the caller.
**
** ^Unless it returns SQLITE_MISUSE,
** the sqlite3_wal_checkpoint_v2() interface
** sets the error information that is queried by
** [sqlite3_errcode()] and [sqlite3_errmsg()].
**
** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
** from SQL.
********* Begin reduce actions *********************************************
Number of entries in apSub
Check that the sort worked
** This function is called as part of a SorterRewind() operation on a sorter
** that has already written two or more level-0 PMAs to one or more temp
** files. It builds a tree of MergeEngine/IncrMerger/PmaReader objects that
** can be used to incrementally merge all PMAs on disk.
**
** If successful, SQLITE_OK is returned and *ppOut set to point to the
** MergeEngine object at the root of the tree before returning. Or, if an
** error occurs, an SQLite error code is returned and the final value
** of *ppOut is undefined.
Unknown opcode in sqlite3_file_control()
SQLITE_COUNTOFVIEW_OPTIMIZATION
Write error here if one occurs
Value of apPage[0]->intKey
Output pointer
In debug mode, we mark all persistent databases as sharable
** even when they are not. This exercises the locking code and
** gives more opportunity for asserts(sqlite3_mutex_held())
** statements to find locking problems.
Allocate or grow the PendingList as required.
Next frame to read from wal file
The 3-byte case
410
Value is a VdbeFrame object
COMMIT
Set defaults for non-supported filesystems
Table handle
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of the page cache subsystem or "pager".
**
** The pager is used to access a database disk file. It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file. The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
Specific chunk into which cursor points
Buffer to a append to
** chng_addr_0:
** regPrev(0) = idx(0)
** chng_addr_1:
** regPrev(1) = idx(1)
** ...
Reference to page 1
Array to write results into (see above)
This branch is taken if an error occurs while trying to open
** or roll back a hot-journal while holding an EXCLUSIVE lock. The
** pager_unlock() routine will be called before returning to unlock
** the file. If the unlock attempt fails, then Pager.eLock must be
** set to UNKNOWN_LOCK (see the comment above the #define for
** UNKNOWN_LOCK above for an explanation).
**
** In order to get pager_unlock() to do this, set Pager.eState to
** PAGER_ERROR now. This is not actually counted as a transition
** to ERROR state in the state diagram at the top of this file,
** since we know that the same call to pager_unlock() will very
** shortly transition the pager object to the OPEN state. Calling
** assert_pager_state() would fail now, as it should not be possible
** to be in ERROR state when there are zero outstanding page
** references.
IN/OUT: True after first int written
Size of zPattern
comment: For length() and typeof() functions with a column argument,
** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
** loading.
label: code-design
Return an integer that records the current (uncommitted) write
** position in the WAL
Language id to use in tokenizing
** An "etByte" is an 8-bit unsigned value.
Address of the next freeblock
Name context for pParse->pNewTable
schema
Low-level memory allocation interface
Sanity checking: The schema for the trigger and for the table are
** always defined. The trigger must be in the same schema as the table
** or else it must be a TEMP trigger.
Merge engine containing PmaReaders to compare
Page number of pNew
"?" or "_"
'='. Part of = or ==
P4_STATIC or P4_TRANSIENT
Number of cells on page
Floating or exponential, depending on exponent. %g
Status return flags
Pointer to string from which to read char
** The Pager.eState variable stores the current 'state' of a pager. A
** pager may be in any one of the seven states shown in the following
** state diagram.
**
** OPEN <------+------+
** | | |
** V | |
** +---------> READER-------+ |
** | | |
** | V |
** |<-------WRITER_LOCKED------> ERROR
** | | ^
** | V |
** |<------WRITER_CACHEMOD-------->|
** | | |
** | V |
** |<-------WRITER_DBMOD---------->|
** | | |
** | V |
** +<------WRITER_FINISHED-------->+
**
**
** List of state transitions and the C [function] that performs each:
**
** OPEN -> READER [sqlite3PagerSharedLock]
** READER -> OPEN [pager_unlock]
**
** READER -> WRITER_LOCKED [sqlite3PagerBegin]
** WRITER_LOCKED -> WRITER_CACHEMOD [pager_open_journal]
** WRITER_CACHEMOD -> WRITER_DBMOD [syncJournal]
** WRITER_DBMOD -> WRITER_FINISHED [sqlite3PagerCommitPhaseOne]
** WRITER_*** -> READER [pager_end_transaction]
**
** WRITER_*** -> ERROR [pager_error]
** ERROR -> OPEN [pager_unlock]
**
**
** OPEN:
**
** The pager starts up in this state. Nothing is guaranteed in this
** state - the file may or may not be locked and the database size is
** unknown. The database may not be read or written.
**
** * No read or write transaction is active.
** * Any lock, or no lock at all, may be held on the database file.
** * The dbSize, dbOrigSize and dbFileSize variables may not be trusted.
**
** READER:
**
** In this state all the requirements for reading the database in
** rollback (non-WAL) mode are met. Unless the pager is (or recently
** was) in exclusive-locking mode, a user-level read transaction is
** open. The database size is known in this state.
**
** A connection running with locking_mode=normal enters this state when
** it opens a read-transaction on the database and returns to state
** OPEN after the read-transaction is completed. However a connection
** running in locking_mode=exclusive (including temp databases) remains in
** this state even after the read-transaction is closed. The only way
** a locking_mode=exclusive connection can transition from READER to OPEN
** is via the ERROR state (see below).
**
** * A read transaction may be active (but a write-transaction cannot).
** * A SHARED or greater lock is held on the database file.
** * The dbSize variable may be trusted (even if a user-level read
** transaction is not active). The dbOrigSize and dbFileSize variables
** may not be trusted at this point.
** * If the database is a WAL database, then the WAL connection is open.
** * Even if a read-transaction is not open, it is guaranteed that
** there is no hot-journal in the file-system.
**
** WRITER_LOCKED:
**
** The pager moves to this state from READER when a write-transaction
** is first opened on the database. In WRITER_LOCKED state, all locks
** required to start a write-transaction are held, but no actual
** modifications to the cache or database have taken place.
**
** In rollback mode, a RESERVED or (if the transaction was opened with
** BEGIN EXCLUSIVE) EXCLUSIVE lock is obtained on the database file when
** moving to this state, but the journal file is not written to or opened
** to in this state. If the transaction is committed or rolled back while
** in WRITER_LOCKED state, all that is required is to unlock the database
** file.
**
** IN WAL mode, WalBeginWriteTransaction() is called to lock the log file.
** If the connection is running with locking_mode=exclusive, an attempt
** is made to obtain an EXCLUSIVE lock on the database file.
**
** * A write transaction is active.
** * If the connection is open in rollback-mode, a RESERVED or greater
** lock is held on the database file.
** * If the connection is open in WAL-mode, a WAL write transaction
** is open (i.e. sqlite3WalBeginWriteTransaction() has been successfully
** called).
** * The dbSize, dbOrigSize and dbFileSize variables are all valid.
** * The contents of the pager cache have not been modified.
** * The journal file may or may not be open.
** * Nothing (not even the first header) has been written to the journal.
**
** WRITER_CACHEMOD:
**
** A pager moves from WRITER_LOCKED state to this state when a page is
** first modified by the upper layer. In rollback mode the journal file
** is opened (if it is not already open) and a header written to the
** start of it. The database file on disk has not been modified.
**
** * A write transaction is active.
** * A RESERVED or greater lock is held on the database file.
** * The journal file is open and the first header has been written
** to it, but the header has not been synced to disk.
** * The contents of the page cache have been modified.
**
** WRITER_DBMOD:
**
** The pager transitions from WRITER_CACHEMOD into WRITER_DBMOD state
** when it modifies the contents of the database file. WAL connections
** never enter this state (since they do not modify the database file,
** just the log file).
**
** * A write transaction is active.
** * An EXCLUSIVE or greater lock is held on the database file.
** * The journal file is open and the first header has been written
** and synced to disk.
** * The contents of the page cache have been modified (and possibly
** written to disk).
**
** WRITER_FINISHED:
**
** It is not possible for a WAL connection to enter this state.
**
** A rollback-mode pager changes to WRITER_FINISHED state from WRITER_DBMOD
** state after the entire transaction has been successfully written into the
** database file. In this state the transaction may be committed simply
** by finalizing the journal file. Once in WRITER_FINISHED state, it is
** not possible to modify the database further. At this point, the upper
** layer must either commit or rollback the transaction.
**
** * A write transaction is active.
** * An EXCLUSIVE or greater lock is held on the database file.
** * All writing and syncing of journal and database data has finished.
** If no error occurred, all that remains is to finalize the journal to
** commit the transaction. If an error did occur, the caller will need
** to rollback the transaction.
**
** ERROR:
**
** The ERROR state is entered when an IO or disk-full error (including
** SQLITE_IOERR_NOMEM) occurs at a point in the code that makes it
** difficult to be sure that the in-memory pager state (cache contents,
** db size etc.) are consistent with the contents of the file-system.
**
** Temporary pager files may enter the ERROR state, but in-memory pagers
** cannot.
**
** For example, if an IO error occurs while performing a rollback,
** the contents of the page-cache may be left in an inconsistent state.
** At this point it would be dangerous to change back to READER state
** (as usually happens after a rollback). Any subsequent readers might
** report database corruption (due to the inconsistent cache), and if
** they upgrade to writers, they may inadvertently corrupt the database
** file. To avoid this hazard, the pager switches into the ERROR state
** instead of READER following such an error.
**
** Once it has entered the ERROR state, any attempt to use the pager
** to read or write data returns an error. Eventually, once all
** outstanding transactions have been abandoned, the pager is able to
** transition back to OPEN state, discarding the contents of the
** page-cache and any other in-memory state at the same time. Everything
** is reloaded from disk (and, if necessary, hot-journal rollback peformed)
** when a read-transaction is next opened on the pager (transitioning
** the pager into READER state). At that point the system has recovered
** from the error.
**
** Specifically, the pager jumps into the ERROR state if:
**
** 1. An error occurs while attempting a rollback. This happens in
** function sqlite3PagerRollback().
**
** 2. An error occurs while attempting to finalize a journal file
** following a commit in function sqlite3PagerCommitPhaseTwo().
**
** 3. An error occurs while attempting to write to the journal or
** database file in function pagerStress() in order to free up
** memory.
**
** In other cases, the error is returned to the b-tree layer. The b-tree
** layer then attempts a rollback operation. If the error condition
** persists, the pager enters the ERROR state via condition (1) above.
**
** Condition (3) is necessary because it can be triggered by a read-only
** statement executed within a transaction. In this case, if the error
** code were simply returned to the user, the b-tree layer would not
** automatically attempt a rollback, as it assumes that an error in a
** read-only statement cannot leave the pager in an internally inconsistent
** state.
**
** * The Pager.errCode variable is set to something other than SQLITE_OK.
** * There are one or more outstanding references to pages (after the
** last reference is dropped the pager should move back to OPEN state).
** * The pager is not an in-memory pager.
**
**
** Notes:
**
** * A pager is never in WRITER_DBMOD or WRITER_FINISHED state if the
** connection is open in WAL mode. A WAL connection is always in one
** of the first four states.
**
** * Normally, a connection open in exclusive mode is never in PAGER_OPEN
** state. There are two exceptions: immediately after exclusive-mode has
** been turned on (and before any read or write transactions are
** executed), and when the pager is leaving the "error state".
**
** * See also: assert_pager_state().
comment:
** Return a pointer to a buffer containing the term associated with the
** entry that the iterator currently points to.
label: code-design
Next in list of deferred tokens
xCommit - commit transaction
If there are any write-transactions at all, invoke the commit hook
True if aLeft[] contains PK fields only
Saved LIMIT and OFFSET
Address to jump to for next iteration
comment: Docid of most recently inserted document
label: documentation
Number of result columns written here
If we get this far, it means that the reader will want to use
** the WAL to get at content from recent commits. The job now is
** to select one of the aReadMark[] entries that is closest to
** but not exceeding pWal->hdr.mxFrame and lock that entry.
Cursor pointing at record to retrieve.
comment: Process the ORDER BY clause for singleton SELECT statements.
** The ORDER BY clause for compounds SELECT statements is handled
** below, after all of the result-sets for all of the elements of
** the compound have been resolved.
**
** If there is an ORDER BY clause on a term of a compound-select other
** than the right-most term, then that is a syntax error. But the error
** is not detected until much later, and so we need to go ahead and
** resolve those symbols on the incorrect ORDER BY for consistency.
label: code-design
Initial value of pParse->pWith
The page being analyzed
Figure out how much space the key will consume if it is written to
** the current node of layer iLayer. Due to the prefix compression,
** the space required changes depending on which node the key is to
** be added to.
** Change the lock state for a shared-memory segment.
Vdbe
Priority queue for search points
Search TEMP before MAIN
** Return true if expression pExpr is a vector, or false otherwise.
**
** A vector is defined as any expression that results in two or more
** columns of result. Every TK_VECTOR node is an vector because the
** parser will not generate a TK_VECTOR with fewer than two entries.
** But a TK_SELECT might be either a vector or a scalar. It is only
** considered a vector if it has two or more result columns.
** Return the value of the 'auto-vacuum' property. If auto-vacuum is
** enabled 1 is returned. Otherwise 0.
SQLITE_CORE
# include "sqlite3ext.h"
Range constraints on queries
If the magic name ":memory:" will create an in-memory database, then
** leave the autoVacuum mode at 0 (do not auto-vacuum), even if
** SQLITE_DEFAULT_AUTOVACUUM is true. On the other hand, if
** SQLITE_OMIT_MEMORYDB has been defined, then ":memory:" is just a
** regular file-name. In this case the auto-vacuum applies as per normal.
as ::=
Data actually written
************* Begin file sqlite3rbu.c *************************************
Output should be DISTINCT
True if an incremental I/O handle
Compute successively longer WherePaths using the previous generation
** of WherePaths as the basis for the next. Keep track of the mxChoice
** best paths at each generation
Number of memory registers for sub-program
comment: If iLevel is less than 0 and this is not a scan, include a seg-reader
** for the pending-terms. If this is a scan, then this call must be being
** made by an fts4aux module, not an FTS table. In this case calling
** Fts3SegReaderPending might segfault, as the data structures used by
** fts4aux are not completely populated. So it's easiest to filter these
** calls out here.
label: code-design
************* Begin file mem0.c *******************************************
HAVE_READLINK && HAVE_LSTAT
ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE
** The parser calls this routine after the CREATE VIRTUAL TABLE statement
** has been completely parsed.
Return a pointer to the allocated memory.
************* Begin file btreeInt.h ***************************************
The GROUP BY clause. May be NULL
Do whatever the default action is
SQLITE_OMIT_CTE
If the cache is already full, delete the least recently used entry
************* Begin file os_setup.h ***************************************
Root of tree
Advance pointer p until it points to pEnd or an 0x01 byte that is
** not part of a varint. Note that it is not possible for a negative
** or extremely large varint to occur within an uncorrupted position
** list. So the last byte of each varint may be assumed to have a clear
** 0x80 bit.
ACTION
Counting column references
For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and
** OP_SeekLE opcodes are allowed, and these must be immediately followed
** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key.
Make any required updates to pointer map entries associated with
** cells stored on sibling pages following the balance operation. Pointer
** map entries associated with divider cells are set by the insertCell()
** routine. The associated pointer map entries are:
**
** a) if the cell contains a reference to an overflow chain, the
** entry associated with the first page in the overflow chain, and
**
** b) if the sibling pages are not leaves, the child page associated
** with the cell.
**
** If the sibling pages are not leaves, then the pointer map entry
** associated with the right-child of each sibling may also need to be
** updated. This happens below, after the sibling pages have been
** populated, not here.
The trunk has no leaves and the list is not being searched.
** So extract the trunk page itself and use it as the newly
** allocated page
Test all NOT NULL constraints.
comment: Temporary space to use
label: code-design
The JSON to search
Pointer p now points at the first byte past the varint we are
** interested in. So, unless the doclist is corrupt, the 0x80 bit is
** clear on character p[-1].
The operand, and output
** Initialize and deinitialize the mutex subsystem.
** Return the address of the next instruction to be inserted.
Pointer to node data (or NULL)
Database size after this commit
IN_INDEX_LOOP, _MEMBERSHIP, and/or _NOOP_OK
** The following object holds the list of automatically loaded
** extensions.
**
** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
** mutex must be held while accessing this list.
** Input "r" is a numeric quantity which might be a julian day number,
** or the number of seconds since 1970. If the value if r is within
** range of a julian day number, install it as such and set validJD.
** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
xUpdate - write data
Text of the SQL statement
Parent context (if any)
940
transtype ::= IMMEDIATE
** Added for 3.6.0
If not NULL: boolean for each table and index
Set the BtLock.eLock variable to the maximum of the current lock
** and the requested lock. This means if a write-lock was already held
** and a read-lock requested, we don't incorrectly downgrade the lock.
65
SQLITE_PERM
8
Number of bytes actually read from file
Forward declaration
OUT: Result
Normally, if a transaction is rolled back, any backup processes are
** updated as data is copied out of the rollback journal and into the
** database. This is not generally possible with a WAL database, as
** rollback involves simply truncating the log file. Therefore, if one
** or more frames have already been written to the log (and therefore
** also copied into the backup databases) as part of this transaction,
** the backups must be restarted.
nCol*nPhrase values
(279) trans_opt ::= TRANSACTION
VIEW => ID
** The following set of routines walk through the parse tree and assign
** a specific database to all table references where the database name
** was left unspecified in the original SQL statement. The pFix structure
** must have been initialized by a prior call to sqlite3FixInit().
**
** These routines are used to make sure that an index, trigger, or
** view in one database does not refer to objects in a different database.
** (Exception: indices, triggers, and views in the TEMP database are
** allowed to refer to anything.) If a reference is explicitly made
** to an object in a different database, an error message is added to
** pParse->zErrMsg and these routines return non-zero. If everything
** checks out, these routines return 0.
Next in hash table chain
Content is text with \ escapes
DELETE operations
Number of times lookaside has been disabled
comment:
** The following array of hash tables is used to buffer pending index
** updates during transactions. All pending updates buffered at any one
** time must share a common language-id (see the FTS4 langid= feature).
** The current language id is stored in variable iPrevLangid.
**
** A single FTS4 table may have multiple full-text indexes. For each index
** there is an entry in the aIndex[] array. Index 0 is an index of all the
** terms that appear in the document set. Each subsequent index in aIndex[]
** is an index of prefixes of a specific length.
**
** Variable nPendingData contains an estimate the memory consumed by the
** pending data structures, including hash table overhead, but not including
** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash
** tables are flushed to disk. Variable iPrevDocid is the docid of the most
** recently inserted record.
label: code-design
** This function returns non-zero if the specified UTF-8 string buffer
** ends with a directory separator character or one was successfully
** added to it.
Verify that the call to _bytes() does not invalidate the _text() pointer
OUT: *pzToken is the token text
limit_opt ::= LIMIT expr OFFSET expr
If the SQL column is blank it means this is an index that
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
** constraint for a CREATE TABLE. The index should have already
** been created when we processed the CREATE TABLE. All we have
** to do here is record the root page number for that index.
Read-only system table
VM being constructed
** Open a new Fts5Index handle. If the bCreate argument is true, create
** and initialize the underlying %_data table.
**
** If successful, set *pp to point to the new object and return SQLITE_OK.
** Otherwise, set *pp to NULL and return an SQLite error code.
** Obtain the mutex p. If some other thread already has the mutex, block
** until it can be obtained.
************* Begin file hash.c *******************************************
Text encoding - one of the SQLITE_UTF* values
** Compute a 32-bit checksum on the N-byte buffer. Return the result.
Fixer object
Suspicious pointer arithmetic
The X expression
Opcode: IdxGE P1 P2 P3 P4 P5
** Synopsis: key=r[P3@P4]
**
** The P4 register values beginning with P3 form an unpacked index
** key that omits the PRIMARY KEY. Compare this key value against the index
** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
** fields at the end.
**
** If the P1 index entry is greater than or equal to the key value
** then jump to P2. Otherwise fall through to the next instruction.
** Read a single varint from the doclist at *pp and advance *pp to point
** to the first byte past the end of the varint. Add the value of the varint
** to *pVal.
Allocate space for a new sqlite3_backup object...
** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
** call to sqlite3_backup_init() and is destroyed by a call to
** sqlite3_backup_finish().
selcollist ::= sclp expr as
Column name
** This function is called as the second part of each xNext operation when
** iterating through the results of a full-text query. At this point the
** cursor points to a row that matches the query expression, with the
** following caveats:
**
** * Up until this point, "NEAR" operators in the expression have been
** treated as "AND".
**
** * Deferred tokens have not yet been considered.
**
** If *pRc is not SQLITE_OK when this function is called, it immediately
** returns 0. Otherwise, it tests whether or not after considering NEAR
** operators and deferred tokens the current row is still a match for the
** expression. It returns 1 if both of the following are true:
**
** 1. *pRc is SQLITE_OK when this function returns, and
**
** 2. After scanning the current FTS table row for the deferred tokens,
** it is determined that the row does *not* match the query.
**
** Or, if no error occurs and it seems the current row does match the FTS
** query, return 0.
sign * significand * (10 ^ (esign * exponent))
Use a new PGroup for each PCache
Object describing the transient index
Used to verify lookaside not used for schema
Opcode: RowSetTest P1 P2 P3 P4
** Synopsis: if r[P3] in rowset(P1) goto P2
**
** Register P3 is assumed to hold a 64-bit integer value. If register P1
** contains a RowSet object and that RowSet object contains
** the value held in P3, jump to register P2. Otherwise, insert the
** integer in P3 into the RowSet and continue on to the
** next opcode.
**
** The RowSet object is optimized for the case where sets of integers
** are inserted in distinct phases, which each set contains no duplicates.
** Each set is identified by a unique P4 value. The first set
** must have P4==0, the final set must have P4==-1, and for all other sets
** must have P4>0.
**
** This allows optimizations: (a) when P4==0 there is no need to test
** the RowSet object for P3, as it is guaranteed not to contain it,
** (b) when P4==-1 there is no need to insert the value, as it will
** never be tested for, and (c) when a value that is part of set X is
** inserted, there is no need to search to see if the same value was
** previously inserted as part of set X (only if it was previously
** inserted as part of some other set).
303
Token identifying trigger
Step 5a
************* Begin file memjournal.c *************************************
** Free an allocated buffer obtained from pcache1Alloc().
Make sure the output register has a buffer large enough to store
** the new record. The output register (pOp->p3) is not allowed to
** be one of the input registers (because the following call to
** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
** Release a MemPage. This should be called once for each prior
** call to btreeGetPage.
The affinity to be applied
comment:
** Change the page size used by the Pager object. The new page size
** is passed in *pPageSize.
**
** If the pager is in the error state when this function is called, it
** is a no-op. The value returned is the error state error code (i.e.
** one of SQLITE_IOERR, an SQLITE_IOERR_xxx sub-code or SQLITE_FULL).
**
** Otherwise, if all of the following are true:
**
** * the new page size (value of *pPageSize) is valid (a power
** of two between 512 and SQLITE_MAX_PAGE_SIZE, inclusive), and
**
** * there are no outstanding page references, and
**
** * the database is either not an in-memory database or it is
** an in-memory database that currently consists of zero pages.
**
** then the pager object page size is set to *pPageSize.
**
** If the page size is changed, then this function uses sqlite3PagerMalloc()
** to obtain a new Pager.pTmpSpace buffer. If this allocation attempt
** fails, SQLITE_NOMEM is returned and the page size remains unchanged.
** In all other cases, SQLITE_OK is returned.
**
** If the page size is not changed, either because one of the enumerated
** conditions above is not true, the pager was in error state when this
** function was called, or because the memory allocation attempt failed,
** then *pPageSize is set to the old, retained page size before returning.
label: code-design
Ticket #3810.
** Normally, whenever a table is dropped, all associated triggers are
** dropped too. But if a TEMP trigger is created on a non-TEMP table
** and the table is dropped by a different database connection, the
** trigger is not visible to the database connection that does the
** drop so the trigger cannot be dropped. This results in an
** "orphaned trigger" - a trigger whose associated table is missing.
eidlist ::= nm collate sortorder
This table's current rowid value
Append the name of the path for element i to pStr
True if a temp table was used
d8..df ........
Cursor object
** Check the internal RTree node given by pCellData against constraint p.
** If this constraint cannot be satisfied by any child within the node,
** set *peWithin to NOT_WITHIN.
** Take or release a shared-memory lock.
x IS NULL
IMP: R-04460-53386
** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
The value of the "rank" column.
comment:
** Return TRUE if all of the following are true:
**
** (1) X has the same or lower cost that Y
** (2) X is a proper subset of Y
** (3) X skips at least as many columns as Y
**
** By "proper subset" we mean that X uses fewer WHERE clause terms
** than Y and that every WHERE clause term used by X is also used
** by Y.
**
** If X is a proper subset of Y then Y is a better choice and ought
** to have a lower cost. This routine returns TRUE when that cost
** relationship is inverted and needs to be adjusted. The third rule
** was added because if X uses skip-scan less than Y it still might
** deserve a lower cost even if it is a proper subset of Y.
label: code-design
True to use a bg thread for this object
Write the contents of the page out to the database file.
Opcode: VNext P1 P2 * * *
**
** Advance virtual table P1 to the next row in its result set and
** jump to instruction P2. Or, if the virtual table has reached
** the end of its result set, then fall through to the next instruction.
Write a frame or frames to the log.
** This routine is a no-op if the database schema is already initialized.
** Otherwise, the schema is loaded. An error code is returned.
Cannot insert into a read-only table.
Copy of sixth arg to _apply()
A single database
Neither the RHS or LHS are deferred.
Cursor is pointing ot the last entry
"PRAGMA index_list" includes the main PK b-tree
For looping through nTerm phrase terms
Only truncate if it is an in-memory sub-journal.
Never gets this far otherwise
Justification of ALWAYS(): The xConstructor method is required to
** create a valid sqlite3_vtab if it returns SQLITE_OK.
Unpacked version of aRecord[]
comment: INSTEAD OF triggers can only appear on views and BEFORE triggers
** cannot appear on views. So we might as well translate every
** INSTEAD OF trigger into a BEFORE trigger. It simplifies code
** elsewhere.
label: code-design
** Return the number of values available from the current row of the
** currently executing statement pStmt.
"SELECT *" statement on zTbl
1 for STAT3 or STAT4. 0 otherwise
Number of RBU VFS in the stack
** Delete any previous value and set the value stored in *pMem to val,
** manifest type INTEGER.
The jrnlEnc flag is true if Journal pages should be passed through
** the codec. It is false for pure in-memory journals.
** Do the work for either sqlite3changeset_start() or start_strm().
file-mapping handle
Skip over the 'height' varint that occurs at the start of every
** interior node. Then load the blockid of the left-child of the b-tree
** node into variable iChild.
**
** Even if the data structure on disk is corrupted, this (reading two
** varints from the buffer) does not risk an overread. If zNode is a
** root node, then the buffer comes from a SELECT statement. SQLite does
** not make this guarantee explicitly, but in practice there are always
** either more than 20 bytes of allocated space following the nNode bytes of
** contents, or two zero bytes. Or, if the node is read from the %_segments
** table, then there are always 20 bytes of zeroed padding following the
** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
TUNING: Minimum for skip-scan
Id of this connection with its winShmNode
** Set the auxiliary data pointer and delete function, for the iArg'th
** argument to the user-function defined by pCtx. Any previous value is
** deleted by calling the delete function specified when it was set.
**
** The left-most argument is 0.
**
** Undocumented behavior: If iArg is negative then make the data available
** to all functions within the current prepared statement using iArg as an
** access code.
Opcode: IfNot P1 P2 P3 * *
**
** Jump to P2 if the value in register P1 is False. The value
** is considered false if it has a numeric value of zero. If the value
** in P1 is NULL then take the jump if and only if P3 is non-zero.
Right-hand Fts5SegIter
550
tab2 must not be a virtual table
comment:
**
** This function - unixLogErrorAtLine(), is only ever called via the macro
** unixLogError().
**
** It is invoked after an error occurs in an OS function and errno has been
** set. It logs a message using sqlite3_log() containing the current value of
** errno and, if possible, the human-readable equivalent from strerror() or
** strerror_r().
**
** The first argument passed to the macro should be the error code that
** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN).
** The two subsequent arguments should be the name of the OS function that
** failed (e.g. "unlink", "open") and the associated file-system path,
** if any.
label: code-design
sqlite3GetFuncCollSeq() might be called
Make sure at least the first p2+1 entries of the header have been
** parsed and valid information is in aOffset[] and pC->aType[].
** Macros to determine the number of bytes required by a normal Expr
** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
** and an Expr struct with the EP_TokenOnly flag set.
Want a reserved lock?
71
** The near-set object passed as the first argument contains more than
** one phrase. All phrases currently point to the same row. The
** Fts5ExprPhrase.poslist buffers are populated accordingly. This function
** tests if the current row contains instances of each phrase sufficiently
** close together to meet the NEAR constraint. Non-zero is returned if it
** does, or zero otherwise.
**
** If in/out parameter (*pRc) is set to other than SQLITE_OK when this
** function is called, it is a no-op. Or, if an error (e.g. SQLITE_NOMEM)
** occurs within this function (*pRc) is set accordingly before returning.
** The return value is undefined in both these cases.
**
** If no error occurs and non-zero (a match) is returned, the position-list
** of each phrase object is edited to contain only those entries that
** meet the constraint before returning.
** Read and return an unsigned 32-bit big-endian integer from the buffer
** passed as the only argument.
Structure object to return
Bytes of valid data so far
** Advance an iterator created by sqlite3changeset_start() to the next
** change in the changeset. This function may return SQLITE_ROW, SQLITE_DONE
** or SQLITE_CORRUPT.
**
** This function may not be called on iterators passed to a conflict handler
** callback by changeset_apply().
File descriptor for main journal
** Create a new VFS file descriptor (stored in memory obtained from
** sqlite3_malloc) and open the file named "path" in the file descriptor.
**
** The caller is responsible not only for closing the file descriptor
** but also for freeing the memory associated with the file descriptor.
rank MATCH ? expression (or NULL)
** This function is used by test procedures to inspect the internal state
** of the global cache.
&& !defined(SQLITE_OMIT_SUBQUERY)
comment: Mask of FTS5INDEX_XXX flags
label: code-design
Search for a table and column that appears on one side or the
** other of the == operator in every subterm. That table and column
** will be recorded in iCursor and iColumn. There might not be any
** such table and column. Set okToChngToIN if an appropriate table
** and column is found but leave okToChngToIN false if not found.
284
the count using a callback.
Values for up to two %d fields in zPfx
* The value used with sqlite3_win32_set_directory() to specify that
* the data directory should be changed.
** Create an sqlite3_backup process to copy the contents of zSrcDb from
** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
** a pointer to the new sqlite3_backup object.
**
** If an error occurs, NULL is returned and an error code and error message
** stored in database handle pDestDb.
Always analyze if any index lacks statistics
** Pragma virtual table module xEof method.
comment:
** This macro is used by various functions that merge doclists. The two
** arguments are 64-bit docid values. If the value of the stack variable
** bDescDoclist is 0 when this macro is invoked, then it returns (i1-i2).
** Otherwise, (i2-i1).
**
** Using this makes it easier to write code that can merge doclists that are
** sorted in either ascending or descending order.
label: code-design
Values to return.
** Advance the iterator passed as the only argument. If the end of the
** doclist-index page is reached, return non-zero.
Name of PK index
Now search for a zipvfs instance lower down in the VFS stack. If
** one is found, this is an error.
** HAVE_MREMAP defaults to true on Linux and false everywhere else.
Size of each buffer in bytes
Do not use an automatic index if the this loop is expected
** to run less than 2 times.
For looping over expression in a list
SQLITE_OMIT_DECLTYPE
If we reach this point, it means that pExpr refers to a table
** that is in the FROM clause of the aggregate query.
**
** Make an entry for the column in pAggInfo->aCol[] if there
** is not an entry there already.
_FTS5_H
comment: These registers need to be preserved in case there is an IN operator
** loop. So we could deallocate the registers here (and potentially
** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
** simpler and safer to simply not reuse the registers.
**
** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
label: code-design
Estimated rows in table - from sqlite_stat1 table
Column currently being processed
19
Used by fstat()
** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
** the value of iCol encoded as a varint to *pp. This will start a new
** column list.
**
** Set *pp to point to the byte just after the last byte written before
** returning (do not modify it if iCol==0). Return the total number of bytes
** written (0 if iCol==0).
If leaving WAL mode, close the log file. If successful, the call
** to PagerCloseWal() checkpoints and deletes the write-ahead-log
** file. An EXCLUSIVE lock may still be held on the database file
** after a successful return.
62
The complete WAL information
Refcount for pOuterNC and outer contexts
Need convertCompoundSelectToSubquery()
If there is not already a read-only (or read-write) transaction opened
** on the b-tree database, open one now. If a transaction is opened, it
** will be closed before this function returns.
Next entry is on the next page
If the SF_Converted flags is set, then this Select object was
** was created by the convertCompoundSelectToSubquery() function.
** In this case the ORDER BY clause (p->pOrderBy) should be resolved
** as if it were part of the sub-query, not the parent. This block
** moves the pOrderBy down to the sub-query. It will be moved back
** after the names have been resolved.
** Finished with one layer of the tree
(298) conslist ::= tcons (OPTIMIZED OUT)
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread. In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter. If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
a: p4<<29 | p6<<15 | p8 (unmasked)
** Reset a sorting cursor back to its original empty state.
Return true if value x is found any of the first nCol entries of aiCol[]
Check if the root node now has exactly one child. If so, remove
** it, schedule the contents of the child for reinsertion and
** reduce the tree height by one.
**
** This is equivalent to copying the contents of the child into
** the root node (the operation that Gutman's paper says to perform
** in this scenario).
This block is really an inlined version of sqlite3VdbeMemRelease()
** that takes advantage of the fact that the memory cell value is
** being set to NULL after releasing any dynamic resources.
**
** The justification for duplicating code is that according to
** callgrind, this causes a certain test case to hit the CPU 4.7
** percent less (x86 linux, gcc version 4.1.2, -O6) than if
** sqlite3MemRelease() were called from here. With -O2, this jumps
** to 6.6 percent. The test case is inserting 1000 rows into a table
** with no indexes using a single prepared INSERT statement, bind()
** and reset(). Inserts are grouped into a transaction.
Parse string
** This function compares the two table rows or index records
** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
** or positive integer if key1 is less than, equal to or
** greater than key2. The {nKey1, pKey1} key must be a blob
** created by the OP_MakeRecord opcode of the VDBE. The pPKey2
** key must be a parsed key such as obtained from
** sqlite3VdbeParseRecord.
**
** If argument bSkip is non-zero, it is assumed that the caller has already
** determined that the first fields of the keys are equal.
**
** Key1 and Key2 do not have to contain the same number of fields. If all
** fields that appear in both keys are equal, then pPKey2->default_rc is
** returned.
**
** If database corruption is discovered, set pPKey2->errCode to
** SQLITE_CORRUPT and return 0. If an OOM error is encountered,
** pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
** malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
Do not create a trigger on a system table
Used to accumulate return value
IMP: R-14450-37597
ifdef SQLITE_DEBUG
comment: Ensure adequate test coverage
label: test
defer_subclause ::= DEFERRABLE init_deferred_pred_opt
colset ::= STRING
Schema name of database to vacuum
Delete the Table structure itself.
Busy handler for eMode2
Jump here if the results are unknown due to NULLs
Test variable that can be set to enable WHERE tracing
WITH
xBegin - begin transaction
Table hold the row
idlist_opt ::= LP idlist RP
All output needs to be distinct
Zero-based index of first term.
Number of bytes to write
Number of terms written to node so far
Desired number of arguments. (-1)==any
Next byte to write in WAL file
********************************* Test and Debug Logic *********************
SQLITE_STMTSTATUS_MEMUSED
The expression parse tree
Raw cell content as appears on disk
If this is not a view, open the table and and all indices
Pointer to first in list of synonyms
** Append a new table name to the given SrcList. Create a new SrcList if
** need be. A new entry is created in the SrcList even if pTable is NULL.
**
** A SrcList is returned, or NULL if there is an OOM error. The returned
** SrcList might be the same as the SrcList that was input or it might be
** a new one. If an OOM error does occurs, then the prior value of pList
** that is input to this routine is automatically freed.
**
** If pDatabase is not null, it means that the table has an optional
** database name prefix. Like this: "database.table". The pDatabase
** points to the table name and the pTable points to the database name.
** The SrcList.a[].zName field is filled with the table name which might
** come from pTable (if pDatabase is NULL) or from pDatabase.
** SrcList.a[].zDatabase is filled with the database name from pTable,
** or with NULL if no database is specified.
**
** In other words, if call like this:
**
** sqlite3SrcListAppend(D,A,B,0);
**
** Then B is a table name and the database name is unspecified. If called
** like this:
**
** sqlite3SrcListAppend(D,A,B,C);
**
** Then C is the table name and B is the database name. If C is defined
** then so is B. In other words, we never have a case where:
**
** sqlite3SrcListAppend(D,A,0,C);
**
** Both pTable and pDatabase are assumed to be quoted. They are dequoted
** before being added to the SrcList.
Name of the table to add to the FROM clause
True to disable the incremental doclist optimization. This is controled
** by special insert command 'test-no-incr-doclist'.
Extend the Fts5Structure object as required to ensure the output
** segment exists.
Offset of space for 4-byte poslist size
If there is no "=MODE" part of the pragma, do a query for the
** current mode
Check if this phrase descends from an OR expression node. If not,
** return NULL. Otherwise, the entry that corresponds to docid
** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
** tree that the node is part of has been marked as EOF, but the node
** itself is not EOF, then it may point to an earlier entry.
comment: The "yyy" in the name "xxx.yyy"
label: code-design
aKWOffset[i] is the index into zKWText[] of the start of
** the text for the i-th keyword.
** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
Name of the file used for SHM
Scan for a vowel
** Values that may be OR'd together to form the argument to the
** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
**
** The BTREE_BULKLOAD flag is set on index cursors when the index is going
** to be filled with content that is already in sorted order.
**
** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
** OP_SeekLE opcodes for a range search, but where the range of entries
** selected will all have the same key. In other words, the cursor will
** be used only for equality key searches.
**
Original value of pNew->nOut
Pages per sector for pTargetFd
The operand
File name for write-ahead log
Was sqlite3_global_recover(), but that function is deprecated
__cplusplus
Fix the database pointer on page iPtrPage that pointed at iDbPage so
** that it points at iFreePage. Also fix the pointer map entry for
** iPtrPage.
** This routine is called if the collation factory fails to deliver a
** collation function in the best encoding but there may be other versions
** of this collation function (for other text encodings) available. Use one
** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
** possible.
Bitmap representation
TK_COLUMN: cursor number of table holding column
** TK_REGISTER: register number
** TK_TRIGGER: 1 -> new, 0 -> old
** EP_Unlikely: 134217728 times likelihood
** TK_SELECT: 1st register of result vector
Now that there is a read-lock on the source database, query the
** source pager for the number of pages in the database.
** Compare the values currently indicated by the two nodes as follows:
**
** res = (*p1) - (*p2)
**
** Nodes that point to values that come later in the iteration order are
** considered to be larger. Nodes at EOF are the largest of all.
**
** This means that if the iteration order is ASC, then numerically larger
** rowids are considered larger. Or if it is the default DESC, numerically
** smaller rowids are larger.
237
** Open an Fts3MultiSegReader to scan the doclist for term zTerm/nTerm. Or,
** if isPrefix is true, to scan the doclist for all terms for which
** zTerm/nTerm is a prefix. If successful, return SQLITE_OK and write
** a pointer to the new Fts3MultiSegReader to *ppSegcsr. Otherwise, return
** an SQLite error code.
**
** It is the responsibility of the caller to free this object by eventually
** passing it to fts3SegReaderCursorFree()
**
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
** Output parameter *ppSegcsr is set to 0 if an error occurs.
Size of the header in the record
Current offset in a[]
Whether the function call succeeded or failed, set the output parameters
** to whatever their local counterparts contain. If an error did occur,
** this has the effect of zeroing all output parameters.
Error code returned by ICU function
The index type
True if uses a statement journal
Write the master journal data to the end of the journal file. If
** an error occurs, return the error code to the caller.
The BTree
Statement requested from fts3SqlStmt()
Number of terms in the result set
Number of new slots to add to pSrc->a[]
** Change the page number of page p to newPgno.
label B:
The following block stores the meta information that will be returned
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
** and autoinc. At this point there are two possibilities:
**
** 1. The specified column name was rowid", "oid" or "_rowid_"
** and there is no explicitly declared IPK column.
**
** 2. The table is not a view and the column name identified an
** explicitly declared column. Copy meta information from *pCol.
** Interpret the given string as a locking mode value.
A MATCH operator or equivalent
A malloc may have failed inside of the xFunc() call. If this
** is the case, clear the mallocFailed flag and return NULL.
Source b-tree file
One of TK_DELETE, TK_UPDATE, TK_INSERT
A record being sorted
Move a page here to make room for the root-page
Number of bytes to allocate for iterator
OUT: Total number of pages cached
Opcode: Halt P1 P2 * P4 P5
**
** Exit immediately. All open cursors, etc are closed
** automatically.
**
** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
** or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
** For errors, it can be some other value. If P1!=0 then P2 will determine
** whether or not to rollback the current transaction. Do not rollback
** if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
** then back out all changes that have occurred during this execution of the
** VDBE, but do not rollback the transaction.
**
** If P4 is not null then it is an error message string.
**
** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
**
** 0: (no change)
** 1: NOT NULL contraint failed: P4
** 2: UNIQUE constraint failed: P4
** 3: CHECK constraint failed: P4
** 4: FOREIGN KEY constraint failed: P4
**
** If P5 is not zero and P4 is NULL, then everything after the ":" is
** omitted.
**
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
** every program. So a jump past the last instruction of the program
** is the same as executing Halt.
Hash table to query
True if constraint checking is deferred till COMMIT
** Get a page from the pager and initialize it.
**
** If pCur!=0 then the page is being fetched as part of a moveToChild()
** call. Do additional sanity checking on the page in this case.
** And if the fetch fails, this routine must decrement pCur->iPage.
**
** The page is fetched as read-write unless pCur is not NULL and is
** a read-only cursor.
**
** If an error occurs, then *ppPage is undefined. It
** may remain unchanged, or it may be set to an invalid value.
create a copy of the lock path if the conch is taken
************* Begin file legacy.c *****************************************
True if the EXPLAIN flag is found on the query
EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
** increasing offset.
** Increment the schema cookie of the main database opened by p->dbMain.
**
** Or, if this is an RBU vacuum, set the schema cookie of the main db
** opened by p->dbMain to one more than the schema cookie of the main
** db opened by p->dbRbu.
************* End of mem5.c ***********************************************
Skip over any whitespace before checking for a keyword, an open or
** close bracket, or a quoted string.
OUT: Mask of WhereLoops to run in reverse order
Locate the PRIMARY KEY index. Or, if this table was originally
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
Next element in list
Set the current transaction state to TRANS_NONE and unlock the
** pager if this call closed the only read or write transaction.
Approximate page size used in %_data
Error code returned by the function.
child table cols -> parent key cols
Special processing to add months
** Add the list of function arguments to the SrcList entry for a
** table-valued-function.
P4 is a vector of 32-bit integers
Store integers here
************* End of mutex_w32.c ******************************************
Do the commit only if all databases successfully complete phase 1.
** If one of the BtreeCommitPhaseOne() calls fails, this indicates an
** IO error while deleting or truncating a journal file. It is unlikely,
** but could happen. In this case abandon processing and return the error.
If the translation is between UTF-16 little and big endian, then
** all that is required is to swap the byte order. This case is handled
** differently from the others.
'>'. Part of > or >=
** This structure encapsulates a user-function destructor callback (as
** configured using create_function_v2()) and a reference counter. When
** create_function_v2() is called to create a function with a destructor,
** a single object of this type is allocated. FuncDestructor.nRef is set to
** the number of FuncDef objects created (either 1 or 3, depending on whether
** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor
** member of each of the new FuncDef objects is set to point to the allocated
** FuncDestructor.
**
** Thereafter, when one of the FuncDef objects is deleted, the reference
** count on this object is decremented. When it reaches 0, the destructor
** is invoked and the FuncDestructor structure freed.
Mem.z points to an ephemeral string
comment: Database connection (for malloc)
label: code-design
Use the patchset format if true
** Return true if the expression contains no non-deterministic SQL
** functions. Do not consider non-deterministic SQL functions that are
** part of sub-select statements.
Values between 2097152 and 268435455
Version 3.12.0 and later
Base class used by SQLite core
Index in pInfo->aConstraint[]
comment:
** Generate code that will assemble an index key and stores it in register
** regOut. The key with be for index pIdx which is an index on pTab.
** iCur is the index of a cursor open on the pTab table and pointing to
** the entry that needs indexing. If pTab is a WITHOUT ROWID table, then
** iCur must be the cursor of the PRIMARY KEY index.
**
** Return a register number which is the first in a block of
** registers that holds the elements of the index key. The
** block of registers has already been deallocated by the time
** this routine returns.
**
** If *piPartIdxLabel is not NULL, fill it in with a label and jump
** to that label if pIdx is a partial index that should be skipped.
** The label should be resolved using sqlite3ResolvePartIdxLabel().
** A partial index should be skipped if its WHERE clause evaluates
** to false or null. If pIdx is not a partial index, *piPartIdxLabel
** will be set to zero which is an empty label that is ignored by
** sqlite3ResolvePartIdxLabel().
**
** The pPrior and regPrior parameters are used to implement a cache to
** avoid unnecessary register loads. If pPrior is not NULL, then it is
** a pointer to a different index for which an index key has just been
** computed into register regPrior. If the current pIdx index is generating
** its key into the same sequence of registers and if pPrior and pIdx share
** a column in common, then the register corresponding to that column already
** holds the correct value and the loading of that register is skipped.
** This optimization is helpful when doing a DELETE or an INTEGRITY_CHECK
** on a table with multiple indices, and especially with the ROWID or
** PRIMARY KEY columns of the index.
label: code-design
************* Continuing where we left off in os_common.h *****************
** Enter a mutex on a Btree given a cursor owned by that Btree.
**
** These entry points are used by incremental I/O only. Enter() is required
** any time OMIT_SHARED_CACHE is not defined, regardless of whether or not
** the build is threadsafe. Leave() is only required by threadsafe builds.
The schema has been loaded
121
Page content
Number of queued entries by iLevel
FLOA
At this point, there is a write transaction open on both the
** vacuum database and the main database. Assuming no error occurs,
** both transactions are closed by this block - the main database
** transaction by sqlite3BtreeCopyFile() and the other by an explicit
** call to sqlite3BtreeCommit().
Number of nested calls to the parser/code generator
expr ::= expr in_op LP select RP
** Helper functions to obtain and relinquish the global mutex. The
** global mutex is used to protect the winLockInfo objects used by
** this file, all of which may be shared by multiple threads.
**
** Function winShmMutexHeld() is used to assert() that the global mutex
** is held when required. This function is only used as part of assert()
** statements. e.g.
**
** winShmEnterMutex()
** assert( winShmMutexHeld() );
** winShmLeaveMutex()
pSelect is correlated, not constant
comment: The correct SQL-92 behavior is for the LIKE operator to ignore
** case. Thus 'a' LIKE 'A' would be true.
label: code-design
Find old rows
Microsoft-style identifiers in [...]
Current read offset
** This version of the memory allocation is for use by the application.
** First make sure the memory subsystem is initialized, then do the
** allocation.
** This object becomes the sqlite3_user_data() for the SQL functions
** that are created by sqlite3_rtree_geometry_callback() and
** sqlite3_rtree_query_callback() and which appear on the right of MATCH
** operators in order to constrain a search.
**
** xGeom and xQueryFunc are the callback functions. Exactly one of
** xGeom and xQueryFunc fields is non-NULL, depending on whether the
** SQL function was created using sqlite3_rtree_geometry_callback() or
** sqlite3_rtree_query_callback().
**
** This object is deleted automatically by the destructor mechanism in
** sqlite3_create_function_v2().
** This callback is invoked once for each index when reading the
** sqlite_stat1 table.
**
** argv[0] = name of the table
** argv[1] = name of the index (might be NULL)
** argv[2] = results of analysis - on integer for each column
**
** Entries for which argv[1]==NULL simply record the number of rows in
** the table.
** Generate code that will cause the most recent index analysis to
** be loaded into internal hash tables where is can be used.
True for UPDATE, False for INSERT
Statement handle pointing at new row
comment: Number of COLNAME_xxx symbols
label: code-design
single- and double-quoted strings
Exact encoding match
If the call to xBestIndex() with all terms enabled produced a plan
** that does not require any source tables (IOW: a plan with mBest==0),
** then there is no point in making any further calls to xBestIndex()
** since they will all return the same result (if the xBestIndex()
** implementation is sane).
New row data is stored here
** Check to see if the frame with header in aFrame[] and content
** in aData[] is valid. If it is a valid frame, fill *piPage and
** *pnTruncate and return true. Return if the frame is not valid.
Attempt to compute the RHS. After this step, if anything other than
** IN_INDEX_NOOP is returned, the table opened ith cursor pExpr->iTable
** contains the values that make up the RHS. If IN_INDEX_NOOP is returned,
** the RHS has not yet been coded.
Sorting index number. 0==None
Resize an allocation
Allocate space to hold the change in document sizes
Currently always set to 2
Opcode: SoftNull P1 * * * *
** Synopsis: r[P1]=NULL
**
** Set register P1 to have the value NULL as seen by the OP_MakeRecord
** instruction, but do not free any string or blob memory associated with
** the register, so that if the value was a string or blob that was
** previously copied using OP_SCopy, the copies will continue to be valid.
** Generate the text of a WHERE expression which can be used to select all
** tables that have foreign key constraints that refer to table pTab (i.e.
** constraints for which pTab is the parent table) from the sqlite_master
** table.
** Allowed values for the DB.pSchema->flags field.
**
** The DB_SchemaLoaded flag is set after the database schema has been
** read into internal hash tables.
**
** DB_UnresetViews means that one or more views have column names that
** have been filled out. If the schema changes, these column names might
** changes and so the view will need to be reset.
Used size of aTree/aReadr (power of 2)
Language being queried for
Only the rowid is required for a table btree
Bytes of memory required to allocate the new cache
comment:
** CAPI3REF: Prepared Statement Status
** METHOD: sqlite3_stmt
**
** ^(Each prepared statement maintains various
** [SQLITE_STMTSTATUS counters] that measure the number
** of times it has performed specific operations.)^ These counters can
** be used to monitor the performance characteristics of the prepared
** statements. For example, if the number of table steps greatly exceeds
** the number of table searches or result rows, that would tend to indicate
** that the prepared statement is using a full table scan rather than
** an index.
**
** ^(This interface is used to retrieve and reset counter values from
** a [prepared statement]. The first argument is the prepared statement
** object to be interrogated. The second argument
** is an integer code for a specific [SQLITE_STMTSTATUS counter]
** to be interrogated.)^
** ^The current value of the requested counter is returned.
** ^If the resetFlg is true, then the counter is reset to zero after this
** interface call returns.
**
** See also: [sqlite3_status()] and [sqlite3_db_status()].
label: code-design
Figure out whether or not the current contents of memory should be
** flushed to a PMA before continuing. If so, do so.
**
** If using the single large allocation mode (pSorter->aMemory!=0), then
** flush the contents of memory to a new PMA if (a) at least one value is
** already in memory and (b) the new value will not fit in memory.
**
** Or, if using separate allocations for each record, flush the contents
** of memory to a PMA if either of the following are true:
**
** * The total memory allocated for the in-memory list is greater
** than (page-size * cache-size), or
**
** * The total memory allocated for the in-memory list is greater
** than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
from
OUT: Tokenization cursor
Size of zName in bytes, including \0
Buffer to write to
True if docids are descending
** Initialize the iterator object pIter to iterate through the entries in
** segment pSeg. The iterator is left pointing to the first entry when
** this function returns.
**
** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
** an error has already occurred when this function is called, it is a no-op.
A range of registers to hold previous output
Number of backup operations reading this btree
Write the old.* vector first.
comment:
** An instance of this object is used for writing a PMA.
**
** The PMA is written one record at a time. Each record is of an arbitrary
** size. But I/O is more efficient if it occurs in page-sized blocks where
** each block is aligned on a page boundary. This object caches writes to
** the PMA so that aligned, page-size blocks are written.
label: code-design
** If the Index.aSample variable is not NULL, delete the aSample[] array
** and its contents.
Jumps here in order to return true.
Mask of SQLITE_INDEX_SCAN_* flags
Cursor for the first index
This block advances the phrase iterators until they point to a set of
** entries that together comprise a match.
Verify that the every entry in the mapping region is still reachable
** via the hash table even after the cleanup.
** Generate code that will erase and refill index *pIdx. This is
** used to initialize a newly created index or to recompute the
** content of an index in response to a REINDEX command.
**
** if memRootPage is not negative, it means that the index is newly
** created. The register specified by memRootPage contains the
** root page number of the index. If memRootPage is negative, then
** the index already exists and must be cleared before being refilled and
** the root page number of the index is taken from pIndex->tnum.
Fts3 table handle
As configured by CursorSetHints()
Top of insert loop. Label "C" in templates 3 and 4
Arguments to currently executing user function
Exclude terms using these operators
Opcode: VDestroy P1 * * P4 *
**
** P4 is the name of a virtual table in database P1. Call the xDestroy method
** of that table.
** The maximum value of a ?nnn wildcard that the parser will accept.
*************************************************************************
** Interface to code in fts5_buffer.c.
Underlying file is readonly
The end of a position list is marked by a zero encoded as an FTS3
** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
** of some other, multi-byte, value.
**
** The following while-loop moves pEnd to point to the first byte that is not
** immediately preceded by a byte with the 0x80 bit set. Then increments
** pEnd once more so that it points to the byte immediately following the
** last byte in the position-list.
900
aSeg[] index of firstest iterator
** An instance of the WhereScan object is used as an iterator for locating
** terms in the WHERE clause that are useful to the query planner.
** Return true if there have been no changes to monitored tables recorded
** by the session object passed as the only argument.
Query flattening
Preferred text encoding
xFileSize
index internal
The very beginning of the WHERE loop
Pointer to corresponding expr token
Snippet start text - "<b>"
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
** a match.
Starting offset to score
2x number of WHEN terms
Query term
tab1 must not have triggers
Hint level
OUT: Copy of zThis
** Callback used by fts5Bm25GetData() to count the number of rows in the
** table matched by each individual phrase within the query.
If the new Btree uses a sharable pBtShared, then link the new
** Btree into the list of all sharable Btrees for the same connection.
** The list is kept in ascending order by pBt address.
Root page of PK index
Space to write cursor structure
Copy of SubProgram.token
** Maximum number of prefix indexes on single FTS5 table. This must be
** less than 32. If it is set to anything large than that, an #error
** directive in fts5_index.c will cause the build to fail.
Close all cursors opened via this handle.
*********** Begin %syntax_error code ***************************************
write it out to the temporary break file
Destructor for pUser
Pointer to save as auxdata
Release memory back to the heap
** Error message for when two or more terms of a compound select have different
** size result sets.
Registered using sqlite3_preupdate_hook()
** Return TRUE if the word ends with three letters which
** are consonant-vowel-consonent and where the final consonant
** is not 'w', 'x', or 'y'.
**
** The word is reversed here. So we are really checking the
** first three letters and the first one cannot be in [wxy].
If the function returned an error, throw an exception
Here code is inserted which will be executed whenever the
** parser fails
Implement the main merge loop
First argument for xOutput
%w -> Strings with '\"' doubled
Source line number where error occurred
Number of pages in pPage[]
comment:
** Move data out of a btree key or data field and into a Mem structure.
** The data is payload from the entry that pCur is currently pointing
** to. offset and amt determine what portion of the data or key to retrieve.
** The result is written into the pMem element.
**
** The pMem object must have been initialized. This routine will use
** pMem->zMalloc to hold the content from the btree, if possible. New
** pMem->zMalloc space will be allocated if necessary. The calling routine
** is responsible for making sure that the pMem object is eventually
** destroyed.
**
** If this routine fails for any reason (malloc returns NULL or unable
** to read from the disk) then the pMem is left in an inconsistent state.
label: code-design
comment: The NEVER() on the second term is because sqlite3FunctionUsesThisSrc()
** is always called before sqlite3ExprAnalyzeAggregates() and so the
** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If
** sqlite3FunctionUsesThisSrc() is used differently in the future, the
** NEVER() will need to be removed.
label: code-design
idlist ::= idlist COMMA nm
The complete IN operator
** An object of the following type is used to read data from a single
** FTS segment node. See the following functions:
**
** nodeReaderInit()
** nodeReaderNext()
** nodeReaderRelease()
Do not use a rollback journal
ID => nothing
Must be element [1]
Remove the page from the files free-list. This is not required
** if bCommit is non-zero. In that case, the free-list will be
** truncated to zero after this function returns, so it doesn't
** matter if it still contains some garbage entries.
** CAPI3REF: Index Of A Parameter With A Given Name
** METHOD: sqlite3_stmt
**
** ^Return the index of an SQL parameter given its name. ^The
** index value returned is suitable for use as the second
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
** is returned if no matching parameter is found. ^The parameter
** name must be given in UTF-8 even if the original statement
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
** [sqlite3_prepare16_v3()].
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_count()], and
** [sqlite3_bind_parameter_name()].
Size of allocation containing aBuf
cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END
The ')' before options in the CREATE TABLE
ROLLBACK
if the conch has data compare the contents
Operations on page references.
If zName is specified, operate on only the one system call
** specified.
Ensure the database schema has been loaded
Limits
Next and previous entry on the min-heap
Types of VDBE cursors
comment: mem1.u.i = 0; // not needed, here to silence compiler warning
label: code-design
** Open a temporary file.
**
** Write the file descriptor into *pFile. Return SQLITE_OK on success
** or some other error code if we fail. The OS will automatically
** delete the temporary file when it is closed.
**
** The flags passed to the VFS layer xOpen() call are those specified
** by parameter vfsFlags ORed with the following:
**
** SQLITE_OPEN_READWRITE
** SQLITE_OPEN_CREATE
** SQLITE_OPEN_EXCLUSIVE
** SQLITE_OPEN_DELETEONCLOSE
comment:
** Return the opcode for a given address. If the address is -1, then
** return the most recently inserted opcode.
**
** If a memory allocation error has occurred prior to the calling of this
** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
** is readable but not writable, though it is cast to a writable value.
** The return of a dummy opcode allows the call to continue functioning
** after an OOM fault without having to check to see if the return from
** this routine is a valid pointer. But because the dummy.opcode is 0,
** dummy will never be written to. This is verified by code inspection and
** by running with Valgrind.
label: code-design
Write transactions are not possible on a read-only database
** Invoke the OP_AggFinalize opcode for every aggregate function
** in the AggInfo structure.
Single result column
EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
** Single-thread.
Create/Connect to the underlying relational database schema. If
** that is successful, call sqlite3_declare_vtab() to configure
** the r-tree table schema.
Size of aRoot[] in bytes
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the PRAGMA command.
** Append text to the HighlightContext output string - p->zOut. Argument
** z points to a buffer containing n bytes of text to append. If n is
** negative, everything up until the first '\0' is appended to the output.
**
** If *pRc is set to any value other than SQLITE_OK when this function is
** called, it is a no-op. If an error (i.e. an OOM condition) is encountered,
** *pRc is set to an error code before returning.
Populate the azTblCol[] and nTblCol variables based on the columns
** of the input table. Ignore any input table columns that begin with
** "rbu_".
** This is the callback routine for the code that initializes the
** database. See sqlite3Init() below for additional information.
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
**
** Each callback contains the following information:
**
** argv[0] = name of thing being created
** argv[1] = root page number for table or index. 0 for trigger or view.
** argv[2] = SQL text for the CREATE statement.
**
5x
Read the specified cookie value
Create the SELECT statement to read keys in sorted order
#include <stdlib.h>
True if all terms are at the same rowid
The prepared statement being evaluated
All offsets for this column have been gathered.
Add the first rowid field to the hash-entry
If there is already a lock of this type or more restrictive on the
** unixFile, do nothing. Don't use the end_lock: exit path, as
** unixEnterMutex() hasn't been called yet.
Name to be added
** Generate code to move content from registers iFrom...iFrom+nReg-1
** over to iTo..iTo+nReg-1. Keep the column cache up-to-date.
Matching column in the left table
Used to iterate through old.* values
Number of nested loop
PRAGMA checkpoint_fullfsync=ON
Added by 3.5.0
comment: One of the INCRINIT_XXX constants
label: code-design
The original page number
** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
** array. Return the error code for the first error that occurs, or
** SQLITE_OK if all xSync operations are successful.
**
** If an error message is available, leave it in p->zErrMsg.
** Implementation of the R*-tree variant of SplitNode from Beckman[1990].
Opcode: OpenPseudo P1 P2 P3 * *
** Synopsis: P3 columns in r[P2]
**
** Open a new cursor that points to a fake table that contains a single
** row of data. The content of that one row is the content of memory
** register P2. In other words, cursor P1 becomes an alias for the
** MEM_Blob content contained in register P2.
**
** A pseudo-table created by this opcode is used to hold a single
** row output from the sorter so that the row can be decomposed into
** individual columns using the OP_Column opcode. The OP_Column opcode
** is the only cursor opcode that works with a pseudo-table.
**
** P3 is the number of fields in the records that will be stored by
** the pseudo-table.
Pointer map 'type' entry for pDbPage
jump, in3
Buffer containing poslist
sqlite3GetVdbe() has always been previously called
Delete all attached table objects. And the contents of their
** associated hash-tables.
Restrictions on range of iteration
** This function ensures that the caller has obtained an exclusive
** shared-cache table-lock on the %_segdir table. This is required before
** writing data to the fts3 table. If this lock is not acquired first, then
** the caller may end up attempting to take this lock as part of committing
** a transaction, causing SQLite to return SQLITE_LOCKED or
** LOCKED_SHAREDCACHEto a COMMIT command.
**
** It is best to avoid this because if FTS3 returns any error when
** committing a transaction, the whole transaction will be rolled back.
** And this is not what users expect when they get SQLITE_LOCKED_SHAREDCACHE.
** It can still happen if the user locks the underlying tables directly
** instead of accessing them via FTS.
Will become the return value of this function
comment: The skip-scan logic inside the call to codeAllEqualityConstraints()
** above has already left the cursor sitting on the correct row,
** so no further seeking is needed
label: code-design
** Return a list of comma separated SQL expressions and a FROM clause that
** could be used in a SELECT statement such as the following:
**
** SELECT <list of expressions> FROM %_content AS x ...
**
** to return the docid, followed by each column of text data in order
** from left to write. If parameter zFunc is not NULL, then instead of
** being returned directly each column of text data is passed to an SQL
** function named zFunc first. For example, if zFunc is "unzip" and the
** table has the three user-defined columns "a", "b", and "c", the following
** string is returned:
**
** "docid, unzip(x.'a'), unzip(x.'b'), unzip(x.'c') FROM %_content AS x"
**
** The pointer returned points to a buffer allocated by sqlite3_malloc(). It
** is the responsibility of the caller to eventually free it.
**
** If *pRc is not SQLITE_OK when this function is called, it is a no-op (and
** a NULL pointer is returned). Otherwise, if an OOM error is encountered
** by this function, NULL is returned and *pRc is set to SQLITE_NOMEM. If
** no error occurs, *pRc is left unmodified.
Result code to return
Newly allocated winShmNode
Integer value
Size of sibling on the left
************* End of msvc.h ***********************************************
The WhereOrSet object holds a set of possible WhereOrCosts that
** correspond to the subquery(s) of OR-clause processing. Only the
** best N_OR_COST elements are retained.
If non-NULL, bulk memory to hold pList
Use SorterOpen instead of OpenEphemeral
Allocate the buffers used by this operation. The allocation is
** relinquished before this function returns.
IMP: R-64479-57858
DELETE statement
The minimum count for any phrase so far.
sqlite3VbeCursorRestore() can only fail if the record has been deleted
** out from under the cursor. That will never happens for an IdxRowid
** or Seek opcode
Next available winShm.id value
1230
Used when p4type is P4_SUBPROGRAM
Connection is read only
Linked list of records
New segment within pStruct
** Return true if it OK to factor constant expressions into the initialization
** code. The argument is a Parse object for the code generator.
SQLITE_AFF_TEXT
** Allocate a new Select structure and return a pointer to that
** structure.
** Token pTok has appeared in a MATCH expression where the NEAR operator
** is expected. If token pTok does not contain "NEAR", store an error
** in the pParse object.
A parse of the cell we are pointing at
Name of pragma
** Determine if the argument is a power of two
True if the value to convert is signed
** Schema of the tokenizer table.
************* Begin file opcodes.c ****************************************
Value for "level" column of output
Column for entry to add
SQLITE_OK
Virtual table handle
** Parse context.
** Return the total number of blocks this module has read from the %_data
** table since it was created.
comment: EVIDENCE-OF: R-26747-61719 When the application provides any amount of
** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
** large heap allocations.
label: code-design
Sync the db file
comment:
** CAPI3REF: Low-Level Control Of Database Files
** METHOD: sqlite3
**
** ^The [sqlite3_file_control()] interface makes a direct call to the
** xFileControl method for the [sqlite3_io_methods] object associated
** with a particular database identified by the second argument. ^The
** name of the database is "main" for the main database or "temp" for the
** TEMP database, or the name that appears after the AS keyword for
** databases that are added using the [ATTACH] SQL command.
** ^A NULL pointer can be used in place of "main" to refer to the
** main database file.
** ^The third and fourth parameters to this routine
** are passed directly through to the second and third parameters of
** the xFileControl method. ^The return value of the xFileControl
** method becomes the return value of this routine.
**
** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
** a pointer to the underlying [sqlite3_file] object to be written into
** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
** case is a short-circuit path which does not actually invoke the
** underlying sqlite3_io_methods.xFileControl method.
**
** ^If the second parameter (zDbName) does not match the name of any
** open database file, then SQLITE_ERROR is returned. ^This error
** code is not remembered and will not be recalled by [sqlite3_errcode()]
** or [sqlite3_errmsg()]. The underlying xFileControl method might
** also return SQLITE_ERROR. There is no way to distinguish between
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
** xFileControl method.
**
** See also: [SQLITE_FCNTL_LOCKSTATE]
label: code-design
int nByte
** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc);
** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr);
** rc = sqlite3Fts5ExprNext(pExpr)
** ){
** // The document with rowid iRowid matches the expression!
** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
** }
comment:
** Change the way data is synced to disk in order to increase or decrease
** how well the database resists damage due to OS crashes and power
** failures. Level 1 is the same as asynchronous (no syncs() occur and
** there is a high probability of damage) Level 2 is the default. There
** is a very low but non-zero probability of damage. Level 3 reduces the
** probability of damage to near zero but with a write performance reduction.
label: code-design
If the pager is in the ERROR state and the call to unlock the database
** file fails, set the current lock to UNKNOWN_LOCK. See the comment
** above the #define for UNKNOWN_LOCK for an explanation of why this
** is necessary.
For ORDER BY, column number in result set
Input JSON
************* Begin file btmutex.c ****************************************
comment: The row-trigger may have deleted the row being updated. In this
** case, jump to the next row. No updates or AFTER triggers are
** required. This behavior - what happens when the row being updated
** is deleted or renamed by a BEFORE trigger - is left undefined in the
** documentation.
label: documentation
Index of the database that is being written
Name of the operator
After reading the first page of the database assuming a page size
** of BtShared.pageSize, we have discovered that the page-size is
** actually pageSize. Unlock the database, leave pBt->pPage1 at
** zero and return SQLITE_OK. The caller will call this function
** again with the correct page-size.
79
** Recover as many snapshots as possible from the wal file associated with
** schema zDb of database db.
Advance each of the segments to point to the first docid.
The pointer is always the first 4 bytes of the page in this case.
Mapped memory region
number of free pages
IN/OUT: PendingList structure
If there is an ORDER BY clause and it is not being ignored, set up
** space for the aSortCost[] array. Each element of the aSortCost array
** is either zero - meaning it has not yet been initialized - or the
** cost of sorting nRowEst rows of data where the first X terms of
** the ORDER BY clause are already in order, where X is the array
** index.
Create labels for the "break" and "continue" instructions
** for the current loop. Jump to addrBrk to break out of a loop.
** Jump to cont to go immediately to the next iteration of the
** loop.
**
** When there is an IN operator, we also have a "addrNxt" label that
** means to continue with the next IN value combination. When
** there are no IN operators in the constraints, the "addrNxt" label
** is the same as "addrBrk".
Number of neighbors on either side of pPage
** The unixFile structure is subclass of sqlite3_file specific to the unix
** VFS implementations.
the open file object
** Make fts5yytestcase() the same as testcase()
old.* database record
comment:
** This function must be called before exiting any API function (i.e.
** returning control to the user) that has called sqlite3_malloc or
** sqlite3_realloc.
**
** The returned value is normally a copy of the second argument to this
** function. However, if a malloc() failure has occurred since the previous
** invocation SQLITE_NOMEM is returned instead.
**
** If an OOM as occurred, then the connection error-code (the value
** returned by sqlite3_errcode()) is set to SQLITE_NOMEM.
label: code-design
Copy of update mask used with pUpdate
** CAPI3REF: Number Of SQL Parameters
** METHOD: sqlite3_stmt
**
** ^This routine can be used to find the number of [SQL parameters]
** in a [prepared statement]. SQL parameters are tokens of the
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
** placeholders for values that are [sqlite3_bind_blob | bound]
** to the parameters at a later time.
**
** ^(This routine actually returns the index of the largest (rightmost)
** parameter. For all forms except ?NNN, this will correspond to the
** number of unique parameters. If parameters of the ?NNN form are used,
** there may be gaps in the list.)^
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_name()], and
** [sqlite3_bind_parameter_index()].
Forward references
ERROR: generated size does not match predicted size
Segment term filter configuration
Write the nRec value into the journal file header. If in
** full-synchronous mode, sync the journal first. This ensures that
** all data has really hit the disk before nRec is updated to mark
** it as a candidate for rollback.
**
** This is not required if the persistent media supports the
** SAFE_APPEND property. Because in this case it is not possible
** for garbage data to be appended to the file, the nRec field
** is populated with 0xFFFFFFFF when the journal header is written
** and never needs to be updated.
** Forward declarations of structure
Number of matching column names
Check that no sample contains an anEq[] entry with an index of
** p->nMaxEqZero or greater set to zero.
** Generate an ORDER BY or GROUP BY term out-of-range error.
** Change the size of an existing memory allocation
Silently convert bound parameters that appear inside of CREATE
** statements into a NULL when parsing the CREATE statement text out
** of the sqlite_master table
** This function does an "OR" merge of two doclists (output contains all
** positions contained in either argument doclist). If the docids in the
** input doclists are sorted in ascending order, parameter bDescDoclist
** should be false. If they are sorted in ascending order, it should be
** passed a non-zero value.
**
** If no error occurs, *paOut is set to point at an sqlite3_malloc'd buffer
** containing the output doclist and SQLITE_OK is returned. In this case
** *pnOut is set to the number of bytes in the output doclist.
**
** If an error occurs, an SQLite error code is returned. The output values
** are undefined in this case.
Iterator used for several purposes
** Get the suggested cache-size value.
** The xRollbackTo() method.
**
** Discard the contents of the pending terms table.
Hash value
64-bit offset
Move the write position of the WAL back to iFrame. Called in
** response to a ROLLBACK TO command.
Copy of third arg to _filter_table()
IN operator used as a loop
for each column: True==DESC, False==ASC
%r -> 1st, 2nd, 3rd, 4th, etc. English only
getenv("TEMP")
1 when initialized
Advance pointer p until it points to pEnd or an 0x01 byte that is
** not part of a varint
The database disk image is malformed
** Implementation of the round() function
This branch is taken when the xShmMap() method returns SQLITE_BUSY.
** We assume this is a transient condition, so return WAL_RETRY. The
** xShmMap() implementation used by the default unix and win32 VFS
** modules may return SQLITE_BUSY due to a race condition in the
** code that determines whether or not the shared-memory region
** must be zeroed before the requested page is returned.
Do we own the heap (i.e. destroy it on shutdown)?
Store allocated handle here
** This routine generates code that will initialize all of the
** register used by the autoincrement tracker.
The request could not be fulfilled using a freelist slot. Check
** to see if defragmentation is necessary.
Forward references
Forms a linked list of all cursors
synopsis: if P1.nullRow then r[P3]=NULL, goto P2
To many cells for a single page. The page must be corrupt
** Allowed values for the unixFile.ctrlFlags bitmask:
All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
** the cursor. These terms are not needed as hints for a pure range
** scan (that has no == terms) so omit them.
Make sure there is enough space in p->azResult to hold everything
** we need to remember from this invocation of the callback.
expr ::= expr likeop expr
The associated database connection
(302) selectnowith ::= oneselect (OPTIMIZED OUT)
List of dirty pages to write
** If the cursor requires seeking (bSeekRequired flag is set), seek it.
** Return SQLITE_OK if no error occurs, or an SQLite error code otherwise.
**
** If argument bErrormsg is true and an error occurs, an error message may
** be left in sqlite3_vtab.zErrMsg.
Parameter passed through to xFilter()
Trigger under construct by a CREATE TRIGGER
** Cursor iCur is open on an intkey b-tree (a table). Register iRowid contains
** a rowid value just read from cursor iIdxCur, open on index pIdx. This
** function generates code to do a deferred seek of cursor iCur to the
** rowid stored in register iRowid.
**
** Normally, this is just:
**
** OP_DeferredSeek $iCur $iRowid
**
** However, if the scan currently being coded is a branch of an OR-loop and
** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek
** is set to iIdxCur and P4 is set to point to an array of integers
** containing one entry for each column of the table cursor iCur is open
** on. For each table column, if the column is the i'th column of the
** index, then the corresponding array entry is set to (i+1). If the column
** does not appear in the index at all, the array entry is set to 0.
** Define the required Windows SDK version constants if they are not
** already available.
Mapping from columns of pTab to entries in pChanges
We have a match. Do not delete the master journal file.
New level-0 PMA merger
Number of segments not deleted
comment:
** CAPI3REF: Obtain old.* Values From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
** Furthermore, it may only be called if the type of change that the iterator
** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the vector of
** original row values stored as part of the UPDATE or DELETE change and
** returns SQLITE_OK. The name of the function comes from the fact that this
** is similar to the "old.*" columns available to update or delete triggers.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
comment: If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use
** the strerror() function to obtain the human-readable error message
** equivalent to errno. Otherwise, use strerror_r().
label: code-design
Page in use, not on the LRU list
sqlite_stat4.nDLt
** Store an incr-merge hint in the database.
If BTREE_SAVEPOSITION is set, the cursor must already be pointing
** to a row with the same key as the new entry being inserted.
** Head of a linked list of all sqlite3 objects created by this process
** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection
** is not NULL. This variable may only accessed while the STATIC_MASTER
** mutex is held.
abNotindexed
************* End of hash.c ***********************************************
Incr-merge parameter A
96
Name of the system call
** This is a helper routine for sqlite3PcacheFetchFinish()
**
** In the uncommon case where the page being fetched has not been
** initialized, this routine is invoked to do the initialization.
** This routine is broken out into a separate function since it
** requires extra stack manipulation that can be avoided in the common
** case.
Find out which shared locks are already held by sibling connections.
** If any sibling already holds an exclusive lock, go ahead and return
** SQLITE_BUSY.
** This function populates the pRtree->nRowEst variable with an estimate
** of the number of rows in the virtual table. If possible, this is based
** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
Module destructor function
Link the new savepoint into the database handle's list.
Expression used to recompute the rowid
Pointer to buffer containing doclist
comment:
** The interface to the virtual-table mechanism is currently considered
** to be experimental. The interface might change in incompatible ways.
** If this is a problem for you, do not use the interface at this time.
**
** When the virtual-table mechanism stabilizes, we will declare the
** interface fixed, support it indefinitely, and remove this comment.
label: code-design
Copy the triggers, views, and virtual tables from the main database
** over to the temporary database. None of these objects has any
** associated storage, so all we have to do is copy their entries
** from the SQLITE_MASTER table.
Opcode: Gosub P1 P2 * * *
**
** Write the current address onto register P1
** and then jump to address P2.
comment:
** This function may only be called with an iterator passed to an
** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
** it sets the output variable to the total number of known foreign key
** violations in the destination database and returns SQLITE_OK.
**
** In all other cases this function returns SQLITE_MISUSE.
label: code-design
Database connection to read from
EVIDENCE-OF: R-37923-12173 The sqlite3_prepare_v2() interface works
** exactly the same as sqlite3_prepare_v3() with a zero prepFlags
** parameter.
**
** Proof in that the 5th parameter to sqlite3LockAndPrepare is 0
IN/OUT: Error code
Column that token must appear in (or -1)
Buffer containing prefix to match
** This function is a no-op if *pRc is set to other than SQLITE_OK when it
** is called. Otherwise, append a serialized table header (part of the binary
** changeset format) to buffer *pBuf. If an error occurs, set *pRc to an
** SQLite error code before returning.
Change structure
cmd ::= REINDEX nm dbnm
fts3_write.c
************* Begin file os_win.h *****************************************
File opened that is not a database file
Size of buffer aData[] in bytes
IMMEDIATE => ID
Used when p4type is P4_INT64
This only happens when coding check constraints
Memory space from which to build Expr object
** Free the configuration object passed as the only argument.
* The value used with sqlite3_win32_set_directory() to specify that
* the temporary directory should be changed.
Number of vector elements in comparison
** The next global variable is incremented each time the OP_Found opcode
** is executed. This is used to test whether or not the foreign key
** operation implemented using OP_FkIsZero is working. This variable
** has no function other than to help verify the correct operation of the
** library.
This expression is a "*" or a "TABLE.*" and needs to be
** expanded.
If rc is not SQLITE_OK at this point, then either the malloc
** subsystem could not be initialized or the system failed to allocate
** the pInitMutex mutex. Return an error in either case.
bFullMutex
Query prefix, if any
Number of columns in this key
If the sibling pages are not leaves, ensure that the right-child pointer
** of the right-most new sibling page is set to the value that was
** originally in the same field of the right-most old sibling page.
1410
Code the trigger program into the sub-vdbe.
** A minimum allocation is an instance of the following structure.
** Larger allocations are an array of these structures where the
** size of the array is a power of 2.
**
** The size of this object must be a power of two. That fact is
** verified in memsys5Init().
** Called when a transaction completes (either by COMMIT or ROLLBACK).
** The sqlite3_blob object should be released at this point.
Parsing context for error messages
************* Include os_win.h in the middle of mutex_w32.c ***************
** CAPI3REF: Total Number Of Rows Modified
** METHOD: sqlite3
**
** ^This function returns the total number of rows inserted, modified or
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
** since the database connection was opened, including those executed as
** part of trigger programs. ^Executing any other type of SQL statement
** does not affect the value returned by sqlite3_total_changes().
**
** ^Changes made as part of [foreign key actions] are included in the
** count, but those made as part of REPLACE constraint resolution are
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
** are not counted.
**
** See also the [sqlite3_changes()] interface, the
** [count_changes pragma], and the [total_changes() SQL function].
**
** If a separate thread makes changes on the same database connection
** while [sqlite3_total_changes()] is running then the value
** returned is unpredictable and not meaningful.
** Read or write a four-byte big-endian integer value.
** Return pointers to the hash table and page number array stored on
** page iHash of the wal-index. The wal-index is broken into 32KB pages
** numbered starting from 0.
**
** Set output variable *paHash to point to the start of the hash table
** in the wal-index file. Set *piZero to one less than the frame
** number of the first frame indexed by this hash table. If a
** slot in the hash table is set to N, it refers to frame number
** (*piZero+N) in the log.
**
** Finally, set *paPgno so that *paPgno[1] is the page number of the
** first frame indexed by the hash table, frame (*piZero+1).
Pointer map 'page-no' entry for pDbPage
Pointer to module implementation
Next output slot in pColset
** Return TRUE if the word ends in a double consonant.
**
** The text is reversed here. So we are really looking at
** the first two characters of z[].
Number of Journal Records
Check some assumptions:
** (a) the cursor is open for writing,
** (b) there is a read/write transaction open,
** (c) the connection holds a write-lock on the table (if required),
** (d) there are no conflicting read-locks, and
** (e) the cursor points at a valid row of an intKey table.
The main btree structure
Now, if the table is not stored in the temp database, reload any temp
** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined.
The database name
If this is a new rowid, append the 4-byte size field for the previous
** entry, and the new rowid for this entry.
The function calling context
Maximum page size is 64KiB
****************************************************************************
** The next group of routines implement the I/O methods specified
** by the sqlite3_io_methods object.
*****************************************************************************
** Add an entry to one of the pending-terms hash tables.
Return number of characters processed so far. %n
Add the ON clause to the end of the WHERE clause, connected by
** an AND operator.
** 2008 August 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements that page cache.
Existing index DESCENDING
sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
**
** Enable or disable various optimizations for testing purposes. The
** argument N is a bitmask of optimizations to be disabled. For normal
** operation N should be 0. The idea is that a test program (like the
** SQL Logic Test or SLT test module) can run the same SQL multiple times
** with various optimizations disabled to verify that the same answer
** is obtained in every case.
Malloc'd child-journal file descriptor
Used to iterate through hash buckets
Read the schema information out of the schema tables
** This routine identifies subexpressions in the WHERE clause where
** each subexpression is separated by the AND operator or some other
** operator specified in the op parameter. The WhereClause structure
** is filled with pointers to subexpressions. For example:
**
** WHERE a=='hello' AND coalesce(b,11)<10 AND (c+12!=d OR c==22)
** \________/ \_______________/ \________________/
** slot[0] slot[1] slot[2]
**
** The original WHERE clause in pExpr is unaltered. All this routine
** does is make slot[] entries point to substructure within pExpr.
**
** In the previous sentence and in the diagram, "slot[]" refers to
** the WhereClause.a[] array. The slot[] array grows as needed to contain
** all terms of the WHERE clause.
Used to be pPager->nOvfl
If it is open, sync the journal file before calling UnlockAndRollback.
** If this is not done, then an unsynced portion of the open journal
** file may be played back into the database. If a power failure occurs
** while this is happening, the database could become corrupt.
**
** If an error occurs while trying to sync the journal, shift the pager
** into the ERROR state. This causes UnlockAndRollback to unlock the
** database and close the journal file without attempting to roll it
** back or finalize it. The next database user will have to do hot-journal
** rollback before accessing the database file.
TRANSACTION => nothing
** xNext() method for a node of type FTS5_TERM.
X is not a subset of Y
** Return true if this is an in-memory or temp-file backed pager.
Pointer to current key
RECURSIVE => ID
** Return the global mutex used by this PCACHE implementation. The
** sqlite3_status() routine needs access to this mutex.
** Log an error that is an API call on a connection pointer that should
** not have been used. The "type" of connection pointer is given as the
** argument. The zType is a word like "NULL" or "closed" or "invalid".
Number of extra copies of last page
True if statement may modify/insert multiple rows
Copy of pContext passed to s_r_g_c()
** The following routines are implementations of the MemPage.xParseCell()
** method.
**
** Parse a cell content block and fill in the CellInfo structure.
**
** btreeParseCellPtr() => table btree leaf nodes
** btreeParseCellNoPayload() => table btree internal nodes
** btreeParseCellPtrIndex() => index btree nodes
**
** There is also a wrapper function btreeParseCell() that works for
** all MemPage types and that references the cell by index rather than
** by pointer.
Special case: Add leading zeros if the flag_zeropad flag is
** set and we are not left justified
Possibly overload the function if the first argument is
** a virtual table column.
**
** For infix functions (LIKE, GLOB, REGEXP, and MATCH) use the
** second argument, not the first, as the argument to test to
** see if it is a column in a virtual table. This is done because
** the left operand of infix functions (the operand we want to
** control overloading) ends up as the second argument to the
** function. The expression "A glob B" is equivalent to
** "glob(B,A). We want to use the A in "A glob B" to test
** for function overloading. But we use the B term in "glob(B,A)".
Initial checksum value input
Offset to cell content of cell being deleted
A count of rows changed
If there is both an upper and lower bound specified, and the
** comparisons indicate that they are close together, use the fallback
** method (assume that the scan visits 1/64 of the rows) for estimating
** the number of rows visited. Otherwise, estimate the number of rows
** using the method described in the header comment for this function.
** Destroy a bitmap object. Reclaim all memory used.
Write results into this register
Array of jump instruction addresses
Previous docid stored in doclist
Return Code
Source page object
Phrase object to initialize
Pointer to memory from sqliteMalloc()
229
An i-node
** When full-text index nodes are loaded from disk, the buffer that they
** are loaded into has the following number of bytes of padding at the end
** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
** of 920 bytes is allocated for it.
**
** This means that if we have a pointer into a buffer containing node data,
** it is always safe to read up to two varints from it without risking an
** overread, even if the node data is corrupted.
12
** If this is a WAL database, call sqlite3WalSnapshotRecover(). If this
** is not a WAL database, return an error.
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
** it takes up less space.
If this is a main database file and the file was opened using a URI
** filename, check for the "modeof" parameter. If present, interpret
** its value as a filename and try to copy the mode, uid and gid from
** that file.
Results
get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN
** bytes of writable memory.
** Close an rbu file.
** Load an incr-merge hint from the database. The incr-merge hint, if one
** exists, is stored in the rowid==1 row of the %_stat table.
**
** If successful, populate blob *pHint with the value read from the %_stat
** table and return SQLITE_OK. Otherwise, if an error occurs, return an
** SQLite error code.
Check to verify that it is possible to get a read lock on all
** database schemas. The inability to get a read lock indicates that
** some other database connection is holding a write-lock, which in
** turn means that the other connection has made uncommitted changes
** to the schema.
**
** Were we to proceed and prepare the statement against the uncommitted
** schema changes and if those schema changes are subsequently rolled
** back and different changes are made in their place, then when this
** prepared statement goes to run the schema cookie would fail to detect
** the schema change. Disaster would follow.
**
** This thread is currently holding mutexes on all Btrees (because
** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
** is not possible for another thread to start a new schema change
** while this routine is running. Hence, we do not need to hold
** locks on the schema, we just need to make sure nobody else is
** holding them.
**
** Note that setting READ_UNCOMMITTED overrides most lock detection,
** but it does *not* override schema lock detection, so this all still
** works even if READ_UNCOMMITTED is set.
For an index scan, make sure referenced columns are actually in
** the index.
The database connection holding this btree
The "Select-ID" for this loop
lp ::= LP
Context object for fts5ParseTokenize
Strings. %s
A 'table' record consists of:
**
** * A constant 'T' character,
** * Number of columns in said table (a varint),
** * An array of nCol bytes (sPK),
** * A nul-terminated table name.
If pShmNode->nRef has reached 0, then close the underlying
** shared-memory file, too
** Disable lookaside memory allocation for objects that might be
** shared across database connections.
2-byte (or larger) signed integer
This can occur if there exists an index on a TEMP table which
** has the same name as another index on a permanent index. Since
** the permanent table is hidden by the TEMP table, we can also
** safely ignore the index on the permanent table.
** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
** values. This function populates the array with values required to
** "rollback" the write position of the WAL handle back to the current
** point in the event of a savepoint rollback (via WalSavepointUndo()).
Each a[] describes a term of the WHERE cluase
EV: R-33326-45252
Set the value of this object
If we are unable to rollback, quit and return the error
** code. This will cause the pager to enter the error state
** so that no further harm will be done. Perhaps the next
** process to come along will be able to rollback the database.
** Convert the pStep->zTarget string into a SrcList and return a pointer
** to that SrcList.
**
** This routine adds a specific database name, if needed, to the target when
** forming the SrcList. This prevents a trigger in one database from
** referring to a target in another database. An exception is when the
** trigger is in TEMP in which case it can refer to any other database it
** wants.
old.* and new.* values
Register holding maximum rowid
Re-insert the contents of any underfull nodes removed from the tree.
Acquire a RESERVED lock
Array of WHEN terms
Phrase to merge pList/nList into
IN/OUT: Previous rowid written (if any)
Mask for four values above
** Change the value of a Mem to be a string or a BLOB.
**
** The memory management strategy depends on the value of the xDel
** parameter. If the value passed is SQLITE_TRANSIENT, then the
** string is copied into a (possibly existing) buffer managed by the
** Mem structure. Otherwise, any existing buffer is freed and the
** pointer copied.
**
** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
** size limit) then no memory allocation occurs. If the string can be
** stored without allocating memory, then it is. If a memory allocation
** is required to store the string, then value of pMem is unchanged. In
** either case, SQLITE_TOOBIG is returned.
comment: Now that it is known how many phrases there are, allocate and zero
** the required space using malloc().
label: code-design
Desired text encoding
** Recover the wal-index by reading the write-ahead log file.
**
** This routine first tries to establish an exclusive lock on the
** wal-index to prevent other threads/processes from doing anything
** with the WAL or wal-index while recovery is running. The
** WAL_RECOVER_LOCK is also held so that other threads will know
** that this thread is running recovery. If unable to establish
** the necessary locks, this routine returns SQLITE_BUSY.
** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation.
Pointer to page data (for checksum)
Third parameter
** Free the expression node object passed as the only argument.
** Chunk i is a free chunk that has been unlinked. Adjust its
** size parameters for check-out and return a pointer to the
** user portion of the chunk.
******* Begin file sqlite3session.h ********
for the right-hand
** Each instance of this object holds a sequence of WhereLoop objects
** that implement some or all of a query plan.
**
** Think of each WhereLoop object as a node in a graph with arcs
** showing dependencies and costs for travelling between nodes. (That is
** not a completely accurate description because WhereLoop costs are a
** vector, not a scalar, and because dependencies are many-to-one, not
** one-to-one as are graph nodes. But it is a useful visualization aid.)
** Then a WherePath object is a path through the graph that visits some
** or all of the WhereLoop objects once.
**
** The "solver" works by creating the N best WherePath objects of length
** 1. Then using those as a basis to compute the N best WherePath objects
** of length 2. And so forth until the length of WherePaths equals the
** number of nodes in the FROM clause. The best (lowest cost) WherePath
** at the end is the chosen query plan.
Total space in bytes required on leaf
comment: If the client is reading or writing an index and the schema is
** not loaded, then it is too difficult to actually check to see if
** the correct locks are held. So do not bother - just return true.
** This case does not come up very often anyhow.
label: code-design
Advance at least as far as this
Equality constraint on the langid column
** End of interface to code in fts5_aux.c.
*************************************************************************
conch file host id length
The pCx->pCursor will be close automatically, if it exists, by
** the call above.
For sizes MX_SMALL+1 and larger
SQLITE_MUTEX_W32
Cursor number for ephemeral table
Next character in the format string
... change the ending to this (not reversed)
changeset_apply() context
** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact.
Check to see if the new index entry will be unique
** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
** none.
**
** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
** But it does set pMem->u.r and pMem->u.i appropriately.
** This function is similar to sqlite3ExprDup(), except that if pzBuffer
** is not NULL then *pzBuffer is assumed to point to a buffer large enough
** to store the copy of expression p, the copies of p->u.zToken
** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
** if any. Before returning, *pzBuffer is set to the first byte past the
** portion of the buffer copied into by this function.
** If the following global variable points to a string which is the
** name of a directory, then that directory will be used to store
** temporary files.
**
** See also the "PRAGMA temp_store_directory" SQL command.
The SELECT statement
** Flush the current contents of VdbeSorter.list to a new PMA, possibly
** using a background thread.
Array of phrase pointers
BETWEENOTNULLIKECASCADELETECASECOLLATECREATECURRENT_DATEDETACH
Destructor
TUNING: For simple queries, only the best path is tracked.
** For 2-way joins, the 5 best paths are followed.
** For joins of 3 or more tables, track the 10 best paths
The rollback may have destroyed the pPage1->aData value. So
** call btreeGetPage() on page 1 again to make
** sure pPage1->aData is set correctly.
Temporary buffer
key_opt ::=
A slot in pIdx->aSample[]
Next in BtShared.pLock list
** Return an Expr object that refers to a memory register corresponding
** to column iCol of table pTab.
**
** regBase is the first of an array of register that contains the data
** for pTab. regBase itself holds the rowid. regBase+1 holds the first
** column. regBase+2 holds the second column, and so forth.
If the schema-cookie from the database file matches the cookie
** stored with the in-memory representation of the schema, do
** not reload the schema from the database file.
**
** If virtual-tables are in use, this is not just an optimization.
** Often, v-tables store their data in other SQLite tables, which
** are queried from within xNext() and other v-table methods using
** prepared queries. If such a query is out-of-date, we do not want to
** discard the database schema, as the user code implementing the
** v-table would have to be ready for the sqlite3_vtab structure itself
** to be invalidated whenever sqlite3_step() is called from within
** a v-table method.
** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation
** is used regardless of the run-time threadsafety setting.
** RBU handle.
**
** nPhaseOneStep:
** If the RBU database contains an rbu_count table, this value is set to
** a running estimate of the number of b-tree operations required to
** finish populating the *-oal file. This allows the sqlite3_bp_progress()
** API to calculate the permyriadage progress of populating the *-oal file
** using the formula:
**
** permyriadage = (10000 * nProgress) / nPhaseOneStep
**
** nPhaseOneStep is initialized to the sum of:
**
** nRow * (nIndex + 1)
**
** for all source tables in the RBU database, where nRow is the number
** of rows in the source table and nIndex the number of indexes on the
** corresponding target database table.
**
** This estimate is accurate if the RBU update consists entirely of
** INSERT operations. However, it is inaccurate if:
**
** * the RBU update contains any UPDATE operations. If the PK specified
** for an UPDATE operation does not exist in the target table, then
** no b-tree operations are required on index b-trees. Or if the
** specified PK does exist, then (nIndex*2) such operations are
** required (one delete and one insert on each index b-tree).
**
** * the RBU update contains any DELETE operations for which the specified
** PK does not exist. In this case no operations are required on index
** b-trees.
**
** * the RBU update contains REPLACE operations. These are similar to
** UPDATE operations.
**
** nPhaseOneStep is updated to account for the conditions above during the
** first pass of each source table. The updated nPhaseOneStep value is
** stored in the rbu_state table if the RBU update is suspended.
The rowid
** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to
** something between S (inclusive) and E (exclusive).
**
** In other words, S is a buffer and E is a pointer to the first byte after
** the end of buffer S. This macro returns true if P points to something
** contained within the buffer S.
True if RowSet.pEntry is sorted
Second list to merge
** Enable or disable the extended result codes.
** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
** is a no-op. Otherwise, it adds a single row of output to the EQP result,
** where the caption is of the form:
**
** "USE TEMP B-TREE FOR xxx"
**
** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which
** is determined by the zUsage argument.
Write new index here
The result of the merge
same as TK_BITNOT, synopsis: r[P1]= ~r[P1]
** Write an entry into the pointer map.
**
** This routine updates the pointer map entry for page number 'key'
** so that it maps to type 'eType' and parent page number 'pgno'.
**
** If *pRC is initially non-zero (non-SQLITE_OK) then this routine is
** a no-op. If an error occurs, the appropriate error code is written
** into *pRC.
Pointer to doclist for this term
comment:
** Finalize an iterator allocated with sqlite3changeset_start().
**
** This function may not be called on iterators passed to a conflict handler
** callback by changeset_apply().
label: code-design
It is possible to have a Blob value that has some non-zero content
** followed by zero content. But that only comes up for Blobs formed
** by the OP_MakeRecord opcode, and such Blobs never get passed into
** sqlite3MemCompare().
Entries in aScan[]
** Called when a transaction starts.
** The different query plans.
Same as aData for leaves. aData+4 for interior
Information about aggregates at this level
Space for holding column names
CONFLICT
6 -> LANGUAGEID
The patch
** CAPI3REF: Automatically Load Statically Linked Extensions
**
** ^This interface causes the xEntryPoint() function to be invoked for
** each new [database connection] that is created. The idea here is that
** xEntryPoint() is the entry point for a statically linked [SQLite extension]
** that is to be automatically loaded into all new database connections.
**
** ^(Even though the function prototype shows that xEntryPoint() takes
** no arguments and returns void, SQLite invokes xEntryPoint() with three
** arguments and expects an integer result as if the signature of the
** entry point where as follows:
**
** <blockquote><pre>
** int xEntryPoint(
** sqlite3 *db,
** const char **pzErrMsg,
** const struct sqlite3_api_routines *pThunk
** );
** </pre></blockquote>)^
**
** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
** point to an appropriate error message (obtained from [sqlite3_mprintf()])
** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
** is NULL before calling the xEntryPoint(). ^SQLite will invoke
** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
**
** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
** on the list of automatic extensions is a harmless no-op. ^No entry point
** will be called more than once for each database connection that is opened.
**
** See also: [sqlite3_reset_auto_extension()]
** and [sqlite3_cancel_auto_extension()]
xTruncate
** Add a new instruction to the list of instructions current in the
** VDBE. Return the address of the new instruction.
**
** Parameters:
**
** p Pointer to the VDBE
**
** op The opcode for this instruction
**
** p1, p2, p3 Operands
**
** Use the sqlite3VdbeResolveLabel() function to fix an address and
** the sqlite3VdbeChangeP4() function to change the value of the P4
** operand.
** This routine checks if there is a RESERVED lock held on the specified
** file by this or any other process. If such a lock is held, return
** non-zero, otherwise zero.
236
Type of expression node pExpr
Column names to return
If collation sequence pColl was created directly by a call to
** sqlite3_create_collation, and not generated by synthCollSeq(),
** then any copies made by synthCollSeq() need to be invalidated.
** Also, collation destructor - CollSeq.xDel() - function may need
** to be called.
147
**********************************************************************
** Methods below this point are only available if iVersion>=1.
Soft limit for node size
************* End of fts3_icu.c *******************************************
4 if pPage is a leaf. 0 if not
"GROUP" or "ORDER" or ""
OUT: Error message (if rc!=SQLITE_OK)
Lock all btrees used by the statement
if the host id matches and the lock path already exists in the conch
** we'll try to use the path there, if we can't open that path, we'll
** retry with a new auto-generated path
Statement used to read %_segdir entry
Required collating sequence, if not NULL
** Advance the iterator passed as an argument to the next position. Return
** 1 if the iterator is at EOF or if it now points to the start of the
** position list for the next column.
(323) vtabarglist ::= vtabarg
Obtain or release the WRITER lock.
True (1) if h,m,s are valid
177
zWal
** Generate code that will evaluate expression pExpr and store the
** results in register target. The results are guaranteed to appear
** in register target. If the expression is constant, then this routine
** might choose to code the expression at initialization time.
Mask for page offset
** Add a term to the segment being constructed by the SegmentWriter object
** *ppWriter. When adding the first term to a segment, *ppWriter should
** be passed NULL. This function will allocate a new SegmentWriter object
** and return it via the input/output variable *ppWriter in this case.
**
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code.
Number of entries in apShm[] array
************* Begin file btree.h ******************************************
Path to this element
Do not require OOMs if true
Put the results here
comment:
** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
** in memory obtained from sqlite3DbMalloc).
label: code-design
** A list of BtShared objects that are eligible for participation
** in shared cache. This variable has file scope during normal builds,
** but the test harness needs to access it so we make it global for
** test builds.
**
** Access to this variable is protected by SQLITE_MUTEX_STATIC_MASTER.
General heap allocations
** The %_data table is completely empty when this function is called. This
** function populates it with the initial structure objects for each index,
** and the initial version of the "averages" record (a zero-byte blob).
Rowset of rows to be updated
Size of this object
Opcode: Gt P1 P2 P3 P4 P5
** Synopsis: IF r[P3]>r[P1]
**
** This works just like the Lt opcode except that the jump is taken if
** the content of register P3 is greater than the content of
** register P1. See the Lt opcode for additional information.
Cannot use an IS term from the WHERE clause as an index driver for
** the RHS of a LEFT JOIN. Such a term can only be used if it is from
** the ON clause.
** Swap all content between two VDBE structures.
If there has been exactly one prior match and this match
** is for the right-hand table of a NATURAL JOIN or is in a
** USING clause, then skip this match.
SQLITE_CANTOPEN
CLOB
IEEE floating point
same as TK_LE, synopsis: IF r[P3]<=r[P1]
** Initialize zType for the new view or table.
Index of cursor database in db->aDb[] (or -1)
7
** Count the number of fullsyncs and normal syncs. This is used to test
** that syncs and fullsyncs are occurring at the right times.
sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
**
** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
** not.
Write number of errors seen to this variable
Start offset of token
If the statement has been run before (and is paused at the OP_ResultRow)
** then back it up to the point where it does the OP_SeekRowid. This could
** have been down with an extra OP_Goto, but simply setting the program
** counter is faster.
val now holds the lower bound of the coordinate pair
** Print the content of a WhereTerm object
1 for writing. 0 for read-only
New name of table
1120
True for a write lock
************* Begin file os_win.c *****************************************
Replace the backslashes from the filename and lowercase it
** to derive a mutex name.
Number of elements
Data for this leaf
** Provide hints to the cursor. The particular hint given (and the type
** and number of the varargs parameters) is determined by the eHintType
** parameter. See the definitions of the BTREE_HINT_* macros for details.
comment:
** Truncate the in-memory database file image to nPage pages. This
** function does not actually modify the database file on disk. It
** just sets the internal state of the pager object so that the
** truncation will be done when the current transaction is committed.
**
** This function is only called right before committing a transaction.
** Once this function has been called, the transaction must either be
** rolled back or committed. It is not safe to call this function and
** then continue writing to the database.
label: code-design
** For an indexes on expression X, locate every instance of expression X in pExpr
** and change that subexpression into a reference to the appropriate column of
** the index.
FTS index object
Write tail of the output list here
oneselect
A semicolon
Verify that all sibling pages are of the same "type" (table-leaf,
** table-interior, index-leaf, or index-interior).
xNext - advance a cursor
If the free-list must be searched for 'nearby'
Destination database name
ON UPDATE
Buffer to accumulate new.* record in
Iteration of constraint generator loop
How aggressive at syncing data to disk
This is the Walker callback from checkConstraintUnchanged(). Set
** bit 0x01 of pWalker->eCode if
** pWalker->eCode to 0 if this expression node references any of the
** columns that are being modifed by an UPDATE statement.
TBD need to come up with better match here. Perhaps
** use FILE_ID_BOTH_DIR_INFO Structure.
168
** Delete the cell at index iCell of node pNode. After removing the
** cell, adjust the r-tree data structure if required.
Number of columns in one row of the result set
Begin a loop that will extract all source rows in GROUP BY order.
** This might involve two separate loops with an OP_Sort in between, or
** it might be a single loop that uses an index to extract information
** in the right order to begin with.
107
IN/OUT: First token of snippet
synopsis: r[P3]=func(r[P2@P5])
** Test to see whether or not the database connection is in autocommit
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
** by default. Autocommit is disabled by a BEGIN statement and reenabled
** by the next COMMIT or ROLLBACK.
IMP: R-29538-34987
Copy pages from the log to the database file
The clause this term is part of
The BLOB containing the varints
Set up the array of NodeWriter objects
Array of memory cells for parent frame
26
************************************************************************
Size of aIndex[] array
** Finish with a read transaction. All this does is release the
** read-lock.
Shared part of btree structure
comment:
** Simplify a filename into its canonical form
** by making the following changes:
**
** * removing any trailing and duplicate /
** * convert /./ into just /
** * convert /A/../ where A is any simple name into just /
**
** Changes are made in-place. Return the new name length.
**
** The original filename is in z[0..n-1]. Return the number of
** characters in the simplified name.
label: code-design
Return the header size
** Return TRUE if the given operator is one of the operators that is
** allowed for an indexable WHERE clause term. The allowed operators are
** "=", "<", ">", "<=", ">=", "IN", "IS", and "IS NULL"
** Return TRUE if the iCol-th column of index pIdx is NOT NULL
Address of OP_OpenEphemeral opcode for tabTnct
Page p itself has already been visited.
0x10 .. 0x1F
** Attempt to set the size of the memory mapping maintained by file
** descriptor pFd to nNew bytes. Any existing mapping is discarded.
**
** If successful, this function sets the following variables:
**
** unixFile.pMapRegion
** unixFile.mmapSize
** unixFile.mmapSizeActual
**
** If unsuccessful, an error message is logged via sqlite3_log() and
** the three variables above are zeroed. In this case SQLite should
** continue accessing the database using the xRead() and xWrite()
** methods.
Destructor for pPtr (or NULL)
Where the SELECT should store results
Iterator to advance to next page
FormatMessage returns 0 on failure. Otherwise it
** returns the number of TCHARs written to the output
** buffer, excluding the terminating null char.
xFetch()'d data for this page
** Implementation of the TRIM(), LTRIM(), and RTRIM() functions.
** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
Set to 1 when TABLE matches
** Return a sanitized version of the sector-size of OS file pFile. The
** return value is guaranteed to lie between 32 and MAX_SECTOR_SIZE.
Content registers (after the rowid)
Invalid value
The cookie mask contains one bit for each database file open.
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
** set for each database that is used. Generate code to start a
** transaction on each used database and to verify the schema cookie
** on each used database.
** Return a pointer to static memory containing an SQL NULL value.
** Move to the next matching rowid.
** Free a snapshot handle obtained from sqlite3_snapshot_get().
Index of zColumn in row-record
An attempt to read a column out of a subquery or other
** temporary table.
** Set *ppModule to a pointer to the sqlite3_tokenizer_module
** structure for the unicode tokenizer.
Context object for new user-function
If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
** case the purpose of this call is to estimate the number of rows returned
** by the overall query. Once this estimate has been obtained, the caller
** will invoke this function a second time, passing the estimate as the
** nRowEst parameter.
List of other sharable Btrees from the same db
comment: This is the first term on a leaf that is not the leftmost leaf in
** the segment b-tree. In this case it is necessary to add a term to
** the b-tree hierarchy that is (a) larger than the largest term
** already written to the segment and (b) smaller than or equal to
** this term. In other words, a prefix of (pTerm/nTerm) that is one
** byte longer than the longest prefix (pTerm/nTerm) shares with the
** previous term.
**
** Usually, the previous term is available in pPage->term. The exception
** is if this is the first term written in an incremental-merge step.
** In this case the previous term is not available, so just write a
** copy of (pTerm/nTerm) into the parent node. This is slightly
** inefficient, but still correct.
label: code-design
Assign cursor numbers to the table and all its indices.
Possibly relative input path
List of field names to be indexed
** Convenience functions for opening and closing files using
** sqlite3_malloc() to obtain space for the file-handle structure.
In this case we would like to delete the journal file. If it is
** not possible, then that is not a problem. Deleting the journal file
** here is an optimization only.
**
** Before deleting the journal file, obtain a RESERVED lock on the
** database file. This ensures that the journal file is not deleted
** while it is in use by some other client.
** If the inner loop was generated using a non-null pOrderBy argument,
** then the results were placed in a sorter. After the loop is terminated
** we need to run the sorter and output the results. The following
** routine generates the code needed to do that.
Number of PRIMARY KEY memory cells
Jump here for an error that occurs after successfully allocating
** curMain and calling sqlite3BtreeEnter(). For an error that occurs
** before that point, jump to error_out.
** Return the SorterCompare function to compare values collected by the
** sorter object passed as the only argument.
** This function may only be called while the iterator is pointing to an
** SQLITE_UPDATE or SQLITE_DELETE change (see sqlite3changeset_op()).
** Otherwise, SQLITE_MISUSE is returned.
**
** It sets *ppValue to point to an sqlite3_value structure containing the
** iVal'th value in the old.* record. Or, if that particular value is not
** included in the record (because the change is an UPDATE and the field
** was not modified and is not a PK column), set *ppValue to NULL.
**
** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
** not modified. Otherwise, SQLITE_OK.
156
309
SET clause for UPDATE.
If this is to be the first rowid written to the page, set the
** rowid-pointer in the page-header. Also append a value to the dlidx
** buffer, in case a doclist-index is required.
sqlite3AssertMayAbort() logic
Size of buffer p in bytes
Index in pWC of the next virtual term
The current leaf node is full. Write it out to the database.
4 billion rows
Pointer to left-most node of this depth
If p!=0, it must match the iOff value.
Grow the output buffer if required.
13
comment: These use local variables, so do them in a separate routine
** to avoid having to move the frame pointer in the common case
label: code-design
True after xBegin but before xCommit/xRollback
SQLITE_OS_UNIX
EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
** between 512 and 65536 inclusive.
Skip over position list
** Initialize SQLite.
**
** This routine must be called to initialize the memory allocation,
** VFS, and mutex subsystems prior to doing any serious work with
** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
** this routine will be called automatically by key routines such as
** sqlite3_open().
**
** This routine is a no-op except on its very first call for the process,
** or for the first call after a call to sqlite3_shutdown.
**
** The first thread to call this routine runs the initialization to
** completion. If subsequent threads call this routine before the first
** thread has finished the initialization process, then the subsequent
** threads must block until the first thread finishes with the initialization.
**
** The first thread might call this routine recursively. Recursive
** calls to this routine should not block, of course. Otherwise the
** initialization process would never complete.
**
** Let X be the first thread to enter this routine. Let Y be some other
** thread. Then while the initial invocation of this routine by X is
** incomplete, it is required that:
**
** * Calls to this routine from Y must block until the outer-most
** call by X completes.
**
** * Recursive calls to this routine from thread X return immediately
** without blocking.
MSVC is picky about pulling func ptrs from va lists.
** http://support.microsoft.com/kb/47961
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
Filename in OS encoding
Point the object iterator at the first object
First byte of cell content area
comment: Each unsigned integer in the following array corresponds to a contiguous
** range of unicode codepoints that are not either letters or numbers (i.e.
** codepoints for which this function should return 0).
**
** The most significant 22 bits in each 32-bit value contain the first
** codepoint in the range. The least significant 10 bits are used to store
** the size of the range (always at least 1). In other words, the value
** ((C<<22) + N) represents a range of N codepoints starting with codepoint
** C. It is not possible to represent a range larger than 1023 codepoints
** using this format.
label: code-design
The authorization context
end_block
This is an UPDATE. Foreign key processing is only required if the
** operation modifies one or more child or parent key columns.
** CAPI3REF: Configure database connections
** METHOD: sqlite3
**
** The sqlite3_db_config() interface is used to make configuration
** changes to a [database connection]. The interface is similar to
** [sqlite3_config()] except that the changes apply to a single
** [database connection] (specified in the first argument).
**
** The second argument to sqlite3_db_config(D,V,...) is the
** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
** that indicates what aspect of the [database connection] is being configured.
** Subsequent arguments vary depending on the configuration verb.
**
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
** the call is considered successful.
Currently in a VACUUM
For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
** value. Make a copy of the cell contents and return a pointer to it.
** It is not safe to return a pointer to the memory cell itself as the
** caller may modify the value text encoding.
** Two routines for printing the content of an sqlite3_index_info
** structure. Used for testing and debugging only. If neither
** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
** are no-ops.
Write a table header
Enable automatic indexes
Statements to read/write/delete a record from xxx_node
Regardless of the strategy selected, FTS can deliver rows in rowid (or
** docid) order. Both ascending and descending are possible.
The conch file contains the header, host id and lock file path
This may fail if SQLite value p contains a utf-16 string that must
** be converted to utf-8 and an OOM error occurs while doing so.
Usually, regResult is the first cell in an array of memory cells
** containing the current result row. In this case regOrig is set to the
** same value. However, if the results are being sent to the sorter, the
** values for any expressions that are also part of the sort-key are omitted
** from this array. In this case regOrig is set to zero.
** Deallocate a KeyInfo object
comment:
** Implement steps 3, 4, and 5 of the pcache1Fetch() algorithm described
** in the header of the pcache1Fetch() procedure.
**
** This steps are broken out into a separate procedure because they are
** usually not needed, and by avoiding the stack initialization required
** for these steps, the main pcache1Fetch() procedure can run faster.
label: code-design
Return True
The index associated with pLoop
Compute data for all columns of the new entry, beginning
** with the first column.
If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
** a virtual term for each vector component. The expression object
** used by each such virtual term is pExpr (the full vector IN(...)
** expression). The WhereTerm.iField variable identifies the index within
** the vector on the LHS that the virtual term represents.
**
** This only works if the RHS is a simple SELECT, not a compound
There are pages on the freelist. Reuse one of those pages.
Lhs input changeset
Offset to the cell content area
comment:
** Takes an already filled in unix file and alters it so all file locking
** will be performed on the local proxy lock file. The following fields
** are preserved in the locking context so that they can be restored and
** the unix structure properly cleaned up at close time:
** ->lockingContext
** ->pMethod
label: code-design
SQLITE_OMIT_COMPLETE
True when processing first term on page
SQL statement 1 (see above)
comment:
** When SQLITE_OMIT_WSD is defined, it means that the target platform does
** not support Writable Static Data (WSD) such as global and static variables.
** All variables must either be on the stack or dynamically allocated from
** the heap. When WSD is unsupported, the variable declarations scattered
** throughout the SQLite code must become constants instead. The SQLITE_WSD
** macro is used for this purpose. And instead of referencing the variable
** directly, we use its constant as a key to lookup the run-time allocated
** buffer that holds real variable. The constant is also the initializer
** for the run-time allocated buffer.
**
** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL
** macros become no-ops and have zero performance impact.
label: code-design
Identifier from "INDEXED BY <zIndex>" clause
Size of aDoclist[] in bytes
blocks are atomic
defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt
Opcode: MustBeInt P1 P2 * * *
**
** Force the value in register P1 to be an integer. If the value
** in P1 is not an integer and cannot be converted into an integer
** without data loss, then jump immediately to P2, or if P2==0
** raise an SQLITE_MISMATCH exception.
** This function opens a cursor used to read the input data for an
** incremental merge operation. Specifically, it opens a cursor to scan
** the oldest nSeg segments (idx=0 through idx=(nSeg-1)) in absolute
** level iAbsLevel.
Check to see if a unixShmNode object already exists. Reuse an existing
** one if present. Create a new one if necessary.
** Free all memory allocations in the pParse object
comment:
** CAPI3REF: Online Backup API.
**
** The backup API copies the content of one database into another.
** It is useful either for creating backups of databases or
** for copying in-memory databases to or from persistent files.
**
** See Also: [Using the SQLite Online Backup API]
**
** ^SQLite holds a write transaction open on the destination database file
** for the duration of the backup operation.
** ^The source database is read-locked only while it is being read;
** it is not locked continuously for the entire backup operation.
** ^Thus, the backup may be performed on a live source database without
** preventing other database connections from
** reading or writing to the source database while the backup is underway.
**
** ^(To perform a backup operation:
** <ol>
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
** backup,
** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
** the data between the two databases, and finally
** <li><b>sqlite3_backup_finish()</b> is called to release all resources
** associated with the backup operation.
** </ol>)^
** There should be exactly one call to sqlite3_backup_finish() for each
** successful call to sqlite3_backup_init().
**
** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
**
** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
** [database connection] associated with the destination database
** and the database name, respectively.
** ^The database name is "main" for the main database, "temp" for the
** temporary database, or the name specified after the AS keyword in
** an [ATTACH] statement for an attached database.
** ^The S and M arguments passed to
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
** and database name of the source database, respectively.
** ^The source and destination [database connections] (parameters S and D)
** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
** an error.
**
** ^A call to sqlite3_backup_init() will fail, returning NULL, if
** there is already a read or read-write transaction open on the
** destination database.
**
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
** returned and an error code and error message are stored in the
** destination [database connection] D.
** ^The error code and message for the failed call to sqlite3_backup_init()
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
** [sqlite3_errmsg16()] functions.
** ^A successful call to sqlite3_backup_init() returns a pointer to an
** [sqlite3_backup] object.
** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
** sqlite3_backup_finish() functions to perform the specified backup
** operation.
**
** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
**
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
** the source and destination databases specified by [sqlite3_backup] object B.
** ^If N is negative, all remaining source pages are copied.
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
** are still more pages to be copied, then the function returns [SQLITE_OK].
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
** from source to destination, then it returns [SQLITE_DONE].
** ^If an error occurs while running sqlite3_backup_step(B,N),
** then an [error code] is returned. ^As well as [SQLITE_OK] and
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
**
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
** <ol>
** <li> the destination database was opened read-only, or
** <li> the destination database is using write-ahead-log journaling
** and the destination and source page sizes differ, or
** <li> the destination database is an in-memory database and the
** destination and source page sizes differ.
** </ol>)^
**
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
** the [sqlite3_busy_handler | busy-handler function]
** is invoked (if one is specified). ^If the
** busy-handler returns non-zero before the lock is available, then
** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
** sqlite3_backup_step() can be retried later. ^If the source
** [database connection]
** is being used to write to the source database when sqlite3_backup_step()
** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
** case the call to sqlite3_backup_step() can be retried later on. ^(If
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
** [SQLITE_READONLY] is returned, then
** there is no point in retrying the call to sqlite3_backup_step(). These
** errors are considered fatal.)^ The application must accept
** that the backup operation has failed and pass the backup operation handle
** to the sqlite3_backup_finish() to release associated resources.
**
** ^The first call to sqlite3_backup_step() obtains an exclusive lock
** on the destination file. ^The exclusive lock is not released until either
** sqlite3_backup_finish() is called or the backup operation is complete
** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
** sqlite3_backup_step() obtains a [shared lock] on the source database that
** lasts for the duration of the sqlite3_backup_step() call.
** ^Because the source database is not locked between calls to
** sqlite3_backup_step(), the source database may be modified mid-way
** through the backup process. ^If the source database is modified by an
** external process or via a database connection other than the one being
** used by the backup operation, then the backup will be automatically
** restarted by the next call to sqlite3_backup_step(). ^If the source
** database is modified by the using the same database connection as is used
** by the backup operation, then the backup database is automatically
** updated at the same time.
**
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
**
** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
** application wishes to abandon the backup operation, the application
** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
** ^The sqlite3_backup_finish() interfaces releases all
** resources associated with the [sqlite3_backup] object.
** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
** active write-transaction on the destination database is rolled back.
** The [sqlite3_backup] object is invalid
** and may not be used following a call to sqlite3_backup_finish().
**
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
** sqlite3_backup_step() errors occurred, regardless or whether or not
** sqlite3_backup_step() completed.
** ^If an out-of-memory condition or IO error occurred during any prior
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
** sqlite3_backup_finish() returns the corresponding [error code].
**
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
** is not a permanent error and does not affect the return value of
** sqlite3_backup_finish().
**
** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
**
** ^The sqlite3_backup_remaining() routine returns the number of pages still
** to be backed up at the conclusion of the most recent sqlite3_backup_step().
** ^The sqlite3_backup_pagecount() routine returns the total number of pages
** in the source database at the conclusion of the most recent
** sqlite3_backup_step().
** ^(The values returned by these functions are only updated by
** sqlite3_backup_step(). If the source database is modified in a way that
** changes the size of the source database or the number of pages remaining,
** those changes are not reflected in the output of sqlite3_backup_pagecount()
** and sqlite3_backup_remaining() until after the next
** sqlite3_backup_step().)^
**
** <b>Concurrent Usage of Database Handles</b>
**
** ^The source [database connection] may be used by the application for other
** purposes while a backup operation is underway or being initialized.
** ^If SQLite is compiled and configured to support threadsafe database
** connections, then the source database connection may be used concurrently
** from within other threads.
**
** However, the application must guarantee that the destination
** [database connection] is not passed to any other API (by any thread) after
** sqlite3_backup_init() is called and before the corresponding call to
** sqlite3_backup_finish(). SQLite does not currently check to see
** if the application incorrectly accesses the destination [database connection]
** and so no error code is reported, but the operations may malfunction
** nevertheless. Use of the destination database connection while a
** backup is in progress might also also cause a mutex deadlock.
**
** If running in [shared cache mode], the application must
** guarantee that the shared cache used by the destination database
** is not accessed while the backup is running. In practice this means
** that the application must guarantee that the disk file being
** backed up to is not accessed by any connection within the process,
** not just the specific connection that was passed to sqlite3_backup_init().
**
** The [sqlite3_backup] object itself is partially threadsafe. Multiple
** threads may safely make multiple concurrent calls to sqlite3_backup_step().
** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
** APIs are not strictly speaking threadsafe. If they are invoked at the
** same time as another thread is invoking sqlite3_backup_step() it is
** possible that they return invalid values.
label: code-design
comment:
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
** 0 means mutexes are permanently disable and the library is never
** threadsafe. 1 means the library is serialized which is the highest
** level of threadsafety. 2 means the library is multithreaded - multiple
** threads can use SQLite as long as no two threads try to use the same
** database connection at the same time.
**
** Older versions of SQLite used an optional THREADSAFE macro.
** We support that for legacy.
**
** To ensure that the correct value of "THREADSAFE" is reported when querying
** for compile-time options at runtime (e.g. "PRAGMA compile_options"), this
** logic is partially replicated in ctime.c. If it is updated here, it should
** also be updated there.
label: code-design
Saved value of db->flags
VFS to use for this b-tree
Wrong number of arguments means "no match"
** Implementation of xSync() method. Flush the contents of the pending-terms
** hash-table to the database.
COLUMNKW => ID
comment: Give a better score to a function with a specific number of arguments
** than to function that accepts any number of arguments.
label: code-design
Clear MemPage.isInit to make sure the corruption detection code in
** btreeInitPage() is executed.
An ephemeral table
Assuming the record contains N fields, the record format looks
** like this:
**
** ------------------------------------------------------------------------
** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
** ------------------------------------------------------------------------
**
** Data(0) is taken from register P1. Data(1) comes from register P1+1
** and so forth.
**
** Each type field is a varint representing the serial type of the
** corresponding data element (see sqlite3VdbeSerialType()). The
** hdr-size field is also a varint which is the offset from the beginning
** of the record to data0.
WHERE clause terms
** A structure to store values read from the rbu_state table in memory.
If the ORDER BY clause contains only columns in the current
** virtual table then allocate space for the aOrderBy part of
** the sqlite3_index_info structure.
** Powersafe overwrite is on by default. But can be turned off using
** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
True for an ephemeral table
The new object must be linked on to the end of the list, not
** simply added to the start of it. This is to ensure that the
** tables within the output of sqlite3changegroup_output() are in
** the right order.
Release the page reference.
** Constants for the largest and smallest possible 64-bit signed integers.
SQL to be evaluated
Either an error, or no such table.
** Append a new element to the given IdList. Create a new IdList if
** need be.
**
** A new IdList is returned, or NULL if malloc() fails.
** Register built-in functions used to help implement ALTER TABLE
The new state to shift in
WHERE clause for partial indices
Name of this database. (schema name, not filename)
True for select lists like "count(*)"
IN/OUT: Incr. by number tokens inserted
Parent tokenizer module
xRead
The score for this node. Smallest goes first.
If the destination is DistQueue, then cursor (iParm+1) is open
** on a second ephemeral index that holds all values every previously
** added to the queue.
** Report an error that an expression is not valid for some set of
** pNC->ncFlags values determined by validMask.
if exponent is present
** Determine the largest segment index value that exists within absolute
** level iAbsLevel+1. If no error occurs, set *piIdx to this value plus
** one before returning SQLITE_OK. Or, if there are no segments at all
** within level iAbsLevel, set *piIdx to zero.
**
** If an error occurs, return an SQLite error code. The final value of
** *piIdx is undefined in this case.
** Advance the cursor to the next entry in the database.
** Return value:
**
** SQLITE_OK success
** SQLITE_DONE cursor is already pointing at the last element
** otherwise some kind of error occurred
**
** The main entry point is sqlite3BtreeNext(). That routine is optimized
** for the common case of merely incrementing the cell counter BtCursor.aiIdx
** to the next cell on the current page. The (slower) btreeNext() helper
** routine is called when it is necessary to move to a different page or
** to restore the cursor.
**
** If bit 0x01 of the F argument in sqlite3BtreeNext(C,F) is 1, then the
** cursor corresponds to an SQL index and this routine could have been
** skipped if the SQL index had been a unique index. The F argument
** is a hint to the implement. SQLite btree implementation does not use
** this hint, but COMDB2 does.
Function for logging
Output character index
We cannot be in random rowid mode if this is
** an AUTOINCREMENT table.
True if src db requires unlocking
Current index is unique
Number of input segments
** CAPI3REF: Enable Or Disable A Session Object
**
** Enable or disable the recording of changes by a session object. When
** enabled, a session object records changes made to the database. When
** disabled - it does not. A newly created session object is enabled.
** Refer to the documentation for [sqlite3session_changeset()] for further
** details regarding how enabling and disabling a session object affects
** the eventual changesets.
**
** Passing zero to this function disables the session. Passing a value
** greater than zero enables it. Passing a value less than zero is a
** no-op, and may be used to query the current state of the session.
**
** The return value indicates the final state of the session object: 0 if
** the session is disabled, or 1 if it is enabled.
** Acquire a lock on the handle h
comment: A memory allocation of a number of bytes which is near the maximum
** signed integer value might cause an integer overflow inside of the
** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
** 255 bytes of overhead. SQLite itself will never use anything near
** this amount. The only way to reach the limit is with sqlite3_malloc()
label: code-design
Add pPage to the dirty list
** Implementation of xOpen method.
** Arguments aLeft and aRight are pointers to change records for table pTab.
** This function returns true if the two records apply to the same row (i.e.
** have the same values stored in the primary key columns), or false
** otherwise.
Final leaf to traverse
The text of the modifier
Initialize the node to no-match
27
** Merge two lists of pages connected by pDirty and in pgno order.
** Do not bother fixing the pDirtyPrev pointers.
29
Number of references to this node
6
xConnect - connect to an existing table
** Change the string value of an sqlite3_value object
Set up the input stream
If bCommit is zero, this loop runs exactly once and page pLastPg
** is swapped with the first free page pulled off the free list.
**
** On the other hand, if bCommit is greater than zero, then keep
** looping until a free-page located within the first nFin pages
** of the file is found.
Get the exclusive locks at the system level. Then if successful
** also mark the local connection as being locked.
Add this many extra columns to the end
Table cursor
************* End of fts3_hash.h ******************************************
Provide the ability to easily simulate an I/O error during testing
Table whose indices are to be analyzed
This loop runs once for each destination page spanned by the source
** page. For each iteration, variable iOff is set to the byte offset
** of the destination page.
Close any open statement handles.
Set of pages moved to free-list this transaction
Get the conversion type modifier
88..8f ........
"stat" column of stat1 table
e0..e7 ........
50..57 PQRSTUVW
First arg to busy callback
Composite sort order
1st argument to the access auth function
Max frame that can be backfilled
Output operand
comment: TODO: Check that both arguments are non-NULL
label: requirement
On Android, ftruncate() always uses 32-bit offsets, even if
** _FILE_OFFSET_BITS=64 is defined. This means it is unsafe to attempt to
** truncate a file to any size larger than 2GiB. Silently ignore any
** such attempts.
Buffer containing term
Set iBestLvl to the level to read input segments from.
Pointer to application-specific data
The WHERE_* flags defined in sqliteInt.h
If zName is NULL, the upper layer is requesting a temp file.
** Create a new mask for cursor iCursor.
**
** There is one cursor per table in the FROM clause. The number of
** tables in the FROM clause is limited by a test early in the
** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]
** array will never overflow.
Never called with prior errors
Number of cells on this page, local and ovfl
As there exists an unusable MATCH constraint this is an
** unusable plan. Set a prohibitively high cost.
Information for internal btree tables
3
azColumn
************* Include sqlite3ext.h in the middle of loadext.c *************
vtabarg ::=
Constant factoring
Information desired. SQLITE_SCANSTAT_*
Generate the expected index checksum based on the contents of the
** %_content table. This block stores the checksum in ctx.cksum.
Open all tables in the pTabList and any indices selected for
** searching those tables.
OUTPUT: True if column is auto-increment
** Attempt to allocate and return a pointer to a zeroed block of nByte
** bytes.
**
** If an error (i.e. an OOM condition) occurs, return NULL and leave an
** error code in the rbu handle passed as the first argument. Or, if an
** error has already occurred when this function is called, return NULL
** immediately without attempting the allocation or modifying the stored
** error code.
910
xDisconnect
Name of the database
** Read a 64-bit variable-length integer from memory starting at p[0].
** Return the number of bytes read, or 0 on error.
** The value is stored in *v.
Used internally - xBestIndex should ignore
Number of leaf pages yet to be written
Name of database file
** The following global variable is incremented every time a cursor
** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes. The test
** procedures use this information to make sure that indices are
** working correctly. This variable has no function other than to
** help verify the correct operation of the library.
Register holding rowid of CREATE TABLE entry
We are forced to roll back the active transaction. Before doing
** so, abort any other statements this handle currently has active.
** Register a function to be invoked when a transaction commits.
** If the invoked function returns non-zero, then the commit becomes a
** rollback.
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append a blob of data to the buffer.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
same as TK_FLOAT, out2
comment:
** This is the fallback stemmer used when the porter stemmer is
** inappropriate. The input word is copied into the output with
** US-ASCII case folding. If the input word is too long (more
** than 20 bytes if it contains no digits or more than 6 bytes if
** it contains digits) then word is truncated to 20 or 6 bytes
** by taking 10 or 3 bytes from the beginning and end.
label: code-design
OS functions to use for IO
Pointer to value 1
The expression to evaluate
End of [...]
** Create a new tokenizer. The values in the argv[] array are the
** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL
** TABLE statement that created the fts3 table. For example, if
** the following SQL is executed:
**
** CREATE .. USING fts3( ... , tokenizer <tokenizer-name> arg1 arg2)
**
** then argc is set to 2, and the argv[] array contains pointers
** to the strings "arg1" and "arg2".
**
** This method should return either SQLITE_OK (0), or an SQLite error
** code. If SQLITE_OK is returned, then *ppTokenizer should be set
** to point at the newly created tokenizer structure. The generic
** sqlite3_tokenizer.pModule variable should not be initialized by
** this callback. The caller will do so.
Previous result register. No uniqueness if 0
Index to read from
defined(SQLITE_MUTEX_OMIT)
Bytes of space to allocate at pRet
SQLITE_ENABLE_CURSOR_HINTS
Maximum difference in token positions
** Set the value returned by the sqlite3_last_insert_rowid() API function.
** CAPI3REF: Obtain A Composite Changeset From A Changegroup
**
** Obtain a buffer containing a changeset (or patchset) representing the
** current contents of the changegroup. If the inputs to the changegroup
** were themselves changesets, the output is a changeset. Or, if the
** inputs were patchsets, the output is also a patchset.
**
** As with the output of the sqlite3session_changeset() and
** sqlite3session_patchset() functions, all changes related to a single
** table are grouped together in the output of this function. Tables appear
** in the same order as for the very first changeset added to the changegroup.
** If the second or subsequent changesets added to the changegroup contain
** changes for tables that do not appear in the first changeset, they are
** appended onto the end of the output changeset, again in the order in
** which they are first encountered.
**
** If an error occurs, an SQLite error code is returned and the output
** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
** is returned and the output variables are set to the size of and a
** pointer to the output buffer, respectively. In this case it is the
** responsibility of the caller to eventually free the buffer using a
** call to sqlite3_free().
If iCol is less than zero, then the expression requests the
** rowid of the sub-select or view. This expression is legal (see
** test case misc2.2.2) - it always evaluates to NULL.
expr ::= expr in_op nm dbnm paren_exprlist
Index of *output* segment in iAbsLevel+1
** Is the sqlite3ErrName() function needed in the build? Currently,
** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when
** OSTRACE is enabled), and by several "test*.c" files (which are
** compiled using SQLITE_TEST).
CONFLICTCROSSCURRENT_TIMESTAMPRIMARYDEFERREDISTINCTDROPFAIL
At this point:
** iFreeBlk: First freeblock after iStart, or zero if none
** iPtr: The address of a pointer to iFreeBlk
**
** Check to see if iFreeBlk should be coalesced onto the end of iStart.
Next free slot in %_segments
** Open the database handle and attach the RBU database as "rbu". If an
** error occurs, leave an error code and message in the RBU handle.
Candidate values for BtLock.eLock
If requesting a write-lock, then the Btree must have an open write
** transaction on this file. And, obviously, for this to be so there
** must be an open write transaction on the file itself.
OUT: size of doclist in bytes
comment: It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
** that call was dangerous and had no detectable benefit since the cache
** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
** has been removed.
label: code-design
The global PGroup for mode (2)
Check for the zero-length marker in the %_segments table
*************************************************************************
** Interface to code in fts5_aux.c.
********* End of lemon-generated parsing tables ****************************
comment:
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
** KEYWORDS: {application-defined SQL function}
** KEYWORDS: {application-defined SQL functions}
** METHOD: sqlite3
**
** ^These functions (collectively known as "function creation routines")
** are used to add SQL functions or aggregates or to redefine the behavior
** of existing SQL functions or aggregates. The only differences between
** these routines are the text encoding expected for
** the second parameter (the name of the function being created)
** and the presence or absence of a destructor callback for
** the application data pointer.
**
** ^The first parameter is the [database connection] to which the SQL
** function is to be added. ^If an application uses more than one database
** connection then application-defined SQL functions must be added
** to each database connection separately.
**
** ^The second parameter is the name of the SQL function to be created or
** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
** representation, exclusive of the zero-terminator. ^Note that the name
** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
** ^Any attempt to create a function with a longer name
** will result in [SQLITE_MISUSE] being returned.
**
** ^The third parameter (nArg)
** is the number of arguments that the SQL function or
** aggregate takes. ^If this parameter is -1, then the SQL function or
** aggregate may take any number of arguments between 0 and the limit
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
** parameter is less than -1 or greater than 127 then the behavior is
** undefined.
**
** ^The fourth parameter, eTextRep, specifies what
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
** its parameters. The application should set this parameter to
** [SQLITE_UTF16LE] if the function implementation invokes
** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
** implementation invokes [sqlite3_value_text16be()] on an input, or
** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
** otherwise. ^The same SQL function may be registered multiple times using
** different preferred text encodings, with different implementations for
** each encoding.
** ^When multiple implementations of the same function are available, SQLite
** will pick the one that involves the least amount of data conversion.
**
** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
** to signal that the function will always return the same result given
** the same inputs within a single SQL statement. Most SQL functions are
** deterministic. The built-in [random()] SQL function is an example of a
** function that is not deterministic. The SQLite query planner is able to
** perform additional optimizations on deterministic functions, so use
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
**
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
** function can gain access to this pointer using [sqlite3_user_data()].)^
**
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
** pointers to C-language functions that implement the SQL function or
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
** callback only; NULL pointers must be passed as the xStep and xFinal
** parameters. ^An aggregate SQL function requires an implementation of xStep
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
** SQL function or aggregate, pass NULL pointers for all three function
** callbacks.
**
** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
** then it is destructor for the application data pointer.
** The destructor is invoked when the function is deleted, either by being
** overloaded or when the database connection closes.)^
** ^The destructor is also invoked if the call to
** sqlite3_create_function_v2() fails.
** ^When the destructor callback of the tenth parameter is invoked, it
** is passed a single argument which is a copy of the application data
** pointer which was the fifth parameter to sqlite3_create_function_v2().
**
** ^It is permitted to register multiple implementations of the same
** functions with the same name but with either differing numbers of
** arguments or differing preferred text encodings. ^SQLite will use
** the implementation that most closely matches the way in which the
** SQL function is used. ^A function implementation with a non-negative
** nArg parameter is a better match than a function implementation with
** a negative nArg. ^A function where the preferred text encoding
** matches the database encoding is a better
** match than a function where the encoding is different.
** ^A function where the encoding difference is between UTF16le and UTF16be
** is a closer match than a function where the encoding difference is
** between UTF8 and UTF16.
**
** ^Built-in functions may be overloaded by new application-defined functions.
**
** ^An application-defined function is permitted to call other
** SQLite interfaces. However, such calls must not
** close the database connection nor finalize or reset the prepared
** statement in which the function is running.
label: code-design
** Query a blob handle for the size of the data.
**
** The Incrblob.nByte field is fixed for the lifetime of the Incrblob
** so no mutex is required for access.
EP_xIsSelect and op = IN, EXISTS, SELECT
Result of an sqlite3BtreeLast()
Number of zero bytes at the end of the record
Register allocations
** Private interfaces - callable only by other where.c routines.
**
** where.c:
Iterate in descending rowid order
Return address register for reset subroutine
assert( p->rc==SQLITE_OK );
True if iPrev is valid
flag values passed to the btree insert
If this is the first header read from the journal, truncate the
** database file back to its original size.
Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise
** an out-of-order write following a WAL restart could result in
** database corruption. See the ticket:
**
** http://localhost:591/sqlite/info/ff5be73dee
Value to be set
1-byte header, 16-byte host id, path
** Add the size of memory allocation "p" to the count in
** *db->pnBytesFreed.
The pager calls this method to signal that it has done
** a rollback and that the database is therefore unchanged and
** it hence it is OK for the transaction change counter to be
** unchanged.
Number of outputs for the new entry
Assert the truth of VdbeCoverageAlwaysTaken() and
** VdbeCoverageNeverTaken()
Size of changeset in bytes
Number of arguments. -1 means unlimited
** Implementation of the sqlite3_pcache.xShrink method.
**
** Free up as much memory as possible.
*****************************************************************************
****************************** No-op Locking **********************************
**
** Of the various locking implementations available, this is by far the
** simplest: locking is ignored. No attempt is made to lock the database
** file for reading or writing.
**
** This locking mode is appropriate for use on read-only databases
** (ex: databases that are burned into CD-ROM, for example.) It can
** also be used if the application employs some external mechanism to
** prevent simultaneous access of the same database by two or more
** database connections. But there is a serious risk of database
** corruption if this locking mode is used in situations where multiple
** database connections are accessing the same database file at the same
** time and one or more of those connections are writing.
Iterator to read values from
** Convert the text beginning at *pz into an integer and return
** its value. Advance *pz to point to the first character past
** the integer.
**
** This function used for parameters to merge= and incrmerge=
** commands.
Second PmaReader to compare
The element to be inserted
Next offset in pgidx
First byte past end of available space
** Update the maximum rowid for an autoincrement calculation.
**
** This routine should be called when the regRowid register holds a
** new rowid that is about to be inserted. If that new rowid is
** larger than the maximum rowid in the memId memory cell, then the
** memory cell is updated.
Size of buffer pointed to by zHeader
See if it is possible to write these frames into the start of the
** log file, instead of appending to it at pWal->hdr.mxFrame.
Prevent the single-thread code below
Expressions of the form:
**
** expr1 IN (?1)
** expr1 NOT IN (?2)
**
** with exactly one value on the RHS can be simplified to something
** like this:
**
** expr1 == ?1
** expr1 <> ?2
**
** But, the RHS of the == or <> is marked with the EP_Generic flag
** so that it may not contribute to the computation of comparison
** affinity or the collating sequence to use for comparison. Otherwise,
** the semantics would be subtly different from IN or NOT IN.
Auxiliary data storage
cast works around VC++ bug
Array of indexes for this table
LIKE range processing counter register (times 2)
** Set the suggested cache-size value.
comment:
** CAPI3REF: Constants Defining Special Destructor Behavior
**
** These are special values for the destructor that is passed in as the
** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
** argument is SQLITE_STATIC, it means that the content pointer is constant
** and will never change. It does not need to be destroyed. ^The
** SQLITE_TRANSIENT value means that the content will likely change in
** the near future and that SQLite should make its own private copy of
** the content before returning.
**
** The typedef is necessary to work around problems in certain
** C++ compilers.
label: code-design
Data from the btree layer
Index in aiMap[]
Current value of 'term' column
Operation NULL
If this is a scalar select that is part of an expression, then
** store the results in the appropriate memory cell or array of
** memory cells and break out of the scan loop.
Array of characters to make exceptions
comment:
** TODO: Make this more efficient!
label: code-design
Write new cursor here
Child page number
** Clear the Rtree.pNodeBlob object
** Pseudo-code for loop that calls stat_push():
**
** Rewind csr
** if eof(csr) goto end_of_scan;
** regChng = 0
** goto chng_addr_0;
**
** next_row:
** regChng = 0
** if( idx(0) != regPrev(0) ) goto chng_addr_0
** regChng = 1
** if( idx(1) != regPrev(1) ) goto chng_addr_1
** ...
** regChng = N
** goto chng_addr_N
**
** chng_addr_0:
** regPrev(0) = idx(0)
** chng_addr_1:
** regPrev(1) = idx(1)
** ...
**
** endDistinctTest:
** regRowid = idx(rowid)
** stat_push(P, regChng, regRowid)
** Next csr
** if !eof(csr) goto next_row;
**
** end_of_scan:
Step 3. The LHS is now known to be non-NULL. Do the binary search
** of the RHS using the LHS as a probe. If found, the result is
** true.
520
Leave cursor pointing at NEXT or PREV
2: (!start_constraints && startEq && !bRev)
CREATE TABLE x(input, token, start, end, position)
Replacement table for iParent
** The number of times that a ReadFile(), WriteFile(), and DeleteFile()
** will be retried following a locking error - probably caused by
** antivirus software. Also the initial delay before the first retry.
** The delay increases linearly with each retry.
Fields below are only available in SQLite 3.10.0 and later
3 -> UNCOMPRESS
67
The pager to set safety level for
SQLITE_NOMEM
** 2007 August 14
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes.
**
** This file contains code that is common across all mutex implementations.
** An abstract type for a pointer to an IO method finder function:
NULL Function Name
Database containing the trigger
** The implementation of user-defined scalar function fts5_decode().
Field to extract from pVector
Populate the change object. None of the preupdate_old(),
** preupdate_new() or SerializeValue() calls below may fail as all
** required values and encodings have already been cached in memory.
** It is not possible for an OOM to occur in this block.
The view was modified by some other optimization such as
** pushDownWhereTerms()
Write-ahead log used by "journal_mode=wal"
Size of array apRegion
** Insert a new FuncDef into a FuncDefHash hash table.
** CAPI3REF: Overload A Function For A Virtual Table
** METHOD: sqlite3
**
** ^(Virtual tables can provide alternative implementations of functions
** using the [xFindFunction] method of the [virtual table module].
** But global versions of those functions
** must exist in order to be overloaded.)^
**
** ^(This API makes sure a global version of a function with a particular
** name and number of parameters exists. If no such function exists
** before this API is called, a new function is created.)^ ^The implementation
** of the new function always causes an exception to be thrown. So
** the new function is not good for anything by itself. Its only
** purpose is to be a placeholder function that can be overloaded
** by a [virtual table].
Bytes required to hold all column names
sqlite3_bind_int(p->pIdxWriter, 1, pWriter->iSegid);
(4)
One of TRIGGER_BEFORE, TRIGGER_AFTER
** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
** that name in the set of source tables in pSrcList and make the pExpr
** expression node refer back to that source column. The following changes
** are made to pExpr:
**
** pExpr->iDb Set the index in db->aDb[] of the database X
** (even if X is implied).
** pExpr->iTable Set to the cursor number for the table obtained
** from pSrcList.
** pExpr->pTab Points to the Table structure of X.Y (even if
** X and/or Y are implied.)
** pExpr->iColumn Set to the column number within the table.
** pExpr->op Set to TK_COLUMN.
** pExpr->pLeft Any expression this points to is deleted
** pExpr->pRight Any expression this points to is deleted.
**
** The zDb variable is the name of the database (the "X"). This value may be
** NULL meaning that name is of the form Y.Z or Z. Any available database
** can be used. The zTable variable is the name of the table (the "Y"). This
** value can be NULL if zDb is also NULL. If zTable is NULL it
** means that the form of the name is Z and that columns from any table
** can be used.
**
** If the name cannot be resolved unambiguously, leave an error message
** in pParse and return WRC_Abort. Return WRC_Prune on success.
xVdbeBranch
38
True if this cursor is at EOF
comment:
** This routine ends a transaction. A transaction is usually ended by
** either a COMMIT or a ROLLBACK operation. This routine may be called
** after rollback of a hot-journal, or if an error occurs while opening
** the journal file or writing the very first journal-header of a
** database transaction.
**
** This routine is never called in PAGER_ERROR state. If it is called
** in PAGER_NONE or PAGER_SHARED state and the lock held is less
** exclusive than a RESERVED lock, it is a no-op.
**
** Otherwise, any active savepoints are released.
**
** If the journal file is open, then it is "finalized". Once a journal
** file has been finalized it is not possible to use it to roll back a
** transaction. Nor will it be considered to be a hot-journal by this
** or any other database connection. Exactly how a journal is finalized
** depends on whether or not the pager is running in exclusive mode and
** the current journal-mode (Pager.journalMode value), as follows:
**
** journalMode==MEMORY
** Journal file descriptor is simply closed. This destroys an
** in-memory journal.
**
** journalMode==TRUNCATE
** Journal file is truncated to zero bytes in size.
**
** journalMode==PERSIST
** The first 28 bytes of the journal file are zeroed. This invalidates
** the first journal header in the file, and hence the entire journal
** file. An invalid journal file cannot be rolled back.
**
** journalMode==DELETE
** The journal file is closed and deleted using sqlite3OsDelete().
**
** If the pager is running in exclusive mode, this method of finalizing
** the journal file is never used. Instead, if the journalMode is
** DELETE and the pager is in exclusive mode, the method described under
** journalMode==PERSIST is used instead.
**
** After the journal is finalized, the pager moves to PAGER_READER state.
** If running in non-exclusive rollback mode, the lock on the file is
** downgraded to a SHARED_LOCK.
**
** SQLITE_OK is returned if no error occurs. If an error occurs during
** any of the IO operations to finalize the journal file or unlock the
** database then the IO error code is returned to the user. If the
** operation to finalize the journal file fails, then the code still
** tries to unlock the database file if not in exclusive mode. If the
** unlock operation fails as well, then the first error code related
** to the first error encountered (the journal finalization one) is
** returned.
label: code-design
cmd ::= DROP VIEW ifexists fullname
Number of parameters
** Size of the column cache
** If it is currently unknown whether or not the FTS table has an %_stat
** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
** if an error occurs.
Call to try make a page clean
ColCache valid when aColCache[].iLevel<=iCacheLevel
IF
Error detected by xRecordCompare (CORRUPT or NOMEM)
True to grab the global stats
Pointer to buffer containing block data
Current size of node in bytes
** Merge two lists of RowSetEntry objects. Remove duplicates.
**
** The input lists are connected via pRight pointers and are
** assumed to each already be in sorted order.
The phrase object to trim the doclist of
Address of "loops" counter
** Round up a request size to the next valid allocation size.
** A WhereTerm with eOperator==WO_OR has its u.pOrInfo pointer set to
** a dynamically allocated instance of the following structure.
Loop through the doclists in the aaOutput[] array. Merge them all
** into a single doclist.
synopsis: r[P2@P3+1]=r[P1@P3+1]
Size of new segment at iAbsLevel
Number of tokens seen so far
nPage
** This routine generates VDBE code to compute the content of a WITH RECURSIVE
** query of the form:
**
** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
** \___________/ \_______________/
** p->pPrior p
**
**
** There is exactly one reference to the recursive-table in the FROM clause
** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
**
** The setup-query runs once to generate an initial set of rows that go
** into a Queue table. Rows are extracted from the Queue table one by
** one. Each row extracted from Queue is output to pDest. Then the single
** extracted row (now in the iCurrent table) becomes the content of the
** recursive-table for a recursive-query run. The output of the recursive-query
** is added back into the Queue table. Then another row is extracted from Queue
** and the iteration continues until the Queue table is empty.
**
** If the compound query operator is UNION then no duplicate rows are ever
** inserted into the Queue table. The iDistinct table keeps a copy of all rows
** that have ever been inserted into Queue and causes duplicates to be
** discarded. If the operator is UNION ALL, then duplicates are allowed.
**
** If the query has an ORDER BY, then entries in the Queue table are kept in
** ORDER BY order and the first entry is extracted for each cycle. Without
** an ORDER BY, the Queue table is just a FIFO.
**
** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
** have been output to pDest. A LIMIT of zero means to output no rows and a
** negative LIMIT means to output all rows. If there is also an OFFSET clause
** with a positive value, then the first OFFSET outputs are discarded rather
** than being sent to pDest. The LIMIT count does not begin until after OFFSET
** rows have been skipped.
Most recent error code (SQLITE_*)
left
PCache object
Label for the end of the insertion loop
wqlist
** Count the number of references to columns.
Database to write to
sqlite_stat4.nLt
Ascii for "J"
** This is a convenience routine that makes sure that all thread-specific
** data for this thread has been deallocated.
**
** SQLite no longer uses thread-specific data so this routine is now a
** no-op. It is retained for historical compatibility.
Firstest rowid of other than aFirst[1]
** The following type and function are used to iterate through all opcodes
** in a Vdbe main program and each of the sub-programs (triggers) it may
** invoke directly or indirectly. It should be used as follows:
**
** Op *pOp;
** VdbeOpIter sIter;
**
** memset(&sIter, 0, sizeof(sIter));
** sIter.v = v; // v is of type Vdbe*
** while( (pOp = opIterNext(&sIter)) ){
** // Do something with pOp
** }
** sqlite3DbFree(v->db, sIter.apSub);
**
Shorthand for pScan->pWC
** This function is the implementation of both the xConnect and xCreate
** methods of the r-tree virtual table.
**
** argv[0] -> module name
** argv[1] -> database name
** argv[2] -> table name
** argv[...] -> column names...
Reg array containing OLD.* and NEW.* values
Opcode: Delete P1 P2 P3 P4 P5
**
** Delete the record at which the P1 cursor is currently pointing.
**
** If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then
** the cursor will be left pointing at either the next or the previous
** record in the table. If it is left pointing at the next record, then
** the next Next instruction will be a no-op. As a result, in this case
** it is ok to delete a record from within a Next loop. If
** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
** left in an undefined state.
**
** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
** delete one of several associated with deleting a table row and all its
** associated index entries. Exactly one of those deletes is the "primary"
** delete. The others are all on OPFLAG_FORDELETE cursors or else are
** marked with the AUXDELETE flag.
**
** If the OPFLAG_NCHANGE flag of P2 (NB: P2 not P5) is set, then the row
** change count is incremented (otherwise not).
**
** P1 must not be pseudo-table. It has to be a real table with
** multiple rows.
**
** If P4 is not NULL then it points to a Table object. In this case either
** the update or pre-update hook, or both, may be invoked. The P1 cursor must
** have been positioned using OP_NotFound prior to invoking this opcode in
** this case. Specifically, if one is configured, the pre-update hook is
** invoked if P4 is not NULL. The update-hook is invoked if one is configured,
** P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.
**
** If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
** of the memory cell that contains the value that the rowid of the row will
** be set to by the update.
Offset in pointer map page
** 2002 February 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C-language implementations for many of the SQL
** functions of SQLite. (Some function, and in particular the date and
** time functions, are implemented separately.)
** current_time()
**
** This function returns the same value as time('now').
Number of references to this KeyInfo object
P4 is a pointer to an sqlite3_vtab structure
Release the shared CKPT lock obtained above.
** A constraint has failed while inserting a row into an rtree table.
** Assuming no OOM error occurs, this function sets the error message
** (at pRtree->base.zErrMsg) to an appropriate value and returns
** SQLITE_CONSTRAINT.
**
** Parameter iCol is the index of the leftmost column involved in the
** constraint failure. If it is 0, then the constraint that failed is
** the unique constraint on the id column. Otherwise, it is the rtree
** (c1<=c2) constraint on columns iCol and iCol+1 that has failed.
**
** If an OOM occurs, SQLITE_NOMEM is returned instead of SQLITE_CONSTRAINT.
** Some systems have stricmp(). Others have strcasecmp(). Because
** there is no consistency, we will define our own.
**
** IMPLEMENTATION-OF: R-30243-02494 The sqlite3_stricmp() and
** sqlite3_strnicmp() APIs allow applications and extensions to compare
** the contents of two buffers containing UTF-8 strings in a
** case-independent fashion, using the same definition of "case
** independence" that SQLite uses internally when comparing identifiers.
#include "fts5Int.h"
285
************* End of attach.c *********************************************
Append formatted text (not to exceed N bytes) to the JsonString.
True if resolving columns of CREATE INDEX
cmd ::= PRAGMA nm dbnm EQ nmnum
Sum of the nEq values
** Open a journal file.
**
** The behaviour of the journal file depends on the value of parameter
** nSpill. If nSpill is 0, then the journal file is always create and
** accessed using the underlying VFS. If nSpill is less than zero, then
** all content is always stored in main-memory. Finally, if nSpill is a
** positive value, then the journal file is initially created in-memory
** but may be flushed to disk later on. In this case the journal file is
** flushed to disk either when it grows larger than nSpill bytes in size,
** or when sqlite3JournalCreate() is called.
Remove cells from the start and end of the page
Opcode that opens the sorter
Second part of index name. May be NULL
OR using multiple indices
First token of current snippet
************* Include fts3_tokenizer.h in the middle of fts3Int.h *********
Update the aBest[] array.
List of VALUES() to be inserted
204
GetMeta() and UpdateMeta() cannot fail in this context because
** we already have page 1 loaded into cache and marked dirty.
Opcode: SorterOpen P1 P2 P3 P4 *
**
** This opcode works like OP_OpenEphemeral except that it opens
** a transient index that is specifically designed to sort large
** tables using an external merge-sort algorithm.
**
** If argument P3 is non-zero, then it indicates that the sorter may
** assume that a stable sort considering the first P3 fields of each
** key is sufficient to produce the required results.
How many levels of subquery
** Formulate a statement to DELETE a row from database db. Assuming a table
** structure like this:
**
** CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
**
** The DELETE statement looks like this:
**
** DELETE FROM x WHERE a = :1 AND c = :3 AND (:5 OR b IS :2 AND d IS :4)
**
** Variable :5 (nCol+1) is a boolean. It should be set to 0 if we require
** matching b and d values, or 1 otherwise. The second case comes up if the
** conflict handler is invoked with NOTFOUND and returns CHANGESET_REPLACE.
**
** If successful, SQLITE_OK is returned and SessionApplyCtx.pDelete is left
** pointing to the prepared version of the SQL statement.
Authorize the subquery
List of user defined columns
201
resolvetype ::= IGNORE
Remove the entry in the parent cell.
comment:
** This function is used to add VdbeComment() annotations to a VDBE
** program. It is not used in production code, only for debugging.
label: documentation
if pLimit is null, pOffset will always be null as well.
RTREE_GT or RTREE_GE, or fallthrough of RTREE_EQ
Precompiled statements used by the implementation. Each of these
** statements is run and reset within a single virtual table API call.
** An instance of the following structure stores a database schema.
**
** Most Schema objects are associated with a Btree. The exception is
** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
** In shared cache mode, a single Schema object can be shared by multiple
** Btrees that refer to the same underlying BtShared object.
**
** Schema objects are automatically deallocated when the last Btree that
** references them is destroyed. The TEMP Schema is manually freed by
** sqlite3_close().
*
** A thread must be holding a mutex on the corresponding Btree in order
** to access Schema content. This implies that the thread must also be
** holding a mutex on the sqlite3 connection pointer that owns the Btree.
** For a TEMP Schema, only the connection mutex is required.
comment: content=xxx option, or NULL
label: code-design
** This routine is invoked once per CTE by the parser while parsing a
** WITH clause.
The column of the index to be loaded
File descriptor to close
Invoke the callback function if required
** The first character of the string pointed to by argument z is guaranteed
** to be an open-quote character (see function fts5_isopenquote()).
**
** This function searches for the corresponding close-quote character within
** the string and, if found, dequotes the string in place and adds a new
** nul-terminator byte.
**
** If the close-quote is found, the value returned is the byte offset of
** the character immediately following it. Or, if the close-quote is not
** found, -1 is returned. If -1 is returned, the buffer is left in an
** undefined state.
** Parse a "special" CREATE VIRTUAL TABLE directive and update
** configuration object pConfig as appropriate.
**
** If successful, object pConfig is updated and SQLITE_OK returned. If
** an error occurs, an SQLite error code is returned and an error message
** may be left in *pzErr. It is the responsibility of the caller to
** eventually free any such error message using sqlite3_free().
Buffer containing root node
Number of entries in this segment
Sub-program to execute
** For testing purposes, we sometimes want to preserve the state of
** PRNG and restore the PRNG to its saved state at a later time, or
** to reset the PRNG to its initial state. These routines accomplish
** those tasks.
**
** The sqlite3_test_control() interface calls these routines to
** control the PRNG.
Allocate memory for the Pager structure, PCache object, the
** three file descriptors, the database file name and the journal
** file name. The layout in memory is as follows:
**
** Pager object (sizeof(Pager) bytes)
** PCache object (sqlite3PcacheSize() bytes)
** Database file handle (pVfs->szOsFile bytes)
** Sub-journal file handle (journalFileSize bytes)
** Main journal file handle (journalFileSize bytes)
** Database file name (nPathname+1 bytes)
** Journal file name (nPathname+8+1 bytes)
Schema of the expression
The VFS containing this xAccess method
OUT: Array of indexes for this table
Allocate a new WhereLoop to add to the end of the list
** Set *ppStmt to a statement handle that may be used to iterate through
** all rows in the %_segdir table, from oldest to newest. If successful,
** return SQLITE_OK. If an error occurs while preparing the statement,
** return an SQLite error code.
**
** There is only ever one instance of this SQL statement compiled for
** each FTS3 table.
**
** The statement returns the following columns from the %_segdir table:
**
** 0: idx
** 1: start_block
** 2: leaves_end_block
** 3: end_block
** 4: root
** CAPI3REF: Recover snapshots from a wal file
** EXPERIMENTAL
**
** If all connections disconnect from a database file but do not perform
** a checkpoint, the existing wal file is opened along with the database
** file the next time the database is opened. At this point it is only
** possible to successfully call sqlite3_snapshot_open() to open the most
** recent snapshot of the database (the one at the head of the wal file),
** even though the wal file may contain other valid snapshots for which
** clients have sqlite3_snapshot handles.
**
** This function attempts to scan the wal file associated with database zDb
** of database handle db and make all valid snapshots available to
** sqlite3_snapshot_open(). It is an error if there is already a read
** transaction open on the database, or if the database is not a wal mode
** database.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
Finalize the journal file.
The columns to change in the UPDATE statement
** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
** extension is currently being used by a version of SQLite too old to
** support estimatedRows. In that case this function is a no-op.
pNext
************* Continuing where we left off in main.c **********************
If no match is found, search the built-in functions.
**
** If the SQLITE_PreferBuiltin flag is set, then search the built-in
** functions even if a prior app-defined function was found. And give
** priority to built-in functions.
**
** Except, if createFlag is true, that means that we are trying to
** install a new function. Whatever FuncDef structure is returned it will
** have fields overwritten with new information appropriate for the
** new function. But the FuncDefs for built-in functions are read-only.
** So we must not search for built-ins when creating a new function.
Typecast byte array
Significant digits after the decimal point
Malloced memory used by some conversion
** Close all cursors in the current frame.
46
The soft heap limit
Number of virtual tables to lock
Scan visits at most 1 row
Case 3.
OUT: Mapped memory
Memory usable by this allocator
The Z in X.Y.Z cannot be NULL
List of table triggers, if required
** This macro is used to calculate hash key values for data structures. In
** order to use this macro, the entire data structure must be represented
** as a series of unsigned integers. In order to calculate a hash-key value
** for a data structure represented as three such integers, the macro may
** then be used as follows:
**
** int hash_key_value;
** hash_key_value = HASH_APPEND(0, <value 1>);
** hash_key_value = HASH_APPEND(hash_key_value, <value 2>);
** hash_key_value = HASH_APPEND(hash_key_value, <value 3>);
**
** In practice, the data structures this macro is used for are the primary
** key values of modified rows.
Phrase expression
** This function may only be called while the iterator is pointing to an
** SQLITE_UPDATE or SQLITE_INSERT change (see sqlite3changeset_op()).
** Otherwise, SQLITE_MISUSE is returned.
**
** It sets *ppValue to point to an sqlite3_value structure containing the
** iVal'th value in the new.* record. Or, if that particular value is not
** included in the record (because the change is an UPDATE and the field
** was not modified), set *ppValue to NULL.
**
** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
** not modified. Otherwise, SQLITE_OK.
** This routine installs a default busy handler that waits for the
** specified number of milliseconds before returning 0.
******* Begin file fts5.h ********
The WhereLoop object
1420
Flags that may be passed as the third argument to xTokenize()
The SRT_ operation to apply to prior selects
LOOKUP_DOCSIZE
void* int int
** Add MEM_Str to the set of representations for the given Mem. Numbers
** are converted using sqlite3_snprintf(). Converting a BLOB to a string
** is a no-op.
**
** Existing representations MEM_Int and MEM_Real are invalidated if
** bForce is true but are retained if bForce is false.
**
** A MEM_Null value will never be passed to this function. This function is
** used for converting values to text for returning to the user (i.e. via
** sqlite3_value_text()), or for ensuring that values to be used as btree
** keys are strings. In the former case a NULL pointer is returned the
** user and the latter is an internal programming error.
** In this version of BtreeMoveto, pKey is a packed index record
** such as is generated by the OP_MakeRecord opcode. Unpack the
** record and then call BtreeMovetoUnpacked() to do the work.
Operands are not equal
comment:
** CAPI3REF: Advance A Changeset Iterator
**
** This function may only be used with iterators created by function
** [sqlite3changeset_start()]. If it is called on an iterator passed to
** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
** is returned and the call has no effect.
**
** Immediately after an iterator is created by sqlite3changeset_start(), it
** does not point to any change in the changeset. Assuming the changeset
** is not empty, the first call to this function advances the iterator to
** point to the first change in the changeset. Each subsequent call advances
** the iterator to point to the next change in the changeset (if any). If
** no error occurs and the iterator points to a valid change after a call
** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
** Otherwise, if all changes in the changeset have already been visited,
** SQLITE_DONE is returned.
**
** If an error occurs, an SQLite error code is returned. Possible error
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
** SQLITE_NOMEM.
label: code-design
Suppress the first OFFSET entries if there is an OFFSET clause
True to enable full mutexing
Left hand child expression
Transient list of dirty sorted by pgno
OUT: End-of-file flag
12-14
** Give a listing of the program in the virtual machine.
**
** The interface is the same as sqlite3VdbeExec(). But instead of
** running the code, it invokes the callback once for each instruction.
** This feature is used to implement "EXPLAIN".
**
** When p->explain==1, each instruction is listed. When
** p->explain==2, only OP_Explain instructions are listed and these
** are shown in a different format. p->explain==2 is used to implement
** EXPLAIN QUERY PLAN.
**
** When p->explain==1, first the main program is listed, then each of
** the trigger subprograms are listed one by one.
Tell the wal layer that an EXCLUSIVE lock has been obtained (or released)
** by the pager layer on the database file.
Number of segments to merge
Vdbe being configured
True to use prefix-indexes
Create a list of user columns for the content table
************* Continuing where we left off in loadext.c *******************
Minimum docid to return
** Return true if pTab is a contentless table.
Next input in pColset
** Pragma virtual table module xRowid method.
Packed key if the btree is an index
The index to be used for a inequality constraint
Append the position-list data to the output
comment:
** If the path name starts with a forward slash or a backslash, it is either
** a legal UNC name, a volume relative path, or an absolute path name in the
** "Unix" format on Windows. There is no easy way to differentiate between
** the final two cases; therefore, we return the safer return value of TRUE
** so that callers of this function will simply use it verbatim.
label: code-design
comment:
** Change the comment on the most recently coded instruction. Or
** insert a No-op and add the comment to that new instruction. This
** makes the code easier to read during debugging. None of this happens
** in a production build.
label: code-design
** Insert a record into the %_segments table.
If there is already a lock of this type or more restrictive on the
** unixFile, do nothing. Don't use the afp_end_lock: exit path, as
** unixEnterMutex() hasn't been called yet.
rowid >= ?
Allowed equality operators
** Invoke the xRollback method of all virtual tables in the
** sqlite3.aVTrans array. Then clear the array itself.
IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
** contains the text of SQLITE_VERSION macro.
Maximum size of regions mapped by sorter
** Register a VFS with the system. It is harmless to register the same
** VFS multiple times. The new VFS becomes the default if makeDflt is
** true.
Valid operators for constraints
************* Begin file whereInt.h ***************************************
the GROUP BY clause
The pragma statement to run
Matchinfo context
Register holding block-output return address
Either this is the cheapest token in the entire query, or it is
** part of a multi-token phrase. Either way, the entire doclist will
** (eventually) be loaded into memory. It may as well be now.
EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
** leaf table b-tree page.
idlist
Token for <value>, or NULL
Not required due to the previous to assert() statements
Number of leaf pages flushed
** Attempt to set the page size of the destination to match the page size
** of the source.
Pointer to data to append to buffer
Table to append
** The implementation of user-defined scalar functions fts5_expr() (bTcl==0)
** and fts5_expr_tcl() (bTcl!=0).
Current offset within aNode[]
Grab the write lock on the log file. If successful, upgrade to
** PAGER_RESERVED state. Otherwise, return an error code to the caller.
** The busy-handler is not invoked if another connection already
** holds the write-lock. If possible, the upper layer will call it.
** The threadid macro resolves to the thread-id or to 0. Used for
** testing and debugging only.
zNum is greater than 9223372036854775808 so it overflows
get memory map allocation granularity
** An instance of this structure represents a set of one or more CTEs
** (common table expressions) created by a single WITH clause.
Name of the transformation
Current number of samples
Offset to beginning of page header
IMPLEMENTATION-OF: R-34391-24921 The sqlite3_release_memory() routine
** is a no-op returning zero if SQLite is not compiled with
** SQLITE_ENABLE_MEMORY_MANAGEMENT.
The SELECT statement containing the clause
Pointer to right-sibling
9
comment:
** If *pArg is initially negative then this is a query. Set *pArg to
** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
**
** If *pArg is 0 or 1, then clear or set the mask bit of pFile->ctrlFlags.
label: code-design
** This function is called to generate code executed when a row is deleted
** from the parent table of foreign key constraint pFKey and, if pFKey is
** deferred, when a row is inserted into the same table. When generating
** code for an SQL UPDATE operation, this function may be called twice -
** once to "delete" the old row and once to "insert" the new row.
**
** Parameter nIncr is passed -1 when inserting a row (as this may decrease
** the number of FK violations in the db) or +1 when deleting one (as this
** may increase the number of FK constraint problems).
**
** The code generated by this function scans through the rows in the child
** table that correspond to the parent table row being deleted or inserted.
** For each child row found, one of the following actions is taken:
**
** Operation | FK type | Action taken
** --------------------------------------------------------------------------
** DELETE immediate Increment the "immediate constraint counter".
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
** throw a "FOREIGN KEY constraint failed" exception.
**
** INSERT immediate Decrement the "immediate constraint counter".
**
** DELETE deferred Increment the "deferred constraint counter".
** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
** throw a "FOREIGN KEY constraint failed" exception.
**
** INSERT deferred Decrement the "deferred constraint counter".
**
** These operations are identified in the comment at the top of this file
** (fkey.c) as "I.2" and "D.2".
xShmLock
** Create an RBU VFS named zName that accesses the underlying file-system
** via existing VFS zParent. Or, if the zParent parameter is passed NULL,
** then the new RBU VFS uses the default system VFS to access the file-system.
** The new object is registered as a non-default VFS with SQLite before
** returning.
**
** Part of the RBU implementation uses a custom VFS object. Usually, this
** object is created and deleted automatically by RBU.
**
** The exception is for applications that also use zipvfs. In this case,
** the custom VFS must be explicitly created by the user before the RBU
** handle is opened. The RBU VFS should be installed so that the zipvfs
** VFS uses the RBU VFS, which in turn uses any other VFS layers in use
** (for example multiplexor) to access the file-system. For example,
** to assemble an RBU enabled VFS stack that uses both zipvfs and
** multiplexor (error checking omitted):
**
** // Create a VFS named "multiplex" (not the default).
** sqlite3_multiplex_initialize(0, 0);
**
** // Create an rbu VFS named "rbu" that uses multiplexor. If the
** // second argument were replaced with NULL, the "rbu" VFS would
** // access the file-system via the system default VFS, bypassing the
** // multiplexor.
** sqlite3rbu_create_vfs("rbu", "multiplex");
**
** // Create a zipvfs VFS named "zipvfs" that uses rbu.
** zipvfs_create_vfs_v3("zipvfs", "rbu", 0, xCompressorAlgorithmDetector);
**
** // Make zipvfs the default VFS.
** sqlite3_vfs_register(sqlite3_vfs_find("zipvfs"), 1);
**
** Because the default VFS created above includes a RBU functionality, it
** may be used by RBU clients. Attempting to use RBU with a zipvfs VFS stack
** that does not include the RBU layer results in an error.
**
** The overhead of adding the "rbu" VFS to the system is negligible for
** non-RBU users. There is no harm in an application accessing the
** file-system via "rbu" all the time, even if it only uses RBU functionality
** occasionally.
The binary record
** Rtree virtual table module xNext method.
Type of token
Size of buffer zPrev in bytes
Name of the column.
In a join with a USING clause, omit columns in the
** using clause from the table on the right.
** Convert the given register into a string if it isn't one
** already. Return non-zero if a malloc() fails.
If the database supports auto-vacuum, make sure no tables contain
** references to pointer-map pages.
The cell index from which to extract the ID
** The xRename method for rtree module virtual tables.
Left hand side of comparison
Flags
** Return the length (in bytes) of the token that begins at z[0].
** Store the token type in *tokenType before returning.
Verify property (2)
Opcode: FkCounter P1 P2 * * *
** Synopsis: fkctr[P1]+=P2
**
** Increment a "constraint counter" by P2 (P2 may be negative or positive).
** If P1 is non-zero, the database constraint counter is incremented
** (deferred foreign key constraints). Otherwise, if P1 is zero, the
** statement counter is incremented (immediate foreign key constraints).
The entire doclist will not fit on this leaf. The following
** loop iterates through the poslists that make up the current
** doclist.
Substitute function - never called
Expression to pass to authorization callback
The database connection that owns this statement
Force xDisconnect calls on all virtual tables
Result code from this function
*****************************************************************************
*************************** Begin AFP Locking *********************************
**
** AFP is the Apple Filing Protocol. AFP is a network filesystem found
** on Apple Macintosh computers - both OS9 and OSX.
**
** Third-party implementations of AFP are available. But this code here
** only works on OSX.
If there is a WAL file in the file-system, open this database in WAL
** mode. Otherwise, the following function call is a no-op.
Bind the rbu_rowid value to column _rowid_
Apply locks to this open shared-memory segment
Remove terms smaller than this
** Object for iterating through a single segment, visiting each term/rowid
** pair in the segment.
**
** pSeg:
** The segment to iterate through.
**
** iLeafPgno:
** Current leaf page number within segment.
**
** iLeafOffset:
** Byte offset within the current leaf that is the first byte of the
** position list data (one byte passed the position-list size field).
** rowid field of the current entry. Usually this is the size field of the
** position list data. The exception is if the rowid for the current entry
** is the last thing on the leaf page.
**
** pLeaf:
** Buffer containing current leaf page data. Set to NULL at EOF.
**
** iTermLeafPgno, iTermLeafOffset:
** Leaf page number containing the last term read from the segment. And
** the offset immediately following the term data.
**
** flags:
** Mask of FTS5_SEGITER_XXX values. Interpreted as follows:
**
** FTS5_SEGITER_ONETERM:
** If set, set the iterator to point to EOF after the current doclist
** has been exhausted. Do not proceed to the next term in the segment.
**
** FTS5_SEGITER_REVERSE:
** This flag is only ever set if FTS5_SEGITER_ONETERM is also set. If
** it is set, iterate through rowid in descending order instead of the
** default ascending order.
**
** iRowidOffset/nRowidOffset/aRowidOffset:
** These are used if the FTS5_SEGITER_REVERSE flag is set.
**
** For each rowid on the page corresponding to the current term, the
** corresponding aRowidOffset[] entry is set to the byte offset of the
** start of the "position-list-size" field within the page.
**
** iTermIdx:
** Index of current term on iTermLeafPgno.
Primary error code from p->rc
pPager->nRef = 0;
Tiebreaker hash
SQLITE_SYSTEM_MALLOC
Terms that may be omitted
Release memory from the SQLITE_CONFIG_SCRATCH allocation
True if the insert is likely to be an append
Append the varints
** If zNum represents an integer that will fit in 32-bits, then set
** *pValue to that integer and return true. Otherwise return false.
**
** This routine accepts both decimal and hexadecimal notation for integers.
**
** Any non-numeric characters that following zNum are ignored.
** This is different from sqlite3Atoi64() which requires the
** input number to be zero-terminated.
** Parse context structure pFrom has just been used to create a sub-vdbe
** (trigger program). If an error has occurred, transfer error information
** from pFrom to pTo.
** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
** zero the memory before returning a pointer to it. If unsuccessful,
** return NULL.
** Decode a blob of varints into N integers
Current rowid
** Close a blob handle that was previously created using
** sqlite3_blob_open().
************* End of pager.h **********************************************
Current token position
Index that owns this iterator
comment: Read the master journal name from the journal, if it is present.
** If a master journal file name is specified, but the file is not
** present on disk, then the journal is not hot and does not need to be
** played back.
**
** TODO: Technically the following is an error because it assumes that
** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
** mxPathname is 512, which is the same as the minimum allowable value
** for pageSize.
label: code-design
** Return a pointer to the right-most SELECT statement in a compound.
right
Discard the results. This is used for SELECT statements inside
** the body of a TRIGGER. The purpose of such selects is to call
** user-defined functions that have side effects. We do not care
** about the actual results of the select.
The following function deletes the "minor type" or semantic value
** associated with a symbol. The symbol can be either a terminal
** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
** a pointer to the value to be deleted. The code used to do the
** deletions is derived from the %destructor and/or %token_destructor
** directives of the input grammar.
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
** conversions will work.
1:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked)
** CAPI3REF: Retrieving Statement SQL
** METHOD: sqlite3_stmt
**
** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
** SQL text used to create [prepared statement] P if P was
** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
** string containing the SQL text of prepared statement P with
** [bound parameters] expanded.
**
** ^(For example, if a prepared statement is created using the SQL
** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
** and parameter :xyz is unbound, then sqlite3_sql() will return
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
** will return "SELECT 2345,NULL".)^
**
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
** is available to hold the result, or if the result would exceed the
** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
**
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
** option causes sqlite3_expanded_sql() to always return NULL.
**
** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
** automatically freed when the prepared statement is finalized.
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
** is obtained from [sqlite3_malloc()] and must be free by the application
** by passing it to [sqlite3_free()].
Index of new segment
** Return a 64-bit integer value for a query parameter.
cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select
EV: R-46199-30249
Search for the end of the position list within the current page.
table_options ::= WITHOUT nm
************* End of pragma.c *********************************************
************* Begin file fts3_icu.c ***************************************
** Estimate the average size of a row for an index.
Pointer to current poslist
Attempt to locate an element of the hash table pH with a key
** that matches pKey. Return the data for this element if it is
** found, or NULL if there is no match.
Fall through to the next case, OP_String
Lookup by rowid on %_content table
Number of bytes in buffer pB
Populate the cell.aCoord[] array. The first coordinate is azData[3].
**
** NB: nData can only be less than nDim*2+3 if the rtree is mis-declared
** with "column" that are interpreted as table constraints.
** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
** This problem was discovered after years of use, so we silently ignore
** these kinds of misdeclared tables to avoid breaking any legacy.
Database page size in bytes. 1==64K
Vdbe to generate code within
** Construct a new expression node for a function with multiple
** arguments.
** Details:
**
** The %_data table managed by this module,
**
** CREATE TABLE %_data(id INTEGER PRIMARY KEY, block BLOB);
**
** , contains the following 5 types of records. See the comments surrounding
** the FTS5_*_ROWID macros below for a description of how %_data rowids are
** assigned to each fo them.
**
** 1. Structure Records:
**
** The set of segments that make up an index - the index structure - are
** recorded in a single record within the %_data table. The record consists
** of a single 32-bit configuration cookie value followed by a list of
** SQLite varints. If the FTS table features more than one index (because
** there are one or more prefix indexes), it is guaranteed that all share
** the same cookie value.
**
** Immediately following the configuration cookie, the record begins with
** three varints:
**
** + number of levels,
** + total number of segments on all levels,
** + value of write counter.
**
** Then, for each level from 0 to nMax:
**
** + number of input segments in ongoing merge.
** + total number of segments in level.
** + for each segment from oldest to newest:
** + segment id (always > 0)
** + first leaf page number (often 1, always greater than 0)
** + final leaf page number
**
** 2. The Averages Record:
**
** A single record within the %_data table. The data is a list of varints.
** The first value is the number of rows in the index. Then, for each column
** from left to right, the total number of tokens in the column for all
** rows of the table.
**
** 3. Segment leaves:
**
** TERM/DOCLIST FORMAT:
**
** Most of each segment leaf is taken up by term/doclist data. The
** general format of term/doclist, starting with the first term
** on the leaf page, is:
**
** varint : size of first term
** blob: first term data
** doclist: first doclist
** zero-or-more {
** varint: number of bytes in common with previous term
** varint: number of bytes of new term data (nNew)
** blob: nNew bytes of new term data
** doclist: next doclist
** }
**
** doclist format:
**
** varint: first rowid
** poslist: first poslist
** zero-or-more {
** varint: rowid delta (always > 0)
** poslist: next poslist
** }
**
** poslist format:
**
** varint: size of poslist in bytes multiplied by 2, not including
** this field. Plus 1 if this entry carries the "delete" flag.
** collist: collist for column 0
** zero-or-more {
** 0x01 byte
** varint: column number (I)
** collist: collist for column I
** }
**
** collist format:
**
** varint: first offset + 2
** zero-or-more {
** varint: offset delta + 2
** }
**
** PAGE FORMAT
**
** Each leaf page begins with a 4-byte header containing 2 16-bit
** unsigned integer fields in big-endian format. They are:
**
** * The byte offset of the first rowid on the page, if it exists
** and occurs before the first term (otherwise 0).
**
** * The byte offset of the start of the page footer. If the page
** footer is 0 bytes in size, then this field is the same as the
** size of the leaf page in bytes.
**
** The page footer consists of a single varint for each term located
** on the page. Each varint is the byte offset of the current term
** within the page, delta-compressed against the previous value. In
** other words, the first varint in the footer is the byte offset of
** the first term, the second is the byte offset of the second less that
** of the first, and so on.
**
** The term/doclist format described above is accurate if the entire
** term/doclist data fits on a single leaf page. If this is not the case,
** the format is changed in two ways:
**
** + if the first rowid on a page occurs before the first term, it
** is stored as a literal value:
**
** varint: first rowid
**
** + the first term on each page is stored in the same way as the
** very first term of the segment:
**
** varint : size of first term
** blob: first term data
**
** 5. Segment doclist indexes:
**
** Doclist indexes are themselves b-trees, however they usually consist of
** a single leaf record only. The format of each doclist index leaf page
** is:
**
** * Flags byte. Bits are:
** 0x01: Clear if leaf is also the root page, otherwise set.
**
** * Page number of fts index leaf page. As a varint.
**
** * First rowid on page indicated by previous field. As a varint.
**
** * A list of varints, one for each subsequent termless page. A
** positive delta if the termless page contains at least one rowid,
** or an 0x00 byte otherwise.
**
** Internal doclist index nodes are:
**
** * Flags byte. Bits are:
** 0x01: Clear for root page, otherwise set.
**
** * Page number of first child page. As a varint.
**
** * Copy of first rowid on page indicated by previous field. As a varint.
**
** * A list of delta-encoded varints - the first rowid on each subsequent
** child page.
**
** json_group_obj(NAME,VALUE)
**
** Return a JSON object composed of all names and values in the aggregate.
True if "PRAGMA synchronous=N" has been run
(304) sclp ::= selcollist COMMA
transform the db path to a unique cache name
Attempt the UPDATE. In the case of a NOTFOUND or DATA conflict,
** the result will be SQLITE_OK with 0 rows modified.
conch file header length
The file descriptor to be filled in
Next offset to write to
This case when there exist aggregate functions or a GROUP BY clause
** or both
comment:
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated. SQLite
** will unwind its stack and return an error. The argument
** to sqlite3_mutex_alloc() is one of these integer constants:
**
** <ul>
** <li> SQLITE_MUTEX_FAST
** <li> SQLITE_MUTEX_RECURSIVE
** <li> SQLITE_MUTEX_STATIC_MASTER
** <li> SQLITE_MUTEX_STATIC_MEM
** <li> SQLITE_MUTEX_STATIC_OPEN
** <li> SQLITE_MUTEX_STATIC_PRNG
** <li> SQLITE_MUTEX_STATIC_LRU
** <li> SQLITE_MUTEX_STATIC_PMEM
** <li> SQLITE_MUTEX_STATIC_APP1
** <li> SQLITE_MUTEX_STATIC_APP2
** <li> SQLITE_MUTEX_STATIC_APP3
** <li> SQLITE_MUTEX_STATIC_VFS1
** <li> SQLITE_MUTEX_STATIC_VFS2
** <li> SQLITE_MUTEX_STATIC_VFS3
** </ul>
**
** The first two constants cause sqlite3_mutex_alloc() to create
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
** The mutex implementation does not need to make a distinction
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
** not want to. But SQLite will only request a recursive mutex in
** cases where it really needs one. If a faster non-recursive mutex
** implementation is available on the host platform, the mutex subsystem
** might return such a mutex in response to SQLITE_MUTEX_FAST.
**
** The other allowed parameters to sqlite3_mutex_alloc() each return
** a pointer to a static preexisting mutex. Six static mutexes are
** used by the current version of SQLite. Future versions of SQLite
** may add additional static mutexes. Static mutexes are for internal
** use by SQLite only. Applications that use SQLite mutexes should
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
** SQLITE_MUTEX_RECURSIVE.
**
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call. But for the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
label: code-design
Number of terms in subquery FROM clause
Create a list of user columns for the virtual table
cnearset
Virtual table of this cursor
** Allocate and return a pointer to an expression to load the column iCol
** from datasource iSrc in SrcList pSrc.
Number of def. imm constraints when stmt started
If the journal has been truncated, simply stop reading and
** processing the journal. This might happen if the journal was
** not completely written and synced prior to a crash. In that
** case, the database should have never been written in the
** first place so it is OK to simply abandon the rollback.
** op1=INSERT, op2=INSERT -> Unsupported. Discard op2.
** op1=INSERT, op2=UPDATE -> INSERT.
** op1=INSERT, op2=DELETE -> (none)
**
** op1=UPDATE, op2=INSERT -> Unsupported. Discard op2.
** op1=UPDATE, op2=UPDATE -> UPDATE.
** op1=UPDATE, op2=DELETE -> DELETE.
**
** op1=DELETE, op2=INSERT -> UPDATE.
** op1=DELETE, op2=UPDATE -> Unsupported. Discard op2.
** op1=DELETE, op2=DELETE -> Unsupported. Discard op2.
SQLITE_OMIT_LIKE_OPTIMIZATION
Number of slots used in aPoint[]
comment:
** Like malloc(), but remember the size of the allocation
** so that we can find it later using sqlite3MemSize().
**
** For this low-level routine, we are guaranteed that nByte>0 because
** cases of nByte<=0 will be intercepted and dealt with by higher level
** routines.
label: code-design
** This function is called to free superfluous dynamically allocated memory
** held by the pager system. Memory in use by any SQLite pager allocated
** by the current thread may be sqlite3_free()ed.
**
** nReq is the number of bytes of memory required. Once this much has
** been released, the function returns. The return value is the total number
** of bytes of memory released.
Current leaf block (or 0)
array of column indexes
isError!=0 or pVdbe->pAuxData modified
Fts5 table object
** Set the current error code to err_code and clear any prior error message.
** Also set iSysErrno (by calling sqlite3System) if the err_code indicates
** that would be appropriate.
memset(pPager->aHash, 0, sizeof(pPager->aHash));
** Return a pointer to the next prepared statement after pStmt associated
** with database connection pDb. If pStmt is NULL, return the first
** prepared statement for the database connection. Return NULL if there
** are no more.
Forward references to internal structures
Size of every page
** CAPI3REF: SQLite Runtime Status
**
** ^These interfaces are used to retrieve runtime status information
** about the performance of SQLite, and optionally to reset various
** highwater marks. ^The first argument is an integer code for
** the specific parameter to measure. ^(Recognized integer codes
** are of the form [status parameters | SQLITE_STATUS_...].)^
** ^The current value of the parameter is returned into *pCurrent.
** ^The highest recorded value is returned in *pHighwater. ^If the
** resetFlag is true, then the highest record value is reset after
** *pHighwater is written. ^(Some parameters do not record the highest
** value. For those parameters
** nothing is written into *pHighwater and the resetFlag is ignored.)^
** ^(Other parameters record only the highwater mark and not the current
** value. For these latter parameters nothing is written into *pCurrent.)^
**
** ^The sqlite3_status() and sqlite3_status64() routines return
** SQLITE_OK on success and a non-zero [error code] on failure.
**
** If either the current value or the highwater mark is too large to
** be represented by a 32-bit integer, then the values returned by
** sqlite3_status() are undefined.
**
** See also: [sqlite3_db_status()]
Table structure - used by update and pre-update hooks
The ORDER BY clause is ignored for all of the above
Sanity checking on the page. This is more important that I originally
** thought. If a power failure occurs while the journal is being written,
** it could cause invalid data to be written into the journal. We need to
** detect this invalid data (with high probability) and ignore it.
The query strategy is to look for an equality constraint on the json
** column. Without such a constraint, the table cannot operate. idxNum is
** 1 if the constraint is found, 3 if the constraint and zRoot are found,
** and 0 otherwise.
Current 'end' value
** The return value of winGetLastErrorMsg
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated).
Triggers for aAction[] actions
Snippet end text - "</b>"
** Helper subroutine for PRAGMA integrity_check:
**
** Generate code to output a single-column result row with the result
** held in register regResult. Decrement the result count and halt if
** the maximum number of result rows have been issued.
2-byte unsigned integer
Free temporary memory and return success
Flags for sqlite3WhereBegin()
We need to prevent a random number of 0x8000000000000000
** (or -9223372036854775808) since when you do abs() of that
** number of you get the same value back again. To do this
** in a way that is testable, mask the sign bit off of negative
** values, resulting in a positive value. Then take the
** 2s complement of that positive value. The end result can
** therefore be no less than -9223372036854775807.
Hash table containing tokenizers
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
** value. Return a pointer to its binary value. Space to hold the
** binary value has been obtained from malloc and must be freed by
** the calling routine.
comment: Malloc may fail when setting the page-size, as there is an internal
** buffer that the pager module resizes using sqlite3_realloc().
label: code-design
Statement for INSERT operations
shared can just be set because we always have an exclusive
Pointer to the data to be bound
Start the view context.
Unary operator
Calculate the 'docid' delta value to write into the merged
** doclist.
Changeset to apply
DESC => ID
** Retry flock() calls that fail with EINTR
SQLITE_STATUS_PAGECACHE_OVERFLOW
Second part of [schema.]id field, or NULL
One of TK_BEFORE, TK_AFTER, TK_INSTEAD
Determine how many bytes of data to read.
comment:
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
label: code-design
Extra data for callback
xDeviceCharacteristics
True if there are one or more Incrblob cursors
** Perform a single step of an incremental-vacuum. If successful, return
** SQLITE_OK. If there is no work to do (and therefore no point in
** calling this function again), return SQLITE_DONE. Or, if an error
** occurs, return some other error code.
**
** More specifically, this function attempts to re-organize the database so
** that the last page of the file currently in use is no longer in use.
**
** Parameter nFin is the number of pages that this database would contain
** were this function called until it returns SQLITE_DONE.
**
** If the bCommit parameter is non-zero, this function assumes that the
** caller will keep calling incrVacuumStep() until it returns SQLITE_DONE
** or an error. bCommit is passed true for an auto-vacuum-on-commit
** operation, or false for an incremental vacuum.
** Use the zone allocator available on apple products unless the
** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
The tokenizer
Note that because the size of the allocation for p->a[] is not
** necessarily a power of two, sqlite3IdListAppend() may not be called
** on the duplicate created by this function.
Name of table into which we are inserting
Virtual machine being coded
IMP: R-53341-35419
Used to iterate through segments
590
** Move a statvfs cursor to the next entry in the file.
Generate code to read the child key values into registers
** regRow..regRow+n. If any of the child key values are NULL, this
** row cannot cause an FK violation. Jump directly to addrOk in
** this case.
** The methods above are in version 1 of the sqlite_vfs object
** definition. Those that follow are added in version 2 or later
GLOB
Constant expression is reusable
** The maximum length of a single SQL statement in bytes.
**
** It used to be the case that setting this value to zero would
** turn the limit off. That is no longer true. It is not possible
** to turn this limit off.
Name of savepoint
True to flush contents of memory to PMA
nearset ::= STRING LP nearphrases neardist_opt RP
Doclist is assembled here
Jump here for next iteration of skip-scan
Size of apChange[] array
Number of WAL frames backfilled into DB
Prefix length (0 for main terms index)
** Add code to implement the OFFSET
Used to build up list of table cols
Jump here when skipping the initialization
between_op ::= BETWEEN
** This function is called as part of an sqlite3VdbeSorterRewind() operation
** on a sorter that has written two or more PMAs to temporary files. It sets
** up either VdbeSorter.pMerger (for single threaded sorters) or pReader
** (for multi-threaded sorters) so that it can be used to iterate through
** all records stored in the sorter.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
Result code form fcntl()
** Recursively walk the expressions of a SELECT statement and generate
** a bitmask indicating which tables are used in that expression
** tree.
** Return TRUE if there is a vowel anywhere within z[0..n-1]
All triggers indexed by name
The 1-byte case. Overwhelmingly the most common. Handled inline
** by the getVarin32() macro
Current index in aRight
comment: First unused byte of aOvflSpace[]
label: code-design
If *pPgno refers to a pointer-map page, allocate two new pages
** at the end of the file instead of one. The first allocated page
** becomes a new pointer-map page, the second is used by the caller.
** A convenience macro that returns the number of elements in
** an array.
comment: Unused parameter
label: code-design
** The following structure contains pointers to all SQLite API routines.
** A pointer to this structure is passed into extensions when they are
** loaded so that the extension can make calls back into the SQLite
** library.
**
** When adding new APIs, add them to the bottom of this structure
** in order to preserve backwards compatibility.
**
** Extensions that use newer APIs should first call the
** sqlite3_libversion_number() to make sure that the API they
** intend to use is supported by the library. Extensions should
** also check to make sure that the pointer to the function is
** not NULL before calling it.
*************** End makeheaders token definitions **************************
Result of sqlite3Strlen30(zTab)
************* End of auth.c ***********************************************
** Release the STATIC_MASTER mutex.
Number of PMAs currently in file
** Compute the absolute value of a 32-bit signed integer, of possible. Or
** if the integer has a value of -2147483648, return +2147483647
** Print an IOTRACE message showing SQL content.
True to cause the name to be dequoted
Used by: stats
Size of db file in bytes
** End of interface to code in fts5_buffer.c.
*************************************************************************
** The following asserts make sure that structures used by the btree are
** the right size. This is to guard against size changes that result
** when compiling on a different architecture.
Device sector size
This is the database that must be used
comment: If the file was truncated to a size smaller than the currently
** mapped region, reduce the effective mapping size as well. SQLite will
** use read() and write() to access data beyond this point from now on.
label: code-design
PGHDR flags defined below
Write the specified cookie value
Retreive the text stored in column iCol. If an SQL NULL is stored
** in column iCol, jump immediately to the next iteration of the loop.
** If an OOM occurs while retrieving the data (this can happen if SQLite
** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM
** to the caller.
True if the delete flag is set
memcmp() result
** Initialize a node-reader object to read the node in buffer aNode/nNode.
**
** If successful, SQLITE_OK is returned and the NodeReader object set to
** point to the first entry on the node (if any). Otherwise, an SQLite
** error code is returned.
unixFile created and returned by ref
Fragment number
comment: Bytes of unused memory
label: code-design
An optimization. If the database was not actually modified during
** this transaction, the pager is running in exclusive-mode and is
** using persistent journals, then this function is a no-op.
**
** The start of the journal file currently contains a single journal
** header with the nRec field set to 0. If such a journal is used as
** a hot-journal during hot-journal rollback, 0 changes will be made
** to the database file. So there is no need to zero the journal
** header. Since the pager is in exclusive mode, there is no need
** to drop any locks either.
comment: Next unused scratch buffer
label: code-design
all other styles use the locking context to store the db file path
Size of aSlot[] array
Finder function name
The expression to check authorization on
First byte of the cell content area
Ideally, the start of the snippet should be pushed forward in the
** document nDesired tokens. This block checks if there are actually
** nDesired tokens to the right of the snippet. If so, *piPos and
** *pHlMask are updated to shift the snippet nDesired tokens to the
** right. Otherwise, the snippet is shifted by the number of tokens
** available.
The "wsdPrng" macro will resolve to the pseudo-random number generator
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
** case where writable static data is supported, wsdPrng can refer directly
** to the "sqlite3Prng" state vector declared above.
** An object of type Fts5SegWriter is used to write to segments.
** Given a btree page and a cell index (0 means the first cell on
** the page, 1 means the second cell, and so forth) return a pointer
** to the cell content.
**
** findCellPastPtr() does the same except it skips past the initial
** 4-byte child pointer found on interior pages, if there is one.
**
** This routine works only for pages that do not contain overflow cells.
!SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED
The HAVING clause. May be NULL
The code generator maintains a stack of active WITH clauses
** with the inner-most WITH clause being at the top of the stack.
**
** This routine pushes the WITH clause passed as the second argument
** onto the top of the stack. If argument bFree is true, then this
** WITH clause will never be popped from the stack. In this case it
** should be freed along with the Parse object. In other cases, when
** bFree==0, the With object will be freed along with the SELECT
** statement with which it is associated.
** Encode value iVal as an SQLite varint and append it to the buffer object
** pBuf. If an OOM error occurs, set the error code in p.
FOREIGN
The cell to write
A term of the ORDER BY clause
Both values must be blobs. Compare using memcmp().
DEFAULT
True for "ORDER BY rowid DESC" queries
result variable
'usermerge' setting
Initial bulk allocation size
Value being transferred
ifnotexists ::=
If using a docid=? or rowid=? strategy, set the UNIQUE flag.
** Record 0 of the %_stat table contains a blob consisting of N varints,
** where N is the number of user defined columns in the fts3 table plus
** two. If nCol is the number of user defined columns, then values of the
** varints are set as follows:
**
** Varint 0: Total number of rows in the table.
**
** Varint 1..nCol: For each column, the total number of tokens stored in
** the column for all rows of the table.
**
** Varint 1+nCol: The total size, in bytes, of all text values in all
** columns of all rows of the table.
**
synopsis: if (--r[P1])==0 goto P2
The associated pager. Also accessible by pBt->pPager
Space allocated for zExtra[]
NULL NULL
** CAPI3REF: Deprecated Soft Heap Limit Interface
** DEPRECATED
**
** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
** interface. This routine is provided for historical compatibility
** only. All new applications should use the
** [sqlite3_soft_heap_limit64()] interface rather than this one.
If zKey is non-NULL, then this foreign key was declared to
** map to an explicit list of columns in table pParent. Check if this
** index matches those columns. Also, check that the index uses
** the default collation sequences for each column.
A bound parameter in a CREATE statement that originates from
** sqlite3_prepare() causes an error
We should already hold a lock on the database connection
Assert that the caller has been consistent. If this cursor was opened
** expecting an index b-tree, then the caller should be inserting blob
** keys with no associated data. If the cursor was opened expecting an
** intkey table, the caller should be inserting integer keys with a
** blob of associated data.
0x70 .. 0x7F
ABORT
** CAPI3REF: Compile-Time Library Version Numbers
**
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
** evaluates to a string literal that is the SQLite version in the
** format "X.Y.Z" where X is the major version number (always 3 for
** SQLite3) and Y is the minor version number and Z is the release number.)^
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
** numbers used in [SQLITE_VERSION].)^
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
** be larger than the release from which it is derived. Either Y will
** be held constant and Z will be incremented or else Y will be incremented
** and Z will be reset to zero.
**
** Since [version 3.6.18] ([dateof:3.6.18]),
** SQLite source code has been stored in the
** <a href="http://www.fossil-scm.org/">Fossil configuration management
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
** a string which identifies a particular check-in of SQLite
** within its configuration management system. ^The SQLITE_SOURCE_ID
** string contains the date and time of the check-in (UTC) and a SHA1
** or SHA3-256 hash of the entire source tree.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
** An instance of this structure (in the form of a BLOB) is returned by
** the SQL functions that sqlite3_rtree_geometry_callback() and
** sqlite3_rtree_query_callback() create, and is read as the right-hand
** operand to the MATCH operator of an R-Tree.
Destination for SELECT on rhs of INSERT
Not a compound SELECT
In the amalgamation, the os_unix.c and os_win.c source files come before
** this source file. Verify that the #defines of the locking byte offsets
** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
** For that matter, if the lock offset ever changes from its initial design
** value of 120, we need to know that so there is an assert() to check it.
Check that the column is not part of an FK child key definition. It
** is not necessary to check if it is part of a parent key, as parent
** key columns must be indexed. The check below will pick up this
** case.
Wal iterator context
turn off high bit in final byte
** Indicate that the statement currently under construction might write
** more than one entry (example: deleting one row then inserting another,
** inserting multiple rows in a table, or inserting a row and index entries.)
** If an abort occurs after some of these writes have completed, then it will
** be necessary to undo the completed writes.
If a tokenizer= option was successfully parsed, the tokenizer has
** already been allocated. Otherwise, allocate an instance of the default
** tokenizer (unicode61) now.
Handle describing change and conflict
Make sure no sibling connections hold locks that will block this
** lock. If any do, return SQLITE_BUSY right away.
# include <sys/ioctl.h>
Value of pPage->aData[0]
Expression that pNear is a part of
Region to retrieve
PRAGMA index_xinfo = <pk-index>
Unsigned for byte-order conversions
NOTINDEXED
The memcpy() statement assumes that the wildcard characters are
** the first three statements in the compareInfo structure. The
** asserts() that follow verify that assumption
Table being updated or deleted from
Next hash entry with same hash-key
comment:
** 2008 November 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file implements the default page cache implementation (the
** sqlite3_pcache interface). It also contains part of the implementation
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
** If the default page cache implementation is overridden, then neither of
** these two features are available.
**
** A Page cache line looks like this:
**
** -------------------------------------------------------------
** | database page content | PgHdr1 | MemPage | PgHdr |
** -------------------------------------------------------------
**
** The database page content is up front (so that buffer overreads tend to
** flow harmlessly into the PgHdr1, MemPage, and PgHdr extensions). MemPage
** is the extension added by the btree.c module containing information such
** as the database page number and how that database page is used. PgHdr
** is added by the pcache.c layer and contains information used to keep track
** of which pages are "dirty". PgHdr1 is an extension added by this
** module (pcache1.c). The PgHdr1 header is a subclass of sqlite3_pcache_page.
** PgHdr1 contains information needed to look up a page by its page number.
** The superclass sqlite3_pcache_page.pBuf points to the start of the
** database page content and sqlite3_pcache_page.pExtra points to PgHdr.
**
** The size of the extension (MemPage+PgHdr+PgHdr1) can be determined at
** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
** size can vary according to architecture, compile-time options, and
** SQLite library version number.
**
** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
** using a separate memory allocation from the database page content. This
** seeks to overcome the "clownshoe" problem (also called "internal
** fragmentation" in academic literature) of allocating a few bytes more
** than a power of two with the memory allocator rounding up to the next
** power of two, and leaving the rounded-up space unused.
**
** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
** with this module. Information is passed back and forth as PgHdr1 pointers.
**
** The pcache.c and pager.c modules deal pointers to PgHdr objects.
** The btree.c module deals with pointers to MemPage objects.
**
** SOURCE OF PAGE CACHE MEMORY:
**
** Memory for a page might come from any of three sources:
**
** (1) The general-purpose memory allocator - sqlite3Malloc()
** (2) Global page-cache memory provided using sqlite3_config() with
** SQLITE_CONFIG_PAGECACHE.
** (3) PCache-local bulk allocation.
**
** The third case is a chunk of heap memory (defaulting to 100 pages worth)
** that is allocated when the page cache is created. The size of the local
** bulk allocation can be adjusted using
**
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
**
** If N is positive, then N pages worth of memory are allocated using a single
** sqlite3Malloc() call and that memory is used for the first N pages allocated.
** Or if N is negative, then -1024*N bytes of memory are allocated and used
** for as many pages as can be accomodated.
**
** Only one of (2) or (3) can be used. Once the memory available to (2) or
** (3) is exhausted, subsequent allocations fail over to the general-purpose
** memory allocator (1).
**
** Earlier versions of SQLite used only methods (1) and (2). But experiments
** show that method (3) with N==100 provides about a 5% performance boost for
** common workloads.
label: code-design
Bottom of the rowid change constraint check
** Unlock an rbuVfs-file.
** If the user has not set the safety-level for this database connection
** using "PRAGMA synchronous", and if the safety-level is not already
** set to the value passed to this function as the second parameter,
** set it so.
** Return TRUE if the page given in the argument was previously passed
** to sqlite3PagerWrite(). In other words, return TRUE if it is ok
** to change the content of the page.
RESTRICT => ID
SQLITE_PRINTF flags below
316
The P1 operand
From ANALYZE: Est. rows selected by each column
comment: Function context - put error messages here
label: code-design
A regular table
ERROR: copy exceeds output file size
True if the outermost savepoint is a TS
AS => nothing
Parameters passed to SQL geom function
Set up the Stat4Accum.a[] and aBest[] arrays
** Generate a Token object from a string
Name context for parent SELECT statement
Result of a Windows lock call
****************************** sqlite3_bind_ ***************************
**
** Routines used to attach values to wildcards in a compiled SQL statement.
293
IN
196
If the leaf in question has already been trimmed from the segment,
** ignore this b-tree entry. Otherwise, load it into memory.
Both X and Y have COLLATE operators. Make sure X is always
** used by clearing the EP_Collate flag from Y.
Register holding rowid
The BTree cursor
True for an infix function: LIKE, GLOB, etc
************* Begin file malloc.c *****************************************
** Used only when SQLITE_NO_SYNC is not defined.
169
Segment term filter condition
Last frame in list
Must be of the form INSERT INTO ... SELECT ...
** Argument pWith (which may be NULL) points to a linked list of nested
** WITH contexts, from inner to outermost. If the table identified by
** FROM clause element pItem is really a common-table-expression (CTE)
** then return a pointer to the CTE definition for that table. Otherwise
** return NULL.
**
** If a non-NULL value is returned, set *ppContext to point to the With
** object that the returned CTE belongs to.
ABC in prefix=ABC parameter to parse
Must make sure nOverflow is reset to zero even if the balance()
** fails. Internal data structure corruption will result otherwise.
** Also, set the cursor state to invalid. This stops saveCursorPosition()
** from trying to save the current position of the cursor.
"x IN (value, value, ...)"
comment:
** The ALWAYS and NEVER macros surround boolean expressions which
** are intended to always be true or false, respectively. Such
** expressions could be omitted from the code completely. But they
** are included in a few cases in order to enhance the resilience
** of SQLite to unexpected behavior - to make the code "self-healing"
** or "ductile" rather than being "brittle" and crashing at the first
** hint of unplanned behavior.
**
** In other words, ALWAYS and NEVER are added for defensive code.
**
** When doing coverage testing ALWAYS and NEVER are hard-coded to
** be true and false so that the unreachable code they specify will
** not be counted as untested code.
label: code-design
SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below
** Disconnect all the virtual table objects in the sqlite3.pDisconnect list.
**
** This function may only be called when the mutexes associated with all
** shared b-tree databases opened using connection db are held by the
** caller. This is done to protect the sqlite3.pDisconnect list. The
** sqlite3.pDisconnect list is accessed only as follows:
**
** 1) By this function. In this case, all BtShared mutexes and the mutex
** associated with the database handle itself must be held.
**
** 2) By function vtabDisconnectAll(), when it adds a VTable entry to
** the sqlite3.pDisconnect list. In this case either the BtShared mutex
** associated with the database the virtual table is stored in is held
** or, if the virtual table is stored in a non-sharable database, then
** the database handle mutex is held.
**
** As a result, a sqlite3.pDisconnect cannot be accessed simultaneously
** by multiple threads. It is thread-safe.
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the VACUUM command.
**
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
Offset into aDigits[] of the digits string
** An instance of the following structure is used to store the busy-handler
** callback for a given sqlite handle.
**
** The sqlite.busyHandler member of the sqlite struct contains the busy
** callback for the database handle. Each pager opened via the sqlite
** handle is passed a pointer to sqlite.busyHandler. The busy-handler
** callback is currently invoked only from within pager.c.
Opcode: Pagecount P1 P2 * * *
**
** Write the current number of pages in database P1 to memory cell P2.
** Implementation of the sqlite3_pcache.xUnpin method.
**
** Mark a page as unpinned (eligible for asynchronous recycling).
Number of tokens in query
44
IMP: R-38091-32352
The optimizer is able to deliver rows in group by order so
** we do not have to sort. The OP_OpenEphemeral table will be
** cancelled later because we still need to use the pKeyInfo
123
OUT: Total number of frames checkpointed
258
The result code
************* End of hwtime.h *********************************************
Build and compile a statement to execute:
Store pointer to the allocated page here
Allocate space for the aMSI[] array of each FTSQUERY_PHRASE node
ORDER BY correctly sorts the inner loop
Number of outstanding xFetch references
This token started out using characters that can appear in keywords,
** but z[i] is a character not allowed within keywords, so this must
** be an identifier instead
docid>=?
If zKey is NULL, then this foreign key is implicitly mapped to
** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
** identified by the test.
If the BtCursor.aOverflow[] has not been allocated, allocate it now.
**
** The aOverflow[] array is sized at one entry for each overflow page
** in the overflow chain. The page number of the first overflow page is
** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
** means "not yet known" (the cache is lazily populated).
Top and bottom range constraints
An element of aTo[] that we are working on
Computed column name as a token
HAVING
** Convert a multi-byte character string to UTF-8.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
If not building as part of the core, include sqlite3ext.h.
mnHeap, mxHeap
** Merge two position-lists as required by the NEAR operator. The argument
** position lists correspond to the left and right phrases of an expression
** like:
**
** "phrase 1" NEAR "phrase number 2"
**
** Position list *pp1 corresponds to the left-hand side of the NEAR
** expression and *pp2 to the right. As usual, the indexes in the position
** lists are the offsets of the last token in each phrase (tokens "1" and "2"
** in the example above).
**
** The output position list - written to *pp - is a copy of *pp2 with those
** entries that are not sufficiently NEAR entries in *pp1 removed.
This is the descendent of an OR node. In this case we cannot use
** an incremental phrase. Load the entire doclist for the phrase
** into memory in this case.
** Return the N-dimensional volumn of the cell stored in *p.
** Implementation of the sqlite_version() function. The result is the version
** of the SQLite library that is running.
Reassembly the compound query so that it will be freed correctly
** by the calling function
List of in-memory records
Find the memory cell that will be used to store the blob of memory
** required for this VdbeCursor structure. It is convenient to use a
** vdbe memory cell to manage the memory allocation required for a
** VdbeCursor structure for the following reasons:
**
** * Sometimes cursor numbers are used for a couple of different
** purposes in a vdbe program. The different uses might require
** different sized allocations. Memory cells provide growable
** allocations.
**
** * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
** be freed lazily via the sqlite3_release_memory() API. This
** minimizes the number of malloc calls made by the system.
**
** The memory cell for cursor 0 is aMem[0]. The rest are allocated from
** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
** Cursor 2 is at Mem[p->nMem-2]. And so forth.
Generate a subroutine that will fill an ephemeral table with
** the content of this subquery. pItem->addrFillSub will point
** to the address of the generated subroutine. pItem->regReturn
** is a register allocated to hold the subroutine return address
Buffer containing page data
comment: sqlite3_malloc()
label: code-design
** Return the P5 value that should be used for a binary comparison
** opcode (OP_Eq, OP_Ge etc.) used to compare pExpr1 and pExpr2.
P3 Value for OP_VFilter
Not all WHERE terms resolved by outer loop
Used internally by sqlite3Fts3SegReaderXXX() calls
File handle to write to
Trigger being finished
First token of best snippet
** CAPI3REF: Run-time Limits
** METHOD: sqlite3
**
** ^(This interface allows the size of various constructs to be limited
** on a connection by connection basis. The first parameter is the
** [database connection] whose limit is to be set or queried. The
** second parameter is one of the [limit categories] that define a
** class of constructs to be size limited. The third parameter is the
** new limit for that construct.)^
**
** ^If the new limit is a negative number, the limit is unchanged.
** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
** [limits | hard upper bound]
** set at compile-time by a C preprocessor macro called
** [limits | SQLITE_MAX_<i>NAME</i>].
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
** ^Attempts to increase a limit above its hard upper bound are
** silently truncated to the hard upper bound.
**
** ^Regardless of whether or not the limit was changed, the
** [sqlite3_limit()] interface returns the prior value of the limit.
** ^Hence, to find the current value of a limit without changing it,
** simply invoke this interface with the third parameter set to -1.
**
** Run-time limits are intended for use in applications that manage
** both their own internal database and also databases that are controlled
** by untrusted external sources. An example application might be a
** web browser that has its own databases for storing history and
** separate databases controlled by JavaScript applications downloaded
** off the Internet. The internal databases can be given the
** large, default limits. Databases managed by external sources can
** be given much smaller limits designed to prevent a denial of service
** attack. Developers might also want to use the [sqlite3_set_authorizer()]
** interface to further control untrusted SQL. The size of the database
** created by an untrusted script can be contained using the
** [max_page_count] [PRAGMA].
**
** New run-time limit categories may be added in future releases.
comment:
** The following two macros are used within the PAGERTRACE() macros above
** to print out file-descriptors.
**
** PAGERID() takes a pointer to a Pager struct as its argument. The
** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
** struct as its argument.
label: code-design
IMP: R-11967-56545
** PRAGMA [schema.]cache_spill
** PRAGMA cache_spill=BOOLEAN
** PRAGMA [schema.]cache_spill=N
**
** The first form reports the current local setting for the
** page cache spill size. The second form turns cache spill on
** or off. When turnning cache spill on, the size is set to the
** current cache_size. The third form sets a spill size that
** may be different form the cache size.
** If N is positive then that is the
** number of pages in the cache. If N is negative, then the
** number of pages is adjusted so that the cache uses -N kibibytes
** of memory.
**
** If the number of cache_spill pages is less then the number of
** cache_size pages, no spilling occurs until the page count exceeds
** the number of cache_size pages.
**
** The cache_spill=BOOLEAN setting applies to all attached schemas,
** not just the schema specified.
target database handle
Size of the rendering buffer
Search for prior reference to this subquery
True to use background threads
At this point (pTargetFd->iCookie) contains the value of the
** change-counter cookie (the thing that gets incremented when a
** transaction is committed in rollback mode) currently stored on
** page 1 of the database file.
Buffer of at least *pnList items to use
Write out the page data.
** Implementation of the length() function
** Extract the iCol-th column from the nRec-byte record in pRec. Write
** the column value into *ppVal. If *ppVal is initially NULL then a new
** sqlite3_value object is allocated.
**
** If *ppVal is initially NULL then the caller is responsible for
** ensuring that the value written into *ppVal is eventually freed.
** This function is used to obtain an SQLite prepared statement handle
** for the statement identified by the second argument. If successful,
** *pp is set to the requested statement handle and SQLITE_OK returned.
** Otherwise, an SQLite error code is returned and *pp is set to 0.
**
** If argument apVal is not NULL, then it must point to an array with
** at least as many entries as the requested statement has bound
** parameters. The values are bound to the statements parameters before
** returning.
comment:
** This function is called to estimate the number of rows visited by a
** range-scan on a skip-scan index. For example:
**
** CREATE INDEX i1 ON t1(a, b, c);
** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;
**
** Value pLoop->nOut is currently set to the estimated number of rows
** visited for scanning (a=? AND b=?). This function reduces that estimate
** by some factor to account for the (c BETWEEN ? AND ?) expression based
** on the stat4 data for the index. this scan will be peformed multiple
** times (once for each (a,b) combination that matches a=?) is dealt with
** by the caller.
**
** It does this by scanning through all stat4 samples, comparing values
** extracted from pLower and pUpper with the corresponding column in each
** sample. If L and U are the number of samples found to be less than or
** equal to the values extracted from pLower and pUpper respectively, and
** N is the total number of samples, the pLoop->nOut value is adjusted
** as follows:
**
** nOut = nOut * ( min(U - L, 1) / N )
**
** If pLower is NULL, or a value cannot be extracted from the term, L is
** set to zero. If pUpper is NULL, or a value cannot be extracted from it,
** U is set to N.
**
** Normally, this function sets *pbDone to 1 before returning. However,
** if no value can be extracted from either pLower or pUpper (and so the
** estimate of the number of rows delivered remains unchanged), *pbDone
** is left as is.
**
** If an error occurs, an SQLite error code is returned. Otherwise,
** SQLITE_OK.
label: code-design
** Internally, the vdbe manipulates nearly all SQL values as Mem
** structures. Each Mem struct may cache multiple representations (string,
** integer etc.) of the same value.
Bitmask of other loops that must run first
True if there exists a MATCH constraint
For storing the record being decoded
Never called on page 1
TUNING: Cost of a unique index lookup is 15
** Macros for looping over all elements of a hash table. The idiom is
** like this:
**
** Hash h;
** HashElem *p;
** ...
** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){
** SomeStructure *pData = sqliteHashData(p);
** // do something with pData
** }
** Attempt to advance the node-reader object passed as the first argument to
** the next entry on the node.
**
** Return an error code if an error occurs (SQLITE_NOMEM is possible).
** Otherwise return SQLITE_OK. If there is no next entry on the node
** (e.g. because the current entry is the last) set NodeReader->aNode to
** NULL to indicate EOF. Otherwise, populate the NodeReader structure output
** variables for the new entry.
The WHERE clause of the outer query
expr ::= JOIN_KW
Append N bytes from zIn onto the end of the JsonString string.
This is VxWorks. Set up things specially for that OS
Imposter table name
Array of shared library handles
138
Left table being joined
The group the new page cache will belong to
First token of snippet
Result code
Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**
** "pNew" is a pointer to the hash table that is to be initialized.
comment: todo
label: requirement
Index Name Table Name
1 = unlock, 0 = lock
** Check if the contents of the FTS index match the current contents of the
** content table. If no error occurs and the contents do match, set *pbOk
** to true and return SQLITE_OK. Or if the contents do not match, set *pbOk
** to false before returning.
**
** If an error occurs (e.g. an OOM or IO error), return an SQLite error
** code. The final value of *pbOk is undefined in this case.
comment: If a pre-update hook is registered and this is a write cursor,
** invoke it here.
**
** TODO: The preupdate-hook is passed SQLITE_DELETE, even though this
** operation should really be an SQLITE_UPDATE. This is probably
** incorrect, but is convenient because at this point the new.* values
** are not easily obtainable. And for the sessions module, an
** SQLITE_UPDATE where the PK columns do not change is handled in the
** same way as an SQLITE_DELETE (the SQLITE_DELETE code is actually
** slightly more efficient). Since you cannot write to a PK column
** using the incremental-blob API, this works. For the sessions module
** anyhow.
label: code-design
************* Include hash.h in the middle of sqliteInt.h *****************
!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
The point in pPage->aCellIdx[] where no cell inserted
** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
** otherwise. Either or both argument may be NULL. Two NULL values are
** considered equal, and NULL is considered distinct from all other values.
** A single VDBE is an opaque structure named "Vdbe". Only routines
** in the source file sqliteVdbe.c are allowed to see the insides
** of this structure.
nStmtSpill
Suppress error messages if VIEW already exists
MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
** then the encoding of the value may not have changed.
IMP: R-59593-21810
Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
** mode, write the rowid into the FIFO. In either of the one-pass modes,
** leave it in register regOldRowid.
List of WHEN terms
This branch is taken if the set of sibling pages somehow contains
** duplicate entries. This can happen if the database is corrupt.
** It would be simpler to detect this as part of the loop below, but
** we do the detection here in order to avoid populating the pager
** cache with two separate objects associated with the same
** page number.
Saved value of p->iLimit
Value to serialize
** Free the list of sorted records starting at pRecord.
comment:
** CAPI3REF: Count The Number Of Rows Modified
** METHOD: sqlite3
**
** ^This function returns the number of rows modified, inserted or
** deleted by the most recently completed INSERT, UPDATE or DELETE
** statement on the database connection specified by the only parameter.
** ^Executing any other type of SQL statement does not modify the value
** returned by this function.
**
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
**
** Changes to a view that are intercepted by
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
** DELETE statement run on a view is always zero. Only changes made to real
** tables are counted.
**
** Things are more complicated if the sqlite3_changes() function is
** executed while a trigger program is running. This may happen if the
** program uses the [changes() SQL function], or if some other callback
** function invokes sqlite3_changes() directly. Essentially:
**
** <ul>
** <li> ^(Before entering a trigger program the value returned by
** sqlite3_changes() function is saved. After the trigger program
** has finished, the original value is restored.)^
**
** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
** statement sets the value returned by sqlite3_changes()
** upon completion as normal. Of course, this value will not include
** any changes performed by sub-triggers, as the sqlite3_changes()
** value will be saved and restored after each sub-trigger has run.)^
** </ul>
**
** ^This means that if the changes() SQL function (or similar) is used
** by the first INSERT, UPDATE or DELETE statement within a trigger, it
** returns the value as set when the calling statement began executing.
** ^If it is used by the second or subsequent such statement within a trigger
** program, the value returned reflects the number of rows modified by the
** previous INSERT, UPDATE or DELETE statement within the same trigger.
**
** See also the [sqlite3_total_changes()] interface, the
** [count_changes pragma], and the [changes() SQL function].
**
** If a separate thread makes changes on the same database connection
** while [sqlite3_changes()] is running then the value returned
** is unpredictable and not meaningful.
label: code-design
VDBE is ready to execute
... is correcct.
Number of messages written to zErrMsg so far
** Convert an SQL-style quoted string into a normal string by removing
** the quote characters. The conversion is done in-place. If the
** input does not begin with a quote character, then this routine
** is a no-op.
**
** Examples:
**
** "abc" becomes abc
** 'xyz' becomes xyz
** [pqr] becomes pqr
** `mno` becomes mno
**
Database index for <database>
P4 is a pointer to a FuncDef structure
loop counter
** Parameter eStat must be either SQLITE_DBSTATUS_CACHE_HIT or
** SQLITE_DBSTATUS_CACHE_MISS. Before returning, *pnVal is incremented by the
** current cache hit or miss count, according to the value of eStat. If the
** reset parameter is non-zero, the cache hit or miss count is zeroed before
** returning.
** Create a new bitmap object able to handle bits between 0 and iSize,
** inclusive. Return a pointer to the new object. Return NULL if
** malloc fails.
Segment reader object
What do we want to learn about the zPath file?
The operand token for setting the span
** Register a callback to be invoked each time a transaction is written
** into the write-ahead-log by this database connection.
** An instance of this structure is used by the parser to record both
** the parse tree for an expression and the span of input text for an
** expression.
Step 4. If the RHS is known to be non-NULL and we did not find
** an match on the search above, then the result must be FALSE.
List of locks held on this shared-btree struct
List of free mmap page headers (pDirty)
Name of database (e.g. "main")
If expensive assert() statements are available, do a linear search
** of the wal-index file content. Make sure the results agree with the
** result obtained using the hash indexes above.
78..7f xyz{|}~.
Pointer to buffer containing record
Start of memory holding current results
Rowid of first leaf block to traverse
** Maximum supported path-length.
** Return a block of memory of at least nBytes in size.
** Return NULL if unable.
**
** This function assumes that the necessary mutexes, if any, are
** already held by the caller. Hence "Unsafe".
full bitset of atomics from max sector size and smaller
** Set the name of a Select object
** CAPI3REF: Prepared Statement Object
** KEYWORDS: {prepared statement} {prepared statements}
**
** An instance of this object represents a single SQL statement that
** has been compiled into binary form and is ready to be evaluated.
**
** Think of each SQL statement as a separate computer program. The
** original SQL text is source code. A prepared statement object
** is the compiled object code. All SQL must be converted into a
** prepared statement before it can be run.
**
** The life-cycle of a prepared statement object usually goes like this:
**
** <ol>
** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
** <li> Bind values to [parameters] using the sqlite3_bind_*()
** interfaces.
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
** <li> Reset the prepared statement using [sqlite3_reset()] then go back
** to step 2. Do this zero or more times.
** <li> Destroy the object using [sqlite3_finalize()].
** </ol>
True if we can share pBt with another db
** Return a JsonNode and all its descendents as a JSON string.
comment:
** Return the system page size.
**
** This function should not be called directly by other code in this file.
** Instead, it should be called via macro osGetpagesize().
label: code-design
The pager that owns pPg
** This is the xRowid method. The SQLite core calls this routine to
** retrieve the rowid for the current row of the result set. The
** rowid should be written to *pRowid.
nbr of 1st byte locked if successful
Copy of initial value of pIn3->flags
Enable load_extension
Number of pages in apOld[]
1
Special case: If this is an INSERT statement that will insert exactly
** one row into the table, raise a constraint immediately instead of
** incrementing a counter. This is necessary as the VM code is being
** generated for will not open a statement transaction.
comment: Malloc must have failed
label: code-design
View Name NULL
OUT: size of *apIndex[] array
Built-in count(*) aggregate
Documents in table
Register that records whether NULLs exist in RHS
sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
**
** Set the nReserve size to N for the main database on the database
** connection db.
The pattern string B
OFFSET
RTREE_LE and RTREE_LT end here
** Allocate a new rowid. This is used for "external content" tables when
** a NULL value is inserted into the rowid column. The new rowid is allocated
** by inserting a dummy row into the %_docsize table. The dummy will be
** overwritten later.
**
** If the %_docsize table does not exist, SQLITE_MISMATCH is returned. In
** this case the user is required to provide a rowid explicitly.
same as TK_GT, jump, in1, in3
Infinity
Original text of the expression
** Within this division (the proxying locking implementation) the procedures
** above this point are all utilities. The lock-related methods of the
** proxy-locking sqlite3_io_method object follow.
Saved trace settings
Tokenizer for this cursor.
xGetSystemCall
The page being overwritten.
************* Include wal.h in the middle of pager.c **********************
** This routine is called after all opcodes have been inserted. It loops
** through all the opcodes and fixes up some details.
**
** (1) For each jump instruction with a negative P2 value (a label)
** resolve the P2 value to an actual address.
**
** (2) Compute the maximum number of arguments used by any SQL function
** and store that value in *pMaxFuncArgs.
**
** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
** indicate what the prepared statement actually does.
**
** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
**
** (5) Reclaim the memory allocated for storing labels.
**
** This routine will only function correctly if the mkopcodeh.tcl generator
** script numbers the opcodes correctly. Changes to this routine must be
** coordinated with changes to mkopcodeh.tcl.
Output success/failure
WHERE rowid IN ( select )
Number of bytes of cell payload
IN/OUT: Preallocated output buffer
** Elements of sqlite3Stat[] are protected by either the memory allocator
** mutex, or by the pcache1 mutex. The following array determines which.
Rowid for record being decoded
If the checksum doesn't add up, then one or more of the disk sectors
** containing the master journal filename is corrupted. This means
** definitely roll back, so just return SQLITE_OK and report a (nul)
** master-journal filename.
Wal-index version
Error message written here
onconf ::= ON CONFLICT resolvetype
** Define various macros that are missing from some systems.
** If we are not using shared cache, then there is no need to
** use mutexes to access the BtShared structures. So make the
** Enter and Leave procedures no-ops.
Current depth of the r-tree structure
** Maximum length of a varint encoded integer. The varint format is different
** from that used by SQLite, so the maximum length is 10, not 9.
SQLITE_NULLEQ is clear and at least one operand is NULL,
** then the result is always NULL.
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
Left doclist
Cells stored on pPg
The matching pSrcList item
** Delete a VdbeFrame object and its contents. VdbeFrame objects are
** allocated by the OP_Program opcode in sqlite3VdbeExec().
EVIDENCE-OF: R-37497-42412 The size of the reserved region is
** determined by the one-byte unsigned integer found at an offset of 20
** into the database file header.
First memory cell containing the PRIMARY KEY
Set the limiter.
uncompress=? parameter (or NULL)
out2
Current expected value of %_config table 'version' field
The reference count on pShmNode has already been incremented under
** the cover of the winShmEnterMutex() mutex and the pointer from the
** new (struct winShm) object to the pShmNode has been set. All that is
** left to do is to link the new object into the linked list starting
** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
** mutex.
Reverse the order of IN operators
mxStrlen
** CAPI3REF: Reset Automatic Extension Loading
**
** ^This interface disables all automatic extensions previously
** registered using [sqlite3_auto_extension()].
** The write transaction open on pPager is being committed (bCommit==1)
** or rolled back (bCommit==0).
**
** Return TRUE if and only if all dirty pages should be flushed to disk.
**
** Rules:
**
** * For non-TEMP databases, always sync to disk. This is necessary
** for transactions to be durable.
**
** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
** file has been created already (via a spill on pagerStress()) and
** when the number of dirty pages in memory exceeds 25% of the total
** cache size.
** Convert a UTF-8 string to Microsoft Unicode.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
** The code generator calls this routine if is discovers that it is
** possible to abort a statement prior to completion. In order to
** perform this abort without corrupting the database, we need to make
** sure that the statement is protected by a statement transaction.
**
** Technically, we only need to set the mayAbort flag if the
** isMultiWrite flag was previously set. There is a time dependency
** such that the abort must occur after the multiwrite. This makes
** some statements involving the REPLACE conflict resolution algorithm
** go a little faster. But taking advantage of this time dependency
** makes it more difficult to prove that the code is correct (in
** particular, it prevents us from writing an effective
** implementation of sqlite3AssertMayAbort()) and so we have chosen
** to take the safe route and skip the optimization.
If no YMD specified, assume 2000-Jan-01
SQLITE_ENABLE_LOCKING_STYLE
FTS5 global context for db handle
First key to write
If the index uses a collation sequence that is different from
** the default collation sequence for the column, this index is
** unusable. Bail out early in this case.
************* Begin file alter.c ******************************************
FAIL
Case 1: Reset the single schema identified by iDb
302
Default behavior: Report an error if the argument to VACUUM is
** not recognized
OUT: expression
EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
** freeblock form a big-endian integer which is the size of the freeblock
** in bytes, including the 4-byte header.
Closing the handle. Fourth parameter is passed the value 2.
Put any active cursors into REQUIRE_SEEK state.
0x0a
** These routines walk (recursively) an expression tree and generate
** a bitmask indicating which tables are used in that expression
** tree.
** This function implements the ChooseLeaf algorithm from Gutman[84].
** ChooseSubTree in r*tree terminology.
refact ::= SET DEFAULT
** CAPI3REF: Function Flags
**
** These constants may be ORed together with the
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
** [sqlite3_create_function_v2()].
same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2]
223
sizeof(MemPage)+sizeof(PgHdr)
Select statement to read idx values
True if entry is not a match
** Advance the position list iterator specified by the first two
** arguments so that it points to the first element with a value greater
** than or equal to parameter iNext.
a: p0 (unmasked)
Compare the term we are searching for with the term just loaded from
** the interior node. If the specified term is greater than or equal
** to the term from the interior node, then all terms on the sub-tree
** headed by node iChild are smaller than zTerm. No need to search
** iChild.
**
** If the interior node term is larger than the specified term, then
** the tree headed by iChild may contain the specified term.
** Translate from TK_xx operator to WO_xx bitmask.
Cannot fail given valid arguments
xCachesize
Loop through all the foreign key constraints for which pTab is the
** child table (the table that the foreign key definition is part of).
260
Pull the requested columns.
** Process time function arguments. argv[0] is a date-time stamp.
** argv[1] and following are modifiers. Parse them all and write
** the resulting time into the DateTime structure p. Return 0
** on success and 1 if there are any errors.
**
** If there are zero parameters (if even argv[0] is undefined)
** then assume a default value of "now" for argv[0].
Pending terms hash table to add entry to
eidlist_opt ::= LP eidlist RP
Thread that is within this mutex
*************************************************************************
** Start of unicode61 tokenizer implementation.
318
** PRAGMA shrink_memory
**
** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
** connection on which it is invoked to free up as much memory as it
** can, by calling sqlite3_db_release_memory().
Database holding the shared memory
** Return true if the BtShared mutex is held on the btree, or if the
** B-Tree is not marked as sharable.
**
** This routine is used only from within assert() statements.
comment: Index of the equality term within this level
label: code-design
** Allocate and return a buffer at least nByte bytes in size.
**
** If an OOM error is encountered, return NULL and set the error code in
** the Fts5Index handle passed as the first argument.
Check that one of SQLITE_SYNC_NORMAL or FULL was passed
When multiple overflows occur, they are always sequential and in
** sorted order. This invariants arise because multiple overflows can
** only occur when inserting divider cells into the parent page during
** balancing, and the dividers are adjacent and sorted.
The loop that contains the LIKE operator
comment:
** Try to adjust the cost of WhereLoop pTemplate upwards or downwards so
** that:
**
** (1) pTemplate costs less than any other WhereLoops that are a proper
** subset of pTemplate
**
** (2) pTemplate costs more than any other WhereLoops for which pTemplate
** is a proper subset.
**
** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
** WHERE clause terms than Y and that every WHERE clause term used by X is
** also used by Y.
label: code-design
36
** Invoke the authorization callback for permission to read column zCol from
** table zTab in database zDb. This function assumes that an authorization
** callback has been registered (i.e. that sqlite3.xAuth is not NULL).
**
** If SQLITE_IGNORE is returned and pExpr is not NULL, then pExpr is changed
** to an SQL NULL expression. Otherwise, if pExpr is NULL, then SQLITE_IGNORE
** is treated as SQLITE_DENY. In this case an error is left in pParse.
comment:
** File Locking Notes: (Mostly about windows but also some info for Unix)
**
** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
** those functions are not available. So we use only LockFile() and
** UnlockFile().
**
** LockFile() prevents not just writing but also reading by other processes.
** A SHARED_LOCK is obtained by locking a single randomly-chosen
** byte out of a specific range of bytes. The lock byte is obtained at
** random so two separate readers can probably access the file at the
** same time, unless they are unlucky and choose the same lock byte.
** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
** There can only be one writer. A RESERVED_LOCK is obtained by locking
** a single byte of the file that is designated as the reserved lock byte.
** A PENDING_LOCK is obtained by locking a designated byte different from
** the RESERVED_LOCK byte.
**
** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
** which means we can use reader/writer locks. When reader/writer locks
** are used, the lock is placed on the same range of bytes that is used
** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
** will support two or more Win95 readers or two or more WinNT readers.
** But a single Win95 reader will lock out all WinNT readers and a single
** WinNT reader will lock out all other Win95 readers.
**
** The following #defines specify the range of bytes used for locking.
** SHARED_SIZE is the number of bytes available in the pool from which
** a random byte is selected for a shared lock. The pool of bytes for
** shared locks begins at SHARED_FIRST.
**
** The same locking strategy and
** byte ranges are used for Unix. This leaves open the possibility of having
** clients on win95, winNT, and unix all talking to the same shared file
** and all locking correctly. To do so would require that samba (or whatever
** tool is being used for file sharing) implements locks correctly between
** windows and unix. I'm guessing that isn't likely to happen, but by
** using the same locking range we are at least open to the possibility.
**
** Locking in windows is manditory. For this reason, we cannot store
** actual data in the bytes used for locking. The pager never allocates
** the pages involved in locking therefore. SHARED_SIZE is selected so
** that all locks will fit on a single page even at the minimum page size.
** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
** is set high so that we don't have to allocate an unused page except
** for very large databases. But one should test the page skipping logic
** by setting PENDING_BYTE low and running the entire regression suite.
**
** Changing the value of PENDING_BYTE results in a subtly incompatible
** file format. Depending on how it is changed, you might not notice
** the incompatibility right away, even running a full regression test.
** The default location of PENDING_BYTE is the first byte past the
** 1GB boundary.
**
label: code-design
Select id (left-most output column)
319
SQLITE_USER_AUTHENTICATION
** Include the header file for the Windows VFS.
Column to filter on
Size of write buffer in bytes
ORDER BY processing for max() func
distinct ::=
comment:
** This routine deallocates a previously
** allocated mutex. SQLite is careful to deallocate every
** mutex that it allocates.
label: code-design
Argument to pass to xNotify
segdir.leaves_end_block
mmap() space per open file
The VDBE cursor used by this IN operator
** Some API routines are omitted when various features are
** excluded from a build of SQLite. Substitute a NULL pointer
** for any missing APIs.
Delete entries for this table or index
** Return the number of columns in the result set for the statement pStmt.
comment: Mask of tables that must be used.
label: code-design
Methods above are valid for version 3
Coordinate value converted to a double
The return code
Offset of wal file entry
Populate the register containing the index name.
State 3. The integer just read is a column number.
** This is a helper function for rbuObjIterCacheTableInfo(). It populates
** the pIter->abIndexed[] array.
Used during OR-clause processing
** Pop an authorization context that was previously pushed
** by sqlite3AuthContextPush
****************** End of the flock lock implementation *********************
*****************************************************************************
Open the storage sub-system
If not NULL, the master journal name
Current write is a delete
0x40..0x4F
Number of distinct values in index
** Query FTS for the tokenizer implementation named zName.
Number of used entries in aCol[]
One of SQLITE_INSERT, UPDATE, DELETE
Parser context.
** Set the number of result columns that will be returned by this SQL
** statement. This is now set at compile time, rather than during
** execution of the vdbe program so that sqlite3_column_count() can
** be called on an SQL statement before sqlite3_step().
True if holding the winShmNode mutex
EV: R-30323-21917 Each foreign key constraint in SQLite is
** classified as either immediate or deferred.
comment:
** Given a file descriptor, locate the unixInodeInfo object that
** describes that file descriptor. Create a new one if necessary. The
** return value might be uninitialized if an error occurs.
**
** The mutex entered using the unixEnterMutex() function must be held
** when this function is called.
**
** Return an appropriate error code.
label: code-design
** CAPI3REF: Reset All Bindings On A Prepared Statement
** METHOD: sqlite3_stmt
**
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
** ^Use this routine to reset all host parameters to NULL.
** Transform a UTF-8 integer literal, in either decimal or hexadecimal,
** into a 64-bit signed integer. This routine accepts hexadecimal literals,
** whereas sqlite3Atoi64() does not.
**
** Returns:
**
** 0 Successful transformation. Fits in a 64-bit signed integer.
** 1 Integer too large for a 64-bit signed integer or is malformed
** 2 Special case of 9223372036854775808
Register holding the AUTOINCREMENT counter
Fill in pNew->pLeft and pNew->pRight.
True if previously initialized. MUST BE FIRST!
List of dirty pages to revert
** Free memory previously obtained from sqlite3Malloc().
pAppData
Check for complete coverage of the page
** The pcache1.separateCache variable is true if each PCache has its own
** private PGroup (mode-1). pcache1.separateCache is false if the single
** PGroup in pcache1.grp is used for all page caches (mode-2).
**
** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
**
** * Use a unified cache in single-threaded applications that have
** configured a start-time buffer for use as page-cache memory using
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
** pBuf argument.
**
** * Otherwise use separate caches (mode-1)
Buffer used for any other block
Vector expression to be appended. Might be NULL
unixFile.pInode is always valid here. Otherwise, a different close
** routine (e.g. nolockClose()) would be called instead.
Base class
comment: Even though there is no encoding conversion, value_blob() might
** need to call malloc() to expand the result of a zeroblob()
** expression.
label: code-design
SQLITE_OMIT_FLOATING_POINT
SQLITE_NOTFOUND
pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us
Collating sequence to be reindexed, or NULL
True if pList should be sqlite3_free()d
Set pTC to point to the cheapest remaining token.
Size of PMA in bytes
Construct a record from the query result, but instead of
** saving that record, use it as a key to delete elements from
** the temporary table iParm.
** CAPI3REF: Evaluate An SQL Statement
** METHOD: sqlite3_stmt
**
** After a [prepared statement] has been prepared using any of
** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
** or [sqlite3_prepare16_v3()] or one of the legacy
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
** must be called one or more times to evaluate the statement.
**
** The details of the behavior of the sqlite3_step() interface depend
** on whether the statement was prepared using the newer "vX" interfaces
** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
** [sqlite3_prepare16_v2()] or the older legacy
** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
** new "vX" interface is recommended for new applications but the legacy
** interface will continue to be supported.
**
** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
** ^With the "v2" interface, any of the other [result codes] or
** [extended result codes] might be returned as well.
**
** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
** database locks it needs to do its job. ^If the statement is a [COMMIT]
** or occurs outside of an explicit transaction, then you can retry the
** statement. If the statement is not a [COMMIT] and occurs within an
** explicit transaction then you should rollback the transaction before
** continuing.
**
** ^[SQLITE_DONE] means that the statement has finished executing
** successfully. sqlite3_step() should not be called again on this virtual
** machine without first calling [sqlite3_reset()] to reset the virtual
** machine back to its initial state.
**
** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
** is returned each time a new row of data is ready for processing by the
** caller. The values may be accessed using the [column access functions].
** sqlite3_step() is called again to retrieve the next row of data.
**
** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
** violation) has occurred. sqlite3_step() should not be called again on
** the VM. More information may be found by calling [sqlite3_errmsg()].
** ^With the legacy interface, a more specific error code (for example,
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
** can be obtained by calling [sqlite3_reset()] on the
** [prepared statement]. ^In the "v2" interface,
** the more specific error code is returned directly by sqlite3_step().
**
** [SQLITE_MISUSE] means that the this routine was called inappropriately.
** Perhaps it was called on a [prepared statement] that has
** already been [sqlite3_finalize | finalized] or on one that had
** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
** be the case that the same database connection is being used by two or
** more threads at the same moment in time.
**
** For all versions of SQLite up to and including 3.6.23.1, a call to
** [sqlite3_reset()] was required after sqlite3_step() returned anything
** other than [SQLITE_ROW] before any subsequent invocation of
** sqlite3_step(). Failure to reset the prepared statement using
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
** sqlite3_step() began
** calling [sqlite3_reset()] automatically in this circumstance rather
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
** break because any application that ever receives an SQLITE_MISUSE error
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
** can be used to restore the legacy behavior.
**
** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
** API always returns a generic error code, [SQLITE_ERROR], following any
** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
** specific [error codes] that better describes the error.
** We admit that this is a goofy design. The problem has been fixed
** with the "v2" interface. If you prepare all of your SQL statements
** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
** then the more specific [error codes] are returned directly
** by sqlite3_step(). The use of the "vX" interfaces is recommended.
** pColumns and pExpr form a vector assignment which is part of the SET
** clause of an UPDATE statement. Like this:
**
** (a,b,c) = (expr1,expr2,expr3)
** Or: (a,b,c) = (SELECT x,y,z FROM ....)
**
** For each term of the vector assignment, append new entries to the
** expression list pList. In the case of a subquery on the RHS, append
** TK_SELECT_COLUMN expressions.
Real value of right operand
** Generate code for a comparison operator.
SQLITE_IGNORE_FLOCK_LOCK_ERRORS
** Compare two UTF-8 strings for equality where the first string is
** a GLOB or LIKE expression. Return values:
**
** SQLITE_MATCH: Match
** SQLITE_NOMATCH: No match
** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards.
**
** Globbing rules:
**
** '*' Matches any sequence of zero or more characters.
**
** '?' Matches exactly one character.
**
** [...] Matches one character from the enclosed list of
** characters.
**
** [^...] Matches one character not in the enclosed list.
**
** With the [...] and [^...] matching, a ']' character can be included
** in the list by making it the first character after '[' or '^'. A
** range of characters can be specified using '-'. Example:
** "[a-z]" matches any single lower-case letter. To match a '-', make
** it the last character in the list.
**
** Like matching rules:
**
** '%' Matches any sequence of zero or more characters
**
*** '_' Matches any one character
**
** Ec Where E is the "esc" character and c is any other
** character, including '%', '_', and esc, match exactly c.
**
** The comments within this routine usually assume glob matching.
**
** This routine is usually quick, but can be N**2 in the worst case.
** Generate code that initializes multiple registers to string or integer
** constants. The registers begin with iDest and increase consecutively.
** One register is initialized for each characgter in zTypes[]. For each
** "s" character in zTypes[], the register is a string if the argument is
** not NULL, or OP_Null if the value is a null pointer. For each "i" character
** in zTypes[], the register is initialized to an integer.
**
** If the input string does not end with "X" then an OP_ResultRow instruction
** is generated for the values inserted.
Next entry in sorted order
Pointer to buffer containing changeset
Accumulate results here
comment:
** If the third argument is non-NULL, then this function releases a
** reference obtained by an earlier call to winFetch(). The second
** argument passed to this function must be the same as the corresponding
** argument that was passed to the winFetch() invocation.
**
** Or, if the third argument is NULL, then this function is being called
** to inform the VFS layer that, according to POSIX, any existing mapping
** may now be invalid and should be unmapped.
label: code-design
** Remove from colset pColset any columns that are not also in colset pMerge.
Allocation is valid
Next in LRU list of unpinned pages
Detach this backup from the source pager.
Copy of third arg to preupdate_hook()
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** Call this routine to record the fact that an OOM (out-of-memory) error
** has happened. This routine will set db->mallocFailed, and also
** temporarily disable the lookaside memory allocator and interrupt
** any running VDBEs.
The parent key is a composite key that includes the IPK column
Size of a[] in bytes
** Convert a filename from whatever the underlying operating system
** supports for filenames into UTF-8. Space to hold the result is
** obtained from malloc and must be freed by the calling function.
Description of the record
sqlite3CompareAffinity() only returns TEXT if one side or the
** other has no affinity and the other side is TEXT. Hence,
** the only way for cmpaff to be TEXT is for idxaff to be TEXT
** and for the term on the LHS of the IN to have no affinity.
************* Begin file icu.c ********************************************
data_version when pStruct read
TermSelect object to merge into
** Initialize bulk memory to be a consistent Mem object.
**
** The minimum amount of initialization feasible is performed.
** Write an unsigned 32-bit value in big-endian format to the supplied
** buffer.
** Generate code for the REINDEX command.
**
** REINDEX -- 1
** REINDEX <collation> -- 2
** REINDEX ?<database>.?<tablename> -- 3
** REINDEX ?<database>.?<indexname> -- 4
**
** Form 1 causes all indices in all attached databases to be rebuilt.
** Form 2 rebuilds all indices in all databases that use the named
** collating function. Forms 3 and 4 rebuild the named index or all
** indices associated with the named table.
OUT: A pointer to the prepared statement
Highwater mark for nOut
Name of target db index (or null)
93
** Return true if the prepared statement is guaranteed to not modify the
** database.
Additional information associated with pTerm
Bytes of content in a[]. Must be a multiple of 8.
Extract the value into this register
Create the imposter table or tables (if required).
Uses the OpenEphemeral opcode
comment:
** Interpret the given string as a safety level. Return 0 for OFF,
** 1 for ON or NORMAL, 2 for FULL, and 3 for EXTRA. Return 1 for an empty or
** unrecognized string argument. The FULL and EXTRA option is disallowed
** if the omitFull parameter it 1.
**
** Note that the values returned are one less that the values that
** should be passed into sqlite3BtreeSetSafetyLevel(). The is done
** to support legacy SQL code. The safety level used to be boolean
** and older scripts may have used numbers 0 for OFF and 1 for ON.
label: code-design
************* Begin file treeview.c ***************************************
funcFlags
Name of function
** 2009 Oct 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file is part of the SQLite FTS3 extension module. Specifically,
** this file contains code to insert, update and delete rows from FTS3
** tables. It also contains code to merge FTS3 b-tree segments. Some
** of the sub-routines used to merge segments are also used by the query
** code in fts3.c.
** Delete an entire VDBE.
** Use nodeAcquire() to obtain the leaf node containing the record with
** rowid iRowid. If successful, set *ppLeaf to point to the node and
** return SQLITE_OK. If there is no such record in the table, set
** *ppLeaf to 0 and return SQLITE_OK. If an error occurs, set *ppLeaf
** to zero and return an SQLite error code.
Prevent by getAndInitPage()
comment:
** This function is used by SQL generated to implement the
** ALTER TABLE command. The first argument is the text of a CREATE TABLE or
** CREATE INDEX command. The second is a table name. The table name in
** the CREATE TABLE or CREATE INDEX statement is replaced with the third
** argument and the result returned. Examples:
**
** sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
** -> 'CREATE TABLE def(a, b, c)'
**
** sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
** -> 'CREATE INDEX i ON def(a, b, c)'
label: code-design
Index of sub-iterator just advanced
The caller is responsible for zeroing output parameters.
Advance the pragma virtual table cursor to the next row
input ::= expr
** Call sqlite3WalkExpr() for every expression in list p or until
** an abort request is seen.
Column to query (or -ve for all columns)
Make sure sufficient number of registers have been allocated
Cannot have triggers on a virtual table. If it were possible,
** this block would have to account for hidden column.
Malloc'd space (possibly) used for zTerm
The vdbe must make its own copy of the column-type and other
** column specific strings, in case the schema is reset before this
** virtual machine is deleted.
If this is the first frame written into the log, write the WAL
** header to the start of the WAL file. See comments at the top of
** this source file for a description of the WAL header format.
** Delete all entries in the FTS5 index.
Database filenames are double-zero terminated if they are not
** URIs with parameters. Hence, they can always be passed into
** sqlite3_uri_parameter().
Omit all terms smaller than this
True for a root-only reader
Output register from the sorter
** Register this backup object with the associated source pager for
** callbacks when pages are changed or the cache invalidated.
1020
** Add connection db to the blocked connections list. It is assumed
** that it is not already a part of the list.
Do as much as possible w/o blocking
Number of the rule by which to reduce
Number of terms contributing to sumEq
If sorting index that was created by a prior OP_OpenEphemeral
** instruction ended up not being needed, then change the OP_OpenEphemeral
** into an OP_Noop.
colset ::= LCP colsetlist RCP
FROM entries not usable at this level
Deleting this row means the whole table is empty. In this case
** delete the contents of all three tables and throw away any
** data in the pendingTerms hash table.
Used by: index_info
Dest pager
True for min() and max() aggregates
The subquery uses a single slot of the FROM clause of the outer
** query. If the subquery has more than one element in its FROM clause,
** then expand the outer query to make space for it to hold all elements
** of the subquery.
**
** Example:
**
** SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
**
** The outer query has 3 slots in its FROM clause. One slot of the
** outer query (the middle slot) is used by the subquery. The next
** block of code will expand the outer query FROM clause to 4 slots.
** The middle slot is expanded to two slots in order to make space
** for the two elements in the FROM clause of the subquery.
** Title text to insert in front of each block
** This function is equivalent to the standard isspace() function.
**
** The standard isspace() can be awkward to use safely, because although it
** is defined to accept an argument of type int, its behavior when passed
** an integer that falls outside of the range of the unsigned char type
** is undefined (and sometimes, "undefined" means segfault). This wrapper
** is defined to accept an argument of type char, and always returns 0 for
** any values that fall outside of the range of the unsigned char type (i.e.
** negative values).
Encoding to use
Disallow both ON and USING clauses in the same join
The LIMIT clause will terminate the loop for us
Arguments for the indexing scheme
Jump here when done, ex: LIMIT reached
Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
** SELECT statement.
** Return the number of times sqlite3MemMalloc() has been called.
Advance to the next row to process.
Resolve the GROUP BY clause. At the same time, make sure
** the GROUP BY clause does not contain aggregate functions.
OUT: Set to true if call is a no-op
************* End of vtab.c ***********************************************
cmd ::= BEGIN transtype trans_opt
** Disconnect all sqlite3_vtab objects that belong to database connection
** db. This is called when db is being closed.
Number of columns in this table
A main database has just been opened. The following block sets
** (pFd->zWal) to point to a buffer owned by SQLite that contains
** the name of the *-wal file this db connection will use. SQLite
** happens to pass a pointer to this buffer when using xAccess()
** or xOpen() to operate on the *-wal file.
126
************* Begin file printf.c *****************************************
850
Name we are searching for
Default tokenizer module
SELECT rowid, * FROM ... WHERE rowid=?
Want a pending lock?
PERSIST
cmd ::= PRAGMA nm dbnm LP nmnum RP
Number of elements in apVal
Add constraints to reduce the search space on a LIKE or GLOB
** operator.
**
** A like pattern of the form "x LIKE 'aBc%'" is changed into constraints
**
** x>='ABC' AND x<'abd' AND x LIKE 'aBc%'
**
** The last character of the prefix "abc" is incremented to form the
** termination condition "abd". If case is not significant (the default
** for LIKE) then the lower-bound is made all uppercase and the upper-
** bound is made all lowercase so that the bounds also work when comparing
** BLOBs.
** Helper functions to obtain and relinquish the global mutex. The
** global mutex is used to protect the unixInodeInfo and
** vxworksFileId objects used by this file, all of which may be
** shared by multiple threads.
**
** Function unixMutexHeld() is used to assert() that the global mutex
** is held when required. This function is only used as part of assert()
** statements. e.g.
**
** unixEnterMutex()
** assert( unixMutexHeld() );
** unixEnterLeave()
Current operation
Copy of aPgno[] used for sorting pages
Temp storage must have already been allocated
There must be at least one outstanding reference to the pager if
** in ERROR state. Otherwise the pager should have already dropped
** back to OPEN state.
noop
Flags passed through to VFS open
comment: Memory for registers, parameters, cursor, etc, is allocated in one or two
** passes. On the first pass, we try to reuse unused memory at the
** end of the opcode array. If we are unable to satisfy all memory
** requirements by reusing the opcode array tail, then the second
** pass will fill in the remainder using a fresh memory allocation.
**
** This two-pass approach that reuses as much memory as possible from
** the leftover memory at the end of the opcode array. This can significantly
** reduce the amount of memory held by a prepared statement.
label: code-design
Special values interpreted by sqlite3SegReaderCursor()
** Find the table that is to be indexed. Return early if not found.
SQLITE_OMIT_PAGER_PRAGMAS
** Store the current database page-size in bytes in p->nPgsz.
**
** If *pRc is non-zero when this function is called, it is a no-op.
** Otherwise, if an error occurs, an SQLite error code is stored in *pRc
** before returning.
** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
** idx_affinity is the affinity of an indexed column. Return true
** if the index with affinity idx_affinity may be used to implement
** the comparison in pExpr.
Fake system time in seconds since 1970.
OUT: Number of bytes at *paToken
If isSimpleCount() returns a pointer to a Table structure, then
** the SQL statement is of the form:
**
** SELECT count(*) FROM <tbl>
**
** where the Table structure returned represents table <tbl>.
**
** This statement is so common that it is optimized specially. The
** OP_Count instruction is executed either on the intkey table that
** contains the data for table <tbl> or on one of its indexes. It
** is better to execute the op on an index, as indexes are almost
** always spread across less pages than their corresponding tables.
BETWEEN
Type of lock currently held on this file
Date/time functions that use 'now', and other functions like
** sqlite_version() that might change over time cannot be used
** in an index.
** CAPI3REF: Attach A Table To A Session Object
**
** If argument zTab is not NULL, then it is the name of a table to attach
** to the session object passed as the first argument. All subsequent changes
** made to the table while the session object is enabled will be recorded. See
** documentation for [sqlite3session_changeset()] for further details.
**
** Or, if argument zTab is NULL, then changes are recorded for all tables
** in the database. If additional tables are added to the database (by
** executing "CREATE TABLE" statements) after this call is made, changes for
** the new tables are also recorded.
**
** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
** defined as part of their CREATE TABLE statement. It does not matter if the
** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
** KEY may consist of a single column, or may be a composite key.
**
** It is not an error if the named table does not exist in the database. Nor
** is it an error if the named table does not have a PRIMARY KEY. However,
** no changes will be recorded in either of these scenarios.
**
** Changes are not recorded for individual rows that have NULL values stored
** in one or more of their PRIMARY KEY columns.
**
** SQLITE_OK is returned if the call completes without error. Or, if an error
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
IN/OUT: Right hand input list
Appropriate locking method
** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
** must be either NO_LOCK or SHARED_LOCK.
**
** If the locking level of the file descriptor is already at or below
** the requested locking level, this routine is a no-op.
**
** If handleNFSUnlock is true, then on downgrading an EXCLUSIVE_LOCK to SHARED
** the byte range is divided into 2 parts and the first part is unlocked then
** set to a read lock, then the other part is simply unlocked. This works
** around a bug in BSD NFS lockd (also seen on MacOSX 10.3+) that fails to
** remove the write lock on a region when a read lock is set.
pgoffset
If obtaining a child page for a cursor, we must verify that the page is
** compatible with the root page.
90
pWriter has an exclusive lock
** If pCsr->pStmt has not been prepared (i.e. if pCsr->pStmt==0), then
** compose and prepare an SQL statement of the form:
**
** "SELECT <columns> FROM %_content WHERE rowid = ?"
**
** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
** it. If an error occurs, return an SQLite error code.
comment: As this "NEAR" object is actually a single phrase that consists
** of a single term only, grab pointers into the poslist managed by the
** fts5_index.c iterator object. This is much faster than synthesizing
** a new poslist the way we have to for more complicated phrase or NEAR
** expressions.
label: code-design
** Return a list of all triggers on table pTab if there exists at least
** one trigger that must be fired when an operation of type 'op' is
** performed on the table, and, if that operation is an UPDATE, if at
** least one of the columns in pChanges is being modified.
** This function returns the space in bytes required to store the copy
** of the Expr structure and a copy of the Expr.u.zToken string (if that
** string is defined.)
Never happens because JNODE_RAW is only set by json_set(),
** json_insert() and json_replace() and those routines do not
** call jsonReturn()
** Decrement the ref-count on a virtual table object. When the ref-count
** reaches zero, call the xDisconnect() method to delete the object.
** The string z[] is an text representation of a real number.
** Convert this string to a double and write it into *pResult.
**
** The string z[] is length bytes in length (bytes, not characters) and
** uses the encoding enc. The string is not necessarily zero-terminated.
**
** Return TRUE if the result is a valid real number (or integer) and FALSE
** if the string is empty or contains extraneous text. Valid numbers
** are in one of these formats:
**
** [+-]digits[E[+-]digits]
** [+-]digits.[digits][E[+-]digits]
** [+-].digits[E[+-]digits]
**
** Leading and trailing whitespace is ignored for the purpose of determining
** validity.
**
** If some prefix of the input string is a valid number, this routine
** returns FALSE but it still converts the prefix and writes the result
** into *pResult.
Update the global lock state and do debug tracing
Return TRUE if the jsonEachCursor object has been advanced off the end
** of the JSON object
comment: We could allocate a fresh RowSetEntry each time one is needed, but it
** is more efficient to pull a preallocated entry from the pool
label: code-design
Unqualified name of the index to create
Move pPage to the front of the list
Index of next entry to replace
** The second argument passed to this function is the name of a PRAGMA
** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
** This function executes the following on sqlite3rbu.dbRbu:
**
** "PRAGMA main.$zPragma"
**
** where $zPragma is the string passed as the second argument, then
** on sqlite3rbu.dbMain:
**
** "PRAGMA main.$zPragma = $val"
**
** where $val is the value returned by the first PRAGMA invocation.
**
** In short, it copies the value of the specified PRAGMA setting from
** dbRbu to dbMain.
************* End of insert.c *********************************************
Maximum number of PMAs that a single MergeEngine can merge
** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
** is disabled. The default value for the auto-vacuum property is
** determined by the SQLITE_DEFAULT_AUTOVACUUM macro.
expr ::= BITNOT expr
** Each memory allocation looks like this:
**
** ------------------------------------------------------------------------
** | Title | backtrace pointers | MemBlockHdr | allocation | EndGuard |
** ------------------------------------------------------------------------
**
** The application code sees only a pointer to the allocation. We have
** to back up from the allocation pointer to find the MemBlockHdr. The
** MemBlockHdr tells us the size of the allocation and the number of
** backtrace pointers. There is also a guard word at the end of the
** MemBlockHdr.
Value returned by GetLastError()
The right operand
multiselect_op ::= EXCEPT|INTERSECT
Value from parent table row
SQLITE_WAL_H
Number of entries in this table
23
** Turn a SELECT statement (that the pSelect parameter points to) into
** a trigger step. Return a pointer to a TriggerStep structure.
**
** The parser calls this routine when it finds a SELECT statement in
** body of a TRIGGER.
Score of parent node
Generic error
Set to true at EOF
This function works in milliseconds, but the underlying OsSleep()
** API uses microseconds. Hence the 1000's.
Initial aLTerm[] space
** Argument p points to a buffer containing a varint to be interpreted as a
** position list size field. Read the varint and return the number of bytes
** read. Before returning, set *pnSz to the number of bytes in the position
** list, and *pbDel to true if the delete flag is set, or false otherwise.
Skip over == and IS and ISNULL terms. (Also skip IN terms when
** doing WHERE_ORDERBY_LIMIT processing).
**
** If the current term is a column of an ((?,?) IN (SELECT...))
** expression for which the SELECT returns more than one column,
** check that it is the only column used by this loop. Otherwise,
** if it is one of two or more, none of the columns can be
** considered to match an ORDER BY term.
Decode any entries that occur before the first term.
Next MAIN_DB file
Statistics
The ORDER BY or GROUP BY clause to be processed
The newly created page cache
The following call to PagerSetPagesize() serves to set the value of
** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
Hash table of in-memory nodes.
A column in the result set. 0..pEList->nExpr-1
IN/OUT: Offset within a[]
** Append the complete text of zero-terminated string z[] to the p string.
comment:
** Cleanup before returning.
label: code-design
cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES
fillInCell() only called for leaves
Used to iterate through entire index
9
** Macros indicating that conditional expressions are always true or
** false.
Did we just have a reader lock?
Load the next term on the node into zBuffer. Use realloc() to expand
** the size of zBuffer if required.
comment: Next term to insert into %_idx table
label: code-design
NO_TEST
KeyInfo for index
Index in pIn[] where zName is stored
** Set the StrAccum object to an error mode.
************* Begin file mutex_unix.c *************************************
Output segment
nil
Check the following statements are true:
**
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
** (b) if CREATE is set, then READWRITE must also be set, and
** (c) if EXCLUSIVE is set, then CREATE must also be set.
** (d) if DELETEONCLOSE is set, then CREATE must also be set.
Cost of path (pFrom+pWLoop)
Aggregate containing min() or max()
Index structure
** CAPI3REF: SQL Trace Event Codes
** KEYWORDS: SQLITE_TRACE
**
** These constants identify classes of events that can be monitored
** using the [sqlite3_trace_v2()] tracing logic. The third argument
** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
** the following constants. ^The first argument to the trace callback
** is one of the following constants.
**
** New tracing constants may be added in future releases.
**
** ^A trace callback has four arguments: xCallback(T,C,P,X).
** ^The T argument is one of the integer type codes above.
** ^The C argument is a copy of the context pointer passed in as the
** fourth argument to [sqlite3_trace_v2()].
** The P and X arguments are pointers whose meanings depend on T.
**
** <dl>
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
** first begins running and possibly at other times during the
** execution of the prepared statement, such as at the start of each
** trigger subprogram. ^The P argument is a pointer to the
** [prepared statement]. ^The X argument is a pointer to a string which
** is the unexpanded SQL text of the prepared statement or an SQL comment
** that indicates the invocation of a trigger. ^The callback can compute
** the same text that would have been returned by the legacy [sqlite3_trace()]
** interface by using the X argument when X begins with "--" and invoking
** [sqlite3_expanded_sql(P)] otherwise.
**
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
** information as is provided by the [sqlite3_profile()] callback.
** ^The P argument is a pointer to the [prepared statement] and the
** X argument points to a 64-bit integer which is the estimated of
** the number of nanosecond that the prepared statement took to run.
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
**
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
** statement generates a single row of result.
** ^The P argument is a pointer to the [prepared statement] and the
** X argument is unused.
**
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
** connection closes.
** ^The P argument is a pointer to the [database connection] object
** and the X argument is unused.
** </dl>
Copy the p->u.zToken string, if any.
Instruction opcode
%d or %u, but not %x, %o
comment: Populate the array of registers beginning at regNew with the new
** row data. This array is used to check constants, create the new
** table and index records, and as the values for any new.* references
** made by triggers.
**
** If there are one or more BEFORE triggers, then do not populate the
** registers associated with columns that are (a) not modified by
** this UPDATE statement and (b) not accessed by new.* references. The
** values for registers not modified by the UPDATE must be reloaded from
** the database after the BEFORE triggers are fired anyway (as the trigger
** may have modified them). So not loading those that are not going to
** be used eliminates some redundant opcodes.
label: code-design
Sync the journal file if required.
Step 6: Loop through rows of the RHS. Compare each row to the LHS.
** If any comparison is NULL, then the result is NULL. If all
** comparisons are FALSE then the final result is FALSE.
**
** For a scalar LHS, it is sufficient to check just the first row
** of the RHS.
Append the current configuration cookie
** Return a pointer to a string containing the 'declaration type' of the
** expression pExpr. The string may be treated as static by the caller.
**
** Also try to estimate the size of the returned value and return that
** result in *pEstWidth.
**
** The declaration type is the exact datatype definition extracted from the
** original CREATE TABLE statement if the expression is a column. The
** declaration type for a ROWID field is INTEGER. Exactly when an expression
** is considered a column can be complex in the presence of subqueries. The
** result-set expression in all of the following SELECT statements is
** considered a column by this function.
**
** SELECT col FROM tbl;
** SELECT (SELECT col FROM tbl;
** SELECT (SELECT col FROM tbl);
** SELECT abc FROM (SELECT col AS abc FROM tbl);
**
** The declaration type for any expression other than a column is NULL.
**
** This routine has either 3 or 6 parameters depending on whether or not
** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
Current pre-update operation
Instruction number of OP_Function opcode
** Implementation of the sqlite3_pcache.xRekey method.
This is the PGroup.lru element
Wal filename for this main db file
Array of sub-vdbes
Open the RBU database
comment:
** Close a file & cleanup AFP specific locking context
label: code-design
If !isPSample, the reason for inclusion
The argument list
** Search along zPath to find the node specified. Return a pointer
** to that node, or NULL if zPath is malformed or if there is no such
** node.
**
** If pApnd!=0, then try to append new nodes to complete zPath if it is
** possible to do so and if no existing node corresponds to zPath. If
** new nodes are appended *pApnd is set to 1.
eidlist_opt ::=
One iterator for each phrase
Final number of cells on page
The aMx[] array translates the 3rd character of each format
** spec into a max size: a b c d e f
** Make sure at least one set of Win32 APIs is available.
Allocated space not yet assigned
** An instance of the following structure is passed as the first
** argument to sqlite3VdbeKeyCompare and is used to control the
** comparison of the two index keys.
**
** Note that aSortOrder[] and aColl[] have nField+1 slots. There
** are nField slots for the columns of an index then one extra slot
** for the rowid at the end.
70
** Change the maximum number of in-memory pages that are allowed
** before attempting to spill pages to journal.
_FTS3_TOKENIZER_H_
Database filename UTF-8 encoded
comment:
** CAPI3REF: Mutexes
**
** The SQLite core uses these routines for thread
** synchronization. Though they are intended for internal
** use by SQLite, code that links against SQLite is
** permitted to use any of these routines.
**
** The SQLite source code contains multiple implementations
** of these mutex routines. An appropriate implementation
** is selected automatically at compile-time. The following
** implementations are available in the SQLite core:
**
** <ul>
** <li> SQLITE_MUTEX_PTHREADS
** <li> SQLITE_MUTEX_W32
** <li> SQLITE_MUTEX_NOOP
** </ul>
**
** The SQLITE_MUTEX_NOOP implementation is a set of routines
** that does no real locking and is appropriate for use in
** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
** and Windows.
**
** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
** implementation is included with the library. In this case the
** application must supply a custom mutex implementation using the
** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
** before calling sqlite3_initialize() or any other public sqlite3_
** function that calls sqlite3_initialize().
**
** ^The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
** routine returns NULL if it is unable to allocate the requested
** mutex. The argument to sqlite3_mutex_alloc() must one of these
** integer constants:
**
** <ul>
** <li> SQLITE_MUTEX_FAST
** <li> SQLITE_MUTEX_RECURSIVE
** <li> SQLITE_MUTEX_STATIC_MASTER
** <li> SQLITE_MUTEX_STATIC_MEM
** <li> SQLITE_MUTEX_STATIC_OPEN
** <li> SQLITE_MUTEX_STATIC_PRNG
** <li> SQLITE_MUTEX_STATIC_LRU
** <li> SQLITE_MUTEX_STATIC_PMEM
** <li> SQLITE_MUTEX_STATIC_APP1
** <li> SQLITE_MUTEX_STATIC_APP2
** <li> SQLITE_MUTEX_STATIC_APP3
** <li> SQLITE_MUTEX_STATIC_VFS1
** <li> SQLITE_MUTEX_STATIC_VFS2
** <li> SQLITE_MUTEX_STATIC_VFS3
** </ul>
**
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
** cause sqlite3_mutex_alloc() to create
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
** The mutex implementation does not need to make a distinction
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
** not want to. SQLite will only request a recursive mutex in
** cases where it really needs one. If a faster non-recursive mutex
** implementation is available on the host platform, the mutex subsystem
** might return such a mutex in response to SQLITE_MUTEX_FAST.
**
** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
** a pointer to a static preexisting mutex. ^Nine static mutexes are
** used by the current version of SQLite. Future versions of SQLite
** may add additional static mutexes. Static mutexes are for internal
** use by SQLite only. Applications that use SQLite mutexes should
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
** SQLITE_MUTEX_RECURSIVE.
**
** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call. ^For the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
**
** ^The sqlite3_mutex_free() routine deallocates a previously
** allocated dynamic mutex. Attempting to deallocate a static
** mutex results in undefined behavior.
**
** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. ^If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
** upon successful entry. ^(Mutexes created using
** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
** In such cases, the
** mutex must be exited an equal number of times before another thread
** can enter.)^ If the same thread tries to enter any mutex other
** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
**
** ^(Some systems (for example, Windows 95) do not support the operation
** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
** will always return SQLITE_BUSY. The SQLite core only ever uses
** sqlite3_mutex_try() as an optimization so this is acceptable
** behavior.)^
**
** ^The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered by the
** calling thread or is not currently allocated.
**
** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
** sqlite3_mutex_leave() is a NULL pointer, then all three routines
** behave as no-ops.
**
** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
label: code-design
** If SQLITE_OMIT_AUTOINCREMENT is defined, then the three routines
** above are all no-ops
Name of the module
** Initialize the auxiliary information for a disk block.
**
** Return SQLITE_OK on success. If we see that the page does
** not contain a well-formed database page, then return
** SQLITE_CORRUPT. Note that a return of SQLITE_OK does not
** guarantee that the page is well-formed. It only shows that
** we failed to detect any corruption.
Advance to the next output block
** Called when iAmt bytes are read from offset iOff of the wal file while
** the rbu object is in capture mode. Record the frame number of the frame
** being read in the aFrame[] array.
If p5 is zero, the seek operation that positioned the cursor prior to
** OP_Delete will have also set the pC->movetoTarget field to the rowid of
** the row that is being deleted
Frame to read from WAL file
** Helper function for fts3NodeWrite().
If the iterator is not at a real match, skip forward until it is.
Page number to obtain
If there was an INDEXED BY clause, then only that one index is
** considered.
If we reach this point, that means the transformation is required.
** Return a nul-terminated copy of the string indicated by pIn. If nIn
** is non-negative, then it is the length of the string in bytes. Otherwise,
** the length of the string is determined using strlen().
**
** It is the responsibility of the caller to eventually free the returned
** buffer using sqlite3_free(). If an OOM error occurs, NULL is returned.
This branch is taken when the journal path required by
** the database being opened will be more than pVfs->mxPathname
** bytes in length. This means the database cannot be opened,
** as it will not be possible to open the journal file or even
** check for a hot-journal before reading.
195
xSync - sync transaction
Pseudotable used to decode sorting results
If this is the right table of a LEFT OUTER JOIN, allocate and
** initialize a memory cell that records if this table matches any
** row of the left table of the join.
comment: Number of contiguous term-less nodes
label: code-design
Link an element into the hash table
The VM under construction
Table object
Address register for the output-A subroutine
vdbePmaReadBlob() return code
Old index in b.apCell[]
groupby_opt
Write the xxx_node table
The RHS of the IN operator
Various SF_* values
Used to iterate through cells
Populate the PagerSavepoint structures just allocated.
FTS5 Configuration object
Figure out how many bytes are required by this new entry
Skip accumulator loading if true
Expression to initialize phrases in
Number of bytes of leaf data written
True if non-integer value was input to the sum
Pathname of file to be opened
Pointer to tail
Zero the output variables in case an error occurs.
Pointer to cell to delete
** 2014 Jun 09
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This is an SQLite module implementing full-text search.
Conflict only if the rowid of the existing index entry
** is different from old-rowid
xOpen
If nLoop is zero, then there are no FROM terms in the query. Since
** in this case the query may return a maximum of one row, the results
** are already in the requested order. Set isOrdered to nOrderBy to
** indicate this. Or, if nLoop is greater than zero, set isOrdered to
** -1, indicating that the result set may or may not be ordered,
** depending on the loops added to the current plan.
IN/OUT: List to sort
** Implementation of the xBestIndex method for FTS5 tables. Within the
** WHERE constraint, it searches for the following:
**
** 1. A MATCH constraint against the special column.
** 2. A MATCH constraint against the "rank" column.
** 3. An == constraint against the rowid column.
** 4. A < or <= constraint against the rowid column.
** 5. A > or >= constraint against the rowid column.
**
** Within the ORDER BY, either:
**
** 5. ORDER BY rank [ASC|DESC]
** 6. ORDER BY rowid [ASC|DESC]
**
** Costs are assigned as follows:
**
** a) If an unusable MATCH operator is present in the WHERE clause, the
** cost is unconditionally set to 1e50 (a really big number).
**
** a) If a MATCH operator is present, the cost depends on the other
** constraints also present. As follows:
**
** * No other constraints: cost=1000.0
** * One rowid range constraint: cost=750.0
** * Both rowid range constraints: cost=500.0
** * An == rowid constraint: cost=100.0
**
** b) Otherwise, if there is no MATCH:
**
** * No other constraints: cost=1000000.0
** * One rowid range constraint: cost=750000.0
** * Both rowid range constraints: cost=250000.0
** * An == rowid constraint: cost=10.0
**
** Costs are not modified by the ORDER BY clause.
** Print into memory obtained from sqliteMalloc(). Use the internal
** %-conversion extensions.
in hash, if not, try to find a spot for it
Path by which to filter zJson
Value of pOp at the top of the loop
Two or more indexes share the same root page. There must
** be imposter tables. So just return true. The assert is not
** useful in that case.
** Generate code for a DELETE FROM statement.
**
** DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
** \________/ \________________/
** pTabList pWhere
** CAPI3REF: Test For Auto-Commit Mode
** KEYWORDS: {autocommit mode}
** METHOD: sqlite3
**
** ^The sqlite3_get_autocommit() interface returns non-zero or
** zero if the given database connection is or is not in autocommit mode,
** respectively. ^Autocommit mode is on by default.
** ^Autocommit mode is disabled by a [BEGIN] statement.
** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
**
** If certain kinds of errors occur on a statement within a multi-statement
** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
** transaction might be rolled back automatically. The only way to
** find out whether SQLite automatically rolled back the transaction after
** an error is to use this function.
**
** If another thread changes the autocommit status of the database
** connection while this routine is running, then the return value
** is undefined.
** Merge the entire database so that there is one segment for each
** iIndex/iLangid combination.
Free up as much memory as possible from the page cache
#include "fts3.h"
True for reverse-order IN operations
Phrase to advance token of
OP_Open should use BTREE_FORDELETE
Opcode: OpenEphemeral P1 P2 * P4 P5
** Synopsis: nColumn=P2
**
** Open a new cursor P1 to a transient table.
** The cursor is always opened read/write even if
** the main database is read-only. The ephemeral
** table is deleted automatically when the cursor is closed.
**
** P2 is the number of columns in the ephemeral table.
** The cursor points to a BTree table if P4==0 and to a BTree index
** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
** that defines the format of keys in the index.
**
** The P5 parameter can be a mask of the BTREE_* flags defined
** in btree.h. These flags control aspects of the operation of
** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
** added automatically.
True if the conversion to IN is valid
OUT: Acquired page object
comment: Initializing the tail of the buffer is not necessary. Everything
** works find if the following memset() is omitted. But initializing
** the memory prevents valgrind from complaining, so we are willing to
** take the performance hit.
label: code-design
An OE_ code for handling a NOT NULL constraint
Length of the keyword in characters
expr ::= expr STAR|SLASH|REM expr
If recursive mutexes are not available, we will have to
** build our own. See below.
************* Continuing where we left off in status.c ********************
18
A VList object records a mapping between parameters/variables/wildcards
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
** variable number associated with that parameter. See the format description
** on the sqlite3VListAdd() routine for more information. A VList is really
** just an array of integers.
Fail the operation and rollback the transaction
White space is ignored
This sample is being added because the prefix that ends in column
** iCol occurs many times in the table. However, if we have already
** added a sample that shares this prefix, there is no need to add
** this one. Instead, upgrade the priority of the highest priority
** existing sample that shares this prefix.
aSalt[0] is a copy of the value stored in the wal file header. It
** is incremented each time the wal file is restarted.
Largest key seen since xTruncate()
Vdbe to iterate through the opcodes of
Convenient short-hand
** This function is the implementation of the xUpdate callback used by
** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
** inserted, updated or deleted.
**
** A delete specifies a single argument - the rowid of the row to remove.
**
** Update and insert operations pass:
**
** 1. The "old" rowid, or NULL.
** 2. The "new" rowid.
** 3. Values for each of the nCol matchable columns.
** 4. Values for the two hidden columns (<tablename> and "rank").
Assign argvIndex values to each constraint in use.
The structure record
boolean
** This "finder" function attempts to determine the best locking strategy
** for the database file "filePath". It then returns the sqlite3_io_methods
** object that implements that strategy.
**
** This is for MacOSX only.
ON CONFLICT policy to code trigger program with
where_opt
** This function is a no-op unless SQLITE_DEBUG is defined when this module
** is compiled. In that case, this function is essentially an assert()
** statement used to verify that the contents of the pIter->aFirst[] array
** are correct.
** An ephemeral string value (signified by the MEM_Ephem flag) contains
** a pointer to a dynamically allocated string where some other entity
** is responsible for deallocating that string. Because the register
** does not control the string, it might be deleted without the register
** knowing it.
**
** This routine converts an ephemeral string into a dynamically allocated
** string that the register itself controls. In other words, it
** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
This block sets stack variable iPg to the leaf page number that may
** contain term (pTerm/nTerm), if it is present in the segment.
Unsigned loop counter
Linked list of all unfreed memory
Return code from execution
** This function is called when inserting, deleting or updating a row of
** table pTab to generate VDBE code to perform foreign key constraint
** processing for the operation.
**
** For a DELETE operation, parameter regOld is passed the index of the
** first register in an array of (pTab->nCol+1) registers containing the
** rowid of the row being deleted, followed by each of the column values
** of the row being deleted, from left to right. Parameter regNew is passed
** zero in this case.
**
** For an INSERT operation, regOld is passed zero and regNew is passed the
** first register of an array of (pTab->nCol+1) registers containing the new
** row data.
**
** For an UPDATE operation, this function is called twice. Once before
** the original record is deleted from the table using the calling convention
** described for DELETE. Then again after the original record is deleted
** but before the new record is inserted using the INSERT convention.
Both x>EXPR and x<EXPR
function to free pUser
Left operand
log(Number of iterations due to IN)
The database connection;
Position list for deferred tokens
Return true if the cursor was opened using the OP_OpenSorter opcode.
When floating-point is omitted, double and int64 are the same thing
Flags used only if debugging
Value returned by SetFilePointerEx()
** Load the contents of the %_config table into memory.
comment:
** CAPI3REF: Configuring The SQLite Library
**
** The sqlite3_config() interface is used to make global configuration
** changes to SQLite in order to tune SQLite to the specific needs of
** the application. The default configuration is recommended for most
** applications and so this routine is usually not necessary. It is
** provided to support rare applications with unusual needs.
**
** <b>The sqlite3_config() interface is not threadsafe. The application
** must ensure that no other SQLite interfaces are invoked by other
** threads while sqlite3_config() is running.</b>
**
** The sqlite3_config() interface
** may only be invoked prior to library initialization using
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
** Note, however, that ^sqlite3_config() can be called as part of the
** implementation of an application-defined [sqlite3_os_init()].
**
** The first argument to sqlite3_config() is an integer
** [configuration option] that determines
** what property of SQLite is to be configured. Subsequent arguments
** vary depending on the [configuration option]
** in the first argument.
**
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
** ^If the option is unknown or SQLite is unable to set the option
** then this routine returns a non-zero [error code].
label: code-design
If this is an auto-vacuum database, update the pointer-map entries
** for any b-tree or overflow pages that pTo now contains the pointers to.
Here code is inserted which will execute if the parser
** stack every overflows
sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax);
Statements created by rbuObjIterPrepareAll()
Map cursor numbers to bitmasks
** pStmt:
** SELECT rowid, <fts> FROM <fts> ORDER BY +rank;
**
** aIdx[]:
** There is one entry in the aIdx[] array for each phrase in the query,
** the value of which is the offset within aPoslist[] following the last
** byte of the position list for the corresponding phrase.
Compute in mxSafeFrame the index of the last frame of the WAL that is
** safe to write into the database. Frames beyond mxSafeFrame might
** overwrite database pages that are in use by active readers and thus
** cannot be backfilled from the WAL.
A negative cache-size value C indicates that the cache is abs(C)
** KiB in size.
This function normally generates a nested loop for all tables in
** pTabList. But if the WHERE_OR_SUBCLAUSE flag is set, then we should
** only generate code for the first table in pTabList and assume that
** any cursors associated with subsequent tables are uninitialized.
Unable to flatten compound queries
Create the destination temporary table if necessary
** Expression p should encode a floating point value between 1.0 and 0.0.
** Return 1024 times this value. Or return -1 if p is not a floating point
** value between 1.0 and 0.0.
One particular FROM clause in a nested query
To iterate through levels
All keys from this input segment have been transfered to the output.
** Set both the first and last page-numbers to 0 to indicate that the
** segment is now empty.
IMP: R-51414-32910
59
************* End of main.c ***********************************************
SQLITE_NULLEQ or zero
Number of attached databases
Deferred search tokens, if any
comment:
** This version of the memory allocator is used only if the
** SQLITE_MEMDEBUG macro is defined
label: code-design
Opcode: ElseNotEq * P2 * * *
**
** This opcode must immediately follow an OP_Lt or OP_Gt comparison operator.
** If result of an OP_Eq comparison on the same two operands
** would have be NULL or false (0), then then jump to P2.
** If the result of an OP_Eq comparison on the two previous operands
** would have been true (1), then fall through.
SQLITE_TEST
Load the built-in tokenizers into the hash table
** Register a new 2nd-generation geometry function for use with the
** r-tree MATCH operator.
Allocate the SegmentWriter structure
Poslist of this iterator
In this case, call balance_nonroot() to redistribute cells
** between pPage and up to 2 of its sibling pages. This involves
** modifying the contents of pParent, which may cause pParent to
** become overfull or underfull. The next iteration of the do-loop
** will balance the parent page to correct this.
**
** If the parent page becomes overfull, the overflow cell or cells
** are stored in the pSpace buffer allocated immediately below.
** A subsequent iteration of the do-loop will deal with this by
** calling balance_nonroot() (balance_deeper() may be called first,
** but it doesn't deal with overflow cells - just moves them to a
** different page). Once this subsequent call to balance_nonroot()
** has completed, it is safe to release the pSpace buffer used by
** the previous call, as the overflow cell data will have been
** copied either into the body of a database page or into the new
** pSpace buffer passed to the latter call to balance_nonroot().
Flags to enable/disable optimizations
Term.pExpr is an IS operator
Allocate and populate the new session object.
File from which to do direct overflow read
** Transfer the contents of pFrom to pTo. Any existing value in pTo is
** freed. If pFrom contains ephemeral data, a copy is made.
**
** pFrom contains an SQL NULL when this routine returns.
New change object
If no test above fails then the indices must be compatible
Do not analyze the TEMP database
Integer and Real
szPma
Address of array containing old row
** CAPI3REF: Conflict resolution modes
** KEYWORDS: {conflict resolution mode}
**
** These constants are returned by [sqlite3_vtab_on_conflict()] to
** inform a [virtual table] implementation what the [ON CONFLICT] mode
** is for the SQL statement being evaluated.
**
** Note that the [SQLITE_IGNORE] constant is also used as a potential
** return value from the [sqlite3_set_authorizer()] callback and that
** [SQLITE_ABORT] is also a [result code].
** Implementation of matchinfo() function.
User name used to authenticate
There exists another row with the new.* primary key.
(5)
Tables that are indexable, satisfying case 2
True if this constraint is usable
Index identifier string
Take the jump if the BETWEEN is NULL
If REPLACE conflict resolution might be invoked, open cursors on all
** indexes in case they are needed to delete records.
cmd ::= VACUUM
If the column contains an "AS <name>" phrase, use <name> as the name
98..9f ........
Try to expand the master using the newly freed chunk
** Implementation of the stat_push SQL function: stat_push(P,C,R)
** Arguments:
**
** P Pointer to the Stat4Accum object created by stat_init()
** C Index of left-most column to differ from previous row
** R Rowid for the current row. Might be a key record for
** WITHOUT ROWID tables.
**
** This SQL function always returns NULL. It's purpose it to accumulate
** statistical data and/or samples in the Stat4Accum object about the
** index being analyzed. The stat_get() SQL function will later be used to
** extract relevant information for constructing the sqlite_statN tables.
**
** The R parameter is only used for STAT3 and STAT4
************* End of sqliteLimit.h ****************************************
comment:
** 2007 August 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the common header for all mutex implementations.
** The sqliteInt.h header #includes this file so that it is available
** to all source files. We break it out in an effort to keep the code
** better organized.
**
** NOTE: source files should *not* #include this header file directly.
** Source files should #include the sqliteInt.h file and let that file
** include this one indirectly.
label: code-design
The cell may contain a pointer to an overflow page. If so, write
** the entry for the overflow page into the pointer map.
INSTEAD
Initialize each of the component segment iterators.
Bytes of space at aAlloc
First argument to the function
OUT: Blob data in malloc'd buffer
Possible values for Rtree.eCoordType:
Total number of columns in the index
If an error has already occurred, this is a no-op
Now manipulate the actual database free-list structure. There are two
** possibilities. If the free-list is currently empty, or if the first
** trunk page in the free-list is full, then this page will become a
** new free-list trunk page. Otherwise, it will become a leaf of the
** first trunk page in the current free-list. This block tests if it
** is possible to add the page as a new free-list leaf.
At least this one VM is active
** Return a pointer to the WalIndexHdr structure in the wal-index.
Begin generating code.
comment:
** The sqlite3_mutex_leave() routine exits a mutex that was previously
** entered by the same thread. The behavior is undefined if the mutex
** is not currently entered. If a NULL pointer is passed as an argument
** this function is a no-op.
label: code-design
Make sure the locking sequence is correct.
** (1) We never move from unlocked to anything higher than shared lock.
** (2) SQLite never explicitly requests a pendig lock.
** (3) A shared lock is always held when a reserve lock is requested.
Count non-delimiter characters.
Number of levels in this index
The index expression
Set the szLeaf field
Index used, or NULL
** An instance of this object represents a single database file.
**
** A single database file can be in use at the same time by two
** or more database connections. When two or more connections are
** sharing the same database file, each connection has it own
** private Btree object for the file and each of those Btrees points
** to this one BtShared object. BtShared.nRef is the number of
** connections currently sharing this database file.
**
** Fields in this structure are accessed under the BtShared.mutex
** mutex, except for nRef and pNext which are accessed under the
** global SQLITE_MUTEX_STATIC_MASTER mutex. The pPager field
** may not be modified once it is initially set as long as nRef>0.
** The pSchema field may be set once under BtShared.mutex and
** thereafter is unchanged as long as nRef>0.
**
** isPending:
**
** If a BtShared client fails to obtain a write-lock on a database
** table (because there exists one or more read-locks on the table),
** the shared-cache enters 'pending-lock' state and isPending is
** set to true.
**
** The shared-cache leaves the 'pending lock' state when either of
** the following occur:
**
** 1) The current writer (BtShared.pWriter) concludes its transaction, OR
** 2) The number of locks held by other connections drops to zero.
**
** while in the 'pending-lock' state, no connection may start a new
** transaction.
**
** This feature is included to help prevent writer-starvation.
comment: An unusual case: this is the first term to be added to the node
** and the static node buffer (p->nNodeSize bytes) is not large
** enough. Use a separately malloced buffer instead This wastes
** p->nNodeSize bytes, but since this scenario only comes about when
** the database contain two terms that share a prefix of almost 2KB,
** this is not expected to be a serious problem.
label: code-design
** Return the 64-bit integer value associated with cell iCell of
** node pNode. If pNode is a leaf node, this is a rowid. If it is
** an internal node, then the 64-bit integer is a child page number.
Number of columns in record
TODO1: Updating pgidx here.
Total sizes of each column
IN/OUT: Left-hand buffer pointer
ABOVE: Height enforcement enabled. BELOW: Height enforcement off
transtype ::=
Number of identifiers on the list
Phrase object
Bytes of data stored in pFd
First in list of all open cursors
Leaf to add to tree
** Find the mode, uid and gid of file zFile.
Minimum local payload in non-LEAFDATA tables
Pointer to phrase counter
SubProgram.nMem is set to the number of memory cells used by the
** program stored in SubProgram.aOp. As well as these, one memory
** cell is required for each cursor used by the program. Set local
** variable nMem (and later, VdbeFrame.nChildMem) to this value.
** Return TRUE if the given expression is a constant which would be
** unchanged by OP_Affinity with the affinity given in the second
** argument.
**
** This routine is used to determine if the OP_Affinity operation
** can be omitted. When in doubt return FALSE. A false negative
** is harmless. A false positive, however, can result in the wrong
** answer.
Where to jump to continue with the next IN case
comment:
** If the third argument is non-NULL, then this function releases a
** reference obtained by an earlier call to unixFetch(). The second
** argument passed to this function must be the same as the corresponding
** argument that was passed to the unixFetch() invocation.
**
** Or, if the third argument is NULL, then this function is being called
** to inform the VFS layer that, according to POSIX, any existing mapping
** may now be invalid and should be unmapped.
label: code-design
************* Begin file hash.h *******************************************
True to count the table
SQLITE_STMTSTATUS_RUN
** Check to make sure the given table is writable. If it is not
** writable, generate an error message and return 1. If it is
** writable return 0;
flags fit in 8 bits
Input flags to control the opening
** Delete memory allocated for the column names of a table or view (the
** Table.aCol[] array).
!SQLITE_OMIT_WAL
Invoke xProgress() when nVmStep reaches this
Term to seek to (or NULL/0)
270
EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
** interior index b-tree page.
Original value of pNew->prereq
Opening flags
Generate code that will continue to the next row if
** the IN constraint is not satisfied
The B*Tree structure for this database file
The WHEN clause of the expression (may be NULL)
************* Begin file fts3_unicode.c ***********************************
Disable nuisance warnings on Borland compilers
Used to loop through N hash tables
RHS is entirely deferred. So we assume it matches every row.
** Advance the LHS iterator to find the next row visited.
SQLITE_WIN32_FILEMAPPING_API
Name of the database file to open
comment: If the HAS_MOVED file-control is unimplemented, assume that the file
** has not been moved. That is the historical behavior of SQLite: prior to
** version 3.8.3, it never checked
label: code-design
** Begin iterating through the set of documents in index pIdx matched by
** the MATCH expression passed as the first argument. If the "bDesc"
** parameter is passed a non-zero value, iteration is in descending rowid
** order. Or, if it is zero, in ascending order.
**
** If iterating in ascending rowid order (bDesc==0), the first document
** visited is that with the smallest rowid that is larger than or equal
** to parameter iFirst. Or, if iterating in ascending order (bDesc==1),
** then the first document visited must have a rowid smaller than or
** equal to iFirst.
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise. It
** is not considered an error if the query does not match any documents.
Offset of db file entry
** If the node is dirty, write it out to the database.
If TEMP was specified, then the trigger name may not be qualified.
If connected to a ZIPVFS backend, override the page size and
** offset with actual values obtained from ZIPVFS.
Read and write return code from here
1 sec timeout
Pointer to TK_STRING expression with pattern prefix
** Expression pExpr is a comparison between two vector values. Compute
** the result of the comparison (1, 0, or NULL) and write that
** result into register dest.
**
** The caller must satisfy the following preconditions:
**
** if pExpr->op==TK_IS: op==TK_EQ and p5==SQLITE_NULLEQ
** if pExpr->op==TK_ISNOT: op==TK_NE and p5==SQLITE_NULLEQ
** otherwise: op==pExpr->op and p5==0
** Copy as much content as we can from the WAL back into the database file
** in response to an sqlite3_wal_checkpoint() request or the equivalent.
**
** The amount of information copies from WAL to database might be limited
** by active readers. This routine will never overwrite a database page
** that a concurrent reader might be using.
**
** All I/O barrier operations (a.k.a fsyncs) occur in this routine when
** SQLite is in WAL-mode in synchronous=NORMAL. That means that if
** checkpoints are always run by a background thread or background
** process, foreground threads will never block on a lengthy fsync call.
**
** Fsync is called on the WAL before writing content out of the WAL and
** into the database. This ensures that if the new content is persistent
** in the WAL and can be recovered following a power-loss or hard reset.
**
** Fsync is also called on the database file if (and only if) the entire
** WAL content is copied into the database file. This second fsync makes
** it safe to delete the WAL since the new content will persist in the
** database file.
**
** This routine uses and updates the nBackfill field of the wal-index header.
** This is the only routine that will increase the value of nBackfill.
** (A WAL reset or recovery will revert nBackfill to zero, but not increase
** its value.)
**
** The caller must be holding sufficient locks to ensure that no other
** checkpoint is running (in any other thread or process) at the same
** time.
AFTER => ID
If this is an UPDATE that is part of a patchset, then all PK and
** modified fields are present in the new.* record. The old.* record
** is currently completely empty. This block shifts the PK fields from
** new.* to old.*, to accommodate the code that reads these arrays.
One of SQLITE_UPDATE, INSERT, DELETE
120
comment:
** CAPI3REF: Name Of The Folder Holding Database Files
**
** ^(If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all database files
** specified with a relative pathname and created or accessed by
** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
** to be relative to that directory.)^ ^If this variable is a NULL
** pointer, then SQLite assumes that all database files specified
** with a relative pathname are relative to the current directory
** for the process. Only the windows VFS makes use of this global
** variable; it is ignored by the unix VFS.
**
** Changing the value of this variable while a database connection is
** open can result in a corrupt database.
**
** It is not safe to read or modify this variable in more than one
** thread at a time. It is not safe to read or modify this variable
** if a [database connection] is being used at the same time in a separate
** thread.
** It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been called and that this variable remain unchanged
** thereafter.
**
** ^The [data_store_directory pragma] may modify this variable and cause
** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
** the [data_store_directory pragma] always assumes that any string
** that this variable points to is held in memory obtained from
** [sqlite3_malloc] and the pragma may attempt to free that memory
** using [sqlite3_free].
** Hence, if this variable is modified directly, either it should be
** made NULL or made to point to memory obtained from [sqlite3_malloc]
** or else the use of the [data_store_directory pragma] should be avoided.
label: code-design
Optimal text encoding
Allocate and populate the Fts3Table structure.
If the destination database has not yet been locked (i.e. if this
** is the first call to backup_step() for the current backup operation),
** try to set its page size to the same as the source database. This
** is especially important on ZipVFS systems, as in that case it is
** not possible to create a database file that uses one page size by
** writing to it with another.
** Hash and comparison functions when the mode is FTS3_HASH_BINARY
Number of entries in aConstraint
didn't get, must be busy
Label for the end of the overall SELECT stmt
The whole database
New table number
Callback for expressions
** Return the number of times the Step function of an aggregate has been
** called.
**
** This function is deprecated. Do not use it for new code. It is
** provide only to avoid breaking legacy code. New aggregate function
** implementations should keep their own counts within their aggregate
** context.
Write the folded case of the last character read to the output
Store only the name
*************************************************************************
** The following block contains those class members that change during
** routine operation. Class members not in this block are either fixed
** when the pager is first created or else only change when there is a
** significant mode change (such as changing the page_size, locking_mode,
** or the journal_mode). From another view, these class members describe
** the "state" of the pager, while other class members describe the
** "configuration" of the pager.
Collating sequence for each term of the key
only mkdir if leaf dir != "." or "/" or ".."
0 if leaf==1. 4 if leaf==0
************* Continuing where we left off in vdbe.c **********************
Tree contains a TK_SELECT operator
** Formulate and prepare a statement to UPDATE a row from database db.
** Assuming a table structure like this:
**
** CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
**
** The UPDATE statement looks like this:
**
** UPDATE x SET
** a = CASE WHEN ?2 THEN ?3 ELSE a END,
** b = CASE WHEN ?5 THEN ?6 ELSE b END,
** c = CASE WHEN ?8 THEN ?9 ELSE c END,
** d = CASE WHEN ?11 THEN ?12 ELSE d END
** WHERE a = ?1 AND c = ?7 AND (?13 OR
** (?5==0 OR b IS ?4) AND (?11==0 OR d IS ?10) AND
** )
**
** For each column in the table, there are three variables to bind:
**
** ?(i*3+1) The old.* value of the column, if any.
** ?(i*3+2) A boolean flag indicating that the value is being modified.
** ?(i*3+3) The new.* value of the column, if any.
**
** Also, a boolean flag that, if set to true, causes the statement to update
** a row even if the non-PK values do not match. This is required if the
** conflict-handler is invoked with CHANGESET_DATA and returns
** CHANGESET_REPLACE. This is variable "?(nCol*3+1)".
**
** If successful, SQLITE_OK is returned and SessionApplyCtx.pUpdate is left
** pointing to the prepared version of the SQL statement.
SQLITEINT_H
OUT: Imposter PK clause
** The diff hook implementations.
True if getNextNode() sees a unary -
compiler-defined memory barrier
cap min request size at 2^12
An index of the table
Return the number of cells in a node
The rest are extensions, not normally found in printf()
Size of database content section
An expression from the ORDER BY clause
Extension API function pointers.
Value returned by preupdate_new/old
If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf
** blocks have already been traversed.
If the SQLITE_TESTCTRL_FAULT_INSTALL callback is registered to a
** function that returns SQLITE_ERROR when passed the argument 200, that
** forces worker threads to run sequentially and deterministically
** for testing purposes.
Right operand
** Return 1 if database is read-only or 0 if read/write. Return -1 if
** no such database exists.
** Mark this cursor as an incremental blob cursor.
Opcode: MaxPgcnt P1 P2 P3 * *
**
** Try to set the maximum page count for database P1 to the value in P3.
** Do not let the maximum page count fall below the current page count and
** do not change the maximum page count value if P3==0.
**
** Store the maximum page count after the change in register P2.
Invoke MustBeInt to coerce the child key value to an integer (i.e.
** apply the affinity of the parent key). If this fails, then there
** is no matching parent key. Before using MustBeInt, make a copy of
** the value. Otherwise, the value inserted into the child key column
** will have INTEGER affinity applied to it, which may not be correct.
PRIVATE: Cache that owns this page
File handle object
** Find the current time (in Universal Coordinated Time). Write the
** current time and date as a Julian Day number into *prNow and
** return 0. Return 1 if the time and date cannot be found.
arguments
Now get the read-lock SHARED_LOCK
Delete the row
Statements to read/write/delete a record from xxx_parent
** Terminator values for position-lists and column-lists.
Allocate the sqlite3_vtab structure
constructor for a JsonEachCursor object for json_tree().
Extract arguments from the current row of the ephemeral table and
** invoke the VUpdate method.
Verify that an index entry exists for the current table row
The first node of the scan
Enable mutex on core
OUT: Error message (if any)
If true, skip the first field
Open and close a Pager connection.
Jump here if the row had already been deleted before any BEFORE
** trigger programs were invoked. Or if a trigger program throws a
** RAISE(IGNORE) exception.
If the useJournal flag is clear, the journal-mode must be "OFF".
** And if the journal-mode is "OFF", the journal file must not be open.
P4 is a pointer to a KeyInfo structure
comment:
** GENERATED CODE ENDS HERE (mkportersteps.tcl)
***************************************************************************
*************************************************************************
label: code-design
** Clear any existing type flags from a Mem and replace them with f
Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode"
comment: copy max significant digits to significand
label: code-design
comment: Extra argument
label: code-design
OUT: Size of root node in bytes
** Do some work towards applying the RBU update to the target db.
**
** Return SQLITE_DONE if the update has been completely applied, or
** SQLITE_OK if no error occurs but there remains work to do to apply
** the RBU update. If an error does occur, some other error code is
** returned.
**
** Once a call to sqlite3rbu_step() has returned a value other than
** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
** that immediately return the same value.
Available for future enhancements
The USING clause of a join
Allocate a VDBE
************* Continuing where we left off in os_unix.c *******************
139
Description of segment
** Adjust the cost C by the costMult facter T. This only occurs if
** compiled with -DSQLITE_ENABLE_COSTMULT
For tracing shifts, the names of all terminals and nonterminals
** are required. The following table supplies these names
Number of work-quanta to perform
One (or both) of the named databases did not exist or an OOM
** error was hit. Or there is a transaction open on the destination
** database. The error has already been written into the pDestDb
** handle. All that is left to do here is free the sqlite3_backup
** structure.
The left part of the FROM clause already seen
Used to iterate through changes
510
A buffer to hold the magic header
No more than 1GiB per allocation
************* Begin file msvc.h *******************************************
66
Name of database session is attached to
** Helper type used by fts3EvalIncrPhraseNext() and incrPhraseTokenNext().
Number of expressions on the list
Statement to bind value to
if decimal point is present
Recursively resolve names in all subqueries
Index level just updated
** Return the value of a system call. Return NULL if zName is not a
** recognized system call name. NULL is also returned if the system call
** is currently undefined.
amalgamator: dontcache
Last frame in log
Height of this node in tree
OUT: New tokenizer handle
Separate file holding temporary table
1510
case_operand ::=
True if sqlite3_free(idxStr) is needed
Like SRT_Queue, but unique results only
Pointer to buffer to copy data from
Prerequesites of pExpr
111
comment: The sqlite3P2Values() routine is able to run faster if it knows
** the value of the largest JUMP opcode. The smaller the maximum
** JUMP opcode the better, so the mkopcodeh.tcl script that
** generated this include file strives to group all JUMP opcodes
** together near the beginning of the list.
label: code-design
The next block of code is equivalent to:
**
** pIter += getVarint32(pIter, nPayload);
**
** The code is inlined to avoid a function call.
** Retry the changes accumulated in the pApply->constraints buffer.
comment: Take steps to avoid spinning forever if there is a protocol error.
**
** Circumstances that cause a RETRY should only last for the briefest
** instances of time. No I/O or other system calls are done while the
** locks are held, so the locks should not be held for very long. But
** if we are unlucky, another process that is holding a lock might get
** paged out or take a page-fault that is time-consuming to resolve,
** during the few nanoseconds that it is holding the lock. In that case,
** it might take longer than normal for the lock to free.
**
** After 5 RETRYs, we begin calling sqlite3OsSleep(). The first few
** calls to sqlite3OsSleep() have a delay of 1 microsecond. Really this
** is more of a scheduler yield than an actual delay. But on the 10th
** an subsequent retries, the delays start becoming longer and longer,
** so that on the 100th (and last) RETRY we delay for 323 milliseconds.
** The total delay time before giving up is less than 10 seconds.
label: code-design
************* End of btree.c **********************************************
** If an error has already occurred when this function is called, it
** immediately returns zero (without doing any work). Or, if an error
** occurs during the execution of this function, it sets the error code
** in the sqlite3rbu object indicated by the first argument and returns
** zero.
**
** The iterator passed as the second argument is guaranteed to point to
** a table (not an index) when this function is called. This function
** attempts to create any imposter table required to write to the main
** table b-tree of the table before returning. Non-zero is returned if
** an imposter table are created, or zero otherwise.
**
** An imposter table is required in all cases except RBU_PK_VTAB. Only
** virtual tables are written to directly. The imposter table has the
** same schema as the actual target table (less any UNIQUE constraints).
** More precisely, the "same schema" means the same columns, types,
** collation sequences. For tables that do not have an external PRIMARY
** KEY, it also means the same PRIMARY KEY declaration.
Current leaf data
** Discard the contents of the cache.
If non-zero, last token to include
** Overwrite cell iCell of node pNode with the contents of pCell.
comment:
** Under certain circumstances, b-tree nodes (doclists) can be loaded into
** memory incrementally instead of all at once. This can be a big performance
** win (reduced IO and CPU) if SQLite stops calling the virtual table xNext()
** method before retrieving all query results (as may happen, for example,
** if a query has a LIMIT clause).
**
** Incremental loading is used for b-tree nodes FTS3_NODE_CHUNK_THRESHOLD
** bytes and larger. Nodes are loaded in chunks of FTS3_NODE_CHUNKSIZE bytes.
** The code is written so that the hard lower-limit for each of these values
** is 1. Clearly such small values would be inefficient, but can be useful
** for testing purposes.
**
** If this module is built with SQLITE_TEST defined, these constants may
** be overridden at runtime for testing purposes. File fts3_test.c contains
** a Tcl interface to read and write the values.
label: code-design
Result of strlen(zDb)
** Create the shadow table named zPost, with definition zDefn. Return
** SQLITE_OK if successful, or an SQLite error code otherwise.
** Convert pMem to type integer. Invalidate any prior representations.
If we get this far, it means we need to compute the table names.
** Note that the call to sqlite3ResultSetOfSelect() will expand any
** "*" elements in the results set of the view and will assign cursors
** to the elements of the FROM clause. But we do not want these changes
** to be permanent. So the computation is done on a copy of the SELECT
** statement that defines the view.
cmd ::= DROP TABLE ifexists fullname
Because sqlite3_value_double() returns 0.0 if the argument is not
** something that can be converted into a number, we have:
** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
** that cannot be converted to a numeric value.
Destructor for the codec
** Return a pointer to the WalCkptInfo structure in the wal-index.
** Sleep for a little while. Return the amount of time slept.
xNextSystemCall
Data type mismatch
Jump to label "D"
List of Table objects to delete after code gen
Call this routine when reloading pages
Where to write new cell content in data[]
6x
** This function may only be called while a write-transaction is active in
** rollback. If the connection is in WAL mode, this call is a no-op.
** Otherwise, if the connection does not already have an EXCLUSIVE lock on
** the database file, an attempt is made to obtain one.
**
** If the EXCLUSIVE lock is already held or the attempt to obtain it is
** successful, or the connection is in WAL mode, SQLITE_OK is returned.
** Otherwise, either SQLITE_BUSY or an SQLITE_IOERR_XXX error code is
** returned.
Number of bytes in current position list
Use the entire master
The column on the LHS of the term. -1 for IPK
Table being renamed
jump, in1, in3
** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
Value for 'idx' column of %_segdir
phrase ::= phrase PLUS STRING star_opt
pAux passed to create_module()
** Create a new tokenizer instance.
Record to read varints from
** An instance of this object describes where to put of the results of
** a SELECT statement.
Segment-reader for this token
index of next token to be returned
Number of columns in stat4 records
Size of azConfig[]
Second callback for SELECTs
End of cell-pointer array
Must be power of 2
Bytes of payload on final overflow page
a: p0<<28 | p2<<14 | p4 (unmasked)
pPager->pFirstSynced = 0;
Which entry in pAggInfo->aCol[] or ->aFunc[]
Complete text of the cell
Size of aOp array
Width of the current field
Count the total number of references to pOuterNC and all of its
** parent contexts. After resolving references to expressions in
** pItem->pSelect, check if this value has changed. If so, then
** SELECT statement pItem->pSelect must be correlated. Set the
** pItem->fg.isCorrelated flag if this is the case.
Index of last valid frame in the WAL
comment: TODO(shess) current implementation requires pInput to be
** nul-terminated. This should either be fixed, or pInput/nBytes
** should be converted to zInput.
label: code-design
fts3_tokenize_vtab.c
This is always a CONSTRAINT conflict.
Fewer features
Max length of an SQL string
A-vs-B comparision jump
Add the PK key for this row to the temporary table
Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL
Notice that even thought SF_Distinct has been cleared from p->selFlags,
** the sDistinct.isTnct is still set. Hence, isTnct represents the
** original setting of the SF_Distinct flag, not the current setting
Address of the output-A subroutine
return value form SQLITE_FCNTL_PRAGMA
At this point pParent may have at most one overflow cell. And if
** this overflow cell is present, it must be the cell with
** index iParentIdx. This scenario comes about when this function
** is called (indirectly) from sqlite3BtreeDelete().
Remove pPage from dirty list
** CAPI3REF: 64-Bit Integer Types
** KEYWORDS: sqlite_int64 sqlite_uint64
**
** Because there is no cross-platform way to specify 64-bit integer types
** SQLite includes typedefs for 64-bit signed and unsigned integers.
**
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
** compatibility only.
**
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
** sqlite3_uint64 and sqlite_uint64 types can store integer values
** between 0 and +18446744073709551615 inclusive.
True if there is an INDEXED BY clause
create a copy of the lock path _only_ if the conch is taken
Boolean. True if locking_mode==EXCLUSIVE
32
Releasing a reader lock or an exclusive lock
Dx
Set to true after xInput finished
IcuCursor.aChar[]
Source pager
Delete the %_docsize record
Another thread is (in the process of) initializing the static
** mutexes
WITH clause attached to this select. Or NULL.
The virtual machine under construction
Opcode: Expire P1 * * * *
**
** Cause precompiled statements to expire. When an expired statement
** is executed using sqlite3_step() it will either automatically
** reprepare itself (if it was originally created using sqlite3_prepare_v2())
** or it will fail with SQLITE_SCHEMA.
**
** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
** then only the currently executing statement is expired.
Size of zAppend in bytes (or -1)
Index of cell to delete
** Argument pTerm must be a synonym iterator. Return the current rowid
** that it points to.
28..2f ()*+,-./
** Obtain a patchset object containing all changes recorded by the
** session object passed as the first argument.
**
** It is the responsibility of the caller to eventually free the buffer
** using sqlite3_free().
File format to use for encoding
If the buffer is now larger than SESSIONS_STRM_CHUNK_SIZE, pass
** its contents to the xOutput() callback.
Bind the new.* PRIMARY KEY values to the SELECT statement.
** Convert zDate into one or more integers according to the conversion
** specifier zFormat.
**
** zFormat[] contains 4 characters for each integer converted, except for
** the last integer which is specified by three characters. The meaning
** of a four-character format specifiers ABCD is:
**
** A: number of digits to convert. Always "2" or "4".
** B: minimum value. Always "0" or "1".
** C: maximum value, decoded as:
** a: 12
** b: 14
** c: 24
** d: 31
** e: 59
** f: 9999
** D: the separator character, or \000 to indicate this is the
** last number to convert.
**
** Example: To translate an ISO-8601 date YYYY-MM-DD, the format would
** be "40f-21a-20c". The "40f-" indicates the 4-digit year followed by "-".
** The "21a-" indicates the 2-digit month followed by "-". The "20c" indicates
** the 2-digit day which is the last integer in the set.
**
** The function returns the number of successful conversions.
** The xConnect() and xCreate() methods for the virtual table. All the
** work is done in function fts5InitVtab().
Number of tables to check. (Number of root pages.)
1: (end_constraints && !bRev && endEq)
Number of arguments. -1 means any number
** Create a session object. This session object will record changes to
** database zDb attached to connection db.
'+' or ' ' or 0 for prefix
RBU object
Current 'rowid' value
flag ASCII delimiters
Normalize realvalue to within 10.0 > realvalue >= 1.0
** Return true if the Btree passed as the only argument is sharable.
Used when p4type is P4_COLLSEQ
If an AS-name match is found, mark this ORDER BY column as being
** a copy of the iCol-th result-set column. The subsequent call to
** sqlite3ResolveOrderGroupBy() will convert the expression to a
** copy of the iCol-th result-set expression.
Column index
Checked before the virtual table is created
Size of zToken in bytes
IMP: R-04300-56712
Omit children but continue walking siblings
Check if the cursor is past the end of the docid range specified
** by Fts3Cursor.iMinDocid/iMaxDocid. If so, set the EOF flag.
dbSize before the current transaction
Update the pager's copy of the change-counter. Otherwise, the
** next time a read transaction is opened the cache will be
** flushed (as the change-counter values will not match).
Check that the array is in order and contains no duplicate entries.
The current doclist-index page is full. Write it to disk and push
** a copy of iRowid (which will become the first rowid on the next
** doclist-index leaf page) up into the next level of the b-tree
** hierarchy. If the node being flushed is currently the root node,
** also push its first rowid upwards.
The first element of the array
Detect a pid change and reset the PRNG. There is a race condition
** here such that two or more threads all trying to open databases at
** the same instant might all reset the PRNG. But multiple resets
** are harmless.
Record to decode
SQLITE_BTREE_H
Jump here to skip excluded rows
** Make sure all writes to a particular file are committed to disk.
An exclusive process lock is held
************* Begin file wal.c ********************************************
Docid to bind for SQL_SELECT_DOCSIZE
If the column is declared as "<name> PRIMARY KEY COLLATE <type>",
** then an index may have been created on this column before the
** collation type was added. Correct this if it is the case.
Opcode: SeekLE P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as a key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the largest entry that
** is less than or equal to the key value. If there are no records
** less than or equal to the key and P2 is not zero, then jump to P2.
**
** This opcode leaves the cursor configured to move in reverse order,
** from the end toward the beginning. In other words, the cursor is
** configured to use Prev, not Next.
**
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
** opcode will always land on a record that equally equals the key, or
** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this
** opcode must be followed by an IdxGE opcode with the same arguments.
** The IdxGE opcode will be skipped if this opcode succeeds, but the
** IdxGE opcode will be used on subsequent loop iterations.
**
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
** This function is called at the start of every write transaction.
** There must already be a RESERVED or EXCLUSIVE lock on the database
** file when this routine is called.
**
** Open the journal file for pager pPager and write a journal header
** to the start of it. If there are active savepoints, open the sub-journal
** as well. This function is only used when the journal file is being
** opened to write a rollback log for a transaction. It is not used
** when opening a hot journal file to roll it back.
**
** If the journal file is already open (as it may be in exclusive mode),
** then this function just writes a journal header to the start of the
** already open file.
**
** Whether or not the journal file is opened by this function, the
** Pager.pInJournal bitvec structure is allocated.
**
** Return SQLITE_OK if everything is successful. Otherwise, return
** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
** an IO error code if opening or writing the journal file fails.
Sector-size field of journal header
** CAPI3REF: Checkpoint Mode Values
** KEYWORDS: {checkpoint mode}
**
** These constants define all valid values for the "checkpoint mode" passed
** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
** meaning of each of these checkpoint modes.
Forward declaration required by incrVacuumStep().
# include <pthread.h>
CONTENT
Pointer to the end of the last xRead()
** Call this routine when the database connection is closing in order
** to clean up loaded extensions
The expression list to be analyzed.
!defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
ccons ::= CONSTRAINT nm
Number of PtrMap pages to be freed
Address of loop counter
For hash-table collisions
First (only) step of trigger program
Strings with '\'' doubled and enclosed in '',
NULL pointers replaced by SQL NULL. %Q
210
Number of fields in the record
Cursor opened by OpenSorter (if in use)
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used by the compiler to add foreign key
** support to compiled SQL statements.
pMethod
Includes the ALL keyword
** Like free() but works for allocations obtained from sqlite3MemMalloc()
** or sqlite3MemRealloc().
**
** For this low-level routine, we already know that pPrior!=0 since
** cases where pPrior==0 will have been intecepted and dealt with
** by higher-level routines.
Next unparsed byte of the header
Parse context to store any error in
Object used to write leaf nodes
Resolve the expressions in the LIMIT and OFFSET clauses. These
** are not allowed to refer to any names, so pass an empty NameContext.
******** End destructor definitions ****************************************
Page number of the page to check
End the virtual table scan
Notify of page size changes
IN/OUT: Mask of phrases seen
** Get or set the "averages" values.
synopsis: if key(P1)!=trim(r[P3],P4) goto P2
Each entry in the following array defines a rule for folding a range
** of codepoints to lower case. The rule applies to a range of nRange
** codepoints starting at codepoint iCode.
**
** If the least significant bit in flags is clear, then the rule applies
** to all nRange codepoints (i.e. all nRange codepoints are upper case and
** need to be folded). Or, if it is set, then the rule only applies to
** every second codepoint in the range, starting with codepoint C.
**
** The 7 most significant bits in flags are an index into the aiOff[]
** array. If a specific codepoint C does require folding, then its lower
** case equivalent is ((C + aiOff[flags>>1]) & 0xFFFF).
**
** The contents of this array are generated by parsing the CaseFolding.txt
** file distributed as part of the "Unicode Character Database". See
** http://www.unicode.org for details.
** Implementation of the sqlite3_pcache.xCachesize method.
**
** Configure the cache_size limit for a cache.
Address of the end of the query
comment: Size of malloc'd buffer at zMalloc
label: code-design
comment:
** 2010 July 12
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains an implementation of the "dbstat" virtual table.
**
** The dbstat virtual table is used to extract low-level formatting
** information from an SQLite database in order to implement the
** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
** for an example implementation.
**
** Additional information is available on the "dbstat.html" page of the
** official SQLite documentation.
label: code-design
** pNew and pOld are both candidate non-periodic samples selected for
** the same column (pNew->iCol==pOld->iCol). Ignoring this column and
** considering only any trailing columns and the sample hash value, this
** function returns true if sample pNew is to be preferred over pOld.
** In other words, if we assume that the cardinalities of the selected
** column for pNew and pOld are equal, is pNew to be preferred over pOld.
**
** This function assumes that for each argument sample, the contents of
** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid.
Average nEq values for keys not in aSample
** Determine if we are dealing with Windows NT.
**
** We ought to be able to determine if we are compiling for Windows 9x or
** Windows NT using the _WIN32_WINNT macro as follows:
**
** #if defined(_WIN32_WINNT)
** # define SQLITE_OS_WINNT 1
** #else
** # define SQLITE_OS_WINNT 0
** #endif
**
** However, Visual Studio 2005 does not set _WIN32_WINNT by default, as
** it ought to, so the above test does not work. We'll just assume that
** everything is Windows NT unless the programmer explicitly says otherwise
** by setting SQLITE_OS_WINNT to 0.
lastErrno set by seekAndWrite
pLogArg
Page cache buffer management:
** These routines implement SQLITE_CONFIG_PAGECACHE.
The number of integers to encode
synopsis: r[P2]=count()
If existing WhereLoop p is better than pTemplate, pTemplate can be
** discarded. WhereLoop p is better if:
** (1) p has no more dependencies than pTemplate, and
** (2) p has an equal or lower cost than pTemplate
Offset of first term on leaf
Session object
Frame number corresponding to aPgno[0]
Power of two >= nSeg
IN/OUT: Current structure of index
IN/OUT: Value read from position-list
ASC => ID
comment: Temporary space used to build header
label: code-design
comment: Counter to prevent infinite loop of reprepares
label: code-design
Mask of affinity bits
** This function is used to process a single interior node when searching
** a b-tree for a term or term prefix. The node data is passed to this
** function via the zNode/nNode parameters. The term to search for is
** passed in zTerm/nTerm.
**
** If piFirst is not NULL, then this function sets *piFirst to the blockid
** of the child node that heads the sub-tree that may contain the term.
**
** If piLast is not NULL, then *piLast is set to the right-most child node
** that heads a sub-tree that may contain a term for which zTerm/nTerm is
** a prefix.
**
** If an OOM error occurs, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK.
** Insert or remove data to or from the index. Each time a document is
** added to or removed from the index, this function is called one or more
** times.
**
** For an insert, it must be called once for each token in the new document.
** If the operation is a delete, it must be called (at least) once for each
** unique token in the document with an iCol value less than zero. The iPos
** argument is ignored for a delete.
Unless it is empty, flush the hash table to disk
** Free the iterator object passed as the second argument.
Copy over the row data
IMP: R-42790-23372
Length of the parameter token
Term to write to internal node
Max args passed to user function by sub-program
Bytes of space for iSerial as varint
Reusable bulk memory
Register holding max rowid
Result from sqlite3Step()
PLAN => ID
** The two values that may be meaningfully bound to the :1 parameter in
** statements SQL_REPLACE_STAT and SQL_SELECT_STAT.
Size of zStr
True when updating a view (INSTEAD OF trigger)
** These #defines should enable >2GB file support on POSIX if the
** underlying operating system supports it. If the OS lacks
** large file support, or if the OS is windows, these should be no-ops.
**
** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any
** system #includes. Hence, this block of code must be the very first
** code in all source files.
**
** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch
** on the compiler command line. This is necessary if you are compiling
** on a recent machine (ex: Red Hat 7.2) but you want your code to work
** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2
** without this option, LFS is enable. But LFS does not exist in the kernel
** in Red Hat 6.0, so the code won't work. Hence, for maximum binary
** portability you should omit LFS.
**
** The previous paragraph was written in 2005. (This paragraph is written
** on 2008-11-28.) These days, all Linux kernels support large files, so
** you should probably leave LFS enabled. But some embedded platforms might
** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful.
**
** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later.
** Add a new subitem to the tree. The moreToFollow flag indicates that this
** is not the last item in the tree.
Freeblock not in ascending order
** Macros for looping over all elements of a hash table. The idiom is
** like this:
**
** Fts3Hash h;
** Fts3HashElem *p;
** ...
** for(p=fts3HashFirst(&h); p; p=fts3HashNext(p)){
** SomeStructure *pData = fts3HashData(p);
** // do something with pData
** }
Undo any changes made by applyAffinity() to the input registers.
** Return a list of N comma separated question marks, where N is the number
** of columns in the %_content table (one for the docid plus one for each
** user-defined text column).
**
** If argument zFunc is not NULL, then all but the first question mark
** is preceded by zFunc and an open bracket, and followed by a closed
** bracket. For example, if zFunc is "zip" and the FTS3 table has three
** user-defined text columns, the following string is returned:
**
** "?, zip(?), zip(?), zip(?)"
**
** The pointer returned points to a buffer allocated by sqlite3_malloc(). It
** is the responsibility of the caller to eventually free it.
**
** If *pRc is not SQLITE_OK when this function is called, it is a no-op (and
** a NULL pointer is returned). Otherwise, if an OOM error is encountered
** by this function, NULL is returned and *pRc is set to SQLITE_NOMEM. If
** no error occurs, *pRc is left unmodified.
If the statement completed successfully, invoke the profile callback
Straight index lookup
The column containing the blob
IN/OUT: SegmentNode handle
OUT: Return data in this Mem structure.
In the current implementation, the rSetup value is either zero
** or the cost of building an automatic index (NlogN) and the NlogN
** is the same for compatible WhereLoops.
pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
** of columns. If each indexed column corresponds to a foreign key
** column of pFKey, then this index is a winner.
OE_Rollback etc.
This is likely to be an append
** Determine the current size of a file in bytes
Value returned by last rbu_step() call
Bytes of memory space allocated for Vdbe.aOp[]
Begin generating the code that will insert the table record into
** the SQLITE_MASTER table. Note in particular that we must go ahead
** and allocate the record number for the table entry now. Before any
** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
** indices to be created and the table record must come before the
** indices. Hence, the record number for the table must be allocated
** now.
comment:
** Mark all temporary registers as being unavailable for reuse.
label: code-design
Value for "idx" field
IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as
** SQLITE_CHECKPOINT_RESTART with the addition that it also
** truncates the log file to zero bytes just prior to a
** successful return.
**
** In theory, it might be safe to do this without updating the
** wal-index header in shared memory, as all subsequent reader or
** writer clients should see that the entire log file has been
** checkpointed and behave accordingly. This seems unsafe though,
** as it would leave the system in a state where the contents of
** the wal-index header do not match the contents of the
** file-system. To avoid this, update the wal-index header to
** indicate that the log file contains zero valid frames.
Attach the temporary database as 'vacuum_db'. The synchronous pragma
** can be set to 'off' for this file, as it is not recovered if a crash
** occurs anyway. The integrity of the database is maintained by a
** (possibly synchronous) transaction opened on the main database before
** sqlite3BtreeCopyFile() is called.
**
** An optimisation would be to use a non-journaled pager.
** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
** that actually made the VACUUM run slower. Very little journalling
** actually occurs when doing a vacuum since the vacuum_db is initially
** empty. Only the journal header is written. Apparently it takes more
** time to parse and run the PRAGMA to turn journalling off than it does
** to write the journal header file.
New array of Db pointers
Append data to the wal-index. It is not necessary to lock the
** wal-index to do this as the SQLITE_SHM_WRITE lock held on the wal-index
** guarantees that there are no other writers, and no data that may
** be in use by existing readers is being overwritten.
** Implementation of the changes() SQL function.
**
** IMP: R-62073-11209 The changes() SQL function is a wrapper
** around the sqlite3_changes() C/C++ function and hence follows the same
** rules for counting changes.
Input stream call (or NULL)
** This function is called after a transaction has been committed. It
** invokes callbacks registered with sqlite3_wal_hook() as required.
File descriptor for database pTo
OUT: Bytes in returned value
** Return the full pathname of the journal file.
Affinity string to modify
** Generate code into the current Vdbe to evaluate the given
** expression. Attempt to store the results in register "target".
** Return the register where results are stored.
**
** With this routine, there is no guarantee that results will
** be stored in target. The result might be stored in some other
** register if it is convenient to do so. The calling function
** must check the return code and move the results to the desired
** register.
Content
This is only called if it is guaranteed that the phrase has at least
** one incremental token. In which case the bIncr flag is set.
comment:
** CAPI3REF: Mutex Methods Object
**
** An instance of this structure defines the low-level routines
** used to allocate and use mutexes.
**
** Usually, the default mutex implementations provided by SQLite are
** sufficient, however the application has the option of substituting a custom
** implementation for specialized deployments or systems for which SQLite
** does not provide a suitable implementation. In this case, the application
** creates and populates an instance of this structure to pass
** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
** Additionally, an instance of this structure can be used as an
** output variable when querying the system for the current mutex
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
**
** ^The xMutexInit method defined by this structure is invoked as
** part of system initialization by the sqlite3_initialize() function.
** ^The xMutexInit routine is called by SQLite exactly once for each
** effective call to [sqlite3_initialize()].
**
** ^The xMutexEnd method defined by this structure is invoked as
** part of system shutdown by the sqlite3_shutdown() function. The
** implementation of this method is expected to release all outstanding
** resources obtained by the mutex methods implementation, especially
** those obtained by the xMutexInit method. ^The xMutexEnd()
** interface is invoked exactly once for each call to [sqlite3_shutdown()].
**
** ^(The remaining seven methods defined by this structure (xMutexAlloc,
** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
** xMutexNotheld) implement the following interfaces (respectively):
**
** <ul>
** <li> [sqlite3_mutex_alloc()] </li>
** <li> [sqlite3_mutex_free()] </li>
** <li> [sqlite3_mutex_enter()] </li>
** <li> [sqlite3_mutex_try()] </li>
** <li> [sqlite3_mutex_leave()] </li>
** <li> [sqlite3_mutex_held()] </li>
** <li> [sqlite3_mutex_notheld()] </li>
** </ul>)^
**
** The only difference is that the public sqlite3_XXX functions enumerated
** above silently ignore any invocations that pass a NULL pointer instead
** of a valid mutex handle. The implementations of the methods defined
** by this structure are not required to handle this case, the results
** of passing a NULL pointer instead of a valid mutex handle are undefined
** (i.e. it is acceptable to provide an implementation that segfaults if
** it is passed a NULL pointer).
**
** The xMutexInit() method must be threadsafe. It must be harmless to
** invoke xMutexInit() multiple times within the same process and without
** intervening calls to xMutexEnd(). Second and subsequent calls to
** xMutexInit() must be no-ops.
**
** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
** memory allocation for a fast or recursive mutex.
**
** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
** called, but only if the prior call to xMutexInit returned SQLITE_OK.
** If xMutexInit fails in any way, it is expected to clean up after itself
** prior to returning.
label: code-design
Variable used as the phrase counter
Number of backends currently in use
End of the loop over all rowids/primary-keys.
jump
Change to WRITER_LOCKED state.
**
** WAL mode sets Pager.eState to PAGER_WRITER_LOCKED or CACHEMOD
** when it has an open transaction, but never to DBMOD or FINISHED.
** This is because in those states the code to roll back savepoint
** transactions may copy data from the sub-journal into the database
** file as well as into the page cache. Which would be incorrect in
** WAL mode.
Check if the iterator is now at EOF. If so, return early.
src table col -> target table col
** The second argument points to an FKey object representing a foreign key
** for which pTab is the parent table. An UPDATE statement against pTab
** is currently being processed. For each column of the table that is
** actually updated, the corresponding element in the aChange[] array
** is zero or greater (if a column is unmodified the corresponding element
** is set to -1). If the rowid column is modified by the UPDATE statement
** the bChngRowid argument is non-zero.
**
** This function returns true if any of the columns that are part of the
** parent key for FK constraint *p are modified.
Some views have defined column names
** Fts5SegIter.iLeafOffset currently points to the first byte of the
** "nSuffix" field of a term. Function parameter nKeep contains the value
** of the "nPrefix" field (if there was one - it is passed 0 if this is
** the first term in the segment).
**
** This function populates:
**
** Fts5SegIter.term
** Fts5SegIter.rowid
**
** accordingly and leaves (Fts5SegIter.iLeafOffset) set to the content of
** the first position list. The position list belonging to document
** (Fts5SegIter.iRowid).
** Something has moved cursor "p" out of place. Maybe the row it was
** pointed to was deleted out from under it. Or maybe the btree was
** rebalanced. Whatever the cause, try to restore "p" to the place it
** is supposed to be pointing. If the row was deleted out from under the
** cursor, set the cursor to point to a NULL row.
Name of the file being opened
The pager cache has created a new page. Its content needs to
** be initialized. But first some error checks:
**
** (1) The maximum page number is 2^31
** (2) Never try to fetch the locking page
** Store the union of cells p1 and p2 in p1.
** Parse a complete JSON string. Return 0 on success or non-zero if there
** are any errors. If an error occurs, free all memory associated with
** pParse.
**
** pParse is uninitialized when this routine is called.
Building a VDBE program
Statement for reading and writing
The special 'table-name' column
fts5YYWILDCARD
Index of root in pWriter->aNodeWriter
1 for tables and indices to be opened
Obtain pointers to the hash-table and page-number array containing
** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
** that the page said hash-table and array reside on is already mapped.
The following calls to preupdate_new() and preupdate_old() can not
** fail. This is because they cache their return values, and by the
** time control flows to here they have already been called once from
** within sessionPreupdateHash(). The first two asserts below verify
** this (that the method has already been called).
The new entry
Right hand serial type
97
Pointer to an array of results
Base register holding constraint values
OUT: Inverse of pChangeset
If filePath==NULL that means we are dealing with a transient file
** that does not need to be locked.
The definition of this CTE
EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
** additional varints, one per column.
Information about the function
OUT: Set to true if row really does exist
P4 is a pointer to BtreeNext() or BtreePrev()
EXCEPT
Zero from this point onwards on cursor reset
Don't allow access, but don't generate an error
Begin a transaction for database iDb.
** Then modify the schema cookie (since the ALTER TABLE modifies the
** schema). Open a statement transaction if the table is a virtual
** table.
only 1 core, use our own zone to contention over global locks,
** e.g. we have our own dedicated locks
Space for aKey if aBuffer and pMap wont work
op2 value for LIKE/REGEXP/GLOB
True if this op is a delete
Sorter cursor to read from
Name of rank function
Cursor to table into which insert is written
** Shutdown the mutex system. This call frees resources allocated by
** sqlite3MutexInit().
** Return the rowid that the cursor currently points to.
Cursor of the RHS table
** Maximum pathname length (in chars) for WinNT. This should normally be
** UNICODE_STRING_MAX_CHARS.
Value for the stat column of sqlite_stat1
Store the results of the setup-query in Queue.
** Change the values for the BTS_SECURE_DELETE and BTS_OVERWRITE flags:
**
** newFlag==0 Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
** newFlag==1 BTS_SECURE_DELETE set and BTS_OVERWRITE is cleared
** newFlag==2 BTS_SECURE_DELETE cleared and BTS_OVERWRITE is set
** newFlag==(-1) No changes
**
** This routine acts as a query if newFlag is less than zero
**
** With BTS_OVERWRITE set, deleted content is overwritten by zeros, but
** freelist leaf pages are not written back to the database. Thus in-page
** deleted content is cleared, but freelist deleted content is not.
**
** With BTS_SECURE_DELETE, operation is like BTS_OVERWRITE with the addition
** that freelist leaf pages are written back into the database, increasing
** the amount of disk I/O.
Value to return for s3_vtab_on_conflict()
Database in which the table lives
Map from pIdx cols to child table cols
The direct assignment in the previous line is possible only because
** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
** following asserts verify this fact.
Continue down into children
xRowid
************* End of ctime.c **********************************************
True if iRoot is the root of an index b-tree
By convertCompoundSelectToSubquery()
Top of the update loop
Size of allocated array at aElem
** Implementation of the like() SQL function. This function implements
** the build-in LIKE operator. The first argument to the function is the
** pattern and the second argument is the string. So, the SQL statements:
**
** A LIKE B
**
** is implemented as like(B, A). If there is an escape character E,
**
** A LIKE B ESCAPE E
**
** is mapped to like(B, A, E).
xSqllog, void*
onconf ::=
************* Begin file vdbeInt.h ****************************************
Parameters to bind
Used to iterate from pExpr to root
Current position
Invalid key size: 0x80 0x80 0x00
Translator union
Really a cast to BLOB
INITIALLY => ID
End of the overrideable system calls
Name of r-tree table
** Register a new geometry function for use with the r-tree MATCH operator.
comment:
** This function is called after the contents of page iPage of the
** source database have been modified. If page iPage has already been
** copied into the destination database, then the data written to the
** destination is now invalidated. The destination copy of iPage needs
** to be updated with the new data before the backup operation is
** complete.
**
** It is assumed that the mutex associated with the BtShared object
** corresponding to the source database is held when this function is
** called.
label: code-design
** Free an RbuState object allocated by rbuLoadState().
Allocate cursors for Current, Queue, and Distinct.
String to return via *pzImposterCols
Copy of p->aOp
Compute only a unique prefix of the key
Max iDivisor is max(u32) / BITVEC_NPTR + 1.
** Allocate and populate an sqlite3_index_info structure. It is the
** responsibility of the caller to eventually release the structure
** by passing the pointer returned by this function to sqlite3_free().
Rowid compenents
languageid=? parameter (or NULL)
Mark off any other ORDER BY terms that reference pLoop
if( !pIncr->bUseThread )
xDelete
** Join thread pTask->thread.
SQLITE_OMIT_OR_OPTIMIZATION
** This function determines if the machine is running a version of Windows
** based on the NT kernel.
** The first element in the apVal[] array is assumed to contain the docid
** (an integer) of a row about to be deleted. Remove all terms from the
** full-text index.
************* End of bitvec.c *********************************************
Different number of columns
219
Maximum local payload in non-LEAFDATA tables
Previously generated index key
aKWHash[i] is the hash value for the i-th keyword
Pointer to function information
Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
** expression it is handled the same way. An ephemeral table is
** filled with index keys representing the results from the
** SELECT or the <exprlist>.
**
** If the 'x' expression is a column value, or the SELECT...
** statement returns a column value, then the affinity of that
** column is used to build the index keys. If both 'x' and the
** SELECT... statement are columns, then numeric affinity is used
** if either column has NUMERIC or INTEGER affinity. If neither
** 'x' nor the SELECT... statement are columns, then numeric affinity
** is used.
OUT: New virtual table
** 2001 September 16
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file (together with is companion C source-code file
** "os.c") attempt to abstract the underlying operating system so that
** the SQLite library will work on both POSIX and windows systems.
**
** This header file is #include-ed by sqliteInt.h and thus ends up
** being included by every source file.
new.* record for second change
************* Include hwtime.h in the middle of os_common.h ***************
No DISTINCT keyword and no aggregate functions
Buffer to assemble wal-header in
Size of buffer at aDoclist
************* End of os_common.h ******************************************
Slots allocated for azResult[]
Do not gather statistics on system tables
Update the count of rows that are inserted
** Load the next leaf page into the segment iterator.
** Write nBuf bytes of random data to the supplied buffer zBuf.
comment: Groupid for the file
label: code-design
** 2000-05-29
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Driver template for the LEMON parser generator.
**
** The "lemon" program processes an LALR(1) input grammar file, then uses
** this template to construct a parser. The "lemon" program inserts text
** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
** interstitial "-" characters) contained in this template is changed into
** the value of the %name directive from the grammar. Otherwise, the content
** of this template is copied straight through into the generate parser
** source file.
**
** The following is the concatenation of all %include directives from the
** input grammar file:
Label "L"
An instance of the SubstContext object describes an substitution edit
** to be performed on a parse tree.
**
** All references to columns in table iTable are to be replaced by corresponding
** expressions in pEList.
WITHOUT
Implements a UNIQUE constraint
** This function constructs and returns a pointer to a nul-terminated
** string containing some SQL clause or list based on one or more of the
** column names currently stored in the pIter->azTblCol[] array.
370
now an error
Refs more than one table
*************************** sqlite3_column_ *******************************
** The following routines are used to access elements of the current row
** in the result set.
Currently, Fts5SegIter.iLeafOffset points to the first byte of
** position-list content for the current rowid. Back it up so that it
** points to the start of the position-list size field.
pOrderBy is really a GROUP BY
** Allocate and return a pointer to a new sqlite3_value object. If
** the second argument to this function is NULL, the object is allocated
** by calling sqlite3ValueNew().
**
** Otherwise, if the second argument is non-zero, then this function is
** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
** already been allocated, allocate the UnpackedRecord structure that
** that function will return to its caller here. Then return a pointer to
** an sqlite3_value within the UnpackedRecord.a[] array.
Coroutine supplying data
Original value of pNew->u.btree.nBtm
** Change the key on an open database. If the current database is not
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
** database is decrypted.
**
** The code to implement this API is not available in the public release
** of SQLite.
** Estimate the number of rows that will be returned based on
** an equality constraint x=VALUE and where that VALUE occurs in
** the histogram data. This only works when x is the left-most
** column of an index and sqlite_stat3 histogram data is available
** for that index. When pExpr==NULL that means the constraint is
** "x IS NULL" instead of "x=VALUE".
**
** Write the estimated row count into *pnRow and return SQLITE_OK.
** If unable to make an estimate, leave *pnRow unchanged and return
** non-zero.
**
** This routine can fail if it is unable to load a collating sequence
** required for string comparison, or if unable to allocate memory
** for a UTF conversion required for comparison. The error is stored
** in the pParse structure.
SQLITE_OMIT_COMPOUND_SELECT
Copy Btree meta values
comment: The FROM clause term to get the next index
label: code-design
Figure out if this is a leaf or an internal node.
p is always 4-byte aligned
This index is a superset of the primary key
comment:
** The fts3 built-in tokenizers - "simple", "porter" and "icu"- are
** implemented in files fts3_tokenizer1.c, fts3_porter.c and fts3_icu.c
** respectively. The following three forward declarations are for functions
** declared in these files used to retrieve the respective implementations.
**
** Calling sqlite3Fts3SimpleTokenizerModule() sets the value pointed
** to by the argument to point to the "simple" tokenizer implementation.
** And so on.
label: code-design
comment: Not used
label: code-design
ORDER
** All unique filenames are held on a linked list headed by this
** variable:
Check for integer primary key out of range
Cursor pointing at blob row
** Generate code to return a single integer value.
The definition of the module
Wal frame containing data for iDbpage
Table triggers are being coded for
Page number in db file
Mask of all well-ordered loops
**** If we reach this point, flattening is permitted. ****
SQLITE_ENABLE_EXPENSIVE_ASSERT
xShmUnmap
** For each row modified during a session, there exists a single instance of
** this structure stored in a SessionTable.aChange[] hash table.
tokenizer for inserts and queries
************* Continuing where we left off in btmutex.c *******************
The database connection to which it belongs
Opcode: Blob P1 P2 * P4 *
** Synopsis: r[P2]=P4 (len=P1)
**
** P4 points to a blob of data P1 bytes long. Store this
** blob in register P2.
comment: Remove the redundant segments from the %_data table
label: code-design
Index of database holding TABLE
synopsis: P3 columns in r[P2]
Used to store transient return codes
Phrase expression node
SQLITE_OMIT_ATTACH
Extract a leaf from the trunk
Check that the trigger name is not reserved and that no trigger of the
** specified name exists
Callback
The backup process p has already copied page iPage. But now it
** has been modified by a transaction on the source pager. Copy
** the new data into the backup.
************* End of os_unix.c ********************************************
The initial database size
Bind values to the DELETE statement. If conflict handling is required,
** bind values for all columns and set bound variable (nCol+1) to true.
** Or, if conflict handling is not required, bind just the PK column
** values and, if it exists, set (nCol+1) to false. Conflict handling
** is not required if:
**
** * this is a patchset, or
** * (pbRetry==0), or
** * all columns of the table are PK columns (in this case there is
** no (nCol+1) variable to bind to).
comment:
** Backwards Compatibility Hack:
**
** Historical versions of SQLite accepted strings as column names in
** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
**
** CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
** CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
**
** This is goofy. But to preserve backwards compatibility we continue to
** accept it. This routine does the necessary conversion. It converts
** the expression given in its argument from a TK_STRING into a TK_ID
** if the expression is just a TK_STRING with an optional COLLATE clause.
** If the epxression is anything other than TK_STRING, the expression is
** unchanged.
label: code-design
No collation sequence of this type for this encoding is registered.
** Call the collation factory to see if it can supply us with one.
comment:
** 2015-06-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.
**
** This file was originally part of where.c but was split out to improve
** readability and editabiliity. This file contains utility routines for
** analyzing Expr objects in the WHERE clause.
label: code-design
The GetProcAddressA() routine is only available on Windows CE.
Integrity check context
The page that contains a pointer to pDbPage
comment:
** This function is exactly the same as sqlite3_create_function(), except
** that it is designed to be called by internal code. The difference is
** that if a malloc() fails in sqlite3_create_function(), an error code
** is returned and the mallocFailed flag cleared.
label: code-design
column number to retrieve
** Make sure the number of reserved bits is the same in the destination
** pager as it is in the source. This comes up when a VACUUM changes the
** number of reserved bits to the "optimal" amount.
(Phrases that will be loaded)^4.
comment:
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
label: code-design
Length of zDb in bytes
** 2001 September 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the implementation of generic hash-tables
** used in SQLite.
*********** Begin %parse_failure code **************************************
Columns to search (NULL -> all columns)
** Close a tokenization cursor previously opened by a call to
** porterOpen() above.
True (1) if iJD is valid
comment: Number of unused bytes on page
label: code-design
Leaf page (iLeafPgno+1)
REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT
** Mark all NULL entries in the Object passed in as JNODE_REMOVE.
BEGIN
** Invoke the pre-update hook. If this is an UPDATE or DELETE pre-update call,
** then cursor passed as the second argument should point to the row about
** to be update or deleted. If the application calls sqlite3_preupdate_old(),
** the required value will be read from the row the cursor points to.
** CAPI3REF: Status Parameters for database connections
** KEYWORDS: {SQLITE_DBSTATUS options}
**
** These constants are the available integer "verbs" that can be passed as
** the second argument to the [sqlite3_db_status()] interface.
**
** New verbs may be added in future releases of SQLite. Existing verbs
** might be discontinued. Applications should check the return code from
** [sqlite3_db_status()] to make sure that the call worked.
** The [sqlite3_db_status()] interface will return a non-zero error code
** if a discontinued or unsupported verb is invoked.
**
** <dl>
** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
** <dd>This parameter returns the number of lookaside memory slots currently
** checked out.</dd>)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
** <dd>This parameter returns the number malloc attempts that were
** satisfied using lookaside memory. Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
** <dd>This parameter returns the number malloc attempts that might have
** been satisfied using lookaside memory but failed due to the amount of
** memory requested being larger than the lookaside slot size.
** Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
** <dd>This parameter returns the number malloc attempts that might have
** been satisfied using lookaside memory but failed due to all lookaside
** memory already being in use.
** Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** memory used by all pager caches associated with the database connection.)^
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
**
** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
** pager cache is shared between two or more connections the bytes of heap
** memory used by that pager cache is divided evenly between the attached
** connections.)^ In other words, if none of the pager caches associated
** with the database connection are shared, this request returns the same
** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
** shared, the value returned by this call will be smaller than that returned
** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
**
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** memory used to store the schema for all databases associated
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
** ^The full amount of memory used by the schemas is reported, even if the
** schema memory is shared with other database connections due to
** [shared cache mode] being enabled.
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
**
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** and lookaside memory used by all prepared statements associated with
** the database connection.)^
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
** <dd>This parameter returns the number of pager cache hits that have
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
** is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
** <dd>This parameter returns the number of pager cache misses that have
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
** is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
** <dd>This parameter returns the number of dirty cache entries that have
** been written to disk. Specifically, the number of pages written to the
** wal file in wal mode databases, or the number of pages written to the
** database file in rollback mode databases. Any pages written as part of
** transaction rollback or database recovery operations are not included.
** If an IO or other error occurs while writing a page to disk, the effect
** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
** <dd>This parameter returns zero for the current value if and only if
** all foreign key constraints (deferred or immediate) have been
** resolved.)^ ^The highwater mark is always 0.
** </dd>
** </dl>
comment:
** Deallocate a register, making available for reuse for some other
** purpose.
**
** If a register is currently being used by the column cache, then
** the deallocation is deferred until the column cache line that uses
** the register becomes stale.
label: code-design
Query prefix
comment: The expression may actually be of the form (x, y) IN (SELECT...).
** In this case there is a separate term for each of (x) and (y).
** However, the nIn multiplier should only be applied once, not once
** for each such term. The following loop checks that pTerm is the
** first such term in use, and sets nIn back to 0 if it is not.
label: code-design
** Set an entry in the wal-index that will map database page number
** pPage into WAL frame iFrame.
Skip partial indices for which the WHERE clause is not true
** PRAGMA temp_store_directory
** PRAGMA temp_store_directory = ""|"directory_name"
**
** Return or set the local value of the temp_store_directory flag. Changing
** the value sets a specific directory to be used for temporary files.
** Setting to a null string reverts to the default temporary directory search.
** If temporary directory is changed, then invalidateTempStorage.
**
SQL function return value
Page-size field of journal header
Return the next entry on the list
comment: DISTINCT keyword not used
label: code-design
** This function is called before attempting a hot-journal rollback. It
** syncs the journal file to disk, then sets pPager->journalHdr to the
** size of the journal file so that the pager_playback() routine knows
** that the entire journal file has been synced.
**
** Syncing a hot-journal to disk before attempting to roll it back ensures
** that if a power-failure occurs during the rollback, the process that
** attempts rollback following system recovery sees the same journal
** content as this process.
**
** If everything goes as planned, SQLITE_OK is returned. Otherwise,
** an SQLite error code.
Write the new new.* record. Consists of a copy of all values
** from the original old.* record, except for the PK columns, which
** are set to "undefined".
Information for virtual tables
Bytes of leaf page data so far
The query under construction
** Allocate or deallocate a block of nReg consecutive registers.
comment: Verify that there is enough key space remaining to avoid
** a buffer overread. The "d1+serial_type1+2" subexpression will
** always be greater than or equal to the amount of required key space.
** Use that approximation to avoid the more expensive call to
** sqlite3VdbeSerialTypeLen() in the common case.
label: code-design
Implement a co-routine that will return a single row of the result
** set on each invocation.
Current state of incremental merge
NULL pBitvec tests
if( !pSorter->bUseThreads )
isMutexInit
FTS3 table snippet comes from
Thread will use this task object
** Return the current file-size of an rbuVfs-file.
New vdbe frame to execute in
Mutex to protect pMain
Pointer to aType[nField]
Malloc'd buffer to load entire frame
************* End of trigger.c ********************************************
** This routine is called when an INITIALLY IMMEDIATE or INITIALLY DEFERRED
** clause is seen as part of a foreign key definition. The isDeferred
** parameter is 1 for INITIALLY DEFERRED and 0 for INITIALLY IMMEDIATE.
** The behavior of the most recently created foreign key is adjusted
** accordingly.
Current index in apPage[i]
Array for converting from half-bytes (nybbles) into ASCII hex
** digits.
ifdef SQLITE_NO_SYNC elif HAVE_FULLFSYNC
Hash table key
Conversion buffer
Trash all content in the buffer being freed
comment:
** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
**
** This function should only be used with iterator objects passed to a
** conflict-handler callback by [sqlite3changeset_apply()] with either
** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
** is set to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the
** "conflicting row" associated with the current conflict-handler callback
** and returns SQLITE_OK.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
** Maximum pathname length (in bytes) for Win32. The MAX_PATH macro is in
** characters, so we allocate 4 bytes per character assuming worst-case of
** 4-bytes-per-character for UTF8.
Set nSum to the number of distinct (iCol+1) field prefixes that
** occur in the stat4 table for this index. Set sumEq to the sum of
** the nEq values for column iCol for the same set (adding the value
** only once where there exist duplicate prefixes).
pPage->nCell must be greater than zero. If this is the root-page
** the cursor would have been INVALID above and this for(;;) loop
** not run. If this is not the root-page, then the moveToChild() routine
** would have already detected db corruption. Similarly, pPage must
** be the right kind (index or table) of b-tree page. Otherwise
** a moveToChild() or moveToRoot() call would have detected corruption.
Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
** are, disable MEMSYS3
comment: No page should ever be explicitly rolled back that is in use, except
** for page 1 which is held in use in order to keep the lock on the
** database active. However such a page may be rolled back as a result
** of an internal error resulting in an automatic call to
** sqlite3PagerRollback().
label: code-design
Must be count(*)
** If this is a WAL database, store a pointer to pSnapshot. Next time a
** read transaction is opened, attempt to read from the snapshot it
** identifies. If this is not a WAL database, return an error.
The parent table
Coverage: it may be that this sqlite3_step() cannot fail. There
** is already a transaction open, so the prepared statement cannot
** throw an SQLITE_SCHEMA exception. The only database page the
** statement reads is page 1, which is guaranteed to be in the cache.
** And no memory allocations are required.
Bit Field Type
Bytes to append to the prefix
** CAPI3REF: Move a BLOB Handle to a New Row
** METHOD: sqlite3_blob
**
** ^This function is used to move an existing [BLOB handle] so that it points
** to a different row of the same database table. ^The new row is identified
** by the rowid value passed as the second argument. Only the row can be
** changed. ^The database, table and column on which the blob handle is open
** remain the same. Moving an existing [BLOB handle] to a new row is
** faster than closing the existing handle and opening a new one.
**
** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
** it must exist and there must be either a blob or text value stored in
** the nominated column.)^ ^If the new row is not present in the table, or if
** it does not contain a blob or text value, or if another error occurs, an
** SQLite error code is returned and the blob handle is considered aborted.
** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
** always returns zero.
**
** ^This function sets the database handle error code and message.
comment: This helper routine to saveAllCursors does the actual work of saving
** the cursors if and when a cursor is found that actually requires saving.
** The common case is that no cursors need to be saved, so this routine is
** broken out from its caller to avoid unnecessary stack pointer movement.
label: code-design
Size of the cell content on the main b-tree page
Return the size in bytes of a PCache object. Used to preallocate
** storage space.
Type of RHS table. IN_INDEX_*
PseudoTable input register
The LIMIT clause will jump out of the loop for us
comment:
** If the sqlite3PcacheFetch() routine is unable to allocate a new
** page because no clean pages are available for reuse and the cache
** size limit has been reached, then this routine can be invoked to
** try harder to allocate a page. This routine might invoke the stress
** callback to spill dirty pages to the journal. It will then try to
** allocate the new page and will only fail to allocate a new page on
** an OOM error.
**
** This routine should be invoked only after sqlite3PcacheFetch() fails.
label: code-design
A SQLITE_FUNC_CONSTANT or _SLOCHNG function
Also an error
** Return the size of the Nth element of the cell array
Spill is ok, but do not sync
Size of azTblCol[] array
If a rollback journal is in use, them make sure the page that is about
** to change is in the rollback journal, or if the page is a new page off
** then end of the file, make sure it is marked as PGHDR_NEED_SYNC.
The index that triggers the constraint
Insert new divider cells into pParent.
The methods of the json_each virtual table
** Set the journal-mode for this pager. Parameter eMode must be one of:
**
** PAGER_JOURNALMODE_DELETE
** PAGER_JOURNALMODE_TRUNCATE
** PAGER_JOURNALMODE_PERSIST
** PAGER_JOURNALMODE_OFF
** PAGER_JOURNALMODE_MEMORY
** PAGER_JOURNALMODE_WAL
**
** The journalmode is set to the value specified if the change is allowed.
** The change may be disallowed for the following reasons:
**
** * An in-memory database can only have its journal_mode set to _OFF
** or _MEMORY.
**
** * Temporary databases cannot have _WAL journalmode.
**
** The returned indicate the current (possibly updated) journal-mode.
synopsis: r[P1]=r[P1]+P2
True if the TEMPORARY keyword is present
Find out what flags are present
Number of bytes required for *p
expr ::= expr NOT NULL
The WHERE clause to be scanned
** Close a handle opened by an earlier call to sqlite3Fts5IndexOpen().
60
The btree to be checked
RAISE => ID
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
Wal handle to write to
Name of database within pSrcDb
Block id
Pointer to sampled record
Number of registers allocated
The foreign key linking pSrc to pTab
** Add node pNode to the node hash table.
Number of columns to test for changes
34
comment: "Slow Change". Value constant during a
** single query - might change over time
label: code-design
** Attempt to release up to n bytes of non-essential memory currently
** held by SQLite. An example of non-essential memory is memory used to
** cache database pages that are not currently in use.
If the pager is in peristent-journal mode, then the physical
** journal-file may extend past the end of the master-journal name
** and 8 bytes of magic data just written to the file. This is
** dangerous because the code to rollback a hot-journal file
** will not be able to find the master-journal name to determine
** whether or not the journal is hot.
**
** Easiest thing to do in this scenario is to truncate the journal
** file to the required size.
The WhereScan object being initialized
Statement holding lock on pIndex
** Versions of isspace(), isalnum() and isdigit() to which it is safe
** to pass signed char values.
Step 1c
nScratch
Test this expression
comment:
** CAPI3REF: Flags for the xAccess VFS method
**
** These integer constants can be used as the third parameter to
** the xAccess method of an [sqlite3_vfs] object. They determine
** what kind of permissions the xAccess method is looking for.
** With SQLITE_ACCESS_EXISTS, the xAccess method
** simply checks whether the file exists.
** With SQLITE_ACCESS_READWRITE, the xAccess method
** checks whether the named directory is both readable and writable
** (in other words, if files can be added, removed, and renamed within
** the directory).
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
** [temp_store_directory pragma], though this could change in a future
** release of SQLite.
** With SQLITE_ACCESS_READ, the xAccess method
** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
** currently unused, though it might be used in a future release of
** SQLite.
label: code-design
** This is a public wrapper for the winUtf8ToUnicode() function.
Check for locking consistency
Expr in which substitution occurs
comment: 1 bit per page in the db (see above)
label: code-design
Non-logarithmic stat1 data for this index
Result of query pNextIdx
** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
**
** This function may only be called with an iterator passed to an
** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
** it sets the output variable to the total number of known foreign key
** violations in the destination database and returns SQLITE_OK.
**
** In all other cases this function returns SQLITE_MISUSE.
if SQLITE_OMIT_LOAD_EXTENSION is defined:
Statement to write %_content table
The WAL file to which we write
** When this function is called, *pp points to the first byte following a
** varint that is part of a doclist (or position-list, or any other list
** of varints). This function moves *pp to point to the start of that varint,
** and sets *pVal by the varint value.
**
** Argument pStart points to the first byte of the doclist that the
** varint is part of.
Cursor number of cursor that does not need seeking
Pointer to page cache object
Page containing the cell
The decimal point
** Check to see if zTabName is really the name of a pragma. If it is,
** then register an eponymous virtual table for that pragma and return
** a pointer to the Module object for the new virtual table.
** Read the first token from the nul-terminated string at *pz.
** Returns the character that should be used as the directory separator.
Number of terms in the join
35
Offset in aKey[] to read from
Some combination of SQLITE_FUNC_*
comment:
** Allocate memory. This routine is like sqlite3_malloc() except that it
** assumes the memory subsystem has already been initialized.
label: code-design
Search constraints.
** Parse dates of the form
**
** YYYY-MM-DD HH:MM:SS.FFF
** YYYY-MM-DD HH:MM:SS
** YYYY-MM-DD HH:MM
** YYYY-MM-DD
**
** Write the result into the DateTime structure and return 0
** on success and 1 if the input string is not a well-formed
** date.
Number of bytes of header space
************* Begin file expr.c *******************************************
IMP: R-52476-28732
Condition (1) is true
comment:
** Include the malloc.h header file, if necessary. Also set define macro
** SQLITE_MALLOCSIZE to the appropriate function name, which is _msize()
** for MSVC and malloc_usable_size() for most other systems (e.g. Linux).
** The memory size function can always be overridden manually by defining
** the macro SQLITE_MALLOCSIZE to the desired function name.
label: code-design
** Return true if, for the purposes of tokenization, codepoint iCode is
** considered a token character (not a separator).
Database holding shared-memory
Value of 'name' column
Total size of allocation
************* Begin file json1.c ******************************************
** Allocate a new expression node from a zero-terminated token that has
** already been dequoted.
Compute a safe address to jump to if we discover that the table for
** this loop is empty and can never contribute content.
** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
** the current value of pCsr->iPageno.
** SQLite value pRowid contains the rowid of a row that may or may not be
** present in the FTS3 table. If it is, delete it and adjust the contents
** of subsiduary data structures accordingly.
************* Begin file pragma.c *****************************************
tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf
offset to first byte to lock
54
Hash table for in-memory data
same as TK_ESCAPE
String containing int array to decode
The entire poslist will not fit on this leaf. So it needs
** to be broken into sections. The only qualification being
** that each varint must be stored contiguously.
If control reaches this point, it means the transformation is
** one of the forms like "+NNN days".
start tokenizing at the beginning
First argument passed to xCallback()
Name of database holding this table
The row containing the glob
List of active virtual machines
** Retrieve a record from the %_data table.
**
** If an error occurs, NULL is returned and an error left in the
** Fts5Index object.
'/'. / or c-style comment
42
** Implementation of the offsets() function for FTS3
** Return the number of bytes required to store value iVal as a varint.
** This routine is called to implement sqlite3_wal_checkpoint() and
** related interfaces.
**
** Obtain a CHECKPOINT lock and then backfill as much information as
** we can from WAL into the database.
**
** If parameter xBusy is not NULL, it is a pointer to a busy-handler
** callback. In this case this function runs a blocking checkpoint.
Pointer to bytes counter
Number of tokens in each fragment
If no preexisting index is available for the IN clause
** and IN_INDEX_NOOP is an allowed reply
** and the RHS of the IN operator is a list, not a subquery
** and the RHS is not constant or has two or fewer terms,
** then it is not worth creating an ephemeral table to evaluate
** the IN operator so return IN_INDEX_NOOP.
** If the SessionInput object passed as the only argument is a streaming
** object and the buffer is full, discard some data to free up space.
** The header string that appears at the beginning of every
** SQLite database.
** An instance of this structure contains information needed to generate
** code for a SELECT that contains aggregate functions.
**
** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
** pointer to this structure. The Expr.iColumn field is the index in
** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
** code for that node.
**
** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the
** original Select structure that describes the SELECT statement. These
** fields do not need to be freed when deallocating the AggInfo structure.
This call frees pShmNode if required
Column reference
String encoding (0 for blobs)
skip trailing spaces
rc==0 here means that one of the keys ran out of fields and
** all the fields up to that point were equal. Return the default_rc
** value.
Re-open the databases.
If the RBU database contains no data_xxx tables, declare the RBU
** update finished.
If nRec is 0 and this rollback is of a transaction created by this
** process and if this is the final header in the journal, then it means
** that this part of the journal was being filled but has not yet been
** synced to disk. Compute the number of pages based on the remaining
** size of the file.
**
** The third term of the test was added to fix ticket #2565.
** When rolling back a hot journal, nRec==0 always means that the next
** chunk of the journal contains zero pages to be rolled back. But
** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
** the journal, it means that the journal might contain additional
** pages that need to be rolled back and that the number of pages
** should be computed based on the journal file size.
Size of database in pages
Pointers to the extension init functions
comment: Do not need to test for a HAVING clause. If HAVING is present but
** there is no ORDER BY, we will get an error.
label: test
Read the values returned by the SELECT into local variables.
Info for single OR-term scan
SQLITE_STATUS_SCRATCH_USED
nHeap
For each aggregate function
SQLITE_WIN32_HAS_ANSI
Statement to query database with
If non-zero, transform OP_rowid to OP_AddImm(1)
Value of 'pgSize' column
Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
** handle rows (possibly in other tables) that refer via a foreign key
** to the row just updated.
Used to hold return values of fstat()
The index whose column is to be loaded
** Register a trace function. The pArg from the previously registered trace
** is returned.
**
** A NULL trace function means that no tracing is executes. A non-NULL
** trace is a pointer to a function that is invoked at the start of each
** SQL statement.
comment: Unused (padding) field
label: code-design
Number of == or IN terms
The look-ahead token
Ok for sqlite3_open_v2()
** If the SELECT passed as the second argument has an associated WITH
** clause, pop it from the stack stored as part of the Parse object.
**
** This function is used as the xSelectCallback2() callback by
** sqlite3SelectExpand() when walking a SELECT tree to resolve table
** names and other FROM clause elements.
Tokenizer to add exceptions to
** End of interface to code in fts5_index.c.
*************************************************************************
A single column of result
Byte offset of token within input text
Number of mmap pages currently outstanding
comment: Suppress warning about unused %extra_argument variable
label: code-design
** Each builtin conversion character (ex: the 'd' in "%d") is described
** by an instance of the following structure
** Change the opcode at addr into OP_Noop
The virtual machine
comment:
** Argument is a pointer to an Fts5Data structure that contains a leaf
** page. This macro evaluates to true if the leaf contains no terms, or
** false if it contains at least one term.
label: code-design
** Register hooks to call when sqlite3BeginBenignMalloc() and
** sqlite3EndBenignMalloc() are called, respectively.
Table containing the row to be deleted
Value for Fts3Phrase.iColumn
** Make every page in the cache clean.
Maximum cost of a set of paths
Cause p to be overwritten by pTemplate
Return an error if we get here
Insert the new divider cell into pParent.
fts3_expr.c
flags passed through to sqlite3_vfs.xOpen()
Memory cell used to implement LEFT OUTER JOIN
0x
Jump here if the key is OK
** Sort all elements on the list of RowSetEntry objects into order of
** increasing v.
same as TK_STRING, synopsis: r[P2]='P4'
Two or more AND-connected terms
1 for new.* ref mask, 0 for old.* ref mask
Pointer to busy-handler function
"ndlt" column of stat[34] entry
Index of conflict record value to fetch
RHS must not overlap with this mask
** Do not accept any file descriptor less than this value, in order to avoid
** opening database file using file descriptors that are commonly used for
** standard input, output, and error.
131
If we created a new conch file (not just updated the contents of a
** valid conch file), try to match the permissions of the database
Begin a transaction and take an exclusive lock on the main database
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
** to ensure that we do not try to change the page-size on a WAL database.
** PRAGMA [schema.]locking_mode
** PRAGMA [schema.]locking_mode = (normal|exclusive)
Length of zSql in bytes.
comment: *****************************************************************************
************************** Begin Proxy Locking ********************************
**
** Proxy locking is a "uber-locking-method" in this sense: It uses the
** other locking methods on secondary lock files. Proxy locking is a
** meta-layer over top of the primitive locking implemented above. For
** this reason, the division that implements of proxy locking is deferred
** until late in the file (here) after all of the other I/O methods have
** been defined - so that the primitive locking methods are available
** as services to help with the implementation of proxy locking.
**
****
**
** The default locking schemes in SQLite use byte-range locks on the
** database file to coordinate safe, concurrent access by multiple readers
** and writers [http://sqlite.org/lockingv3.html]. The five file locking
** states (UNLOCKED, PENDING, SHARED, RESERVED, EXCLUSIVE) are implemented
** as POSIX read & write locks over fixed set of locations (via fsctl),
** on AFP and SMB only exclusive byte-range locks are available via fsctl
** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states.
** To simulate a F_RDLCK on the shared range, on AFP a randomly selected
** address in the shared range is taken for a SHARED lock, the entire
** shared range is taken for an EXCLUSIVE lock):
**
** PENDING_BYTE 0x40000000
** RESERVED_BYTE 0x40000001
** SHARED_RANGE 0x40000002 -> 0x40000200
**
** This works well on the local file system, but shows a nearly 100x
** slowdown in read performance on AFP because the AFP client disables
** the read cache when byte-range locks are present. Enabling the read
** cache exposes a cache coherency problem that is present on all OS X
** supported network file systems. NFS and AFP both observe the
** close-to-open semantics for ensuring cache coherency
** [http://nfs.sourceforge.net/#faq_a8], which does not effectively
** address the requirements for concurrent database access by multiple
** readers and writers
** [http://www.nabble.com/SQLite-on-NFS-cache-coherency-td15655701.html].
**
** To address the performance and cache coherency issues, proxy file locking
** changes the way database access is controlled by limiting access to a
** single host at a time and moving file locks off of the database file
** and onto a proxy file on the local file system.
**
**
** Using proxy locks
** -----------------
**
** C APIs
**
** sqlite3_file_control(db, dbname, SQLITE_FCNTL_SET_LOCKPROXYFILE,
** <proxy_path> | ":auto:");
** sqlite3_file_control(db, dbname, SQLITE_FCNTL_GET_LOCKPROXYFILE,
** &<proxy_path>);
**
**
** SQL pragmas
**
** PRAGMA [database.]lock_proxy_file=<proxy_path> | :auto:
** PRAGMA [database.]lock_proxy_file
**
** Specifying ":auto:" means that if there is a conch file with a matching
** host ID in it, the proxy path in the conch file will be used, otherwise
** a proxy path based on the user's temp dir
** (via confstr(_CS_DARWIN_USER_TEMP_DIR,...)) will be used and the
** actual proxy file name is generated from the name and path of the
** database file. For example:
**
** For database path "/Users/me/foo.db"
** The lock path will be "<tmpdir>/sqliteplocks/_Users_me_foo.db:auto:")
**
** Once a lock proxy is configured for a database connection, it can not
** be removed, however it may be switched to a different proxy path via
** the above APIs (assuming the conch file is not being held by another
** connection or process).
**
**
** How proxy locking works
** -----------------------
**
** Proxy file locking relies primarily on two new supporting files:
**
** * conch file to limit access to the database file to a single host
** at a time
**
** * proxy file to act as a proxy for the advisory locks normally
** taken on the database
**
** The conch file - to use a proxy file, sqlite must first "hold the conch"
** by taking an sqlite-style shared lock on the conch file, reading the
** contents and comparing the host's unique host ID (see below) and lock
** proxy path against the values stored in the conch. The conch file is
** stored in the same directory as the database file and the file name
** is patterned after the database file name as ".<databasename>-conch".
** If the conch file does not exist, or its contents do not match the
** host ID and/or proxy path, then the lock is escalated to an exclusive
** lock and the conch file contents is updated with the host ID and proxy
** path and the lock is downgraded to a shared lock again. If the conch
** is held by another process (with a shared lock), the exclusive lock
** will fail and SQLITE_BUSY is returned.
**
** The proxy file - a single-byte file used for all advisory file locks
** normally taken on the database file. This allows for safe sharing
** of the database file for multiple readers and writers on the same
** host (the conch ensures that they all use the same local lock file).
**
** Requesting the lock proxy does not immediately take the conch, it is
** only taken when the first request to lock database file is made.
** This matches the semantics of the traditional locking behavior, where
** opening a connection to a database file does not take a lock on it.
** The shared lock and an open file descriptor are maintained until
** the connection to the database is closed.
**
** The proxy file and the lock file are never deleted so they only need
** to be created the first time they are used.
**
** Configuration options
** ---------------------
**
** SQLITE_PREFER_PROXY_LOCKING
**
** Database files accessed on non-local file systems are
** automatically configured for proxy locking, lock files are
** named automatically using the same logic as
** PRAGMA lock_proxy_file=":auto:"
**
** SQLITE_PROXY_DEBUG
**
** Enables the logging of error messages during host id file
** retrieval and creation
**
** LOCKPROXYDIR
**
** Overrides the default directory used for lock proxy files that
** are named automatically via the ":auto:" setting
**
** SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
**
** Permissions to use when creating a directory for storing the
** lock proxy files, only used when LOCKPROXYDIR is not set.
**
**
** As mentioned above, when compiled with SQLITE_PREFER_PROXY_LOCKING,
** setting the environment variable SQLITE_FORCE_PROXY_LOCKING to 1 will
** force proxy locking to be used for every database file opened, and 0
** will force automatic proxy locking to be disabled for all database
** files (explicitly calling the SQLITE_FCNTL_SET_LOCKPROXYFILE pragma or
** sqlite_file_control API is not affected by SQLITE_FORCE_PROXY_LOCKING).
label: code-design
** Check that the output buffer is large enough for the temporary file
** name in the following format:
**
** "<temporary_directory>/etilqs_XXXXXXXXXXXXXXX\0\0"
**
** If not, return SQLITE_ERROR. The number 17 is used here in order to
** account for the space used by the 15 character random suffix and the
** two trailing NUL characters. The final directory separator character
** has already added if it was not already present.
Size value to return
Last entry in the stack
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append the string representation of integer iVal
** to the buffer. No nul-terminator is written.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
If a NEAR() clump or phrase may only match a specific set of columns,
** then an object of the following type is used to record the set of columns.
** Each entry in the aiCol[] array is a column that may be matched.
**
** This object is used by fts5_expr.c and fts5_index.c.
Locate the table in question
'.'
Now that the read-lock has been obtained, check that neither the
** value in the aReadMark[] array or the contents of the wal-index
** header have changed.
**
** It is necessary to check that the wal-index header did not change
** between the time it was read and when the shared-lock was obtained
** on WAL_READ_LOCK(mxI) was obtained to account for the possibility
** that the log file may have been wrapped by a writer, or that frames
** that occur later in the log than pWal->hdr.mxFrame may have been
** copied into the database by a checkpointer. If either of these things
** happened, then reading the database with the current value of
** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
** instead.
**
** Before checking that the live wal-index header has not changed
** since it was read, set Wal.minFrame to the first frame in the wal
** file that has not yet been checkpointed. This client will not need
** to read any frames earlier than minFrame from the wal file - they
** can be safely read directly from the database file.
**
** Because a ShmBarrier() call is made between taking the copy of
** nBackfill and checking that the wal-header in shared-memory still
** matches the one cached in pWal->hdr, it is guaranteed that the
** checkpointer that set nBackfill was not working with a wal-index
** header newer than that cached in pWal->hdr. If it were, that could
** cause a problem. The checkpointer could omit to checkpoint
** a version of page X that lies before pWal->minFrame (call that version
** A) on the basis that there is a newer version (version B) of the same
** page later in the wal file. But if version B happens to like past
** frame pWal->hdr.mxFrame - then the client would incorrectly assume
** that it can read version A from the database file. However, since
** we can guarantee that the checkpointer that set nBackfill could not
** see any pages past pWal->hdr.mxFrame, this problem does not come up.
First of real indices on the table
The page getter method for when the pager is an error state
***** This routine is used inside of assert() only ****
**
** Verify that the cursor holds the mutex on its BtShared
FROM clause is not a view
Operands are equal
Now get the read-lock
FROMFULLGLOBYIFISNULLORDERESTRICTRIGHTROLLBACKROWUNIONUSING
** Generate code for an IN expression.
**
** x IN (SELECT ...)
** x IN (value, value, ...)
**
** The left-hand side (LHS) is a scalar or vector expression. The
** right-hand side (RHS) is an array of zero or more scalar values, or a
** subquery. If the RHS is a subquery, the number of result columns must
** match the number of columns in the vector on the LHS. If the RHS is
** a list of values, the LHS must be a scalar.
**
** The IN operator is true if the LHS value is contained within the RHS.
** The result is false if the LHS is definitely not in the RHS. The
** result is NULL if the presence of the LHS in the RHS cannot be
** determined due to NULLs.
**
** This routine generates code that jumps to destIfFalse if the LHS is not
** contained within the RHS. If due to NULLs we cannot determine if the LHS
** is contained in the RHS then jump to destIfNull. If the LHS is contained
** within the RHS then fall through.
**
** See the separate in-operator.md documentation file in the canonical
** SQLite source tree for additional information.
Number of level-0 PMAs to merge
** Print tracing information for a SHIFT action
** This function is only called from within an assert() expression. It
** checks that the sqlite3.nTransaction variable is correctly set to
** the number of non-transaction savepoints currently in the
** linked list starting at sqlite3.pSavepoint.
**
** Usage:
**
** assert( checkSavepointCount(db) );
Things to be changed
Length of zAbsoluteName string
Total number of pages restored from journal
Forward references to structures used for WAL
comment: Optional %extra_argument parameter
label: code-design
** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
** deprecated are always assumed to be based on the NT kernel.
zPath is a path to a WAL or journal file. The following block derives
** the path to the associated database file from zPath. This block handles
** the following naming conventions:
**
** "<path to db>-journal"
** "<path to db>-wal"
** "<path to db>-journalNN"
** "<path to db>-walNN"
**
** where NN is a decimal number. The NN naming schemes are
** used by the test_multiplex.c module.
** An instance of this object serves as a cursor into the rollback journal.
** The cursor can be either for reading or writing.
** This function checks if argument pFrom refers to a CTE declared by
** a WITH clause on the stack currently maintained by the parser. And,
** if currently processing a CTE expression, if it is a recursive
** reference to the current CTE.
**
** If pFrom falls into either of the two categories above, pFrom->pTab
** and other fields are populated accordingly. The caller should check
** (pFrom->pTab!=0) to determine whether or not a successful match
** was found.
**
** Whether or not a match is found, SQLITE_OK is returned if no error
** occurs. If an error does occur, an error message is stored in the
** parser and some error code other than SQLITE_OK returned.
One byte past end of position list
** Open the dynamic library located at zPath and return a handle.
Size of BLOB written into %_stat
zSpan holds DB.TABLE.COLUMN
If the first temporary PMA file has not been opened, open it now.
xSFunc
Second varint to store in hint
The WHERE clause
case 1 trumps case 3
4th argument to snippet()
Verify that the MergeEngine is assigned to a single thread
** Finalize all statements and free all allocations that are specific to
** the current object (table/index pair).
Set to true if a 'special' error
True to trace VDBE execution
True if cell coverage checking should be done
True if pages are on backing store
True if we have seen a malloc failure
A slot for the record has already been allocated in the
** SQLITE_MASTER table. We just need to update that slot with all
** the information we've collected.
**
** The VM register number pParse->regRowid holds the rowid of an
** entry in the sqlite_master table tht was created for this vtab
** by sqlite3StartTable().
Test that this call is being made from within an SQLITE_DELETE or
** SQLITE_UPDATE pre-update callback, and that iIdx is within range.
Need to make a copy of path if we extracted the value
** from the conch file or the path was allocated on the stack
** Turn the pExpr expression into an alias for the iCol-th column of the
** result set in pEList.
**
** If the reference is followed by a COLLATE operator, then make sure
** the COLLATE operator is preserved. For example:
**
** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
**
** Should be transformed into:
**
** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase;
**
** The nSubquery parameter specifies how many levels of subquery the
** alias is removed from the original expression. The usual value is
** zero but it might be more if the alias is contained within a subquery
** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
** structures must be increased by the nSubquery amount.
Copy of fifth arg to _apply()
Destination for coroutine A
************* End of vdbe.h ***********************************************
Name of the column we are looking for
************* End of sqlite3ext.h *****************************************
In this case there is room on the trunk page to insert the page
** being freed as a new leaf.
**
** Note that the trunk page is not really full until it contains
** usableSize/4 - 2 entries, not usableSize/4 - 8 entries as we have
** coded. But due to a coding error in versions of SQLite prior to
** 3.6.0, databases with freelist trunk pages holding more than
** usableSize/4 - 8 entries will be reported as corrupt. In order
** to maintain backwards compatibility with older versions of SQLite,
** we will continue to restrict the number of entries to usableSize/4 - 8
** for now. At some point in the future (once everyone has upgraded
** to 3.6.0 or later) we should consider fixing the conditional above
** to read "usableSize/4-2" instead of "usableSize/4-8".
**
** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
** avoid using the last six entries in the freelist trunk page array in
** order that database files created by newer versions of SQLite can be
** read by older versions of SQLite.
Extra data associated with the callback
** Move the cursor down to a new child page. The newPgno argument is the
** page number of the child page to move to.
**
** This function returns SQLITE_CORRUPT if the page-header flags field of
** the new child page does not match the flags field of the parent (i.e.
** if an intkey page appears to be the parent of a non-intkey page, or
** vice-versa).
Files only.
Request a pointer to the required page from the VFS
** Generate VDBE code for a COMMIT or ROLLBACK statement.
** Code for ROLLBACK is generated if eType==TK_ROLLBACK. Otherwise
** code is generated for a COMMIT.
** Search the list of WhereLoops in *ppPrev looking for one that can be
** replaced by pTemplate.
**
** Return NULL if pTemplate does not belong on the WhereLoop list.
** In other words if pTemplate ought to be dropped from further consideration.
**
** If pX is a WhereLoop that pTemplate can replace, then return the
** link that points to pX.
**
** If pTemplate cannot replace any existing element of the list but needs
** to be added to the list as a new entry, then return a pointer to the
** tail of the list.
Maximum allowed segments per level
Trigger name for error reporting
Begin the search at this node
Now that no other errors can occur, finish filling in the BtCursor
** variables and link the cursor into the BtShared list.
Checksum does not match
** Maximum pathname length (in chars) for Win32. This should normally be
** MAX_PATH.
** If this is a no-op implementation, implement everything as macros.
Maximum allowed string or blob size
Check that sqlite3VdbeUsesBtree() was not called on this VM
User-data pointer
Index interior and leaf nodes
URI args to copy
Figure out where to write the new Expr structure.
Only valid in paren mode
** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn()
** only works for non-virtual tables (ordinary tables and views) and is
** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The
** IsHiddenColumn() macro is general purpose.
IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
** a pointer to the to the sqlite3_version[] string constant.
24
!defined(SQLITE_OMIT_LOAD_EXTENSION)
IMP: R-36257-52125
Number of nested brackets
Check for key annihilation.
** Formulate and prepare a SELECT statement to retrieve a row from table
** zTab in database zDb based on its primary key. i.e.
**
** SELECT * FROM zDb.zTab WHERE pk1 = ? AND pk2 = ? AND ...
** BEGIN CODE GENERATED BY tool/mkctime.tcl
Pointer to new system call value
Search for existing entry. If found, remove it from the hash table.
** Code below may link it back in.
Name of database within pDestDb
Source and destination indices
flags field of new pages before shuffling
Name of new table, or database name
Number of columns stored in the index
All filesystem writes are atomic
** Try to initialize the pCache->pFree and pCache->pBulk fields. Return
** true if pCache->pFree ends up containing one or more free pages.
Write the %_segdir record.
The default page size and offset
** During a rollback, when the pager reloads information into the cache
** so that the cache is restored to its original state at the start of
** the transaction, for each page restored this routine is called.
**
** This routine needs to reset the extra data section at the end of the
** page to agree with the restored data.
** This routine checks for a byte-order mark at the beginning of the
** UTF-16 string stored in *pMem. If one is present, it is removed and
** the encoding of the Mem adjusted. This routine does not do any
** byte-swapping, it just sets Mem.enc appropriately.
**
** The allocation (static, dynamic etc.) and encoding of the Mem may be
** changed by this function.
Initialize the INTEGER value of a ROWID.
** A new segment has just been written to level iLvl of index structure
** pStruct. This function determines if any segments should be promoted
** as a result. Segments are promoted in two scenarios:
**
** a) If the segment just written is smaller than one or more segments
** within the previous populated level, it is promoted to the previous
** populated level.
**
** b) If the segment just written is larger than the newest segment on
** the next populated level, then that segment, and any other adjacent
** segments that are also smaller than the one just written, are
** promoted.
**
** If one or more segments are promoted, the structure object is updated
** to reflect this.
** These macros can be used to test, set, or clear bits in the
** Expr.flags field.
** Context object used by sqlite3Fts5StorageIntegrity().
OUT: Starting offset of token
Round up if true. Round down if false
OUT: score for the cell
** Remove the entry with rowid=iDelete from the r-tree structure.
304
pSqllogArg
** Return the VDBE address or label to jump to in order to break
** out of a WHERE loop.
Index.aiColumn
For looping over tables in pDb
unknown or unsupported join type
Used to full index in sorted order
** time( TIMESTRING, MOD, MOD, ...)
**
** Return HH:MM:SS
** The minimum number of cells allowed for a node is a third of the
** maximum. In Gutman's notation:
**
** m = M/3
**
** If an R*-tree "Reinsert" operation is required, the same number of
** cells are removed from the overfull node and reinserted into the tree.
** Change pMem so that its MEM_Str or MEM_Blob value is stored in
** MEM.zMalloc, where it can be safely written.
**
** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
The database number
16
RHS of comparison
** Return the estimated number of output rows from a WHERE clause
Vdbe to add scanstatus entry to
Parent node (or NULL for root node)
Modify the CREATE TABLE statement.
FTS3 vtab object
Stop reporting errors after this many
Move the *-oal file to *-wal. At this point connection p->db is
** holding a SHARED lock on the target database file (because it is
** in WAL mode). So no other connection may be writing the db.
**
** In order to ensure that there are no database readers, an EXCLUSIVE
** lock is obtained here before the *-oal is moved to *-wal.
Drop the shadow tables
** Return the number of bytes allocated for the expression structure
** passed as the first argument. This is always one of EXPR_FULLSIZE,
** EXPR_REDUCEDSIZE or EXPR_TOKENONLYSIZE.
Created using CREATE INDEX
Restriction 18.
xDlOpen
OUT: Size of position list in bytes
Changegroup object to add changeset to
A routine to convert a binary TK_IS or TK_ISNOT expression into a
** unary TK_ISNULL or TK_NOTNULL expression.
The VDBE
comment: The subquery whose WHERE clause is to be augmented
label: documentation
comment:
** This structure is passed around through all the sanity checking routines
** in order to keep track of some global state information.
**
** The aRef[] array is allocated so that there is 1 bit for each page in
** the database. As the integrity-check proceeds, for each page used in
** the database the corresponding bit is set. This allows integrity-check to
** detect pages that are used twice and orphaned pages (both of which
** indicate corruption).
label: code-design
comment:
** The macro unlikely() is a hint that surrounds a boolean
** expression that is usually false. Macro likely() surrounds
** a boolean expression that is usually true. These hints could,
** in theory, be used by the compiler to generate better code, but
** currently they are just comments for human readers.
label: code-design
** The following table is searched linearly, so it is good to put the
** most frequently used conversion types first.
One of TK_INSERT, TK_UPDATE, TK_DELETE
Iterator for skipping through tbl/idx
An index associated with pTab
The next entry is on the current page.
The rowid searching for
List to scan and in which to make substitutes
** The bitmask datatype defined below is used for various optimizations.
**
** Changing this from a 64-bit to a 32-bit type limits the number of
** tables in a join to 32 instead of 64. But it also reduces the size
** of the library by 738 bytes on ix86.
Value for integer types
Adjust nOut using stat3/stat4 data. Or, if there is no stat3/stat4
** data, using some other estimate.
One-time test address
Search for an existing index that will work for this IN operator
completely fill the hash, then just add it without
Repeat the above with the next record to be updated, until
** all record selected by the WHERE clause have been updated.
** pMem currently only holds a string type (or maybe a BLOB that we can
** interpret as a string if we want to). Compute its corresponding
** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields
** accordingly.
Number of symbolic links followed so far
37
** Register the r-tree module with database handle db. This creates the
** virtual table module "rtree" and the debugging/analysis scalar
** function "rtreenode".
1st argument to snippet()
Space available in zTemp[]
Name of new function
Write the node here
** Close a file.
** Register the fts3tok module with database connection db. Return SQLITE_OK
** if successful or an error code if sqlite3_create_module() fails.
The new hash table
Next are the tables used to determine what action to take based on the
** current state and lookahead token. These tables are used to implement
** functions that take a state number and lookahead value and return an
** action integer.
**
** Suppose the action integer is N. Then the action is determined as
** follows
**
** 0 <= N <= fts5YY_MAX_SHIFT Shift N. That is, push the lookahead
** token onto the stack and goto state N.
**
** N between fts5YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
** and fts5YY_MAX_SHIFTREDUCE reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
**
** N between fts5YY_MIN_REDUCE Reduce by rule N-fts5YY_MIN_REDUCE
** and fts5YY_MAX_REDUCE
**
** N == fts5YY_ERROR_ACTION A syntax error has occurred.
**
** N == fts5YY_ACCEPT_ACTION The parser accepts its input.
**
** N == fts5YY_NO_ACTION No such action. Denotes unused
** slots in the fts5yy_action[] table.
**
** The action table is constructed as a single large table named fts5yy_action[].
** Given state S and lookahead X, the action is computed as either:
**
** (A) N = fts5yy_action[ fts5yy_shift_ofst[S] + X ]
** (B) N = fts5yy_default[S]
**
** The (A) formula is preferred. The B formula is used instead if:
** (1) The fts5yy_shift_ofst[S]+X value is out of range, or
** (2) fts5yy_lookahead[fts5yy_shift_ofst[S]+X] is not equal to X, or
** (3) fts5yy_shift_ofst[S] equal fts5YY_SHIFT_USE_DFLT.
** (Implementation note: fts5YY_SHIFT_USE_DFLT is chosen so that
** fts5YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
** Hence only tests (1) and (2) need to be evaluated.)
**
** The formulas above are for computing the action when the lookahead is
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
** a reduce action) then the fts5yy_reduce_ofst[] array is used in place of
** the fts5yy_shift_ofst[] array and fts5YY_REDUCE_USE_DFLT is used in place of
** fts5YY_SHIFT_USE_DFLT.
**
** The following are the tables generated in this section:
**
** fts5yy_action[] A single table containing all actions.
** fts5yy_lookahead[] A table containing the lookahead for each entry in
** fts5yy_action. Used to detect hash collisions.
** fts5yy_shift_ofst[] For each state, the offset into fts5yy_action for
** shifting terminals.
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
** shifting non-terminals after a reduce.
** fts5yy_default[] Default action for each state.
**
*********** Begin parsing tables *********************************************
** Boolean values
** Begin constructing a new table representation in memory. This is
** the first of several action routines that get called in response
** to a CREATE TABLE statement. In particular, this routine is called
** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
** flag is true if the table should be stored in the auxiliary database
** file instead of in the main database file. This is normally the case
** when the "TEMP" or "TEMPORARY" keyword occurs in between
** CREATE and TABLE.
**
** The new table record is initialized and put in pParse->pNewTable.
** As more of the CREATE TABLE statement is parsed, additional action
** routines will be called to add more information to this record.
** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
** is called to complete the construction of the new table record.
OP_Explain for loop
Rowid to delete
All keys are integers
tridxby ::= NOT INDEXED
3: (end_constraints && bRev && endEq)
Right hand child expression
25-31
nCol rounded up for alignment
** Construct a trigger step that implements an UPDATE statement and return
** a pointer to that trigger step. The parser calls this routine when it
** sees an UPDATE statement inside the body of a CREATE TRIGGER.
Increment the value stored in the P2 operand of the OP_Rowid.
** This function is only called from within a pre-update-hook callback.
** It determines if the current pre-update-hook change affects the same row
** as the change stored in argument pChange. If so, it returns true. Otherwise
** if the pre-update-hook does not affect the same row as pChange, it returns
** false.
Resolve the column names in all the expressions of the
** of the UPDATE statement. Also find the column index
** for each column to be updated in the pChanges array. For each
** column to be updated, make sure we have authorization to change
** that column.
comment: The term being tested
label: test
Number of elements in regKey for WITHOUT ROWID
MEMORY
** Flush any buffered data to disk and clean up the PMA-writer object.
** The results of using the PMA-writer after this call are undefined.
** Return SQLITE_OK if flushing the buffered data succeeds or is not
** required. Otherwise, return an SQLite error code.
**
** Before returning, set *piEof to the offset immediately following the
** last byte written to the file.
Repeat over compound terms
5 -> CONTENT
iVersion
Want a read-only lock?
Flags associated with this schema
** Activate assert() only if SQLITE_TEST is enabled.
Check that this is either a no-op (because the requested lock is
** already held), or one of the transitions that the busy-handler
** may be invoked during, according to the comment above
** sqlite3PagerSetBusyhandler().
Cursor to grab old.* values from
Timezone offset in minutes
** Save the positions of all cursors (except pExcept) that are open on
** the table with root-page iRoot. "Saving the cursor position" means that
** the location in the btree is remembered in such a way that it can be
** moved back to the same spot after the btree has been modified. This
** routine is called just before cursor pExcept is used to modify the
** table, for example in BtreeDelete() or BtreeInsert().
**
** If there are two or more cursors on the same btree, then all such
** cursors should have their BTCF_Multiple flag set. The btreeCursor()
** routine enforces that rule. This routine only needs to be called in
** the uncommon case when pExpect has the BTCF_Multiple flag set.
**
** If pExpect!=NULL and if no other cursors are found on the same root-page,
** then the BTCF_Multiple flag on pExpect is cleared, to avoid another
** pointless call to this routine.
**
** Implementation note: This routine merely checks to see if any cursors
** need to be saved. It calls out to saveCursorsOnList() in the (unusual)
** event that cursors are in need to being saved.
Length of the field
True to set lock. False to clear lock
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
Constant used for this transform
Because the parser constructs pTblName from a single identifier,
** sqlite3FixSrcList can never fail.
Shared b-tree handle
comment:
** Change the maximum number of in-memory pages that are allowed
** before attempting to recycle clean and unused pages.
label: code-design
Insert the new row into the %_content table.
** Release all memory held by the SegmentWriter object passed as the
** first argument.
Not previously opened
synopsis: r[P2]=root iDb=P1
Create a new cursor for the pragma virtual table
Added by 3.3.13
Bounding box coordinates
1 START:
** This routine is called from the TCL test function "translate_selftest".
** It checks that the primitives for serializing and deserializing
** characters in each encoding are inverses of each other.
** Generate or extend an 8 byte checksum based on the data in
** array aByte[] and the initial values of aIn[0] and aIn[1] (or
** initial values of 0 and 0 if aIn==NULL).
**
** The checksum is written back into aOut[] before returning.
**
** nByte must be a positive multiple of 8.
** Return the number of changes in the most recent call to sqlite3_exec().
defined(_WRS_KERNEL)
Close the underlying file handle
Used to iterate through attached dbs
Left subtree (smaller entries)
The table from which records will be deleted
** CAPI3REF: Extract Metadata About A Column Of A Table
** METHOD: sqlite3
**
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
** information about column C of table T in database D
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
** interface returns SQLITE_OK and fills in the non-NULL pointers in
** the final five arguments with appropriate values if the specified
** column exists. ^The sqlite3_table_column_metadata() interface returns
** SQLITE_ERROR and if the specified column does not exist.
** ^If the column-name parameter to sqlite3_table_column_metadata() is a
** NULL pointer, then this routine simply checks for the existence of the
** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
** does not. If the table name parameter T in a call to
** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
** undefined behavior.
**
** ^The column is identified by the second, third and fourth parameters to
** this function. ^(The second parameter is either the name of the database
** (i.e. "main", "temp", or an attached database) containing the specified
** table or NULL.)^ ^If it is NULL, then all attached databases are searched
** for the table using the same algorithm used by the database engine to
** resolve unqualified table references.
**
** ^The third and fourth parameters to this function are the table and column
** name of the desired column, respectively.
**
** ^Metadata is returned by writing to the memory locations passed as the 5th
** and subsequent parameters to this function. ^Any of these arguments may be
** NULL, in which case the corresponding element of metadata is omitted.
**
** ^(<blockquote>
** <table border="1">
** <tr><th> Parameter <th> Output<br>Type <th> Description
**
** <tr><td> 5th <td> const char* <td> Data type
** <tr><td> 6th <td> const char* <td> Name of default collation sequence
** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
** </table>
** </blockquote>)^
**
** ^The memory pointed to by the character pointers returned for the
** declaration type and collation sequence is valid until the next
** call to any SQLite API function.
**
** ^If the specified table is actually a view, an [error code] is returned.
**
** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
** is not a [WITHOUT ROWID] table and an
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
** parameters are set for the explicitly declared column. ^(If there is no
** [INTEGER PRIMARY KEY] column, then the outputs
** for the [rowid] are set as follows:
**
** <pre>
** data type: "INTEGER"
** collation sequence: "BINARY"
** not null: 0
** primary key: 1
** auto increment: 0
** </pre>)^
**
** ^This function causes all database schemas to be read from disk and
** parsed, if that has not already been done, and returns an error if
** any errors are encountered while loading the schema.
Opcode: VColumn P1 P2 P3 * *
** Synopsis: r[P3]=vcolumn(P2)
**
** Store the value of the P2-th column of
** the row of the virtual-table that the
** P1 cursor is pointing to into register P3.
************* Begin file vxworks.h ****************************************
Write the %_docsize record
** Number of entries in a hash table
Number of leaf blocks added this trans
Return a pointer to the buffer containing the record data for SorterRecord
** object p. Should be used as if:
**
** void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
** Return TRUE if the WHERE clause returns rows in ORDER BY order.
** Return FALSE if the output needs to be sorted.
The new rowid
Optional list of result-set columns
Next function with same name
P4 is a 32-bit signed integer
Start of memory holding full result (or 0)
Number of characters in this token
** Locate a VFS by name. If no name is given, simply return the
** first VFS on the list.
** Ensure that the SQLite statement handles required to update the
** target database object currently indicated by the iterator passed
** as the second argument are available.
Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only
** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT.
comment:
** The charMap() macro maps alphabetic characters (only) into their
** lower-case ASCII equivalent. On ASCII machines, this is just
** an upper-to-lower case map. On EBCDIC machines we also need
** to adjust the encoding. The mapping is only valid for alphabetics
** which are the only characters for which this feature is used.
**
** Used by keywordhash.h
label: code-design
Not found. If the name we were looking for was temp.sqlite_master
** then change the name to sqlite_temp_master and try again.
** Query the BtShared.pHasContent vector.
**
** This function is called when a free-list leaf page is removed from the
** free-list for reuse. It returns false if it is safe to retrieve the
** page from the pager layer with the 'no-content' flag set. True otherwise.
** Connect to or create a statvfs virtual table.
OP_OpenRead or OP_OpenWrite
True for UPDATE that affects rowid
** Add a single OP_Explain instruction to the VDBE to explain a simple
** count(*) query ("SELECT count(*) FROM pTab").
** Argument pIn points to the first character in what is expected to be
** a comma-separated list of SQL literals followed by a ')' character.
** If it actually is this, return a pointer to the ')'. Otherwise, return
** NULL to indicate a parse error.
C-style comments
if >0, constraint is part of argv to xFilter
Pause time in microseconds
** json_replace(JSON, PATH, VALUE, ...)
**
** Replace the value at PATH with VALUE. If PATH does not already exist,
** this routine is a no-op. If JSON or PATH is malformed, throw an error.
SQLITE_ENABLE_SNAPSHOT
** The interface to the code in fault.c used for identifying "benign"
** malloc failures. This is only present if SQLITE_UNTESTABLE
** is not defined.
If we reach this point, the frame is valid. Return the page number
** and the new database size.
Add the new session object to the linked list of session objects
** attached to database handle $db. Do this under the cover of the db
** handle mutex.
Case 3: (SELECT ... FROM ...)
** or: EXISTS(SELECT ... FROM ...)
**
** For a SELECT, generate code to put the values for all columns of
** the first row into an array of registers and return the index of
** the first register.
**
** If this is an EXISTS, write an integer 0 (not exists) or 1 (exists)
** into a register and return that register number.
**
** In both cases, the query is augmented with "LIMIT 1". Any
** preexisting limit is discarded in place of the new LIMIT 1.
150
** CAPI3REF: Device Characteristics
**
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
** object returns an integer which is a vector of these
** bit values expressing I/O characteristics of the mass storage
** device that holds the file that the [sqlite3_io_methods]
** refers to.
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
** after reboot following a crash or power loss, the only bytes in a
** file that were written at the application level might have changed
** and that adjacent bytes, even bytes within the same sector are
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
** flag indicates that a file cannot be deleted when open. The
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
** read-only media and cannot be changed even by processes with
** elevated privileges.
** Estimate the total row width for a table.
(319) database_kw_opt ::= DATABASE
When converting from UTF-16, the maximum growth results from
** translating a 2-byte character to a 4-byte UTF-8 character.
** A single byte is required for the output string
** nul-terminator.
The database the table is being created in
Opcode: Add P1 P2 P3 * *
** Synopsis: r[P3]=r[P1]+r[P2]
**
** Add the value in register P1 to the value in register P2
** and store the result in register P3.
** If either input is NULL, the result is NULL.
eidlist_opt
comment: Enable the lookaside-malloc subsystem
label: code-design
Memory mapped page to return
Mask of operations to perform
144
** This function compares two index or table record keys in the same way
** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
** this function deserializes and compares values using the
** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
** in assert() statements to ensure that the optimized code in
** sqlite3VdbeRecordCompare() returns results with these two primitives.
**
** Return true if the result of comparison is equivalent to desiredResult.
** Return false if there is a disagreement.
the LHS of the IN operator
Decomposition of the WHERE clause
Maximum string length
112
110
Address of the output-B subroutine
Number of components of the PRIMARY KEY
Array of replacement values
Makes OP_Jump below testable
Original SQL parameter values
If the database page size is not a power of two, or is greater than
** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
** data. Similarly, if the 'magic' value is invalid, ignore the whole
** WAL file.
No locking occurs in temporary files
291
Number of usable bytes on a page
Allowed values for sqlite3_userauth.authLevel
Name of OS function that failed
comment:
** The interface to the virtual-table mechanism defined above (back up
** to a comment remarkably similar to this one) is currently considered
** to be experimental. The interface might change in incompatible ways.
** If this is a problem for you, do not use the interface at this time.
**
** When the virtual-table mechanism stabilizes, we will declare the
** interface fixed, support it indefinitely, and remove this comment.
label: code-design
refargs ::=
** 2015-06-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains C code to implement the TreeView debugging routines.
** These routines print a parse tree to standard output for debugging and
** analysis.
**
** The interfaces in this file is only available when compiling
** with SQLITE_DEBUG.
comment:
** 2008 December 3
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This module implements an object we call a "RowSet".
**
** The RowSet object is a collection of rowids. Rowids
** are inserted into the RowSet in an arbitrary order. Inserts
** can be intermixed with tests to see if a given rowid has been
** previously inserted into the RowSet.
**
** After all inserts are finished, it is possible to extract the
** elements of the RowSet in sorted order. Once this extraction
** process has started, no new elements may be inserted.
**
** Hence, the primitive operations for a RowSet are:
**
** CREATE
** INSERT
** TEST
** SMALLEST
** DESTROY
**
** The CREATE and DESTROY primitives are the constructor and destructor,
** obviously. The INSERT primitive adds a new element to the RowSet.
** TEST checks to see if an element is already in the RowSet. SMALLEST
** extracts the least value from the RowSet.
**
** The INSERT primitive might allocate additional memory. Memory is
** allocated in chunks so most INSERTs do no allocation. There is an
** upper bound on the size of allocated memory. No memory is freed
** until DESTROY.
**
** The TEST primitive includes a "batch" number. The TEST primitive
** will only see elements that were inserted before the last change
** in the batch number. In other words, if an INSERT occurs between
** two TESTs where the TESTs have the same batch nubmer, then the
** value added by the INSERT will not be visible to the second TEST.
** The initial batch number is zero, so if the very first TEST contains
** a non-zero batch number, it will see all prior INSERTs.
**
** No INSERTs may occurs after a SMALLEST. An assertion will fail if
** that is attempted.
**
** The cost of an INSERT is roughly constant. (Sometimes new memory
** has to be allocated on an INSERT.) The cost of a TEST with a new
** batch number is O(NlogN) where N is the number of elements in the RowSet.
** The cost of a TEST using the same batch number is O(logN). The cost
** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
** primitives are constant time. The cost of DESTROY is O(N).
**
** TEST and SMALLEST may not be used by the same RowSet. This used to
** be possible, but the feature was not used, so it was removed in order
** to simplify the code.
label: code-design
Linked list of coded triggers
rowid <= ?
Disable database changes
If creating a master or main-file journal, this function will open
** a file-descriptor on the directory too. The first time unixSync()
** is called the directory file descriptor will be fsync()ed and close()d.
** xSetOutputs callback used when the Fts5Colset object has nCol==0 (match
** against no columns at all).
** Add a docid/column/position entry to a PendingList structure. Non-zero
** is returned if the structure is sqlite3_realloced as part of adding
** the entry. Otherwise, zero.
**
** If an OOM error occurs, *pRc is set to SQLITE_NOMEM before returning.
** Zero is always returned in this case. Otherwise, if no OOM error occurs,
** it is set to SQLITE_OK.
Number of user columns in table
** Swap the contents of buffer *p1 with that of *p2.
The WhereLoop factory
End of pWC->a[]
True if pDest has a UNIQUE index
Registers used by LIMIT and OFFSET
Size of first block written to WAL file
** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
** based on the sub-platform)?
If non-delete entry should be written
Ticket #1863. To avoid a creating security problems for older
** applications that relink against newer versions of SQLite, the
** ability to run load_extension is turned off by default. One
** must call either sqlite3_enable_load_extension(db) or
** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
** to turn on extension loading.
comment:
** This is part of the fts5_decode() debugging aid.
**
** Arguments pBlob/nBlob contain an "averages" record. This function
** appends a human-readable representation of record to the buffer passed
** as the second argument.
label: code-design
Index into the cell pointer array
Information about the ORDER BY clause
OUT: Bitmask of terms to highlight
The slot remains on the free-list. Reduce its size to account
** for the portion used by the new allocation.
EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra
** spaces at the end of either string do not change the result. In other
** words, strings will compare equal to one another as long as they
** differ only in the number of spaces at the end.
SQLITE_LOCK_TRACE
This call makes sure that the pager has the correct number of
** open savepoints. If the second parameter is greater than 0 and
** the sub-journal is not already open, then it will be opened here.
Condition that must be true
Size of TOP vector
First list to merge
** Generate code that will evaluate all == and IN constraints for an
** index scan.
**
** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
** Suppose the WHERE clause is this: a==5 AND b IN (1,2,3) AND c>5 AND c<10
** The index has as many as three equality constraints, but in this
** example, the third "c" value is an inequality. So only two
** constraints are coded. This routine will generate code to evaluate
** a==5 and b IN (1,2,3). The current values for a and b will be stored
** in consecutive registers and the index of the first register is returned.
**
** In the example above nEq==2. But this subroutine works for any value
** of nEq including 0. If nEq==0, this routine is nearly a no-op.
** The only thing it does is allocate the pLevel->iMem memory cell and
** compute the affinity string.
**
** The nExtraReg parameter is 0 or 1. It is 0 if all WHERE clause constraints
** are == or IN and are covered by the nEq. nExtraReg is 1 if there is
** an inequality constraint (such as the "c>=5 AND c<10" in the example) that
** occurs after the nEq quality constraints.
**
** This routine allocates a range of nEq+nExtraReg memory cells and returns
** the index of the first memory cell in that range. The code that
** calls this routine will use that memory range to store keys for
** start and termination conditions of the loop.
** key value of the loop. If one or more IN operators appear, then
** this routine allocates an additional nEq memory cells for internal
** use.
**
** Before returning, *pzAff is set to point to a buffer containing a
** copy of the column affinity string of the index allocated using
** sqlite3DbMalloc(). Except, entries in the copy of the string associated
** with equality constraints that use BLOB or NONE affinity are set to
** SQLITE_AFF_BLOB. This is to deal with SQL such as the following:
**
** CREATE TABLE t1(a TEXT PRIMARY KEY, b);
** SELECT ... FROM t1 AS t2, t1 WHERE t1.a = t2.b;
**
** In the example above, the index on t1(a) has TEXT affinity. But since
** the right hand side of the equality constraint (t2.b) has BLOB/NONE affinity,
** no conversion should be attempted before using a t2.b value as part of
** a key to search the index. Hence the first byte in the returned affinity
** string in this example would be set to SQLITE_AFF_BLOB.
expr ::= expr CONCAT expr
Include ICU headers
Bytes of data currently in memory
Number of entries in aSegment[]
(306) expr ::= term (OPTIMIZED OUT)
Built-in typeof() function
In some circumstances, we are able to run the xfer optimization
** only if the destination table is initially empty. Unless the
** SQLITE_Vacuum flag is set, this block generates code to make
** that determination. If SQLITE_Vacuum is set, then the destination
** table is always empty.
**
** Conditions under which the destination must be empty:
**
** (1) There is no INTEGER PRIMARY KEY but there are indices.
** (If the destination is not initially empty, the rowid fields
** of index entries might need to change.)
**
** (2) The destination has a unique index. (The xfer optimization
** is unable to test uniqueness.)
**
** (3) onError is something other than OE_Abort and OE_Rollback.
** A CellArray object contains a cache of pointers and sizes for a
** consecutive sequence of cells that might be held on multiple pages.
Dispatch all page fetch requests to the appropriate getter method.
In most cases, we should be able to acquire the lock we
** want without having to go through the ascending lock
** procedure that follows. Just be sure not to block.
IN/OUT: Current offset
Unimplemented version 3 methods
Determine which, if any, tokens in the expression should be deferred.
Ignore the error. Do not do the INSERT or UPDATE
The new record
** It is already known that pMem contains an unterminated string.
** Add the zero terminator.
file desc to assoc this lock with
** Invoke the conflict handler for the change that the changeset iterator
** currently points to.
**
** Argument eType must be either CHANGESET_DATA or CHANGESET_CONFLICT.
** If argument pbReplace is NULL, then the type of conflict handler invoked
** depends solely on eType, as follows:
**
** eType value Value passed to xConflict
** -------------------------------------------------
** CHANGESET_DATA CHANGESET_NOTFOUND
** CHANGESET_CONFLICT CHANGESET_CONSTRAINT
**
** Or, if pbReplace is not NULL, then an attempt is made to find an existing
** record with the same primary key as the record about to be deleted, updated
** or inserted. If such a record can be found, it is available to the conflict
** handler as the "conflicting" record. In this case the type of conflict
** handler invoked is as follows:
**
** eType value PK Record found? Value passed to xConflict
** ----------------------------------------------------------------
** CHANGESET_DATA Yes CHANGESET_DATA
** CHANGESET_DATA No CHANGESET_NOTFOUND
** CHANGESET_CONFLICT Yes CHANGESET_CONFLICT
** CHANGESET_CONFLICT No CHANGESET_CONSTRAINT
**
** If pbReplace is not NULL, and a record with a matching PK is found, and
** the conflict handler function returns SQLITE_CHANGESET_REPLACE, *pbReplace
** is set to non-zero before returning SQLITE_OK.
**
** If the conflict handler returns SQLITE_CHANGESET_ABORT, SQLITE_ABORT is
** returned. Or, if the conflict handler returns an invalid value,
** SQLITE_MISUSE. If the conflict handler returns SQLITE_CHANGESET_OMIT,
** this function returns SQLITE_OK.
************************************************************************
** CUSTOM AUXILIARY FUNCTIONS
**
** Virtual table implementations may overload SQL functions by implementing
** the sqlite3_module.xFindFunction() method.
OP_OpenWrite cursors for the ONEPASS opt
** Array apCell[] contains pointers to nCell b-tree page cells. The
** szCell[] array contains the size in bytes of each cell. This function
** replaces the current contents of page pPg with the contents of the cell
** array.
**
** Some of the cells in apCell[] may currently be stored in pPg. This
** function works around problems caused by this by making a copy of any
** such cells before overwriting the page data.
**
** The MemPage.nFree field is invalidated by this function. It is the
** responsibility of the caller to set it correctly.
Total number of phrase instances
Last leaf page number in segment
Size of buffer zTerm
Name of the module for the virtual table
If one value is a string and the other is a blob, the string is less.
** If both are strings, compare using the collating functions.
Calculate the average document length for this FTS5 table
80
Additional values that can be added to the sync_flags argument of
** sqlite3WalFrames():
Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
** the PENDING_LOCK byte is temporary.
Size of aIndex[]
Cursor number to use
Open transactions both databases. The *-oal file is opened or
** created at this point.
** Argument pLevel describes a strategy for scanning table pTab. This
** function appends text to pStr that describes the subset of table
** rows scanned by the strategy in the form of an SQL expression.
**
** For example, if the query:
**
** SELECT * FROM t1 WHERE a=1 AND b>2;
**
** is run and there is an index on (a, b), then this function returns a
** string similar to:
**
** "a=? AND b>?"
How many seg-readers to advance
** Zero the contents of the buffer object. But do not free the associated
** memory allocation.
IN/OUT: Tokens in phrase of *paPoslist
Level to add scanstatus() entry for
Free any outstanding Savepoint structures.
OUT: Write the answer here
The SELECT statement being coded.
** An instance of the following object is used to record information about
** how to process the DISTINCT keyword, to simplify passing that information
** into the selectInnerLoop() routine.
If there is no type specified, columns have the default affinity
** 'BLOB'.
comment: Read and write the xxx_rowid table
label: code-design
Check if any samples from the aBest[] array should be pushed
** into IndexSample.a[] at this point.
comment:
** CAPI3REF: Mutex Handle
**
** The mutex module within SQLite defines [sqlite3_mutex] to be an
** abstract type for a mutex object. The SQLite core never looks
** at the internal representation of an [sqlite3_mutex]. It only
** deals with pointers to the [sqlite3_mutex] object.
**
** Mutexes are created using [sqlite3_mutex_alloc()].
label: code-design
** Return the name of a wildcard parameter. Return NULL if the index
** is out of range or if the wildcard is unnamed.
**
** The result is always UTF-8.
The complete select statement being coded
Set to update db->lastRowid
Sync the db file if currently doing an incremental checkpoint
188
Pointer to Fts5Global object
** Finalize the statement handle at pCsr->pStmt.
**
** Or, if that statement handle is one created by fts3CursorSeekStmt(),
** and the Fts3Table.pSeekStmt slot is currently NULL, save the statement
** pointer there instead of finalizing it.
** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
** routine does *not* accept hexadecimal notation.
**
** If the zNum value is representable as a 64-bit twos-complement
** integer, then write that value into *pNum and return 0.
**
** If zNum is exactly 9223372036854775808, return 2. This special
** case is broken out because while 9223372036854775808 cannot be a
** signed 64-bit integer, its negative -9223372036854775808 can be.
**
** If zNum is too big for a 64-bit integer and is not
** 9223372036854775808 or if zNum contains any non-numeric text,
** then return 1.
**
** length is the number of bytes in the string (bytes, not characters).
** The string is not necessarily zero-terminated. The encoding is
** given by enc.
1490
Low-level mutex interface
expr ::= CAST LP expr AS typetoken RP
Look up the table being altered.
** Allocate or return the aggregate context for a user function. A new
** context is allocated on the first call. Subsequent calls return the
** same context that was returned on prior calls.
The module for this tokenizer
** Read the last entry (most recently pushed) from the hint blob *pHint
** and then remove the entry. Write the two values read to *piAbsLevel and
** *pnInput before returning.
**
** If no error occurs, return SQLITE_OK. If the hint blob in *pHint does
** not contain at least two valid varints, return SQLITE_CORRUPT_VTAB.
Restriction 17: If the sub-query is a compound SELECT, then it must
** use only the UNION ALL operator. And none of the simple select queries
** that make up the compound SELECT are allowed to be aggregate or distinct
** queries.
True for a savepoint rollback
The parse context of the CREATE TRIGGER statement
2nd parameter to sqlite3_bind out of range
comment: Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
** OP_VNext, or OP_SorterNext) all jump here upon
** completion. Check to see if sqlite3_interrupt() has been called
** or if the progress callback needs to be invoked.
**
** This code uses unstructured "goto" statements and does not look clean.
** But that is not due to sloppy coding habits. The code is written this
** way for performance, to avoid having to run the interrupt and progress
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
** faster according to "valgrind --tool=cachegrind"
label: code-design
Shared memory associated with this inode
Expr. to advance to next matching row
Root page of table
** This is called to code the required FOR EACH ROW triggers for an operation
** on table pTab. The operation to code triggers for (INSERT, UPDATE or DELETE)
** is given by the op parameter. The tr_tm parameter determines whether the
** BEFORE or AFTER triggers are coded. If the operation is an UPDATE, then
** parameter pChanges is passed the list of columns being modified.
**
** If there are no triggers that fire at the specified time for the specified
** operation on pTab, this function is a no-op.
**
** The reg argument is the address of the first in an array of registers
** that contain the values substituted for the new.* and old.* references
** in the trigger program. If N is the number of columns in table pTab
** (a copy of pTab->nCol), then registers are populated as follows:
**
** Register Contains
** ------------------------------------------------------
** reg+0 OLD.rowid
** reg+1 OLD.* value of left-most column of pTab
** ... ...
** reg+N OLD.* value of right-most column of pTab
** reg+N+1 NEW.rowid
** reg+N+2 OLD.* value of left-most column of pTab
** ... ...
** reg+N+N+1 NEW.* value of right-most column of pTab
**
** For ON DELETE triggers, the registers containing the NEW.* values will
** never be accessed by the trigger program, so they are not allocated or
** populated by the caller (there is no data to populate them with anyway).
** Similarly, for ON INSERT triggers the values stored in the OLD.* registers
** are never accessed, and so are not allocated by the caller. So, for an
** ON INSERT trigger, the value passed to this function as parameter reg
** is not a readable register, although registers (reg+N) through
** (reg+N+N+1) are.
**
** Parameter orconf is the default conflict resolution algorithm for the
** trigger program to use (REPLACE, IGNORE etc.). Parameter ignoreJump
** is the instruction that control should jump to if a trigger program
** raises an IGNORE exception.
comment:
** The SQLITE_AFF_MASK values masks off the significant bits of an
** affinity value.
label: code-design
INSERT_CONTENT
*************************** sqlite3_value_ *******************************
** The following routines extract information from a Mem or sqlite3_value
** structure.
** This is a magic string that appears at the beginning of every
** SQLite database in order to identify the file as a real database.
**
** You can change this value at compile-time by specifying a
** -DSQLITE_FILE_HEADER="..." on the compiler command-line. The
** header must be exactly 16 bytes including the zero-terminator so
** the string itself should be 15 characters long. If you change
** the header, then your custom library will not be able to read
** databases generated by the standard tools and the standard tools
** will not be able to read databases created by your custom library.
one of TK_DELETE, TK_INSERT, TK_UPDATE
Built-in coalesce() or ifnull()
Amount of payload held locally, not on overflow
** Deallocate and destroy a parser. Destructors are called for
** all stack elements before shutting the parser down.
**
** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it
** is defined in a %include section of the input grammar) then it is
** assumed that the input pointer is never NULL.
List of names of LHS of the assignment
** CAPI3REF: Authorizer Action Codes
**
** The [sqlite3_set_authorizer()] interface registers a callback function
** that is invoked to authorize certain SQL statement actions. The
** second parameter to the callback is an integer code that specifies
** what action is being authorized. These are the integer action codes that
** the authorizer callback may be passed.
**
** These action code values signify what kind of operation is to be
** authorized. The 3rd and 4th parameters to the authorization
** callback function will be parameters or NULL depending on which of these
** codes is used as the second parameter. ^(The 5th parameter to the
** authorizer callback is the name of the database ("main", "temp",
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
** is the name of the inner-most trigger or view that is responsible for
** the access attempt or NULL if this access attempt is directly from
** top-level SQL code.
Fall through for the RTREE_EQ case
End if( affinity_ok )
** Eqivalent to:
**
** char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
Check the table schemas match
New object to return
** Implementation of the instr() function.
**
** instr(haystack,needle) finds the first occurrence of needle
** in haystack and returns the number of previous characters plus 1,
** or 0 if needle does not occur within haystack.
**
** If both haystack and needle are BLOBs, then the result is one more than
** the number of bytes in haystack prior to the first occurrence of needle,
** or 0 if needle never occurs in haystack.
The database file
Verify that the database still has the same name as it did when
** it was originally opened.
7: (start_constraints && startEq && bRev)
Iterator object
** Return a pointer to the name of a variable in the given VList that
** has the value iVal. Or return a NULL if there is no such variable in
** the list
Available backtrace slots
comment:
** Exactly one of the following macros must be defined in order to
** specify which memory allocation subsystem to use.
**
** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
** SQLITE_WIN32_MALLOC // Use Win32 native heap API
** SQLITE_ZERO_MALLOC // Use a stub allocator that always fails
** SQLITE_MEMDEBUG // Debugging version of system malloc()
**
** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the
** assert() macro is enabled, each call into the Win32 native heap subsystem
** will cause HeapValidate to be called. If heap validation should fail, an
** assertion will be triggered.
**
** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
** the default.
label: code-design
Index in p->aIndex[]
Pointer to blob containing changeset
Index in sqlite3.aDb[] of database holding pTab
The shared memory being locked
Input data
Fill in the header.
Create the SELECT statement to read keys from data_xxx
** CAPI3REF: Generate A Changeset From A Session Object
**
** Obtain a changeset containing changes to the tables attached to the
** session object passed as the first argument. If successful,
** set *ppChangeset to point to a buffer containing the changeset
** and *pnChangeset to the size of the changeset in bytes before returning
** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
** zero and return an SQLite error code.
**
** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
** each representing a change to a single row of an attached table. An INSERT
** change contains the values of each field of a new database row. A DELETE
** contains the original values of each field of a deleted database row. An
** UPDATE change contains the original values of each field of an updated
** database row along with the updated values for each updated non-primary-key
** column. It is not possible for an UPDATE change to represent a change that
** modifies the values of primary key columns. If such a change is made, it
** is represented in a changeset as a DELETE followed by an INSERT.
**
** Changes are not recorded for rows that have NULL values stored in one or
** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
** no corresponding change is present in the changesets returned by this
** function. If an existing row with one or more NULL values stored in
** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
** only an INSERT is appears in the changeset. Similarly, if an existing row
** with non-NULL PRIMARY KEY values is updated so that one or more of its
** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
** DELETE change only.
**
** The contents of a changeset may be traversed using an iterator created
** using the [sqlite3changeset_start()] API. A changeset may be applied to
** a database with a compatible schema using the [sqlite3changeset_apply()]
** API.
**
** Within a changeset generated by this function, all changes related to a
** single table are grouped together. In other words, when iterating through
** a changeset or when applying a changeset to a database, all changes related
** to a single table are processed before moving on to the next table. Tables
** are sorted in the same order in which they were attached (or auto-attached)
** to the sqlite3_session object. The order in which the changes related to
** a single table are stored is undefined.
**
** Following a successful call to this function, it is the responsibility of
** the caller to eventually free the buffer that *ppChangeset points to using
** [sqlite3_free()].
**
** <h3>Changeset Generation</h3>
**
** Once a table has been attached to a session object, the session object
** records the primary key values of all new rows inserted into the table.
** It also records the original primary key and other column values of any
** deleted or updated rows. For each unique primary key value, data is only
** recorded once - the first time a row with said primary key is inserted,
** updated or deleted in the lifetime of the session.
**
** There is one exception to the previous paragraph: when a row is inserted,
** updated or deleted, if one or more of its primary key columns contain a
** NULL value, no record of the change is made.
**
** The session object therefore accumulates two types of records - those
** that consist of primary key values only (created when the user inserts
** a new record) and those that consist of the primary key values and the
** original values of other table columns (created when the users deletes
** or updates a record).
**
** When this function is called, the requested changeset is created using
** both the accumulated records and the current contents of the database
** file. Specifically:
**
** <ul>
** <li> For each record generated by an insert, the database is queried
** for a row with a matching primary key. If one is found, an INSERT
** change is added to the changeset. If no such row is found, no change
** is added to the changeset.
**
** <li> For each record generated by an update or delete, the database is
** queried for a row with a matching primary key. If such a row is
** found and one or more of the non-primary key fields have been
** modified from their original values, an UPDATE change is added to
** the changeset. Or, if no such row is found in the table, a DELETE
** change is added to the changeset. If there is a row with a matching
** primary key in the database, but all fields contain their original
** values, no change is added to the changeset.
** </ul>
**
** This means, amongst other things, that if a row is inserted and then later
** deleted while a session object is active, neither the insert nor the delete
** will be present in the changeset. Or if a row is deleted and then later a
** row with the same primary key values inserted while a session object is
** active, the resulting changeset will contain an UPDATE change instead of
** a DELETE and an INSERT.
**
** When a session object is disabled (see the [sqlite3session_enable()] API),
** it does not accumulate records when rows are inserted, updated or deleted.
** This may appear to have some counter-intuitive effects if a single row
** is written to more than once during a session. For example, if a row
** is inserted while a session object is enabled, then later deleted while
** the same session object is disabled, no INSERT record will appear in the
** changeset, even though the delete took place while the session was disabled.
** Or, if one field of a row is updated while a session is disabled, and
** another field of the same row is updated while the session is enabled, the
** resulting changeset will contain an UPDATE change that updates both fields.
Page being freed. May be NULL.
The 6th parameter to db->xAuth callbacks
VACUUM
A sorting index used to test for distinctness
Local copy of initial highlight-mask
yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0
** Obtain a reference to an r-tree node.
Reinstall the LIKE and GLOB functions. The variant of LIKE
** used will be case sensitive or not depending on the RHS.
SQLITE_AFF_NUMERIC
comment: Set the magic to VDBE_MAGIC_RUN sooner rather than later.
label: code-design
Figure out the best index to use to search a pragma virtual table.
**
** There are not really any index choices. But we want to encourage the
** query planner to give == constraints on as many hidden parameters as
** possible, and especially on the first hidden parameter. So return a
** high cost if hidden parameters are unconstrained.
If the page being moved is dirty and has not been saved by the latest
** savepoint, then save the current contents of the page into the
** sub-journal now. This is required to handle the following scenario:
**
** BEGIN;
** <journal page X, then modify it in memory>
** SAVEPOINT one;
** <Move page X to location Y>
** ROLLBACK TO one;
**
** If page X were not written to the sub-journal here, it would not
** be possible to restore its contents when the "ROLLBACK TO one"
** statement were is processed.
**
** subjournalPage() may need to allocate space to store pPg->pgno into
** one or more savepoint bitvecs. This is the reason this function
** may return SQLITE_NOMEM.
Number of unixShm objects pointing to this
** Make sure the TEMP database is open and available for use. Return
** the number of errors. Leave any error messages in the pParse structure.
Records are always returned in ascending order of (name, path).
** If this will satisfy the client, set the orderByConsumed flag so that
** SQLite does not do an external sort.
Last insert rowid (sqlite3.lastRowid)
** Return the full pathname of the underlying database file. Return
** an empty string if the database is in-memory or a TEMP database.
**
** The pager filename is invariant as long as the pager is
** open so it is safe to access without the BtShared mutex.
Map from parent key columns to child table columns
key_opt ::= KEY expr
The record flows over onto one or more overflow pages. In
** this case the whole cell needs to be parsed, a buffer allocated
** and accessPayload() used to retrieve the record into the
** buffer before VdbeRecordCompare() can be called.
**
** If the record is corrupt, the xRecordCompare routine may read
** up to two varints past the end of the buffer. An extra 18
** bytes of padding is allocated at the end of the buffer in
** case this happens.
1270
** The page that pCur currently points to has just been modified in
** some way. This function figures out if this modification means the
** tree needs to be balanced, and if so calls the appropriate balancing
** routine. Balancing routines are:
**
** balance_quick()
** balance_deeper()
** balance_nonroot()
Loop through the returned columns. Set nStr to the number of bytes of
** space required to store a copy of each column name, including the
** nul-terminator byte.
True for first term on page
** 2008 June 13
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains definitions of global variables and constants.
comment:
** hwtime.h contains inline assembler code for implementing
** high-performance timing routines.
label: code-design
******* End of sqlite3session.h ********
** Unlock a file region.
Check if this is to be a periodic sample. If so, add it.
Step 5. If a usable page buffer has still not been found,
** attempt to allocate a new one.
IF => ID
Bytes of data
** Count the number of fullsyncs and normal syncs. This is used to test
** that syncs and fullsyncs are occuring at the right times.
lastErrno set by seekAndRead
** Object used to represent a single file opened and mmapped to provide
** shared memory. When multiple threads all reference the same
** log-summary, each thread has its own winFile object, but they all
** point to a single instance of this object. In other words, each
** log-summary is opened only once per process.
**
** winShmMutexHeld() must be true when creating or destroying
** this object or while reading or writing the following fields:
**
** nRef
** pNext
**
** The following fields are read-only after the object is created:
**
** fid
** zFilename
**
** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
** winShmMutexHeld() is true when reading or writing any other field
** in this structure.
**
Size of buffer containing root node
Contents of table pTab
Term to scan doclist of
Size of buffer at aNode (or 0)
Number of dirty pages as a percentage of the configured cache size
If the INSERT statement included an IDLIST term, then make sure
** all elements of the IDLIST really are columns of the table and
** remember the column indices.
**
** If the table has an INTEGER PRIMARY KEY column and that column
** is named in the IDLIST, then record in the ipkColumn variable
** the index into IDLIST of the primary key column. ipkColumn is
** the index of the primary key as it appears in IDLIST, not as
** is appears in the original table. (The index of the INTEGER
** PRIMARY KEY in the original table is pTab->iPKey.)
** The CHECK_PAGE macro takes a PgHdr* as an argument. If SQLITE_CHECK_PAGES
** is defined, and NDEBUG is not defined, an assert() statement checks
** that the page is either dirty or still matches the calculated page-hash.
create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm
comment:
** If there are currently more than nMaxPage pages allocated, try
** to recycle pages to reduce the number allocated to nMaxPage.
label: code-design
True if checksums in WAL are big-endian
The condition (pIter->eLock!=eLock) in the following if(...)
** statement is a simplification of:
**
** (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
**
** since we know that if eLock==WRITE_LOCK, then no other connection
** may hold a WRITE_LOCK on any table in this file (since there can
** only be a single writer).
comment:
** Initialize the temporary index cursor just opened as a sorter cursor.
**
** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
** to determine the number of fields that should be compared from the
** records being sorted. However, if the value passed as argument nField
** is non-zero and the sorter is able to guarantee a stable sort, nField
** is used instead. This is used when sorting records for a CREATE INDEX
** statement. In this case, keys are always delivered to the sorter in
** order of the primary key, which happens to be make up the final part
** of the records being sorted. So if the sort is stable, there is never
** any reason to compare PK fields and they can be ignored for a small
** performance boost.
**
** The sorter can guarantee a stable sort when running in single-threaded
** mode, but not in multi-threaded mode.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
label: code-design
comment: Term to query for
label: code-design
30
Return the new journal mode
The escape character
OUT: Set to true if dequoting required
cmd ::= ATTACH database_kw_opt expr AS expr key_opt
Used to be a conditional
SQL functions can be expensive. So try to move constant functions
** out of the inner loop, even if that means an extra OP_Copy.
** Processing is determine by the affinity parameter:
**
** SQLITE_AFF_INTEGER:
** SQLITE_AFF_REAL:
** SQLITE_AFF_NUMERIC:
** Try to convert pRec to an integer representation or a
** floating-point representation if an integer representation
** is not possible. Note that the integer representation is
** always preferred, even if the affinity is REAL, because
** an integer representation is more space efficient on disk.
**
** SQLITE_AFF_TEXT:
** Convert pRec to a text representation.
**
** SQLITE_AFF_BLOB:
** No-op. pRec is unchanged.
The page cache
Sorter task to read from
Column of table to populate aTerm for
Return the total number of pages stored in the cache
First element already in pEntry
REPLACE_CONFIG
Name of fts5 table
Number of bytes of data space
True if initialized
Value for "leaves_end_block" field
(276) ecmd ::= explain cmdx SEMI
Write the next key to the output.
bMemstat
Value of %_segdir.leaves_end_block
Requested snippet length (in tokens)
Find the iHash'th table
End for loop over the format string
Use this buffer for space if required
Number of memory cells required
side-effects-ok
If WHERE_OR_SUBCLAUSE is set, index cursor number
** If WHERE_USE_LIMIT, then the limit amount
0x04
The record-size field is a 2 byte varint and the record
** fits entirely on the main b-tree page.
Cursor from which column data is extracted
varint containing prefix size
** Read the contents of frame iRead from the wal file into buffer pOut
** (which is nOut bytes in size). Return SQLITE_OK if successful, or an
** error code otherwise.
defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS)
** Compiling and using WAL mode requires several APIs that are only
** available in Windows platforms based on the NT kernel.
Make sure the locking sequence is correct
Send data to a co-routine
Cursor that data will be read from
** Erase the eponymous virtual table instance associated with
** virtual table module pMod, if it exists.
OUT: Created tokenizer cursor
Version 3.8.11 and later
comment:
** Write a 64-bit big-endian integer value to the buffer aBuf[].
label: code-design
** This routine is called by the parser to add a new term to the
** end of a growing FROM clause. The "p" parameter is the part of
** the FROM clause that has already been constructed. "p" is NULL
** if this is the first term of the FROM clause. pTable and pDatabase
** are the name of the table and database named in the FROM clause term.
** pDatabase is NULL if the database name qualifier is missing - the
** usual case. If the term has an alias, then pAlias points to the
** alias token. If the term is a subquery, then pSubquery is the
** SELECT statement that the subquery encodes. The pTable and
** pDatabase parameters are NULL for subqueries. The pOn and pUsing
** parameters are the content of the ON and USING clauses.
**
** Return a new SrcList which encodes is the FROM with the new
** term added.
Can only happen following on OOM
** A total of nLeaf leaf pages of data has just been flushed to a level-0
** segment. This function updates the write-counter accordingly and, if
** necessary, performs incremental merge work.
**
** If an error occurs, set the Fts5Index.rc error code. If an error has
** already occurred, this function is a no-op.
** VDBE Calling Convention
** -----------------------
**
** Example:
**
** For the following INSERT statement:
**
** CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
** INSERT INTO t1 VALUES(1, 2, 3.1);
**
** Register (x): 2 (type integer)
** Register (x+1): 1 (type integer)
** Register (x+2): NULL (type NULL)
** Register (x+3): 3.1 (type real)
Data for current page of this level
** pE is a pointer to an expression which is a single term in the
** ORDER BY of a compound SELECT. The expression has not been
** name resolved.
**
** At the point this routine is called, we already know that the
** ORDER BY term is not an integer index into the result set. That
** case is handled by the calling routine.
**
** Attempt to match pE against result set columns in the left-most
** SELECT statement. Return the index i of the matching column,
** as an indication to the caller that it should sort by the i-th column.
** The left-most column is 1. In other words, the value returned is the
** same integer value that would be used in the SQL statement to indicate
** the column.
**
** If there is no match, return 0. Return -1 if an error occurs.
** This function is a complex assert() that verifies the following
** properties of the blocked connections list:
**
** 1) Each entry in the list has a non-NULL value for either
** pUnlockConnection or pBlockingConnection, or both.
**
** 2) All entries in the list that share a common value for
** xUnlockNotify are grouped together.
**
** 3) If the argument db is not NULL, then none of the entries in the
** blocked connections list have pUnlockConnection or pBlockingConnection
** set to db. This is used when closing connection db.
Cells to delete
End attempt to optimize using an index
now insert a "." before the last / character
"SELECT * FROM %_segdir WHERE level = ? ORDER BY ..."
** Set up a raw page so that it looks like a database page holding
** no entries.
The index (1-based) of the term out of range
** CAPI3REF: Cancel Automatic Extension Loading
**
** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
** initialization routine X that was registered using a prior call to
** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
** routine returns 1 if initialization routine X was successfully
** unregistered and it returns 0 if X was not on the list of initialization
** routines.
seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt
The subroutine that manifests the view might be a one-time routine,
** or it might need to be rerun on each iteration because it
** encodes a correlated subquery.
** Write a varint with value iVal into the buffer at aBuf. Return the
** number of bytes written.
Need to invoke convertCompoundSelectToSubquery()
** Return true if the area covered by p2 is a subset of the area covered
** by p1. False otherwise.
True if the loop has UNIQUE NOT NULL columns
If this is an AUTOINCREMENT table, look up the sequence number in the
** sqlite_sequence table and store it in memory cell regAutoinc.
Size of array at aElem
** An open write-ahead log file is represented by an instance of the
** following object.
xCreate
** Figure out what version of the code to use. The choices are
**
** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
** mutexes implementation cannot be overridden
** at start-time.
**
** SQLITE_MUTEX_NOOP For single-threaded applications. No
** mutual exclusion is provided. But this
** implementation can be overridden at
** start-time.
**
** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
**
** SQLITE_MUTEX_W32 For multi-threaded applications on Win32.
** Return the sector size in bytes of the underlying block device for
** the specified file. This is almost always 512 bytes, but may be
** larger for some devices.
**
** SQLite code assumes this function cannot fail. It also assumes that
** if two files are created in the same file-system directory (i.e.
** a database and its journal file) that the sector size will be the
** same for both.
comment: The following is just a sanity check to make sure SQLite has
** been compiled correctly. It is important to run this code, but
** we don't want to run it too often and soak up CPU cycles for no
** reason. So we run it once during initialization.
label: code-design
** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
** reserved for working around a windows/posix incompatibility). It is
** used in the journal to signify that the remainder of the journal file
** is devoted to storing a master journal name - there are no more pages to
** roll back. See comments for function writeMasterJournal() in pager.c
** for details.
The expired flag was set on the VDBE before the first call
** to sqlite3_step(). For consistency (since sqlite3_step() was
** called), set the database error in this case as well.
If a truth probability is specified using the likelihood() hints,
** then use the probability provided by the application.
Release the locks.
Check if the current entries really are a phrase match
No key specified. Use the key from the main database
1130
OUT: Selected leaf page
comment:
** CAPI3REF: Add A Changeset To A Changegroup
**
** Add all changes within the changeset (or patchset) in buffer pData (size
** nData bytes) to the changegroup.
**
** If the buffer contains a patchset, then all prior calls to this function
** on the same changegroup object must also have specified patchsets. Or, if
** the buffer contains a changeset, so must have the earlier calls to this
** function. Otherwise, SQLITE_ERROR is returned and no changes are added
** to the changegroup.
**
** Rows within the changeset and changegroup are identified by the values in
** their PRIMARY KEY columns. A change in the changeset is considered to
** apply to the same row as a change already present in the changegroup if
** the two rows have the same primary key.
**
** Changes to rows that do not already appear in the changegroup are
** simply copied into it. Or, if both the new changeset and the changegroup
** contain changes that apply to a single row, the final contents of the
** changegroup depends on the type of each change, as follows:
**
** <table border=1 style="margin-left:8ex;margin-right:8ex">
** <tr><th style="white-space:pre">Existing Change </th>
** <th style="white-space:pre">New Change </th>
** <th>Output Change
** <tr><td>INSERT <td>INSERT <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>INSERT <td>UPDATE <td>
** The INSERT change remains in the changegroup. The values in the
** INSERT change are modified as if the row was inserted by the
** existing change and then updated according to the new change.
** <tr><td>INSERT <td>DELETE <td>
** The existing INSERT is removed from the changegroup. The DELETE is
** not added.
** <tr><td>UPDATE <td>INSERT <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>UPDATE <td>UPDATE <td>
** The existing UPDATE remains within the changegroup. It is amended
** so that the accompanying values are as if the row was updated once
** by the existing change and then again by the new change.
** <tr><td>UPDATE <td>DELETE <td>
** The existing UPDATE is replaced by the new DELETE within the
** changegroup.
** <tr><td>DELETE <td>INSERT <td>
** If one or more of the column values in the row inserted by the
** new change differ from those in the row deleted by the existing
** change, the existing DELETE is replaced by an UPDATE within the
** changegroup. Otherwise, if the inserted row is exactly the same
** as the deleted row, the existing DELETE is simply discarded.
** <tr><td>DELETE <td>UPDATE <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>DELETE <td>DELETE <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** </table>
**
** If the new changeset contains changes to a table that is already present
** in the changegroup, then the number of columns and the position of the
** primary key columns for the table must be consistent. If this is not the
** case, this function fails with SQLITE_SCHEMA. If the input changeset
** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
** returned. Or, if an out-of-memory condition occurs during processing, this
** function returns SQLITE_NOMEM. In all cases, if an error occurs the
** final contents of the changegroup is undefined.
**
** If no error occurs, SQLITE_OK is returned.
label: code-design
** Array of lists of free blocks according to the block size
** for smaller chunks, or a hash on the block size for larger
** chunks.
GetVersionEx() is current
If there is no open transaction, then mark this as a special
** "transaction savepoint".
expr ::= expr COLLATE ID|STRING
Error message
** Convert an SQL-style quoted string into a normal string by removing
** the quote characters. The conversion is done in-place. If the
** input does not begin with a quote character, then this routine
** is a no-op.
**
** Examples:
**
** "abc" becomes abc
** 'xyz' becomes xyz
** [pqr] becomes pqr
** `mno` becomes mno
List of active savepoints
If the current node of layer iLayer contains zero keys, or if adding
** the key to it will not cause it to grow to larger than nNodeSize
** bytes in size, write the key here.
** Assign expression b to lvalue a. A second, no-op, version of this macro
** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code
** in sqlite3Select() to assign values to structure member variables that
** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the
** code with #ifndef directives.
Jump here to start the next IN combination
129
Advance the first pCsr->nAdvance entries in the apSegment[] array
** forward. Then sort the list in order of current term again.
Size of segment just written
First page of the overflow chain
xDestroy - Drop a table
** Set the most recent error code and error string for the sqlite
** handle "db". The error code is set to "err_code".
**
** If it is not NULL, string zFormat specifies the format of the
** error string in the style of the printf functions: The following
** format characters are allowed:
**
** %s Insert a string
** %z A string that should be freed after use
** %d Insert an integer
** %T Insert a token
** %S Insert the first element of a SrcList
**
** zFormat and any string tokens that follow it are assumed to be
** encoded in UTF-8.
**
** To clear the most recent error for sqlite handle "db", sqlite3Error
** should be called with err_code set to SQLITE_OK and zFormat set
** to NULL.
1200
** Structures used by the virtual table interface
** Initialize all term iterators in the pNear object. If any term is found
** to match no documents at all, return immediately without initializing any
** further iterators.
**
** If an error occurs, return an SQLite error code. Otherwise, return
** SQLITE_OK. It is not considered an error if some term matches zero
** documents.
Size of record in bytes
Only the first 8 bytes (above) are zeroed by pager.c when a new page
** is allocated. All fields that follow must be initialized before use
SQLITE_ECEL_* flags
5: (start_constraints && !startEq && bRev)
The xColumn method simply returns the corresponding column from
** the PRAGMA.
If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
** NULL, the caller expects a table b-tree. If this is not the case,
** return an SQLITE_CORRUPT error.
**
** Earlier versions of SQLite assumed that this test could not fail
** if the root page was already loaded when this function was called (i.e.
** if pCur->iPage>=0). But this is not so if the database is corrupted
** in such a way that page pRoot is linked into a second b-tree table
** (or the freelist).
Output flags returned to SQLite core
** This function is called before generating code to update or delete a
** row contained in table pTab. If the operation is a DELETE, then
** parameter aChange is passed a NULL value. For an UPDATE, aChange points
** to an array of size N, where N is the number of columns in table pTab.
** If the i'th column is not modified by the UPDATE, then the corresponding
** entry in the aChange[] array is set to -1. If the column is modified,
** the value is 0 or greater. Parameter chngRowid is set to true if the
** UPDATE statement modifies the rowid fields of the table.
**
** If any foreign key processing will be required, this function returns
** non-zero. If there is no foreign key related processing, this function
** returns zero.
**
** For an UPDATE, this function returns 2 if:
**
** * There are any FKs for which pTab is the child and the parent table, or
** * the UPDATE modifies one or more parent keys for which the action is
** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
**
** Or, assuming some other foreign key processing is required, 1.
comment: No memory allocation is ever used on mem1. Prove this using
** the following assert(). If the assert() fails, it indicates a
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
label: code-design
Size of regions
Address of array containing child table row
A result set
** 2007 June 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements a tokenizer for fts3 based on the ICU library.
The szMalloc field holds the correct memory allocation size
Name of the file (UTF-8)
p->flags holds EP_Collate and p->pLeft->flags does not. And
** p->x.pSelect cannot. So if p->x.pLeft exists, it must hold at
** least one EP_Collate. Thus the following two ALWAYS.
comment:
** In addition to its current configuration, have the Fts3MultiSegReader
** passed as the 4th argument also scan the doclist for term zTerm/nTerm.
**
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
label: code-design
** This function starts a write transaction on the WAL.
**
** A read transaction must have already been started by a prior call
** to sqlite3WalBeginReadTransaction().
**
** If another thread or process has written into the database since
** the read transaction was started, then it is not possible for this
** thread to write as doing so would cause a fork. So this routine
** returns SQLITE_BUSY in that case and no write transaction is started.
**
** There can only be a single writer active at a time.
Append to this SrcList. NULL creates a new SrcList
Which tables are currently available
** CAPI3REF: Online Backup Object
**
** The sqlite3_backup object records state information about an ongoing
** online backup operation. ^The sqlite3_backup object is created by
** a call to [sqlite3_backup_init()] and is destroyed by a call to
** [sqlite3_backup_finish()].
**
** See Also: [Using the SQLite Online Backup API]
** Code an OP_TableLock instruction for each table locked by the
** statement (configured by calls to sqlite3TableLock()).
The associated database
** Search the free-list on page pPg for space to store a cell nByte bytes in
** size. If one can be found, return a pointer to the space and remove it
** from the free-list.
**
** If no suitable space can be found on the free-list, return NULL.
**
** This function may detect corruption within pPg. If corruption is
** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
**
** Slots on the free list that are between 1 and 3 bytes larger than nByte
** will be ignored if adding the extra space to the fragmentation count
** causes the fragmentation count to exceed 60.
** Advance iterator pIter to the next entry.
**
** This version of fts5SegIterNext() is only used by reverse iterators.
Make the JSON in p the result of the SQL function.
** Move the iterator passed as the only argument to the previous entry.
Update the sqlite_sequence table by storing the content of the
** maximum rowid counter values recorded while inserting into
** autoincrement tables.
porter rule condition: (m > 1 and (*S or *T))
Append the table key to the end of the index. For WITHOUT ROWID
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
** normal tables (when pPk==0) this will be the rowid.
** In the amalgamation, the parse.c file generated by lemon and the
** tokenize.c file are concatenated. In that case, sqlite3RunParser()
** has access to the the size of the yyParser object and so the parser
** engine can be allocated from stack. In that case, only the
** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked
** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be
** omitted.
pExpr is original. Make a new entry in pAggInfo->aFunc[]
comment: A malloc must have failed
label: code-design
comment: This routine is never used in single-threaded mode
label: requirement
OP_Found will use an unpacked key
Bytes buffered before opening the file
** Return a pointer to a subexpression of pVector that is the i-th
** column of the vector (numbered starting with 0). The caller must
** ensure that i is within range.
**
** If pVector is really a scalar (and "scalar" here includes subqueries
** that return a single column!) then return pVector unmodified.
**
** pVector retains ownership of the returned subexpression.
**
** If the vector is a (SELECT ...) then the expression returned is
** just the expression for the i-th term of the result set, and may
** not be ready for evaluation because the table cursor has not yet
** been positioned.
Payload to be inserted
Return segments in order from oldest to newest.
************* Continuing where we left off in pragma.c ********************
************* Begin file dbstat.c *****************************************
The FTS3 table
Page number array for hash table
OUT: Final checksum value output
************* End of legacy.c *********************************************
** Add a new module argument to pTable->azModuleArg[].
** The string is not copied - the pointer is stored. The
** string will be freed automatically when the table is
** deleted.
First register in OLD.* array
Create a record for this index entry as it should appear after
** the insert or update. Store that record in the aRegIdx[ix] register
*********** End %syntax_error code *****************************************
OUT: Number of backfilled frames in WAL
Left side of comparison
Assuming the wal-index file was successfully mapped, populate the
** page number array and hash table entry.
Tokenizer for this table
Total bytes of data (incl. structure)
First in linked list of saved aux-data
Check that the pointer pOld points to a valid, non-free block.
Next sample to test
Register that is true if RHS contains NULL values
If the first attempt to open the database file fails and the bRetry
** flag it set, this means that the db was not opened because it seemed
** to be a wal-mode db. But, this may have happened due to an earlier
** RBU vacuum operation leaving an old wal file in the directory.
** If this is the case, it will have been checkpointed and deleted
** when the handle was closed and a second attempt to open the
** database may succeed.
1. first try to open/create the file
** 2. if that fails, and this is a lock file (not-conch), try creating
** the parent directories and then try again.
** 3. if that fails, try to open the file read-only
** otherwise return BUSY (if lock file) or CANTOPEN for the conch file
The next block of code is equivalent to:
**
** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
**
** The code is inlined to avoid a function call.
** The following 256 byte lookup table is used to support SQLites built-in
** equivalents to the following standard library functions:
**
** isspace() 0x01
** isalpha() 0x02
** isdigit() 0x04
** isalnum() 0x06
** isxdigit() 0x08
** toupper() 0x20
** SQLite identifier character 0x40
** Quote character 0x80
**
** Bit 0x20 is set if the mapped character requires translation to upper
** case. i.e. if the character is a lower-case ASCII character.
** If x is a lower-case ASCII character, then its upper-case equivalent
** is (x - 0x20). Therefore toupper() can be implemented as:
**
** (x & ~(map[x]&0x20))
**
** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
** array. tolower() is used more often than toupper() by SQLite.
**
** Bit 0x40 is set if the character is non-alphanumeric and can be used in an
** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any
** non-ASCII UTF character. Hence the test for whether or not a character is
** part of an identifier is 0x46.
VM to add scanstatus() to
** This function is used to create the text of expressions of the form:
**
** name=<constant1> OR name=<constant2> OR ...
**
** If argument zWhere is NULL, then a pointer string containing the text
** "name=<constant>" is returned, where <constant> is the quoted version
** of the string passed as argument zConstant. The returned buffer is
** allocated using sqlite3DbMalloc(). It is the responsibility of the
** caller to ensure that it is eventually freed.
**
** If argument zWhere is not NULL, then the string returned is
** "<where> OR name=<constant>", where <where> is the contents of zWhere.
** In this case zWhere is passed to sqlite3DbFree() before returning.
**
Mask of FTS5_TOKENIZE_* flags
** Append SegReader object pNew to the end of the pCsr->apSegment[] array.
Page number
True if WAL file exists
2,3
Assert that operands are never NULL
columnname ::= nm typetoken
The SrcList to be enlarged
comment:
** Return TRUE if the WHERE clause term pTerm is of a form where it
** could be used with an index to access pSrc, assuming an appropriate
** index existed.
label: code-design
Update the in-memory representation of all UNIQUE indices by converting
** the final rowid column into one or more columns of the PRIMARY KEY.
EOF when i equals or exceeds this value
** Advance iterator pIter to the next entry.
**
** If an error occurs, Fts5Index.rc is set to an appropriate error code. It
** is not considered an error if the iterator reaches EOF. If an error has
** already occurred when this function is called, it is a no-op.
Deallocate page if true
** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
** functions are not available (e.g. those not using MSVC, Cygwin, etc).
Opcode: Found P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If P4==0 then register P3 holds a blob constructed by MakeRecord. If
** P4>0 then register P3 is the first of P4 registers that form an unpacked
** record.
**
** Cursor P1 is on an index btree. If the record identified by P3 and P4
** is a prefix of any entry in P1 then a jump is made to P2 and
** P1 is left pointing at the matching entry.
**
** This operation leaves the cursor in a state where it can be
** advanced in the forward direction. The Next instruction will work,
** but not the Prev instruction.
**
** See also: NotFound, NoConflict, NotExists. SeekGe
A connection with the read-uncommitted flag set will never try to
** obtain a read-lock using this function. The only read-lock obtained
** by a connection in read-uncommitted mode is on the sqlite_master
** table, and that lock is obtained in BtreeBeginTrans().
If pWalker->eCode is 2 then any term of the expression that comes from
** the ON or USING clauses of a left join disqualifies the expression
** from being considered constant.
** End of highlight() implementation.
*************************************************************************
Zero-length table names are allowed
IMP: R-51971-34154
Total leaves written to level 0
Create new databases in format 1
** Page type flags. An ORed combination of these flags appear as the
** first byte of on-disk image of every BTree page.
The WHERE processing context
OUT: Allocated Wal handle
RHS of LIKE/GLOB ends with wildcard
Now update the actual sibling pages. The order in which they are updated
** is important, as this code needs to avoid disrupting any page from which
** cells may still to be read. In practice, this means:
**
** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
** then it is not safe to update page apNew[iPg] until after
** the left-hand sibling apNew[iPg-1] has been updated.
**
** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
** then it is not safe to update page apNew[iPg] until after
** the right-hand sibling apNew[iPg+1] has been updated.
**
** If neither of the above apply, the page is safe to update.
**
** The iPg value in the following loop starts at nNew-1 goes down
** to 0, then back up to nNew-1 again, thus making two passes over
** the pages. On the initial downward pass, only condition (1) above
** needs to be tested because (2) will always be true from the previous
** step. On the upward pass, both conditions are always true, so the
** upwards pass simply processes pages that were missed on the downward
** pass.
If it did not delete it, the row-trigger may still have modified
** some of the columns of the row being updated. Load the values for
** all columns not modified by the update statement into their
** registers in case this has happened.
frame == (aHash[x]+iZero)
Number of tokens in phrase
OUT: Parsed query structure
Indicates an exclusive lock has been obtained
** If the second argument is not NULL, release any allocations associated
** with the memory cells in the p->aMem[] array. Also free the UnpackedRecord
** structure itself, using sqlite3DbFree().
**
** This function is used to free UnpackedRecord structures allocated by
** the vdbeUnpackRecord() function found in vdbeapi.c.
The WherePath to check
Gather entropy into this buffer
Record the number of outstanding lookaside allocations in schema Tables
** prior to doing any free() operations. Since schema Tables do not use
** lookaside, this number should not change.
Table being modified
Column to scan for
all memory is allocated, proxys are created and assigned,
** switch the locking context and pMethod then return.
Maximum number of cells for pNode
If currently processing the PRIMARY KEY of a WITHOUT ROWID
** table, only conflict if the new PRIMARY KEY values are actually
** different from the old.
**
** For a UNIQUE index, only conflict if the PRIMARY KEY values
** of the matched index row are different from the original PRIMARY
** KEY values of this row before the update.
comment:
** CAPI3REF: OS Interface Object
**
** An instance of the sqlite3_vfs object defines the interface between
** the SQLite core and the underlying operating system. The "vfs"
** in the name of the object stands for "virtual file system". See
** the [VFS | VFS documentation] for further information.
**
** The value of the iVersion field is initially 1 but may be larger in
** future versions of SQLite. Additional fields may be appended to this
** object when the iVersion value is increased. Note that the structure
** of the sqlite3_vfs object changes in the transaction between
** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
** modified.
**
** The szOsFile field is the size of the subclassed [sqlite3_file]
** structure used by this VFS. mxPathname is the maximum length of
** a pathname in this VFS.
**
** Registered sqlite3_vfs objects are kept on a linked list formed by
** the pNext pointer. The [sqlite3_vfs_register()]
** and [sqlite3_vfs_unregister()] interfaces manage this list
** in a thread-safe way. The [sqlite3_vfs_find()] interface
** searches the list. Neither the application code nor the VFS
** implementation should use the pNext pointer.
**
** The pNext field is the only field in the sqlite3_vfs
** structure that SQLite will ever modify. SQLite will only access
** or modify this field while holding a particular static mutex.
** The application should never modify anything within the sqlite3_vfs
** object once the object has been registered.
**
** The zName field holds the name of the VFS module. The name must
** be unique across all VFS modules.
**
** [[sqlite3_vfs.xOpen]]
** ^SQLite guarantees that the zFilename parameter to xOpen
** is either a NULL pointer or string obtained
** from xFullPathname() with an optional suffix added.
** ^If a suffix is added to the zFilename parameter, it will
** consist of a single "-" character followed by no more than
** 11 alphanumeric and/or "-" characters.
** ^SQLite further guarantees that
** the string will be valid and unchanged until xClose() is
** called. Because of the previous sentence,
** the [sqlite3_file] can safely store a pointer to the
** filename if it needs to remember the filename for some reason.
** If the zFilename parameter to xOpen is a NULL pointer then xOpen
** must invent its own temporary name for the file. ^Whenever the
** xFilename parameter is NULL it will also be the case that the
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
**
** The flags argument to xOpen() includes all bits set in
** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
** or [sqlite3_open16()] is used, then flags includes at least
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
** If xOpen() opens a file read-only then it sets *pOutFlags to
** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
**
** ^(SQLite will also add one of the following flags to the xOpen()
** call, depending on the object being opened:
**
** <ul>
** <li> [SQLITE_OPEN_MAIN_DB]
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
** <li> [SQLITE_OPEN_TEMP_DB]
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
** <li> [SQLITE_OPEN_TRANSIENT_DB]
** <li> [SQLITE_OPEN_SUBJOURNAL]
** <li> [SQLITE_OPEN_MASTER_JOURNAL]
** <li> [SQLITE_OPEN_WAL]
** </ul>)^
**
** The file I/O implementation can use the object type flags to
** change the way it deals with files. For example, an application
** that does not care about crash recovery or rollback might make
** the open of a journal file a no-op. Writes to this journal would
** also be no-ops, and any attempt to read the journal would return
** SQLITE_IOERR. Or the implementation might recognize that a database
** file will be doing page-aligned sector reads and writes in a random
** order and set up its I/O subsystem accordingly.
**
** SQLite might also add one of the following flags to the xOpen method:
**
** <ul>
** <li> [SQLITE_OPEN_DELETEONCLOSE]
** <li> [SQLITE_OPEN_EXCLUSIVE]
** </ul>
**
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
** will be set for TEMP databases and their journals, transient
** databases, and subjournals.
**
** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
** SQLITE_OPEN_CREATE, is used to indicate that file should always
** be created, and that it is an error if it already exists.
** It is <i>not</i> used to indicate the file should be opened
** for exclusive access.
**
** ^At least szOsFile bytes of memory are allocated by SQLite
** to hold the [sqlite3_file] structure passed as the third
** argument to xOpen. The xOpen method does not have to
** allocate the structure; it should just fill it in. Note that
** the xOpen method must set the sqlite3_file.pMethods to either
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
** element will be valid after xOpen returns regardless of the success
** or failure of the xOpen call.
**
** [[sqlite3_vfs.xAccess]]
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
** to test whether a file is at least readable. The file can be a
** directory.
**
** ^SQLite will always allocate at least mxPathname+1 bytes for the
** output buffer xFullPathname. The exact size of the output buffer
** is also passed as a parameter to both methods. If the output buffer
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
** handled as a fatal error by SQLite, vfs implementations should endeavor
** to prevent this by setting mxPathname to a sufficiently large value.
**
** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
** interfaces are not strictly a part of the filesystem, but they are
** included in the VFS structure for completeness.
** The xRandomness() function attempts to return nBytes bytes
** of good-quality randomness into zOut. The return value is
** the actual number of bytes of randomness obtained.
** The xSleep() method causes the calling thread to sleep for at
** least the number of microseconds given. ^The xCurrentTime()
** method returns a Julian Day Number for the current date and time as
** a floating point value.
** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
** Day Number multiplied by 86400000 (the number of milliseconds in
** a 24-hour day).
** ^SQLite will use the xCurrentTimeInt64() method to get the current
** date and time if that method is available (if iVersion is 2 or
** greater and the function pointer is not NULL) and will fall back
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
**
** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
** are not used by the SQLite core. These optional interfaces are provided
** by some VFSes to facilitate testing of the VFS code. By overriding
** system calls with functions under its control, a test program can
** simulate faults and error conditions that would otherwise be difficult
** or impossible to induce. The set of system calls that can be overridden
** varies from one VFS to another, and from one version of the same VFS to the
** next. Applications that use these interfaces must be prepared for any
** or all of these interfaces to be NULL or for their behavior to change
** from one release to the next. Applications must not attempt to access
** any of these methods if the iVersion of the VFS is less than 3.
label: code-design
Select the child node which will be enlarged the least if pCell
** is inserted into it. Resolve ties by choosing the entry with
** the smallest area.
Aux data pointer
** Return TRUE if the database file is opened read-only. Return FALSE
** if the database is (in theory) writable.
Remove the slot from the free-list. Update the number of
** fragmented bytes within the page.
Local cache of pPage->hdrOffset
Cursor to iterate through level(s)
The main DB, main journal, WAL file and master journal are never
** automatically deleted. Nor are they ever temporary files.
List of available buffers
Number of szAtom sized blocks in zPool
Or, if aOut==0, here
comment: Used only to suppress a compiler warning
label: code-design
Index of parent of each node
sqlite3Fts5Parser_ENGINEALWAYSONSTACK
A VACUUM cannot change the pagesize of an encrypted database.
** Configure SQL variable iVar so that binding a new value to it signals
** to sqlite3_reoptimize() that re-preparing the statement may result
** in a better query plan.
The root page of the b-tree now contains no cells. The only sibling
** page is the right-child of the parent. Copy the contents of the
** child page into the parent, decreasing the overall height of the
** b-tree structure by one. This is described as the "balance-shallower"
** sub-algorithm in some documentation.
**
** If this is an auto-vacuum database, the call to copyNodeContent()
** sets all pointer-map entries corresponding to database image pages
** for which the pointer is stored within the content being copied.
**
** It is critical that the child page be defragmented before being
** copied into the parent, because if the parent is page 1 then it will
** by smaller than the child due to the database header, and so all the
** free space needs to be up front.
Functions to support testing and debugging.
** CAPI3REF: SQL Function Context Object
**
** The context in which an SQL function executes is stored in an
** sqlite3_context object. ^A pointer to an sqlite3_context object
** is always first parameter to [application-defined SQL functions].
** The application-defined SQL function implementation will pass this
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
** and/or [sqlite3_set_auxdata()].
IN terms are only valid for sorting in the ORDER BY LIMIT
** optimization, and then only if they are actually used
** by the query plan
tab1 and tab2 may not be the same table
The name of the table/view the trigger applies to
Compute the complete text of the CREATE statement
Return code from subprocedures
Load the statistics from the sqlite_stat4 table.
Restrictions (22) and (24)
36
** chng_addr_N:
** regRowid = idx(rowid) // STAT34 only
** stat_push(P, regChng, regRowid) // 3rd parameter STAT34 only
** Next csr
** if !eof(csr) goto next_row;
Copy of Fts5Config.eDetail
2:save off p0<<21 | p1<<14 | p2<<7 | p3 (masked)
** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery().
comment:
** Some Microsoft compilers lack this definition.
label: test
Size of buffer a[] in bytes
comment:
** Set the value of the Pager.sectorSize variable for the given
** pager based on the value returned by the xSectorSize method
** of the open database file. The sector size will be used
** to determine the size and alignment of journal header and
** master journal pointers within created journal files.
**
** For temporary files the effective sector size is always 512 bytes.
**
** Otherwise, for non-temporary files, the effective sector size is
** the value returned by the xSectorSize() method rounded up to 32 if
** it is less than 32, or rounded down to MAX_SECTOR_SIZE if it
** is greater than MAX_SECTOR_SIZE.
**
** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
** the effective sector size to its minimum value (512). The purpose of
** pPager->sectorSize is to define the "blast radius" of bytes that
** might change if a crash occurs while writing to a single byte in
** that range. But with POWERSAFE_OVERWRITE, the blast radius is zero
** (that is what POWERSAFE_OVERWRITE means), so we minimize the sector
** size. For backwards compatibility of the rollback journal file format,
** we cannot reduce the effective sector size below 512.
label: code-design
Fields in sorter record
Verify that the version number on the WAL format is one that
** are able to understand
** Enable or disable the session object passed as the first argument.
Separate the left and the right query from one another
Index Name NULL
** 2001 September 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for the generic hash-table implementation
** used in SQLite. We've modified it slightly to serve as a standalone
** hash table implementation for the full-text indexing module.
**
** The following functions:
**
** sqlite3VdbeSerialType()
** sqlite3VdbeSerialTypeLen()
** sqlite3VdbeSerialLen()
** sqlite3VdbeSerialPut()
** sqlite3VdbeSerialGet()
**
** encapsulate the code that serializes values for storage in SQLite
** data and index records. Each serialized value consists of a
** 'serial-type' and a blob of data. The serial type is an 8-byte unsigned
** integer, stored as a varint.
**
** In an SQLite index record, the serial type is stored directly before
** the blob of data that it corresponds to. In a table record, all serial
** types are stored at the start of the record, and the blobs of data at
** the end. Hence these functions allow the caller to handle the
** serial-type and data blob separately.
**
** The following table describes the various storage classes for data:
**
** serial type bytes of data type
** -------------- --------------- ---------------
** 0 0 NULL
** 1 1 signed integer
** 2 2 signed integer
** 3 3 signed integer
** 4 4 signed integer
** 5 6 signed integer
** 6 8 signed integer
** 7 8 IEEE float
** 8 0 Integer constant 0
** 9 0 Integer constant 1
** 10,11 reserved for expansion
** N>=12 and even (N-12)/2 BLOB
** N>=13 and odd (N-13)/2 text
**
** The 8 and 9 types were added in 3.3.0, file format 4. Prior versions
** of SQLite will not understand those serial types.
True if next rowid is first in doclist
** This function is purely an internal test. It does not contribute to
** FTS functionality, or even the integrity-check, in any way.
**
** Instead, it tests that the same set of pgno/rowid combinations are
** visited regardless of whether the doclist-index identified by parameters
** iSegid/iLeaf is iterated in forwards or reverse order.
P5
** Subqueries stores the original database, table and column names for their
** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
** Check to see if the zSpan given to this routine matches the zDb, zTab,
** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
** match anything.
szMmap
Add a segment iterator for the current contents of the hash table.
Cursor used to read input data
123456789 123456789 123
colsetlist ::= STRING
True to scan from zTerm to EOF
******* sqlite3_pcache Methods *********************************************
same as TK_SLASH, in1, in2, out3
OUT: Error number if error occurs
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
Rowid for current entry
Check if the temp table already contains this key. If so,
** the row has already been included in the result set and
** can be ignored (by jumping past the Gosub below). Otherwise,
** insert the key into the temp table and proceed with processing
** the row.
**
** Use some of the same optimizations as OP_RowSetTest: If iSet
** is zero, assume that the key cannot already be present in
** the temp table. And if iSet is -1, assume that there is no
** need to insert the key into the temp table, as it will never
** be tested for.
New virtual expression
Opcode: ReopenIdx P1 P2 P3 P4 P5
** Synopsis: root=P2 iDb=P3
**
** The ReopenIdx opcode works exactly like ReadOpen except that it first
** checks to see if the cursor on P1 is already open with a root page
** number of P2 and if it is this opcode becomes a no-op. In other words,
** if the cursor is already open, do not reopen it.
**
** The ReopenIdx opcode may only be used with P5==0 and with P4 being
** a P4_KEYINFO object. Furthermore, the P3 value must be the same as
** every other ReopenIdx or OpenRead for the same cursor number.
**
** See the OpenRead opcode documentation for additional information.
ELSE
The sqlite_statN table does not exist. Create it. Note that a
** side-effect of the CREATE TABLE statement is to leave the rootpage
** of the new table in register pParse->regRoot. This is important
** because the OpenWrite opcode below will be needing it.
OUT: New iterator
Size of shared-memory regions
True to set the USESEEKRESULT flag on OP_[Idx]Insert
Commit by zeroing journal header
At this point, any non-zero iOrderByCol values indicate that the
** ORDER BY column expression is identical to the iOrderByCol'th
** expression returned by SELECT statement pSub. Since these values
** do not necessarily correspond to columns in SELECT statement pParent,
** zero them before transfering the ORDER BY clause.
**
** Not doing this may cause an error if a subsequent call to this
** function attempts to flatten a compound sub-query into pParent
** (the only way this can happen is if the compound sub-query is
** currently part of pSub->pSrc). See ticket [d11a6e908f].
Load b.apCell[] with pointers to all cells in pOld. If pOld
** constains overflow cells, include them in the b.apCell[] array
** in the correct spot.
**
** Note that when there are multiple overflow cells, it is always the
** case that they are sequential and adjacent. This invariant arises
** because multiple overflows can only occurs when inserting divider
** cells into a parent on a prior balance, and divider cells are always
** adjacent and are inserted in order. There is an assert() tagged
** with "NOTE 1" in the overflow cell insertion loop to prove this
** invariant.
**
** This must be done in advance. Once the balance starts, the cell
** offset section of the btree page will be overwritten and we will no
** long be able to find the cells if a pointer to each cell is not saved
** first.
** Add an entry to the Fts5SFinder.aFirst[] array. Grow the array if
** necessary. Return SQLITE_OK if successful, or SQLITE_NOMEM if an
** error occurs.
08..0f ........
Statement number (or 0 if has not opened stmt)
Load the contents of the %_config table
If one value is NULL, it is less than the other. If both values
** are NULL, return 0.
moved CSE2 up
Function to call when busy
First character of input text
Move to the next entry that matches the configured constraints.
Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
** statement only). For DETACH, set it to false (expire all existing
** statements).
buffer in which to construct conch name
Index of column in second table
A fake index object for the primary key
Column to match on.
Offset to next unparsed byte of the header
** The MSVC CRT on Windows CE may not have a localtime() function.
** So define a substitute.
SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
Return no rowids earlier than this
pkChng!=0 does not mean that the rowid has changed, only that
** it might have changed. Skip the conflict logic below if the rowid
** is unchanged.
Write the header for the new UPDATE change. Same as the original.
SQLITE_PREPARE_* flags
comment: If the default value for the new column was specified with a
** literal NULL, then set pDflt to 0. This simplifies checking
** for an SQL NULL default below.
label: code-design
** This interface is used by the fts5vocab module.
For UNIQUE indexes, verify that only one entry exists with the
** current key. The entry is unique if (1) any column is NULL
** or (2) the next entry has a different key
First allowable cell index
The SnippetIter object has just been initialized. The first snippet
** candidate always starts at offset 0 (even if this candidate has a
** score of 0.0).
Declare the table schema to SQLite.
Index name
FTS cursor handle
** Truncate an open file to a specified size
Make sure cursor numbers have been assigned to all entries in
** the FROM clause of the SELECT statement.
If there was a master journal and this routine will return success,
** see if it is possible to delete the master journal.
constructor for a JsonEachCursor object for json_each().
A complex statement machine used to detect the end of a CREATE TRIGGER
** statement. This is the normal case.
If a transaction is open, roll it back. This also ensures that if
** any database schemas have been modified by an uncommitted transaction
** they are reset. And that the required b-tree mutex is held to make
** the pager rollback and schema reset an atomic operation.
(301) resolvetype ::= raisetype (OPTIMIZED OUT)
True to use in-memory sub-journals
Parent key index for this FK
Use the foreground thread for this operation
True if this is a VIRTUAL table
VDBE cursor for the canonical data source
Disables and re-enables match
** Remove entries from the sqlite_statN tables (for N in (1,2,3))
** after a DROP INDEX or DROP TABLE command.
This block codes the top of loop only. The complete loop is the
** following pseudocode (template 3):
**
** C: yield X, at EOF goto D
** insert the select result into <table> from R..R+n
** goto C
** D: ...
Index key to query for
** Implementation of the xSetAuxdata() method.
True to omit this if found
************* Begin file mem3.c *******************************************
** Print the SQL that was used to generate a VDBE program.
Constructor for the json_each virtual table
** Mark the VDBE as one that can only be run multiple times.
** Append position iPos to the position list being accumulated in buffer
** pBuf, which must be already be large enough to hold the new data.
** The previous position written to this list is *piPrev. *piPrev is set
** to iPos before returning.
** This function performs the parts of the "close file" operation
** common to all locking schemes. It closes the directory and file
** handles, if they are valid, and sets all fields of the unixFile
** structure to 0.
**
** It is *not* necessary to hold the mutex when this routine is called,
** even on VxWorks. A mutex will be acquired on VxWorks by the
** vxworksReleaseFileId() routine.
Add the new entry to the end of the cache
Name of the database to use internally
** This function is called when flushing a leaf page that contains no
** terms at all to disk.
Object for pair-wise doclist merging
Tables used by best possible plan
0
Next registered VFS
This routine is not called unless a write-transaction has already
** been started. The journal file may or may not be open at this point.
** It is never called in the ERROR state.
Unpacked index key
IMP: R-38219-53002
VFS containing this as the xDelete method
now attemmpt to get the exclusive lock range
Information about the record format
Main database structure
No term was written to this page.
Start of range is constrained
** Return the current term.
** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
** by an earlier call to rbuObjIterCacheTableInfo().
** Given an expression list (which is really the list of expressions
** that form the result set of a SELECT statement) compute appropriate
** column names for a table that would hold the expression list.
**
** All column names will be unique.
**
** Only the column names are computed. Column.zType, Column.zColl,
** and other fields of Column are zeroed.
**
** Return SQLITE_OK on success. If a memory allocation error occurs,
** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
**
** The only guarantee that SQLite makes about column names is that if the
** column has an AS clause assigning it a name, that will be the name used.
** That is the only documented guarantee. However, countless applications
** developed over the years have made baseless assumptions about column names
** and will break if those assumptions changes. Hence, use extreme caution
** when modifying this routine to avoid breaking legacy.
**
** See Also: generateColumnNames()
comment: The cell should normally be sized correctly. However, when moving a
** malformed cell from a leaf page to an interior page, if the cell size
** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
** might be less than 8 (leaf-size + pointer) on the interior node. Hence
** the term after the || in the following assert().
label: code-design
** File control method. For custom operations on an rbuVfs-file.
Use the standard inner loop.
Mask of snippet terms to highlight
** Extend level iLvl so that there is room for at least nExtra more
** segments.
cmd ::= PRAGMA nm dbnm LP minus_num RP
0x50..0x5F
************* Include vxworks.h in the middle of sqliteInt.h **************
** 2014 August 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
**
** OVERVIEW
**
** The RBU extension requires that the RBU update be packaged as an
** SQLite database. The tables it expects to find are described in
** sqlite3rbu.h. Essentially, for each table xyz in the target database
** that the user wishes to write to, a corresponding data_xyz table is
** created in the RBU database and populated with one row for each row to
** update, insert or delete from the target table.
**
** The update proceeds in three stages:
**
** 1) The database is updated. The modified database pages are written
** to a *-oal file. A *-oal file is just like a *-wal file, except
** that it is named "<database>-oal" instead of "<database>-wal".
** Because regular SQLite clients do not look for file named
** "<database>-oal", they go on using the original database in
** rollback mode while the *-oal file is being generated.
**
** During this stage RBU does not update the database by writing
** directly to the target tables. Instead it creates "imposter"
** tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
** to update each b-tree individually. All updates required by each
** b-tree are completed before moving on to the next, and all
** updates are done in sorted key order.
**
** 2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
** location using a call to rename(2). Before doing this the RBU
** module takes an EXCLUSIVE lock on the database file, ensuring
** that there are no other active readers.
**
** Once the EXCLUSIVE lock is released, any other database readers
** detect the new *-wal file and read the database in wal mode. At
** this point they see the new version of the database - including
** the updates made as part of the RBU update.
**
** 3) The new *-wal file is checkpointed. This proceeds in the same way
** as a regular database checkpoint, except that a single frame is
** checkpointed each time sqlite3rbu_step() is called. If the RBU
** handle is closed before the entire *-wal file is checkpointed,
** the checkpoint progress is saved in the RBU database and the
** checkpoint can be resumed by another RBU client at some point in
** the future.
**
** POTENTIAL PROBLEMS
**
** The rename() call might not be portable. And RBU is not currently
** syncing the directory after renaming the file.
**
** When state is saved, any commit to the *-oal file and the commit to
** the RBU update database are not atomic. So if the power fails at the
** wrong moment they might get out of sync. As the main database will be
** committed before the RBU update database this will likely either just
** pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
** constraint violations).
**
** If some client does modify the target database mid RBU update, or some
** other error occurs, the RBU extension will keep throwing errors. It's
** not really clear how to get out of this state. The system could just
** by delete the RBU update database and *-oal file and have the device
** download the update again and start over.
**
** At present, for an UPDATE, both the new.* and old.* records are
** collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
** fields are collected. This means we're probably writing a lot more
** data to disk when saving the state of an ongoing update to the RBU
** update database than is strictly necessary.
**
out2: P2 is an output
The JSON parser that contains the TARGET
Join type mask
1 byte past end of aAll
porter rule condition: (*v*)
Number of tokens desired for snippet
True if sorter record includes seq. no.
int
Set the output variables before returning.
First argument to sqlite3_result_...()
** This constant should already be defined (in the "WinNT.h" SDK file).
Index in mem3.aPool[] of next free chunk
Set variable iNext to the next available segdir index at level iLevel.
xBestIndex - Determine search strategy
Where to jump when NULLs seen in step 2
Require a write-lock on the table to perform this operation
Size of sibling on the right
COLLATE, AS, or UNLIKELY
Create a new thread
insert_cmd ::= REPLACE
If the pager is in CACHEMOD state, then there must be a copy of this
** page in the pager cache. In this case just update the pager cache,
** not the database file. The page is left marked dirty in this case.
**
** An exception to the above rule: If the database is in no-sync mode
** and a page is moved during an incremental vacuum then the page may
** not be in the pager cache. Later: if a malloc() or IO error occurs
** during a Movepage() call, then the page may not be in the cache
** either. So the condition described in the above paragraph is not
** assert()able.
**
** If in WRITER_DBMOD, WRITER_FINISHED or OPEN state, then we update the
** pager cache if it exists and the main file. The page is then marked
** not dirty. Since this code is only executed in PAGER_OPEN state for
** a hot-journal rollback, it is guaranteed that the page-cache is empty
** if the pager is in OPEN state.
**
** Ticket #1171: The statement journal might contain page content that is
** different from the page content at the start of the transaction.
** This occurs when a page is changed prior to the start of a statement
** then changed again within the statement. When rolling back such a
** statement we must not write to the original database unless we know
** for certain that original page contents are synced into the main rollback
** journal. Otherwise, a power loss might leave modified data in the
** database file without an entry in the rollback journal that can
** restore the database to its original form. Two conditions must be
** met before writing to the database files. (1) the database must be
** locked. (2) we know that the original page content is fully synced
** in the main journal either because the page is not in cache or else
** the page is marked as needSync==0.
**
** 2008-04-14: When attempting to vacuum a corrupt database file, it
** is possible to fail a statement on a database that does not yet exist.
** Do not attempt to write if database file has never been opened.
Number of UChar elements in pInput
SQL statement to delete rows
108
** Erase column-cache entry number i
** Process a pragma statement.
**
** Pragmas are of this form:
**
** PRAGMA [schema.]id [= value]
**
** The identifier might also be a string. The value is a string, and
** identifier, or a number. If minusFlag is true, then the value is
** a number that was preceded by a minus sign.
**
** If the left side is "database.id" then pId1 is the database name
** and pId2 is the id. If the left side is just "id" then pId1 is the
** id and pId2 is any empty string.
************* Include fts3Int.h in the middle of fts3.c *******************
Version 3.8.7 and later
** Check a unixFile that is a database. Verify the following:
**
** (1) There is exactly one hard link on the file
** (2) The file is not a symbolic link
** (3) The file has not been renamed or unlinked
**
** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
Primary key declaration for imposter
OUT: Number of tokens returned before this one
Index to write to
full
** Information held in the "sqlite3" database connection object and used
** to manage user authentication.
Context of the fixation
Code constant expressions that where factored out of inner loops
comment: The temp-database schema is allocated differently from the other schema
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
** So it needs to be freed here. Todo: Why not roll the temp schema into
** the same sqliteMalloc() as the one that allocates the database
** structure?
label: code-design
Name of attached database (or NULL)
274
Tell the code in notify.c that the connection no longer holds any
** locks and does not require any further unlock-notify callbacks.
Current FTS5 configuration
Number of pages on the freelist initially
** Compare the term that the Fts3SegReader object passed as the first argument
** points to with the term specified by arguments zTerm and nTerm.
**
** If the pSeg iterator is already at EOF, return 0. Otherwise, return
** -ve if the pSeg term is less than zTerm/nTerm, 0 if the two terms are
** equal, or +ve if the pSeg term is greater than zTerm/nTerm.
rbu VFS shim methods
214
** The yDbMask datatype for the bitmask of all attached databases.
** Threading interface
For looping through segments
String or blob
Value inserted into rank column
Number of entries in aArg[]
Database to detach at end of vacuum
True if iterator is "rowid DESC"
** Execute as much of a VDBE program as we can.
** This is the core of sqlite3_step().
OP_ResultRow called with zero columns
2
defined(InterlockedCompareExchange)
Write high-water mark here
Associated index cursor from which to read
Opcode: IdxDelete P1 P2 P3 * *
** Synopsis: key=r[P2@P3]
**
** The content of P3 registers starting at register P2 form
** an unpacked index key. This opcode removes that entry from the
** index opened by cursor P1.
The table trigger pTrigger is attached to
If this call is to check if a *-wal file associated with an RBU target
** database connection exists, and the RBU update is in RBU_STAGE_OAL,
** the following special handling is activated:
**
** a) if the *-wal file does exist, return SQLITE_CANTOPEN. This
** ensures that the RBU extension never tries to update a database
** in wal mode, even if the first page of the database file has
** been damaged.
**
** b) if the *-wal file does not exist, claim that it does anyway,
** causing SQLite to call xOpen() to open it. This call will also
** be intercepted (see the rbuVfsOpen() function) and the *-oal
** file opened instead.
** Token pToken is an incrementally loaded token that is part of a
** multi-token phrase. Advance it to the next matching document in the
** database and populate output variable *p with the details of the new
** entry. Or, if the iterator has reached EOF, set *pbEof to true.
**
** If an error occurs, return an SQLite error code. Otherwise, return
** SQLITE_OK.
SegmentNode handle
synopsis: r[P2..P3]=NULL
zNum is less than 9223372036854775808 so it fits
For client use (any custom purpose)
If the next character is a digit, this is a floating point
** number that begins with ".". Fall thru into the next case
Fall thru
** Scan through the expression pExpr. Replace every reference to
** a column in table number iTable with a copy of the iColumn-th
** entry in pEList. (But leave references to the ROWID column
** unchanged.)
**
** This routine is part of the flattening procedure. A subquery
** whose result set is defined by pEList appears as entry in the
** FROM clause of a SELECT such that the VDBE cursor assigned to that
** FORM clause entry is iTable. This routine makes the necessary
** changes to pExpr so that it refers directly to the source table
** of the subquery rather the result set of the subquery.
fts3.c
A bitfield type for use inside of structures. Always follow with :N where
** N is the number of bits.
1070
Current state number
Check that the leaf contains at least one term, and that it is equal
** to or larger than the split-key in zIdxTerm. Also check that if there
** is also a rowid pointer within the leaf page header, it points to a
** location before the term.
Update allocator performance statistics.
iReg is a temp register that needs to be freed
Generates a warning - but it always works
The cell index area
Idx of column in child table
Mark the database file just opened as an RBU target database. If
** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
** This is an error.
Non-NULL for UPDATE operations
afp style keeps a reference to the db path in the filePath field
** of the struct
Minimum number of pages reserved
** Resize the block of memory pointed to by p to n bytes. If the
** resize fails, set the mallocFailed flag in the connection object.
Table this step applies to
81
List of triggers stored in pSchema
10's digit
Replace references to this table
Number of ORDER BY terms satisfied by indices
Parameter number to bind to
Check for mismatched parenthesis
** 2009 November 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to insert the values of host parameters
** (aka "wildcards") into the SQL text output by sqlite3_trace().
**
** The Vdbe parse-tree explainer is also found here.
read the existing conch file
Needed for various definitions...
22
A single constraint term
** Currently, SQLite never calls the LockFileEx function without wanting the
** call to fail immediately if the lock cannot be obtained.
** CAPI3REF: Write Data Into A BLOB Incrementally
** METHOD: sqlite3_blob
**
** ^(This function is used to write data into an open [BLOB handle] from a
** caller-supplied buffer. N bytes of data are copied from the buffer Z
** into the open BLOB, starting at offset iOffset.)^
**
** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
** Otherwise, an [error code] or an [extended error code] is returned.)^
** ^Unless SQLITE_MISUSE is returned, this function sets the
** [database connection] error code and message accessible via
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
**
** ^If the [BLOB handle] passed as the first argument was not opened for
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
** this function returns [SQLITE_READONLY].
**
** This function may only modify the contents of the BLOB; it is
** not possible to increase the size of a BLOB using this API.
** ^If offset iOffset is less than N bytes from the end of the BLOB,
** [SQLITE_ERROR] is returned and no data is written. The size of the
** BLOB (and hence the maximum value of N+iOffset) can be determined
** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
** than zero [SQLITE_ERROR] is returned and no data is written.
**
** ^An attempt to write to an expired [BLOB handle] fails with an
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
** before the [BLOB handle] expired are not rolled back by the
** expiration of the handle, though of course those changes might
** have been overwritten by the statement that expired the BLOB handle
** or by other independent statements.
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
**
** See also: [sqlite3_blob_read()].
We have found a candidate table and column. Check to see if that
** table and column is common to every term in the OR clause
comment:
** Value used to signify the end of an position-list. This is safe because
** it is not possible to have a document with 2^31 terms.
label: documentation
Count the number of columns that will be added to the index
** and used to match WHERE clause constraints
Mask of phrases already covered
Estimated number of rows generated by this path
TRANSACTION
** Delete the file at zPath. If the dirSync argument is true, fsync()
** the directory after deleting the file.
Write the hint values into the %_stat table for the next incr-merger
****************** End of the no-op lock implementation *********************
*****************************************************************************
The right-hand side (RHS) of the IN operator
fstat() info for database file
Database file holding the shared memory
1190
Figure out the type of table this step will deal with.
First key value passed to hook
The sqlite_stat[134] table already exists. Delete all rows.
Constant expressions
Load the full doclist for the phrase into memory.
Open page 1 of the file for writing.
True if opening an ephemeral, temporary database
** This is the xFilter interface for the virtual table. See
** the virtual table xFilter method documentation for additional
** information.
**
** There are three possible query strategies:
**
** 1. Full-text search using a MATCH operator.
** 2. A by-rowid lookup.
** 3. A full-table scan.
First register in VUpdate arg array
in1
The write cursors opened by WHERE_ONEPASS
** Populate pCsr->aMatchinfo[] with data for the current row. The
** 'matchinfo' data is an array of 32-bit unsigned integers (C type u32).
X==Ei (form A) or just Ei (form B)
Array used to calculate phrase freq.
Index of loop to report on
IN/OUT: SegmentWriter handle
Root page of index
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
Move the page to the head of the dirty list. If p->pDirtyPrev==0,
** then page p is already at the head of the dirty list and the
** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
** tag above.
EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
** argument of type int. If non-zero, then URI handling is globally
** enabled. If the parameter is zero, then URI handling is globally
** disabled.
Seg-reader cursor for this term
Preserve SQL text
This strategy involves a two rowid lookups on an B-Tree structures
** and then a linear search of an R-Tree node. This should be
** considered almost as quick as a direct rowid lookup (for which
** sqlite uses an internal cost of 0.0). It is expected to return
** a single row.
!defined(SQLITE_RTREE_INT_ONLY)
Version 3.18.0 and later
Tokenizer object
** Return true if the iterator passed as the only argument is at EOF.
a: p0<<14 | p2 (masked)
Used by DOCID_CMP() macro
Name of new table or NULL
** This routine implements a busy callback that sleeps and tries
** again until a timeout value is reached. The timeout value is
** an integer number of milliseconds passed in as the first
** argument.
** CAPI3REF: Register A Virtual Table Implementation
** METHOD: sqlite3
**
** ^These routines are used to register a new [virtual table module] name.
** ^Module names must be registered before
** creating a new [virtual table] using the module and before using a
** preexisting [virtual table] for the module.
**
** ^The module name is registered on the [database connection] specified
** by the first parameter. ^The name of the module is given by the
** second parameter. ^The third parameter is a pointer to
** the implementation of the [virtual table module]. ^The fourth
** parameter is an arbitrary client data pointer that is passed through
** into the [xCreate] and [xConnect] methods of the virtual table module
** when a new virtual table is be being created or reinitialized.
**
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
** is a pointer to a destructor for the pClientData. ^SQLite will
** invoke the destructor function (if it is not NULL) when SQLite
** no longer needs the pClientData pointer. ^The destructor will also
** be invoked if the call to sqlite3_create_module_v2() fails.
** ^The sqlite3_create_module()
** interface is equivalent to sqlite3_create_module_v2() with a NULL
** destructor.
!SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
For an in-memory database, make sure the original page continues
** to exist, in case the transaction needs to roll back. Use pPgOld
** as the original page since it has already been allocated.
aDistance array
m
** PRAGMA [schema.]page_size
** PRAGMA [schema.]page_size=N
**
** The first form reports the current setting for the
** database page size in bytes. The second form sets the
** database page size value. The value can only be set if
** the database has not yet been created.
Update statement to modify idx values
Divider cells in pParent
** Clear any and all virtual-table information from the Table record.
** This routine is called, for example, just before deleting the Table
** record.
**
** Since it is a virtual-table, the Table structure contains a pointer
** to the head of a linked list of VTable structures. Each VTable
** structure is associated with a single sqlite3* user of the schema.
** The reference count of the VTable structure associated with database
** connection db is decremented immediately (which may lead to the
** structure being xDisconnected and free). Any other VTable structures
** in the list are moved to the sqlite3.pDisconnect list of the associated
** database connection.
** Maximum number of pages in one database file.
**
** This is really just the default value for the max_page_count pragma.
** This value can be lowered (or raised) at run-time using that the
** max_page_count macro.
** Deallocate all memory associated with a WhereAndInfo object.
Absolute level to open
Loop through all columns of the table being considered for snippets.
** If the iCol argument to this function was negative, this means all
** columns of the FTS3 table. Otherwise, only column iCol is considered.
The expression to be fixed to one database
Current size of wal-index file
comment:
** If we get to this point, the path name should almost certainly be a purely
** relative one (i.e. not a UNC name, not absolute, and not volume relative).
label: code-design
* This is the extra space for the initial size of the Win32-specific heap,
* in bytes. This value may be zero.
Minimum cell size is 4
FILETIME structure is a 64-bit value representing the number of
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
Look for a valid schema=? constraint. If found, change the idxNum to
** 1 and request the value of that constraint be sent to xFilter. And
** lower the cost estimate to encourage the constrained version to be
** used.
If an error has occurred, mark the session object as failed.
Bitmask identifying table iTab
Registers to allocate
New rowid
comment: Do not code a test for this constraint
label: test
True if really sorted (not just grouped)
One less than frame number of aPgno[1]
Do not gather statistics on views or virtual tables
Delete the master journal file. This commits the transaction. After
** doing this the directory is synced again before any individual
** transaction files are deleted.
Buffer to fold text into
** Convert a UTF-16 string in the native encoding into a UTF-8 string.
** Memory to hold the UTF-8 string is obtained from sqlite3_malloc and must
** be freed by the calling function.
**
** NULL is returned if there is an allocation error.
xFilter
Could not find an existing table or index to use as the RHS b-tree.
** We will have to generate an ephemeral table to do the job.
True if the AUTOINCREMENT keyword is present
xColumn
** Retry ftruncate() calls that fail due to EINTR
**
** All calls to ftruncate() within this file should be made through
** this wrapper. On the Android platform, bypassing the logic below
** could lead to a corrupt database.
** Compare two ExprList objects. Return 0 if they are identical and
** non-zero if they differ in any way.
**
** If any subelement of pB has Expr.iTable==(-1) then it is allowed
** to compare equal to an equivalent element in pA with Expr.iTable==iTab.
**
** This routine might return non-zero for equivalent ExprLists. The
** only consequence will be disabled optimizations. But this routine
** must never return 0 if the two ExprList objects are different, or
** a malfunction will result.
**
** Two NULL pointers are considered to be the same. But a NULL pointer
** always differs from a non-NULL pointer.
Base class. Must be first
A-overwrites-OP
Size decreases
All threads share a single random number generator.
** This structure is the current state of the generator.
Initial root node
add_column_fullname ::= fullname
** 2005 February 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
The table we are inserting into
** The page handle passed as the first argument refers to a dirty page
** with a page number other than iNew. This function changes the page's
** page number to iNew and sets the value of the PgHdr.flags field to
** the value passed as the third parameter.
** The names of the following types declared in vdbeInt.h are required
** for the VdbeOp definition.
** Functions generated by lemon from fts5parse.y.
vtabargtoken ::= ANY
During the search for the best function definition, this procedure
** is called to test how well the function passed as the first argument
** matches the request for a function with nArg arguments in a system
** that uses encoding enc. The value returned indicates how well the
** request is matched. A higher value indicates a better match.
**
** If nArg is -1 that means to only return a match (non-zero) if p->nArg
** is also -1. In other words, we are searching for a function that
** takes a variable number of arguments.
**
** If nArg is -2 that means that we are searching for any function
** regardless of the number of arguments it uses, so return a positive
** match score for any
**
** The returned value is always between 0 and 6, as follows:
**
** 0: Not a match.
** 1: UTF8/16 conversion required and function takes any number of arguments.
** 2: UTF16 byte order change required and function takes any number of args.
** 3: encoding matches and function takes any number of arguments
** 4: UTF8/16 conversion required - argument count matches exactly
** 5: UTF16 byte order conversion required - argument count matches exactly
** 6: Perfect match: encoding and argument count match exactly.
**
** If nArg==(-2) then any function with a non-null xSFunc is
** a perfect match and any function with xSFunc NULL is
** a non-match.
Column number in the sorting index
Determine if doclists may be loaded from disk incrementally. This is
** possible if the bOptOk argument is true, the FTS doclists will be
** scanned in forward order, and the phrase consists of
** MAX_INCR_PHRASE_TOKENS or fewer tokens, none of which are are "^first"
** tokens or prefix tokens that cannot use a prefix-index.
Open the sqlite_stat[134] tables for writing.
Database handle session is attached to
630
Verify property (1)
Ordinary Step 3, for the case where FALSE and NULL are distinct
Pointer to int
(321) kwcolumn_opt ::=
Name of table that the key points to (aka: Parent)
comment:
** CAPI3REF: One-Step Query Execution Interface
** METHOD: sqlite3
**
** The sqlite3_exec() interface is a convenience wrapper around
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
** that allows an application to run multiple statements of SQL
** without having to use a lot of C code.
**
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
** semicolon-separate SQL statements passed into its 2nd argument,
** in the context of the [database connection] passed in as its 1st
** argument. ^If the callback function of the 3rd argument to
** sqlite3_exec() is not NULL, then it is invoked for each result row
** coming out of the evaluated SQL statements. ^The 4th argument to
** sqlite3_exec() is relayed through to the 1st argument of each
** callback invocation. ^If the callback pointer to sqlite3_exec()
** is NULL, then no callback is ever invoked and result rows are
** ignored.
**
** ^If an error occurs while evaluating the SQL statements passed into
** sqlite3_exec(), then execution of the current statement stops and
** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
** is not NULL then any error message is written into memory obtained
** from [sqlite3_malloc()] and passed back through the 5th parameter.
** To avoid memory leaks, the application should invoke [sqlite3_free()]
** on error message strings returned through the 5th parameter of
** sqlite3_exec() after the error message string is no longer needed.
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
** NULL before returning.
**
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
** routine returns SQLITE_ABORT without invoking the callback again and
** without running any subsequent SQL statements.
**
** ^The 2nd argument to the sqlite3_exec() callback function is the
** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
** callback is an array of pointers to strings obtained as if from
** [sqlite3_column_text()], one for each column. ^If an element of a
** result row is NULL then the corresponding string pointer for the
** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
** sqlite3_exec() callback is an array of pointers to strings where each
** entry represents the name of corresponding result column as obtained
** from [sqlite3_column_name()].
**
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
** to an empty string, or a pointer that contains only whitespace and/or
** SQL comments, then no SQL statements are evaluated and the database
** is not changed.
**
** Restrictions:
**
** <ul>
** <li> The application must ensure that the 1st parameter to sqlite3_exec()
** is a valid and open [database connection].
** <li> The application must not close the [database connection] specified by
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
** <li> The application must not modify the SQL statement text passed into
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
** </ul>
label: code-design
** Declarations used for tracing the operating system interfaces.
comment: The term to be analyzed
label: code-design
Last UPDATE used (for PK b-tree updates only), or NULL.
** Add a new element to the end of an expression list. If pList is
** initially NULL, then create a new expression list.
**
** If a memory allocation error occurs, the entire list is freed and
** NULL is returned. If non-NULL is returned, then it is guaranteed
** that the new entry was successfully appended.
Pretend we are in EXCLUSIVE mode
*************************************************************************
***************************************************************************
** GENERATED CODE STARTS HERE (mkportersteps.tcl)
308
sqlite3_step() verifies this
True if we need to scan in reverse order
************* Include keywordhash.h in the middle of tokenize.c ***********
************* Include fts3_hash.h in the middle of fts3Int.h **************
This error condition is now caught prior to reaching this function
Offset of pFd to begin writing at
defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
Number of entries in a[]
The name context used to resolve the name
SQLITE_ERROR
Allocate a bitvec to use to store the set of pages rolled back
Offset into aPrefix[] of the prefix string
Pointer to value 2
Array of child nodes
** CAPI3REF: String Comparison
**
** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
** and extensions to compare the contents of two buffers containing UTF-8
** strings in a case-independent fashion, using the same definition of "case
** independence" that SQLite uses internally when comparing identifiers.
** Do various sanity checks on a single page of a tree. Return
** the tree depth. Root pages return 0. Parents of root pages
** return 1, and so forth.
**
** These checks are done:
**
** 1. Make sure that cells and freeblocks do not overlap
** but combine to completely cover the page.
** 2. Make sure integer cell keys are in order.
** 3. Check the integrity of overflow pages.
** 4. Recursively call checkTreePage on all children.
** 5. Verify that the depth of all children is the same.
The OR-clause broken out into subterms
** Deregister and destroy an RBU vfs created by an earlier call to
** sqlite3rbu_create_vfs().
** Possible values for the sqlite3.flags.
**
** Value constraints (enforced via assert()):
** SQLITE_FullFSync == PAGER_FULLFSYNC
** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
** SQLITE_CacheSpill == PAGER_CACHE_SPILL
Make a copy of the entire SELECT statement that defines the view.
** This will force all the Expr.token.z values to be dynamically
** allocated rather than point to the input string - which means that
** they will persist after the current sqlite3_exec() call returns.
adjust the sign of significand
Table column number
660
If MEM_Dyn is set then Mem.xDel!=0.
** Mem.xDel might not be initialized if MEM_Dyn is clear.
Database structure for this iterator
** Only set the lastErrno if the error code is a real error and not
** a normal expected return code of SQLITE_BUSY or SQLITE_OK
Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
** that both the BtShared and database handle mutexes are held.
** FTS maintains a separate indexes for each language-id (a 32-bit integer).
** Within each language id, a separate index is maintained to store the
** document terms, and each configured prefix size (configured the FTS
** "prefix=" option). And each index consists of multiple levels ("relative
** levels").
**
** All three of these values (the language id, the specific index and the
** level within the index) are encoded in 64-bit integer values stored
** in the %_segdir table on disk. This function is used to convert three
** separate component values into the single 64-bit integer value that
** can be used to query the %_segdir table.
**
** Specifically, each language-id/index combination is allocated 1024
** 64-bit integer level values ("absolute levels"). The main terms index
** for language-id 0 is allocate values 0-1023. The first prefix index
** (if any) for language-id 0 is allocated values 1024-2047. And so on.
** Language 1 indexes are allocated immediately following language 0.
**
** So, for a system with nPrefix prefix indexes configured, the block of
** absolute levels that corresponds to language-id iLangid and index
** iIndex starts at absolute level ((iLangid * (nPrefix+1) + iIndex) * 1024).
** Return TRUE if a KeyInfo object can be change. The KeyInfo object
** can only be changed if this is just a single reference to the object.
**
** This routine is used only inside of assert() statements.
comment:
** Open an RBU handle to perform an RBU vacuum on database file zTarget.
** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
** that it can be suspended and resumed like an RBU update.
**
** The second argument to this function identifies a database in which
** to store the state of the RBU vacuum operation if it is suspended. The
** first time sqlite3rbu_vacuum() is called, to start an RBU vacuum
** operation, the state database should either not exist or be empty
** (contain no tables). If an RBU vacuum is suspended by calling
** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
** returned SQLITE_DONE, the vacuum state is stored in the state database.
** The vacuum can be resumed by calling this function to open a new RBU
** handle specifying the same target and state databases.
**
** If the second argument passed to this function is NULL, then the
** name of the state database is "<database>-vacuum", where <database>
** is the name of the target database file. In this case, on UNIX, if the
** state database is not already present in the file-system, it is created
** with the same permissions as the target db is made.
**
** This function does not delete the state database after an RBU vacuum
** is completed, even if it created it. However, if the call to
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
** of the state tables within the state database are zeroed. This way,
** the next call to sqlite3rbu_vacuum() opens a handle that starts a
** new RBU vacuum operation.
**
** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
** describing the sqlite3rbu_create_vfs() API function below for
** a description of the complications associated with using RBU with
** zipvfs databases.
label: code-design
** Bits of the Pager.doNotSpill flag. See further description below.
Mark the page that is about to be modified as dirty.
OUT: Number of FK violations
Used when p4type is P4_FUNCDEF
8x
If more than one term matches the prefix, sort the Fts3HashElem
** objects in term order using qsort(). This uses the same comparison
** callback as is used when flushing terms to disk.
Generating CHECK constraints or inserting into partial index
comment: NOT USED
label: code-design
** This function is called to release all dynamic resources held by the
** merge-writer object pWriter, and if no error has occurred, to flush
** all outstanding node buffers held by pWriter to disk.
**
** If *pRc is not SQLITE_OK when this function is called, then no attempt
** is made to write any data to disk. Instead, this function serves only
** to release outstanding resources.
**
** Otherwise, if *pRc is initially SQLITE_OK and an error occurs while
** flushing buffers to disk, *pRc is set to an SQLite error code before
** returning.
True if yymajor has invoked an error
nBlob==0 in detail=none mode.
** Invoke the profile callback. This routine is only called if we already
** know that the profile callback is defined and needs to be invoked.
** This routine transforms the internal text encoding used by pMem to
** desiredEnc. It is an error if the string is already of the desired
** encoding, or if *pMem does not contain a string value.
Update the write-counter. While doing so, set nWork.
EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
** always be at least one cell before the first freeblock.
Space to hold MEM_Str or MEM_Blob if szMalloc>0
** 2013 November 25
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains pre-processor directives related to operating system
** detection and/or setup.
Various flags. EP_* See below
SQLITE_ENABLE_MEMSYS3
Open the database file. If the btree is successfully opened, use
** it to obtain the database schema. At this point the schema may
** or may not be initialized.
Calculate the estimated cost based on the flags set in idxFlags.
** 2007 August 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement mutexes for pthreads
** pExpr is a comparison operator. Return the type affinity that should
** be applied to both operands prior to doing the comparison.
** Return non-zero if the bit in the IntegrityCk.aPgRef[] array that
** corresponds to page iPg is already set.
The selected WhereLoop object
Opcode: FkIfZero P1 P2 * * *
** Synopsis: if fkctr[P1]==0 goto P2
**
** This opcode tests if a foreign key constraint-counter is currently zero.
** If so, jump to instruction P2. Otherwise, fall through to the next
** instruction.
**
** If P1 is non-zero, then the jump is taken if the database constraint-counter
** is zero (the one that counts deferred constraint violations). If P1 is
** zero, the jump is taken if the statement constraint-counter is zero
** (immediate foreign key constraint violations).
** Set the maximum page count for a database if mxPage is positive.
** No changes are made if mxPage is 0 or negative.
** Regardless of the value of mxPage, return the maximum page count.
** Return true if any register in the range iFrom..iTo (inclusive)
** is used as part of the column cache.
**
** This routine is used within assert() and testcase() macros only
** and does not appear in a normal build.
SQL statement passed to declare_vtab()
maximum depth of the parser stack
Right-child page number (or 0)
Pass the expected checksum down to the FTS index module. It will
** verify, amongst other things, that it matches the checksum generated by
** inspecting the index itself.
Registers holding data and rowid
** Implementation of xRollback(). Discard the contents of the pending-terms
** hash-table. Any changes made to the database are reverted by SQLite.
Total size of one pcache line
** There are 2 different modes of operation for a hash table:
**
** FTS3_HASH_STRING pKey points to a string that is nKey bytes long
** (including the null-terminator, if any). Case
** is respected in comparisons.
**
** FTS3_HASH_BINARY pKey points to binary data nKey bytes long.
** memcmp() is used to compare keys.
**
** A copy of the key is made if the copyKey parameter to fts3HashInit is 1.
1550
** If the last opcode is "op" and it is not a jump destination,
** then remove it. Return true if and only if an opcode was removed.
xSavepoint
pWal->readLock is usually set, but might be -1 if there was a
** prior error while attempting to acquire are read-lock. This cannot
** happen if the connection is actually in exclusive mode (as no xShmLock
** locks are taken in this case). Nor should the pager attempt to
** upgrade to exclusive-mode following such an error.
Set TRUE at EOF. Set false for more content
** Initialize the fts3 extension. If this extension is built as part
** of the sqlite library, then this function is called directly by
** SQLite. If fts3 is built as a dynamically loadable extension, this
** function is called by the sqlite3_extension_init() entry point.
** Return the SQL associated with a prepared statement
** If the current doclist-index accumulating in pWriter->aDlidx[] is large
** enough, flush it to disk and return 1. Otherwise discard it and return
** zero.
Copy of BtShared.maxLocal or BtShared.maxLeaf
comment: One of the P4_xxx constants for p4
label: code-design
** This function does all the work for both the xConnect and xCreate methods.
** These tables have no persistent representation of their own, so xConnect
** and xCreate are identical operations.
**
** argv[0]: module name
** argv[1]: database name
** argv[2]: table name
** argv[3]: first argument (tokenizer name)
Scan query (fts5vocab)
Names of columns for pragmas that return multi-column result
** or that return single-column results where the name of the
** result column is different from the name of the pragma
** This object is a convenience wrapper holding all information needed
** to construct WhereLoop objects for a particular query.
** A macro to discover the encoding of a database.
Size of column value in tokens
Setting isLeftJoin to -1 causes OP_IfNullRow opcodes to be generated for
** every reference to any result column from subquery in a join, even though
** they are not necessary. This will stress-test the OP_IfNullRow opcode.
312
Populate this object
Value of 'pgOffset' column
Link list of trigger program steps
** The zeroblob(N) function returns a zero-filled blob of size N bytes.
Invalidate all ephemeral cursor row caches
Generate code to skip over the creation and initialization of the
** transient index on 2nd and subsequent iterations of the loop.
** If a Win32 native heap has been configured, this function will attempt to
** compact it. Upon success, SQLITE_OK will be returned. Upon failure, one
** of SQLITE_NOMEM, SQLITE_ERROR, or SQLITE_NOTFOUND will be returned. The
** "pnLargest" argument, if non-zero, will be used to return the size of the
** largest committed free block in the heap, in bytes.
"rowid" column of stat[34] entry
duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
** and the SELECT subtree.
250
ASC or DESC for INTEGER PRIMARY KEY
The pSubWInfo->untestedTerms flag means that this OR term
** contained one or more AND term from a notReady table. The
** terms from the notReady table could not be tested and will
** need to be tested later.
Operation performed by this node
Which column of the vector to return
Comparison result if keys are equal
Write the averages record
** Set the SegReader to point to the first docid in the doclist associated
** with the current term.
Obtain a RESERVED lock on the database file. If the exFlag parameter
** is true, then immediately upgrade this to an EXCLUSIVE lock. The
** busy-handler callback can be used when upgrading to the EXCLUSIVE
** lock, but not when obtaining the RESERVED lock.
TEMPORARY
True if there is a doclist-index
Used to iterate name contexts
The routine to run as a thread
** If the following global variable points to a string which is the
** name of a directory, then that directory will be used to store
** all database files specified with a relative pathname.
**
** See also the "PRAGMA data_store_directory" SQL command.
Database only autoinc table
Now begin substituting subquery result set expressions for
** references to the iParent in the outer query.
**
** Example:
**
** SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
** \ \_____________ subquery __________/ /
** \_____________________ outer query ______________________________/
**
** We look at every expression in the outer query and every place we see
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
Mask of FTS5INDEX_QUERY_X flags
True if callback data is initialized
automatically defined by SQLITE_ENABLE_FTS4
The ONEPASS_DESIRED flags never occurs together with ORDER BY
Text of the error report
Number of bytes in string zName
OUT: Number of phrases in query
Compute collating sequences used by
** temporary tables needed to implement the compound select.
** Attach the KeyInfo structure to all temporary tables.
**
** This section is run by the right-most SELECT statement only.
** SELECT statements to the left always skip this part. The right-most
** SELECT might also skip this part if it has no ORDER BY clause and
** no temp tables are required.
Forward reference
WITH => ID
** Allocate a new porter tokenizer. Return a pointer to the new
** tokenizer in *ppModule
SQL-style comments from "--" to end of line
Return the size of an allocation
comment:
** Allocate memory that is to be used and released right away.
** This routine is similar to alloca() in that it is not intended
** for situations where the memory might be held long-term. This
** routine is intended to get memory to old large transient data
** structures that would not normally fit on the stack of an
** embedded processor.
label: code-design
** Generate code for the SELECT statement given in the p argument.
**
** The results are returned according to the SelectDest structure.
** See comments in sqliteInt.h for further information.
**
** This routine returns the number of errors. If any errors are
** encountered, then an appropriate error message is left in
** pParse->zErrMsg.
**
** This routine does NOT free the Select structure passed in. The
** calling function needs to do that.
** Constants used for locking
Reference page
** Return TRUE if zTable is the name of the system table that stores the
** list of users and their access credentials.
** Open an RBU handle.
**
** Argument zTarget is the path to the target database. Argument zRbu is
** the path to the RBU database. Each call to this function must be matched
** by a call to sqlite3rbu_close(). When opening the databases, RBU passes
** the SQLITE_CONFIG_URI flag to sqlite3_open_v2(). So if either zTarget
** or zRbu begin with "file:", it will be interpreted as an SQLite
** database URI, not a regular file name.
**
** If the zState argument is passed a NULL value, the RBU extension stores
** the current state of the update (how many rows have been updated, which
** indexes are yet to be updated etc.) within the RBU database itself. This
** can be convenient, as it means that the RBU application does not need to
** organize removing a separate state file after the update is concluded.
** Or, if zState is non-NULL, it must be a path to a database file in which
** the RBU extension can store the state of the update.
**
** When resuming an RBU update, the zState argument must be passed the same
** value as when the RBU update was started.
**
** Once the RBU update is finished, the RBU extension does not
** automatically remove any zState database file, even if it created it.
**
** By default, RBU uses the default VFS to access the files on disk. To
** use a VFS other than the default, an SQLite "file:" URI containing a
** "vfs=..." option may be passed as the zTarget option.
**
** IMPORTANT NOTE FOR ZIPVFS USERS: The RBU extension works with all of
** SQLite's built-in VFSs, including the multiplexor VFS. However it does
** not work out of the box with zipvfs. Refer to the comment describing
** the zipvfs_create_vfs() API below for details on using RBU with zipvfs.
** The second argument is a Trigger structure allocated by the
** fkActionTrigger() routine. This function deletes the Trigger structure
** and all of its sub-components.
**
** The Trigger structure or any of its sub-components may be allocated from
** the lookaside buffer belonging to database handle dbMem.
Current node image to append to
True if next rowid is first in page
Update the db file change counter via the direct-write method. The
** following call will modify the in-memory representation of page 1
** to include the updated change counter and then write page 1
** directly to the database file. Because of the atomic-write
** property of the host file-system, this is safe.
OUT: True if there are NULL values in PK
FTS5 backend object
Return SQLITE_ROW
same as TK_STRING, out2
Previous id read from aDoclist
RAISE
The page of the frame to be written
Used to iterate through phrase tokens
Name of database file for pPager
The VDBE under construction
The row that the VUpdate opcode will delete: none
** Define the parameters of the hash tables in the wal-index file. There
** is a hash-table following every HASHTABLE_NPAGE page numbers in the
** wal-index.
**
** Changing any of these constants will alter the wal-index format and
** create incompatibilities.
Append a single character
Fts5Storage.aTotalSize[]
Start the view context
(315) foreach_clause ::=
True if RHS must be unique
For STRING expressions, the near cluster
************* End of fault.c **********************************************
Value to return via *paiCol
If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
** fts5_test_mi.c is compiled and linked into the executable. And call
** its entry point to enable the matchinfo() demo.
zName
Check for a "special" INSERT operation. One of the form:
**
** INSERT INTO xyz(xyz) VALUES('command');
UPDATE + DELETE
Cannot be both MEM_Null and some other type
No rowid. PRIMARY KEY is the key
in3
** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
IGNORE
** This function is invoked by the vdbe to call the xDestroy method
** of the virtual table named zTab in database iDb. This occurs
** when a DROP TABLE is mentioned.
**
** This call is a no-op if zTab is not a virtual table.
0x01
Parent frame
Used to iterate through aHash[]
STAT3 and STAT4 have a parameter on this routine.
CONSTRAINT
** Argument pNode is an FTS5_AND node.
assert( db->pPreUpdate->pUnpacked );
Address of OP_FkIfZero
** Recompute pMerger->aTree[iOut] by comparing the next keys on the
** two PmaReaders that feed that entry. Neither of the PmaReaders
** are advanced. This routine merely does the comparison.
xShutdown
3-byte signed integer
This is the sub-WHERE clause body. First skip over
** duplicate rows from prior sub-WHERE clauses, and record the
** rowid (or PRIMARY KEY) for the current row so that the same
** row will be skipped in subsequent sub-WHERE clauses.
Create an implicit NOT operator.
** json_array_length(JSON)
** json_array_length(JSON, PATH)
**
** Return the number of elements in the top-level JSON array.
** Return 0 if the input is not a well-formed JSON array.
Two copies of the header content
Program counter
Allocate the Fts5Bm25Data object
If there is no more data to be read from the buffer, read the next
** p->nBuffer bytes of data from the file into it. Or, if there are less
** than p->nBuffer bytes remaining in the PMA, read all remaining data.
** Rtree virtual table module xFilter method.
Visibility of parent node
** Read an entry from the pointer map.
**
** This routine retrieves the pointer map entry for page 'key', writing
** the type and parent page number to *pEType and *pPgno respectively.
** An error code is returned if something goes wrong, otherwise SQLITE_OK.
Remove page from cache
Cursor number of the subquery
SELECT may not have a LIMIT clause
Beginning here are the reduction cases. A typical example
** follows:
** case 0:
** #line <lineno> <grammarfile>
** { ... } // User supplied code
** #line <lineno> <thisfile>
** break;
** Attempt to seek the file-descriptor passed as the first argument to
** absolute offset iOff, then attempt to write nBuf bytes of data from
** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise,
** return the actual number of bytes written (which may be less than
** nBuf).
End mark for a varint
If RESTRICT, "SELECT RAISE(...)"
Open the index sub-system
** Convert a scalar expression node to a TK_REGISTER referencing
** register iReg. The caller must ensure that iReg already contains
** the correct value for the expression.
Uncommitted Hash table changes
** An instance of the following structure holds information about SQL
** functions arguments that are the parameters to the printf() function.
Set the P5 operand of the OP_Program instruction to non-zero if
** recursive invocation of this trigger program is disallowed. Recursive
** invocation is disallowed if (a) the sub-program is really a trigger,
** not a foreign key action, and (b) the flag to enable recursive triggers
** is clear.
Subtask context (for pKeyInfo)
The pBt is no longer on the sharing list, so we can access
** it without having to hold the mutex.
**
** Clean out and delete the BtShared object.
OUT: SQLite db handle
Opcode: AutoCommit P1 P2 * * *
**
** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
** back any currently active btree transactions. If there are any active
** VMs (apart from this one), then a ROLLBACK fails. A COMMIT fails if
** there are active writing VMs or active VMs that use shared cache.
**
** This instruction causes the VM to halt.
Has no NOT INDEXED clause
comment: Convert the data in the temporary table into whatever form
** it is that we currently need.
label: code-design
comment: Zero or more PragFlg_XXX values
label: code-design
Number of entries in aExt[]
VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS)
ccons ::= DEFAULT ID|INDEXED
Set pFile->locktype to this value before exiting
The desired encoding for the collating sequence
For operators other than UNION ALL we have to make sure that
** the ORDER BY clause covers every term of the result set. Add
** terms to the ORDER BY clause as necessary.
comment: Remove the xxx_parent entry.
label: code-design
** Form A:
** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
**
** Form B:
** CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
**
** Form A is can be transformed into the equivalent form B as follows:
** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
** WHEN x=eN THEN rN ELSE y END
**
** X (if it exists) is in pExpr->pLeft.
** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
** odd. The Y is also optional. If the number of elements in x.pList
** is even, then Y is omitted and the "otherwise" result is NULL.
** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
**
** The result of the expression is the Ri for the first matching Ei,
** or if there is no matching Ei, the ELSE term Y, or if there is
** no ELSE term, NULL.
** Write mapping (iNode->iPar) to the <rtree>_parent table.
Affinity of the LHS of the IN
Last page in WAL for this reader
Number of docs in database
** An instance of the following type is used to iterate through the contents
** of a doclist-index record.
**
** pData:
** Record containing the doclist-index data.
**
** bEof:
** Set to true once iterator has reached EOF.
**
** iOff:
** Set to the current offset within record pData.
Assert that the p1 parameter is valid. Also that if there is no open
** transaction, then there cannot be any savepoints.
the WHERE clause
** Allocate and return a new expression object. If anything goes wrong (i.e.
** OOM error), leave an error code in pParse and return NULL.
Checkpoint and close the log. Because an EXCLUSIVE lock is held on
** the database file, the log and log-summary files will be deleted.
The table being read
comment: The FROM clause btree term to add
label: code-design
Offsets into aPoslist for current row
pPager->xBusyHandler = 0;
** Append the hash of the 64-bit integer passed as the second argument to the
** hash-key value passed as the first. Return the new hash-key value.
PRAGMA synchronous=OFF
EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
** equivalent to likelihood(X, 0.0625).
** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
** short-hand for likelihood(X,0.0625).
** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
** for likelihood(X,0.9375).
** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
** to likelihood(X,0.9375).
Sizes of each column, in tokens
Function used to reclaim memory
************* Begin file update.c *****************************************
Populate this structure before returning.
The return address register
If we are holding a PENDING lock that ought to be released, then
** release it now.
** Change the limit on the amount of the database file that may be
** memory mapped.
If pTemplate is always better than p, then cause p to be overwritten
** with pTemplate. pTemplate is better than p if:
** (1) pTemplate has no more dependences than p, and
** (2) pTemplate has an equal or lower cost than p.
Use ExprList.u.x.iOrderByCol
All table that pExpr might refer to
ColNames:
** 2015 May 08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This is an SQLite virtual table module implementing direct access to an
** existing FTS5 index. The module may create several different types of
** tables:
**
** col:
** CREATE TABLE vocab(term, col, doc, cnt, PRIMARY KEY(term, col));
**
** One row for each term/column combination. The value of $doc is set to
** the number of fts5 rows that contain at least one instance of term
** $term within column $col. Field $cnt is set to the total number of
** instances of term $term in column $col (in any row of the fts5 table).
**
** row:
** CREATE TABLE vocab(term, doc, cnt, PRIMARY KEY(term));
**
** One row for each term in the database. The value of $doc is set to
** the number of fts5 rows that contain at least one instance of term
** $term. Field $cnt is set to the total number of instances of term
** $term in the database.
** CAPI3REF: Constants Passed To The Conflict Handler
**
** Values that may be passed as the second argument to a conflict-handler.
**
** <dl>
** <dt>SQLITE_CHANGESET_DATA<dd>
** The conflict handler is invoked with CHANGESET_DATA as the second argument
** when processing a DELETE or UPDATE change if a row with the required
** PRIMARY KEY fields is present in the database, but one or more other
** (non primary-key) fields modified by the update do not contain the
** expected "before" values.
**
** The conflicting row, in this case, is the database row with the matching
** primary key.
**
** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
** argument when processing a DELETE or UPDATE change if a row with the
** required PRIMARY KEY fields is not present in the database.
**
** There is no conflicting row in this case. The results of invoking the
** sqlite3changeset_conflict() API are undefined.
**
** <dt>SQLITE_CHANGESET_CONFLICT<dd>
** CHANGESET_CONFLICT is passed as the second argument to the conflict
** handler while processing an INSERT change if the operation would result
** in duplicate primary key values.
**
** The conflicting row in this case is the database row with the matching
** primary key.
**
** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
** If foreign key handling is enabled, and applying a changeset leaves the
** database in a state containing foreign key violations, the conflict
** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
** exactly once before the changeset is committed. If the conflict handler
** returns CHANGESET_OMIT, the changes, including those that caused the
** foreign key constraint violation, are committed. Or, if it returns
** CHANGESET_ABORT, the changeset is rolled back.
**
** No current or conflicting row information is provided. The only function
** it is possible to call on the supplied sqlite3_changeset_iter handle
** is sqlite3changeset_fk_conflicts().
**
** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
** If any other constraint violation occurs while applying a change (i.e.
** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
** invoked with CHANGESET_CONSTRAINT as the second argument.
**
** There is no conflicting row in this case. The results of invoking the
** sqlite3changeset_conflict() API are undefined.
**
** </dl>
comment: Initialize the output variables to -1 in case an error occurs.
label: code-design
Length of string argv[1]
printf("SQL: [%s]\n", zSql); fflush(stdout);
OUT: Jump to this label to skip partial index
Compare size with this KeyInfo
Write the term for this entry to disk.
Set if global data is loaded
Neither sqlite3changeset_old or sqlite3changeset_new can fail if the
** argument iterator points to a suitable entry. Make sure that xValue
** is one of these to guarantee that it is safe to ignore the return
** in the code below.
** Combine two changesets together.
OUT: Total number of OR nodes in expr.
Object partially overlaps query region
** RECORD FORMAT:
**
** The following record format is similar to (but not compatible with) that
** used in SQLite database files. This format is used as part of the
** change-set binary format, and so must be architecture independent.
**
** Unlike the SQLite database record format, each field is self-contained -
** there is no separation of header and data. Each field begins with a
** single byte describing its type, as follows:
**
** 0x00: Undefined value.
** 0x01: Integer value.
** 0x02: Real value.
** 0x03: Text value.
** 0x04: Blob value.
** 0x05: SQL NULL value.
**
** Note that the above match the definitions of SQLITE_INTEGER, SQLITE_TEXT
** and so on in sqlite3.h. For undefined and NULL values, the field consists
** only of the single type byte. For other types of values, the type byte
** is followed by:
**
** Text values:
** A varint containing the number of bytes in the value (encoded using
** UTF-8). Followed by a buffer containing the UTF-8 representation
** of the text value. There is no nul terminator.
**
** Blob values:
** A varint containing the number of bytes in the value, followed by
** a buffer containing the value itself.
**
** Integer values:
** An 8-byte big-endian integer value.
**
** Real values:
** An 8-byte big-endian IEEE 754-2008 real value.
**
** Varint values are encoded in the same way as varints in the SQLite
** record format.
**
** CHANGESET FORMAT:
**
** A changeset is a collection of DELETE, UPDATE and INSERT operations on
** one or more tables. Operations on a single table are grouped together,
** but may occur in any order (i.e. deletes, updates and inserts are all
** mixed together).
**
** Each group of changes begins with a table header:
**
** 1 byte: Constant 0x54 (capital 'T')
** Varint: Number of columns in the table.
** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
** N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated.
**
** Followed by one or more changes to the table.
**
** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
** 1 byte: The "indirect-change" flag.
** old.* record: (delete and update only)
** new.* record: (insert and update only)
**
** The "old.*" and "new.*" records, if present, are N field records in the
** format described above under "RECORD FORMAT", where N is the number of
** columns in the table. The i'th field of each record is associated with
** the i'th column of the table, counting from left to right in the order
** in which columns were declared in the CREATE TABLE statement.
**
** The new.* record that is part of each INSERT change contains the values
** that make up the new row. Similarly, the old.* record that is part of each
** DELETE change contains the values that made up the row that was deleted
** from the database. In the changeset format, the records that are part
** of INSERT or DELETE changes never contain any undefined (type byte 0x00)
** fields.
**
** Within the old.* record associated with an UPDATE change, all fields
** associated with table columns that are not PRIMARY KEY columns and are
** not modified by the UPDATE change are set to "undefined". Other fields
** are set to the values that made up the row before the UPDATE that the
** change records took place. Within the new.* record, fields associated
** with table columns modified by the UPDATE change contain the new
** values. Fields associated with table columns that are not modified
** are set to "undefined".
**
** PATCHSET FORMAT:
**
** A patchset is also a collection of changes. It is similar to a changeset,
** but leaves undefined those fields that are not useful if no conflict
** resolution is required when applying the changeset.
**
** Each group of changes begins with a table header:
**
** 1 byte: Constant 0x50 (capital 'P')
** Varint: Number of columns in the table.
** nCol bytes: 0x01 for PK columns, 0x00 otherwise.
** N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated.
**
** Followed by one or more changes to the table.
**
** 1 byte: Either SQLITE_INSERT (0x12), UPDATE (0x17) or DELETE (0x09).
** 1 byte: The "indirect-change" flag.
** single record: (PK fields for DELETE, PK and modified fields for UPDATE,
** full record for INSERT).
**
** As in the changeset format, each field of the single record that is part
** of a patchset change is associated with the correspondingly positioned
** table column, counting from left to right within the CREATE TABLE
** statement.
**
** For a DELETE change, all fields within the record except those associated
** with PRIMARY KEY columns are set to "undefined". The PRIMARY KEY fields
** contain the values identifying the row to delete.
**
** For an UPDATE change, all fields except those associated with PRIMARY KEY
** columns and columns that are modified by the UPDATE are set to "undefined".
** PRIMARY KEY fields contain the values identifying the table row to update,
** and fields associated with modified columns contain the new column values.
**
** The records associated with INSERT changes are in the same format as for
** changesets. It is not possible for a record associated with an INSERT
** change to contain a field set to "undefined".
comment:
** Implementation of the sqlite3_pcache.xFetch method.
**
** Fetch a page by key value.
**
** Whether or not a new page may be allocated by this function depends on
** the value of the createFlag argument. 0 means do not allocate a new
** page. 1 means allocate a new page if space is easily available. 2
** means to try really hard to allocate a new page.
**
** For a non-purgeable cache (a cache used as the storage for an in-memory
** database) there is really no difference between createFlag 1 and 2. So
** the calling function (pcache.c) will never have a createFlag of 1 on
** a non-purgeable cache.
**
** There are three different approaches to obtaining space for a page,
** depending on the value of parameter createFlag (which may be 0, 1 or 2).
**
** 1. Regardless of the value of createFlag, the cache is searched for a
** copy of the requested page. If one is found, it is returned.
**
** 2. If createFlag==0 and the page is not already in the cache, NULL is
** returned.
**
** 3. If createFlag is 1, and the page is not already in the cache, then
** return NULL (do not allocate a new page) if any of the following
** conditions are true:
**
** (a) the number of pages pinned by the cache is greater than
** PCache1.nMax, or
**
** (b) the number of pages pinned by the cache is greater than
** the sum of nMax for all purgeable caches, less the sum of
** nMin for all other purgeable caches, or
**
** 4. If none of the first three conditions apply and the cache is marked
** as purgeable, and if one of the following is true:
**
** (a) The number of pages allocated for the cache is already
** PCache1.nMax, or
**
** (b) The number of pages allocated for all purgeable caches is
** already equal to or greater than the sum of nMax for all
** purgeable caches,
**
** (c) The system is under memory pressure and wants to avoid
** unnecessary pages cache entry allocations
**
** then attempt to recycle a page from the LRU list. If it is the right
** size, return the recycled buffer. Otherwise, free the buffer and
** proceed to step 5.
**
** 5. Otherwise, allocate and return a new page buffer.
**
** There are two versions of this routine. pcache1FetchWithMutex() is
** the general case. pcache1FetchNoMutex() is a faster implementation for
** the common case where pGroup->mutex is NULL. The pcache1Fetch() wrapper
** invokes the appropriate routine.
label: code-design
Register storing resulting
21
Generate code to this VDBE
Search for this index expression
transtype ::= DEFERRED
** Called during virtual module initialization to register UDF
** fts5_decode() with SQLite
** Use standard C library malloc and free on non-Apple systems.
** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
x>EXPR or x>=EXPR constraint
xCurrentTimeInt64 (version 2)
Allocate the sqlite data structure
Number of bytes to allocate
Size of doclist
Original value of pNew->wsFlags
comment: Update the Fts5PageWriter.term field.
label: code-design
The cursor to be moved
Encoding did not change
Size of the journal file in bytes
!defined(_OS_COMMON_H_)
** INSERT OR REPLACE a record into the %_data table.
WHERE rowid ..
File descriptor for sub-journal
The iterator to advance by one position
For use by extension VFS
In an UPDATE operation, if this index is the PRIMARY KEY index
** of a WITHOUT ROWID table and there has been no change the
** primary key, then no collision is possible. The collision detection
** logic below can all be skipped.
synopsis: if fkctr[P1]==0 goto P2
comment: NB: The sqlite3OpcodeName() function is implemented by code created
** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
** information from the vdbe.c source text
label: code-design
PRAGMA fullfsync=ON
RO incr-blob open on %_data table
Write cell size here
**
** This function appends an update change to the buffer (see the comments
** under "CHANGESET FORMAT" at the top of the file). An update change
** consists of:
**
** 1 byte: SQLITE_UPDATE (0x17)
** n bytes: old.* record (see RECORD FORMAT)
** m bytes: new.* record (see RECORD FORMAT)
**
** The SessionChange object passed as the third argument contains the
** values that were stored in the row when the session began (the old.*
** values). The statement handle passed as the second argument points
** at the current version of the row (the new.* values).
**
** If all of the old.* values are equal to their corresponding new.* value
** (i.e. nothing has changed), then no data at all is appended to the buffer.
**
** Otherwise, the old.* record contains all primary key values and the
** original values of any fields that have been modified. The new.* record
** contains the new values of only those fields that have been modified.
** Allocate k new pages. Reuse old pages where possible.
************* End of analyze.c ********************************************
True if second change is indirect
fall thru
** Return the maximum amount of memory that has ever been
** checked out since either the beginning of this process
** or since the most recent reset.
First token in coalesced phrase instance
Set nDestTruncate to the final number of pages in the destination
** database. The complication here is that the destination page
** size may be different to the source page size.
**
** If the source page size is smaller than the destination page size,
** round up. In this case the call to sqlite3OsTruncate() below will
** fix the size of the file. However it is important to call
** sqlite3PagerTruncateImage() here so that any pages in the
** destination file that lie beyond the nDestTruncate page mark are
** journalled by PagerCommitPhaseOne() before they are destroyed
** by the file truncation.
Position of last value written
Byte offset of end of current token
Like SRT_Fifo, but unique results only
Opcode: DecrJumpZero P1 P2 * * *
** Synopsis: if (--r[P1])==0 goto P2
**
** Register P1 must hold an integer. Decrement the value in P1
** and jump to P2 if the new value is exactly zero.
IMPLEMENTATION-OF: R-57228-12904 Invoking sqlite3_finalize() on a NULL
** pointer is a harmless no-op.
** Allocate a new segment-id for the structure pStruct. The new segment
** id must be between 1 and 65335 inclusive, and must not be used by
** any currently existing segment. If a free segment id cannot be found,
** SQLITE_FULL is returned.
**
** If an error has already occurred, this function is a no-op. 0 is
** returned in this case.
Fall through into OP_NotExists
term ::= STRING
** Additional bit values that can be ORed with an affinity without
** changing the affinity.
**
** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
** It causes an assert() to fire if either operand to a comparison
** operator is NULL. It is added to certain comparison operators to
** prove that the operands are always NOT NULL.
DB Page containing root of this index
True if this is the first term written
Index in pSrc->a[] of first new slot
(299) tconscomma ::=
The Windows errno from the last I/O error
The token that holds the name of the view
Construct an expression node for a unary postfix operator
** One of the cells in node pNode is guaranteed to have a 64-bit
** integer value equal to iRowid. Return the index of this cell.
Multi-segment-reader handle
** Invoke SQLITE_FCNTL_MMAP_SIZE based on the current value of szMmap.
** Try to provide a memory barrier operation, needed for initialization
** and also for the xShmBarrier method of the VFS in cases when SQLite is
** compiled without mutexes (SQLITE_THREADSAFE=0).
Integer value of left operand
Previous in LRU list of unpinned pages
Free allocated structure
** Set the Pager.xGet method for the appropriate routine used to fetch
** content from the pager.
See the tool/mkopcodeh.tcl script for details
Number of bytes to read
Number of child nodes
Write the record
comment: Sort entries into the forest on the first test of a new batch.
** To save unnecessary work, only do this when the batch number changes.
label: code-design
Deprecated
COLLATE
IN/OUT: The WHERE clause to add to
pArg
SQLITE_UPDATE, DELETE or INSERT
Pointer to allocation
************* Begin file date.c *******************************************
Number of memory cells used so far
CREATE => nothing
Select a sub-task to sort and flush the current list of in-memory
** records to disk. If the sorter is running in multi-threaded mode,
** round-robin between the first (pSorter->nTask-1) tasks. Except, if
** the background thread from a sub-tasks previous turn is still running,
** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
** fall back to using the final sub-task. The first (pSorter->nTask-1)
** sub-tasks are prefered as they use background threads - the final
** sub-task uses the main thread.
pPager->pFirst = 0;
Shorthand for pTerm->eOperator
restore the original locking context and pMethod then close it
SQLITE_OS_UNIX && defined(SQLITE_MUTEX_PTHREADS)
** Iterator pIter currently points to the first rowid in a doclist. This
** function sets the iterator up so that iterates in reverse order through
** the doclist.
neardist_opt ::= COMMA STRING
** Return true if a memory cell is not marked as invalid. This macro
** is for use inside assert() statements only.
This is one term of an OR-optimization using the PRIMARY KEY of a
** WITHOUT ROWID table. No need for a separate index
The "B" part of a "A AS B" phrase. zName is the "A"
The new freeblock is at the beginning of the cell content area,
** so just extend the cell content area rather than create another
** freelist entry
** An SQL parser context. A copy of this structure is passed through
** the parser and down into all the parser action routine in order to
** carry around information that is global to the entire parse.
**
** The structure is divided into two parts. When the parser and code
** generate call themselves recursively, the first part of the structure
** is constant but the second part is reset at the beginning and end of
** each recursion.
**
** The nTableLock and aTableLock variables are only used if the shared-cache
** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are
** used to store the set of table-locks required by the statement being
** compiled. Function sqlite3TableLock() is used to add entries to the
** list.
** Open an in-memory journal file.
On OS X on an msdos filesystem, the inode number is reported
** incorrectly for zero-size files. See ticket #3260. To work
** around this problem (we consider it a bug in OS X, not SQLite)
** we always increase the file size to 1 by writing a single byte
** prior to accessing the inode number. The one byte written is
** an ASCII 'S' character which also happens to be the first byte
** in the header of every SQLite database. In this way, if there
** is a race condition such that another thread has already populated
** the first page of the database, no damage is done.
** Decrement the BtShared.nRef counter. When it reaches zero,
** remove the BtShared structure from the sharing list. Return
** true if the BtShared.nRef counter reaches zero and return
** false if it is still positive.
True to enable triggers
** This routine sets the value to be returned by subsequent calls to
** sqlite3_changes() on the database handle 'db'.
Acts as query when has one argument
** This function merges two sorted lists into a single sorted list.
**
** aLeft[] and aRight[] are arrays of indices. The sort key is
** aContent[aLeft[]] and aContent[aRight[]]. Upon entry, the following
** is guaranteed for all J<K:
**
** aContent[aLeft[J]] < aContent[aLeft[K]]
** aContent[aRight[J]] < aContent[aRight[K]]
**
** This routine overwrites aRight[] with a new (probably longer) sequence
** of indices such that the aRight[] contains every index that appears in
** either aLeft[] or the old aRight[] and such that the second condition
** above is still met.
**
** The aContent[aLeft[X]] values will be unique for all X. And the
** aContent[aRight[X]] values will be unique too. But there might be
** one or more combinations of X and Y such that
**
** aLeft[X]!=aRight[Y] && aContent[aLeft[X]] == aContent[aRight[Y]]
**
** When that happens, omit the aLeft[X] and use the aRight[Y] index.
Switch on the character-class of the first byte
** of the token. See the comment on the CC_ defines
** above.
File descriptor to write to
** This is called during initialization to register the fts5_expr() scalar
** UDF with the SQLite handle passed as the only argument.
Number of active VDBEs that read and write
** Destroy the part of winFile that deals with wince locks
Number of active OP_VDestroy operations
try to create all the intermediate directories
OE_Abort, OE_Ignore, OE_Replace, or OE_None
** Delete all cached deferred doclists. Deferred doclists are cached
** (allocated) by the sqlite3Fts3CacheDeferredDoclists() function.
True if is an aggregate function
Allocate new SessionTable object.
Error and awaiting close
Original value of pNew->u.btree.nTop
FTS5_MAX_SEGMENT is currently defined as 2000. So the following
** array is 63 elements, or 252 bytes, in size.
Join all threads
This is really OP_Noop and OP_Explain
If recursive mutexes are not available, then we have to grow
** our own. This implementation assumes that pthread_equal()
** is atomic - that it cannot be deceived into thinking self
** and p->owner are equal if p->owner changes between two values
** that are not equal to self while the comparison is taking place.
** This implementation also assumes a coherent cache - that
** separate processes cannot read different values from the same
** address at the same time. If either of these two conditions
** are not met, then the mutexes will fail and problems will result.
OUT: True to retry.
Get an EXCLUSIVE lock on the database file. At this point it is
** important that a RESERVED lock is not obtained on the way to the
** EXCLUSIVE lock. If it were, another process might open the
** database file, detect the RESERVED lock, and conclude that the
** database is safe to read while this process is still rolling the
** hot-journal back.
**
** Because the intermediate RESERVED lock is not requested, any
** other process attempting to access the database file will get to
** this point in the code and fail to obtain its own EXCLUSIVE lock
** on the database file.
**
** Unless the pager is in locking_mode=exclusive mode, the lock is
** downgraded to SHARED_LOCK before this function returns.
End switch over the format type
Assume an indexed expression can always yield a NULL
** This function retrieves the doclist for the specified term (or term
** prefix) from the database.
Advance iterator ctx.iter so that it points to the first coalesced
** phrase instance at or following position iBestStart.
Name of rank and rowid columns
** Insert or replace a WhereLoop entry using the template supplied.
**
** An existing WhereLoop entry might be overwritten if the new template
** is better and has fewer dependencies. Or the template will be ignored
** and no insert will occur if an existing WhereLoop is faster and has
** fewer dependencies than the template. Otherwise a new WhereLoop is
** added based on the template.
**
** If pBuilder->pOrSet is not NULL then we care about only the
** prerequisites and rRun and nOut costs of the N best loops. That
** information is gathered in the pBuilder->pOrSet object. This special
** processing mode is used only for OR clause processing.
**
** When accumulating multiple loops (when pBuilder->pOrSet is NULL) we
** still might overwrite similar loops with the new template if the
** new template is better. Loops may be overwritten if the following
** conditions are met:
**
** (1) They have the same iTab.
** (2) They have the same iSortIdx.
** (3) The template has same or fewer dependencies than the current loop
** (4) The template has the same or lower cost than the current loop
** Return True if it is possible that pIndex might be useful in
** implementing the ORDER BY clause in pBuilder.
**
** Return False if pBuilder does not contain an ORDER BY clause or
** if there is no way for pIndex to be useful in implementing that
** ORDER BY clause.
rowid == ?
Node number of parent node
Array of hash slots
Jump over the subroutines
comment: Avoid memory leak when malloc fails
label: code-design
If after trying to extract new entries from the header, nHdrParsed is
** still not up to p2, that means that the record has fewer than p2
** columns. So the result will be either the default value or a NULL.
980
Opcode to add sorter record to sorter
************* Begin file trigger.c ****************************************
1250
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
** alternative memory allocator is engaged to handle all of SQLites
** memory allocation needs.
Set of table index masks
The query is a simple term lookup that matches at most one term in
** the index. All that is required is a straight hash-lookup.
**
** Because the stack address of pE may be accessed via the aElem pointer
** below, the "Fts3HashElem *pE" must be declared so that it is valid
** within this entire function, not just this "else{...}" block.
pIdx is not a UNIQUE index
EVIDENCE-OF: R-53367-43190 If either argument to this option is
** negative, then that argument is changed to its compile-time default.
**
** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
** silently truncated if necessary so that it does not exceed the
** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
** compile-time option.
Length of database filename - dbPath
** Database Format of R-Tree Tables
** --------------------------------
**
** The data structure for a single virtual r-tree table is stored in three
** native SQLite tables declared as follows. In each case, the '%' character
** in the table name is replaced with the user-supplied name of the r-tree
** table.
**
** CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
** CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
** CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
**
** The data for each node of the r-tree structure is stored in the %_node
** table. For each node that is not the root node of the r-tree, there is
** an entry in the %_parent table associating the node with its parent.
** And for each row of data in the table, there is an entry in the %_rowid
** table that maps from the entries rowid to the id of the node that it
** is stored on.
**
** The root node of an r-tree always exists, even if the r-tree table is
** empty. The nodeno of the root node is always 1. All other nodes in the
** table must be the same size as the root node. The content of each node
** is formatted as follows:
**
** 1. If the node is the root node (node 1), then the first 2 bytes
** of the node contain the tree depth as a big-endian integer.
** For non-root nodes, the first 2 bytes are left unused.
**
** 2. The next 2 bytes contain the number of entries currently
** stored in the node.
**
** 3. The remainder of the node contains the node entries. Each entry
** consists of a single 8-byte integer followed by an even number
** of 4-byte coordinates. For leaf nodes the integer is the rowid
** of a record. For internal nodes it is the node number of a
** child page.
comment: Execute assert() statements to ensure that the Vdbe.apCsr[] and
** Vdbe.aMem[] arrays have already been cleaned up.
label: code-design
** Return a checksum of all entries in the FTS index that correspond to
** language id iLangid. The checksum is calculated by XORing the checksums
** of each individual entry (see fts3ChecksumEntry()) together.
**
** If successful, the checksum value is returned and *pRc set to SQLITE_OK.
** Otherwise, if an error occurs, *pRc is set to an SQLite error code. The
** return value is undefined in this case.
OUT: Results of parse
WITH clause that pCte belongs to
Possible values for RtreeConstraint.op
Mark node i of pParse as being a child of iParent. Call recursively
** to fill in all the descendants of node i.
Allocate the array of TermOffset iterators.
CURRENT_TIME
** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
int *psz
Releasing a pending lock
Combination of the previous two
** Attempt to automatically detect the operating system and setup the
** necessary pre-processor macros for it.
Prerequesites of the pExpr->pLeft
ccons ::= DEFAULT term
Index cursor
comment:
** This function is called just before writing a set of frames to the log
** file (see sqlite3WalFrames()). It checks to see if, instead of appending
** to the current log file, it is possible to overwrite the start of the
** existing log file with the new frames (i.e. "reset" the log). If so,
** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
** unchanged.
**
** SQLITE_OK is returned if no error is encountered (regardless of whether
** or not pWal->hdr.mxFrame is modified). An SQLite error code is returned
** if an error occurs.
label: code-design
Bytes to allocate for PCache
************* Include os_common.h in the middle of mutex_w32.c ************
from ::= FROM seltablist
IMP: R-26835-10964
xOpen - open a cursor
comment:
** This routine attempts to flatten subqueries as a performance optimization.
** This routine returns 1 if it makes changes and 0 if no flattening occurs.
**
** To understand the concept of flattening, consider the following
** query:
**
** SELECT a FROM (SELECT x+y AS a FROM t1 WHERE z<100) WHERE a>5
**
** The default way of implementing this query is to execute the
** subquery first and store the results in a temporary table, then
** run the outer query on that temporary table. This requires two
** passes over the data. Furthermore, because the temporary table
** has no indices, the WHERE clause on the outer query cannot be
** optimized.
**
** This routine attempts to rewrite queries such as the above into
** a single flat select, like this:
**
** SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
**
** The code generated for this simplification gives the same result
** but only has to scan the data once. And because indices might
** exist on the table t1, a complete scan of the data might be
** avoided.
**
** Flattening is only attempted if all of the following are true:
**
** (1) The subquery and the outer query do not both use aggregates.
**
** (2) The subquery is not an aggregate or (2a) the outer query is not a join
** and (2b) the outer query does not use subqueries other than the one
** FROM-clause subquery that is a candidate for flattening. (2b is
** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
**
** (3) The subquery is not the right operand of a LEFT JOIN
** or (a) the subquery is not itself a join and (b) the FROM clause
** of the subquery does not contain a virtual table and (c) the
** outer query is not an aggregate.
**
** (4) The subquery is not DISTINCT.
**
** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
** sub-queries that were excluded from this optimization. Restriction
** (4) has since been expanded to exclude all DISTINCT subqueries.
**
** (6) The subquery does not use aggregates or the outer query is not
** DISTINCT.
**
** (7) The subquery has a FROM clause. TODO: For subqueries without
** A FROM clause, consider adding a FROM clause with the special
** table sqlite_once that consists of a single row containing a
** single NULL.
**
** (8) The subquery does not use LIMIT or the outer query is not a join.
**
** (9) The subquery does not use LIMIT or the outer query does not use
** aggregates.
**
** (**) Restriction (10) was removed from the code on 2005-02-05 but we
** accidently carried the comment forward until 2014-09-15. Original
** text: "The subquery does not use aggregates or the outer query
** does not use LIMIT."
**
** (11) The subquery and the outer query do not both have ORDER BY clauses.
**
** (**) Not implemented. Subsumed into restriction (3). Was previously
** a separate restriction deriving from ticket #350.
**
** (13) The subquery and outer query do not both use LIMIT.
**
** (14) The subquery does not use OFFSET.
**
** (15) The outer query is not part of a compound select or the
** subquery does not have a LIMIT clause.
** (See ticket #2339 and ticket [02a8e81d44]).
**
** (16) The outer query is not an aggregate or the subquery does
** not contain ORDER BY. (Ticket #2942) This used to not matter
** until we introduced the group_concat() function.
**
** (17) The sub-query is not a compound select, or it is a UNION ALL
** compound clause made up entirely of non-aggregate queries, and
** the parent query:
**
** * is not itself part of a compound select,
** * is not an aggregate or DISTINCT query, and
** * is not a join
**
** The parent and sub-query may contain WHERE clauses. Subject to
** rules (11), (13) and (14), they may also contain ORDER BY,
** LIMIT and OFFSET clauses. The subquery cannot use any compound
** operator other than UNION ALL because all the other compound
** operators have an implied DISTINCT which is disallowed by
** restriction (4).
**
** Also, each component of the sub-query must return the same number
** of result columns. This is actually a requirement for any compound
** SELECT statement, but all the code here does is make sure that no
** such (illegal) sub-query is flattened. The caller will detect the
** syntax error and return a detailed message.
**
** (18) If the sub-query is a compound select, then all terms of the
** ORDER by clause of the parent must be simple references to
** columns of the sub-query.
**
** (19) The subquery does not use LIMIT or the outer query does not
** have a WHERE clause.
**
** (20) If the sub-query is a compound select, then it must not use
** an ORDER BY clause. Ticket #3773. We could relax this constraint
** somewhat by saying that the terms of the ORDER BY clause must
** appear as unmodified result columns in the outer query. But we
** have other optimizations in mind to deal with that case.
**
** (21) The subquery does not use LIMIT or the outer query is not
** DISTINCT. (See ticket [752e1646fc]).
**
** (22) The subquery is not a recursive CTE.
**
** (23) The parent is not a recursive CTE, or the sub-query is not a
** compound query. This restriction is because transforming the
** parent to a compound query confuses the code that handles
** recursive queries in multiSelect().
**
** (24) The subquery is not an aggregate that uses the built-in min() or
** or max() functions. (Without this restriction, a query like:
** "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
** return the value X for which Y was maximal.)
**
**
** In this routine, the "p" parameter is a pointer to the outer query.
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
**
** If flattening is not attempted, this routine is a no-op and returns 0.
** If flattening is attempted this routine returns 1.
**
** All of the expression analysis must occur on both the outer query and
** the subquery before this routine runs.
label: code-design
** Implement a memory barrier or memory fence on shared memory.
**
** All loads and stores begun before the barrier must complete before
** any load or store begun after the barrier.
** Return a pointer to the data for the specified page.
** The proxy locking method is a "super-method" in the sense that it
** opens secondary file descriptors for the conch and lock files and
** it uses proxy, dot-file, AFP, and flock() locking methods on those
** secondary files. For this reason, the division that implements
** proxy locking is located much further down in the file. But we need
** to go ahead and define the sqlite3_io_methods and finder function
** for proxy locking here. So we forward declare the I/O methods.
Bytes of text in zName
File descriptor open on db file
If pLast is NULL at this point, then the last rowid for this doclist
** lies on the page currently indicated by the iterator. In this case
** pIter->iLeafOffset is already set to point to the position-list size
** field associated with the first relevant rowid on the page.
**
** Or, if pLast is non-NULL, then it is the page that contains the last
** rowid. In this case configure the iterator so that it points to the
** first rowid on this page.
** Return the number of connections to the BtShared object accessed by
** the Btree handle passed as the only argument. For private caches
** this is always 1. For shared caches it may be 1 or greater.
The BLOB encoding of the document size
Next value in trailing position list
Language id for tokenizer
The "docid <= ?" constraint, if any
If pToRelease is not zero than pPayload points into the data area
** of pToRelease. Make sure pToRelease is still writeable.
** Generate code that will do an analysis of a single table in
** a database. If pOnlyIdx is not NULL then it is a single index
** in pTab that should be analyzed.
Opcode: NewRowid P1 P2 P3 * *
** Synopsis: r[P2]=rowid
**
** Get a new integer record number (a.k.a "rowid") used as the key to a table.
** The record number is not previously used as a key in the database
** table that cursor P1 points to. The new record number is written
** written to register P2.
**
** If P3>0 then P3 is a register in the root frame of this VDBE that holds
** the largest previously generated record number. No new record numbers are
** allowed to be less than this value. When this value reaches its maximum,
** an SQLITE_FULL error is generated. The P3 register is updated with the '
** generated record number. This P3 mechanism is used to help implement the
** AUTOINCREMENT feature.
Only the first key on the page may ==maxKey
XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY
Number of columns in the result
Both sides of the comparison are columns. If one has numeric
** affinity, use that. Otherwise use no affinity.
Number of entries in aEquiv[]
"rank" function. Populated on demand from vtab.xColumn().
************* End of the posix advisory lock implementation *****************
*****************************************************************************
A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
** MEM_Ephem, MEM_Cleared, or MEM_Subtype
Array of mmap'd *-shm regions
** For the entry that cursor pCur is point to, return as
** many bytes of the key or data as are available on the local
** b-tree page. Write the number of available bytes into *pAmt.
**
** The pointer returned is ephemeral. The key/data may move
** or be destroyed on the next call to any Btree routine,
** including calls from other threads against the same cache.
** Hence, a mutex on the BtShared should be held prior to calling
** this routine.
**
** These routines is used to get quick access to key and data
** in the common case where no overflow pages are used.
Query result set. Req'd for DISTINCT
(314) plus_num ::= INTEGER|FLOAT
** zSql is a zero-terminated string of UTF-8 SQL text. Return the number of
** bytes in this text up to but excluding the first character in
** a host parameter. If the text contains no host parameters, return
** the total number of bytes in the text.
The specific table containing the indexed database
If not NULL, bind only if true
** Create a tokenizer cursor to tokenize an input buffer. The caller
** is responsible for ensuring that the input buffer remains valid
** until the cursor is closed (using the xClose() method).
Estimated cost of using this index
** Masks used for mem5.aCtrl[] elements.
The cursor on the LHS of the term
** Locate the table identified by *p.
**
** This is a wrapper around sqlite3LocateTable(). The difference between
** sqlite3LocateTable() and this function is that this function restricts
** the search to schema (p->pSchema) if it is not NULL. p->pSchema may be
** non-NULL if it is part of a view or trigger program definition. See
** sqlite3FixSrcList() for details.
Zero tells OP_Found to use a composite key
If either the iTab or iSortIdx values for two WhereLoop are different
** then those WhereLoops need to be considered separately. Neither is
** a candidate to replace the other.
Size of header before each frame in wal
!defined(SQLITE_VDBEINT_H)
Database to be rekeyed
Evaluate subqueries as coroutines
Extra bytes at the end
At this point the transaction is committed but the write lock
** is still held on the file. If there is a size limit configured for
** the persistent journal and the journal file currently consumes more
** space than that limit allows for, truncate it now. There is no need
** to sync the file following this operation.
expr ::= CASE case_operand case_exprlist case_else END
Value for "level" field (absolute level)
Mask of usable tables
True to allow FTS4-only syntax
Generate code to handle the case of A>B
Output buffer
Absolute index of input segments
*************************************************************************
** Interface to code in fts5_vocab.c.
** Make sure the BtCursor* given in the argument has a valid
** BtCursor.info structure. If it is not already valid, call
** btreeParseCell() to fill it in.
**
** BtCursor.info is a cache of the information in the current cell.
** Using this cache reduces the number of calls to btreeParseCell().
************* End of table.c **********************************************
comment: ****************************************************************************
** The cases of the switch statement above this line should all be indented
** by 6 spaces. But the left-most 6 spaces have been removed to improve the
** readability. From this point on down, the normal indentation rules are
** restored.
****************************************************************************
label: code-design
** Generate the text of a WHERE expression which can be used to select all
** temporary triggers on table pTab from the sqlite_temp_master table. If
** table pTab has no temporary triggers, or is itself stored in the
** temporary database, NULL is returned.
EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
** integer at offset 20 is the number of bytes of space at the end of
** each page to reserve for extensions.
**
** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
** determined by the one-byte unsigned integer found at an offset of 20
** into the database file header.
************* End of fts5.c ***********************************************
The original expression
Range of content
Set pStmt to the compiled version of:
**
** SELECT max(level) FROM %Q.'%q_segdir' WHERE level BETWEEN ? AND ?
**
** (1024 is actually the value of macro FTS3_SEGDIR_PREFIXLEVEL_STR).
Blocks allocated for leaf nodes
Bytes of zTitle to save. Includes '\0' and padding
** CAPI3REF: Database Connection Status
** METHOD: sqlite3
**
** ^This interface is used to retrieve runtime status information
** about a single [database connection]. ^The first argument is the
** database connection object to be interrogated. ^The second argument
** is an integer constant, taken from the set of
** [SQLITE_DBSTATUS options], that
** determines the parameter to interrogate. The set of
** [SQLITE_DBSTATUS options] is likely
** to grow in future releases of SQLite.
**
** ^The current value of the requested parameter is written into *pCur
** and the highest instantaneous value is written into *pHiwtr. ^If
** the resetFlg is true, then the highest instantaneous value is
** reset back down to the current value.
**
** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
** non-zero [error code] on failure.
**
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
The phrase the token belongs to
Term/rowid iterator object
Do FK constraint checks.
Number of times table has been busy
CAST
**
ERROR: unterminated delta
aSpace1
Snippet ellipsis text - "<b>...</b>"
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
** * custom tokenizers, and
** * custom auxiliary functions.
Page number to clear
table_options ::=
xFileControl
Current db structure (or NULL)
The posix advisory locking structure
Score of this snippet
comment: Compilers may complain that mem1.u.i is potentially uninitialized.
** We could initialize it, as shown here, to silence those complaints.
** But in fact, mem1.u.i will never actually be used uninitialized, and doing
** the unnecessary initialization has a measurable negative performance
** impact, since this routine is a very high runner. And so, we choose
** to ignore the compiler warnings and leave this variable uninitialized.
label: code-design
Segment "age".
Array of nArg CREATE VIRTUAL TABLE args
** Close a handle opened by an earlier call to sqlite3Fts5StorageOpen().
Set and get the suggested cache-size for the specified pager-cache.
**
** If no global maximum is configured, then the system attempts to limit
** the total number of pages cached by purgeable pager-caches to the sum
** of the suggested cache-sizes.
Trailing values to read from sorter
** Attempt to locate an element of the hash table pH with a key
** that matches pKey,nKey. Return the data for this element if it is
** found, or NULL if there is no match.
sharedCacheEnabled
Global context (one per db handle)
Include hidden columns in output
Create a new auxiliary function
Number of memory cells for child frame
Equal to pPage->aData
If the hint read from the %_stat table is not empty, check if the
** last entry in it specifies a relative level smaller than or equal
** to the level identified by the block above (if any). If so, this
** iteration of the loop will work on merging at the hinted level.
The aColumn[] value for the sPk index
183
OUT: Inverse of input
Arguments to the unlock callback
Black magic: If the SQLITE_WriteSchema flag is set, then consider
** the schema loaded, even if errors occurred. In this situation the
** current sqlite3_prepare() operation will fail, but the following one
** will attempt to compile the supplied statement against whatever subset
** of the schema was loaded before the error occurred. The primary
** purpose of this is to allow access to the sqlite_master table
** even when its contents have been corrupted.
Statement journals spill to disk when their size exceeds the following
** threshold (in bytes). 0 means that statement journals are created and
** written to disk immediately (the default behavior for SQLite versions
** before 3.12.0). -1 means always keep the entire statement journal in
** memory. (The statement journal is also always held entirely in memory
** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this
** setting.)
The node from which to extract the ID
If the record number will change, set register regNewRowid to
** contain the new value. If the record number is not being modified,
** then regNewRowid is the same register as regOldRowid, which is
** already populated.
** The following two macros - READ_UTF8 and WRITE_UTF8 - have been copied
** from the sqlite3 source file utf.c. If this file is compiled as part
** of the amalgamation, they are not required.
Name of the pragma
** Populate the pIdx->aAvgEq[] array based on the samples currently
** stored in pIdx->aSample[].
Limit the length of the LIKE or GLOB pattern to avoid problems
** of deep recursion and N*N behavior in patternCompare().
OP_Insert: Set to update db->nChange
Ensure the table name matches database name and that the table exists
** Generate code that will extract the iColumn-th column from
** table pTab and store the column value in a register.
**
** An effort is made to store the column value in register iReg. This
** is not garanteeed for GetColumn() - the result can be stored in
** any register. But the result is guaranteed to land in register iReg
** for GetColumnToReg().
**
** There must be an open cursor to pTab in iTable when this routine
** is called. If iColumn<0 then code is generated that extracts the rowid.
(312) nmnum ::= DELETE
** Convert a sorted list of elements into a binary tree. Make the tree
** as deep as it needs to be in order to contain the entire list.
** Validate that no temporary register falls within the range of
** iFirst..iLast, inclusive. This routine is only call from within assert()
** statements.
163
** Context object passed by sqlite3Stat4ProbeSetValue() through to
** valueNew(). See comments above valueNew() for details.
comment: Extra space after the Index object
label: code-design
synopsis: Move P3 to P1.rowid if needed
Compute the content of the next row to insert into a range of
** registers beginning at regIns.
** Return an integer value for one of the parameters to the opcode pOp
** determined by character c.
';'
Total number of pages in apHash
Either the state is greater than PAGER_WRITER_CACHEMOD (a transaction
** or savepoint rollback done at the request of the caller) or this is
** a hot-journal rollback. If it is a hot-journal rollback, the pager
** is in state OPEN and holds an EXCLUSIVE lock. Hot-journal rollback
** only reads from the main journal, not the sub-journal.
** Print into memory obtained from sqlite3_malloc(). Omit the internal
** %-conversion extensions.
Not a subquery
** Constraint: If you have ENABLE_COLUMN_METADATA then you must
** not define OMIT_DECLTYPE.
A SELECT statement used in place of a table name
** Generate an instruction that will put the integer describe by
** text z[0..n-1] into register iMem.
**
** Expr.u.zToken is always UTF8 and zero-terminated.
EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
** strings byte by byte using the memcmp() function from the standard C
** library.
If the EP_TokenOnly flag is set in the Expr.flags mask, then no
** space is allocated for the fields below this point. An attempt to
** access them will result in a segfault or malfunction.
********************************************************************
** Public interfaces:
**
** sqlite3ConnectionBlocked()
** sqlite3ConnectionUnlocked()
** sqlite3ConnectionClosed()
** sqlite3_unlock_notify()
** This routine checks if there is a RESERVED lock held on the specified
** file by this or any other process. If such a lock is held, set *pResOut
** to a non-zero value otherwise *pResOut is set to zero. The return value
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
Write the result table here
Calculate the hash-key for this change. If the primary key of the row
** includes a NULL value, exit early. Such changes are ignored by the
** session module.
420
Mask of rev-order loops for (..)
conchHeld < 0 is lockless
** The following macros mimic the standard library functions toupper(),
** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
** sqlite versions only work for ASCII characters, regardless of locale.
************* Begin file fts3_hash.h **************************************
True for descending rowid order
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code for implementations of the r-tree and r*-tree
** algorithms packaged as an SQLite virtual table module.
A new savepoint cannot be created if there are active write
** statements (i.e. open read/write incremental blob handles).
The following function deletes the "minor type" or semantic value
** associated with a symbol. The symbol can be either a terminal
** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is
** a pointer to the value to be deleted. The code used to do the
** deletions is derived from the %destructor and/or %token_destructor
** directives of the input grammar.
** We have so far matched pBuilder->pNew->u.btree.nEq terms of the
** index pIndex. Try to match one more.
**
** When this function is called, pBuilder->pNew->nOut contains the
** number of rows expected to be visited by filtering using the nEq
** terms only. If it is modified, this value is restored before this
** function returns.
**
** If pProbe->tnum==0, that means pIndex is a fake index used for the
** INTEGER PRIMARY KEY.
Correct answer
OUT: Write encoded frame here
Some basic sanity checking on the Btree. The list of Btrees
** connected by pNext and pPrev should be in sorted order by
** Btree.pBt value. All elements of the list should belong to
** the same connection. Only shared Btrees are on the list.
The call assures that only valid opcodes are sent
Different expressions in the index
Argument to xUnlockNotify
Maximum relative level value in db
Step 4
Size of term zTerm in bytes
True if aRight[] contains PK fields only
comment:
** Include the header file used to customize the compiler options for MSVC.
** This should be done first so that it can successfully prevent spurious
** compiler warnings due to subsequent content in this file and other files
** that are included by this file.
label: code-design
** Rollback all database files. If tripCode is not SQLITE_OK, then
** any write cursors are invalidated ("tripped" - as in "tripping a circuit
** breaker") and made to return tripCode if there are any further
** attempts to use that cursor. Read cursors remain open and valid
** but are "saved" in case the table pages are moved around.
OUT: 0 for MATCH, or else an op2 value
Size of the zAuthPW in bytes
** Configure the language id of a tokenizer cursor.
OUT: Next free index at iAbsLevel+1
Actually do the update of the change counter
segdir.root
Pointer to allocated object to return
** This function is used to serialize the contents of value pValue (see
** comment titled "RECORD FORMAT" above).
**
** If it is non-NULL, the serialized form of the value is written to
** buffer aBuf. *pnWrite is set to the number of bytes written before
** returning. Or, if aBuf is NULL, the only thing this function does is
** set *pnWrite.
**
** If no error occurs, SQLITE_OK is returned. Or, if an OOM error occurs
** within a call to sqlite3_value_text() (may fail if the db is utf-16))
** SQLITE_NOMEM is returned.
First in list of all aux. functions
IMP: R-57884-37496
Parser context.
Automatic index names generated from within sqlite3_declare_vtab()
** must have names that are distinct from normal automatic index names.
** The following statement converts "sqlite3_autoindex..." into
** "sqlite3_butoindex..." in order to make the names distinct.
** The "vtab_err.test" test demonstrates the need of this statement.
Bytes to allocate segment root node
comment: The opcode being coded
label: code-design
Tail of unprocessed SQL
First page of the database
Number of extra registers needed
** This constant controls how often segments are merged. Once there are
** FTS3_MERGE_COUNT segments of level N, they are merged into a single
** segment of level N+1.
Variables populated based on current entry.
The result set of the SELECT
** Return the number of wildcards that can be potentially bound to.
** This routine is added to support DBD::SQLite.
Parse context for sub-vdbe
Initialize the output fields of the sqlite3_index_info structure
Register Allocations
Defer deleting the Table object associated with the
** subquery until code generation is
** complete, since there may still exist Expr.pTab entries that
** refer to the subquery even after flattening. Ticket #3346.
**
** pSubitem->pTab is always non-NULL by test restrictions and tests above.
Aux. function implementation
OUT: The affected (or effected) rowid
Generate code into this virtual machine
RELEASE => ID
Invoke the xFilter method
The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
** and prevents OP_Ne from overwriting NULL with 0. This flag
** is only used in contexts where either:
** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
** (2) op==OP_Ne && (r[P2]==NULL || r[P2]==1)
** Therefore it is not necessary to check the content of r[P2] for
** NULL.
temp ::= TEMP
A hash on key
Allocated size of aRowidOffset[] array
** Return the page number for page pPg.
Drop pages with this pgno or larger
SQL function arguments to VXPrintf
Number of tokens to shift snippet by
Check that the %_docsize and %_content tables contain the expected
** number of rows.
If iNext is FTS3_MERGE_COUNT, indicating that level iLevel is already
** full, merge all segments in level iLevel into a single iLevel+1
** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
** if iNext is less than FTS3_MERGE_COUNT, allocate index iNext.
Special processing for WITHOUT ROWID Tables
** Increment the reference count for page pPg.
** This function is an fts3ExprIterate() callback used by fts3BestSnippet().
** Each invocation populates an element of the SnippetIter.aPhrase[] array.
Index into input list
270
720
OUT: Value from conflicting row
Area memory mapped
unlikely() or likelihood() function
218
1: trimleft 2: trimright 3: trim
** Return TRUE if the given julian day number is within range.
**
** The input is the JulianDay times 86400000.
First token to include
Allocated size of aVTrans
Check for one of the special errors
Apply context
OUT: Buffer containing output changeset
Next frame address
(6)
The pager object
** Return a pointer to a buffer owned by the sorter that contains the
** current key.
fourth parameter
** This routine adds datatype and collating sequence information to
** the Table structures of all FROM-clause subqueries in a
** SELECT statement.
**
** Use this routine after name resolution.
**** This file contains automatically generated code ******
**
** The code in this file has been automatically generated by
**
** sqlite/tool/mkkeywordhash.c
**
** The code in this file implements a function that determines whether
** or not a given identifier is really an SQL keyword. The same thing
** might be implemented more directly using a hand-written hash table.
** But by using this automatically generated code, the size of the code
** is substantially reduced. This is important for embedded applications
** on platforms with limited memory.
Values allocated/calculated once only
Database currently in use
synopsis: affinity(r[P1@P2])
A list of columns to be indexed
Coalesced Instance Iterator
List of frames to log
-DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
** mode. Doing nothing at all also makes NORMAL the default.
Vararg list
Thread ID
OPFLAG_FORDELETE or zero, as appropriate
Object used to lock page 1
A BTREE_SINGLE database is always a temporary and/or ephemeral
EVIDENCE-OF: R-38720-18127 The default setting is determined by the
** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
** that compile-time option is omitted.
** Determine if an index pIdx on table with cursor iCur contains will
** the expression pExpr. Return true if the index does cover the
** expression and false if the pExpr expression references table columns
** that are not found in the index pIdx.
**
** An index covering an expression means that the expression can be
** evaluated using only the index and without having to lookup the
** corresponding table entry.
Node data
This case occurs after failing to recompile an sql statement.
** The error message from the SQL compiler has already been loaded
** into the database handle. This block copies the error message
** from the database handle into the statement and sets the statement
** program counter to 0 to ensure that when the statement is
** finalized or reset the parser error message is available via
** sqlite3_errmsg() and sqlite3_errcode().
Last entry on the pEntry list
Begin generating code.
************* Begin file pcache1.c ****************************************
** This function is called from within the xFilter method. It initializes
** the full-text query currently stored in pCsr->pExpr. To iterate through
** the results of a query, the caller does:
**
** fts3EvalStart(pCsr);
** while( 1 ){
** fts3EvalNext(pCsr);
** if( pCsr->bEof ) break;
** ... return row pCsr->iPrevId to the caller ...
** }
Schema object being upated
One or more of the following flags are set to indicate the validOK
** representations of the value stored in the Mem struct.
**
** If the MEM_Null flag is set, then the value is an SQL NULL value.
** For a pointer type created using sqlite3_bind_pointer() or
** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
**
** If the MEM_Str flag is set then Mem.z points at a string representation.
** Usually this is encoded in the same unicode encoding as the main
** database (see below for exceptions). If the MEM_Term flag is also
** set, then the string is nul terminated. The MEM_Int and MEM_Real
** flags may coexist with the MEM_Str flag.
** Write the current contents of in-memory linked-list pList to a level-0
** PMA in the temp file belonging to sub-task pTask. Return SQLITE_OK if
** successful, or an SQLite error code otherwise.
**
** The format of a PMA is:
**
** * A varint. This varint contains the total number of bytes of content
** in the PMA (not including the varint itself).
**
** * One or more records packed end-to-end in order of ascending keys.
** Each record consists of a varint followed by a blob of data (the
** key). The varint is the number of bytes in the blob of data.
void*, int nByte, int min
At this point, nFree contains the sum of the offset to the start
** of the cell-content area plus the number of free bytes within
** the cell-content area. If this is greater than the usable-size
** of the page, then the page must be corrupted. This check also
** serves to verify that the offset to the start of the cell-content
** area, according to the page header, lies within the page.
Address of a cell
serial type
Db containing fts5 table
** Return the VFS structure for the pager.
True if pointing to a row with no data
comment: malloc.c filters out 0 byte requests
label: code-design
** Implementation of the sqlite3_pcache.xShutdown method.
** Note that the static mutex allocated in xInit does
** not need to be freed.
Tree contains a TK_COLLATE operator
Close any rollback journal previously open
True for unindexed columns
Change the OP_OpenEphemeral coded earlier to an OP_Null
** sets the MEM_Cleared bit on the first register of the
** previous value. This will cause the OP_Ne below to always
** fail on the first iteration of the loop even if the first
** row is all NULLs.
** A main database named zName has just been opened. The following
** function returns a pointer to a buffer owned by SQLite that contains
** the name of the *-wal file this db connection will use. SQLite
** happens to pass a pointer to this buffer when using xAccess()
** or xOpen() to operate on the *-wal file.
Initialize and shutdown the page cache subsystem
Reverse unordered SELECTs
Length in bytes of master journal name
Expr.pLeft, .pRight, .u.pSelect all NULL
** Update the accumulator memory cells for an aggregate based on
** the current cursor position.
If not NULL, increment this in DbFree()
Jump here to continue with the next loop cycle
Index of database containing table/index
GROUP BY clause
Decrement the count of locks against this same file. When the
** count reaches zero, close any other file descriptors whose close
** was deferred because of outstanding locks.
3
** Declare to the Vdbe that the BTree object at db->aDb[i] is used.
**
** The prepared statements need to know in advance the complete set of
** attached databases that will be use. A mask of these databases
** is maintained in p->btreeMask. The p->lockMask value is the subset of
** p->btreeMask of databases that will require a lock.
** Add a record to the sorter.
A general purpose loop counter
comment: Opcode: JournalMode P1 P2 P3 * *
**
** Change the journal mode of database P1 to P3. P3 must be one of the
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
** modes (delete, truncate, persist, off and memory), this is a simple
** operation. No IO is required.
**
** If changing into or out of WAL mode the procedure is more complicated.
**
** Write a string containing the final journal-mode to register P2.
label: code-design
** The checkProfileCallback(DB,P) macro checks to see if a profile callback
** is needed, and it invokes the callback if it is needed.
Largest defined DBSTATUS
True for a prefix search
Instruction to open the Ephemeral table
we didn't find it in the hash. h points to the first
Set iSz to the expected size of file pTask->file after writing the PMA.
** This is used by an assert() statement at the end of this function.
** Set the SQLITE_INDEX_SCAN_UNIQUE flag in pIdxInfo->flags. Unless this
** extension is currently being used by a version of SQLite too old to
** support index-info flags. In that case this function is a no-op.
** Return true if the two-argument version of fts3_tokenizer()
** has been activated via a prior call to sqlite3_db_config(db,
** SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, 1, 0);
The new offset
comment:
** For WinCE, some API function parameters do not appear to be declared as
** volatile.
label: code-design
Amount of space allocated in zText
SQLite connection to register module with
Current bytes of pending data
** Remove all terms smaller than zTerm/nTerm from segment iIdx in absolute
** level iAbsLevel. This may involve deleting entries from the %_segments
** table, and modifying existing entries in both the %_segments and %_segdir
** tables.
**
** SQLITE_OK is returned if the segment is updated successfully. Or an
** SQLite error code otherwise.
** Routines to read or write a two- and four-byte big-endian integer values.
#include "fts3_tokenizer.h"
** Empty (but do not delete) a hash table.
** Add type and collation information to a column list based on
** a SELECT statement.
**
** The column list presumably came from selectColumnNamesFromExprList().
** The column list has only names, not types or collations. This
** routine goes through and adds the types and collations.
**
** This routine requires that all identifiers in the SELECT
** statement be resolved.
** Attempt to parse the given string into a julian day number. Return
** the number of errors.
**
** The following are acceptable forms for the input string:
**
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
** DDDD.DD
** now
**
** In the first form, the +/-HH:MM is always optional. The fractional
** seconds extension (the ".FFF") is optional. The seconds portion
** (":SS.FFF") is option. The year and date can be omitted as long
** as there is a time string. The time string can be omitted as long
** as there is a year and date.
File path associated with error
This array determines which meta meta values are preserved in the
** vacuum. Even entries are the meta value number and odd entries
** are an increment to apply to the meta value after the vacuum.
** The increment is used to increase the schema cookie so that other
** connections to the same database will know to reread the schema.
** 2013 Apr 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code for the "fts3tokenize" virtual table module.
** An fts3tokenize virtual table is created as follows:
**
** CREATE VIRTUAL TABLE <tbl> USING fts3tokenize(
** <tokenizer-name>, <arg-1>, ...
** );
**
** The table created has the following schema:
**
** CREATE TABLE <tbl>(input, token, start, end, position)
**
** When queried, the query must include a WHERE clause of type:
**
** input = <string>
**
** The virtual table module tokenizes this <string>, using the FTS3
** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
** statement and returns one row for each token in the result. With
** fields set as follows:
**
** input: Always set to a copy of <string>
** token: A token from the input.
** start: Byte offset of the token within the input <string>.
** end: Byte offset of the byte immediately following the end of the
** token within the input string.
** pos: Token offset of token within input.
**
Read and decode the next log frame.
Pointer to 1 byte past end of doclist
Memory cell containing record
** This function is a no-op if *pRc is other than SQLITE_OK when it is called.
** Otherwise, it advances the expression passed as the second argument to
** point to the next matching row in the database. Expressions iterate through
** matching rows in docid order. Ascending order if Fts3Cursor.bDesc is zero,
** or descending if it is non-zero.
**
** If an error occurs, *pRc is set to an SQLite error code. Otherwise, if
** successful, the following variables in pExpr are set:
**
** Fts3Expr.bEof (non-zero if EOF - there is no next row)
** Fts3Expr.iDocid (valid if bEof==0. The docid of the next row)
**
** If the expression is of type FTSQUERY_PHRASE, and the expression is not
** at EOF, then the following variables are populated with the position list
** for the phrase for the visited row:
**
** FTs3Expr.pPhrase->doclist.nList (length of pList in bytes)
** FTs3Expr.pPhrase->doclist.pList (pointer to position list)
**
** It says above that this function advances the expression to the next
** matching row. This is usually true, but there are the following exceptions:
**
** 1. Deferred tokens are not taken into account. If a phrase consists
** entirely of deferred tokens, it is assumed to match every row in
** the db. In this case the position-list is not populated at all.
**
** Or, if a phrase contains one or more deferred tokens and one or
** more non-deferred tokens, then the expression is advanced to the
** next possible match, considering only non-deferred tokens. In other
** words, if the phrase is "A B C", and "B" is deferred, the expression
** is advanced to the next row that contains an instance of "A * C",
** where "*" may match any single token. The position list in this case
** is populated as for "A * C" before returning.
**
** 2. NEAR is treated as AND. If the expression is "x NEAR y", it is
** advanced to point to the next row that matches "x AND y".
**
** See sqlite3Fts3EvalTestDeferred() for details on testing if a row is
** really a match, taking into account deferred tokens and NEAR operators.
Only save cursor with this iRoot. Save all if zero
Offset of record to playback
Number of tables or subqueries in the FROM clause
Step 7: If we reach this point, we know that the result must
** be false.
1340
Bytes of space for Index object + arrays
Op for vtab MATCH/LIKE/GLOB/REGEXP terms
** The following macros redefine the API routines so that they are
** redirected through the global sqlite3_api structure.
**
** This header file is also used by the loadext.c source file
** (part of the main SQLite library - not an extension) so that
** it can get access to the sqlite3_api_routines structure
** definition. But the main library does not want to redefine
** the API. So the redefinition macros are only valid if the
** SQLITE_CORE macros is undefined.
** Write the buffer for the segment node pTree and all of its peers to the
** database. Then call this function recursively to write the parent of
** pTree and its peers to the database.
**
** Except, if pTree is a root node, do not write it to the database. Instead,
** set output variables *paRoot and *pnRoot to contain the root node.
**
** If successful, SQLITE_OK is returned and output variable *piLast is
** set to the largest blockid written to the database (or zero if no
** blocks were written to the db). Otherwise, an SQLite error code is
** returned.
* The initial size of the Win32-specific heap. This value may be zero.
** Estimate the logarithm of the input value to base 2.
Return code from sqlite3_exec()
The parser
OUT: Pointer to mapping
** Resize an Index object to hold N columns total. Return SQLITE_OK
** on success and SQLITE_NOMEM on an OOM error.
This was the root node. Push its first rowid up to the new root.
ISNULL
Parsed MATCH query string
occurrences
comment: Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
** number as the prior appearance of the same name, or if the name
** has never appeared before, reuse the same variable number
label: code-design
comment: Hash table of all pages. The following variables may only be accessed
** when the accessor is holding the PGroup mutex.
label: code-design
Syntax error
** This is a utility for setting or clearing a bit-range lock on an
** AFP filesystem.
**
** Return SQLITE_OK on success, SQLITE_BUSY on failure.
Used to iterate through table columns
Raw text of the SQL statement
Offset into aKey[] of next data element
Accumulated output
The VDBE cursor used to access pIdx
** The assert_nc() macro is similar to the assert() macro, except that it
** is used for assert() conditions that are true only if it can be
** guranteed that the database is not corrupt.
** Flush any dirty pages in the pager-cache for any attached database
** to disk.
** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
Save the positions of any open cursors. This is required in
** case they are holding a reference to an xFetch reference
** corresponding to page pgnoRoot.
Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
** If malloc failed, then the while() loop above may not have iterated
** through all opcodes and hasAbort may be set incorrectly. Return
** true for this case to prevent the assert() in the callers frame
** from failing.
Current leaf page number
Type values record decode. MUST BE LAST
0 -> MATCHINFO
************* Begin file fts3.h *******************************************
** Allowed values of VdbeOp.p4type
All backends
Scan past any delimiter characters before the start of the next token.
** Return SQLITE_DONE early if this takes us all the way to the end of
** the input.
A WhereTerm under consideration
** CAPI3REF: Text Encodings
**
** These constant define integer codes that represent the various
** text encodings supported by SQLite.
** Write the serialized data blob for the value stored in pMem into
** buf. It is assumed that the caller has allocated sufficient space.
** Return the number of bytes written.
**
** nBuf is the amount of space left in buf[]. The caller is responsible
** for allocating enough space to buf[] to hold the entire field, exclusive
** of the pMem->u.nZero bytes for a MEM_Zero value.
**
** Return the number of bytes actually written into buf[]. The number
** of bytes in the zero-filled tail is included in the return value only
** if those bytes were zeroed in buf[].
synopsis: output=r[P1@P2]
For looping over PmaReader objects
1 to write. 0 read-only
comment: If there are still other outstanding references to the shared-btree
** structure, return now. The remainder of this procedure cleans
** up the shared-btree.
label: code-design
************* Continuing where we left off in tokenize.c ******************
Expression (pLeft = pRight)
Because of the FTS3_NODE_PADDING bytes of padding, the following is
** safe (no risk of overread) even if the node data is corrupted.
SQLITE_OMIT_VACUUM
If possible, improve on the iLower estimate using ($P:$L).
Variables set by fts3SegReaderNext(). These may be read directly
** by the caller. They are valid from the time SegmentReaderNew() returns
** until SegmentReaderNext() returns something other than SQLITE_OK
** (i.e. SQLITE_DONE).
EQP output string
** Seek to the offset passed as the second argument, then read cnt
** bytes into pBuf. Return the number of bytes actually read.
**
** NB: If you define USE_PREAD or USE_PREAD64, then it might also
** be necessary to define _XOPEN_SOURCE to be 500. This varies from
** one system to another. Since SQLite does not define USE_PREAD
** in any form by default, we will not attempt to define _XOPEN_SOURCE.
** See tickets #2741 and #2681.
**
** To avoid stomping the errno value on a failed read the lastErrno value
** is set before returning.
** Implementation of the sqlite3_pcache.xTruncate method.
**
** Discard all unpinned pages in the cache with a page number equal to
** or greater than parameter iLimit. Any pinned pages with a page number
** equal to or greater than iLimit are implicitly unpinned.
1 for DESC or 0 for ASC
************* Begin file analyze.c ****************************************
Allocate the Bitvec to be tested and a linear array of
** bits to act as the reference
comment:
** Return the device characteristics for the file.
**
** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
** However, that choice is controversial since technically the underlying
** file system does not always provide powersafe overwrites. (In other
** words, after a power-loss event, parts of the file that were never
** written might end up being altered.) However, non-PSOW behavior is very,
** very rare. And asserting PSOW makes a large reduction in the amount
** of required I/O for journaling, since a lot of padding is eliminated.
** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
** available to turn it off and URI query parameter available to turn it off.
label: code-design
populated by sqlite3_create_module()
Number of bytes in the key
************* End of vdbeaux.c ********************************************
Bind the current output segment id to the index-writer. This is an
** optimization over binding the same value over and over as rows are
** inserted into %_idx by the current writer.
Index of languageid=? value in apVal
0xffffffff is never a valid page number
Number of coordinates
Has no WHERE clause
comment:
** This function is called to handle an FTS INSERT command. In other words,
** an INSERT statement of the form:
**
** INSERT INTO fts(fts) VALUES($pCmd)
** INSERT INTO fts(fts, rank) VALUES($pCmd, $pVal)
**
** Argument pVal is the value assigned to column "fts" by the INSERT
** statement. This function returns SQLITE_OK if successful, or an SQLite
** error code if an error occurs.
**
** The commands implemented by this function are documented in the "Special
** INSERT Directives" section of the documentation. It should be updated if
** more commands are added to this function.
label: documentation
Check for condition (a)
exprlist ::=
"DELETE FROM %_data ... id>=? AND id<=?"
** This is the maximum number of
**
** * Columns in a table
** * Columns in an index
** * Columns in a view
** * Terms in the SET clause of an UPDATE statement
** * Terms in the result set of a SELECT statement
** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
** * Terms in the VALUES clause of an INSERT statement
**
** The hard upper limit here is 32676. Most database people will
** tell you that in a well-normalized database, you usually should
** not have more than a dozen or so columns in any table. And if
** that is the case, there is no point in having more than a few
** dozen values in any of the other situations described above.
SQLITE_ENABLE_STAT3_OR_STAT4
Frame number associated with aPgno[0]
** Check to see if element iRowid was inserted into the rowset as
** part of any insert batch prior to iBatch. Return 1 or 0.
**
** If this is the first test of a new batch and if there exist entries
** on pRowSet->pEntry, then sort those entries into the forest at
** pRowSet->pForest so that they can be tested.
The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
** pointer and, if the file is a main database file, link it into the
** mutex protected linked list of all such files.
comment: Pointer to block from malloc()
label: code-design
ORDER BY terms to skip
SQLITE_MAX_EXPR_DEPTH>0
MergeEngine to initialize
** CAPI3REF: SQL Trace Hook
** METHOD: sqlite3
**
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
** function X against [database connection] D, using property mask M
** and context pointer P. ^If the X callback is
** NULL or if the M mask is zero, then tracing is disabled. The
** M argument should be the bitwise OR-ed combination of
** zero or more [SQLITE_TRACE] constants.
**
** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
**
** ^The X callback is invoked whenever any of the events identified by
** mask M occur. ^The integer return value from the callback is currently
** ignored, though this may change in future releases. Callback
** implementations should return zero to ensure future compatibility.
**
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
** ^The T argument is one of the [SQLITE_TRACE]
** constants to indicate why the callback was invoked.
** ^The C argument is a copy of the context pointer.
** The P and X arguments are pointers whose meanings depend on T.
**
** The sqlite3_trace_v2() interface is intended to replace the legacy
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
** are deprecated.
comment:
** Release a unixInodeInfo structure previously allocated by findInodeInfo().
**
** The mutex entered using the unixEnterMutex() function must be held
** when this function is called.
label: code-design
** Ensure that there are at least nByte bytes available in the buffer. Or,
** if there are not nByte bytes remaining in the input, that all available
** data is in the buffer.
**
** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
** Function to delete compiled regexp objects. Registered as
** a destructor function with sqlite3_set_auxdata().
Functions used to manage pager transactions and savepoints.
This routine is only be called from within a read transaction.
State 1. In this state we are expecting either a 1, indicating
** that the following integer will be a column number, or the
** start of a position list for column 0.
**
** The only difference between state 1 and state 2 is that if the
** integer encountered in state 1 is not 0 or 1, then we need to
** increment the column 0 "nDoc" count for this term.
Frame to read
OUT: New session object
100
** CAPI3REF: Create An Iterator To Traverse A Changeset
**
** Create an iterator used to iterate through the contents of a changeset.
** If successful, *pp is set to point to the iterator handle and SQLITE_OK
** is returned. Otherwise, if an error occurs, *pp is set to zero and an
** SQLite error code is returned.
**
** The following functions can be used to advance and query a changeset
** iterator created by this function:
**
** <ul>
** <li> [sqlite3changeset_next()]
** <li> [sqlite3changeset_op()]
** <li> [sqlite3changeset_new()]
** <li> [sqlite3changeset_old()]
** </ul>
**
** It is the responsibility of the caller to eventually destroy the iterator
** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
** changeset (pChangeset) must remain valid until after the iterator is
** destroyed.
**
** Assuming the changeset blob was created by one of the
** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
** [sqlite3changeset_invert()] functions, all changes within the changeset
** that apply to a single table are grouped together. This means that when
** an application iterates through a changeset using an iterator created by
** this function, all changes that relate to a single table are visited
** consecutively. There is no chance that the iterator will visit a change
** the applies to table X, then one for table Y, and then later on visit
** another change for table X.
The UNLIKELY() function is a no-op. The result is the value
** of the first argument.
Used by codeCursorHint()
OUT: Size of current key in bytes
** When testing, keep a count of the number of open files.
** 2005 May 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
rank MATCH ?
************************************************************************
** This section contains code for WinCE only.
Jump destination or storage location
case_exprlist ::= WHEN expr THEN expr
Do extra initialization steps requested by the SQLITE_EXTRA_INIT
** compile-time option.
One entry for each token in the phrase
The following are only used if the FTS5_SEGITER_REVERSE flag is set.
comment: Create the rbu_tmp_xxx table and the triggers to populate it.
label: code-design
Previous thread used to flush PMA
Value to write the string rep. of
List of function arguments
SQLITE_INSERT, UPDATE or DELETE
Name context for processing aggregate information
Add dlidx if this many empty pages
Used to iterate through schemas
This happens when parsing a token or quoted phrase that contains
** no token characters at all. (e.g ... MATCH '""').
Note: this call could be optimized away - since the same values must
** have been requested when testing key $P in whereEqualScanEst().
Same position as prev. token
Full-text table handle
This just creates a place-holder record in the sqlite_master table.
** The record created does not contain anything yet. It will be replaced
** by the real entry in code generated at sqlite3EndTable().
**
** The rowid for the new entry is left in register pParse->regRowid.
** The root page number of the new table is left in reg pParse->regRoot.
** The rowid and root page number values are needed by the code that
** sqlite3EndTable will generate.
Add condition to terminate at NULLs
306
** Streaming version of sqlite3session_patchset().
** Implementation of the stat_get(P,J) SQL function. This routine is
** used to query statistical information that has been gathered into
** the Stat4Accum object by prior calls to stat_push(). The P parameter
** has type BLOB but it is really just a pointer to the Stat4Accum object.
** The content to returned is determined by the parameter J
** which is one of the STAT_GET_xxxx values defined above.
**
** The stat_get(P,J) function is not available to generic SQL. It is
** inserted as part of a manually constructed bytecode program. (See
** the callStatGet() routine below.) It is guaranteed that the P
** parameter will always be a poiner to a Stat4Accum object, never a
** NULL.
**
** If neither STAT3 nor STAT4 are enabled, then J is always
** STAT_GET_STAT1 and is hence omitted and this routine becomes
** a one-parameter function, stat_get(P), that always returns the
** stat1 table entry information.
** Generate code that will tell the VDBE the declaration types of columns
** in the result set.
comment:
** Bitmasks used by sqlite3GetVarint(). These precomputed constants
** are defined here rather than simply putting the constant expressions
** inline in order to work around bugs in the RVT compiler.
**
** SLOT_2_0 A mask for (0x7f<<14) | 0x7f
**
** SLOT_4_2_0 A mask for (0x7f<<28) | SLOT_2_0
label: code-design
The node number
Grab the cookie value
If MEM_Null is set, then either the value is a pure NULL (the usual
** case) or it is a pointer set using sqlite3_bind_pointer() or
** sqlite3_result_pointer(). If a pointer, then MEM_Term must also be
** set.
comment:
** 2011-07-09
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code for the VdbeSorter object, used in concert with
** a VdbeCursor to sort large numbers of keys for CREATE INDEX statements
** or by SELECT statements with ORDER BY clauses that cannot be satisfied
** using indexes and without LIMIT clauses.
**
** The VdbeSorter object implements a multi-threaded external merge sort
** algorithm that is efficient even if the number of elements being sorted
** exceeds the available memory.
**
** Here is the (internal, non-API) interface between this module and the
** rest of the SQLite system:
**
** sqlite3VdbeSorterInit() Create a new VdbeSorter object.
**
** sqlite3VdbeSorterWrite() Add a single new row to the VdbeSorter
** object. The row is a binary blob in the
** OP_MakeRecord format that contains both
** the ORDER BY key columns and result columns
** in the case of a SELECT w/ ORDER BY, or
** the complete record for an index entry
** in the case of a CREATE INDEX.
**
** sqlite3VdbeSorterRewind() Sort all content previously added.
** Position the read cursor on the
** first sorted element.
**
** sqlite3VdbeSorterNext() Advance the read cursor to the next sorted
** element.
**
** sqlite3VdbeSorterRowkey() Return the complete binary blob for the
** row currently under the read cursor.
**
** sqlite3VdbeSorterCompare() Compare the binary blob for the row
** currently under the read cursor against
** another binary blob X and report if
** X is strictly less than the read cursor.
** Used to enforce uniqueness in a
** CREATE UNIQUE INDEX statement.
**
** sqlite3VdbeSorterClose() Close the VdbeSorter object and reclaim
** all resources.
**
** sqlite3VdbeSorterReset() Refurbish the VdbeSorter for reuse. This
** is like Close() followed by Init() only
** much faster.
**
** The interfaces above must be called in a particular order. Write() can
** only occur in between Init()/Reset() and Rewind(). Next(), Rowkey(), and
** Compare() can only occur in between Rewind() and Close()/Reset(). i.e.
**
** Init()
** for each record: Write()
** Rewind()
** Rowkey()/Compare()
** Next()
** Close()
**
** Algorithm:
**
** Records passed to the sorter via calls to Write() are initially held
** unsorted in main memory. Assuming the amount of memory used never exceeds
** a threshold, when Rewind() is called the set of records is sorted using
** an in-memory merge sort. In this case, no temporary files are required
** and subsequent calls to Rowkey(), Next() and Compare() read records
** directly from main memory.
**
** If the amount of space used to store records in main memory exceeds the
** threshold, then the set of records currently in memory are sorted and
** written to a temporary file in "Packed Memory Array" (PMA) format.
** A PMA created at this point is known as a "level-0 PMA". Higher levels
** of PMAs may be created by merging existing PMAs together - for example
** merging two or more level-0 PMAs together creates a level-1 PMA.
**
** The threshold for the amount of main memory to use before flushing
** records to a PMA is roughly the same as the limit configured for the
** page-cache of the main database. Specifically, the threshold is set to
** the value returned by "PRAGMA main.page_size" multipled by
** that returned by "PRAGMA main.cache_size", in bytes.
**
** If the sorter is running in single-threaded mode, then all PMAs generated
** are appended to a single temporary file. Or, if the sorter is running in
** multi-threaded mode then up to (N+1) temporary files may be opened, where
** N is the configured number of worker threads. In this case, instead of
** sorting the records and writing the PMA to a temporary file itself, the
** calling thread usually launches a worker thread to do so. Except, if
** there are already N worker threads running, the main thread does the work
** itself.
**
** The sorter is running in multi-threaded mode if (a) the library was built
** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
** than zero, and (b) worker threads have been enabled at runtime by calling
** "PRAGMA threads=N" with some value of N greater than 0.
**
** When Rewind() is called, any data remaining in memory is flushed to a
** final PMA. So at this point the data is stored in some number of sorted
** PMAs within temporary files on disk.
**
** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
** sorter is running in single-threaded mode, then these PMAs are merged
** incrementally as keys are retreived from the sorter by the VDBE. The
** MergeEngine object, described in further detail below, performs this
** merge.
**
** Or, if running in multi-threaded mode, then a background thread is
** launched to merge the existing PMAs. Once the background thread has
** merged T bytes of data into a single sorted PMA, the main thread
** begins reading keys from that PMA while the background thread proceeds
** with merging the next T bytes of data. And so on.
**
** Parameter T is set to half the value of the memory threshold used
** by Write() above to determine when to create a new PMA.
**
** If there are more than SORTER_MAX_MERGE_COUNT PMAs in total when
** Rewind() is called, then a hierarchy of incremental-merges is used.
** First, T bytes of data from the first SORTER_MAX_MERGE_COUNT PMAs on
** disk are merged together. Then T bytes of data from the second set, and
** so on, such that no operation ever merges more than SORTER_MAX_MERGE_COUNT
** PMAs at a time. This done is to improve locality.
**
** If running in multi-threaded mode and there are more than
** SORTER_MAX_MERGE_COUNT PMAs on disk when Rewind() is called, then more
** than one background thread may be created. Specifically, there may be
** one background thread for each temporary file on disk, and one background
** thread to merge the output of each of the others to a single PMA for
** the main thread to read from.
label: code-design
Length of BTM vector
RELEASE
** The following version of unixSectorSize() is optimized for QNX.
Opcode: Savepoint P1 * * P4 *
**
** Open, release or rollback the savepoint named by parameter P4, depending
** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
res might be negative because the table is empty. Check to
** see if this is the case.
A DELETE operation. Foreign key processing is required if the
** table in question is either the child or parent table for any
** foreign key constraint.
** Shorthand for the functions above
Replacement content for JNODE_REPLACE
** Close the read-only blob handle, if it is open.
** Page paths:
**
** The value of the 'path' column describes the path taken from the
** root-node of the b-tree structure to each page. The value of the
** root-node path is '/'.
**
** The value of the path for the left-most child page of the root of
** a b-tree is '/000/'. (Btrees store content ordered from left to right
** so the pages to the left have smaller keys than the pages to the right.)
** The next to left-most child of the root page is
** '/001', and so on, each sibling page identified by a 3-digit hex
** value. The children of the 451st left-most sibling have paths such
** as '/1c2/000/, '/1c2/001/' etc.
**
** Overflow pages are specified by appending a '+' character and a
** six-digit hexadecimal value to the path to the cell they are linked
** from. For example, the three overflow pages in a chain linked from
** the left-most cell of the 450th child of the root page are identified
** by the paths:
**
** '/1c2/000+000000' // First page in overflow chain
** '/1c2/000+000001' // Second page in overflow chain
** '/1c2/000+000002' // Third page in overflow chain
**
** If the paths are sorted using the BINARY collation sequence, then
** the overflow pages associated with a cell will appear earlier in the
** sort-order than its child page:
**
** '/1c2/000/' // Left-most child of 451st child of root
The index being used for this loop
'[' is a single-byte character
FROM clause not a virtual table
'['. [...] style quoted ids
Number of arguments to the function
** The hex() function. Interpret the argument as a blob. Return
** a hexadecimal rendering as text.
The table containing the blob
Default return value, in case of an error
comment: Too many digits
label: code-design
Condition 3
True if ORDER BY [rank|rowid] DESC
nullRow[] is an OP_Record encoding of a row containing 5 NULLs
The group mutex must be released before pcache1Alloc() is called. This
** is because it might call sqlite3_release_memory(), which assumes that
** this mutex is not held.
If all the seg-readers are at EOF, we're finished. return SQLITE_OK.
** Generate a human-readable description of a Select object.
CHECK constraint references the ROWID
Write the integer values
** If the input FuncDef structure is ephemeral, then free it. If
** the FuncDef is not ephermal, then do nothing.
FTSQUERY_PHRASE expression
True if pPage is a leaf of a LEAFDATA tree
Index of second table in pSrc
If page one was fetched successfully, and this function is not
** operating in direct-mode, make page 1 writable. When not in
** direct mode, page 1 is always held in cache and hence the PagerGet()
** above is always successful - hence the ALWAYS on rc==SQLITE_OK.
Token argument. Might be NULL
Value to write to hash-table slot
Implied first min-heap entry
15
Input iterator
** Perform a reduce action and the shift that must immediately
** follow the reduce.
comment:
** CAPI3REF: Record A Database Snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
** new [sqlite3_snapshot] object that records the current state of
** schema S in database connection D. ^On success, the
** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
** If there is not already a read-transaction open on schema S when
** this function is called, one is opened automatically.
**
** The following must be true for this function to succeed. If any of
** the following statements are false when sqlite3_snapshot_get() is
** called, SQLITE_ERROR is returned. The final value of *P is undefined
** in this case.
**
** <ul>
** <li> The database handle must be in [autocommit mode].
**
** <li> Schema S of [database connection] D must be a [WAL mode] database.
**
** <li> There must not be a write transaction open on schema S of database
** connection D.
**
** <li> One or more transactions must have been written to the current wal
** file since it was created on disk (by any connection). This means
** that a snapshot cannot be taken on a wal mode database with no wal
** file immediately after it is first opened. At least one transaction
** must be written to it first.
** </ul>
**
** This function may also return SQLITE_NOMEM. If it is called with the
** database handle in autocommit mode but fails for some other reason,
** whether or not a read transaction is opened on schema S is undefined.
**
** The [sqlite3_snapshot] object returned from a successful call to
** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
** to avoid a memory leak.
**
** The [sqlite3_snapshot_get()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
label: code-design
New pX->pLeft vector
If this is a scalar select that is part of an expression, then
** store the results in the appropriate memory cell and break out
** of the scan loop.
Database schema version number for this file
** Return the number of changes since the database handle was opened.
** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
** the planner assumes that the specified pOrderBy list is actually a GROUP
** BY clause - and so any order that groups rows as required satisfies the
** request.
**
** Normally, in this case it is not possible for the caller to determine
** whether or not the rows are really being delivered in sorted order, or
** just in some other order that provides the required grouping. However,
** if the WHERE_SORTBYGROUP flag is also passed to sqlite3WhereBegin(), then
** this function may be called on the returned WhereInfo object. It returns
** true if the rows really will be sorted in the specified order, or false
** otherwise.
**
** For example, assuming:
**
** CREATE INDEX i1 ON t1(x, Y);
**
** then
**
** SELECT * FROM t1 GROUP BY x,y ORDER BY x,y; -- IsSorted()==1
** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
comment: Following an incremental-merge operation, assuming that the input
** segments are not completely consumed (the usual case), they are updated
** in place to remove the entries that have already been merged. This
** involves updating the leaf block that contains the smallest unmerged
** entry and each block (if any) between the leaf and the root node. So
** if the height of the input segment b-trees is N, and input segments
** are merged eight at a time, updating the input segments at the end
** of an incremental-merge requires writing (8*(1+N)) blocks. N is usually
** small - often between 0 and 2. So the overhead of the incremental
** merge is somewhere between 8 and 24 blocks. To avoid this overhead
** dwarfing the actual productive work accomplished, the incremental merge
** is only attempted if it will write at least 64 leaf blocks. Hence
** nMinMerge.
**
** Of course, updating the input segments also involves deleting a bunch
** of blocks from the segments table. But this is not considered overhead
** as it would also be required by a crisis-merge that used the same input
** segments.
label: code-design
72
Trigger this program was coded from
Blob read from %_segments table
Values between 128 and 16383
An element of pSelect->pSrc
All CHECK constraints
Nul-terminated URI to parse
** Allocate a new Fts5Iter object.
**
** The new object will be used to iterate through data in structure pStruct.
** If iLevel is -ve, then all data in all segments is merged. Or, if iLevel
** is zero or greater, data from the first nSegment segments on level iLevel
** is merged.
**
** The iterator initially points to the first term/rowid entry in the
** iterated data.
Number of leaf pages in unit of work
** Move to the next matching rowid that occurs at or after iMatch. The
** definition of "at or after" depends on whether this iterator iterates
** in ascending or descending rowid order.
** This is called as part of an incremental checkpoint operation. Copy
** a single frame of data from the wal file into the database file, as
** indicated by the RbuFrame object.
Write the first journal header to the journal file and open
** the sub-journal if necessary.
FTS Table handle
************* End of rtree.c **********************************************
The FK maps to the IPK if any of the following are true:
**
** 1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
** mapped to the primary key of table pParent, or
** 2) The FK is explicitly mapped to a column declared as INTEGER
** PRIMARY KEY.
Object iterator for column names
same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2
Write the rowid.
No-op if we do not support a codec
Initial cost estimate
Reanalyze if the table is 25 times larger than the last analysis
Initial space for EQP output string
The cache to truncate
x IN (...)
Array of opcodes for sub-program
table of a LEFT JOIN
** Register a profile function. The pArg from the previously registered
** profile function is returned.
**
** A NULL profile function means that no profiling is executes. A non-NULL
** profile is a pointer to a function that is invoked at the conclusion of
** each SQL statement that is run.
Invoke the xNext() method of the module. There is no way for the
** underlying implementation to return an error if one occurs during
** xNext(). Instead, if an error occurs, true is returned (indicating that
** data is available) and the error code returned when xColumn or
** some other method is next invoked on the save virtual table cursor.
Allocate the sqlite3_index_info structure
Mark the page as clean.
** The Table structure pTable is really a VIEW. Fill in the names of
** the columns of the view in the pTable structure. Return the number
** of errors. If an error is seen leave an error message in pParse->zErrMsg.
State vector for the DB fixer
Search point for the leaf
** Number of malloc size increments to track.
If p==0 (unmap the entire file) then there must be no outstanding
** xFetch references. Or, if p!=0 (meaning it is an xFetch reference),
** then there must be at least one outstanding.
** Clean up any resources allocated as part of the iterator object passed
** as the only argument.
** Truncate an rbuVfs-file.
GetVersionEx() is deprecated
** If the virtual table pVtab supports the transaction interface
** (xBegin/xRollback/xCommit and optionally xSync) and a transaction is
** not currently open, invoke the xBegin method now.
**
** If the xBegin call is successful, place the sqlite3_vtab pointer
** in the sqlite3.aVTrans array.
** Each SQL index is represented in memory by an
** instance of the following structure.
**
** The columns of the table that are to be indexed are described
** by the aiColumn[] field of this structure. For example, suppose
** we have the following table and index:
**
** CREATE TABLE Ex1(c1 int, c2 int, c3 text);
** CREATE INDEX Ex2 ON Ex1(c3,c1);
**
** In the Table structure describing Ex1, nCol==3 because there are
** three columns in the table. In the Index structure describing
** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed.
** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the
** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
** The second column to be indexed (c1) has an index of 0 in
** Ex1.aCol[], hence Ex2.aiColumn[1]==0.
**
** The Index.onError field determines whether or not the indexed columns
** must be unique and what to do if they are not. When Index.onError=OE_None,
** it means this is not a unique index. Otherwise it is a unique index
** and the value of Index.onError indicate the which conflict resolution
** algorithm to employ whenever an attempt is made to insert a non-unique
** element.
**
** While parsing a CREATE TABLE or CREATE INDEX statement in order to
** generate VDBE code (as opposed to parsing one read from an sqlite_master
** table as part of parsing an existing database schema), transient instances
** of this structure may be created. In this case the Index.tnum variable is
** used to store the address of a VDBE instruction, not a database page
** number (it cannot - the database page is not allocated until the VDBE
** program is executed). See convertToWithoutRowidTable() for details.
Any unrecognized conversion type
** Add an opcode that includes the p4 value with a P4_INT64 or
** P4_REAL type.
0==closed, 1==open, 2==synced
EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
** there is a hard upper bound set at compile-time by a C preprocessor
** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
** "_MAX_".)
Name of the common-table
sqlite3WalEndReadTransaction() was not called for the previous
** transaction in locking_mode=EXCLUSIVE. So call it now. If we
** are in locking_mode=NORMAL and EndRead() was previously called,
** the duplicate call is harmless.
Silently ignore database qualifiers inside CHECK constraints and
** partial indices. Do not raise errors because that might break
** legacy and because it does not hurt anything to just ignore the
** database name.
Generate code into this VDBE
comment:
** An iterator of this type is used to iterate through all objects in
** the target database that require updating. For each such table, the
** iterator visits, in order:
**
** * the table itself,
** * each index of the table (zero or more points to visit), and
** * a special "cleanup table" state.
**
** abIndexed:
** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
** it points to an array of flags nTblCol elements in size. The flag is
** set for each column that is either a part of the PK or a part of an
** index. Or clear otherwise.
**
label: code-design
************* Begin file fts3_tokenizer.c *********************************
** *pRoot is the head of a list of free chunks of the same size
** or same size hash. In other words, *pRoot is an entry in either
** mem3.aiSmall[] or mem3.aiHash[].
**
** This routine examines all entries on the given list and tries
** to coalesce each entries with adjacent free chunks.
**
** If it sees a chunk that is larger than mem3.iMaster, it replaces
** the current mem3.iMaster with the new larger chunk. In order for
** this mem3.iMaster replacement to work, the master chunk must be
** linked into the hash tables. That is not the normal state of
** affairs, of course. The calling routine must link the master
** chunk before invoking this routine, then must unlink the (possibly
** changed) master chunk once this routine has finished.
Array of new.* values
Number of pages starting at pg1 to journal
Allocate readers for this expression
Record consists of PK fields only
Depth of node containing pCell
Table Name NULL
Start offset in pFile
When converting from UTF-8 to UTF-16 the maximum growth is caused
** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
** character. Two bytes are required in the output buffer for the
** nul-terminator.
TUNING: If there is both an upper and lower limit and neither limit
** has an application-defined likelihood(), assume the range is
** reduced by an additional 75%. This means that, by default, an open-ended
** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
** match 1/64 of the index.
Opcode: Subtract P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]-r[P1]
**
** Subtract the value in register P1 from the value in register P2
** and store the result in register P3.
** If either input is NULL, the result is NULL.
WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK
If a content=xxx option was specified, the following:
**
** 1. Ignore any compress= and uncompress= options.
**
** 2. If no column names were specified as part of the CREATE VIRTUAL
** TABLE statement, use all columns from the content table.
comment: This function is used by SQL generated to implement the
** ALTER TABLE command. The first argument is the text of a CREATE TRIGGER
** statement. The second is a table name. The table name in the CREATE
** TRIGGER statement is replaced with the third argument and the result
** returned. This is analagous to renameTableFunc() above, except for CREATE
** TRIGGER, not CREATE INDEX and CREATE TABLE.
label: code-design
SQLITE_ENABLE_MEMSYS5
Values for the OP_Variable opcode.
seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt
6
Index into pNode into which pCell is written
Extract the content for the p2+1-th column. Control can only
** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
** all valid.
If any database other than TEMP is reset, then also reset TEMP
** since TEMP might be holding triggers that reference tables in the
** other database.
Value of a host parameter
Buffer containing serialized structure
If this is a delete, decrement nPhaseOneStep by nIndex. If the DELETE
** statement below does actually delete a row, nPhaseOneStep will be
** incremented by the same amount when SQL function rbu_tmp_insert()
** is invoked by the trigger.
** Count the number of times that the LIKE operator (or GLOB which is
** just a variation of LIKE) gets called. This is used for testing
** only.
Number of valid a[] entries
comment: Maximum allowed allocation. 0 for no malloc usage
label: code-design
if defined SQLITE_OMIT_AUTOVACUUM
iLikeRepCntr actually stores 2x the counter register number. The
** bottom bit indicates whether the search order is ASC or DESC.
#include "sqlite3ext.h"
Prefix character. "+" or "-" or " " or '\0'.
** Find the appropriate action for a parser given the terminal
** look-ahead token iLookAhead.
An internal node.
** Erase all information in a table and add the root of the table to
** the freelist. Except, the root of the principle table (the one on
** page 1) is never added to the freelist.
**
** This routine will fail with SQLITE_LOCKED if there are any open
** cursors on the table.
**
** If AUTOVACUUM is enabled and the page at iTable is not the last
** root page in the database file, then the last root page
** in the database file is moved into the slot formerly occupied by
** iTable and that last slot formerly occupied by the last root page
** is added to the freelist instead of iTable. In this say, all
** root pages are kept at the beginning of the database file, which
** is necessary for AUTOVACUUM to work right. *piMoved is set to the
** page number that used to be the last root page in the file before
** the move. If no page gets moved, *piMoved is set to 0.
** The last root page is recorded in meta[3] and the value of
** meta[3] is updated by this procedure.
Update the .nOut value of this loop
File-system block size
Extend the p->aAlloc[] allocation if required.
** Convert a double into a LogEst
** In other words, compute an approximation for 10*log2(x).
Size of name in zName[]
** Return the number of references to the specified page.
True if there are triggers or FKs or
** subqueries in the WHERE clause
Status code
If there is no open read-transaction on the source database, open
** one now. If a transaction is opened here, then it will be closed
** before this function exits.
Compute the limit registers
The Loop object
** Return true if the underlying VFS for the given pager supports the
** primitives necessary for write-ahead logging.
comment:
** Generate a human-readable explanation of an expression list.
label: code-design
First register holding data to be sorted
Index of next token to be returned
Opening highlight
The "docid >= ?" constraint, if any
Use the SQLite core versions if this routine is part of the
** SQLite amalgamation
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
** The following formatting characters are allowed:
**
** %s Insert a string
** %z A string that should be freed after use
** %d Insert an integer
** %T Insert a token
** %S Insert the first element of a SrcList
**
** This function should be used to report any error that occurs while
** compiling an SQL statement (i.e. within sqlite3_prepare()). The
** last thing the sqlite3_prepare() function does is copy the error
** stored by this function into the database handle using sqlite3Error().
** Functions sqlite3Error() or sqlite3ErrorWithMsg() should be used
** during statement execution (sqlite3_step() etc.).
** At this point, variables are initialized as follows:
**
** flag_alternateform TRUE if a '#' is present.
** flag_altform2 TRUE if a '!' is present.
** flag_prefix '+' or ' ' or zero
** flag_leftjustify TRUE if a '-' is present or if the
** field width was negative.
** flag_zeropad TRUE if the width began with 0.
** flag_long 1 for "l", 2 for "ll"
** width The specified field width. This is
** always non-negative. Zero is the default.
** precision The specified precision. The default
** is -1.
** xtype The class of the conversion.
** infop Pointer to the appropriate info struct.
************* End of mem1.c ***********************************************
Connection
Array element to populate
Previous rowid value written to page
with
Discard pTemplate
Number of pragmas: 60 on by default, 77 total.
','
Number of pages on the freelist
** Set the FTS5CSR_REQUIRE_RESEEK flag on all FTS5_PLAN_MATCH cursors
** open on table pTab.
A collating sequence
** PRAGMA [schema.]incremental_vacuum(N)
**
** Do N steps of incremental vacuuming on a database.
SELECT may not have a GROUP BY clause
** sqlite3MallocDisallow() increments the following counter.
** sqlite3MallocAllow() decrements it.
Maximum length of zSql in bytes.
String inserted before highlighted term
This loop runs once for each entry in the blocked-connections list.
Index of left-hand Fts5SegIter
** Create a temporary file name in zBuf. zBuf must be allocated
** by the calling process and must be big enough to hold at least
** pVfs->mxPathname bytes.
1
** The 'pre-update' hook registered by this module with SQLite databases.
Name of target db table
Base class - must be first
146
No LIMIT means no OFFSET
** Release memory held by the Mem p, both external memory cleared
** by p->xDel and memory in p->zMalloc.
**
** This is a helper routine invoked by sqlite3VdbeMemRelease() in
** the unusual case where there really is memory in p that needs
** to be freed.
Invalidate all incrblob cursors open on table iTable (assuming iTable
** is the root of a table b-tree - if it is not, the following call is
** a no-op).
If doNot is true, then add a TK_NOT Expr-node wrapper around the
** outside of *ppExpr.
If not initializing, then create a record for the new table
** in the SQLITE_MASTER table of the database.
**
** If this is a TEMPORARY table, write the entry into the auxiliary
** file instead of into the main database file.
Desired maximum mmap size
REFERENCES
Length of aDoclist in bytes
** On recent Windows platforms, the localtime_s() function is available
** as part of the "Secure CRT". It is essentially equivalent to
** localtime_r() available under most POSIX platforms, except that the
** order of the parameters is reversed.
**
** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
**
** If the user has not indicated to use localtime_r() or localtime_s()
** already, check for an MSVC build environment that provides
** localtime_s().
Advance to the next term of the compound
** The following types are used as part of the implementation of the
** fts3BestSnippet() routine.
Form the KeyInfo object from this ExprList
a pointer to a SrcList
comment: The following value requires a mutex to change. We skip the mutex on
** reading because (1) most platforms read a 32-bit integer atomically and
** (2) even if an incorrect value is read, no great harm is done since this
** is really just an optimization.
label: code-design
Free the contents of the apShm[] array. And the array itself.
This is a utility routine used to set the ExprSpan.zStart and
** ExprSpan.zEnd values of pOut so that the span covers the complete
** range of text beginning with pStart and going to the end of pEnd.
** Deallocate a WhereClause structure. The WhereClause structure
** itself is not freed. This routine is the inverse of
** sqlite3WhereClauseInit().
Opcode: IfPos P1 P2 P3 * *
** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
**
** Register P1 must contain an integer.
** If the value of register P1 is 1 or greater, subtract P3 from the
** value in P1 and jump to P2.
**
** If the initial value of register P1 is less than 1, then the
** value is unchanged and control passes through to the next instruction.
Target table for DELETE, UPDATE, INSERT
comment: 0x8000 not currently used
label: code-design
0x01. Next integer will be a column number.
30..37 01234567
OUT: pointer to doclist
To assert pCache->nPage is correct
Result of sqlite3_reset()
OFFSET value. NULL means no offset
Number of slots allocated for aPoint[]
** Query status information.
** Return TRUE if the mask of type in eType matches no bits of the type of the
** allocation p. Also return true if p==NULL.
**
** This routine is designed for use within an assert() statement, to
** verify the type of an allocation. For example:
**
** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
** An instance of this structure is used to manage a pair of buffers, each
** (nElem * sizeof(u32)) bytes in size. See the MatchinfoBuffer code below
** for details.
comment: Calculate a hash value for this term. This is the same hash checksum
** used by the fts5_hash.c module. This is not important for correct
** operation of the module, but is necessary to ensure that some tests
** designed to produce hash table collisions really do work.
label: code-design
** Reset the tokenizer cursor passed as the only argument. As if it had
** just been returned by fts3tokOpenMethod().
Length of zMod in bytes
IMP: R-25361-16150 This function is omitted from SQLite by default. It
** is only available if the SQLITE_SOUNDEX compile-time option is used
** when SQLite is built.
0x8
database name - used by the update hook
Content of the new cell
Unused file descriptors to close
comment: Make sure the new table name does not collide with an existing
** index or table name in the same database. Issue an error message if
** it does. The exception is if the statement being parsed was passed
** to an sqlite3_declare_vtab() call. In that case only the column names
** and types will be used, so there is no need to test for namespace
** collisions.
label: code-design
** Each open file is managed by a separate instance of the "Pager" structure.
Array of collation sequence names for index
NEED_SYNC can be set independently of WRITEABLE. This can happen,
** for example, when using the sqlite3PagerDontWrite() optimization:
** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
** (2) Page X moved to freelist, WRITEABLE is cleared
** (3) Page X reused, WRITEABLE is set again
** If NEED_SYNC had been cleared in step 2, then it would not be reset
** in step 3, and page might be written into the database without first
** syncing the rollback journal, which might cause corruption on a power
** loss.
**
** Another example is when the database page size is smaller than the
** disk sector size. When any page of a sector is journalled, all pages
** in that sector are marked NEED_SYNC even if they are still CLEAN, just
** in case they are later modified, since all pages in the same sector
** must be journalled and synced before any of those pages can be safely
** written.
type of the previous token
comment: Initialize the malloc() system and the recursive pInitMutex mutex.
** This operation is protected by the STATIC_MASTER mutex. Note that
** MutexAlloc() is called for a static mutex prior to initializing the
** malloc subsystem - this implies that the allocation of a static
** mutex must not require support from the malloc subsystem.
label: code-design
The precision in %q and %Q means how many input characters to
** consume, not the length of the output...
** if( precision>=0 && precision<length ) length = precision;
** cnt==0 means there was not match. cnt>1 means there were two or
** more matches. Either way, we have an error.
The TK_SELECT_COLUMN Expr node:
**
** pLeft: pVector containing TK_SELECT. Not deleted.
** pRight: not used. But recursively deleted.
** iColumn: Index of a column in pVector
** iTable: 0 or the number of columns on the LHS of an assignment
** pLeft->iTable: First in an array of register holding result, or 0
** if the result is not yet computed.
**
** sqlite3ExprDelete() specifically skips the recursive delete of
** pLeft on TK_SELECT_COLUMN nodes. But pRight is followed, so pVector
** can be attached to pRight to cause this node to take ownership of
** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes
** with the same pLeft pointer to the pVector, but only one of them
** will own the pVector.
Jump here (skipping the main loop body subroutine) if the
** current sub-WHERE row is a duplicate from prior sub-WHEREs.
COMMIT => nothing
Has no LIMIT clause
WRITEABLE pages must also be DIRTY
Number of bits handled by each apSub[] entry.
Release the reference to the new page.
When reducing a lock such that other processes can start
** reading the database file again, make sure that the
** transaction counter was updated if any part of the database
** file changed. If the transaction counter is not updated,
** other connections to the same file might not realize that
** the file has changed and hence might not know to flush their
** cache. The use of a stale cache can lead to database corruption.
Object completely outside of query region
VDBE under construction
Largest permissible value of i
** The following singleton contains the global configuration for
** the SQLite library.
The last rowid in the doclist may not be on the current page. Search
** forward to find the page containing the last rowid.
Size of every page in this cache
** Return the size of the prefix, in bytes, that buffer
** (pNew/<length-unknown>) shares with buffer (pOld/nOld).
**
** Buffer (pNew/<length-unknown>) is guaranteed to be greater
** than buffer (pOld/nOld).
Offset of header in journal file
6: (start_constraints && startEq && !bRev)
Opcode: Rewind P1 P2 * * *
**
** The next use of the Rowid or Column or Next instruction for P1
** will refer to the first entry in the database table or index.
** If the table or index is empty, jump immediately to P2.
** If the table or index is not empty, fall through to the following
** instruction.
**
** This opcode leaves the cursor configured to move in forward order,
** from the beginning toward the end. In other words, the cursor is
** configured to use Next, not Prev.
** This vector defines all the methods that can operate on an
** sqlite3_file for win32.
Write the current in-memory list to a PMA. When the VdbeSorterWrite()
** function flushes the contents of memory to disk, it immediately always
** creates a new list consisting of a single key immediately afterwards.
** So the list is never empty at this point.
Value of %_segdir.start_block
** Release all the table locks (locks obtained via calls to
** the setSharedCacheTableLock() procedure) held by Btree object p.
**
** This function assumes that Btree p has an open read or write
** transaction. If it does not, then the BTS_PENDING flag
** may be incorrectly cleared.
** Structure allocated for each backup operation.
comment: The pager this page is part of
label: documentation
isOrdered for (pFrom+pWLoop)
Condition 1
** Resolve an expression that was part of an ATTACH or DETACH statement. This
** is slightly different from resolving a normal SQL expression, because simple
** identifiers are treated as strings, not possible column names or aliases.
**
** i.e. if the parser sees:
**
** ATTACH DATABASE abc AS def
**
** it treats the two expressions as literal strings 'abc' and 'def' instead of
** looking for columns of the same name.
**
** This only applies to the root node of pExpr, so the statement:
**
** ATTACH DATABASE abc||def AS 'db2'
**
** will fail because neither abc or def can be resolved.
Calculate the length in bytes and the checksum of zMaster
323
Cell extends past end of page
Each element in the hash table is an instance of the following
** structure. All elements are stored on a single doubly-linked list.
**
** Again, this structure is intended to be opaque, but it can't really
** be opaque because it is used by macros.
True if pParent is a root-page
comment: Balance the tree. If the entry deleted was located on a leaf page,
** then the cursor still points to that page. In this case the first
** call to balance() repairs the tree, and the if(...) condition is
** never true.
**
** Otherwise, if the entry deleted was on an internal node page, then
** pCur is pointing to the leaf page from which a cell was removed to
** replace the cell deleted from the internal node. This is slightly
** tricky as the leaf node may be underfull, and the internal node may
** be either under or overfull. In this case run the balancing algorithm
** on the leaf node first. If the balance proceeds far enough up the
** tree that we can be sure that any problem in the internal node has
** been corrected, so be it. Otherwise, after balancing the leaf node,
** walk the cursor up the tree to the internal node and balance it as
** well.
label: code-design
** A cursor is a pointer to a particular entry within a particular
** b-tree within a database file.
**
** The entry is identified by its MemPage and the index in
** MemPage.aCell[] of the entry.
**
** A single database file can be shared by two more database connections,
** but cursors cannot be shared. Each cursor is associated with a
** particular database connection identified BtCursor.pBtree.db.
**
** Fields in this structure are accessed under the BtShared.mutex
** found at self->pBt->mutex.
**
** skipNext meaning:
** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
** eState==FAULT: Cursor fault with skipNext as error code.
Use the standard library for separate compilation
Search for a deferred foreign key constraint for which this table
** is the child table. If one cannot be found, return without
** generating any VDBE code. If one can be found, then jump over
** the entire DELETE if there are no outstanding deferred constraints
** when this statement is run.
Next value in position list
Rollback any active transaction and free the handle structure.
** The call to sqlite3BtreeRollback() drops any table-locks held by
** this handle.
************* Begin file fts5.c *******************************************
If the p5 flag is clear, then recursive invocation of triggers is
** disabled for backwards compatibility (p5 is set if this sub-program
** is really a trigger, not a foreign key action, and the flag set
** and cleared by the "PRAGMA recursive_triggers" command is clear).
**
** It is recursive invocation of triggers, at the SQL level, that is
** disabled. In some cases a single trigger may generate more than one
** SubProgram (if the trigger may be executed with more than one different
** ON CONFLICT algorithm). SubProgram structures associated with a
** single trigger all have the same value for the SubProgram.token
** variable.
(280) trans_opt ::= TRANSACTION nm
User authentication failed
If not NULL, blob handle to read node
Where to send the data
Initial working space
Commit the transaction to the *-oal file.
Number of entries allocated in a[] below
The table being inserted or updated
Verify ok to add new elements
Delete the corresponding entry in the <rtree>_rowid table.
Buffer used to build up %_docsize blob
** Generate code to drop a table.
Add cells to the start of the page
EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
** length.
** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
** (N-13)/2 bytes in length.
Zero the entries in the aPgno array that correspond to frames with
** frame numbers greater than pWal->hdr.mxFrame.
If this is an in-memory db, or no pages have been written to, or this
** function has already been called, it is mostly a no-op. However, any
** backup in progress needs to be restarted.
0 1 2 3 4 5 6 7 8 9
** Given a node number iNode, return the corresponding key to use
** in the Rtree.aHash table.
** A single instruction of the virtual machine has an opcode
** and as many as three operands. The instruction is recorded
** as an instance of the following structure:
Number of imm. FK constraints this VM
comment:
** Argument zFmt is a printf() style format string. This function performs
** the printf() style processing, then appends the results to buffer pBuf.
**
** Like sqlite3Fts5BufferAppendString(), this function ensures that the byte
** following the buffer data is set to 0x00, even though this byte is not
** included in the pBuf->n count.
label: code-design
Blob value for "root" field
** Implementation of highlight() function.
** Create a hash table, free a hash table.
** 2004 April 13
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used to translate between UTF-8,
** UTF-16, UTF-16BE, and UTF-16LE.
**
** Notes on UTF-8:
**
** Byte-0 Byte-1 Byte-2 Byte-3 Value
** 0xxxxxxx 00000000 00000000 0xxxxxxx
** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx
** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx
** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx
**
**
** Notes on UTF-16: (with wwww+1==uuuuu)
**
** Word-0 Word-1 Value
** 110110ww wwzzzzyy 110111yy yyxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
** zzzzyyyy yyxxxxxx 00000000 zzzzyyyy yyxxxxxx
**
**
** BOM or Byte Order Mark:
** 0xff 0xfe little-endian utf-16 follows
** 0xfe 0xff big-endian utf-16 follows
**
Number of columns forming the key
For ON UPDATE, construct the next term of the WHEN clause.
** The final WHEN clause will be like this:
**
** WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
Callback to invoke
P4 is a pointer to an Expr tree
Analyze all of the subexpressions.
If some other connection is holding an exclusive lock, the
** requested lock may not be obtained.
If the current block is not empty, and if adding this term/doclist
** to the current block would make it larger than Fts3Table.nNodeSize
** bytes, write this block out to the database.
Last result returned from the iterator
OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED
SELECT name ... WHERE rootpage = $tnum
comment:
** CAPI3REF: Synchronization Type Flags
**
** When SQLite invokes the xSync() method of an
** [sqlite3_io_methods] object it uses a combination of
** these integer values as the second argument.
**
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
** sync operation only needs to flush data to mass storage. Inode
** information need not be flushed. If the lower four bits of the flag
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
** If the lower four bits equal SQLITE_SYNC_FULL, that means
** to use Mac OS X style fullsync instead of fsync().
**
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
** settings. The [synchronous pragma] determines when calls to the
** xSync VFS method occur and applies uniformly across all platforms.
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
** energetic or rigorous or forceful the sync operations are and
** only make a difference on Mac OSX for the default SQLite code.
** (Third-party VFS implementations might also make the distinction
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
** operating systems natively supported by SQLite, only Mac OSX
** cares about the difference.)
label: code-design
** Read keys from pIncr->pMerger and populate pIncr->aFile[1]. The format
** of the data stored in aFile[1] is the same as that used by regular PMAs,
** except that the number-of-bytes varint is omitted from the start.
Number of characters in function name
Code the current SELECT statement
Errors are detected by individual opcodes, with an immediate
** jumps to abort_due_to_error.
Number of constraints in p
** The expression pExpr passed as the second argument to this function
** must be of type FTSQUERY_PHRASE.
**
** The returned value is either NULL or a pointer to a buffer containing
** a position-list indicating the occurrences of the phrase in column iCol
** of the current row.
**
** More specifically, the returned buffer contains 1 varint for each
** occurrence of the phrase in the column, stored using the normal (delta+2)
** compression and is terminated by either an 0x01 or 0x00 byte. For example,
** if the requested column contains "a b X c d X X" and the position-list
** for 'X' is requested, the buffer returned may contain:
**
** 0x04 0x05 0x03 0x01 or 0x04 0x05 0x03 0x00
**
** This function works regardless of whether or not the phrase is deferred,
** incremental, or neither.
** Close a file.
**
** It is reported that an attempt to close a handle might sometimes
** fail. This is a very unreasonable result, but Windows is notorious
** for being unreasonable so I do not doubt that it might happen. If
** the close fails, we pause for 100 milliseconds and try again. As
** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before
** giving up and returning an error.
** Set node pNode, which is part of expression pExpr, to point to the first
** match. If there are no matches, set the Node.bEof flag to indicate EOF.
**
** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
** It is not an error if there are no matches.
Patch up the ORDER BY clause
Load the FTS index structure
Subtype for this value
** Compute the soundex encoding of a word.
**
** IMP: R-59782-00072 The soundex(X) function returns a string that is the
** soundex encoding of the string X.
1320
** 2008 August 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite page cache
** subsystem.
with ::= WITH wqlist
** Return the sum of the reference counts for all pages held by pPager.
Overflow chain ends prematurely
Maybe another cursor on the same btree
Number of bytes to lock
** Walk an expression tree. Return non-zero if the expression is constant
** or a function call with constant arguments. Return and 0 if there
** are any variables.
**
** For the purposes of this function, a double-quoted string (ex: "abc")
** is considered a variable but a single-quoted string (ex: 'abc') is
** a constant.
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
** where X is a reference to the iColumn of table iCur or of index pIdx
** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
** the op parameter. Return a pointer to the term. Return 0 if not found.
**
** If pIdx!=0 then it must be one of the indexes of table iCur.
** Search for terms matching the iColumn-th column of pIdx
** rather than the iColumn-th column of table iCur.
**
** The term returned might by Y=<expr> if there is another constraint in
** the WHERE clause that specifies that X=Y. Any such constraints will be
** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
** other equivalent values. Hence a search for X will return <expr> if X=A1
** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
**
** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
** then try for the one with no dependencies on <expr> - in other words where
** <expr> is a constant expression of some kind. Only return entries of
** the form "X <op> Y" where Y is a column in another table if no terms of
** the form "X <op> <const-expr>" exist. If no terms with a constant RHS
** exist, try to return a term that does not use WO_EQUIV.
** Return the bitwise-OR of all Expr.flags fields in the given
** ExprList.
Destination page size
Number of bytes in buffer aRecord[]
** Move the open database page pDbPage to location iFreePage in the
** database. The pDbPage reference remains valid.
**
** The isCommit flag indicates that there is no need to remember that
** the journal needs to be sync()ed before database page pDbPage->pgno
** can be written to. The caller has already promised not to write to that
** page.
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
** defined at compile-time. If it is not a no-op, a single OP_Explain opcode
** is added to the output to describe the table scan strategy in pLevel.
**
** If an OP_Explain opcode is added to the VM, its address is returned.
** Otherwise, if no OP_Explain is coded, zero is returned.
Total number of calls to malloc
** Same as above, except that this implementation works for WinRT.
Index in mem3.aPool[] of previous free chunk
Most recent error message
Bytes in pPage beyond the header
comment:
** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
** is not the case, this function returns [SQLITE_MISUSE].
**
** If argument pzTab is not NULL, then *pzTab is set to point to a
** nul-terminated utf-8 encoded string containing the name of the table
** affected by the current change. The buffer remains valid until either
** sqlite3changeset_next() is called on the iterator or until the
** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
** set to the number of columns in the table affected by the change. If
** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change
** is an indirect change, or false (0) otherwise. See the documentation for
** [sqlite3session_indirect()] for a description of direct and indirect
** changes. Finally, if pOp is not NULL, then *pOp is set to one of
** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
** type of change that the iterator currently points to.
**
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
** SQLite error code is returned. The values of the output variables may not
** be trusted in this case.
label: code-design
'%'
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append the string zStr enclosed in quotes (") and
** with any embedded quote characters escaped to the buffer. No
** nul-terminator byte is written.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
Not always defined in the headers as it ought to be
RHS table
comment:
** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
** there is room for at least nCol elements. If an OOM occurs, store an
** error code in the RBU handle passed as the first argument.
label: code-design
Number of objects currently in use
Magic value read from WAL header
First page of the sector pPg is located on.
Statement used to fetch segdir
Allocate the hash table if it has not already been allocated
The opcode
The score for a perfect match
MATCH
comment: Avoid a warning indicating that sqlite3Fts5ParserTrace() is unused
label: code-design
cnearset ::= colset COLON nearset
(307) likeop ::= LIKE_KW|MATCH
If the WAL file is not empty, return the number of bytes of content
** stored in each frame (i.e. the db page-size when the WAL was created).
Locate the table into which we will be inserting new information.
1 to honor DESC in index. 0 to ignore.
************* Begin file walker.c *****************************************
Formulate the zContentExprlist text
Number of overflow cell bodies in aCell[]
nexprlist ::= expr
Number of bytes of memory available to this allocator
New term to write
comment: FIXME: Be smarter about indexes that use expressions
label: code-design
** Return the N-th compile-time option string. If N is out of range,
** return a NULL pointer.
** Update the value of the change-counter at offsets 24 and 92 in
** the header and the sqlite version number at offset 96.
**
** This is an unconditional update. See also the pager_incr_changecounter()
** routine which only updates the change-counter if the update is actually
** needed, as determined by the pPager->changeCountDone state variable.
Stop when row count reaches this
** This function is called to close the connection to the log file prior
** to switching from WAL to rollback mode.
**
** Before closing the log file, this function attempts to take an
** EXCLUSIVE lock on the database file. If this cannot be obtained, an
** error (SQLITE_BUSY) is returned and the log connection is not closed.
** If successful, the EXCLUSIVE lock is not released before returning.
Force schema load before running
** Return some kind of integer value which is the best we can do
** at representing the value that *pMem describes as an integer.
** If pMem is an integer, then the value is exact. If pMem is
** a floating-point then the value returned is the integer part.
** If pMem is a string or blob, then we make an attempt to convert
** it into an integer and return that. If pMem represents an
** an SQL-NULL value, return 0.
**
** If pMem represents a string value, its encoding might be changed.
Opcode: IfSmaller P1 P2 P3 * *
**
** Estimate the number of rows in the table P1. Jump to P2 if that
** estimate is less than approximately 2**(0.1*P3).
Change counter
p->iCoord might point to either a lower or upper bound coordinate
** in a coordinate pair. But make pCellData point to the lower bound.
The FROM is a subquery
** Named semaphore locking is only available on VxWorks.
**
*************** End of the named semaphore lock implementation ****************
*****************************************************************************
The expression to be analyzed.
Initialize the memory allocator
Check btree cell sizes on load
If !=0, WAL frame to return data from
Number of elements in aSavepoint[]
same as TK_GE, jump, in1, in3
Advance each level to the last entry on the last page
** Insert a new value into a RowSet.
**
** The mallocFailed flag of the database connection is set if a
** memory allocation fails.
A foreign key constraint
List of tables
Cookie value to store
Backup handle
************* Include fts3.h in the middle of main.c **********************
An error message
** This object is the header on a single record while that record is being
** held in memory and prior to being written out as part of a PMA.
**
** How the linked list is connected depends on how memory is being managed
** by this module. If using a separate allocation for each in-memory record
** (VdbeSorter.list.aMemory==0), then the list is always connected using the
** SorterRecord.u.pNext pointers.
**
** Or, if using the single large allocation method (VdbeSorter.list.aMemory!=0),
** then while records are being accumulated the list is linked using the
** SorterRecord.u.iNext offset. This is because the aMemory[] array may
** be sqlite3Realloc()ed while records are being accumulated. Once the VM
** has finished passing records to the sorter, or when the in-memory buffer
** is full, the list is sorted. As part of the sorting process, it is
** converted to use the SorterRecord.u.pNext pointers. See function
** vdbeSorterSort() for details.
OUT: Buffer containing changeset
Figure out the db that the trigger will be created in
Return a pointer to the allocated object to the caller. Note that
** only the pointer (the 2nd parameter) matters. The size of the object
** (given by the 3rd parameter) is never used and can be any positive
** value.
** This function creates the second imposter table used when writing to
** a table b-tree where the table has an external primary key. If the
** iterator passed as the second argument does not currently point to
** a table (not index) with an external primary key, this function is a
** no-op.
**
** Assuming the iterator does point to a table with an external PK, this
** function creates a WITHOUT ROWID imposter table named "rbu_imposter2"
** used to access that PK index. For example, if the target table is
** declared as follows:
**
** CREATE TABLE t1(a, b TEXT, c REAL, PRIMARY KEY(b, c));
**
** then the imposter table schema is:
**
** CREATE TABLE rbu_imposter2(c1 TEXT, c2 REAL, id INTEGER) WITHOUT ROWID;
**
Top of a loop checking foreign keys
Error message codes for OP_Halt
** Object used to iterate through all "coalesced phrase instances" in
** a single column of the current row. If the phrase instances in the
** column being considered do not overlap, this object simply iterates
** through them. Or, if they do overlap (share one or more tokens in
** common), each set of overlapping instances is treated as a single
** match. See documentation for the highlight() auxiliary function for
** details.
**
** Usage is:
**
** for(rc = fts5CInstIterNext(pApi, pFts, iCol, &iter);
** (rc==SQLITE_OK && 0==fts5CInstIterEof(&iter);
** rc = fts5CInstIterNext(&iter)
** ){
** printf("instance starts at %d, ends at %d\n", iter.iStart, iter.iEnd);
** }
**
************* Begin file vdbesort.c ***************************************
Reload the schema of the modified table.
getenv("TMP")
comment:
** CAPI3REF: Prepared Statement Scan Status
** METHOD: sqlite3_stmt
**
** This interface returns information about the predicted and measured
** performance for pStmt. Advanced applications can use this
** interface to compare the predicted and the measured performance and
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
**
** Since this interface is expected to be rarely used, it is only
** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
** compile-time option.
**
** The "iScanStatusOp" parameter determines which status information to return.
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
** of this interface is undefined.
** ^The requested measurement is written into a variable pointed to by
** the "pOut" parameter.
** Parameter "idx" identifies the specific loop to retrieve statistics for.
** Loops are numbered starting from zero. ^If idx is out of range - less than
** zero or greater than or equal to the total number of loops used to implement
** the statement - a non-zero value is returned and the variable that pOut
** points to is unchanged.
**
** ^Statistics might not be available for all loops in all statements. ^In cases
** where there exist loops with no available statistics, this function behaves
** as if the loop did not exist - it returns non-zero and leave the variable
** that pOut points to unchanged.
**
** See also: [sqlite3_stmt_scanstatus_reset()]
label: code-design
Allocate space for Fts3Cursor.aMatchinfo[] and Fts3Cursor.zMatchinfo.
Number of iterators/phrases
The HAVING clause
** Convert raw bits from the on-disk RTree record into a coordinate value.
** The on-disk format is big-endian and needs to be converted for little-
** endian platforms. The on-disk record stores integer coordinates if
** eInt is true and it stores 32-bit floating point records if eInt is
** false. a[] is the four bytes of the on-disk record to be decoded.
** Store the results in "r".
**
** There are five versions of this macro. The last one is generic. The
** other four are various architectures-specific optimizations.
Round away from zero
************* End of fts3Int.h ********************************************
540
Sanity checking on other operands
Current position list
** An implementation of the LockFile() API of Windows for CE
free the system buffer allocated by FormatMessage
Allocate space for aXRef[], aRegIdx[], and aToOpen[].
** Initialize aXRef[] and aToOpen[] to their default values.
** json_extract(JSON, PATH, ...)
**
** Return the element described by PATH. Return NULL if there is no
** PATH element. If there are multiple PATHs, then return a JSON array
** with the result from each path. Throw an error if the JSON or any PATH
** is malformed.
Number of conch taking failures
WhereLoop.u.btree.pIndex is valid
Extra zero bytes when MEM_Zero and MEM_Blob set
1040
** If the word ends with zFrom and xCond() is true for the stem
** of the word that preceeds the zFrom ending, then change the
** ending to zTo.
**
** The input word *pz and zFrom are both in reverse order. zTo
** is in normal order.
**
** Return TRUE if zFrom matches. Return FALSE if zFrom does not
** match. Not that TRUE is returned even if xCond() fails and
** no substitution occurs.
File offset to begin writing at
comment:
** Invoke the xNext method of an Fts5ExprNode object. This macro should be
** used as if it has the same signature as the xNext() methods themselves.
label: code-design
** This function encodes a single frame header and writes it to a buffer
** supplied by the caller. A frame-header is made up of a series of
** 4-byte big-endian integers, as follows:
**
** 0: Page number.
** 4: For commit records, the size of the database image in pages
** after the commit. For all other records, zero.
** 8: Salt-1 (copied from the wal-header)
** 12: Salt-2 (copied from the wal-header)
** 16: Checksum-1.
** 20: Checksum-2.
Context used to resolve WHERE clause
Opcode: Sequence P1 P2 * * *
** Synopsis: r[P2]=cursor[P1].ctr++
**
** Find the next available sequence number for cursor P1.
** Write the sequence number into register P2.
** The sequence number on the cursor is incremented after this
** instruction.
Invoke the main loop body as a subroutine
** The size of the of each page record in the journal is given by
** the following macro.
** Bitmasks for the operators on WhereTerm objects. These are all
** operators that are of interest to the query planner. An
** OR-ed combination of these values can be used when searching for
** particular WhereTerms within a WhereClause.
**
** Value constraints:
** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
** Generate code for a single equality term of the WHERE clause. An equality
** term can be either X=expr or X IN (...). pTerm is the term to be
** coded.
**
** The current value for the constraint is left in a register, the index
** of which is returned. An attempt is made store the result in iTarget but
** this is only guaranteed for TK_ISNULL and TK_IN constraints. If the
** constraint is a TK_EQ or TK_IS, then the current value might be left in
** some other register and it is the caller's responsibility to compensate.
**
** For a constraint of the form X=expr, the expression is evaluated in
** straight-line code. For constraints of the form X IN (...)
** this routine sets up a loop that will iterate over all values of X.
New element added to the pH
1-byte signed integer
when_clause
There are no pages on the freelist, so append a new page to the
** database image.
**
** Normally, new pages allocated by this block can be requested from the
** pager layer with the 'no-content' flag set. This prevents the pager
** from trying to read the pages content from disk. However, if the
** current transaction has already run one or more incremental-vacuum
** steps, then the page we are about to allocate may contain content
** that is required in the event of a rollback. In this case, do
** not set the no-content flag. This causes the pager to load and journal
** the current page content before overwriting it.
**
** Note that the pager will not actually attempt to load or journal
** content for any page that really does lie past the end of the database
** file on disk. So the effects of disabling the no-content optimization
** here are confined to those pages that lie between the end of the
** database image and the end of the database file.
Do not allow memory allocation
String on RHS of LIKE operator
Number of entries in aTC[]
List of values being extracted
assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew );
** Context object for havingToWhereExprCb().
1280
If Fts3Cursor.pMIBuffer is NULL, then this is the first time the
** matchinfo function has been called for this query. In this case
** allocate the array used to accumulate the matchinfo data and
** initialize those elements that are constant for every row.
The hash table to insert into
If an error occurs, we jump here
OUT: gid of zFile.
The table being constructed
The computed column name
The value returned by this function should always be the same as
** the (CellInfo.nSize) value found by doing a full parse of the
** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
** this function verifies that this invariant is not violated.
This is the general case where many pages are being removed.
** It is necessary to scan the entire hash table
** Insert a new cell on pPage at cell index "i". pCell points to the
** content of the cell.
**
** If the cell content will fit on the page, then put it there. If it
** will not fit, then make a copy of the cell content into pTemp if
** pTemp is not null. Regardless of pTemp, allocate a new entry
** in pPage->apOvfl[] and make it point to the cell content (either
** in pTemp or the original pCell) and also record its index.
** Allocating a new entry in pPage->aCell[] implies that
** pPage->nOverflow is incremented.
**
** *pRC must be SQLITE_OK when this routine is called.
read-write cursor
** Arguments nArg/azArg contain the string arguments passed to the xCreate
** or xConnect method of the virtual table. This function attempts to
** allocate an instance of Fts5Config containing the results of parsing
** those arguments.
**
** If successful, SQLITE_OK is returned and *ppOut is set to point to the
** new Fts5Config object. If an error occurs, an SQLite error code is
** returned, *ppOut is set to NULL and an error message may be left in
** *pzErr. It is the responsibility of the caller to eventually free any
** such error message using sqlite3_free().
At this point, pWLoop is a candidate to be the next loop.
** Compute its cost
typetoken ::=
This function is called when Btree p is concluding its
** transaction. If there currently exists a writer, and p is not
** that writer, then the number of locks held by connections other
** than the writer must be about to drop to zero. In this case
** set the BTS_PENDING flag to 0.
**
** If there is not currently a writer, then BTS_PENDING must
** be zero already. So this next line is harmless in that case.
Btree page of current entry
ACTION => ID
** For tokenizers with no "unicode" modifier, the set of token characters
** is the same as the set of ASCII range alphanumeric characters.
OUT: WITH clause return value belongs to
Type of join between this table and the previous
Value to destroy
This file is used on unix only
Linked list of all sub-programs used by VM
Authentication not yet checked
comment: True after malloc is initialized
label: code-design
sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
**
** If parameter onoff is non-zero, configure the wrappers so that all
** subsequent calls to localtime() and variants fail. If onoff is zero,
** undo this setting.
b8..bf ........
Write the name of each database file in the transaction into the new
** master journal file. If an error occurs at this point close
** and delete the master journal file. All the individual journal files
** still have 'null' as the master journal pointer, so they will roll
** back independently if a failure occurs.
Statement used to read %_content
szOsFile
comment:
** Cleans up the mapped region of the specified file, if any.
label: code-design
** Ensure that the Fts5Cursor.nInstCount and aInst[] variables are populated
** correctly for the current view. Return SQLITE_OK if successful, or an
** SQLite error code otherwise.
exprlist
** Force RBU to save its state to disk.
**
** If a power failure or application crash occurs during an update, following
** system recovery RBU may resume the update from the point at which the state
** was last saved. In other words, from the most recent successful call to
** sqlite3rbu_close() or this function.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
Make sure the new file size is written into the inode right away.
** Otherwise the journal might resurrect following a power loss and
** cause the last transaction to roll back. See
** https://bugzilla.mozilla.org/show_bug.cgi?id=1072773
SETUP-INVARIANT above
Store result as keys in an index
** When testing, also keep a count of the number of open files.
Disable the original
** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
** contains the size in bytes of each such cell. This function adds the
** space associated with each cell in the array that is currently stored
** within the body of pPg to the pPg free-list. The cell-pointers and other
** fields of the page are not updated.
**
** This function returns the total number of cells added to the free-list.
4-byte unsigned integer
No table references
Size of pOrig region in bytes
xInit
Currently iOff points to the first byte of a varint. This block
** decrements iOff until it points to the first byte of the previous
** varint. Taking care not to read any memory locations that occur
** before the buffer in memory.
#ifndef SQLITE_OMIT_INCRBLOB
Adjust base and n to skip over SQLITE_AFF_BLOB entries at the beginning
** and end of the affinity string.
** Implementation of the sqlite3_pcache.xCreate method.
**
** Allocate a new cache.
The root page of this tree
* Make sure that the calculated cache size, in pages, cannot cause the
* initial size of the Win32-specific heap to exceed the maximum amount
* of memory that can be specified in the call to HeapCreate.
'"', '\'', or '`'. String literals, quoted ids
MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
** ensure that if Mem.szMalloc>0 then it is safe to do
** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
** That saves a few cycles in inner loops.
Hash value to return
The tree being checked out
** Remove a row from the FTS table.
Holding area for temporary registers
This Mem is a shallow copy of pScopyFrom
sortorder ::=
The value of pExpr->op and op are related as follows:
**
** pExpr->op op
** --------- ----------
** TK_ISNULL OP_NotNull
** TK_NOTNULL OP_IsNull
** TK_NE OP_Eq
** TK_EQ OP_Ne
** TK_GT OP_Le
** TK_LE OP_Gt
** TK_GE OP_Lt
** TK_LT OP_Ge
**
** For other values of pExpr->op, op is undefined and unused.
** The value of TK_ and OP_ constants are arranged such that we
** can compute the mapping above using the following expression.
** Assert()s verify that the computation is correct.
The page that contains the cell
Do not allow the upper bound of a LIKE optimization range constraint
** to mix with a lower range bound from some other source
Overflows are sequential
If some thread using this PID has a lock via a different unixFile*
** handle that precludes the requested lock, return BUSY.
If the cursor is already positioned at the point we are trying
** to move to, then just return without doing any work
comment:
** CAPI3REF: Suspend Execution For A Short Time
**
** The sqlite3_sleep() function causes the current thread to suspend execution
** for at least a number of milliseconds specified in its parameter.
**
** If the operating system does not support sleep requests with
** millisecond time resolution, then the time will be rounded up to
** the nearest second. The number of milliseconds of sleep actually
** requested from the operating system is returned.
**
** ^SQLite implements this interface by calling the xSleep()
** method of the default [sqlite3_vfs] object. If the xSleep() method
** of the default VFS is not implemented correctly, or not implemented at
** all, then the behavior of sqlite3_sleep() may deviate from the description
** in the previous paragraphs.
label: code-design
** Compare the contents of the two buffers using memcmp(). If one buffer
** is a prefix of the other, it is considered the lesser.
**
** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
** +ve if pRight is smaller than pLeft. In other words:
**
** res = *pLeft - *pRight
** Allocate space to hold a new trigger step. The allocated space
** holds both the TriggerStep object and the TriggerStep.target.z string.
**
** If an OOM error occurs, NULL is returned and db->mallocFailed is set.
OUT: Token text
Name of symbol to add
Name of index or table
What to do with query results
The parsing context. Errors accumulate here
rbu database handle
PmaReader from which to take the blob
True if token must appear at position 0
The temporary database we vacuum into
The sqlite3_aggregate_count() function is deprecated. But just to make
** sure it still operates correctly, verify that its count agrees with our
** internal count when using count(*) and when the total count can be
** expressed as a 32-bit integer.
Write the bytes into this buffer
Virtual machine under construction
Total term size
in2
Translate JSON formatted string into raw text
OUT: Value of original database size field
** This is the xColumn method, called by SQLite to request a value from
** the row that the supplied cursor currently points to.
**
** If:
**
** (iCol < p->nColumn) -> The value of the iCol'th user column.
** (iCol == p->nColumn) -> Magic column with the same name as the table.
** (iCol == p->nColumn+1) -> Docid column
** (iCol == p->nColumn+2) -> Langid column
Array of flags, set on target PK columns
If a transaction is open, the disconnectAllVtab() call above
** will not have called the xDisconnect() method on any virtual
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
** call will do so. We need to do this before the check for active
** SQL statements below, as the v-table implementation may be storing
** some prepared statements internally.
The WAL has been completely backfilled (or it is empty).
** and can be safely ignored.
************* End of mem2.c ***********************************************
Methods above are valid for version 1
OF => ID
a8..af ........
The argument values
** External API function used to create a new virtual-table module.
Nesting depth
synopsis: root=P2 iDb=P3
This is an in-memory DB
Either chngPk or chngRowid
x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf
Different WHERE clauses
Result string
comment:
** Advance to the next document that matches the FTS expression in
** Fts3Cursor.pExpr.
label: documentation
pPager->stmtSize = 0;
If SQLITE_NULLEQ is set (which will only happen if the operator is
** OP_Eq or OP_Ne) then take the jump or not depending on whether
** or not both operands are null.
** This function is only called from within a pre-update handler for a
** write to table pTab, part of session pSession. If this is the first
** write to this table, initalize the SessionTable.nCol, azCol[] and
** abPK[] arrays accordingly.
**
** If an error occurs, an error code is stored in sqlite3_session.rc and
** non-zero returned. Or, if no error occurs but the table has no primary
** key, sqlite3_session.rc is left set to SQLITE_OK and non-zero returned to
** indicate that updates on this table should be ignored. SessionTable.abPK
** is set to NULL in this case.
True for threadsafe connections
OUT: gid to set on the file
If using the onepass strategy, no-op out the OP_OpenEphemeral coded
** above. Also, if this is a top-level parse (not a trigger), clear the
** multi-write flag so that the VM does not open a statement journal
Step 3: Abort if createFlag is 1 but the cache is nearly full
Number of cells to add to pPg
Collating sequence to use on this term
Recursive part w/o aColCache
Used by: busy_timeout
Aggregate column length array
Database lock protocol error
Register holding assembled index record
94
SELECT rowid FROM x ... (dup of pSrc)
p1 is smaller
Token associated with this expression
151
FIX ME: Compute pExpr->affinity based on the expected return
** type of the function
Name of the table to be locked
** Term pTerm is a vector range comparison operation. The first comparison
** in the vector can be optimized using column nEq of the index. This
** function returns the total number of vector elements that can be used
** as part of the range comparison.
**
** For example, if the query is:
**
** WHERE a = ? AND (b, c, d) > (?, ?, ?)
**
** and the index:
**
** CREATE INDEX ... ON (a, b, c, d, e)
**
** then this function would be invoked with nEq=1. The value returned in
** this case is 3.
** Bitfield flags for P5 value in various opcodes.
**
** Value constraints (enforced via assert()):
** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
** OPFLAG_BULKCSR == BTREE_BULKLOAD
** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
** OPFLAG_FORDELETE == BTREE_FORDELETE
** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
** OPFLAG_AUXDELETE == BTREE_AUXDELETE
same as TK_GT, synopsis: IF r[P3]>r[P1]
Integer value contained in u.iValue
Offset of pgidx in a[]
comment:
** Search for an unused file descriptor that was opened on the database
** file (not a journal or master-journal file) identified by pathname
** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
** argument to this function.
**
** Such a file descriptor may exist if a database connection was closed
** but the associated file descriptor could not be closed because some
** other file descriptor open on the same file is holding a file-lock.
** Refer to comments in the unixClose() function and the lengthy comment
** describing "Posix Advisory Locking" at the start of this file for
** further details. Also, ticket #4018.
**
** If a suitable file descriptor is found, then it is returned. If no
** such file descriptor is located, -1 is returned.
label: code-design
Column number of LHS
Current 'start' value
** This function is used to add page iPage to the database file free-list.
** It is assumed that the page is not already a part of the free-list.
**
** The value passed as the second argument to this function is optional.
** If the caller happens to have a pointer to the MemPage object
** corresponding to page iPage handy, it may pass it as the second value.
** Otherwise, it may pass NULL.
**
** If a pointer to a MemPage object is passed as the second argument,
** its reference count is not altered by this function.
** Construct a WalInterator object that can be used to loop over all
** pages in the WAL in ascending order. The caller must hold the checkpoint
** lock.
**
** On success, make *pp point to the newly allocated WalInterator object
** return SQLITE_OK. Otherwise, return an error code. If this routine
** returns an error, the value of *pp is undefined.
**
** The calling routine should invoke walIteratorFree() to destroy the
** WalIterator object when it has finished with it.
If the P4 argument is not NULL, then it must be an SQL comment string.
** The "--" string is broken up to prevent false-positives with srcck1.c.
**
** This assert() provides evidence for:
** EVIDENCE-OF: R-50676-09860 The callback can compute the same text that
** would have been returned by the legacy sqlite3_trace() interface by
** using the X argument when X begins with "--" and invoking
** sqlite3_expanded_sql(P) otherwise.
** Return the appropriate collating sequence for the iCol-th column of
** the result set for the compound-select statement "p". Return NULL if
** the column has no default collating sequence.
**
** The collating sequence for the compound select is taken from the
** left-most term of the select that has a collating sequence.
An error has occurred. Delete the hash table and return the error code.
If the "=MODE" part does not match any known journal mode,
** then do a query
The expression is a column. Locate the table the column is being
** extracted from in NameContext.pSrcList. This table may be real
** database table or a subquery.
Assert that P3 is a valid memory cell.
Name of the table to be updated
** Sometimes we need a small amount of code such as a variable initialization
** to setup for a later assert() statement. We do not want this code to
** appear when assert() is disabled. The following macro is therefore
** used to contain that setup code. The "VVA" acronym stands for
** "Verification, Validation, and Accreditation". In other words, the
** code within VVA_ONLY() will only run during verification processes.
IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
** returns an integer equal to SQLITE_VERSION_NUMBER.
** Hash table for global functions - functions common to all
** database connections. After initialization, this table is
** read-only.
Address register for select-B coroutine
comment: Increment Parse.nHeight by the height of the largest expression
** tree referred to by this, the parent select. The child select
** may contain expression trees of at most
** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
** more conservative than necessary, but much easier than enforcing
** an exact limit.
label: code-design
New table object (if required)
out3: P3 is an output
Child table contain "REFERENCES" keyword
Make this point to any syntax error
Do not defer seeks if unique
Used by: foreign_key_list
** Release an SQLite statement handle obtained via an earlier call to
** sqlite3Fts5StorageStmt(). The eStmt parameter passed to this function
** must match that passed to the sqlite3Fts5StorageStmt() call.
500
Reload the constraint value into reg[iReg+j+2]. The same value
** was loaded into the same register prior to the OP_VFilter, but
** the xFilter implementation might have changed the datatype or
** encoding of the value in the register, so it *must* be reloaded.
4-byte signed integer
End of function
True if REPLACE is used to resolve INT PK conflict
** *pCurrent gets an accurate estimate of the amount of memory used
** to store the schema for all databases (main, temp, and any ATTACHed
** databases. *pHighwater is set to zero.
** Macros for testing whether or not optimizations are enabled or disabled.
OUT: Return the Pager structure here
Check if any child key columns are being modified.
How to dispose of the results. On of SRT_* above.
(308) exprlist ::= nexprlist
Parent class. MUST BE FIRST
If this is a prefix query, check that the results returned if the
** the index is disabled are the same. In both ASC and DESC order.
**
** This check may only be performed if the hash table is empty. This
** is because the hash table only supports a single scan query at
** a time, and the multi-iter loop from which this function is called
** is already performing such a scan.
Used by sqlite3WhereExprUsage()
True if an equality comparison has been seen
** CAPI3REF: Data Change Notification Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_update_hook() interface registers a callback function
** with the [database connection] identified by the first argument
** to be invoked whenever a row is updated, inserted or deleted in
** a [rowid table].
** ^Any callback set by a previous call to this function
** for the same database connection is overridden.
**
** ^The second argument is a pointer to the function to invoke when a
** row is updated, inserted or deleted in a rowid table.
** ^The first argument to the callback is a copy of the third argument
** to sqlite3_update_hook().
** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
** or [SQLITE_UPDATE], depending on the operation that caused the callback
** to be invoked.
** ^The third and fourth arguments to the callback contain pointers to the
** database and table name containing the affected row.
** ^The final callback parameter is the [rowid] of the row.
** ^In the case of an update, this is the [rowid] after the update takes place.
**
** ^(The update hook is not invoked when internal system tables are
** modified (i.e. sqlite_master and sqlite_sequence).)^
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
**
** ^In the current implementation, the update hook
** is not invoked when conflicting rows are deleted because of an
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
** invoked when rows are deleted using the [truncate optimization].
** The exceptions defined in this paragraph might change in a future
** release of SQLite.
**
** The update hook implementation must not do anything that will modify
** the database connection that invoked the update hook. Any actions
** to modify the database connection must be deferred until after the
** completion of the [sqlite3_step()] call that triggered the update hook.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
** ^The sqlite3_update_hook(D,C,P) function
** returns the P argument from the previous call
** on the same [database connection] D, or NULL for
** the first call on D.
**
** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
** and [sqlite3_preupdate_hook()] interfaces.
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unambiguous reference to a database column.
True if sqlite3_interrupt has been called
Validate index entries for the current row
Round nByte up to the next valid power of two
Writer context
** Callback for tokenizing terms used by ParseTerm().
Number of terms in the ORDER BY clause
comment: sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
**
** Set the VDBE coverage callback function to xCallback with context
** pointer ptr.
label: test
SELECT statement in which to make substitutions
ERROR: insert count exceeds size of delta
An automatic index created by a PRIMARY KEY or UNIQUE constraint
Used by: database_list
** Decrement the reference count on a vxworksFileId object. Free
** the object when the reference count reaches zero.
************* Begin file status.c *****************************************
If in full-sync mode, advance to the next disk sector before writing
** the master journal name. This is in case the previous page written to
** the journal has already been synced.
The maximum number of cells on a single page of the database. This
** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself
** plus 2 bytes for the index to the cell in the page header). Such
** small cells will be rare, but they are possible.
Index being probed
Information about each format field
Size of allocation used for *p
List to which to append. Might be NULL
8
String to quote, escape and append
xDeviceCapabilities
The write-ahead log
** Check to see if column iCol of the given statement is valid. If
** it is, return a pointer to the Mem for the value of that column.
** If iCol is not valid, return a pointer to a Mem which has a value
** of NULL.
******* End %stack_overflow code *******************************************
Try to truncate the WAL file to zero bytes if the checkpoint
** completed and fsynced (rc==SQLITE_OK) and we are in persistent
** WAL mode (bPersist) and if the PRAGMA journal_size_limit is a
** non-negative value (pWal->mxWalSize>=0). Note that we truncate
** to zero bytes as truncating to the journal_size_limit might
** leave a corrupt WAL file on disk.
True for statements that read
The specific comparison operator
Column on LHS of MATCH operator
Blob I/O on xxx_node
Before populating the accumulator registers, clear the column cache.
** Otherwise, if any of the required column values are already present
** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
** to pC->iMem. But by the time the value is used, the original register
** may have been used, invalidating the underlying buffer holding the
** text or blob value. See ticket [883034dcb5].
**
** Another solution would be to change the OP_SCopy used to copy cached
** values to an OP_Copy.
VIRTUAL => ID
710
175
Free any existing lookaside buffer for this handle before
** allocating a new one so we don't have to have space for
** both at the same time.
** This function is called to rollback or release (commit) a savepoint.
** The savepoint to release or rollback need not be the most recently
** created savepoint.
**
** Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE.
** If it is SAVEPOINT_RELEASE, then release and destroy the savepoint with
** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
** that have occurred since the specified savepoint was created.
**
** The savepoint to rollback or release is identified by parameter
** iSavepoint. A value of 0 means to operate on the outermost savepoint
** (the first created). A value of (Pager.nSavepoint-1) means operate
** on the most recently created savepoint. If iSavepoint is greater than
** (Pager.nSavepoint-1), then this function is a no-op.
**
** If a negative value is passed to this function, then the current
** transaction is rolled back. This is different to calling
** sqlite3PagerRollback() because this function does not terminate
** the transaction or unlock the database, it just restores the
** contents of the database to its original state.
**
** In any case, all savepoints with an index greater than iSavepoint
** are destroyed. If this is a release operation (op==SAVEPOINT_RELEASE),
** then savepoint iSavepoint is also destroyed.
**
** This function may return SQLITE_NOMEM if a memory allocation fails,
** or an IO error code if an IO error occurs while rolling back a
** savepoint. If no errors occur, SQLITE_OK is returned.
The table in which we should change things
comment:
** Extract the smallest element from the RowSet.
** Write the element into *pRowid. Return 1 on success. Return
** 0 if the RowSet is already empty.
**
** After this routine has been called, the sqlite3RowSetInsert()
** routine may not be called again.
**
** This routine may not be called after sqlite3RowSetTest() has
** been used. Older versions of RowSet allowed that, but as the
** capability was not used by the code generator, it was removed
** for code economy.
label: code-design
Restriction (6)
** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
** then edit any error message string so as to remove all occurrences of
** the pattern "rbu_imp_[0-9]*".
** Functions called by the storage module as part of integrity-check.
SHM region size
** A version of vdbeSorterCompare() that assumes that it has already been
** determined that the first field of key1 is equal to the first field of
** key2.
** This is common tail processing for btreeParseCellPtr() and
** btreeParseCellPtrIndex() for the case when the cell does not fit entirely
** on a single B-tree page. Make necessary adjustments to the CellInfo
** structure.
************* End of fts3_porter.c ****************************************
Array of rootpage numbers for tables to be checked
Figure out how much space to allocate
OUT: Pointer to doclist for pTerm
** Sort the elements in list aList using aContent[] as the sort key.
** Remove elements with duplicate keys, preferring to keep the
** larger aList[] values.
**
** The aList[] entries are indices into aContent[]. The values in
** aList[] are to be sorted so that for all J<K:
**
** aContent[aList[J]] < aContent[aList[K]]
**
** For any X and Y such that
**
** aContent[aList[X]] == aContent[aList[Y]]
**
** Keep the larger of the two values aList[X] and aList[Y] and discard
** the smaller.
** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
** suitable for comparing serialized records to the unpacked record passed
** as the only argument.
** Close a cache.
No other bits set
Selected leaf node
Number of segments that share a docid
If the file on disk is smaller than the database image, use
** pager_truncate to grow the file here. This can happen if the database
** image was extended as part of the current transaction and then the
** last page in the db image moved to the free-list. In this case the
** last page is never written out to disk, leaving the database file
** undersized. Fix this now if it is the case.
** 2010 February 23
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file implements routines used to report what compile-time options
** SQLite was built with.
Not currently locked
No user-visible "rowid" column
** If pMem is an object with a valid string representation, this routine
** ensures the internal encoding for the string representation is
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
**
** If pMem is not a string object, or the encoding of the string
** representation is already stored using the requested encoding, then this
** routine is a no-op.
**
** SQLITE_OK is returned if the conversion is successful (or not required).
** SQLITE_NOMEM may be returned if a malloc() fails during conversion
** between formats.
Name of the shared library containing extension
If we get this far, it means that the xfer optimization is at
** least a possibility, though it might only work if the destination
** table (tab1) is initially empty.
Swap the roles of aFrom and aTo for the next generation
The following code adds nothing to the actual functionality
** of the program. It is only here for testing and debugging.
** On the other hand, it does burn CPU cycles every time through
** the evaluator loop. So we can leave it out when NDEBUG is defined.
Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
** method that there may be extra parameters following the file-name.
comment:
** For MinGW, check to see if we can include the header file containing its
** version information, among other things. Normally, this internal MinGW
** header file would [only] be included automatically by other MinGW header
** files; however, the contained version information is now required by this
** header file to work around binary compatibility issues (see below) and
** this is the only known way to reliably obtain it. This entire #if block
** would be completely unnecessary if there was any other way of detecting
** MinGW via their preprocessor (e.g. if they customized their GCC to define
** some MinGW-specific macros). When compiling for MinGW, either the
** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be
** defined; otherwise, detection of conditions specific to MinGW will be
** disabled.
label: code-design
SQLITE_MAX_WORKER_THREADS>0
** unixepoch
**
** Treat the current value of p->s as the number of
** seconds since 1970. Convert to a real julian day number.
xRekey
Not an aggregate
If it is not already open and the file exists on disk, open the
** journal for read/write access. Write access is required because
** in exclusive-access mode the file descriptor will be kept open
** and possibly used for a transaction later on. Also, write-access
** is usually required to finalize the journal in journal_mode=persist
** mode (and also for journal_mode=truncate on some systems).
**
** If the journal does not exist, it usually means that some
** other connection managed to get in and roll it back before
** this connection obtained the exclusive lock above. Or, it
** may mean that the pager was in the error-state when this
** function was called and the journal file does not exist.
Set the value of register r[1] in the SQL statement to integer iRow.
** This is done directly as a performance optimization
Readr data from here after Rewind()
If the approximation iKey is smaller than the actual real search
** term, substitute <= for < and > for >=.
defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
The Index.aiColumn[] values are normally positive integer. But
** there are some negative values that have special meaning:
A user column. Or, if this is a full-table scan, possibly the
** language-id column. Seek the cursor.
True if sub-query is correlated
Each column used only once
***************** End of the dot-file lock implementation *******************
*****************************************************************************
OUT: VFS to use
** Generate an instruction that will put the floating point
** value described by z[0..n-1] into register iMem.
**
** The z[] string will probably not be zero-terminated. But the
** z[n] character is guaranteed to be something that does not look
** like the continuation of the number.
Set the JsonString object to an empty string
The OP_RowData opcodes always follow OP_NotExists or
** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
** that might invalidate the cursor.
** If this where not the case, on of the following assert()s
** would fail. Should this ever change (because of changes in the code
** generator) then the fix would be to insert a call to
** sqlite3VdbeCursorMoveto().
** Set the number of backtrace levels kept for each allocation.
** A value of zero turns off backtracing. The number is always rounded
** up to a multiple of 2.
Last memory cell in new array
** The argument is an Fts3Expr structure for a binary operator (any type
** except an FTSQUERY_PHRASE). Return an integer value representing the
** precedence of the operator. Lower values have a higher precedence (i.e.
** group more tightly). For example, in the C language, the == operator
** groups more tightly than ||, and would therefore have a higher precedence.
**
** When using the new fts3 query syntax (when SQLITE_ENABLE_FTS3_PARENTHESIS
** is defined), the order of the operators in precedence from highest to
** lowest is:
**
** NEAR
** NOT
** AND (including implicit ANDs)
** OR
**
** Note that when using the old query syntax, the OR operator has a higher
** precedence than the AND operator.
iTermLeafOffset may be equal to szLeaf if the term is the last
** thing on the page - i.e. the first rowid is on the following page.
** In this case leave pIter->pLeaf==0, this iterator is at EOF.
Estimated number of result rows
Do constraint checks.
Current side of the stack
** Given the nKey-byte encoding of a record in pKey[], populate the
** UnpackedRecord structure indicated by the fourth argument with the
** contents of the decoded record.
** The magic Explain opcode are only inserted when explain==2 (which
** is to say when the EXPLAIN QUERY PLAN syntax is used.)
** This opcode records information from the optimizer. It is the
** the same as a no-op. This opcodesnever appears in a real VM program.
** CAPI3REF: Constants Returned By The Conflict Handler
**
** A conflict handler callback must return one of the following three values.
**
** <dl>
** <dt>SQLITE_CHANGESET_OMIT<dd>
** If a conflict handler returns this value no special action is taken. The
** change that caused the conflict is not applied. The session module
** continues to the next change in the changeset.
**
** <dt>SQLITE_CHANGESET_REPLACE<dd>
** This value may only be returned if the second argument to the conflict
** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
** is not the case, any changes applied so far are rolled back and the
** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
**
** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
** handler, then the conflicting row is either updated or deleted, depending
** on the type of change.
**
** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
** handler, then the conflicting row is removed from the database and a
** second attempt to apply the change is made. If this second attempt fails,
** the original row is restored to the database before continuing.
**
** <dt>SQLITE_CHANGESET_ABORT<dd>
** If this value is returned, any changes applied so far are rolled back
** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
** </dl>
Code AFTER triggers
** The "unknown" function is automatically substituted in place of
** any unrecognized function name when doing an EXPLAIN or EXPLAIN QUERY PLAN
** when the SQLITE_ENABLE_UNKNOWN_FUNCTION compile-time option is used.
** When the "sqlite3" command-line shell is built using this functionality,
** that allows an EXPLAIN or EXPLAIN QUERY PLAN for complex queries
** involving application-defined functions to be examined in a generic
** sqlite3 shell.
The file descriptor
** Implementation of the abs() function.
**
** IMP: R-23979-26855 The abs(X) function returns the absolute value of
** the numeric argument X.
True for final fragment in snippet
Flags passed as 4th argument to xOpen()
Allocated size of aOverflow[] array
870
LIMIT counter
True if a header read failed
** Walk all expressions associated with SELECT statement p. Do
** not invoke the SELECT callback on p, but do (of course) invoke
** any expr callbacks and SELECT callbacks that come from subqueries.
** Return WRC_Abort or WRC_Continue.
The requested memory region does not exist. If isWrite is set to
** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
**
** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
** the requested memory region.
** Initialize a DbFixer structure. This routine must be called prior
** to passing the structure to one of the sqliteFixAAAA() routines below.
Rowid of final block in segment (or 0)
limit_opt ::= LIMIT expr COMMA expr
Name of the view, trigger, or index
Size of zLeTerm in bytes
Only called if really needed
82
comment:
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
** Otherwise, if the allocation at pBlob->a is not already at least nMin
** bytes in size, extend (realloc) it to be so.
**
** If an OOM error occurs, set *pRc to SQLITE_NOMEM and leave pBlob->a
** unmodified. Otherwise, if the allocation succeeds, update pBlob->nAlloc
** to reflect the new size of the pBlob->a[] buffer.
label: code-design
Mask of phrases covered by this snippet
** Schema of the terms table.
Table zTbl
Write the new IncrMerger here
** Handle type for pages.
Column to score
Omit error if index already exists
Attempt to omit tables from the join that do not effect the result
SQLITE_HASH_H
This routine never gets call with a positive pgno except right
** after sqlite3PcacheCleanAll(). So if there are dirty pages,
** it must be that pgno==0.
Rows visited by (pFrom+pWLoop)
"*" at the end of the pattern matches
Used to iterate through columns
Fts3Table
Skip pages already processed
Current index in output buffer
Length of key in bytes
Register holding return address of addrFillSub
Try to return memory used by the pcache module to the main memory heap
Otherwise, treat the ORDER BY term as an ordinary expression
Arguments for SQLITE_PRINTF_SQLFUNC
Destructor for BtShared.pSchema
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the sqlite B-Tree file
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
Must be compatible with this index
b: p1 (unmasked)
comment: This OP_Delete opcode fires the pre-update-hook only. It does
** not modify the b-tree. It is more efficient to let the coming
** OP_Insert replace the existing entry than it is to delete the
** existing entry and then insert a new one.
label: code-design
The user has issued a query of the form "MATCH '*...'". This
** indicates that the MATCH expression is not a full text query,
** but a request for an internal parameter.
Size of the Bitvec structure in bytes.
Propagate these bits up tree
Pointer to doclist of current entry
** Return a 32-bit hash of the page data for pPage.
Constraint handling. A write operation on an r-tree table may return
** SQLITE_CONSTRAINT for two reasons:
**
** 1. A duplicate rowid value, or
** 2. The supplied data violates the "x2>=x1" constraint.
**
** In the first case, if the conflict-handling mode is REPLACE, then
** the conflicting row can be removed before proceeding. In the second
** case, SQLITE_CONSTRAINT must be returned regardless of the
** conflict-handling mode specified by the user.
OUT: Size of record in bytes
** Expression pExpr must be of type FTSQUERY_PHRASE.
**
** If it is not already allocated and populated, this function allocates and
** populates the Fts3Expr.aMI[] array for expression pExpr. If pExpr is part
** of a NEAR expression, then it also allocates and populates the same array
** for all other phrases that are part of the NEAR expression.
**
** SQLITE_OK is returned if the aMI[] array is successfully allocated and
** populated. Otherwise, if an error occurs, an SQLite error code is returned.
comment: TODO(shess) This needs expansion to handle UTF-8
** case-insensitivity.
label: code-design
Template WhereLoop object
Number of entries in pPath->aLoop[]
Flags passed to sqlite3WhereBegin()
** Change the P5 operand on the last opcode (which should be an OP_MakeRecord)
** to be the number of columns in table pTab that must not be NULL-trimmed.
**
** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero.
Keying information for the group by clause
#include <time.h>
** Find a unique file ID for the given absolute pathname. Return
** a pointer to the vxworksFileId object. This pointer is the unique
** file ID.
**
** The nRef field of the vxworksFileId object is incremented before
** the object is returned. A new vxworksFileId object is created
** and added to the global list if necessary.
**
** If a memory allocation error occurs, return NULL.
** This routine generates VDBE code that causes the deletion of all
** index entries associated with a single row of a single table, pTab
**
** Preconditions:
**
** 1. A read/write cursor "iDataCur" must be open on the canonical storage
** btree for the table pTab. (This will be either the table itself
** for rowid tables or to the primary key index for WITHOUT ROWID
** tables.)
**
** 2. Read/write cursors for all indices of pTab must be open as
** cursor number iIdxCur+i for the i-th index. (The pTab->pIndex
** index is the 0-th index.)
**
** 3. The "iDataCur" cursor must be already be positioned on the row
** that is to be deleted.
Register all VFSes defined in the aVfs[] array
Database number
star_opt ::=
Finially, delete what is left of the subquery and return
** success.
Generate the subroutine return
Mask of cursor flags (see below)
we couldn't create the proxy lock file with the old lock file path
** so try again via auto-naming
Appending to an existing hash-entry. Check that there is enough
** space to append the largest possible new entry. Worst case scenario
** is:
**
** + 9 bytes for a new rowid,
** + 4 byte reserved for the "poslist size" varint.
** + 1 byte for a "new column" byte,
** + 3 bytes for a new column number (16-bit max) as a varint,
** + 5 bytes for the new position offset (32-bit max).
The ORDER BY and GROUP BY clauses may not refer to terms in
** outer queries
leaves_end_block
Do the rest of the initialization under the recursive mutex so
** that we will be able to handle recursive calls into
** sqlite3_initialize(). The recursive calls normally come through
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
** recursive calls might also be possible.
**
** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
** to the xInit method, so the xInit method need not be threadsafe.
**
** The following mutex is what serializes access to the appdef pcache xInit
** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
** call to sqlite3PcacheInitialize().
Load an unaligned and unsigned 32-bit integer
** Compare the contents of the pLeft buffer with the pRight/nRight blob.
**
** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
** +ve if pRight is smaller than pLeft. In other words:
**
** res = *pLeft - *pRight
***************************************************************************
*****************************************************************************
** Everything after this point is just test code.
OUT: uid of zFile.
Not the root node
Bitmap of additional columns
Obtain the average docsize (in pages).
** The various operations on open token or token prefix iterators opened
** using sqlite3Fts5IndexQuery().
** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
** return the number of unicode characters in pZ up to (but not including)
** the first 0x00 byte. If nByte is not less than zero, return the
** number of unicode characters in the first nByte of pZ (or up to
** the first 0x00, whichever comes first).
The first nOBSat columns of the previous row
Opcode: AggFinal P1 P2 * P4 *
** Synopsis: accum=r[P1] N=P2
**
** Execute the finalizer function for an aggregate. P1 is
** the memory location that is the accumulator for the aggregate.
**
** P2 is the number of arguments that the step function takes and
** P4 is a pointer to the FuncDef for this function. The P2
** argument is not used by this opcode. It is only there to disambiguate
** functions that can take varying numbers of arguments. The
** P4 argument is only needed for the degenerate case where
** the step function was not previously called.
1170
** Subterms pOne and pTwo are contained within WHERE clause pWC. The
** two subterms are in disjunction - they are OR-ed together.
**
** If these two terms are both of the form: "A op B" with the same
** A and B values but different operators and if the operators are
** compatible (if one is = and the other is <, for example) then
** add a new virtual AND term to pWC that is the combination of the
** two.
**
** Some examples:
**
** x<y OR x=y --> x<=y
** x=y OR x=y --> x=y
** x<=y OR x<y --> x<=y
**
** The following is NOT generated:
**
** x<y OR x>y --> x!=y
Containing WITH clause, or NULL
End if not an rowid index
** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
** the entire master journal file. The case pSavepoint==NULL occurs when
** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction
** savepoint.
**
** When pSavepoint is not NULL (meaning a non-transaction savepoint is
** being rolled back), then the rollback consists of up to three stages,
** performed in the order specified:
**
** * Pages are played back from the main journal starting at byte
** offset PagerSavepoint.iOffset and continuing to
** PagerSavepoint.iHdrOffset, or to the end of the main journal
** file if PagerSavepoint.iHdrOffset is zero.
**
** * If PagerSavepoint.iHdrOffset is not zero, then pages are played
** back starting from the journal header immediately following
** PagerSavepoint.iHdrOffset to the end of the main journal file.
**
** * Pages are then played back from the sub-journal file, starting
** with the PagerSavepoint.iSubRec and continuing to the end of
** the journal file.
**
** Throughout the rollback process, each time a page is rolled back, the
** corresponding bit is set in a bitvec structure (variable pDone in the
** implementation below). This is used to ensure that a page is only
** rolled back the first time it is encountered in either journal.
**
** If pSavepoint is NULL, then pages are only played back from the main
** journal file. There is no need for a bitvec in this case.
**
** In either case, before playback commences the Pager.dbSize variable
** is reset to the value that it held at the start of the savepoint
** (or transaction). No page with a page-number greater than this value
** is played back. If one is encountered it is simply skipped.
** Find the current time (in Universal Coordinated Time). Write into *piNow
** the current time and date as a Julian Day number times 86_400_000. In
** other words, write into *piNow the number of milliseconds since the Julian
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
** proleptic Gregorian calendar.
**
** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
** cannot be found.
** The winFile structure is a subclass of sqlite3_file* specific to the win32
** portability layer.
289
True if this is a VIEW
destructor for json_each virtual table
Add a WO_MATCH auxiliary term to the constraint set if the
** current expression is of the form: column MATCH expr.
** This information is used by the xBestIndex methods of
** virtual tables. The native query optimizer does not attempt
** to do anything with MATCH functions.
IN/OUT: Pointer to position list
** The pVal argument is known to be a value other than NULL.
** Convert it into a string with encoding enc and return a pointer
** to a zero-terminated version of that string.
comment: Malloc utility
label: code-design
comment: unused
label: code-design
** This routine deallocates a previously allocated mutex.
Do no locking
** Generate a CREATE TABLE statement appropriate for the given
** table. Memory to hold the text of the statement is obtained
** from sqliteMalloc() and must be freed by the calling function.
1180
** A sort order can be either ASC or DESC.
New cell to insert if nData>1
If non-NULL, store record pointer here
** Attempt to extract a value from pExpr and use it to construct *ppVal.
**
** If pAlloc is not NULL, then an UnpackedRecord object is created for
** pAlloc if one does not exist and the new value is added to the
** UnpackedRecord object.
**
** A value is extracted in the following cases:
**
** * (pExpr==0). In this case the value is assumed to be an SQL NULL,
**
** * The expression is a bound variable, and this is a reprepare, or
**
** * The expression is a literal value.
**
** On success, *ppVal is made to point to the extracted value. The caller
** is responsible for ensuring that the value is eventually freed.
* Calculate the maximum legal cache size, in pages, based on the maximum
* possible initial heap size and the default page size, setting aside the
* needed extra space.
Binary operator
Trace sqlite3VdbeAddOp() calls
Return the current rowid value
Combines with pBt->pPager->iDataVersion
If we have not already resolved the name, then maybe
** it is a new.* or old.* trigger argument reference
comment:
** The following two macros are used internally. They are similar to the
** sqlite3changeset_new() and sqlite3changeset_old() functions, except that
** they omit all error checking and return a pointer to the requested value.
label: code-design
!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
aIndex
Database page number for frame
The underlying unixShmNode object
** 2011 Jan 27
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
The sqlite3GetBoolean() function is used by other modules but the
** remainder of this file is specific to PRAGMA processing. So omit
** the rest of the file if PRAGMAs are omitted from the build.
Varint that may be written to pOut
Number of outputs for this subquery
Hint blob to append to
For scanning through pCell
A "NOT INDEXED" clause was supplied. See parse.y
** construct "indexed_opt" for details.
** Extract the user data from a sqlite3_context structure and return a
** pointer to it.
**
** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
** returns a copy of the pointer to the database connection (the 1st
** parameter) of the sqlite3_create_function() and
** sqlite3_create_function16() routines that originally registered the
** application defined function.
** Close a file.
190
The virtual machine being built up
The letter 'x', or start of BLOB literal
OPTIMIZATION-IF-TRUE
Append JSON content here
comment:
** This routine redistributes cells on the iParentIdx'th child of pParent
** (hereafter "the page") and up to 2 siblings so that all pages have about the
** same amount of free space. Usually a single sibling on either side of the
** page are used in the balancing, though both siblings might come from one
** side if the page is the first or last child of its parent. If the page
** has fewer than 2 siblings (something which can only happen if the page
** is a root page or a child of a root page) then all available siblings
** participate in the balancing.
**
** The number of siblings of the page might be increased or decreased by
** one or two in an effort to keep pages nearly full but not over full.
**
** Note that when this routine is called, some of the cells on the page
** might not actually be stored in MemPage.aData[]. This can happen
** if the page is overfull. This routine ensures that all cells allocated
** to the page and its siblings fit into MemPage.aData[] before returning.
**
** In the course of balancing the page and its siblings, cells may be
** inserted into or removed from the parent page (pParent). Doing so
** may cause the parent page to become overfull or underfull. If this
** happens, it is the responsibility of the caller to invoke the correct
** balancing routine to fix this problem (see the balance() routine).
**
** If this routine fails for any reason, it might leave the database
** in a corrupted state. So if this routine fails, the database should
** be rolled back.
**
** The third argument to this function, aOvflSpace, is a pointer to a
** buffer big enough to hold one page. If while inserting cells into the parent
** page (pParent) the parent page becomes overfull, this buffer is
** used to store the parent's overflow cells. Because this function inserts
** a maximum of four divider cells into the parent page, and the maximum
** size of a cell stored within an internal node is always less than 1/4
** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
** enough for all overflow cells.
**
** If aOvflSpace is set to a null pointer, this function returns
** SQLITE_NOMEM.
label: code-design
If non-NULL, write serialized value here
p2 is smaller
Create transient tab and store like SRT_Table
comment:
** Return the number of bytes of space at the end of every page that
** are intentually left unused. This is the "reserved" space that is
** sometimes used by extensions.
**
** If SQLITE_HAS_MUTEX is defined then the number returned is the
** greater of the current reserved space and the maximum requested
** reserve space.
label: code-design
xGeom and xQueryFunc argument
we can skip these cause they were (effectively) done above in calc'ing s
Skip backwards passed any trailing 0x00 bytes added by NearTrim()
Page number of the new child page
Count rows changed by INSERT,
The token itself
Best snippet score found so far
append the "-conch" suffix to the file
The count-of-view optimization
Result of comparison operation
All duplicates are adjacent
If using separate RBU and state databases, attach the state database to
** the RBU db handle now.
Offset in zDoc of start of token
** 2006 July 10
**
** The author disclaims copyright to this source code.
**
*************************************************************************
** Defines the interface to tokenizers used by fulltext-search. There
** are three basic components:
**
** sqlite3_tokenizer_module is a singleton defining the tokenizer
** interface functions. This is essentially the class structure for
** tokenizers.
**
** sqlite3_tokenizer is used to define a particular tokenizer, perhaps
** including customization information defined at creation time.
**
** sqlite3_tokenizer_cursor is generated by a tokenizer to generate
** tokens from a particular input.
Cursors in the equivalence class
2 NORMAL:
comment:
** This is part of the fts5_decode() debugging aid.
**
** Arguments pBlob/nBlob contain a serialized Fts5Structure object. This
** function appends a human-readable representation of the same object
** to the buffer passed as the second argument.
label: code-design
** Write a 64-bit variable-length integer to memory starting at p[0].
** The length of data write will be between 1 and 9 bytes. The number
** of bytes written is returned.
**
** A variable-length integer consists of the lower 7 bits of each byte
** for all bytes that have the 8th bit set and one byte with the 8th
** bit clear. Except, if we get to the 9th byte, it stores the full
** 8 bits and is the last byte.
FTS3 Cursor object
OUT: Dlidx flag
True to fail localtime() calls
ASC or DESC on the i-th expression
EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
** in the SQLITE_CHECKPOINT_PASSIVE mode.
I/O error: lastErrno set by seekAndRead
CTIME_KW => ID
328
** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
**
** Checkpoint the database.
Size of buffer at a[] in bytes
Check if there were any options specified that should be interpreted
** here. Options that are interpreted here include "vfs" and those that
** correspond to flags that may be passed to the sqlite3_open_v2()
** method.
Verify the affinity and collating sequence match
True to sort in descending order
Open an ephemeral index to use for the distinct set.
comment:
** EXTENSION API FUNCTIONS
**
** xUserData(pFts):
** Return a copy of the context pointer the extension function was
** registered with.
**
** xColumnTotalSize(pFts, iCol, pnToken):
** If parameter iCol is less than zero, set output variable *pnToken
** to the total number of tokens in the FTS5 table. Or, if iCol is
** non-negative but less than the number of columns in the table, return
** the total number of tokens in column iCol, considering all rows in
** the FTS5 table.
**
** If parameter iCol is greater than or equal to the number of columns
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
** an OOM condition or IO error), an appropriate SQLite error code is
** returned.
**
** xColumnCount(pFts):
** Return the number of columns in the table.
**
** xColumnSize(pFts, iCol, pnToken):
** If parameter iCol is less than zero, set output variable *pnToken
** to the total number of tokens in the current row. Or, if iCol is
** non-negative but less than the number of columns in the table, set
** *pnToken to the number of tokens in column iCol of the current row.
**
** If parameter iCol is greater than or equal to the number of columns
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
** an OOM condition or IO error), an appropriate SQLite error code is
** returned.
**
** This function may be quite inefficient if used with an FTS5 table
** created with the "columnsize=0" option.
**
** xColumnText:
** This function attempts to retrieve the text of column iCol of the
** current document. If successful, (*pz) is set to point to a buffer
** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
** if an error occurs, an SQLite error code is returned and the final values
** of (*pz) and (*pn) are undefined.
**
** xPhraseCount:
** Returns the number of phrases in the current query expression.
**
** xPhraseSize:
** Returns the number of tokens in phrase iPhrase of the query. Phrases
** are numbered starting from zero.
**
** xInstCount:
** Set *pnInst to the total number of occurrences of all phrases within
** the query within the current row. Return SQLITE_OK if successful, or
** an error code (i.e. SQLITE_NOMEM) if an error occurs.
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option. If the FTS5 table is created
** with either "detail=none" or "detail=column" and "content=" option
** (i.e. if it is a contentless table), then this API always returns 0.
**
** xInst:
** Query for the details of phrase match iIdx within the current row.
** Phrase matches are numbered starting from zero, so the iIdx argument
** should be greater than or equal to zero and smaller than the value
** output by xInstCount().
**
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
** to the column in which it occurs and *piOff the token offset of the
** first token of the phrase. The exception is if the table was created
** with the offsets=0 option specified. In this case *piOff is always
** set to -1.
**
** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
** if an error occurs.
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option.
**
** xRowid:
** Returns the rowid of the current row.
**
** xTokenize:
** Tokenize text using the tokenizer belonging to the FTS5 table.
**
** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
** This API function is used to query the FTS table for phrase iPhrase
** of the current query. Specifically, a query equivalent to:
**
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
**
** with $p set to a phrase equivalent to the phrase iPhrase of the
** current query is executed. Any column filter that applies to
** phrase iPhrase of the current query is included in $p. For each
** row visited, the callback function passed as the fourth argument
** is invoked. The context and API objects passed to the callback
** function may be used to access the properties of each matched row.
** Invoking Api.xUserData() returns a copy of the pointer passed as
** the third argument to pUserData.
**
** If the callback function returns any value other than SQLITE_OK, the
** query is abandoned and the xQueryPhrase function returns immediately.
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
** Otherwise, the error code is propagated upwards.
**
** If the query runs to completion without incident, SQLITE_OK is returned.
** Or, if some error occurs before the query completes or is aborted by
** the callback, an SQLite error code is returned.
**
**
** xSetAuxdata(pFts5, pAux, xDelete)
**
** Save the pointer passed as the second argument as the extension functions
** "auxiliary data". The pointer may then be retrieved by the current or any
** future invocation of the same fts5 extension function made as part of
** of the same MATCH query using the xGetAuxdata() API.
**
** Each extension function is allocated a single auxiliary data slot for
** each FTS query (MATCH expression). If the extension function is invoked
** more than once for a single FTS query, then all invocations share a
** single auxiliary data context.
**
** If there is already an auxiliary data pointer when this function is
** invoked, then it is replaced by the new pointer. If an xDelete callback
** was specified along with the original pointer, it is invoked at this
** point.
**
** The xDelete callback, if one is specified, is also invoked on the
** auxiliary data pointer after the FTS5 query has finished.
**
** If an error (e.g. an OOM condition) occurs within this function, an
** the auxiliary data is set to NULL and an error code returned. If the
** xDelete parameter was not NULL, it is invoked on the auxiliary data
** pointer before returning.
**
**
** xGetAuxdata(pFts5, bClear)
**
** Returns the current auxiliary data pointer for the fts5 extension
** function. See the xSetAuxdata() method for details.
**
** If the bClear argument is non-zero, then the auxiliary data is cleared
** (set to NULL) before this function returns. In this case the xDelete,
** if any, is not invoked.
**
**
** xRowCount(pFts5, pnRow)
**
** This function is used to retrieve the total number of rows in the table.
** In other words, the same value that would be returned by:
**
** SELECT count(*) FROM ftstable;
**
** xPhraseFirst()
** This function is used, along with type Fts5PhraseIter and the xPhraseNext
** method, to iterate through all instances of a single query phrase within
** the current row. This is the same information as is accessible via the
** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
** to use, this API may be faster under some circumstances. To iterate
** through instances of phrase iPhrase, use the following code:
**
** Fts5PhraseIter iter;
** int iCol, iOff;
** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
** iCol>=0;
** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
** ){
** // An instance of phrase iPhrase at offset iOff of column iCol
** }
**
** The Fts5PhraseIter structure is defined above. Applications should not
** modify this structure directly - it should only be used as shown above
** with the xPhraseFirst() and xPhraseNext() API methods (and by
** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option. If the FTS5 table is created
** with either "detail=none" or "detail=column" and "content=" option
** (i.e. if it is a contentless table), then this API always iterates
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
**
** xPhraseNext()
** See xPhraseFirst above.
**
** xPhraseFirstColumn()
** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
** and xPhraseNext() APIs described above. The difference is that instead
** of iterating through all instances of a phrase in the current row, these
** APIs are used to iterate through the set of columns in the current row
** that contain one or more instances of a specified phrase. For example:
**
** Fts5PhraseIter iter;
** int iCol;
** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
** iCol>=0;
** pApi->xPhraseNextColumn(pFts, &iter, &iCol)
** ){
** // Column iCol contains at least one instance of phrase iPhrase
** }
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" option. If the FTS5 table is created with either
** "detail=none" "content=" option (i.e. if it is a contentless table),
** then this API always iterates through an empty set (all calls to
** xPhraseFirstColumn() set iCol to -1).
**
** The information accessed using this API and its companion
** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
** (or xInst/xInstCount). The chief advantage of this API is that it is
** significantly more efficient than those alternatives when used with
** "detail=column" tables.
**
** xPhraseNextColumn()
** See xPhraseFirstColumn above.
label: code-design
A WO_xx value describing <op>
defer_subclause_opt ::=
SELECT may not have a WHERE clause
** Return the pathname of the journal file for this database. The return
** value of this routine is the same regardless of whether the journal file
** has been created or not.
**
** The pager journal filename is invariant as long as the pager is
** open so it is safe to access without the BtShared mutex.
** Prototypes for the VDBE interface. See comments on the implementation
** for a description of what each of these routines does.
650
Name context to resolve expressions in
203
comment:
** All of the static variables used by this module are collected
** into a single structure named "mem5". This is to keep the
** static variables organized and to reduce namespace pollution
** when this module is combined with other in the amalgamation.
label: code-design
12
Collation sequence name
Lock offset to lock for checkpoint
Allowed values for second argument to pcacheManageDirtyList()
Original I/O methods for close
** Deinitialize this module.
Opcode: ShiftRight P1 P2 P3 * *
** Synopsis: r[P3]=r[P2]>>r[P1]
**
** Shift the integer value in register P2 to the right by the
** number of bits specified by the integer in register P1.
** Store the result in register P3.
** If either input is NULL, the result is NULL.
Do no file locking
First search for a match amongst the application-defined functions.
wqlist ::= nm eidlist_opt AS LP select RP
** Undo the effects of sqlite3_initialize(). Must not be called while
** there are outstanding database connections or memory allocations or
** while any part of SQLite is otherwise in use in any thread. This
** routine is not threadsafe. But it is safe to invoke this routine
** on when SQLite is already shut down. If SQLite is already shut down
** when this routine is invoked, then this routine is a harmless no-op.
8-byte signed integer
The table to be opened
Name of the journal file
** Compute the iLimit and iOffset fields of the SELECT based on the
** pLimit and pOffset expressions. pLimit and pOffset hold the expressions
** that appear in the original SQL statement after the LIMIT and OFFSET
** keywords. Or NULL if those keywords are omitted. iLimit and iOffset
** are the integer memory register numbers for counters used to compute
** the limit and offset. If there is no limit and/or offset, then
** iLimit and iOffset are negative.
**
** This routine changes the values of iLimit and iOffset only if
** a limit or offset is defined by pLimit and pOffset. iLimit and
** iOffset should have been preset to appropriate default values (zero)
** prior to calling this routine.
**
** The iOffset register (if it exists) is initialized to the value
** of the OFFSET. The iLimit register is initialized to LIMIT. Register
** iOffset+1 is initialized to LIMIT+OFFSET.
**
** Only if pLimit!=0 or pOffset!=0 do the limit registers get
** redefined. The UNION ALL operator uses this property to force
** the reuse of the same limit and offset registers across multiple
** SELECT statements.
** If the Vdbe passed as the first argument opened a statement-transaction,
** close it now. Argument eOp must be either SAVEPOINT_ROLLBACK or
** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement
** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
** statement transaction is committed.
**
** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
** Otherwise SQLITE_OK.
True if cache is purgeable
Variables below this point are populated by fts3_expr.c when parsing
** a MATCH expression. Everything above is part of the evaluation phase.
** Write nData bytes of data to the PMA. Return SQLITE_OK
** if successful, or an SQLite error code if an error occurs.
Check if the current doclist ends on this page. If it does, return
** early without loading the doclist-index (as it belongs to a different
** term.
Counter incremented each transaction
The number of pcache slots
****************************************************************************
** What follows is a massive switch statement where each case implements a
** separate instruction in the virtual machine. If we follow the usual
** indentation conventions, each case should be indented by 6 spaces. But
** that is a lot of wasted space on the left margin. So the code within
** the switch statement will break with convention and be flush-left. Another
** big comment (similar to this one) will mark the point in the code where
** we transition back to normal indentation.
**
** The formatting of each case is important. The makefile for SQLite
** generates two C files "opcodes.h" and "opcodes.c" by scanning this
** file looking for lines that begin with "case OP_". The opcodes.h files
** will be filled with #defines that give unique integer values to each
** opcode and the opcodes.c file is filled with an array of strings where
** each string is the symbolic name for the corresponding opcode. If the
** case statement is followed by a comment of the form "/# same as ... #/"
** that comment is used to determine the particular value of the opcode.
**
** Other keywords in the comment that follows each case are used to
** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
** Keywords include: in1, in2, in3, out2, out3. See
** the mkopcodeh.awk script for additional information.
**
** Documentation about VDBE opcodes is generated by scanning this file
** for lines of that contain "Opcode:". That line and all subsequent
** comment lines are used in the generation of the opcode.html documentation
** file.
**
** SUMMARY:
**
** Formatting is important to scripts that scan this file.
** Do not deviate from the formatting style currently in use.
**
****************************************************************************
Number used to identify the index
Initialize the name-context
Begin writing at this offset into the file
cmd ::= PRAGMA nm dbnm
comment: If the payload will not fit completely on the local page, we have
** to decide how much to store locally and how much to spill onto
** overflow pages. The strategy is to minimize the amount of unused
** space on overflow pages while keeping the amount of local storage
** in between minLocal and maxLocal.
**
** Warning: changing the way overflow payload is distributed in any
** way will result in an incompatible file format.
label: code-design
Phrase number (numbered from zero)
First part of [schema.]id field
Initialize the locking parameters
Mutex used to control access to shared lock
Right key
mem(P3) holds an integer
If an existing TriggerPrg could not be located, create a new one.
** Compare two blobs. Return negative, zero, or positive if the first
** is less than, equal to, or greater than the second, respectively.
** If one blob is a prefix of the other, then the shorter is the lessor.
** Memory map or remap the file opened by file-descriptor pFd (if the file
** is already mapped, the existing mapping is replaced by the new). Or, if
** there already exists a mapping for this file, and there are still
** outstanding xFetch() references to it, this function is a no-op.
**
** If parameter nByte is non-negative, then it is the requested size of
** the mapping to create. Otherwise, if nByte is less than zero, then the
** requested size is the size of the file on disk. The actual size of the
** created mapping is either the requested size or the value configured
** using SQLITE_FCNTL_MMAP_SIZE, whichever is smaller.
**
** SQLITE_OK is returned if no error occurs (even if the mapping is not
** recreated as a result of outstanding references) or an SQLite error
** code otherwise.
comment:
** Execute a rollback if a transaction is active and unlock the
** database file.
**
** If the pager has already entered the ERROR state, do not attempt
** the rollback at this time. Instead, pager_unlock() is called. The
** call to pager_unlock() will discard all in-memory pages, unlock
** the database file and move the pager back to OPEN state. If this
** means that there is a hot-journal left in the file-system, the next
** connection to obtain a shared lock on the pager (which may be this one)
** will roll it back.
**
** If the pager has not already entered the ERROR state, but an IO or
** malloc error occurs during a rollback, then this will itself cause
** the pager to enter the ERROR state. Which will be cleared by the
** call to pager_unlock(), as described above.
label: code-design
comment: Bytes to copy from previous term
label: code-design
Level of %_segdir entries to delete
Flags passed to sqlite3_vfs.xOpen()
OP_Delete/Insert: save cursor pos
The next group of variables are used to track whether or not the
** transaction counter in bytes 24-27 of database files are updated
** whenever any part of the database changes. An assertion fault will
** occur if a file is updated without also updating the transaction
** counter. This test is made to avoid new problems similar to the
** one described by ticket #3584.
True if rerunning after an auto-reprepare
220
The database index in sqlite3.aDb[]
How to compare records
Read-only page is acceptable
Built-in length() function
Flags. See WINFILE_* below
Values loaded from the %_config table
This VDBE program seeks a btree cursor to the identified
** db/table/row entry. The reason for using a vdbe program instead
** of writing code to use the b-tree layer directly is that the
** vdbe program will take advantage of the various transaction,
** locking and error handling infrastructure built into the vdbe.
**
** After seeking the cursor, the vdbe executes an OP_ResultRow.
** Code external to the Vdbe then "borrows" the b-tree cursor and
** uses it to implement the blob_read(), blob_write() and
** blob_bytes() functions.
**
** The sqlite3_blob_close() function finalizes the vdbe program,
** which closes the b-tree cursor and (possibly) commits the
** transaction.
The mutex type
Lastest rowid any iterator points to
True if token ends with a "*" character
If pTab is a virtual table, call ViewGetColumnNames() to ensure
** it is initialized.
** The second argument passed to this function may be NULL, or it may be
** an existing Fts5Colset object. This function returns a pointer to
** a new colset object containing the contents of (p) with new value column
** number iCol appended.
**
** If an OOM error occurs, store an error code in pParse and return NULL.
** The old colset object (if any) is not freed in this case.
Create the rootpage for the index using CreateIndex. But before
** doing so, code a Noop instruction and store its address in
** Index.tnum. This is required in case this index is actually a
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
** that case the convertToWithoutRowidTable() routine will replace
** the Noop with a Goto to jump over the VDBE code generated below.
Maximum amount of payload held locally
** Allocate and return an Fts5Colset object specifying the inverse of
** the colset passed as the second argument. Free the colset passed
** as the second argument before returning.
** The backtrace functionality is only available with GLIBC
** Indicate that sqlite3ParserFree() will never be called with a null
** pointer.
REAL
Used by OP_Delete
** Put the DateTime object into its error state.
Bitmask of phrases covered by snippet
Location in parent of right-sibling pointer
The parser context
** Return the current journal mode.
comment: Byte of unused space on each page
label: code-design
262
** This function attempts to transform the expression tree at (*pp) to
** an equivalent but more balanced form. The tree is modified in place.
** If successful, SQLITE_OK is returned and (*pp) set to point to the
** new root expression node.
**
** nMaxDepth is the maximum allowable depth of the balanced sub-tree.
**
** Otherwise, if an error occurs, an SQLite error code is returned and
** expression (*pp) freed.
first page on free list trunk
This mutex is needed because pFile->pInode is shared across threads
Address of the A==B subroutine
Wanting an exclusive lock?
comment: Call to try to make pages clean
label: code-design
** Free a dynamic mutex.
** If there are no outstanding cursors and we are not in the middle
** of a transaction but there is a read lock on the database, then
** this routine unrefs the first page of the database file which
** has the effect of releasing the read lock.
**
** If there is a transaction in progress, this routine is a no-op.
NULL
Next object in linked list
Add the current term to the interior node tree. The term added to
** the interior tree must:
**
** a) be greater than the largest term on the leaf node just written
** to the database (still available in pWriter->zTerm), and
**
** b) be less than or equal to the term about to be added to the new
** leaf node (zTerm/nTerm).
**
** In other words, it must be the prefix of zTerm 1 byte longer than
** the common prefix (if any) of zTerm and pWriter->zTerm.
** This function is used to iterate backwards (from the end to start)
** through doclists. It is used by this module to iterate through phrase
** doclists in reverse and by the fts3_write.c module to iterate through
** pending-terms lists when writing to databases with "order=desc".
**
** The doclist may be sorted in ascending (parameter bDescIdx==0) or
** descending (parameter bDescIdx==1) order of docid. Regardless, this
** function iterates from the end of the doclist to the beginning.
OOM detected prior to this routine
OUT: Number of columns in table
Write the page out to disk
There is a quirk here. The users INSERT statement may have specified
** a value for the "rowid" field, for the "docid" field, or for both.
** Which is a problem, since "rowid" and "docid" are aliases for the
** same value. For example:
**
** INSERT INTO fts3tbl(rowid, docid) VALUES(1, 2);
**
** In FTS3, this is an error. It is an error to specify non-NULL values
** for both docid and some other rowid alias.
True if constraints are supported
Invalid name?
** Create a new JsonNode instance based on the arguments and append that
** instance to the JsonParse. Return the index in pParse->aNode[] of the
** new node, or -1 if a memory allocation fails.
32-bit is the default
don't break the lock on short read or a version mismatch
Flags to pass to mmap()
Scan past delimiter characters
** Convert a Microsoft Unicode string to a multi-byte character string,
** using the ANSI or OEM code page.
**
** Space to hold the returned string is obtained from sqlite3_malloc().
If the handle had any kind of transaction open, decrement the
** transaction count of the shared btree. If the transaction count
** reaches 0, set the shared state to TRANS_NONE. The unlockBtreeIfUnused()
** call below will unlock the pager.
Append the pgidx to the page buffer. Set the szLeaf header field.
TODO1: Fix this
Destroy an sqlite3_value object previously obtained from
** sqlite3_value_dup().
Reset the checkpoint-header. This is safe because this thread is
** currently holding locks that exclude all other readers, writers and
** checkpointers.
Size of buffer pOut in bytes
56
Prevent ON clause terms of a LEFT JOIN from being used to drive
** an index for tables to the left of the join.
One side is a column, the other is not. Use the columns affinity.
Assert that the caller has opened the required transaction.
Page number corresponding to btterm
Pointer to the "extra" space
A long-standing parser bug is that this syntax was allowed:
**
** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
** ^^^^^^^^
**
** To maintain backwards compatibility, ignore the database
** name on pTableName if we are reparsing out of SQLITE_MASTER.
Execute the statement to insert the record. Set *piDocid to the
** new docid value.
Cache of doclist for this phrase.
Task context
True if a lookup of a single entry.
A transaction must be open when this is called.
** Argument pVector points to a vector expression - either a TK_VECTOR
** or TK_SELECT that returns more than one column. This function returns
** the register number of a register that contains the value of
** element iField of the vector.
**
** If pVector is a TK_SELECT expression, then code for it must have
** already been generated using the exprCodeSubselect() routine. In this
** case parameter regSelect should be the first in an array of registers
** containing the results of the sub-select.
**
** If pVector is of type TK_VECTOR, then code for the requested field
** is generated. In this case (*pRegFree) may be set to the number of
** a temporary register to be freed by the caller before returning.
**
** Before returning, output parameter (*ppExpr) is set to point to the
** Expr object corresponding to element iElem of the vector.
bLocaltimeFault
FTS3 table
** End of interface to code in fts5_tokenizer.c.
*************************************************************************
comment: If control flows to this point, this must be a regular token, or
** the end of the input. Read a regular token using the sqlite3_tokenizer
** interface. Before doing so, figure out if there is an explicit
** column specifier for the token.
**
** TODO: Strangely, it is not possible to associate a column specifier
** with a quoted phrase, only with a single token. Not sure if this was
** an implementation artifact or an intentional decision when fts3 was
** first implemented. Whichever it was, this module duplicates the
** limitation.
label: code-design
comment: Query flattening in sqlite3Select() might refill p->pOrderBy.
** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak.
label: code-design
Total overflow pages used by doclists
** A function that loads a shared-library extension then returns NULL.
Options
If the current leaf page is full, flush it to disk.
** Allocate an RbuState object and load the contents of the rbu_state
** table into it. Return a pointer to the new object. It is the
** responsibility of the caller to eventually free the object using
** sqlite3_free().
**
** If an error occurs, leave an error code and message in the rbu handle
** and return NULL.
Sync the database file to disk.
If mapping failed, close the shared memory handle and erase it
Probe for stat4 (if required)
Collect 'global' stats as well as local
aPgno[] index of page number to use
184
(3)
Check that the list really is sorted now.
************* End of memjournal.c *****************************************
Preallocated space for the PCache
Conflict resolution strategy
Only one recursive reference is permitted.
Rendering buffer
261
The largest iLevel value in the tree
WHEN clause
Already in locking_mode=NORMAL
The only reason to read this page is to obtain the page
** number for the next page in the overflow chain. The page
** data is not required. So first try to lookup the overflow
** page-list cache, if any, then fall back to the getOverflowPage()
** function.
10
Non-zero if in an error state
290
Linear scan of %_content table
synopsis: r[P2]=P4 (len=P1)
** Bind the PRIMARY KEY values from the change passed in argument pChange
** to the SELECT statement passed as the first argument. The SELECT statement
** is as prepared by function sessionSelectStmt().
**
** Return SQLITE_OK if all PK values are successfully bound, or an SQLite
** error code (e.g. SQLITE_NOMEM) otherwise.
Number of entries in aInLoop[]
The cksum argument passed to this function is a checksum calculated
** based on all expected entries in the FTS index (including prefix index
** entries). This block checks that a checksum calculated based on the
** actual contents of FTS index is identical.
**
** Two versions of the same checksum are calculated. The first (stack
** variable cksum2) based on entries extracted from the full-text index
** while doing a linear scan of each individual index in turn.
**
** As each term visited by the linear scans, a separate query for the
** same term is performed. cksum3 is calculated based on the entries
** extracted by these queries.
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
** [prepared statement] S has been stepped at least once using
** [sqlite3_step(S)] but has neither run to completion (returned
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
** interface returns false if S is a NULL pointer. If S is not a
** NULL pointer and is not a pointer to a valid [prepared statement]
** object, then the behavior is undefined and probably undesirable.
**
** This interface can be used in combination [sqlite3_next_stmt()]
** to locate all prepared statements associated with a database
** connection that are in need of being reset. This can be used,
** for example, in diagnostic routines to search for prepared
** statements that are holding a transaction open.
** Return true if the argument interpreted as a unicode codepoint
** is a diacritical modifier character.
e8..ef ........
The underlying mmapped file
State used by the fts5DataXXX() functions.
If creating a temp table, the name may not be qualified. Unless
** the database name is "temp" anyway.
Get a list of all dirty pages in the cache, sorted by page number
** Remove the i-th cell from pPage. This routine effects pPage only.
** The cell content is not freed or deallocated. It is assumed that
** the cell content has been copied someplace else. This routine just
** removes the reference to the cell from pPage.
**
** "sz" must be the number of bytes in the cell.
The "subtype" set for JSON values
** Rtree virtual table module xClose method.
Allow infinite precision
Number of characters in string value, excluding '\0'
Size of zName and its \0 terminator
One of OE_None, OE_Cascade etc.
Wildcard of the form "?nnn". Convert "nnn" to an integer and
** use it as the variable number
** An instance of the following structure is used by the tree walker
** to count references to table columns in the arguments of an
** aggregate function, in order to implement the
** sqlite3FunctionThisSrc() routine.
EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
** twos-complement integer.
comment:
** Attempt to start a read transaction. This might fail due to a race or
** other transient condition. When that happens, it returns WAL_RETRY to
** indicate to the caller that it is safe to retry immediately.
**
** On success return SQLITE_OK. On a permanent failure (such an
** I/O error or an SQLITE_BUSY because another process is running
** recovery) return a positive error code.
**
** The useWal parameter is true to force the use of the WAL and disable
** the case where the WAL is bypassed because it has been completely
** checkpointed. If useWal==0 then this routine calls walIndexReadHdr()
** to make a copy of the wal-index header into pWal->hdr. If the
** wal-index header has changed, *pChanged is set to 1 (as an indication
** to the caller that the local paget cache is obsolete and needs to be
** flushed.) When useWal==1, the wal-index header is assumed to already
** be loaded and the pChanged parameter is unused.
**
** The caller must set the cnt parameter to the number of prior calls to
** this routine during the current read attempt that returned WAL_RETRY.
** This routine will start taking more aggressive measures to clear the
** race conditions after multiple WAL_RETRY returns, and after an excessive
** number of errors will ultimately return SQLITE_PROTOCOL. The
** SQLITE_PROTOCOL return indicates that some other process has gone rogue
** and is not honoring the locking protocol. There is a vanishingly small
** chance that SQLITE_PROTOCOL could be returned because of a run of really
** bad luck when there is lots of contention for the wal-index, but that
** possibility is so small that it can be safely neglected, we believe.
**
** On success, this routine obtains a read lock on
** WAL_READ_LOCK(pWal->readLock). The pWal->readLock integer is
** in the range 0 <= pWal->readLock < WAL_NREADER. If pWal->readLock==(-1)
** that means the Wal does not hold any read lock. The reader must not
** access any database page that is modified by a WAL frame up to and
** including frame number aReadMark[pWal->readLock]. The reader will
** use WAL frames up to and including pWal->hdr.mxFrame if pWal->readLock>0
** Or if pWal->readLock==0, then the reader will ignore the WAL
** completely and get all content directly from the database file.
** If the useWal parameter is 1 then the WAL will never be ignored and
** this routine will always set pWal->readLock>0 on success.
** When the read transaction is completed, the caller must release the
** lock on WAL_READ_LOCK(pWal->readLock) and set pWal->readLock to -1.
**
** This routine uses the nBackfill and aReadMark[] fields of the header
** to select a particular WAL_READ_LOCK() that strives to let the
** checkpoint process do as much work as possible. This routine might
** update values of the aReadMark[] array in the header, but if it does
** so it takes care to hold an exclusive lock on the corresponding
** WAL_READ_LOCK() while changing values.
label: code-design
** Add an OP_ParseSchema opcode. This routine is broken out from
** sqlite3VdbeAddOp4() since it needs to also needs to mark all btrees
** as having been used.
**
** The zWhere string must have been obtained from sqlite3_malloc().
** This routine will take ownership of the allocated memory.
If this is a deferred FK constraint, or a CASCADE or SET NULL
** action applies, then any foreign key violations caused by
** removing the parent key will be rectified by the action trigger.
** So do not set the "may-abort" flag in this case.
**
** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
** may-abort flag will eventually be set on this statement anyway
** (when this function is called as part of processing the UPDATE
** within the action trigger).
**
** Note 2: At first glance it may seem like SQLite could simply omit
** all OP_FkCounter related scans when either CASCADE or SET NULL
** applies. The trouble starts if the CASCADE or SET NULL action
** trigger causes other triggers or action rules attached to the
** child table to fire. In these cases the fk constraint counters
** might be set incorrectly if any OP_FkCounter related scans are
** omitted.
Finish the work of sqlite3DbMallocRawNN for the unusual and
** slower case when the allocation cannot be fulfilled using lookaside.
** PRAGMA encoding
** PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
**
** In its first form, this pragma returns the encoding of the main
** database. If the database is not initialized, it is initialized now.
**
** The second form of this pragma is a no-op if the main database file
** has not already been initialized. In this case it sets the default
** encoding that will be used for the main database file if a new file
** is created. If an existing main database file is opened, then the
** default text encoding for the existing database is used.
**
** In all cases new databases created using the ATTACH command are
** created to use the same default text encoding as the main database. If
** the main database has not been initialized and/or created when ATTACH
** is executed, this is done before the ATTACH operation.
**
** In the second form this pragma sets the text encoding to be used in
** new database files created using this database handle. It is only
** useful if invoked immediately after the main database i
Overwrite deleted content with zeros
** This is the value that walTryBeginRead returns when it needs to
** be retried.
** Attempt to obtain the exclusive WAL lock defined by parameters lockIdx and
** n. If the attempt fails and parameter xBusy is not NULL, then it is a
** busy-handler function. Invoke it and retry the lock until either the
** lock is successfully obtained or the busy-handler returns 0.
** Populate the buffer pointed to by zBufOut with nByte bytes of
** random data.
14
Opcode: Null P1 P2 P3 * *
** Synopsis: r[P2..P3]=NULL
**
** Write a NULL into registers P2. If P3 greater than P2, then also write
** NULL into register P3 and every register in between P2 and P3. If P3
** is less than P2 (typically P3 is zero) then only register P2 is
** set to NULL.
**
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
** OP_Ne or OP_Eq.
Index of column in pFrom
comment: may be negative.
label: code-design
1400
** The number of bits in a Bitmask. "BMS" means "BitMask Size".
Object iterator
Initialize the rowset register to contain NULL. An SQL NULL is
** equivalent to an empty rowset. Or, create an ephemeral index
** capable of holding primary keys in the case of a WITHOUT ROWID.
**
** Also initialize regReturn to contain the address of the instruction
** immediately following the OP_Return at the bottom of the loop. This
** is required in a few obscure LEFT JOIN cases where control jumps
** over the top of the loop into the body of it. In this case the
** correct response for the end-of-loop code (the OP_Return) is to
** fall through to the next instruction, just as an OP_Next does if
** called on an uninitialized cursor.
The default safety_level for the main database is FULL; for the temp
** database it is OFF. This matches the pager layer defaults.
If necessary, grow the pIter->aRowidOffset[] array.
This step function is used for both the min() and max() aggregates,
** the only difference between the two being that the sense of the
** comparison is inverted. For the max() aggregate, the
** sqlite3_user_data() function returns (void *)-1. For min() it
** returns (void *)db, where db is the sqlite3* database pointer.
** Therefore the next statement sets variable 'max' to 1 for the max()
** aggregate, or 0 for min().
All data is stored on the current page. Populate the output
** variables to point into the body of the page object.
Unique file ID for vxworks.
** Iterator pIter currently points to a valid entry (not EOF). This
** function appends the position list data for the current entry to
** buffer pBuf. It does not make a copy of the position-list size
** field.
** An instance of the following structure describes the event of a
** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
** TK_DELETE, or TK_INSTEAD. If the event is of the form
**
** UPDATE ON (a,b,c)
**
** Then the "b" IdList records the list "a,b,c".
refact ::= SET NULL
Jump here if the UNIQUE constraint is satisfied
SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
Defined at the top of this function
The next rowid or record number (different terms for the same
** thing) is obtained in a two-step algorithm.
**
** First we attempt to find the largest existing rowid and add one
** to that. But if the largest existing rowid is already the maximum
** positive integer, we have to fall through to the second
** probabilistic algorithm
**
** The second algorithm is to select a rowid at random and see if
** it already exists in the table. If it does not exist, we have
** succeeded. If the random rowid does exist, we select a new one
** and try again, up to 100 times.
** CAPI3REF: Reset A Prepared Statement Object
** METHOD: sqlite3_stmt
**
** The sqlite3_reset() function is called to reset a [prepared statement]
** object back to its initial state, ready to be re-executed.
** ^Any SQL statement variables that had values bound to them using
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
** Use [sqlite3_clear_bindings()] to reset the bindings.
**
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
** back to the beginning of its program.
**
** ^If the most recent call to [sqlite3_step(S)] for the
** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
** or if [sqlite3_step(S)] has never before been called on S,
** then [sqlite3_reset(S)] returns [SQLITE_OK].
**
** ^If the most recent call to [sqlite3_step(S)] for the
** [prepared statement] S indicated an error, then
** [sqlite3_reset(S)] returns an appropriate [error code].
**
** ^The [sqlite3_reset(S)] interface does not change the values
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
The merge engine to advance to the next row
Invoked at every commit.
documents
** 2010 August 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Delete all information from a single table in the database. iTable is
** the page number of the root of the table. After this routine returns,
** the root page is empty, but still exists.
**
** This routine will fail with SQLITE_LOCKED if there are any open
** read cursors on the table. Open write cursors are moved to the
** root of the table.
**
** If pnChange is not NULL, then table iTable must be an intkey table. The
** integer value pointed to by pnChange is incremented by the number of
** entries in the table.
The function name.
Fetch the integer off the end of the index record
Restriction (15)
Automatic indexes
BTree containing table to open
Generated temporary filenames are always double-zero terminated
** for use by sqlite3_uri_parameter().
Block id of first leaf node
The Table object to which the virtual table belongs
(303) oneselect ::= values
VDBE cursor that is the main data repository
True after sqlite3_declare_vtab() is called
The X==Ei expression
Search for a page near this one
** Open the file zPath.
**
** Previously, the SQLite OS layer used three functions in place of this
** one:
**
** sqlite3OsOpenReadWrite();
** sqlite3OsOpenReadOnly();
** sqlite3OsOpenExclusive();
**
** These calls correspond to the following combinations of flags:
**
** ReadWrite() -> (READWRITE | CREATE)
** ReadOnly() -> (READONLY)
** OpenExclusive() -> (READWRITE | CREATE | EXCLUSIVE)
**
** The old OpenExclusive() accepted a boolean argument - "delFlag". If
** true, the file was configured to be automatically deleted when the
** file handle closed. To achieve the same effect using this new
** interface, add the DELETEONCLOSE flag to those specified above for
** OpenExclusive().
Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately.
Replacement expressions
Indexed column is the rowid
The main parser program.
** The first argument is a pointer to a structure obtained from
** "sqlite3Fts5ParserAlloc" which describes the current state of the parser.
** The second argument is the major token number. The third is
** the minor token. The fourth optional argument is whatever the
** user wants (and specified in the grammar) and is available for
** use by the action routines.
**
** Inputs:
** <ul>
** <li> A pointer to the parser (an opaque structure.)
** <li> The major token number.
** <li> The minor token number.
** <li> An option argument of a grammar-specified type.
** </ul>
**
** Outputs:
** None.
Generate code to query the parent index for a matching parent
** key. If a match is found, jump to addrOk.
Simple "PRAGMA locking_mode;" statement. This is a query for
** the current default locking mode (which may be different to
** the locking-mode of the main database).
True if EXPLAIN present on SQL command
38
** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
**
** The integer returned reveals the byte-order of the computer on which
** SQLite is running:
**
** 1 big-endian, determined at run-time
** 10 little-endian, determined at run-time
** 432101 big-endian, determined at compile-time
** 123410 little-endian, determined at compile-time
Path of the file to examine
If nIncr is less than zero, then check at runtime if there are any
** outstanding constraints to resolve. If there are not, there is no need
** to check if deleting this row resolves any outstanding violations.
**
** Check if any of the key columns in the child table row are NULL. If
** any are, then the constraint is considered satisfied. No need to
** search for a matching row in the parent table.
'occurrences' values for current csr row
Not a recursive common table expression.
Deleted OK.
The root page of the table to be locked
New aRegion[] array
This could happen with a network mount
tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt
The "langid = ?" constraint, if any
990
Space to hold the virtual machine's program
If the statement journal is open and the page is not in it,
** then write the page into the statement journal.
Store results here
** Called by the parser to compile a DETACH statement.
**
** DETACH pDbname
Address of the A<B subroutine
** Write out a single frame of the WAL
Declare and initialize constant integer 'isDirect'. If the
** atomic-write optimization is enabled in this build, then isDirect
** is initialized to the value passed as the isDirectMode parameter
** to this function. Otherwise, it is always set to zero.
**
** The idea is that if the atomic-write optimization is not
** enabled at compile time, the compiler can omit the tests of
** 'isDirect' below, as well as the block enclosed in the
** "if( isDirect )" condition.
Mutex type
Size of vector pLeft
** CAPI3REF: Set the Last Insert Rowid value.
** METHOD: sqlite3
**
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
** set the value returned by calling sqlite3_last_insert_rowid(D) to R
** without inserting a row into the database.
** Exit the recursive mutex on a Btree.
At this point variable c contains the first character of the
** pattern string past the "*". Search in the input string for the
** first matching character and recursively continue the match from
** that point.
**
** For a case-insensitive search, set variable cx to be the same as
** c but in the other case and search the input string for either
** c or cx.
testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file
Maximum bytes of data to store
Type passed as 4th argument to SegmentReaderIterate()
** The following macros are used to cast pointers to integers and
** integers to pointers. The way you do this varies from one compiler
** to the next, so we have developed the following set of #if statements
** to generate appropriate macros for a wide range of compilers.
**
** The correct "ANSI" way to do this is to use the intptr_t type.
** Unfortunately, that typedef is not available on all compilers, or
** if it is available, it requires an #include of specific headers
** that vary from one machine to the next.
**
** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
** So we have to define the macros in different ways depending on the
** compiler.
If the file format and encoding in the database have not been set,
** set them now.
SQLITE_SO_ASC or SQLITE_SO_DESC
Merge engine to return
Deal with as much of this read request as possible by transfering
** data from the memory mapping using memcpy().
Address of next instruction to return
Root page of table to open
We will need to create our own temporary table to hold the
** intermediate results.
241
Mem.eSubtype is valid
An index we are evaluating
expr ::= ID|INDEXED LP distinct exprlist RP
** Information about the current state of the WAL file and where
** the next fsync should occur - passed from sqlite3WalFrames() into
** walWriteToLog().
So that sizeof(Mem) is a multiple of 8
Rows processed for all objects
OUT: Error code
Determine the number of integers in the buffer returned by this call.
** CAPI3REF: Compile-Time Authorization Callbacks
** METHOD: sqlite3
** KEYWORDS: {authorizer callback}
**
** ^This routine registers an authorizer callback with a particular
** [database connection], supplied in the first argument.
** ^The authorizer callback is invoked as SQL statements are being compiled
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
** and [sqlite3_prepare16_v3()]. ^At various
** points during the compilation process, as logic is being created
** to perform various actions, the authorizer callback is invoked to
** see if those actions are allowed. ^The authorizer callback should
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
** specific action but allow the SQL statement to continue to be
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
** rejected with an error. ^If the authorizer callback returns
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
** the authorizer will fail with an error message.
**
** When the callback returns [SQLITE_OK], that means the operation
** requested is ok. ^When the callback returns [SQLITE_DENY], the
** [sqlite3_prepare_v2()] or equivalent call that triggered the
** authorizer will fail with an error message explaining that
** access is denied.
**
** ^The first parameter to the authorizer callback is a copy of the third
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
** to the callback is an integer [SQLITE_COPY | action code] that specifies
** the particular action to be authorized. ^The third through sixth parameters
** to the callback are either NULL pointers or zero-terminated strings
** that contain additional details about the action to be authorized.
** Applications must always be prepared to encounter a NULL pointer in any
** of the third through the sixth parameters of the authorization callback.
**
** ^If the action code is [SQLITE_READ]
** and the callback returns [SQLITE_IGNORE] then the
** [prepared statement] statement is constructed to substitute
** a NULL value in place of the table column that would have
** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
** return can be used to deny an untrusted user access to individual
** columns of a table.
** ^When a table is referenced by a [SELECT] but no column values are
** extracted from that table (for example in a query like
** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
** is invoked once for that table with a column name that is an empty string.
** ^If the action code is [SQLITE_DELETE] and the callback returns
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
** [truncate optimization] is disabled and all rows are deleted individually.
**
** An authorizer is used when [sqlite3_prepare | preparing]
** SQL statements from an untrusted source, to ensure that the SQL statements
** do not try to access data they are not allowed to see, or that they do not
** try to execute malicious statements that damage the database. For
** example, an application may allow a user to enter arbitrary
** SQL queries for evaluation by a database. But the application does
** not want the user to be able to make arbitrary changes to the
** database. An authorizer could then be put in place while the
** user-entered SQL is being [sqlite3_prepare | prepared] that
** disallows everything except [SELECT] statements.
**
** Applications that need to process SQL from untrusted sources
** might also consider lowering resource limits using [sqlite3_limit()]
** and limiting database size using the [max_page_count] [PRAGMA]
** in addition to using an authorizer.
**
** ^(Only a single authorizer can be in place on a database connection
** at a time. Each call to sqlite3_set_authorizer overrides the
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
** The authorizer is disabled by default.
**
** The authorizer callback must not do anything that will modify
** the database connection that invoked the authorizer callback.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
** statement might be re-prepared during [sqlite3_step()] due to a
** schema change. Hence, the application should ensure that the
** correct authorizer callback remains in place during the [sqlite3_step()].
**
** ^Note that the authorizer callback is invoked only during
** [sqlite3_prepare()] or its variants. Authorization is not
** performed during statement evaluation in [sqlite3_step()], unless
** as stated in the previous paragraph, sqlite3_step() invokes
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
All collating sequences
comment:
** This function is called when the user executes the following statement:
**
** INSERT INTO <tbl>(<tbl>) VALUES('rebuild');
**
** The entire FTS index is discarded and rebuilt. If the table is one
** created using the content=xxx option, then the new index is based on
** the current contents of the xxx table. Otherwise, it is rebuilt based
** on the contents of the %_content table.
label: code-design
Cursor number of the first index
comment:
** Macros for performance tracing. Normally turned off. Only works
** on i486 hardware.
label: code-design
Mutex to access this object
Used to catch return codes
** Process statements of the form:
**
** INSERT INTO table(table) VALUES('automerge=X');
**
** where X is an integer. X==0 means to turn automerge off. X!=0 means
** turn it on. The setting is persistent.
comment: Size of the temporary register block
label: code-design
Language being queried
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
True if this expression is entirely deferred
Integer value of right operand
Attach the hook to this database
** The functions querySharedCacheTableLock(), setSharedCacheTableLock(),
** and clearAllSharedCacheTableLocks()
** manipulate entries in the BtShared.pLock linked list used to store
** shared-cache table level locks. If the library is compiled with the
** shared-cache feature disabled, then there is only ever one user
** of each BtShared structure and so this locking is not necessary.
** So define the lock related functions as no-ops.
** Rtree virtual table module xDestroy method.
Array of nCol best samples
Index of column matching zCol
Make sure this analysis did not leave any unref() pages.
All unixShm objects pointing to this
** Implementation of SQL scalar function rbu_fossil_delta().
**
** This function applies a fossil delta patch to a blob. Exactly two
** arguments must be passed to this function. The first is the blob to
** patch and the second the patch to apply. If no error occurs, this
** function returns the patched blob.
Only interested in == results
Hash slot index
No more tokens here
** Deserialize cell iCell of node pNode. Populate the structure pointed
** to by pCell with the results.
synopsis: if r[P3] in rowset(P1) goto P2
206
The following loop runs once for each term in a compound-subquery
** flattening (as described above). If we are doing a different kind
** of flattening - a flattening other than a compound-subquery flattening -
** then this loop only runs once.
**
** This loop moves all of the FROM elements of the subquery into the
** the FROM clause of the outer query. Before doing this, remember
** the cursor number for the original outer query FROM element in
** iParent. The iParent cursor will never be used. Subsequent code
** will scan expressions looking for iParent references and replace
** those references with expressions that resolve to the subquery FROM
** elements we are now copying in.
comment:
** This division contains definitions of sqlite3_io_methods objects that
** implement various file locking strategies. It also contains definitions
** of "finder" functions. A finder-function is used to locate the appropriate
** sqlite3_io_methods object for a particular database file. The pAppData
** field of the sqlite3_vfs VFS objects are initialized to be pointers to
** the correct finder-function for that VFS.
**
** Most finder functions return a pointer to a fixed sqlite3_io_methods
** object. The only interesting finder-function is autolockIoFinder, which
** looks at the filesystem type and tries to guess the best locking
** strategy from that.
**
** For finder-function F, two objects are created:
**
** (1) The real finder-function named "FImpt()".
**
** (2) A constant pointer to this function named just "F".
**
**
** A pointer to the F pointer is used as the pAppData value for VFS
** objects. We have to do this instead of letting pAppData point
** directly at the finder-function since C90 rules prevent a void*
** from be cast into a function pointer.
**
**
** Each instance of this macro generates two objects:
**
** * A constant sqlite3_io_methods object call METHOD that has locking
** methods CLOSE, LOCK, UNLOCK, CKRESLOCK.
**
** * An I/O method finder function called FINDER that returns a pointer
** to the METHOD object in the previous bullet.
label: code-design
** Try to convert the type of a function argument or a result column
** into a numeric representation. Use either INTEGER or REAL whichever
** is appropriate. But only do the conversion if it is possible without
** loss of information and return the revised type of the argument.
Pointer to <id> token
comment: If we are just shaving the last few pages off the end of the
** cache, then there is no point in scanning the entire hash table.
** Only scan those hash slots that might contain pages that need to
** be removed.
label: code-design
BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)
Name of fts3 table
If shifting by a negative amount, shift in the other direction
** Added after 3.3.13
Name of file to check
MSVC is picky about pulling func ptrs from va lists.
** http://support.microsoft.com/kb/47961
** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*));
WHERE_GROUPBY or _DISTINCTBY or _ORDERBY_LIMIT
** This is defined in tokenize.c. We just have to import the definition.
Value to append
xCreate/xConnect argument array
** The following value as a destructor means to use sqlite3DbFree().
** The sqlite3DbFree() routine requires two parameters instead of the
** one parameter that destructors normally want. So we have to introduce
** this magic value that the code knows to handle differently. Any
** pointer will work here as long as it is distinct from SQLITE_STATIC
** and SQLITE_TRANSIENT.
Size of zBlob in bytes
The VDBE cursor
in2: P2 is an input
figure out how many UTF-8 characters are in zName
** The following are the meanings of bits in the Expr.flags field.
True if this is a patchset
Return code of various sub-routines
** Implementation of the scalar function fts3_tokenizer_internal_test().
** This function is used for testing only, it is not included in the
** build unless SQLITE_TEST is defined.
**
** The purpose of this is to test that the fts3_tokenizer() function
** can be used as designed by the C-code in the queryTokenizer and
** registerTokenizer() functions above. These two functions are repeated
** in the README.tokenizer file as an example, so it is important to
** test them.
**
** To run the tests, evaluate the fts3_tokenizer_internal_test() scalar
** function with no arguments. An assert() will fail if a problem is
** detected. i.e.:
**
** SELECT fts3_tokenizer_internal_test();
**
Lock the source database handle. The destination database
** handle is not locked in this routine, but it is locked in
** sqlite3_backup_step(). The user is required to ensure that no
** other thread accesses the destination handle for the duration
** of the backup operation. Any attempt to use the destination
** database connection while a backup is in progress may cause
** a malfunction or a deadlock.
joinop ::= JOIN_KW nm nm JOIN
transitive constraints
The fields of the result
** CAPI3REF: Virtual Table Interface Configuration
**
** This function may be called by either the [xConnect] or [xCreate] method
** of a [virtual table] implementation to configure
** various facets of the virtual table interface.
**
** If this interface is invoked outside the context of an xConnect or
** xCreate virtual table method then the behavior is undefined.
**
** At present, there is only one option that may be configured using
** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
** may be added in the future.
Path to target db
Database file path
Buffer containing page-index
# include <time.h>
The comparison operation
First rowid on leaf iLeafPgno
Flags to use to sync header writes
** Write VDBE code to erase table pTab and all associated indices on disk.
** Code to update the sqlite_master tables and internal schema definitions
** in case a root-page belonging to another table is moved by the btree layer
** is also added (this can happen with an auto-vacuum database).
** CAPI3REF: Virtual File System Objects
**
** A virtual filesystem (VFS) is an [sqlite3_vfs] object
** that SQLite uses to interact
** with the underlying operating system. Most SQLite builds come with a
** single default VFS that is appropriate for the host computer.
** New VFSes can be registered and existing VFSes can be unregistered.
** The following interfaces are provided.
**
** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
** ^Names are case sensitive.
** ^Names are zero-terminated UTF-8 strings.
** ^If there is no match, a NULL pointer is returned.
** ^If zVfsName is NULL then the default VFS is returned.
**
** ^New VFSes are registered with sqlite3_vfs_register().
** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
** ^The same VFS can be registered multiple times without injury.
** ^To make an existing VFS into the default VFS, register it again
** with the makeDflt flag set. If two different VFSes with the
** same name are registered, the behavior is undefined. If a
** VFS is registered with a name that is NULL or an empty string,
** then the behavior is undefined.
**
** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
** ^(If the default VFS is unregistered, another VFS is chosen as
** the default. The choice for the new VFS is arbitrary.)^
Used when p4type is P4_VTAB
Advance iterator at least this far
Configuration object
Flush the last leaf page to disk. Set the output segment b-tree height
** and last leaf page number at the same time.
If a rowid value was supplied, check if it is already present in
** the table. If so, the constraint has failed.
** Mark every prepared statement associated with a database connection
** as expired.
**
** An expired statement means that recompilation of the statement is
** recommend. Statements expire when things happen that make their
** programs obsolete. Removing user-defined functions or collating
** sequences, or changing an authorization function are the types of
** things that make prepared statements obsolete.
134
Database page-size
the name context cannot be NULL.
Make sure the encoding is UTF-8
Columns in this table that point to other table
Increment our pretend rowid value.
** The contents of the "structure" record for each index are represented
** using an Fts5Structure record in memory. Which uses instances of the
** other Fts5StructureXXX types as components.
pHeap
comment:
** Macros to determine whether the machine is big or little endian,
** and whether or not that determination is run-time or compile-time.
**
** For best performance, an attempt is made to guess at the byte-order
** using C-preprocessor macros. If that is unsuccessful, or if
** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
** at run-time.
label: code-design
Session changeset-apply context
Take advantage of short-circuit false optimization for AND
The rowid that might be changing
210
Do not use prefix index
comment: VFS to use if no "vfs=xxx" query option
label: code-design
** The snippet() and offsets() functions both return text values. An instance
** of the following structure is used to accumulate those values while the
** functions are running. See fts3StringAppend() for details.
Number of ORDER BY clause terms
One table in the FROM clause
The virtual table being constructed
Linked list of auxdata allocations
Obtain an exclusive lock on all byte in the locking range not already
** locked by the caller. The caller is guaranteed to have locked the
** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
** If successful, the same bytes that are locked here are unlocked before
** this function returns.
Number of entries with this hash
True if holding the unixShmNode mutex
expr ::= nm DOT nm
Used to iterate through VMs
INSERT or UPDATE operations
** Open a handle to begin or resume an RBU VACUUM operation.
Check all the tables.
Boolean parameters. See BTS_* macros below
Fts5 context
Read input from all segments in the input level
** This object represents a single thread of control in a sort operation.
** Exactly VdbeSorter.nTask instances of this object are allocated
** as part of each VdbeSorter object. Instances are never allocated any
** other way. VdbeSorter.nTask is set to the number of worker threads allowed
** (see SQLITE_CONFIG_WORKER_THREADS) plus one (the main thread). Thus for
** single-threaded operation, there is exactly one instance of this object
** and for multi-threaded operation there are two or more instances.
**
** Essentially, this structure contains all those fields of the VdbeSorter
** structure for which each thread requires a separate instance. For example,
** each thread requries its own UnpackedRecord object to unpack records in
** as part of comparison operations.
**
** Before a background thread is launched, variable bDone is set to 0. Then,
** right before it exits, the thread itself sets bDone to 1. This is used for
** two purposes:
**
** 1. When flushing the contents of memory to a level-0 PMA on disk, to
** attempt to select a SortSubtask for which there is not already an
** active background thread (since doing so causes the main thread
** to block until it finishes).
**
** 2. If SQLITE_DEBUG_SORTER_THREADS is defined, to determine if a call
** to sqlite3ThreadJoin() is likely to block. Cases that are likely to
** block provoke debugging output.
**
** In both cases, the effects of the main thread seeing (bDone==0) even
** after the thread has finished are not dire. So we don't worry about
** memory barriers and such here.
If pTab is really a view, make sure it has been initialized.
WinRT has no way to convert a relative path to an absolute one.
First frame that may be overwritten
OUT: New iterator object
No match was found. We will make a new file ID
when_clause ::= WHEN expr
Opcode: Rowid P1 P2 * * *
** Synopsis: r[P2]=rowid
**
** Store in register P2 an integer which is the key of the table entry that
** P1 is currently point to.
**
** P1 can be either an ordinary table or a virtual table. There used to
** be a separate OP_VRowid opcode for use with virtual tables, but this
** one opcode now works for both table types.
Allocate a MultiSegReader for each token in the expression.
Allocate additional space if needed
Array containing doclist (or NULL)
244
Pointer to cursor object to return
** This routine is the only routine in this file with external
** linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file. The
** arguments specify the block of memory to manage.
**
** This routine is only called by sqlite3_config(), and therefore
** is not required to be threadsafe (it is not).
Name context of this SELECT
Variables related to SQLITE_CONFIG_PAGECACHE settings. The
** szSlot, nSlot, pStart, pEnd, nReserve, and isInit values are all
** fixed at sqlite3_initialize() time and do not require mutex protection.
** The nFreeSlot and pFree values do require mutex protection.
EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit
** twos-complement integer.
If needSyncPgno is non-zero, then the journal file needs to be
** sync()ed before any data is written to database file page needSyncPgno.
** Currently, no such page exists in the page-cache and the
** "is journaled" bitvec flag has been set. This needs to be remedied by
** loading the page into the pager-cache and setting the PGHDR_NEED_SYNC
** flag.
**
** If the attempt to load the page into the page-cache fails, (due
** to a malloc() or IO failure), clear the bit in the pInJournal[]
** array. Otherwise, if the page is loaded and written again in
** this transaction, it may be written to the database file before
** it is synced into the journal file. This way, it may end up in
** the journal file twice, but that is not a problem.
Resolve all names in the ORDER BY term expression
** Seek to the offset in id->offset then read cnt bytes into pBuf.
** Return the number of bytes actually read. Update the offset.
**
** To avoid stomping the errno value on a failed write the lastErrno value
** is set before returning.
** Implementation of xBegin() method.
Rowid for this entry
comment:
** 2004 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements an external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
**
** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
** "Sorting And Searching", pages 473-480. Addison-Wesley
** Publishing Company, Reading, Massachusetts.
**
** The basic idea is that each page of the file contains N database
** entries and N+1 pointers to subpages.
**
** ----------------------------------------------------------------
** | Ptr(0) | Key(0) | Ptr(1) | Key(1) | ... | Key(N-1) | Ptr(N) |
** ----------------------------------------------------------------
**
** All of the keys on the page that Ptr(0) points to have values less
** than Key(0). All of the keys on page Ptr(1) and its subpages have
** values greater than Key(0) and less than Key(1). All of the keys
** on Ptr(N) and its subpages have values greater than Key(N-1). And
** so forth.
**
** Finding a particular key requires reading O(log(M)) pages from the
** disk where M is the number of entries in the tree.
**
** In this implementation, a single file can hold one or more separate
** BTrees. Each BTree is identified by the index of its root page. The
** key and data for any entry are combined to form the "payload". A
** fixed amount of payload can be carried directly on the database
** page. If the payload is larger than the preset amount then surplus
** bytes are stored on overflow pages. The payload for an entry
** and the preceding pointer are combined to form a "Cell". Each
** page has a small header which contains the Ptr(N) pointer and other
** information such as the size of key and data.
**
** FORMAT DETAILS
**
** The file is divided into pages. The first page is called page 1,
** the second is page 2, and so forth. A page number of zero indicates
** "no such page". The page size can be any power of 2 between 512 and 65536.
** Each page can be either a btree page, a freelist page, an overflow
** page, or a pointer-map page.
**
** The first page is always a btree page. The first 100 bytes of the first
** page contain a special header (the "file header") that describes the file.
** The format of the file header is as follows:
**
** OFFSET SIZE DESCRIPTION
** 0 16 Header string: "SQLite format 3\000"
** 16 2 Page size in bytes. (1 means 65536)
** 18 1 File format write version
** 19 1 File format read version
** 20 1 Bytes of unused space at the end of each page
** 21 1 Max embedded payload fraction (must be 64)
** 22 1 Min embedded payload fraction (must be 32)
** 23 1 Min leaf payload fraction (must be 32)
** 24 4 File change counter
** 28 4 Reserved for future use
** 32 4 First freelist page
** 36 4 Number of freelist pages in the file
** 40 60 15 4-byte meta values passed to higher layers
**
** 40 4 Schema cookie
** 44 4 File format of schema layer
** 48 4 Size of page cache
** 52 4 Largest root-page (auto/incr_vacuum)
** 56 4 1=UTF-8 2=UTF16le 3=UTF16be
** 60 4 User version
** 64 4 Incremental vacuum mode
** 68 4 Application-ID
** 72 20 unused
** 92 4 The version-valid-for number
** 96 4 SQLITE_VERSION_NUMBER
**
** All of the integer values are big-endian (most significant byte first).
**
** The file change counter is incremented when the database is changed
** This counter allows other processes to know when the file has changed
** and thus when they need to flush their cache.
**
** The max embedded payload fraction is the amount of the total usable
** space in a page that can be consumed by a single cell for standard
** B-tree (non-LEAFDATA) tables. A value of 255 means 100%. The default
** is to limit the maximum cell size so that at least 4 cells will fit
** on one page. Thus the default max embedded payload fraction is 64.
**
** If the payload for a cell is larger than the max payload, then extra
** payload is spilled to overflow pages. Once an overflow page is allocated,
** as many bytes as possible are moved into the overflow pages without letting
** the cell size drop below the min embedded payload fraction.
**
** The min leaf payload fraction is like the min embedded payload fraction
** except that it applies to leaf nodes in a LEAFDATA tree. The maximum
** payload fraction for a LEAFDATA tree is always 100% (or 255) and it
** not specified in the header.
**
** Each btree pages is divided into three sections: The header, the
** cell pointer array, and the cell content area. Page 1 also has a 100-byte
** file header that occurs before the page header.
**
** |----------------|
** | file header | 100 bytes. Page 1 only.
** |----------------|
** | page header | 8 bytes for leaves. 12 bytes for interior nodes
** |----------------|
** | cell pointer | | 2 bytes per cell. Sorted order.
** | array | | Grows downward
** | | v
** |----------------|
** | unallocated |
** | space |
** |----------------| ^ Grows upwards
** | cell content | | Arbitrary order interspersed with freeblocks.
** | area | | and free space fragments.
** |----------------|
**
** The page headers looks like this:
**
** OFFSET SIZE DESCRIPTION
** 0 1 Flags. 1: intkey, 2: zerodata, 4: leafdata, 8: leaf
** 1 2 byte offset to the first freeblock
** 3 2 number of cells on this page
** 5 2 first byte of the cell content area
** 7 1 number of fragmented free bytes
** 8 4 Right child (the Ptr(N) value). Omitted on leaves.
**
** The flags define the format of this btree page. The leaf flag means that
** this page has no children. The zerodata flag means that this page carries
** only keys and no data. The intkey flag means that the key is an integer
** which is stored in the key size entry of the cell header rather than in
** the payload area.
**
** The cell pointer array begins on the first byte after the page header.
** The cell pointer array contains zero or more 2-byte numbers which are
** offsets from the beginning of the page to the cell content in the cell
** content area. The cell pointers occur in sorted order. The system strives
** to keep free space after the last cell pointer so that new cells can
** be easily added without having to defragment the page.
**
** Cell content is stored at the very end of the page and grows toward the
** beginning of the page.
**
** Unused space within the cell content area is collected into a linked list of
** freeblocks. Each freeblock is at least 4 bytes in size. The byte offset
** to the first freeblock is given in the header. Freeblocks occur in
** increasing order. Because a freeblock must be at least 4 bytes in size,
** any group of 3 or fewer unused bytes in the cell content area cannot
** exist on the freeblock chain. A group of 3 or fewer free bytes is called
** a fragment. The total number of bytes in all fragments is recorded.
** in the page header at offset 7.
**
** SIZE DESCRIPTION
** 2 Byte offset of the next freeblock
** 2 Bytes in this freeblock
**
** Cells are of variable length. Cells are stored in the cell content area at
** the end of the page. Pointers to the cells are in the cell pointer array
** that immediately follows the page header. Cells is not necessarily
** contiguous or in order, but cell pointers are contiguous and in order.
**
** Cell content makes use of variable length integers. A variable
** length integer is 1 to 9 bytes where the lower 7 bits of each
** byte are used. The integer consists of all bytes that have bit 8 set and
** the first byte with bit 8 clear. The most significant byte of the integer
** appears first. A variable-length integer may not be more than 9 bytes long.
** As a special case, all 8 bytes of the 9th byte are used as data. This
** allows a 64-bit integer to be encoded in 9 bytes.
**
** 0x00 becomes 0x00000000
** 0x7f becomes 0x0000007f
** 0x81 0x00 becomes 0x00000080
** 0x82 0x00 becomes 0x00000100
** 0x80 0x7f becomes 0x0000007f
** 0x8a 0x91 0xd1 0xac 0x78 becomes 0x12345678
** 0x81 0x81 0x81 0x81 0x01 becomes 0x10204081
**
** Variable length integers are used for rowids and to hold the number of
** bytes of key and data in a btree cell.
**
** The content of a cell looks like this:
**
** SIZE DESCRIPTION
** 4 Page number of the left child. Omitted if leaf flag is set.
** var Number of bytes of data. Omitted if the zerodata flag is set.
** var Number of bytes of key. Or the key itself if intkey flag is set.
** * Payload
** 4 First page of the overflow chain. Omitted if no overflow
**
** Overflow pages form a linked list. Each page except the last is completely
** filled with data (pagesize - 4 bytes). The last page can have as little
** as 1 byte of data.
**
** SIZE DESCRIPTION
** 4 Page number of next overflow page
** * Data
**
** Freelist pages come in two subtypes: trunk pages and leaf pages. The
** file header points to the first in a linked list of trunk page. Each trunk
** page points to multiple leaf pages. The content of a leaf page is
** unspecified. A trunk page looks like this:
**
** SIZE DESCRIPTION
** 4 Page number of next trunk page
** 4 Number of leaf pointers on this page
** * zero or more pages numbers of leaves
label: code-design
Re-enable the lookaside buffer, if it was disabled earlier.
Error message text, if an error occurs
** Free a PendingList object allocated by fts3PendingListAppend().
defined SCANSTAT or STAT4 or ESTIMATED_ROWS
If this is being called to read the first page of the target
** database as part of an rbu vacuum operation, synthesize the
** contents of the first page if it does not yet exist. Otherwise,
** SQLite will not check for a *-wal file.
130
pPager->stmtOpen = 0;
** This (sqlite3EndBenignMalloc()) is called by SQLite code to indicate that
** subsequent malloc failures are benign. A call to sqlite3EndBenignMalloc()
** indicates that subsequent malloc failures are non-benign.
True to enable tracing
** This function is called from within a pre-update callback to retrieve
** a field of the row currently being updated or deleted.
** Structures used by the tokenizer interface. When a new tokenizer
** implementation is registered, the caller provides a pointer to
** an sqlite3_tokenizer_module containing pointers to the callback
** functions that make up an implementation.
**
** When an fts3 table is created, it passes any arguments passed to
** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer
** implementation. The xCreate() function in turn returns an
** sqlite3_tokenizer structure representing the specific tokenizer to
** be used for the fts3 table (customized by the tokenizer clause arguments).
**
** To tokenize an input buffer, the sqlite3_tokenizer_module.xOpen()
** method is called. It returns an sqlite3_tokenizer_cursor object
** that may be used to tokenize a specific input buffer based on
** the tokenization rules supplied by a specific sqlite3_tokenizer
** object.
40
0x06
** Invalidate temp storage, either when the temp storage is changed
** from default, or when 'file' and the temp_store_directory has changed
There is no constraint to check
clearCell never fails when nLocal==nPayload
Corresponding column number in the eq-class
Number of phrases in expression
comment: EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
** single argument which is a pointer to an instance of the
** sqlite3_mem_methods structure. The argument specifies alternative
** low-level memory allocation routines to be used in place of the memory
** allocation routines built into SQLite.
label: code-design
** The default lookaside-configuration, the format "SZ,N". SZ is the
** number of bytes in each lookaside slot (should be a multiple of 8)
** and N is the number of slots. The lookaside-configuration can be
** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
** or at run-time for an individual database connection using
** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
The ORDER BY term is an integer constant. Again, set the column
** number so that sqlite3ResolveOrderGroupBy() will convert the
** order-by term to a copy of the result-set expression
** Release the BtShared mutex associated with B-Tree handle p and
** clear the p->locked boolean.
** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
** the SELECT statement pSelect. If any term is reference to a
** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
** field) then convert that term into a copy of the corresponding result set
** column.
**
** If any errors are detected, add an error message to pParse and
** return non-zero. Return zero if no errors are seen.
Processing a sub-WHERE as part of
** the OR optimization
comment:
** This routine generates code to finish the INSERT or UPDATE operation
** that was started by a prior call to sqlite3GenerateConstraintChecks.
** A consecutive range of registers starting at regNewData contains the
** rowid and the content to be inserted.
**
** The arguments to this routine should be the same as the first six
** arguments to sqlite3GenerateConstraintChecks.
label: code-design
Opcode: Int64 * P2 * P4 *
** Synopsis: r[P2]=P4
**
** P4 is a pointer to a 64-bit integer value.
** Write that value into register P2.
Mask of all possible WO_* values
** Iterator pIter must point to an SQLITE_INSERT entry. This function
** transfers new.* values from the current iterator entry to statement
** pStmt. The table being inserted into has nCol columns.
**
** New.* value $i from the iterator is bound to variable ($i+1) of
** statement pStmt. If parameter abPK is NULL, all values from 0 to (nCol-1)
** are transfered to the statement. Otherwise, if abPK is not NULL, it points
** to an array nCol elements in size. In this case only those values for
** which abPK[$i] is true are read from the iterator and bound to the
** statement.
**
** An SQLite error code is returned if an error occurs. Otherwise, SQLITE_OK.
Expression list to search
** A hash table for built-in function definitions. (Application-defined
** functions use a regular table table from hash.h.)
**
** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
** Collisions are on the FuncDef.u.pHash chain.
Release the checkpointer and writer locks
Already gone?
Next chunk in the journal
** Open a new statvfs cursor.
IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
** argument to xRealloc is always a value returned by a prior call to
** xRoundup.
Allocate the space required for the Stat4Accum object
Allocate required registers.
Uses the skip-scan algorithm
All pages have been processed exactly once
Named POSIX semaphore
Did we have an exclusive lock?
IN/OUT: error code
Trigger definition to return
!SQLITE_DEBUG
Prepared statements under construction
Read all frames from the log file.
Call xBestIndex once for each distinct value of (prereqRight & ~mPrereq)
** in the set of terms that apply to the current virtual table.
Integer 1
Index object
** Implementation of the like() SQL function. This function implements
** the build-in LIKE operator. The first argument to the function is the
** pattern and the second argument is the string. So, the SQL statements:
**
** A LIKE B
**
** is implemented as like(B,A).
**
** This same function (with a different compareInfo structure) computes
** the GLOB operator.
SQLITE_OMIT_XFER_OPT
Evaluate the expression and insert it into the temp table
The next sections is a series of control #defines.
** various aspects of the generated parser.
** YYCODETYPE is the data type used to store the integer codes
** that represent terminal and non-terminal symbols.
** "unsigned char" is used if there are fewer than
** 256 symbols. Larger types otherwise.
** YYNOCODE is a number of type YYCODETYPE that is not used for
** any terminal or nonterminal symbol.
** YYFALLBACK If defined, this indicates that one or more tokens
** (also known as: "terminal symbols") have fall-back
** values which should be used if the original symbol
** would not parse. This permits keywords to sometimes
** be used as identifiers, for example.
** YYACTIONTYPE is the data type used for "action codes" - numbers
** that indicate what to do in response to the next
** token.
** sqlite3ParserTOKENTYPE is the data type used for minor type for terminal
** symbols. Background: A "minor type" is a semantic
** value associated with a terminal or non-terminal
** symbols. For example, for an "ID" terminal symbol,
** the minor type might be the name of the identifier.
** Each non-terminal can have a different minor type.
** Terminal symbols all have the same minor type, though.
** This macros defines the minor type for terminal
** symbols.
** YYMINORTYPE is the data type used for all minor types.
** This is typically a union of many types, one of
** which is sqlite3ParserTOKENTYPE. The entry in the union
** for terminal symbols is called "yy0".
** YYSTACKDEPTH is the maximum depth of the parser's stack. If
** zero the stack is dynamically sized using realloc()
** sqlite3ParserARG_SDECL A static variable declaration for the %extra_argument
** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
** YYERRORSYMBOL is the code number of the error symbol. If not
** defined, then do no error processing.
** YYNSTATE the combined number of states.
** YYNRULE the number of rules in the grammar
** YY_MAX_SHIFT Maximum value for shift actions
** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
** YY_MIN_REDUCE Maximum value for reduce actions
** YY_ERROR_ACTION The yy_action[] code for syntax error
** YY_ACCEPT_ACTION The yy_action[] code for accept
** YY_NO_ACTION The yy_action[] code for no-op
Custom rank function
Routine to fetch a patch
60
Temporary VM
If we reach this point, that means the index pIdx is usable
Offset to the start of the cell content area
** Return the memory allocator mutex. sqlite3_status() needs it.
"DELETE FROM %_idx WHERE segid=?
** The main routine for background threads that write level-0 PMAs.
Number of left-most columns to skip
A MATCH constraint. Use a full-text search.
**
** If there is more than one MATCH constraint available, use the first
** one encountered. If there is both a MATCH constraint and a direct
** rowid/docid lookup, prefer the MATCH strategy. This is done even
** though the rowid/docid lookup is faster than a MATCH query, selecting
** it would lead to an "unable to use function MATCH in the requested
** context" error.
0x0d
** CAPI3REF: Flags For File Open Operations
**
** These bit values are intended for use in the
** 3rd parameter to the [sqlite3_open_v2()] interface and
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
same as TK_MINUS, in1, in2, out3
The VFS used to create pDbFd
indexed_opt ::= NOT INDEXED
295
Size of the binary record
extern "C"
Number of bytes in term suffix
** Log a I/O error retry episode.
The last token parsed
comment: Human readable error text
label: code-design
** During code generation of statements that do inserts into AUTOINCREMENT
** tables, the following information is attached to the Table.u.autoInc.p
** pointer of each autoincrement table to record some side information that
** the code generator needs. We have to keep per-table autoincrement
** information in case inserts are done within triggers. Triggers do not
** normally coordinate their activities, but we do need to coordinate the
** loading and saving of autoincrement information.
This case when the file is being statically linked into the
** application
** Reset the SQL statement passed as the first argument. Return a copy
** of the value returned by sqlite3_reset().
**
** If an error has occurred, then set *pzErrmsg to point to a buffer
** containing an error message. It is the responsibility of the caller
** to eventually free this buffer using sqlite3_free().
colsetlist ::= colsetlist STRING
in_op ::= IN
maxLocal is the maximum amount of payload to store locally for
** a cell. Make sure it is small enough so that at least minFanout
** cells can will fit on one page. We assume a 10-byte page header.
** Besides the payload, the cell must store:
** 2-byte pointer to the cell
** 4-byte child pointer
** 9-byte nKey value
** 4-byte nData value
** 4-byte overflow page pointer
** So a cell consists of a 2-byte pointer, a header which is as much as
** 17 bytes long, 0 to N bytes of payload, and an optional 4 byte overflow
** page pointer.
The page that contains the Cell
Error message prefix
Set the right-child pointer of pParent to point to the new page.
RIGHT
OFFSET => ID
A virtual meta-value
Database Name NULL
The ORDER BY clause
first lock byte
The cached entry matches, so return it
expr
comment: Temporary use register
label: code-design
all negative values become -1.
** date( TIMESTRING, MOD, MOD, ...)
**
** Return YYYY-MM-DD
If an error occurred while creating or writing to the file, restore
** the original before returning. This way, SQLite uses the in-memory
** journal data to roll back changes made to the internal page-cache
** before this function was called.
1140
Next sub-program already visited
Authorization context
Load new statistics out of the sqlite_stat1 table
141
comment:
** This function does not contribute anything to the operation of SQLite.
** it is sometimes activated temporarily while debugging code responsible
** for setting pointer-map entries.
label: code-design
If there is an ORDER BY clause, then we need to sort the results
** and send them to the callback one by one.
This case when the file really is being compiled as a loadable
** extension
Insert the new index entries and the new record.
Set default precision
Add OP_CursorHint opcodes
************* End of mutex.h **********************************************
Array indicating UPDATEd columns (or 0)
A source cursor for SORTED_MATCH
Form 3: Analyze the table or index named as an argument
Number of non-wildcard prefix characters
The table or view or trigger name is passed to this routine via tokens
** pName1 and pName2. If the table name was fully qualified, for example:
**
** CREATE TABLE xxx.yyy (...);
**
** Then pName1 is set to "xxx" and pName2 "yyy". On the other hand if
** the table name is not fully qualified, i.e.:
**
** CREATE TABLE yyy(...);
**
** Then pName1 is set to "yyy" and pName2 is "".
**
** This routine sets the *ppUnqual pointer to point at the token (pName1 or
** pName2) that stores the unqualified table name. The index of the
** database "xxx" is returned.
2*nField extra array elements allocated for aType[], beyond the one
** static element declared in the structure. nField total array slots for
** aType[] and nField+1 array slots for aOffset[]
Number of bytes in buffer pA
If we are doing a normal write to a database file (as opposed to
** doing a hot-journal rollback or a write to some file other than a
** normal database file) then record the fact that the database
** has changed. If the transaction counter is modified, record that
** fact too.
True for a leaf node
Stat4Accum.anDLt
comment:
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser. This pointer is used in subsequent calls
** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
label: code-design
Index in some Table.aCol[] of a column named zName
WRITEPOSLISTSIZE
** Check schema cookies in all databases. If any cookie is out
** of date set pParse->rc to SQLITE_SCHEMA. If all schema cookies
** make no changes to pParse->rc.
Jump here if a comparison is not true in step 6
Check that:
**
** a) The incremental merge object is configured to use the
** right task, and
** b) If it is using task (nTask-1), it is configured to run
** in single-threaded mode. This is important, as the
** root merge (INCRINIT_ROOT) will be using the same task
** object.
** Arguments aLeft and aRight both point to buffers containing change
** records with nCol columns. This function "merges" the two records into
** a single records which is written to the buffer at *paOut. *paOut is
** then set to point to one byte after the last byte written before
** returning.
**
** The merging of records is done as follows: For each column, if the
** aRight record contains a value for the column, copy the value from
** their. Otherwise, if aLeft contains a value, copy it. If neither
** record contains a value for a given column, then neither does the
** output record.
** Report the current page size and number of reserved bytes back
** to the codec.
Write minimum integer primary key here
Table leaf node
If eType==EXTERNAL, root of PK index
Jump to here if not distinct
If the db handle must hold the connection handle mutex here.
** Otherwise the read (and possible write) of db->mallocFailed
** is unsafe, as is the call to sqlite3Error().
same as TK_FLOAT, synopsis: r[P2]=P4
Build up text to return here
High-water mark of the stack
** Return the total number of pages in the source database as of the most
** recent call to sqlite3_backup_step().
** Function assertTruncateConstraint(pPager) checks that one of the
** following is true for all dirty pages currently in the page-cache:
**
** a) The page number is less than or equal to the size of the
** current database image, in pages, OR
**
** b) if the page content were written at this time, it would not
** be necessary to write the current content out to the sub-journal
** (as determined by function subjRequiresPage()).
**
** If the condition asserted by this function were not true, and the
** dirty page were to be discarded from the cache via the pagerStress()
** routine, pagerStress() would not write the current page content to
** the database file. If a savepoint transaction were rolled back after
** this happened, the correct behavior would be to restore the current
** content of the page. However, since this content is not present in either
** the database file or the portion of the rollback journal and
** sub-journal rolled back the content could not be restored and the
** database image would become corrupt. It is therefore fortunate that
** this circumstance cannot arise.
The pointer map data
110
ROLLBACK => ID
** Register a geometry callback named zGeom that can be used as part of an
** R-Tree geometry query as follows:
**
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
comment:
** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
** contains the size in bytes of each such cell. This function attempts to
** add the cells stored in the array to page pPg. If it cannot (because
** the page needs to be defragmented before the cells will fit), non-zero
** is returned. Otherwise, if the cells are added successfully, zero is
** returned.
**
** Argument pCellptr points to the first entry in the cell-pointer array
** (part of page pPg) to populate. After cell apCell[0] is written to the
** page body, a 16-bit offset is written to pCellptr. And so on, for each
** cell in the array. It is the responsibility of the caller to ensure
** that it is safe to overwrite this part of the cell-pointer array.
**
** When this function is called, *ppData points to the start of the
** content area on page pPg. If the size of the content area is extended,
** *ppData is updated to point to the new start of the content area
** before returning.
**
** Finally, argument pBegin points to the byte immediately following the
** end of the space required by this page for the cell-pointer area (for
** all cells - not just those inserted by the current call). If the content
** area must be extended to before this point in order to accomodate all
** cells in apCell[], then the cells do not fit and non-zero is returned.
label: code-design
'$'
First part of the name of the table or view
collate ::=
** Allocate a new SegReader object.
Input text
Used to iterate through levels
comment:
** "Special" FTS4 arguments are column specifications of the following form:
**
** <key> = <value>
**
** There may not be whitespace surrounding the "=" character. The <value>
** term may be quoted, but the <key> may not.
label: code-design
!SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC
prereq always non-zero
4
Register holding operands
Set of characters to trim
Last key written to the current block
Information used by aggregate queries
Compile a SELECT statement for this cursor. For a full-table-scan, the
** statement loops through all rows of the %_content table. For a
** full-text query or docid lookup, the statement retrieves a single
** row by docid.
If this is a leaf page or the tree is not an int-key tree, then
** this page contains countable entries. Increment the entry counter
** accordingly.
** Check to see if this machine uses EBCDIC. (Yes, believe it or
** not, there are still machines out there that use EBCDIC.)
A SELECT statement that supplies values
Constraint value.
Zero or more NC_* flags defined below
** Destroy an existing tokenizer. The fts3 module calls this method
** exactly once for each successful call to xCreate().
All the rest should always be initialized to zero
Verify that integers and floating point values use the same
** byte order. Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
** defined that 64-bit floating point values really are mixed
** endian.
Source data
xUnlock method
Test to see if the iRowid value appears anywhere in the forest.
** Return 1 if it does and 0 if not.
Address of "rows visited" counter
************* End of status.c *********************************************
** Return TRUE (non-zero) of the statement supplied as an argument needs
** to be recompiled. A statement needs to be recompiled whenever the
** execution environment changes in a way that would alter the program
** that sqlite3_prepare() generates. For example, if new functions or
** collating sequences are registered or if an authorizer function is
** added or changed.
Attempt to extend file to this size
The MergeEngine that the IncrMerger will control
Array of expression tokens and costs
Current offset within position list
P5 value for OP_Open* opcodes (except on WITHOUT ROWID)
OS_VXWORKS
Accumulate the output here
IN/OUT: SQLITE_OPEN_XXX flags
** sqlite3_changegroup handle.
comment: The where level to be coded
label: code-design
At this point, the (iCol+1) field prefix of aSample[i] is the first
** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
** is larger than all samples in the array.
More ARRAY/OBJECT entries at u.iAppend
rbu_control value ('x.x.')
** Call exprAnalyze on all terms in a WHERE clause.
**
** Note that exprAnalyze() might add new virtual terms onto the
** end of the WHERE clause. We do not want to analyze these new
** virtual terms, so start analyzing at the end and work forward
** so that the added virtual terms are never processed.
comment:
** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
** zOut is at least big enough to hold nIn bytes. Write the actual
** size of the output word (exclusive of the '\0' terminator) into *pnOut.
**
** Any upper-case characters in the US-ASCII character set ([A-Z])
** are converted to lower case. Upper-case UTF characters are
** unchanged.
**
** Words that are longer than about 20 bytes are stemmed by retaining
** a few bytes from the beginning and the end of the word. If the
** word contains digits, 3 bytes are taken from the beginning and
** 3 bytes from the end. For long words without digits, 10 bytes
** are taken from each end. US-ASCII case folding still applies.
**
** If the input word contains not digits but does characters not
** in [a-zA-Z] then no stemming is attempted and this routine just
** copies the input into the input into the output with US-ASCII
** case folding.
**
** Stemming never increases the length of the word. So there is
** no chance of overflowing the zOut buffer.
label: code-design
The following variables are all protected by the STATIC_MASTER
** mutex, not by sqlite3.mutex. They are used by code in notify.c.
**
** When X.pUnlockConnection==Y, that means that X is waiting for Y to
** unlock so that it can proceed.
**
** When X.pBlockingConnection==Y, that means that something that X tried
** tried to do recently failed with an SQLITE_LOCKED error due to locks
** held by Y.
** If the given Mem* has a zero-filled tail, turn it into an ordinary
** blob stored in dynamically allocated space.
SQLITE_OMIT_LOCALTIME
same as TK_ISNULL, jump, in1
If we are trying to update a view, realize that view into
** an ephemeral table.
Find the best snippet of nFToken tokens in column iRead.
Cursor to create snippet for
Find the named savepoint. If there is no such savepoint, then an
** an error is returned to the user.
** json_valid(JSON)
**
** Return 1 if JSON is a well-formed JSON string according to RFC-7159.
** Return 0 otherwise.
IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL.
Number of arguments to VUpdate
282
User data for aux. function
Datatype of the argument to the memory allocated passed as the
** second argument to sqlite3Fts5ParserAlloc() below. This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
tab2 may not be a view
80..87 ........
(<tbl> MATCH ? ORDER BY rank)
A regular INSERT, UPDATE or DELETE statement. The trick here is that
** any conflict on the rowid value must be detected before any
** modifications are made to the database file. There are 4 cases:
**
** 1) DELETE
** 2) UPDATE (rowid not modified)
** 3) UPDATE (rowid modified)
** 4) INSERT
**
** Cases 3 and 4 may violate the rowid constraint.
Allocate and initialize the hash-table used to store tokenizers.
True if current operation is a delete
Parse the filename/URI argument
**
** Only allow sensible combinations of bits in the flags argument.
** Throw an error if any non-sense combination is used. If we
** do not block illegal combinations here, it could trigger
** assert() statements in deeper layers. Sensible combinations
** are:
**
** 1: SQLITE_OPEN_READONLY
** 2: SQLITE_OPEN_READWRITE
** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
Resolve the references in the WHERE clause.
** Decode the "end_block" field, selected by column iCol of the SELECT
** statement passed as the first argument.
**
** The "end_block" field may contain either an integer, or a text field
** containing the text representation of two non-negative integers separated
** by one or more space (0x20) characters. In the first case, set *piEndBlock
** to the integer value and *pnByte to zero before returning. In the second,
** set *piEndBlock to the first value and *pnByte to the second.
Initialize a tokenizer iterator to iterate through column iCol.
** Discard all pages from cache pCache with a page number (key value)
** greater than or equal to iLimit. Any pinned pages that meet this
** criteria are unpinned before they are discarded.
**
** The PCache mutex must be held when this function is called.
13
Open the table. Loop through all rows of the table, inserting index
** records into the sorter.
Opcode: IdxLE P1 P2 P3 P4 P5
** Synopsis: key=r[P3@P4]
**
** The P4 register values beginning with P3 form an unpacked index
** key that omits the PRIMARY KEY or ROWID. Compare this key value against
** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
** ROWID on the P1 index.
**
** If the P1 index entry is less than or equal to the key value then jump
** to P2. Otherwise fall through to the next instruction.
Fd for main db of dbRbu
This code runs once to initialize everything.
** Set the soft heap-size limit for the library. Passing a zero or
** negative value indicates no limit.
Size of utf-16 input string in bytes
*************** End of %include directives *********************************
** Add a new column to the table currently being constructed.
**
** The parser calls this routine once for each column declaration
** in a CREATE TABLE statement. sqlite3StartTable() gets called
** first to get things going. Then this routine is called for each
** column.
** Each cache entry is represented by an instance of the following
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
** in memory.
If this is an auto-vacuum database, update the pointer map
** with entries for the new page, and any pointer from the
** cell on the page to an overflow page. If either of these
** operations fails, the return code is set, but the contents
** of the parent page are still manipulated by thh code below.
** That is Ok, at this point the parent page is guaranteed to
** be marked as dirty. Returning an error code will cause a
** rollback, undoing any changes made to the parent page.
** This routine is called when a commit occurs.
Decode the page just read from disk
case PragTyp_BUSY_TIMEOUT
If this is a DELETE or UPDATE operation, remove the old record.
Seek opcode
comment: TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
** of all sub-scans required by the OR-scan. However, due to rounding
** errors, it may be that the cost of the OR-scan is equal to its
** most expensive sub-scan. Add the smallest possible penalty
** (equivalent to multiplying the cost by 1.07) to ensure that
** this does not happen. Otherwise, for WHERE clauses such as the
** following where there is an index on "y":
**
** WHERE likelihood(x=?, 0.99) OR y=?
**
** the planner may elect to "OR" together a full-table scan and an
** index lookup. And other similarly odd results.
label: code-design
sqlite3_int64, sqlite3_int64
If no zContent option was specified, fill in the default values.
SQLITE_BLDF_* flags
Two or more OR-connected terms
comment:
** Return FALSE if there is no chance that the expression can be NULL.
**
** If the expression might be NULL or if the expression is too complex
** to tell return TRUE.
**
** This routine is used as an optimization, to skip OP_IsNull opcodes
** when we know that a value cannot be NULL. Hence, a false positive
** (returning TRUE when in fact the expression can never be NULL) might
** be a small performance hit but is otherwise harmless. On the other
** hand, a false negative (returning FALSE when the result could be NULL)
** will likely result in an incorrect answer. So when in doubt, return
** TRUE.
label: code-design
SQLITE_OS_SETUP_H
** Default synchronous levels.
**
** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ
** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
**
** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS
** OFF 1 0
** NORMAL 2 1
** FULL 3 2
** EXTRA 4 3
**
** The "PRAGMA synchronous" statement also uses the zero-based numbers.
** In other words, the zero-based numbers are used for all external interfaces
** and the one-based values are used internally.
NEAR parameter
Store the SELECT statement in pRight so it will be deleted when
** sqlite3ExprListDelete() is called
Table being queried
Only change the value of sqlite.enc if the database handle is not
** initialized. If the main database exists, the new sqlite.enc value
** will be overwritten when the schema is next loaded. If it does not
** already exists, it will be created to use the new encoding value.
The JSON that is being patched
SQLITE_OMIT_DEPRECATED
Database filename (UTF-16)
(322) kwcolumn_opt ::= COLUMNKW
The following condition causes URIs with five leading / characters
** like file://///host/path to be converted into UNCs like //host/path.
** The correct URI for that UNC has only two or four leading / characters
** file://host/path or file:////host/path. But 5 leading slashes is a
** common error, we are told, so we handle it as a special case.
Expected pointer map parent page number
Do not allow any cells smaller than 4 bytes. If a smaller cell
** does exist, pad it with 0x00 bytes.
(rowid = ?)
** Check to see if there are references to columns in table
** pWalker->u.pIdxCover->iCur can be satisfied using the index
** pWalker->u.pIdxCover->pIdx.
New virtual table object
** An instance of the following structure represents a single search term
** or term prefix.
create_table_args ::= AS select
Chunk size configured by FCNTL_CHUNK_SIZE
comment:
** This function is called to drop a trigger from the database schema.
**
** This may be called directly from the parser and therefore identifies
** the trigger by name. The sqlite3DropTriggerPtr() routine does the
** same job as this routine except it takes a pointer to the trigger
** instead of the trigger name.
*
label: code-design
** Allowed values for Table.tabFlags.
**
** TF_OOOHidden applies to tables or view that have hidden columns that are
** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
** the TF_OOOHidden attribute would apply in this case. Such tables require
** special handling during INSERT processing.
The AND operator in x>=y AND x<=z
Index on key columns in pTo
** End of interface to code in fts5_config.c.
*************************************************************************
Number of prefix indexes
Changes list if ON UPDATE CASCADE
comment: The following blocks should probably assert in debug mode, but they
are to cleanup in case any locks remained open
label: code-design
Total number of pages in database file
case_else ::= ELSE expr
Mark a single page as clean
Zero or more SQLITE_PREPARE_ flags
Error message from sqlite3_mprintf()
Sum of ref counts over all pages
Open a read-only cursor on the index being analyzed.
first rowid on page
Number of matchable phrases in query
mutex
** This function is called when the user invokes "PRAGMA wal_checkpoint",
** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint()
** or wal_blocking_checkpoint() API functions.
**
** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
Search for equality and range constraints on the "term" column.
** And equality constraints on the hidden "languageid" column.
Number of bytes to return.
Page size must be a power of 2
Fallback loop must terminate
Memory management strategy for zName
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
Index into Parse.aAlias[] for zName
Fall through into OP_Function
** The first argument, pCur, is a cursor opened on some b-tree. Count the
** number of entries in the b-tree and write the result to *pnEntry.
**
** SQLITE_OK is returned if the operation is successfully executed.
** Otherwise, if an error is encountered (i.e. an IO error or database
** corruption) an SQLite error code is returned.
Rtree table
If this is an UPDATE OF <column-list> trigger,
the <column-list> is stored here
** This routine generates the code needed to write autoincrement
** maximum rowid values back into the sqlite_sequence register.
** Every statement that might do an INSERT into an autoincrement
** table (either directly or through triggers) needs to call this
** routine just before the "exit" code.
*
Non-zero if locking is disabled.
Write the page data
func or agg-step
Offset of start of buffer in file
comment: TODO: Do we need this if the leaf-index is appended? Probably...
label: code-design
synopsis: Start at P2
** Generate code to drop and reload the internal representation of table
** pTab from the database, including triggers and temporary triggers.
** Argument zName is the name of the table in the database schema at
** the time the generated code is executed. This can be different from
** pTab->zName if this function is being called to code part of an
** "ALTER TABLE RENAME TO" statement.
The vector inequality constraint
182
Do not allow backup if the destination database is in WAL mode
** and the page sizes are different between source and destination
** Free all memory associated with foreign key definitions attached to
** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
** hash table.
If pState is NULL, then the wal file may not have been opened and
** recovered. Running a read-statement here to ensure that doing so
** does not interfere with the "capture" process below.
Cursor snippet is being generated from
OOM
True to enable memory status
Value extracted from record
Try to delete the WAL file if the checkpoint completed and
** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
** mode (!bPersist)
If the user specified a negative value for the languageid, use zero
** instead. This works, as the "languageid=?" constraint will also
** be tested by the VDBE layer. The test will always be false (since
** this module will not return a row with a negative languageid), and
** so the overall query will return zero rows.
Parent table that child points to
Subroutine return code
Pointer to a single WhereLoop object
** Append a single varint to a PendingList buffer. SQLITE_OK is returned
** if successful, or an SQLite error code otherwise.
**
** This function also serves to allocate the PendingList structure itself.
** For example, to create a new PendingList structure containing two
** varints:
**
** PendingList *p = 0;
** fts3PendingListAppendVarint(&p, 1);
** fts3PendingListAppendVarint(&p, 2);
Skip any MATCH_ALL or MATCH_ONE characters that follow a
** MATCH_ALL. For each MATCH_ONE, skip one character in the
** test string.
** Initialize the mutex system.
** If X and Y are NULL (in other words if only the column name Z is
** supplied) and the value of Z is enclosed in double-quotes, then
** Z is a string literal if it doesn't match any column names. In that
** case, we need to return right away and not make any changes to
** pExpr.
**
** Because no reference was made to outer contexts, the pNC->nRef
** fields are not changed in any context.
Cursor object to populate
** The following routines implement the various date and time functions
** of SQLite.
0=Monday, 1=Tuesday, ... 6=Sunday
Type of the container - used for error messages
getenv("SQLITE_TMPDIR")
** Perform a shift action.
Works for compilers other than LLVM
It is not possible to do a full assert_pager_state() here, as this
** function may be called from within PagerOpen(), before the state
** of the Pager object is internally consistent.
**
** At one point this function returned an error if the pager was in
** PAGER_ERROR state. But since PAGER_ERROR state guarantees that
** there is at least one outstanding page reference, this function
** is a no-op for that case anyhow.
Find the next free blockid in the %_segments table
True for an update, false otherwise
** Find and return the schema associated with a BTree. Create
** a new one if necessary.
Second arg to matchinfo() function
IMPLEMENTATION-OF: R-49045-42493 SQLite will use the xCurrentTimeInt64()
** method to get the current date and time if that method is available
** (if iVersion is 2 or greater and the function pointer is not NULL) and
** will fall back to xCurrentTime() if xCurrentTimeInt64() is
** unavailable.
Expr list from which to derive column names
Cursor to receive the page, or NULL
Table cursor common to all terms
List of binary trees of entries
Index of PmaReader to advance
OUT: Length of *ppOffsetList in bytes
comment: Table type - an RBU_PK_XXX value
label: code-design
** Default maximum size of memory used by memory-mapped I/O in the VFS
** Return the best representation of pMem that we can get into a
** double. If pMem is already a double or an integer, return its
** value. If it is a string or blob, try to convert it to a double.
** If it is a NULL, return 0.0.
comment:
** This is the obsolete pcache_methods object that has now been replaced
** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
** retained in the header file for backwards compatibility only.
label: code-design
1390
comment:
** The first argument must be a nul-terminated string. This function
** returns a copy of the string in memory obtained from sqlite3_malloc().
** It is the responsibility of the caller to eventually free this memory
** using sqlite3_free().
**
** If an OOM condition is encountered when attempting to allocate memory,
** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
** if the allocation succeeds, (*pRc) is left unchanged.
label: code-design
SQLITE_OMIT_AUTHORIZATION
generate the SELECT expression tree.
Index of the database holding pTab
Previous element in list of dirty pages
OUT: Pointer to buffer containing data
distinct ::= DISTINCT
Address of OP_OpenEphemeral instruction
root
Decode the arguments passed through to this function.
**
** Note: The following set of if(...) statements must be in the same
** order as the corresponding entries in the struct at the top of
** fts5BestIndexMethod().
Virtual table configuration
** Given a page number of a regular database page, return the page
** number for the pointer-map page that contains the entry for the
** input page number.
**
** Return 0 (not a valid page) for pgno==1 since there is
** no pointer map associated with page 1. The integrity_check logic
** requires that ptrmapPageno(*,1)!=1.
EVIDENCE-OF: R-10421-19736 If any other process is running a
** checkpoint operation at the same time, the lock cannot be obtained and
** SQLITE_BUSY is returned.
** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
** it will not be invoked in this case.
** The maximum (and only) versions of the wal and wal-index formats
** that may be interpreted by this version of SQLite.
**
** If a client begins recovering a WAL file and finds that (a) the checksum
** values in the wal-header are correct and (b) the version field is not
** WAL_MAX_VERSION, recovery fails and SQLite returns SQLITE_CANTOPEN.
**
** Similarly, if a client successfully reads a wal-index header (i.e. the
** checksum test is successful) and finds that the version field is not
** WALINDEX_MAX_VERSION, then no read-transaction is opened and SQLite
** returns SQLITE_CANTOPEN.
Parent savepoint (if any)
assert( seenReplace==0 );
Used by: index_xinfo
** Based on the primary key values stored in change aRecord, calculate a
** hash key. Assume the has table has nBucket buckets. The hash keys
** calculated by this function are compatible with those calculated by
** sessionPreupdateHash().
**
** The bPkOnly argument is non-zero if the record at aRecord[] is from
** a patchset DELETE. In this case the non-PK fields are omitted entirely.
Zero pad
** Change the error string stored in Vdbe.zErrMsg
synopsis: r[P3]=PX
EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
** integer.
** Convert the JsonNode pNode into a pure JSON string and
** append to pOut. Subsubstructure is also included. Return
** the number of JsonNode objects that are encoded.
New Pager.aSavepoint array
Verify that all AggInfo registers are within the range specified by
** AggInfo.mnReg..AggInfo.mxReg
***************************************************************************
**************************** sqlite3_vfs methods ****************************
**
** This division contains the implementation of methods on the
** sqlite3_vfs object.
Name of column in parent table
True to ignore xSavepoint invocations
** The default initial allocation for the pagecache when using separate
** pagecaches for each database connection. A positive number is the
** number of pages. A negative number N translations means that a buffer
** of -1024*N bytes is allocated and used for as many pages as it will hold.
**
** The default value of "20" was choosen to minimize the run-time of the
** speedtest1 test program with options: --shrink-memory --reprepare
Seek the table cursor, if required
** Return SQLITE_CORRUPT_VTAB.
************* End of backup.c *********************************************
If p holds a string or blob, the Mem.z must point to exactly
** one of the following:
**
** (1) Memory in Mem.zMalloc and managed by the Mem object
** (2) Memory to be freed using Mem.xDel
** (3) An ephemeral string or blob
** (4) A static string or blob
SYNC_NORMAL or SYNC_FULL for wal writes
Datatype of the argument to the memory allocated passed as the
** second argument to sqlite3ParserAlloc() below. This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
SQL for the statement
#ifndef SQLITE_OMIT_FOREIGN_KEY
If not NULL, info on how to process ORDER BY
Output the final row of result
Sizes of deleted document written here
** Close the blob handle at p->pSegments, if it is open. See comments above
** the sqlite3Fts3ReadBlock() function for details.
** CAPI3REF: Virtual Table Object
** KEYWORDS: sqlite3_module {virtual table module}
**
** This structure, sometimes called a "virtual table module",
** defines the implementation of a [virtual tables].
** This structure consists mostly of methods for the module.
**
** ^A virtual table module is created by filling in a persistent
** instance of this structure and passing a pointer to that instance
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
** ^The registration remains valid until it is replaced by a different
** module or until the [database connection] closes. The content
** of this structure must not change while it is registered with
** any database connection.
6-byte signed integer
Access permission denied
Check this handle's interrupt flag
if the conch isn't writable and doesn't match, we can't take it
READWRITE | CREATE
comment: Unused
label: code-design
Index (0..Fts3Table.nIndex-1)
** Obtain the STATIC_MASTER mutex.
OUT: Set to true if constraint may cause a replace
comment:
** Return a pointer to a buffer containing a text representation of the
** expression passed as the first argument. The buffer is obtained from
** sqlite3_malloc(). It is the responsibility of the caller to use
** sqlite3_free() to release the memory. If an OOM condition is encountered,
** NULL is returned.
**
** If the second argument is not NULL, then its contents are prepended to
** the returned expression text and then freed using sqlite3_free().
label: code-design
Average number of tokens in each row
Global context for this function
Activation phrase
Evaluate the current GROUP BY terms and store in b0, b1, b2...
** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
** Then compare the current GROUP BY terms against the GROUP BY terms
** from the previous row currently stored in a0, a1, a2...
** Do up to nPg pages of automerge work on the index.
**
** Return true if any changes were actually made, or false otherwise.
** The remainder of this file contains the declarations of the functions
** that make up the Pager sub-system API. See source code comments for
** a detailed description of each routine.
B-Tree Database
TUNING: Cost of full table scan is (N*3.0).
The ',' token after the last column defn.
All conditions meet
Acceptable operators
** Structure used to store the context required by the
** sqlite3_preupdate_*() API functions.
The major token value. This is the code
** number for the token at this stack level
Return the results
Argument to xRollbackCallback()
Sorted index for this segment
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.
**
** If an error occurs, an error code is returned and *pp is set to NULL.
**
** Otherwise, if the bExtend parameter is 0 and the requested shared-memory
** region has not been allocated (by any client, including one running in a
** separate process), then *pp is set to NULL and SQLITE_OK returned. If
** bExtend is non-zero and the requested shared-memory region has not yet
** been allocated, it is allocated by this function.
**
** If the shared-memory region has already been allocated or is allocated by
** this call as described above, then it is mapped into this processes
** address space (if it is not already), *pp is set to point to the mapped
** memory and SQLITE_OK returned.
WAL handle
** The next global variable records the size of the largest MEM_Blob
** or MEM_Str that has been used by a VDBE opcode. The test procedures
** use this information to make sure that the zero-blob functionality
** is working correctly. This variable has no function other than to
** help verify the correct operation of the library.
Unless this is a view, open cursors for the table we are
** deleting from and all its indices. If this is a view, then the
** only effect this statement has is to fire the INSTEAD OF
** triggers.
Figure out the effective temporary directory. First, check if one
** has been explicitly set by the application; otherwise, use the one
** configured by the operating system.
One of TK_UNION, TK_EXCEPT etc.
PmaReader to populate
DELETE
Must be compatible with this index, if not NULL
Number of slots in aOut[]
P4 is a pointer to a Table structure
Docs in descending rowid order
ifndef SQLITE_OMIT_WAL
fts3_snippet.c
comment:
* If this is non-zero, an isolated heap will be created by the native Win32
* allocator subsystem; otherwise, the default process heap will be used. This
* setting has no effect when compiling for WinRT. By default, this is enabled
* and an isolated heap will be created to store all allocated data.
*
******************************************************************************
* WARNING: It is important to note that when this setting is non-zero and the
* winMemShutdown function is called (e.g. by the sqlite3_shutdown
* function), all data that was allocated using the isolated heap will
* be freed immediately and any attempt to access any of that freed
* data will almost certainly result in an immediate access violation.
******************************************************************************
label: code-design
** Make yytestcase() the same as testcase()
True if attempting to insert into a view
130
Open file descriptor on path
Mask of function arguments that are constant
Number of columns in result set
SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; );
Unless the pager is in noSync mode, the journal file was just
** successfully synced. Either way, clear the PGHDR_NEED_SYNC flag on
** all pages.
Set *pCurrent to non-zero if there are unresolved deferred foreign
** key constraints. Set *pCurrent to zero if all foreign key constraints
** have been satisfied. The *pHighwater is always set to zero.
Verify that the database file has not be deleted or renamed out from
** under the pager. Return SQLITE_OK if the database is still were it ought
** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error
** code from sqlite3OsAccess()) if the database has gone missing.
** Free the list of FileChunk structures headed at MemJournal.pFirst.
** xSetOutputs callback used by detail=full when there is a column filter.
0x70..0x7F
This is the common case where the desired content fits on the original
** page - where the content is not on an overflow page
comment: Read and write the xxx_parent table
label: code-design
** This function counts the total number of docids in the doclist stored
** in buffer aList[], size nList bytes.
**
** If the isPoslist argument is true, then it is assumed that the doclist
** contains a position-list following each docid. Otherwise, it is assumed
** that the doclist is simply a list of docids stored as delta encoded
** varints.
Insert the end of a co-routine
#include "fts3_hash.h"
** Session handle structure.
** Return the total number of references to all pages held by the cache.
**
** This is not the total number of pages referenced, but the sum of the
** reference count for all pages.
synopsis: r[P1]=max(r[P1],r[P2])
** A container for a temp file handle and the current amount of data
** stored in the file.
Callback pointers
** Valid values for the second argument to sqlite3PagerLockingMode().
Next in a list of them all
Convert to ascii
The new leaf holds no terms or rowids
0,1
2: Seek the cursor to rowid=r[1]
91
Estimated number of output rows
** Return N random bytes.
** This function changes all write-locks held by Btree p into read-locks.
List of attached tables
Current docid (if pList!=0)
Size of array apWiData
If pSynced is NULL and this page has a clear NEED_SYNC flag, set
** pSynced to point to it. Checking the NEED_SYNC flag is an
** optimization, as if pSynced points to a page with the NEED_SYNC
** flag set sqlite3PcacheFetchStress() searches through all newer
** entries of the dirty-list for a page with NEED_SYNC clear anyway.
NOTE 1
Top of the loop body
Address of the select-A-exhausted subroutine
The FROM clause of the subquery
comment:
** 2008 February 16
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements an object that represents a fixed-length
** bitmap. Bits are numbered starting with 1.
**
** A bitmap is used to record which pages of a database file have been
** journalled during a transaction, or which pages have the "dont-write"
** property. Usually only a few pages are meet either condition.
** So the bitmap is usually sparse and has low cardinality.
** But sometimes (for example when during a DROP of a large table) most
** or all of the pages in a database can get journalled. In those cases,
** the bitmap becomes dense with high cardinality. The algorithm needs
** to handle both cases well.
**
** The size of the bitmap is fixed when the object is created.
**
** All bits are clear when the bitmap is created. Individual bits
** may be set or cleared one at a time.
**
** Test operations are about 100 times more common that set operations.
** Clear operations are exceedingly rare. There are usually between
** 5 and 500 set operations per Bitvec object, though the number of sets can
** sometimes grow into tens of thousands or larger. The size of the
** Bitvec object is the number of pages in the database file at the
** start of a transaction, and is thus usually less than a few thousand,
** but can be as large as 2 billion for a really big database.
label: code-design
** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to
** a non-negative 32-bit integer before it is returned.
comment:
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains the VFS implementation for unix-like operating systems
** include Linux, MacOSX, *BSD, QNX, VxWorks, AIX, HPUX, and others.
**
** There are actually several different VFS implementations in this file.
** The differences are in the way that file locking is done. The default
** implementation uses Posix Advisory Locks. Alternative implementations
** use flock(), dot-files, various proprietary locking schemas, or simply
** skip locking all together.
**
** This source file is organized into divisions where the logic for various
** subfunctions is contained within the appropriate division. PLEASE
** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed
** in the correct division and should be clearly labeled.
**
** The layout of divisions is as follows:
**
** * General-purpose declarations and utility functions.
** * Unique file ID logic used by VxWorks.
** * Various locking primitive implementations (all except proxy locking):
** + for Posix Advisory Locks
** + for no-op locks
** + for dot-file locks
** + for flock() locking
** + for named semaphore locks (VxWorks only)
** + for AFP filesystem locks (MacOSX only)
** * sqlite3_file methods not associated with locking.
** * Definitions of sqlite3_io_methods objects for all locking
** methods plus "finder" functions for each locking method.
** * sqlite3_vfs method implementations.
** * Locking primitives for the proxy uber-locking-method. (MacOSX only)
** * Definitions of sqlite3_vfs objects for all locking methods
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
label: code-design
Number of bytes in buffer z
Number of bytes in zTerm
** This constant should already be defined (in the "WinDef.h" SDK file).
comment: List of unused pcache-local pages
label: code-design
nCol values
************* Continuing where we left off in os_win.c ********************
EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
** a single parameter which is a pointer to an integer and writes into
** that integer the number of extra bytes per page required for each page
** in SQLITE_CONFIG_PAGECACHE.
Snippet to extract
Name of SQL function
If non-NULL, store size of record here
Write this value to the list
** Return an estimate for the number of rows in the table that pCur is
** pointing to. Return a negative number if no estimate is currently
** available.
EQP id of left-hand query
** Prepare a virtual machine for execution for the first time after
** creating the virtual machine. This involves things such
** as allocating registers and initializing the program counter.
** After the VDBE has be prepped, it can be executed by one or more
** calls to sqlite3VdbeExec().
**
** This function may be called exactly once on each virtual machine.
** After this routine is called the VM has been "packaged" and is ready
** to run. After this routine is called, further calls to
** sqlite3VdbeAddOp() functions are prohibited. This routine disconnects
** the Vdbe from the Parse object that helped generate it so that the
** the Vdbe becomes an independent entity and the Parse object can be
** destroyed.
**
** Use the sqlite3VdbeRewind() procedure to restore a virtual machine back
** to its initial state after it has been run.
Low-level file information
Total segments in this structure
comment:
** This macro is used when a local variable is set to a value that is
** [sometimes] not used by the code (e.g. via conditional compilation).
label: code-design
Store SQLITE_NOMEM here if required
Turns out that wasn't a keyword after all. This happens if the
** user has supplied a token such as "ORacle". Continue.
Index into aSub array
Node or entry ID
comment: Avoid leaking memory if malloc has failed.
label: code-design
Either "tbl" or "idx"
Add a field to the new.* record. Or the only record if currently
** generating a patchset.
Copy of pFKey->pNextFrom
180
xSync
The WhereLoop builder
We are told that some versions of Android contain a bug that
** sizes ino_t at only 32-bits instead of 64-bits. (See
** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
** To work around this, always allocate 64-bits for the inode number.
** On small machines that only have 32-bit inodes, this wastes 4 bytes,
** but that should not be a big deal.
comment: SQLITE_WIN32_MALLOC
label: code-design
** This function does the work for an sqlite3rbu_step() call.
**
** The object-iterator (p->objiter) currently points to a valid object,
** and the input cursor (p->objiter.pSelect) currently points to a valid
** input row. Perform whatever processing is required and return.
**
** If no error occurs, SQLITE_OK is returned. Otherwise, an error code
** and message is left in the RBU handle and a copy of the error code
** returned.
Extract the PRIMARY KEY from the end of the index entry and
** store it in registers regR..regR+nPk-1
getenv("TMPDIR")
Link the foreign key to the table as the last step.
True if output is already ordered
comment: If the LHS and RHS of the IN operator do not match, that
** error will have been caught long before we reach this point.
label: code-design
** Copy the values stored in the VdbeFrame structure to its Vdbe. This
** is used, for example, when a trigger sub-program is halted to restore
** control to the main program.
Number of entries in aColCache[]
In case the cursor has been used before, clear it now.
** Variables in which to record status information.
True if the DISTINCT keyword is present
** Buffers p1 and p2 contain doclists. This function merges the content
** of the two doclists together and sets buffer p1 to the result before
** returning.
**
** If an error occurs, an error code is left in p->rc. If an error has
** already occurred, this function is a no-op.
Register holding assembled record for the table
On commit, recalculate checksums from here
Parent of this frame, or NULL if parent is main
Cursor to iterate through zInput
Token to add or remove to or from index
TEMP
comment:
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser. This pointer is used in subsequent calls
** to sqlite3Parser and sqlite3ParserFree.
label: code-design
** Malloc function used by SQLite to obtain space from the buffer configured
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
** exists, this function falls back to sqlite3Malloc().
** Destroy an existing tokenizer cursor. The fts3 module calls this
** method exactly once for each successful call to xOpen().
** This function is called after the cursor passed as the only argument
** is moved to point at a different row. It clears all cached data
** specific to the previous row stored by the cursor object.
** This routine does a complete check of the given BTree file. aRoot[] is
** an array of pages numbers were each page number is the root page of
** a table. nRoot is the number of entries in aRoot.
**
** A read-only or read-write transaction must be opened before calling
** this function.
**
** Write the number of error seen in *pnErr. Except for some memory
** allocation errors, an error message held in memory obtained from
** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
** returned. If a memory allocation error occurs, NULL is returned.
Index of column to create snippet from
fullname ::= nm dbnm
** Each foreign key constraint is an instance of the following structure.
**
** A foreign key is associated with two tables. The "from" table is
** the table that contains the REFERENCES clause that creates the foreign
** key. The "to" table is the table that is named in the REFERENCES clause.
** Consider this example:
**
** CREATE TABLE ex1(
** a INTEGER PRIMARY KEY,
** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x)
** );
**
** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2".
** Equivalent names:
**
** from-table == child-table
** to-table == parent-table
**
** Each REFERENCES clause generates an instance of the following structure
** which is attached to the from-table. The to-table need not exist when
** the from-table is created. The existence of the to-table is not checked.
**
** The list of all parents for child Table X is held at X.pFKey.
**
** A list of all children for a table named Z (which might not even exist)
** is held in Schema.fkeyHash with a hash key of Z.
comment:
** An open page cache is an instance of struct Pager. A description of
** some of the more important member variables follows:
**
** eState
**
** The current 'state' of the pager object. See the comment and state
** diagram above for a description of the pager state.
**
** eLock
**
** For a real on-disk database, the current lock held on the database file -
** NO_LOCK, SHARED_LOCK, RESERVED_LOCK or EXCLUSIVE_LOCK.
**
** For a temporary or in-memory database (neither of which require any
** locks), this variable is always set to EXCLUSIVE_LOCK. Since such
** databases always have Pager.exclusiveMode==1, this tricks the pager
** logic into thinking that it already has all the locks it will ever
** need (and no reason to release them).
**
** In some (obscure) circumstances, this variable may also be set to
** UNKNOWN_LOCK. See the comment above the #define of UNKNOWN_LOCK for
** details.
**
** changeCountDone
**
** This boolean variable is used to make sure that the change-counter
** (the 4-byte header field at byte offset 24 of the database file) is
** not updated more often than necessary.
**
** It is set to true when the change-counter field is updated, which
** can only happen if an exclusive lock is held on the database file.
** It is cleared (set to false) whenever an exclusive lock is
** relinquished on the database file. Each time a transaction is committed,
** The changeCountDone flag is inspected. If it is true, the work of
** updating the change-counter is omitted for the current transaction.
**
** This mechanism means that when running in exclusive mode, a connection
** need only update the change-counter once, for the first transaction
** committed.
**
** setMaster
**
** When PagerCommitPhaseOne() is called to commit a transaction, it may
** (or may not) specify a master-journal name to be written into the
** journal file before it is synced to disk.
**
** Whether or not a journal file contains a master-journal pointer affects
** the way in which the journal file is finalized after the transaction is
** committed or rolled back when running in "journal_mode=PERSIST" mode.
** If a journal file does not contain a master-journal pointer, it is
** finalized by overwriting the first journal header with zeroes. If
** it does contain a master-journal pointer the journal file is finalized
** by truncating it to zero bytes, just as if the connection were
** running in "journal_mode=truncate" mode.
**
** Journal files that contain master journal pointers cannot be finalized
** simply by overwriting the first journal-header with zeroes, as the
** master journal pointer could interfere with hot-journal rollback of any
** subsequently interrupted transaction that reuses the journal file.
**
** The flag is cleared as soon as the journal file is finalized (either
** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
** journal file from being successfully finalized, the setMaster flag
** is cleared anyway (and the pager will move to ERROR state).
**
** doNotSpill
**
** This variables control the behavior of cache-spills (calls made by
** the pcache module to the pagerStress() routine to write cached data
** to the file-system in order to free up memory).
**
** When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set,
** writing to the database from pagerStress() is disabled altogether.
** The SPILLFLAG_ROLLBACK case is done in a very obscure case that
** comes up during savepoint rollback that requires the pcache module
** to allocate a new page to prevent the journal file from being written
** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF
** case is a user preference.
**
** If the SPILLFLAG_NOSYNC bit is set, writing to the database from
** pagerStress() is permitted, but syncing the journal file is not.
** This flag is set by sqlite3PagerWrite() when the file-system sector-size
** is larger than the database page-size in order to prevent a journal sync
** from happening in between the journalling of two pages on the same sector.
**
** subjInMemory
**
** This is a boolean variable. If true, then any required sub-journal
** is opened as an in-memory journal file. If false, then in-memory
** sub-journals are only used for in-memory pager files.
**
** This variable is updated by the upper layer each time a new
** write-transaction is opened.
**
** dbSize, dbOrigSize, dbFileSize
**
** Variable dbSize is set to the number of pages in the database file.
** It is valid in PAGER_READER and higher states (all states except for
** OPEN and ERROR).
**
** dbSize is set based on the size of the database file, which may be
** larger than the size of the database (the value stored at offset
** 28 of the database header by the btree). If the size of the file
** is not an integer multiple of the page-size, the value stored in
** dbSize is rounded down (i.e. a 5KB file with 2K page-size has dbSize==2).
** Except, any file that is greater than 0 bytes in size is considered
** to have at least one page. (i.e. a 1KB file with 2K page-size leads
** to dbSize==1).
**
** During a write-transaction, if pages with page-numbers greater than
** dbSize are modified in the cache, dbSize is updated accordingly.
** Similarly, if the database is truncated using PagerTruncateImage(),
** dbSize is updated.
**
** Variables dbOrigSize and dbFileSize are valid in states
** PAGER_WRITER_LOCKED and higher. dbOrigSize is a copy of the dbSize
** variable at the start of the transaction. It is used during rollback,
** and to determine whether or not pages need to be journalled before
** being modified.
**
** Throughout a write-transaction, dbFileSize contains the size of
** the file on disk in pages. It is set to a copy of dbSize when the
** write-transaction is first opened, and updated when VFS calls are made
** to write or truncate the database file on disk.
**
** The only reason the dbFileSize variable is required is to suppress
** unnecessary calls to xTruncate() after committing a transaction. If,
** when a transaction is committed, the dbFileSize variable indicates
** that the database file is larger than the database image (Pager.dbSize),
** pager_truncate() is called. The pager_truncate() call uses xFilesize()
** to measure the database file on disk, and then truncates it if required.
** dbFileSize is not used when rolling back a transaction. In this case
** pager_truncate() is called unconditionally (which means there may be
** a call to xFilesize() that is not strictly required). In either case,
** pager_truncate() may cause the file to become smaller or larger.
**
** dbHintSize
**
** The dbHintSize variable is used to limit the number of calls made to
** the VFS xFileControl(FCNTL_SIZE_HINT) method.
**
** dbHintSize is set to a copy of the dbSize variable when a
** write-transaction is opened (at the same time as dbFileSize and
** dbOrigSize). If the xFileControl(FCNTL_SIZE_HINT) method is called,
** dbHintSize is increased to the number of pages that correspond to the
** size-hint passed to the method call. See pager_write_pagelist() for
** details.
**
** errCode
**
** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
** sub-codes.
label: code-design
Fall through
If the handle has a write-transaction open, commit the shared-btrees
** transaction and set the shared state to TRANS_READ.
Write the file descriptor here
Context
PagerRollback() is a no-op if called in READER or OPEN state. If
** the pager is already in the ERROR state, the rollback is not
** attempted here. Instead, the error code is returned to the caller.
Index of "the page" in pParent
** Similar to fts3SqlStmt(). Except, after binding the parameters in
** array apVal[] to the SQL statement identified by eStmt, the statement
** is executed.
**
** Returns SQLITE_OK if the statement is successfully executed, or an
** SQLite error code otherwise.
Number of bytes in the BLOB
** Get a VDBE for the given parser context. Create a new one if necessary.
** If an error occurs, return NULL and leave a message in pParse.
The returned text includes up to four fragments of text extracted from
** the data in the current row. The first iteration of the for(...) loop
** below attempts to locate a single fragment of text nToken tokens in
** size that contains at least one instance of all phrases in the query
** expression that appear in the current row. If such a fragment of text
** cannot be found, the second iteration of the loop attempts to locate
** a pair of fragments, and so on.
Name of this index
************* End of prepare.c ********************************************
Space for Index.aAvgEq[]
The left operand
** When this function is called, *ppPoslist is assumed to point to the
** start of a column-list. After it returns, *ppPoslist points to the
** to the terminator (POS_COLUMN or POS_END) byte of the column-list.
**
** A column-list is list of delta-encoded positions for a single column
** within a single document within a doclist.
**
** The column-list is terminated either by a POS_COLUMN varint (1) or
** a POS_END varint (0). This routine leaves *ppPoslist pointing to
** the POS_COLUMN or POS_END that terminates the column-list.
**
** If pp is not NULL, then the contents of the column-list are copied
** to *pp. *pp is set to point to the first byte past the last byte copied
** before this function returns. The POS_COLUMN or POS_END terminator
** is not copied into *pp.
** Advance the snippet iterator to the next candidate snippet.
** Deallocate internal memory used by a WhereLoop object
** Return the full pathname of the database file.
**
** Except, if the pager is in-memory only, then return an empty string if
** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when
** used to report the filename to the user, for compatibility with legacy
** behavior. But when the Btree needs to know the filename for matching to
** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
** participate in shared-cache.
Name context for sub-vdbe
First try to find another RBU vfs lower down in the vfs stack. If
** one is found, this vfs will operate in pass-through mode. The lower
** level vfs will do the special RBU handling.
comment:
** The SELECT statement iterating through the keys for the current object
** (p->objiter.pSelect) currently points to a valid row. This function
** determines the type of operation requested by this row and returns
** one of the following values to indicate the result:
**
** * RBU_INSERT
** * RBU_DELETE
** * RBU_IDX_DELETE
** * RBU_UPDATE
**
** If RBU_UPDATE is returned, then output variable *pzMask is set to
** point to the text value indicating the columns to update.
**
** If the rbu_control field contains an invalid value, an error code and
** message are left in the RBU handle and zero returned.
label: code-design
comment: This routine is never called after sqlite3RowSetNext()
label: requirement
Context that contains this SELECT
Array of WhereLoop objects implementing this path
Register to hold name of table
List of columns to extract.
Bitmask of db->aDb[] entries referenced
** Delete all information from the single table that pCur is open on.
**
** This routine only work for pCur on an ephemeral table.
'+'
Iterates through set of root pages
Values to insert into the %_idx table
Total number of segments
Template WhereLoop under construction
** An instance of the following structure keeps track of a mapping
** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
**
** The VDBE cursor numbers are small integers contained in
** SrcList_item.iCursor and Expr.iTable fields. For any given WHERE
** clause, the cursor numbers might not begin with 0 and they might
** contain gaps in the numbering sequence. But we want to make maximum
** use of the bits in our bitmasks. This structure provides a mapping
** from the sparse cursor numbers into consecutive integers beginning
** with 0.
**
** If WhereMaskSet.ix[A]==B it means that The A-th bit of a Bitmask
** corresponds VDBE cursor number B. The A-th bit of a bitmask is 1<<A.
**
** For example, if the WHERE clause expression used these VDBE
** cursors: 4, 5, 8, 29, 57, 73. Then the WhereMaskSet structure
** would map those cursor numbers into bits 0 through 5.
**
** Note that the mapping is not necessarily ordered. In the example
** above, the mapping might go like this: 4->3, 5->1, 8->2, 29->0,
** 57->5, 73->4. Or one of 719 other combinations might be used. It
** does not really matter. What is important is that sparse cursor
** numbers all get mapped into bit numbers that begin with 0 and contain
** no gaps.
Type of test to make on this file
** Like sqlite3ExprCompare() except COLLATE operators at the top-level
** are ignored.
** 2009 March 3
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the implementation of the sqlite3_unlock_notify()
** API method and its associated functionality.
Number of bytes in nKey
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
** intended for use only inside assert() statements. On some platforms,
** there might be race conditions that can cause these routines to
** deliver incorrect results. In particular, if pthread_equal() is
** not an atomic operation, then these routines might delivery
** incorrect results. On most platforms, pthread_equal() is a
** comparison of two integers and is therefore atomic. But we are
** told that HPUX is not such a platform. If so, then these routines
** will not always work correctly on HPUX.
**
** On those platforms where pthread_equal() is not atomic, SQLite
** should be compiled without -DSQLITE_DEBUG and with -DNDEBUG to
** make sure no assert() statements are evaluated and hence these
** routines are never called.
Number of result rows written here
OUT: Position integer of token
using_opt ::=
The cursor for the index
Original JSON string
** CAPI3REF: Compare the ages of two snapshot handles.
** EXPERIMENTAL
**
** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
** of two valid snapshot handles.
**
** If the two snapshot handles are not associated with the same database
** file, the result of the comparison is undefined.
**
** Additionally, the result of the comparison is only valid if both of the
** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
** last time the wal file was deleted. The wal file is deleted when the
** database is changed back to rollback mode or when the number of database
** clients drops to zero. If either snapshot handle was obtained before the
** wal file was last deleted, the value returned by this function
** is undefined.
**
** Otherwise, this API returns a negative value if P1 refers to an older
** snapshot than P2, zero if the two handles refer to the same database
** snapshot, and a positive value if P1 is a newer snapshot than P2.
Assembled sorter record
** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
**
** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
** otherwise.
** Execute the following SQL:
**
** DELETE FROM %_data WHERE id BETWEEN $iFirst AND $iLast
Increment the nRef value on all name contexts from TopNC up to
** the point where the name matched.
True for "ORDER BY rowid DESC"
Prerequisites of the new entry
Register the result column names for pragmas that return results
comment:
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated. SQLite
** will unwind its stack and return an error. The argument
** to sqlite3_mutex_alloc() is one of these integer constants:
**
** <ul>
** <li> SQLITE_MUTEX_FAST
** <li> SQLITE_MUTEX_RECURSIVE
** <li> SQLITE_MUTEX_STATIC_MASTER
** <li> SQLITE_MUTEX_STATIC_MEM
** <li> SQLITE_MUTEX_STATIC_OPEN
** <li> SQLITE_MUTEX_STATIC_PRNG
** <li> SQLITE_MUTEX_STATIC_LRU
** <li> SQLITE_MUTEX_STATIC_PMEM
** <li> SQLITE_MUTEX_STATIC_APP1
** <li> SQLITE_MUTEX_STATIC_APP2
** <li> SQLITE_MUTEX_STATIC_APP3
** <li> SQLITE_MUTEX_STATIC_VFS1
** <li> SQLITE_MUTEX_STATIC_VFS2
** <li> SQLITE_MUTEX_STATIC_VFS3
** </ul>
**
** The first two constants cause sqlite3_mutex_alloc() to create
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
** The mutex implementation does not need to make a distinction
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
** not want to. But SQLite will only request a recursive mutex in
** cases where it really needs one. If a faster non-recursive mutex
** implementation is available on the host platform, the mutex subsystem
** might return such a mutex in response to SQLITE_MUTEX_FAST.
**
** The other allowed parameters to sqlite3_mutex_alloc() each return
** a pointer to a static preexisting mutex. Six static mutexes are
** used by the current version of SQLite. Future versions of SQLite
** may add additional static mutexes. Static mutexes are for internal
** use by SQLite only. Applications that use SQLite mutexes should
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
** SQLITE_MUTEX_RECURSIVE.
**
** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call. But for the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
label: code-design
Name of the virtual table
comment:
** Return a pointer to the "temporary page" buffer held internally
** by the pager. This is a buffer that is big enough to hold the
** entire content of a database page. This buffer is used internally
** during rollback and will be overwritten whenever a rollback
** occurs. But other modules are free to use it too, as long as
** no rollbacks are happening.
label: code-design
Output cursor
Next and previous elements in the table
If the sorter uses more than one task, then create the top-level
** MergeEngine here. This MergeEngine will read data from exactly
** one PmaReader per sub-task.
** Designate the PRIMARY KEY for the table. pList is a list of names
** of columns that form the primary key. If pList is NULL, then the
** most recently added column of the table is the primary key.
**
** A table can have at most one primary key. If the table already has
** a primary key (and this is the second primary key) then create an
** error.
**
** If the PRIMARY KEY is on a single column whose datatype is INTEGER,
** then we will try to use that column as the rowid. Set the Table.iPKey
** field of the table under construction to be the index of the
** INTEGER PRIMARY KEY column. Table.iPKey is set to -1 if there is
** no INTEGER PRIMARY KEY.
**
** If the key is not an INTEGER PRIMARY KEY, then create a unique
** index for the key. No index is created for INTEGER PRIMARY KEYs.
If Pager.errCode is set, the contents of the pager cache cannot be
** trusted. Now that there are no outstanding references to the pager,
** it can safely move back to PAGER_OPEN state. This happens in both
** normal and exclusive-locking mode.
True if zBuf is static space
** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
** is a no-op. Otherwise, it adds a single row of output to the EQP result,
** where the caption is of one of the two forms:
**
** "COMPOSITE SUBQUERIES iSub1 and iSub2 (op)"
** "COMPOSITE SUBQUERIES iSub1 and iSub2 USING TEMP B-TREE (op)"
**
** where iSub1 and iSub2 are the integers passed as the corresponding
** function parameters, and op is the text representation of the parameter
** of the same name. The parameter "op" must be one of TK_UNION, TK_EXCEPT,
** TK_INTERSECT or TK_ALL. The first form is used if argument bUseTmp is
** false, or the second form if it is true.
If there is data, jump to P2
Should >=0 for apSub element.
!defined(SQLITE_OMIT_FLOATING_POINT)
Skip any leading divider characters.
The column for the index
For interrupt flag
Net deferred immediate constraints
************* Begin file resolve.c ****************************************
List of docids for full-text queries
** 2006 June 10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to help implement virtual tables.
The result set that needs to be DISTINCT
(317) trnm ::= nm
The SELECT statement holding pOrderBy
** Two versions of the official API. Legacy and new use. In the legacy
** version, the original SQL text is not saved in the prepared statement
** and so if a schema change occurs, SQLITE_SCHEMA is returned by
** sqlite3_step(). In the new version, the original SQL text is retained
** and the statement is automatically recompiled if an schema change
** occurs.
Record best loops here, if not NULL
ifndef SQLITE_AMALGAMATION
Any loop using an appliation-defined index (or PRIMARY KEY or
** UNIQUE constraint) with one or more == constraints is better
** than an automatic index. Unless it is a skip-scan.
Data for the current row, if all on one page
Expressions of the form: CAST(pLeft AS token)
Current offset within zIn[]
List may have been edited in place by fts3EvalNearTrim()
Array of Vdbe cursors for parent frame
Size of buffer after writing tbl header
Number of valid bytes in zDb
Number of bytes in a varint
Number of valid fields currently in pRec
At this point, both p1 and p2 point to the start of column-lists
** for the same column (the column with index iCol1 and iCol2).
** A column-list is a list of non-negative delta-encoded varints, each
** incremented by 2 before being stored. Each list is terminated by a
** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
** and writes the results to buffer p. p is left pointing to the byte
** after the list written. No terminator (POS_END or POS_COLUMN) is
** written to the output.
Expression of which pNode is a part
1 byte past EOF for this PmaReader
New Select.pEList for RHS
Free this WITH object at the end of the parse
tab1 must not be a virtual table
Cursor pointing to entry to read from
synopsis: r[P2]=data
True after snippet is shifted
WHERENAMEAFTEREPLACEANDEFAULTAUTOINCREMENTCASTCOLUMNCOMMIT
IMP: R-51689-46548
At this point we have established that the statement is of the
** correct syntactic form to participate in this optimization. Now
** we have to check the semantics.
Thousands separator for %d and %u
Open cursor iTabCur+j if aToOpen[j] is true
Add the entry to the main terms index.
Old rowid
** Return true if the argument is non-NULL and the WAL module is using
** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
** WAL module is using shared-memory, return false.
** This function is registered as the module destructor (called when an
** FTS3 enabled database connection is closed). It frees the memory
** allocated for the tokenizer hash table.
** Return the current pager state
Function call context
** Maximum pathname length (in bytes) for WinNT. This should normally be
** UNICODE_STRING_MAX_CHARS * sizeof(WCHAR).
** Generate code for the ANALYZE command. The parser calls this routine
** when it recognizes an ANALYZE command.
**
** ANALYZE -- 1
** ANALYZE <database> -- 2
** ANALYZE ?<database>.?<tablename> -- 3
**
** Form 1 causes all indices in all attached databases to be analyzed.
** Form 2 analyzes all indices the single database named.
** Form 3 analyzes all indices associated with the named table.
ifndef SQLITE_OMIT_SHARED_CACHE
Recursive representation
** Query to see if the entry in the %_segments table with blockid iEnd is
** NULL. If no error occurs and the entry is NULL, set *pbRes 1 before
** returning. Otherwise, set *pbRes to 0.
**
** Or, if an error occurs while querying the database, return an SQLite
** error code. The final value of *pbRes is undefined in this case.
**
** This is used to test if a segment is an "appendable" segment. If it
** is, then a NULL entry has been inserted into the %_segments table
** with blockid %_segdir.end_block.
True if only the inner-most loop is ordered
EV: R-30323-21917
.xDel =
WHERE_ONEROW would have been helpful
Opcode: Checkpoint P1 P2 P3 * *
**
** Checkpoint database P1. This is a no-op if P1 is not currently in
** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
** SQLITE_BUSY or not, respectively. Write the number of pages in the
** WAL after the checkpoint into mem[P3+1] and the number of pages
** in the WAL that have been checkpointed after the checkpoint
** completes into mem[P3+2]. However on an error, mem[P3+1] and
** mem[P3+2] are initialized to -1.
Id of this connection within its unixShmNode
** Write data to the file.
Do an integrity check of the B-Tree
**
** Begin by finding the root pages numbers
** for all tables and indices in the database.
** Check that the entry in the pointer-map for page iChild maps to
** page iParent, pointer type ptrType. If not, append an error message
** to pCheck.
** Write page pPg onto the end of the rollback journal.
Use a recursive mutex if it is available
Allocate cursors numbers for Queue and Distinct. The cursor number for
** the Distinct table must be exactly one greater than Queue in order
** for the SRT_DistFifo and SRT_DistQueue destinations to work.
pPager->pLast = 0;
Number of assigned cursor values
Do not save this cursor
Check if the index cursor is past the end of the range.
Check for variable references only
** Two of the file mapping APIs are different under WinRT. Figure out which
** set we need.
Insert the new freeblock into the freelist
** Read a varint value from aBuf[] into *piVal. Return the number of
** bytes read.
Top of the IN loop
SQLITE_STMTSTATUS_AUTOINDEX
if there wasn't a hash collision, and this doesn't
Assumed sector size during rollback
Normal case - r-tree scan. Set up the RtreeCursor.aConstraint array
** with the configured constraints.
Source page size
** The argument is an RtreeCoord. Return the value stored within the RtreeCoord
** formatted as a RtreeDValue (double or int64). This macro assumes that local
** variable pRtree points to the Rtree structure associated with the
** RtreeCoord.
Step 1a
no space allocated, yet.
... printf arguments
Insert code to test for implied constraints based on transitivity
** of the "==" operator.
**
** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
** and we are coding the t1 loop and the t2 loop has not yet coded,
** then we cannot use the "t1.a=t2.b" constraint, but we can code
** the implied "t1.a=123" constraint.
** Purge the winShmNodeList list of all entries with winShmNode.nRef==0.
**
** This is not a VFS shared-memory method; it is a utility function called
** by VFS shared-memory methods.
225
Expression to consider
comment:
** Internally, each RBU connection uses a separate SQLite database
** connection to access the target and rbu update databases. This
** API allows the application direct access to these database handles.
**
** The first argument passed to this function must be a valid, open, RBU
** handle. The second argument should be passed zero to access the target
** database handle, or non-zero to access the rbu update database handle.
** Accessing the underlying database handles may be useful in the
** following scenarios:
**
** * If any target tables are virtual tables, it may be necessary to
** call sqlite3_create_module() on the target database handle to
** register the required virtual table implementations.
**
** * If the data_xxx tables in the RBU source database are virtual
** tables, the application may need to call sqlite3_create_module() on
** the rbu update db handle to any required virtual table
** implementations.
**
** * If the application uses the "rbu_delta()" feature described above,
** it must use sqlite3_create_function() or similar to register the
** rbu_delta() implementation with the target database handle.
**
** If an error has occurred, either while opening or stepping the RBU object,
** this function may return NULL. The error code and message may be collected
** when sqlite3rbu_close() is called.
**
** Database handles returned by this function remain valid until the next
** call to any sqlite3rbu_xxx() function other than sqlite3rbu_db().
label: code-design
25
Index to match column of
Name of this CTE
1st argument
Logarithm of the number of rows in the table
Do not attempt to change the page size for a WAL database
** Return the number of references to the page supplied as an argument.
If everything went according to plan, link the new VTable structure
** into the linked list headed by pTab->pVTable. Then loop through the
** columns of the table to see if any of them contain the token "hidden".
** If so, set the Column COLFLAG_HIDDEN flag and remove the token from
** the type string.
Opcode: CollSeq P1 * * P4
**
** P4 is a pointer to a CollSeq object. If the next call to a user function
** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
** be returned. This is used by the built-in min(), max() and nullif()
** functions.
**
** If P1 is not zero, then it is a register that a subsequent min() or
** max() aggregate will set to 1 if the current row is not the minimum or
** maximum. The P1 register is initialized to 0 by this instruction.
**
** The interface used by the implementation of the aforementioned functions
** to retrieve the collation sequence set by this opcode is not available
** publicly. Only built-in functions have access to this feature.
VDBE has already been allocated
IMP: R-06824-28531
p cannot be part of a CHECK constraint
Allocate a cursors for the main database table and for all indices.
** The index cursors might not be used, but if they are used they
** need to occur right after the database cursor. So go ahead and
** allocate enough space, just in case.
OUT: "Score" for this snippet
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwse, it appends the serialized version of the value stored
** in column iCol of the row that SQL statement pStmt currently points
** to to the buffer.
In-memory list of records
** standard include files.
mx_payload
************* Include whereInt.h in the middle of wherecode.c *************
** Allocate a new page object initially associated with cache pCache.
This subquery can be absorbed into its parent.
OUT: New changeset iterator handle
** Rtree virtual table module xDisconnect method.
A malloc() failed
True if fts5yymajor has invoked an error
void*, int sz, int N
If the user has inserted a NULL value, this function may be called with
** zText==0. In this case, add zero token entries to the hash table and
** return early.
comment:
** Return a pointer to the appropriate hash function given the key class.
**
** The C syntax in this function definition may be unfamilar to some
** programmers, so we provide the following additional explanation:
**
** The name of the function is "ftsHashFunction". The function takes a
** single parameter "keyClass". The return value of ftsHashFunction()
** is a pointer to another function. Specifically, the return value
** of ftsHashFunction() is a pointer to a function that takes two parameters
** with types "const void*" and "int" and returns an "int".
label: code-design
If a HAVING clause is present, then there must be a GROUP BY clause.
OUT: Height
If an older version of the function with a configured destructor is
** being replaced invoke the destructor function here.
Reg with value of this column. 0 means none.
Previous value read from pgidx
Which cookie to read or write
If a WAL transaction is being committed, there is no point in writing
** any pages with page numbers greater than nTruncate into the WAL file.
** They will never be read by any client. So remove them from the pDirty
** list here.
Page size of main database
Userid for the file
Hour and minutes
READ_LOCK or WRITE_LOCK
** To compile without implementing sqlite3Hwtime() for your platform,
** you can remove the above #error and use the following
** stub function. You will lose timing support for many
** of the debugging and testing utilities, but it should at
** least compile and run.
If pCte->zCteErr is non-NULL at this point, then this is an illegal
** recursive reference to CTE pCte. Leave an error in pParse and return
** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
** In this case, proceed.
If the following assert() fails on some obscure processor/compiler
** combination, the work-around is to set the correct pointer
** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option
xShrink
True for a lookup only
** After allocating the Fts3Expr.aMI[] array for each phrase in the
** expression rooted at pExpr, the cursor iterates through all rows matched
** by pExpr, calling this function for each row. This function increments
** the values in Fts3Expr.aMI[] according to the position-list currently
** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase
** expression nodes.
Must match this affinity, if zCollName!=NULL
True if satisfies ORDER BY
!defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
Waiting for read-locks to clear
If the child node is now at EOF, so is the parent AND node. Otherwise,
** the child node is guaranteed to have advanced at least as far as
** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the
** new lastest rowid seen so far.
comment: If the buffer currently allocated is too small for this entry, realloc
** the buffer to make it large enough.
label: code-design
Set idxFlags flags for all WHERE clause terms that will be used.
xConnect
Used to iterate through p->aSample[]
Opcode: InitCoroutine P1 P2 P3 * *
**
** Set up register P1 so that it will Yield to the coroutine
** located at address P3.
**
** If P2!=0 then the coroutine implementation immediately follows
** this opcode. So jump over the coroutine implementation to
** address P2.
**
** See also: EndCoroutine
Hash table
No shared-memory support
comment:
** The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered or
** is not currently allocated. SQLite will never do either.
label: code-design
If this is a delete operation to remove a row from a table b-tree,
** invalidate any incrblob cursors open on the row being deleted.
forward declaration
Control jumps to here if an error is encountered above, or upon
** successful coding of the SELECT.
Checkpoint information in wal-index
True if the OP_Affinity operation has been run
** Find the smallest page number out of all pages held in the WAL that
** has not been returned by any prior invocation of this method on the
** same WalIterator object. Write into *piFrame the frame index where
** that page was last written into the WAL. Write into *piPage the page
** number.
**
** Return 0 on success. If there are no pages in the WAL with a page
** number larger than *piPage, then return 1.
comment: The word is too big or too small for the porter stemmer.
** Fallback to the copy stemmer
label: documentation
** This function is the implementation of both the xConnect and xCreate
** methods of the FTS3 virtual table.
**
** The argv[] array contains the following:
**
** argv[0] -> module name ("fts5")
** argv[1] -> database name
** argv[2] -> table name
** argv[...] -> "column name" and other module argument fields.
OUT: Size of blob data
Initialize sqlite3_vtab_cursor base class
** For all dirty pages currently in the cache, invoke the specified
** callback. This is only used if the SQLITE_CHECK_PAGES macro is
** defined.
Set to " AND " later on
** Free the RtreeCursor.aConstraint[] array and its contents.
comment: note that the quality of the randomness doesn't matter that much
label: code-design
Position list
** PRAGMA threads
** PRAGMA threads = N
**
** Configure the maximum number of worker threads. Return the new
** maximum, which might be less than requested.
** Write a 32-bit integer into a string buffer in big-endian byte order.
Cursor for the canonical data btree
** Assuming zIn points to the first byte of a UTF-8 character,
** advance zIn to point to the first byte of the next UTF-8 character.
** This routine sets the busy callback for an Sqlite database to the
** given callback function with the given argument.
True if xText is allocated space
1460
Prior select in a compound select statement
Global shared lock memory for the file
The isRequirePhrase variable is set to true if a phrase or
** an expression contained in parenthesis is required. If a
** binary operator (AND, OR, NOT or NEAR) is encounted when
** isRequirePhrase is set, this is a syntax error.
Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL
** This assert appears to trigger spuriously on certain
** versions of Windows, possibly due to _beginthreadex()
** and/or CreateThread() not fully setting their thread
** ID parameter before starting the thread.
** Return true if character 't' may be part of an FTS5 bareword, or false
** otherwise. Characters that may be part of barewords:
**
** * All non-ASCII characters,
** * The 52 upper and lower case ASCII characters, and
** * The 10 integer ASCII characters.
** * The underscore character "_" (0x5F).
** * The unicode "subsitute" character (0x1A).
Copy the data from the source page into the destination page.
** Then clear the Btree layer MemPage.isInit flag. Both this module
** and the pager code use this trick (clearing the first byte
** of the page 'extra' space to invalidate the Btree layers
** cached parse of the page). MemPage.isInit is marked
** "MUST BE FIRST" for this purpose.
True if at End Of Results
** Argument rc is an SQLite error code. Return true if this error is
** considered fatal if encountered during a backup operation. All errors
** are considered fatal except for SQLITE_BUSY and SQLITE_LOCKED.
SQLITE_DISABLE_SKIPAHEAD_DISTINCT
** This implementation does not actually create a new thread. It does the
** work of the thread in the main thread, when either the thread is created
** or when it is joined
Size of string aInput in bytes
** Register a statically linked extension that is automatically
** loaded by every new database connection.
Name of the collating sequence
** When this global variable is positive, it gets decremented once before
** each instruction in the VDBE. When it reaches zero, the u1.isInterrupted
** field of the sqlite3 structure is set in order to simulate an interrupt.
**
** This facility is used for testing purposes only. It does not function
** in an ordinary build.
** This array defines hard upper bounds on limit values. The
** initializer must be kept in sync with the SQLITE_LIMIT_*
** #defines in sqlite3.h.
Number of entries in aLTerm[]
Delete and then insert a row
Zero or more SORTFLAG_* bits
Allocate an instance of struct Wal to return.
Add the new segment to the output level
** Change the "spill" limit on the number of pages in the cache.
** If the number of pages exceeds this limit during a write transaction,
** the pager might attempt to "spill" pages to the journal early in
** order to free up memory.
**
** The value returned is the current spill size. If zero is passed
** as an argument, no changes are made to the spill size setting, so
** using mxPage of 0 is a way to query the current spill size.
Iterator to update aFirst[] array for
One slot for each expression in the list
Parse number
comment:
** The xGetLastError() method is designed to return a better
** low-level error message when operating-system problems come up
** during SQLite operation. Only the integer return code is currently
** used.
label: code-design
** Check on a Vdbe to make sure it has not been finalized. Log
** an error and return true if it has been finalized (or is otherwise
** invalid). Return false if it is ok.
Mix sz bytes of entropy into p.
************* End of malloc.c *********************************************
The connection to be closed
End offset of token
** Formulate and prepare an SQL statement to query table zTab by primary
** key. Assuming the following table structure:
**
** CREATE TABLE x(a, b, c, d, PRIMARY KEY(a, c));
**
** The SELECT statement looks like this:
**
** SELECT * FROM x WHERE a = ?1 AND c = ?3
**
** If successful, SQLITE_OK is returned and SessionApplyCtx.pSelect is left
** pointing to the prepared version of the SQL statement.
Schema format version for this file
Debug EXPLAIN QUERY PLAN
530
** Compute the affinity string for table pTab, if it has not already been
** computed. As an optimization, omit trailing SQLITE_AFF_BLOB affinities.
**
** If the affinity exists (if it is no entirely SQLITE_AFF_BLOB values) and
** if iReg>0 then code an OP_Affinity opcode that will set the affinities
** for register iReg and following. Or if affinities exists and iReg==0,
** then just set the P4 operand of the previous opcode (which should be
** an OP_MakeRecord) to the affinity string.
**
** A column affinity string has one character per column:
**
** Character Column affinity
** ------------------------------
** 'A' BLOB
** 'B' TEXT
** 'C' NUMERIC
** 'D' INTEGER
** 'E' REAL
OUT: Global maximum cache size
Quote character
In the normal case (8+3 filenames disabled) the journal filename
** is guaranteed to contain a '-' character.
** SQL statement pSelect is as generated by the sessionSelectRow() function.
** This function binds the primary key values from the change that changeset
** iterator pIter points to to the SELECT and attempts to seek to the table
** entry. If a row is found, the SELECT statement left pointing at the row
** and SQLITE_ROW is returned. Otherwise, if no row is found and no error
** has occured, the statement is reset and SQLITE_OK is returned. If an
** error occurs, the statement is reset and an SQLite error code is returned.
**
** If this function returns SQLITE_ROW, the caller must eventually reset()
** statement pSelect. If any other value is returned, the statement does
** not require a reset().
**
** If the iterator currently points to an INSERT record, bind values from the
** new.* record to the SELECT statement. Or, if it points to a DELETE or
** UPDATE, bind values from the old.* record.
** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to
** operate directly on the rowis returned by a WHERE clause. Return
** ONEPASS_SINGLE (1) if the statement can operation directly because only
** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass
** optimization can be used on multiple
**
** If the ONEPASS optimization is used (if this routine returns true)
** then also write the indices of open cursors used by ONEPASS
** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data
** table and iaCur[1] gets the cursor used by an auxiliary index.
** Either value may be -1, indicating that cursor is not used.
** Any cursors returned will have been opened for writing.
**
** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is
** unable to use the ONEPASS optimization.
Done.
** Sync the database file to disk. This is a no-op for in-memory databases
** or pages with the Pager.noSync flag set.
**
** If successful, or if called on a pager for which it is a no-op, this
** function returns SQLITE_OK. Otherwise, an IO error code is returned.
Save the left position
Iterator opened on pData/nData
Add one to the old schema cookie
REPLACE
** This function is a no-op if *pRc is other than SQLITE_OK when it is
** called. Otherwise, append a single varint to the buffer.
**
** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
** returning.
The ON clause of a join
QUERY => ID
Source page number
Length of each character in zCharSet
0==rowid, 1==tbl, 2==rank
xRollbackTo
Column numbers
Sum of nMin for purgeable caches
Zero the file-handle object. If nSpill was passed zero, initialize
** it using the sqlite3OsOpen() function of the underlying VFS. In this
** case none of the code in this module is executed as a result of calls
** made on the journal file-handle.
The VFS to use for actual file I/O
321
Array of integers that becomes the BLOB
ifdef SQLITE_ENABLE_STAT4
True for a SEARCH. False for SCAN.
** Delete the given Select structure and all of its substructures.
Gather the complete text of the CREATE INDEX statement into
** the zStmt variable
** Set the ExprList.a[].zSpan element of the most recently added item
** on the expression list.
**
** pList might be NULL following an OOM error. But pSpan should never be
** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag
** is set.
*************************************************************************
** Utility routines for dealing with JsonNode and JsonParse objects
*************************************************************************
** Resize the Vdbe.aOp array so that it is at least nOp elements larger
** than its current size. nOp is guaranteed to be less than or equal
** to 1024/sizeof(Op).
**
** If an out-of-memory error occurs while resizing the array, return
** SQLITE_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
** unchanged (this is so that any opcodes already allocated can be
** correctly deallocated along with the rest of the Vdbe).
LIMIT
Jump here if malloc fails
Name of the identifier
Malloced string that needs to be freed
Take the requested lock on the conch file and break a stale lock if the
** host id matches.
** Implementation of bm25() function.
Rowid of the next row to insert
** A foreign key constraint requires that the key columns in the parent
** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
** Given that pParent is the parent table for foreign key constraint pFKey,
** search the schema for a unique index on the parent key columns.
**
** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
** is set to point to the unique index.
**
** If the parent key consists of a single column (the foreign key constraint
** is not a composite foreign key), output variable *paiCol is set to NULL.
** Otherwise, it is set to point to an allocated array of size N, where
** N is the number of columns in the parent key. The first element of the
** array is the index of the child table column that is mapped by the FK
** constraint to the parent table column stored in the left-most column
** of index *ppIdx. The second element of the array is the index of the
** child table column that corresponds to the second left-most column of
** *ppIdx, and so on.
**
** If the required index cannot be found, either because:
**
** 1) The named parent key columns do not exist, or
**
** 2) The named parent key columns do exist, but are not subject to a
** UNIQUE or PRIMARY KEY constraint, or
**
** 3) No parent key columns were provided explicitly as part of the
** foreign key definition, and the parent table does not have a
** PRIMARY KEY, or
**
** 4) No parent key columns were provided explicitly as part of the
** foreign key definition, and the PRIMARY KEY of the parent table
** consists of a different number of columns to the child key in
** the child table.
**
** then non-zero is returned, and a "foreign key mismatch" error loaded
** into pParse. If an OOM error occurs, non-zero is returned and the
** pParse->db->mallocFailed flag is set.
Bytes of space allocated at pSpace
True if this is an in-memory file
** pIn is a UTF-8 encoded string, nIn bytes in size. Return the number of
** unicode characters in the string.
Find the firstest rowid any synonym points to.
Bytes content per ovfl page
** The select statement passed as the first argument is an aggregate query.
** The second argument is the associated aggregate-info object. This
** function tests if the SELECT is of the form:
**
** SELECT count(*) FROM <tbl>
**
** where table is a database table, not a sub-select or view. If the query
** does match this pattern, then a pointer to the Table object representing
** <tbl> is returned. Otherwise, 0 is returned.
Full pathname of this file
comment: If this is an xCreate call, create the underlying tables in the
** database. TODO: For xConnect(), it could verify that said tables exist.
label: code-design
the FROM clause -- which tables to scan
Write to the last byte of each newly allocated or extended page
The virtual table
** Tokenization callback used by integrity check.
Add the current term to the parent node. The term added to the
** parent must:
**
** a) be greater than the largest term on the leaf node just written
** to the database (still available in pLeaf->key), and
**
** b) be less than or equal to the term about to be added to the new
** leaf node (zTerm/nTerm).
**
** In other words, it must be the prefix of zTerm 1 byte longer than
** the common prefix (if any) of zTerm and pWriter->zTerm.
** If the STATIC_MEM mutex is not already held, obtain it now. The mutex
** will already be held (obtained by code in malloc.c) if
** sqlite3GlobalConfig.bMemStat is true.
Check the following statements are true:
**
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
** (b) if CREATE is set, then READWRITE must also be set, and
** (c) if EXCLUSIVE is set, then CREATE must also be set.
** (d) if DELETEONCLOSE is set, then CREATE must also be set.
Fts5 table configuration
Delta to apply to the pattern
** Iterate through all phrase nodes in an FTS3 query, except those that
** are part of a sub-tree that is the right-hand-side of a NOT operator.
** For each phrase node found, the supplied callback function is invoked.
**
** If the callback function returns anything other than SQLITE_OK,
** the iteration is abandoned and the error code returned immediately.
** Otherwise, SQLITE_OK is returned after a callback has been made for
** all eligible phrase nodes.
Flags for sqlite3_vfs.xOpen()
First index cursor
An index being inserted or updated
Keywords and unquoted identifiers
61
!defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
** 2003 October 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the C functions that implement date and time
** functions for SQLite.
**
** There is only one exported symbol in this file - the function
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** SQLite processes all times and dates as julian day numbers. The
** dates and times are stored as the number of days since noon
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
** calendar system.
**
** 1970-01-01 00:00:00 is JD 2440587.5
** 2000-01-01 00:00:00 is JD 2451544.5
**
** This implementation requires years to be expressed as a 4-digit number
** which means that only dates between 0000-01-01 and 9999-12-31 can
** be represented, even though julian day numbers allow a much wider
** range of dates.
**
** The Gregorian calendar system is used for all dates and times,
** even those that predate the Gregorian calendar. Historians usually
** use the julian calendar for dates prior to 1582-10-15 and for some
** dates afterwards, depending on locale. Beware of this difference.
**
** The conversion algorithms are implemented based on descriptions
** in the following text:
**
** Jean Meeus
** Astronomical Algorithms, 2nd Edition, 1998
** ISBM 0-943396-61-1
** Willmann-Bell, Inc
** Richmond, Virginia (USA)
Largest docid for all iterators
Literal "new" token
264
#ifndef SQLITE_OMIT_TRACE
The value of the INTEGER PRIMARY KEY column is always a NULL.
** Whenever this column is read, the rowid will be substituted
** in its place. Hence, fill this column with a NULL to avoid
** taking up data space with information that will never be used.
** As there may be shallow copies of this value, make it a soft-NULL
Number of fields in the header
SQLITE_IOCAP_POWERSAFE_OVERWRITE
253
Opcode: CursorHint P1 * * P4 *
**
** Provide a hint to cursor P1 that it only needs to return rows that
** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
** to values currently held in registers. TK_COLUMN terms in the P4
** expression refer to columns in the b-tree to which cursor P1 is pointing.
Number of bytes in rhs input
** Allocate a new, empty, sqlite3_changegroup.
The table that is indexed
** Return the amount cell p would grow by if it were unioned with pCell.
Serial type to deserialize
Database page-size in bytes
Opcode: Variable P1 P2 * P4 *
** Synopsis: r[P2]=parameter(P1,P4)
**
** Transfer the values of bound parameter P1 into register P2
**
** If the parameter is named, then its name appears in P4.
** The P4 value is used by sqlite3_bind_parameter_name().
************* End of sqlite3rbu.c *****************************************
Name of this column, \000, then the type
Unsorted cost of (pFrom+pWLoop)
Output variables. aPoslist==0 at EOF
FTS5_STRING or FTS5_TERM node
Database that contains the table
True if incr-vacuum is enabled
0x00..0x0F
** Compute the union of two position lists. The output written
** into *pp contains all positions of both *pp1 and *pp2 in sorted
** order and with any duplicates removed. All pointers are
** updated appropriately. The caller is responsible for insuring
** that there is enough space in *pp to hold the complete output.
either the conch didn't match or we need to create a new one
Do not open write-ahead-log files
An engine for executing database bytecode
** Return the size of the header added by this middleware layer
** in the page-cache hierarchy.
The pH containing "elem"
Index of previous free chunk
if (a) the open flags are not O_RDWR, (b) the conch isn't there, and
** (c) the file system is read-only, then enable no-locking access.
** Ugh, since O_RDONLY==0x0000 we test for !O_RDWR since unixOpen asserts
** that openFlags will have only one of O_RDONLY or O_RDWR.
Result of strlen(zFts3)
** Lock an rbuVfs-file.
Name of child table
xRollback
comment:
** There are various methods for file locking used for concurrency
** control:
**
** 1. POSIX locking (the default),
** 2. No locking,
** 3. Dot-file locking,
** 4. flock() locking,
** 5. AFP locking (OSX only),
** 6. Named POSIX semaphores (VXWorks only),
** 7. proxy locking. (OSX only)
**
** Styles 4, 5, and 7 are only available of SQLITE_ENABLE_LOCKING_STYLE
** is defined to 1. The SQLITE_ENABLE_LOCKING_STYLE also enables automatic
** selection of the appropriate locking style based on the filesystem
** where the database is located.
label: code-design
Cursor number of the source table
trigger_event ::= UPDATE OF idlist
Check that the leaf page indicated by the iterator really does
** contain the rowid suggested by the same.
The following are used by the fts3_eval.c module.
OUT: Rank function arguments
Caution: pRoot may iterate through docids in ascending or descending
** order. For this reason, even though it seems more defensive, the
** do loop can not be written:
**
** do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
List of columns in pTableName to insert into
In-memory chunk-size
If already in the error state, this function is a no-op. But on
** the other hand, this routine is never called if we are already in
** an error state.
values ::= VALUES LP nexprlist RP
** Read a varint from the stream of data accessed by p. Set *pnOut to
** the value read.
Search the hash table for an existing record for this row.
R-tree structure
** weekday N
**
** Move the date to the same time on the next occurrence of
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
** date is already on the appropriate weekday, this is a no-op.
Use this text encoding
Steps 2 through 4.
Opcode: RealAffinity P1 * * * *
**
** If register P1 holds an integer convert it to a real value.
**
** This opcode is used when extracting information from a column that
** has REAL affinity. Such column values may still be stored as
** integers, for space efficiency, but after extraction we want them
** to have only a real value.
** Ensure that there is room in the buffer to append nByte bytes of data.
** If not, use sqlite3_realloc() to grow the buffer so that there is.
**
** If successful, return zero. Otherwise, if an OOM condition is encountered,
** set *pRc to SQLITE_NOMEM and return non-zero.
Data to write
************* End of select.c *********************************************
To fully unlock the database, delete the lock file
trigger_time ::= INSTEAD OF
** Compute a string for the "comment" field of a VDBE opcode listing.
**
** The Synopsis: field in comments in the vdbe.c source file gets converted
** to an extra string that is appended to the sqlite3OpcodeName(). In the
** absence of other comments, this synopsis becomes the comment on the opcode.
** Some translation occurs:
**
** "PX" -> "r[X]"
** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
Virtual terms from the LIKE optimization
Configure the number of columns. Configure the cursor to
** think that the table has one more column than it really
** does. An OP_Column to retrieve this imaginary column will
** always return an SQL NULL. This is useful because it means
** we can invoke OP_Column to fill in the vdbe cursors type
** and offset cache without causing any IO.
Outputs
SELECT statement or RHS of INSERT INTO SELECT ...
Figure out whether to use 1, 2, 4, 6 or 8 bytes.
sqlite3_config() does not allow otherwise
Source of content
expr ::= expr AND expr
Table object to append header for
Register for ephem table rowid
Level of segments
** Create new user functions.
Counter to limit the number of searches
exprlist ::= exprlist cnearset
Generate code to handle the case of A<B
*************************************************************************
** Interface to automatically generated code in fts5_unicode2.c.
Context for returning result/error
Ensure that page 0 of the wal-index (the page that contains the
** wal-index header) is mapped. Return early if an error occurs here.
Used to iterate through deferred tokens
** Lists of free blocks. aiFreelist[0] is a list of free blocks of
** size mem5.szAtom. aiFreelist[1] holds blocks of size szAtom*2.
** aiFreelist[2] holds free blocks of size szAtom*4. And so forth.
** Functions for accessing sqlite3_vfs methods
same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1]
try to match the database file R/W permissions, ignore failure
DELETE_DOCSIZE
VDBE instruction address of the start of the loop
The size of a lookaside slot after ROUNDDOWN8 needs to be larger
** than a pointer to be useful.
If the database is zero pages in size, that means that either (1) the
** journal is a remnant from a prior database with the same name where
** the database file but not the journal was deleted, or (2) the initial
** transaction that populates a new database is being rolled back.
** In either case, the journal file can be deleted. However, take care
** not to delete the journal file if it is already open due to
** journal_mode=PERSIST.
** Return the name of the first system call after zName. If zName==NULL
** then return the name of the first system call. Return NULL if zName
** is the last system call or if zName is not the name of a valid
** system call.
Changeset blob
pagetype
** Open the shared-memory area associated with database file pDbFd.
**
** When opening a new shared-memory file, if no other instances of that
** file are currently open, in this process or in other processes, then
** the file must be truncated to zero length or have its header cleared.
** CAPI3REF: Number Of Columns In A Result Set
** METHOD: sqlite3_stmt
**
** ^Return the number of columns in the result set returned by the
** [prepared statement]. ^If this routine returns 0, that means the
** [prepared statement] returns no data (for example an [UPDATE]).
** ^However, just because this routine returns a positive number does not
** mean that one or more rows of data will be returned. ^A SELECT statement
** will always have a positive sqlite3_column_count() but depending on the
** WHERE clause constraints and the table content, it might return no rows.
**
** See also: [sqlite3_data_count()]
************************************************************************
** The following three functions, found below:
**
** rbuDeltaGetInt()
** rbuDeltaChecksum()
** rbuDeltaApply()
**
** are lifted from the fossil source code (http://fossil-scm.org). They
** are used to implement the scalar SQL function rbu_fossil_delta().
** Round up a request size to the next valid allocation size. If
** the allocation is too large to be handled by this allocation system,
** return 0.
**
** All allocations must be a power of two and must be expressed by a
** 32-bit signed integer. Hence the largest allocation is 0x40000000
** or 1073741824 bytes.
Append the prefix-compressed term and doclist to the buffer.
Every page has an associated PCache
EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
** the start of the cell content area. A zero value for this integer is
** interpreted as 65536.
73
Journal omitted.
** Return the current wal-index header checksum for the target database
** as a 64-bit integer.
**
** The checksum is store in the first page of xShmMap memory as an 8-byte
** blob starting at byte offset 40.
** Step the RBU object.
************* Begin file parse.h ******************************************
Initialize the contents of the SnippetIter object. Then iterate through
** the set of phrases in the expression to populate the aPhrase[] array.
Set the output variables and return.
Number of bytes in aRec
A virtual table that is constrained by an IN clause may not
** consume the ORDER BY clause because (1) the order of IN terms
** is not necessarily related to the order of output terms and
** (2) Multiple outputs from a single IN value will not merge
** together.
Mask off the SQLITE_SYNC_* values
** This routine "expands" a SELECT statement and all of its subqueries.
** For additional information on what it means to "expand" a SELECT
** statement, see the comment on the selectExpand worker callback above.
**
** Expanding a SELECT statement is the first step in processing a
** SELECT statement. The SELECT statement must be expanded before
** name resolution is performed.
**
** If anything goes wrong, an error message is written into pParse.
** The calling function can detect the problem by looking at pParse->nErr
** and/or pParse->db->mallocFailed.
245
** Create a new index for an SQL table. pName1.pName2 is the name of the index
** and pTblList is the name of the table that is to be indexed. Both will
** be NULL for a primary key or an index that is created to satisfy a
** UNIQUE constraint. If pTable and pIndex are NULL, use pParse->pNewTable
** as the table to be indexed. pParse->pNewTable is a table that is
** currently being constructed by a CREATE TABLE statement.
**
** pList is a list of columns to be indexed. pList will be NULL if this
** is a primary key or unique-constraint on the most recent column added
** to the table currently under construction.
Set the *pmSeen output variable.
Query the schema of the main database. Create a mirror schema
** in the temporary database.
We are trying for an exclusive lock but another thread in this
** same process is still holding a shared lock.
xUnpin
** The StrAccum "p" is not large enough to accept N new bytes of z[].
** So enlarge if first, then do the append.
**
** This is a helper routine to sqlite3StrAccumAppend() that does special-case
** work (enlarging the buffer) using tail recursion, so that the
** sqlite3StrAccumAppend() routine can use fast calling semantics.
CONTINUE and BREAK addresses
Name of the table we are looking for
************* End of fts3_tokenize_vtab.c *********************************
Allocate space for the new multi-seg-iterator.
If this is the end of a transaction, then we might need to pad
** the transaction and/or sync the WAL file.
**
** Padding and syncing only occur if this set of frames complete a
** transaction and if PRAGMA synchronous=FULL. If synchronous==NORMAL
** or synchronous==OFF, then no padding or syncing are needed.
**
** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
** needed and only the sync is done. If padding is needed, then the
** final frame is repeated (with its commit mark) until the next sector
** boundary is crossed. Only the part of the WAL prior to the last
** sector boundary is synced; the part of the last frame that extends
** past the sector boundary is written after the sync.
Only allow tracing if SQLITE_DEBUG is defined.
(274) cmdlist ::= ecmd (OPTIMIZED OUT)
Number of buffers currently checked out
Symbolic name of this SELECT use for debugging
Delete a row from an aux. index b-tree
** Return the number of bytes required to encode v as a varint
Code the SELECTs to our left into temporary table "tab1".
** 2008 May 26
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This header file is used by programs that want to link against the
** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
Number of bytes of the string text to include in output
comment:
** This is called once for each leaf page except the first that contains
** at least one term. Argument (nTerm/pTerm) is the split-key - a term that
** is larger than all terms written to earlier leaves, and equal to or
** smaller than the first term on the new leaf.
**
** If an error occurs, an error code is left in Fts5Index.rc. If an error
** has already occurred when this function is called, it is a no-op.
label: code-design
Buffer to assemble frame-headers in
Reports from the internet are that performance is always
** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699.
The auto-commit flag is true, the vdbe program was successful
** or hit an 'OR FAIL' constraint and there are no deferred foreign
** key constraints to hold up the transaction. This means a commit
** is required.
Cell index within the node
end-if not one-row
** Each page of the wal-index mapping contains a hash-table made up of
** an array of HASHTABLE_NSLOT elements of the following type.
If the P3 value could not be converted into an integer without
** loss of information, then special processing is required...
Input buffer or stream
Mask of ORDER BY terms that need reversing
EVIDENCE-OF: R-51873-39618 The page size for a database file is
** determined by the 2-byte integer located at an offset of 16 bytes from
** the beginning of the database file.
9,10,11
First argument for conflict handler
Expression (pLeft != pRight)
If the root node was just loaded, set pRtree->iDepth to the height
** of the r-tree structure. A height of zero means all data is stored on
** the root node. A height of one means the children of the root node
** are the leaves, and so on. If the depth as specified on the root node
** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
The x>=y term
Replace with JsonNode.u.iReplace
Address of the OP_IfNot opcode
Minimum local payload in a LEAFDATA table
Create a SrcList structure containing the child table. We need the
** child table as a SrcList for sqlite3WhereBegin()
SQLITE3EXT_H
** Remove the page supplied as an argument from the hash table
** (PCache1.apHash structure) that it is currently stored in.
** Also free the page if freePage is true.
**
** The PGroup mutex must be held when this function is called.
Number of UTF-8 characters in zTabName
** Try to provide a memory barrier operation, needed for initialization
** and also for the implementation of xShmBarrier in the VFS in cases
** where SQLite is compiled without mutexes.
Number of outstanding file locks
Begin a transaction and increment the schema cookie.
** The following values may be passed as the second argument to
** sqlite3OsLock(). The various locks exhibit the following semantics:
**
** SHARED: Any number of processes may hold a SHARED lock simultaneously.
** RESERVED: A single process may hold a RESERVED lock on a file at
** any time. Other processes may hold and obtain new SHARED locks.
** PENDING: A single process may hold a PENDING lock on a file at
** any one time. Existing SHARED locks may persist, but no new
** SHARED locks may be obtained by other processes.
** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
**
** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
** process that requests an EXCLUSIVE lock may actually obtain a PENDING
** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
** sqlite3OsLock().
** Page pParent is an internal (non-leaf) tree page. This function
** asserts that page number iChild is the left-child if the iIdx'th
** cell in page pParent. Or, if iIdx is equal to the total number of
** cells in pParent, that page number iChild is the right-child of
** the page.
Number of aux. indexes on table zTbl
Iterates through aOvfl[]
Figure out if this structure requires optimization. A structure does
** not require optimization if either:
**
** + it consists of fewer than two segments, or
** + all segments are on the same level, or
** + all segments except one are currently inputs to a merge operation.
**
** In the first case, return NULL. In the second, increment the ref-count
** on *pStruct and return a copy of the pointer to it.
************* Continuing where we left off in sqliteInt.h *****************
CURRENT_DATE
comment:
** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
** sizes of memory allocations below this value where possible.
label: code-design
comment:
** CAPI3REF: Binding Values To Prepared Statements
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
** METHOD: sqlite3_stmt
**
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
** literals may be replaced by a [parameter] that matches one of following
** templates:
**
** <ul>
** <li> ?
** <li> ?NNN
** <li> :VVV
** <li> @VVV
** <li> $VVV
** </ul>
**
** In the templates above, NNN represents an integer literal,
** and VVV represents an alphanumeric identifier.)^ ^The values of these
** parameters (also called "host parameter names" or "SQL parameters")
** can be set using the sqlite3_bind_*() routines defined here.
**
** ^The first argument to the sqlite3_bind_*() routines is always
** a pointer to the [sqlite3_stmt] object returned from
** [sqlite3_prepare_v2()] or its variants.
**
** ^The second argument is the index of the SQL parameter to be set.
** ^The leftmost SQL parameter has an index of 1. ^When the same named
** SQL parameter is used more than once, second and subsequent
** occurrences have the same index as the first occurrence.
** ^The index for named parameters can be looked up using the
** [sqlite3_bind_parameter_index()] API if desired. ^The index
** for "?NNN" parameters is the value of NNN.
** ^The NNN value must be between 1 and the [sqlite3_limit()]
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
**
** ^The third argument is the value to bind to the parameter.
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
** is ignored and the end result is the same as sqlite3_bind_null().
**
** ^(In those routines that have a fourth argument, its value is the
** number of bytes in the parameter. To be clear: the value is the
** number of <u>bytes</u> in the value, not the number of characters.)^
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
** is negative, then the length of the string is
** the number of bytes up to the first zero terminator.
** If the fourth parameter to sqlite3_bind_blob() is negative, then
** the behavior is undefined.
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
** that parameter must be the byte offset
** where the NUL terminator would occur assuming the string were NUL
** terminated. If any NUL characters occur at byte offsets less than
** the value of the fourth parameter then the resulting string value will
** contain embedded NULs. The result of expressions involving strings
** with embedded NULs is undefined.
**
** ^The fifth argument to the BLOB and string binding interfaces
** is a destructor used to dispose of the BLOB or
** string after SQLite has finished with it. ^The destructor is called
** to dispose of the BLOB or string even if the call to bind API fails.
** ^If the fifth argument is
** the special value [SQLITE_STATIC], then SQLite assumes that the
** information is in static, unmanaged space and does not need to be freed.
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
** SQLite makes its own private copy of the data immediately, before
** the sqlite3_bind_*() routine returns.
**
** ^The sixth argument to sqlite3_bind_text64() must be one of
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
** to specify the encoding of the text in the third parameter. If
** the sixth argument to sqlite3_bind_text64() is not one of the
** allowed values shown above, or if the text encoding is different
** from the encoding specified by the sixth parameter, then the behavior
** is undefined.
**
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
** (just an integer to hold its size) while it is being processed.
** Zeroblobs are intended to serve as placeholders for BLOBs whose
** content is later written using
** [sqlite3_blob_open | incremental BLOB I/O] routines.
** ^A negative value for the zeroblob results in a zero-length BLOB.
**
** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
** [prepared statement] S to have an SQL value of NULL, but to also be
** associated with the pointer P of type T. ^D is either a NULL pointer or
** a pointer to a destructor function for P. ^SQLite will invoke the
** destructor D with a single argument of P when it is finished using
** P. The T parameter should be a static string, preferably a string
** literal. The sqlite3_bind_pointer() routine is part of the
** [pointer passing interface] added for SQLite 3.20.0.
**
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
** for the [prepared statement] or with a prepared statement for which
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
** routine is passed a [prepared statement] that has been finalized, the
** result is undefined and probably harmful.
**
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
** ^Unbound parameters are interpreted as NULL.
**
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
** [error code] if anything goes wrong.
** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
** [SQLITE_MAX_LENGTH].
** ^[SQLITE_RANGE] is returned if the parameter
** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
**
** See also: [sqlite3_bind_parameter_count()],
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
label: code-design
The journal file from which to read
Only attempt the conversion to TEXT if there is an integer or real
** representation (blob and NULL do not get converted) but no string
** representation. It would be harmless to repeat the conversion if
** there is already a string rep, but it is pointless to waste those
** CPU cycles.
Filename NULL
Range contraints that come from the LIKE optimization are
** always used in pairs.
Otherwise see if some other process holds it.
End of buffer
refarg ::= MATCH nm
Table Name Column Name
ERROR. return a NULL
Main structure
Phrase and token index, respectively
5
The next state
** The following routine only works on pentium-class (or newer) processors.
** It uses the RDTSC opcode to read the cycle count value out of the
** processor and returns that value. This can be used for high-res
** profiling.
Table to index. Use pParse->pNewTable if 0
Generate loop termination code.
Used to iterate through indexes
Size of hash table Rtree.aHash. This hash table is not expected to
** ever contain very many entries, so a fixed number of buckets is
** used.
The x<=z term
** json_group_array(VALUE)
**
** Return a JSON array composed of all values in the aggregate.
The main static mutex
TABLE
ccons ::= CHECK LP expr RP
Number of entries in aRoot[]
Space to hold the labels
If nTruncate is non-zero, this is a commit record.
0x00. Next integer will be a docid.
** A pointer to this structure is used to communicate information
** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback.
same as TK_REM, synopsis: r[P3]=r[P2]%r[P1]
1 for UPDATE, 0 for DELETE
Index.aSortOrder
True if there exists a hot journal-file
op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN
xLanguageid
950
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
True if ORDER BY rank
Remember the size of the LHS in iTable so that we can check that
** the RHS and LHS sizes match during code generation.
Create the DELETE statement to write to the target PK b-tree.
** Because it only performs INSERT operations, this is not required for
** an rbu vacuum handle.
BUSY not possible when useWal==1
Argument to pass to xBusyHandler
VFS only
0x13
It's odd to simulate an io-error here, but really this is just
** using the io-error infrastructure to test that SQLite handles this
** function failing. This function could fail if, for example, the
** current working directory has been unlinked.
** Argument pCsr must be a cursor opened for writing on an
** INTKEY table currently pointing at a valid table entry.
** This function modifies the data stored as part of that entry.
**
** Only the data content may only be modified, it is not possible to
** change the length of the data stored. If this function is called with
** parameters that attempt to write past the end of the existing data,
** no modifications are made and SQLITE_CORRUPT is returned.
ROW
comment:
** Remove an entry from the %_segdir table. This involves running the
** following two statements:
**
** DELETE FROM %_segdir WHERE level = :iAbsLevel AND idx = :iIdx
** UPDATE %_segdir SET idx = idx - 1 WHERE level = :iAbsLevel AND idx > :iIdx
**
** The DELETE statement removes the specific %_segdir level. The UPDATE
** statement ensures that the remaining segments have contiguously allocated
** idx values.
label: code-design
** Return true if the given BtCursor is valid. A valid cursor is one
** that is currently pointing to a row in a (non-empty) table.
** This is a verification routine is used only within assert() statements.
** The pre-update hook implementations.
Register holding an index record
nByte must be a positive
comment:
** A macro to hint to the compiler that a function should not be
** inlined.
label: documentation
Retrieve the current mutex implementation
Call SetAutoVacuum() to set initialize the internal auto and
** incr-vacuum flags. This is required in case this connection
** creates the database file. It is important that it is created
** as an auto-vacuum capable db.
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
Number of full pages read from DB
** Analyze the pExpr expression looking for aggregate functions and
** for variables that need to be added to AggInfo object that pNC->pAggInfo
** points to. Additional entries are made on the AggInfo object as
** necessary.
**
** This routine should only be called after the expression has been
** analyzed by sqlite3ResolveExprNames().
Write results here
How to write to Queue
Schema used for this query
************* End of fts3_unicode.c ***************************************
WhereTerms used
(297) conslist ::= conslist tconscomma tcons
IN/OUT: Position list
Size of doclist in bytes
Allocate the new vtab object and parse the configuration
** Implementation of the xBestIndex method for FTS3 tables. There
** are three possible strategies, in order of preference:
**
** 1. Direct lookup by rowid or docid.
** 2. Full-text search using a MATCH operator on a non-docid column.
** 3. Linear scan of %_content table.
If this was an INSERT, UPDATE or DELETE and no statement transaction
** has been rolled back, update the database connection change-counter.
Copy of the SELECT that implements the view
virtual table
Error code from journal finalization operation
Tokenizer implementations will typically add additional fields
** Add a new CHECK constraint to the table currently under construction.
Position of token in phrase
Constraint type
** This function is the implementation of both the xConnect and xCreate
** methods of the FTS3 virtual table.
**
** The argv[] array contains the following:
**
** argv[0] -> module name ("fts3" or "fts4")
** argv[1] -> database name
** argv[2] -> table name
** argv[...] -> "column name" and other module argument fields.
Incrementally read one PMA
sqlite3ParserTrace(stdout, "parser: ");
** 2012 May 24
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Implementation of the "unicode" full-text-search tokenizer.
Input character index
If the left hand side of the regexp operator is NULL,
** then the result is also NULL.
PRAGMA synchronous=EXTRA
FROM is not a subquery or view
** Recursively apply colset pColset to expression node pNode and all of
** its decendents. If (*ppFree) is not NULL, it contains a spare copy
** of pColset. This function may use the spare copy and set (*ppFree) to
** zero, or it may create copies of pColset using fts5CloneColset().
Escape ' and enclose in '...'
The entire poslist will fit on the current leaf. So copy
** it in one go.
Opcode: SorterData P1 P2 P3 * *
** Synopsis: r[P2]=data
**
** Write into register P2 the current sorter data for sorter cursor P1.
** Then clear the column header cache on cursor P3.
**
** This opcode is normally use to move a record out of the sorter and into
** a register that is the source for a pseudo-table cursor created using
** OpenPseudo. That pseudo-table cursor is the one that is identified by
** parameter P3. Clearing the P3 column cache as part of this opcode saves
** us from having to issue a separate NullRow instruction to clear that cache.
Array indicating modified columns
Index of term>=? value in apVal
someone else might have it reserved
Different sort orders
** This is the xExprCallback for a tree walker. It is used to
** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
** for additional information.
Bulk memory used by pcache-local
A flag to indicate when processing is finished
comment:
** All of the static variables used by this module are collected
** into a single structure named "mem3". This is to keep the
** static variables organized and to reduce namespace pollution
** when this module is combined with other in the amalgamation.
label: code-design
Jump here to skip the current record
Append position iPos to the output
************* End of os_win.h *********************************************
assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA
The word being stemmed (Reversed)
term ::= CTIME_KW
IMP: R-61949-35727
True if the node needs to be written to disk
Originates in ON/USING clause of outer join
Initial static space for a[]
Start label for the block-output subroutine
comment: The recursive SELECT to be coded
label: code-design
xClose method
Check if an existing function is being overridden or deleted. If so,
** and there are active VMs, then return SQLITE_BUSY. If a function
** is being overridden/deleted but there are no active VMs, allow the
** operation to continue but invalidate all precompiled statements.
Insert on an aux. index b-tree
Use the current thread to populate aFile[1], even though this
** PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
** then this function is already running in background thread
** pIncr->pTask->thread.
**
** If this is the INCRINIT_ROOT object, then it is running in the
** main VDBE thread. But that is Ok, as that thread cannot return
** control to the VDBE or proceed with anything useful until the
** first results are ready from this merger object anyway.
Number of bytes of available data
** CAPI3REF: Number of columns in a result set
** METHOD: sqlite3_stmt
**
** ^The sqlite3_data_count(P) interface returns the number of columns in the
** current row of the result set of [prepared statement] P.
** ^If prepared statement P does not have results ready to return
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
** interfaces) then sqlite3_data_count(P) returns 0.
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
** will return non-zero if previous call to [sqlite3_step](P) returned
** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
** where it always returns zero since each step of that multi-step
** pragma returns 0 columns of data.
**
** See also: [sqlite3_column_count()]
First Mem of result set
33
True if inside sqlite3_declare_vtab()
_SQLITE_OS_H_
** Open a shared-memory area associated with open database file pDbFd.
** This particular implementation uses mmapped files.
**
** The file used to implement shared-memory is in the same directory
** as the open database file and has the same name as the open database
** file with the "-shm" suffix added. For example, if the database file
** is "/home/user1/config.db" then the file that is created and mmapped
** for shared memory will be called "/home/user1/config.db-shm".
**
** Another approach to is to use files in /dev/shm or /dev/tmp or an
** some other tmpfs mount. But if a file in a different directory
** from the database file is used, then differing access permissions
** or a chroot() might cause two different processes on the same
** database to end up using different files for shared memory -
** meaning that their memory would not really be shared - resulting
** in database corruption. Nevertheless, this tmpfs file usage
** can be enabled at compile-time using -DSQLITE_SHM_DIRECTORY="/dev/shm"
** or the equivalent. The use of the SQLITE_SHM_DIRECTORY compile-time
** option results in an incompatible build of SQLite; builds of SQLite
** that with differing SQLITE_SHM_DIRECTORY settings attempt to use the
** same database file at the same time, database corruption will likely
** result. The SQLITE_SHM_DIRECTORY compile-time option is considered
** "unsupported" and may go away in a future SQLite release.
**
** When opening a new shared-memory file, if no other instances of that
** file are currently open, in this process or in other processes, then
** the file must be truncated to zero length or have its header cleared.
**
** If the original database file (pDbFd) is using the "unix-excl" VFS
** that means that an exclusive lock is held on the database file and
** that no other processes are able to read or write the database. In
** that case, we do not really need shared memory. No shared memory
** file is created. The shared memory will be simulated with heap memory.
Set to true if out of memory
.zMalloc =
** Open the sqlite_master table stored in database number iDb for
** writing. The table is opened using cursor 0.
"write-version" value for main db files
Bonus points if the text encoding matches
This is a delete. Set the delete flag.
Table that the trigger fires off of
Initialize the VDBE program
No foreign keys against expression indexes
The expression to extract a value from
Size of extra space for each page
Flush all currently outstanding nodes to disk.
For use by application
Steps 3, 4, and 5 implemented by this subroutine
Number of bytes to lock or unlock
Write new cell into this node
Test all UNIQUE constraints by creating entries for each UNIQUE
** index and making sure that duplicate entries do not already exist.
** Compute the revised record entries for indices as we go.
**
** This loop also handles the case of the PRIMARY KEY index for a
** WITHOUT ROWID table.
Constant "b" from BM25 formula
Size of each object in the array
Forward declaration of methods
Address of a freeblock within pPage->aData[]
comment:
** Set up SQL objects in database db used to access the contents of
** the hash table pointed to by argument pHash. The hash table must
** been initialized to use string keys, and to take a private copy
** of the key when a value is inserted. i.e. by a call similar to:
**
** sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1);
**
** This function adds a scalar function (see header comment above
** fts3TokenizerFunc() in this file for details) and, if ENABLE_TABLE is
** defined at compilation time, a temporary virtual table (see header
** comment above struct HashTableVtab) to the database schema. Both
** provide read/write access to the contents of *pHash.
**
** The third argument to this function, zName, is used as the name
** of both the scalar and, if created, the virtual table.
label: code-design
If a new wal-index header was loaded before the checkpoint was
** performed, then the pager-cache associated with pWal is now
** out of date. So zero the cached wal-index header to ensure that
** next time the pager opens a snapshot on this database it knows that
** the cache needs to be reset.
The new cursor
************* End of icu.c ************************************************
Page-type flage for the root page of new table
comment: TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
** If tokenizers are to be allowed to call sqlite3_*() functions, then
** we will need a way to register the API consistently.
label: code-design
For the purposes of the EP_ConstFunc flag, date and time
** functions and other functions that change slowly are considered
** constant because they are constant for the duration of one query
** Add an opcode that includes the p4 value as a pointer.
** IN/OUT parameter (*pa) points to a position list n bytes in size. If
** the position list contains entries for column iCol, then (*pa) is set
** to point to the sub-position-list for that column and the number of
** bytes in it returned. Or, if the argument position list does not
** contain any entries for column iCol, return 0.
Pointer to %_segdir.root buffer
Check if a thread in this process holds such a lock
** Change the pMem->zMalloc allocation to be at least szNew bytes.
** If pMem->zMalloc already meets or exceeds the requested size, this
** routine is a no-op.
**
** Any prior string or blob content in the pMem object may be discarded.
** The pMem->xDel destructor is called, if it exists. Though MEM_Str
** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
** values are preserved.
**
** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
** if unable to complete the resizing.
comment: TODO: SQLite does something special to deal with mixed-endian
** floating point values (e.g. ARM7). This code probably should
** too.
label: code-design
Malformed header - probably all zeros
************* End of callback.c *******************************************
** 2006 September 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Implementation of the full-text-search tokenizer that implements
** a Porter stemmer.
** Free a MatchinfoBuffer object allocated using fts3MIBufferNew()
OUT: Segment id
Btree handle holding this lock
Buffer in which to assemble pgidx
** The following functions are used to register the module with SQLite. If
** this module is being built as part of the SQLite core (SQLITE_CORE is
** defined), then sqlite3_open() will call sqlite3Fts5Init() directly.
**
** Or, if this module is being built as a loadable extension,
** sqlite3Fts5Init() is omitted and the two standard entry points
** sqlite3_fts_init() and sqlite3_fts5_init() defined instead.
sqlite3_pcache_methods2*
** Return the size of the database in pages (or zero, if unknown).
Number of columns in table
OUT: Normalized text for token
Preserve the text encoding
True if copy of key made on insert
The file descriptor for the journal file
** The implementation of the rbu_target_name() SQL function. This function
** accepts one or two arguments. The first argument is the name of a table -
** the name of a table in the RBU database. The second, if it is present, is 1
** for a view or 0 for a table.
**
** For a non-vacuum RBU handle, if the table name matches the pattern:
**
** data[0-9]_<name>
**
** where <name> is any sequence of 1 or more characters, <name> is returned.
** Otherwise, if the only argument does not match the above pattern, an SQL
** NULL is returned.
**
** "data_t1" -> "t1"
** "data0123_t2" -> "t2"
** "dataAB_t3" -> NULL
**
** For an rbu vacuum handle, a copy of the first argument is returned if
** the second argument is either missing or 0 (not a view).
** Return the size of the header added to each page by this module.
Fx
Aggregate function with DISTINCT keyword
Opcode: VFilter P1 P2 P3 P4 *
** Synopsis: iplan=r[P3] zplan='P4'
**
** P1 is a cursor opened using VOpen. P2 is an address to jump to if
** the filtered result set is empty.
**
** P4 is either NULL or a string that was generated by the xBestIndex
** method of the module. The interpretation of the P4 string is left
** to the module implementation.
**
** This opcode invokes the xFilter method on the virtual table specified
** by P1. The integer query plan parameter to xFilter is stored in register
** P3. Register P3+1 stores the argc parameter to be passed to the
** xFilter method. Registers P3+2..P3+1+argc are the argc
** additional parameters which are passed to
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
**
** A jump is made to P2 if the result set after filtering would be empty.
** The maximum legal page number is (2^31 - 1).
Number of bytes of the blob to include in output
CHECK
Reload the table, index and permanent trigger schemas.
IMP: R-24470-31136 This function is an SQL wrapper around the
** sqlite3_sourceid() C interface.
Database is always well-formed
** Prepare to begin tokenizing a particular string. The input
** string to be tokenized is pInput[0..nBytes-1]. A cursor
** used to incrementally tokenize this string is returned in
** *ppCursor.
Number of iterators in aIter not at EOF
** Given an allocation, find the MemBlockHdr for that allocation.
**
** This routine checks the guards at either end of the allocation and
** if they are incorrect it asserts.
** Try to convert a value into a numeric representation if we can
** do so without loss of information. In other words, if the string
** looks like a number, convert it into a number. If it does not
** look like a number, leave it alone.
**
** If the bTryForInt flag is true, then extra effort is made to give
** an integer representation. Strings that look like floating point
** values but which have no fractional component (example: '48.00')
** will have a MEM_Int representation when bTryForInt is true.
**
** If bTryForInt is false, then if the input string contains a decimal
** point or exponential notation, the result is only MEM_Real, even
** if there is an exact integer representation of the quantity.
******* Begin file sqlite3rtree.h ********
Token that describes the complete CREATE TRIGGER
aOrder array
Trace this connection
Make sure zData points to enough of the record to cover the header.
At this point pNew->nOut is set to the number of rows expected to
** be visited by the index scan before considering term pTerm, or the
** values of nIn and nInMul. In other words, assuming that all
** "x IN(...)" terms are replaced with "x = ?". This block updates
** the value of pNew->nOut to account for pTerm (but not nIn/nInMul).
19-24
Number of slots allocated for aLTerm[]
comment:
** Characters that may appear in the second argument to matchinfo().
label: code-design
Extra content
Name of the database containing table, or NULL
EOF
Precision of the current field
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
460
** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
** a miss - like strcmp().
Unless an error has occurred, register numbers are always positive.
OUT: New cursor object
largest root page number
** next_row:
** regChng = 0
** if( idx(0) != regPrev(0) ) goto chng_addr_0
** regChng = 1
** if( idx(1) != regPrev(1) ) goto chng_addr_1
** ...
** regChng = N
** goto endDistinctTest
Number of labels used
An implied index of the table
xOpen
Loop counter 0..nSnippet-1
Write the payload into the local Cell and any extra into overflow pages
** Normally, a PmaReader object iterates through an existing PMA stored
** within a temp file. However, if the PmaReader.pIncr variable points to
** an object of the following type, it may be used to iterate/merge through
** multiple PMAs simultaneously.
**
** There are two types of IncrMerger object - single (bUseThread==0) and
** multi-threaded (bUseThread==1).
**
** A multi-threaded IncrMerger object uses two temporary files - aFile[0]
** and aFile[1]. Neither file is allowed to grow to more than mxSz bytes in
** size. When the IncrMerger is initialized, it reads enough data from
** pMerger to populate aFile[0]. It then sets variables within the
** corresponding PmaReader object to read from that file and kicks off
** a background thread to populate aFile[1] with the next mxSz bytes of
** sorted record data from pMerger.
**
** When the PmaReader reaches the end of aFile[0], it blocks until the
** background thread has finished populating aFile[1]. It then exchanges
** the contents of the aFile[0] and aFile[1] variables within this structure,
** sets the PmaReader fields to read from the new aFile[0] and kicks off
** another background thread to populate the new aFile[1]. And so on, until
** the contents of pMerger are exhausted.
**
** A single-threaded IncrMerger does not open any temporary files of its
** own. Instead, it has exclusive access to mxSz bytes of space beginning
** at offset iStartOff of file pTask->file2. And instead of using a
** background thread to prepare data for the PmaReader, with a single
** threaded IncrMerger the allocate part of pTask->file2 is "refilled" with
** keys from pMerger by the calling thread whenever the PmaReader runs out
** of data.
** Open a blob handle.
Mask of OLD.* columns in use
Magic number for sanity checking
Make an entry in the sqlite_master table
Opcode: SorterNext P1 P2 * * P5
**
** This opcode works just like OP_Next except that P1 must be a
** sorter object for which the OP_SorterSort opcode has been
** invoked. This opcode advances the cursor to the next sorted
** record, or jumps to P2 if there are no more sorted records.
************* End of parse.c **********************************************
comment:
** The following array holds FuncDef structures for all of the functions
** defined in this file.
**
** The array cannot be constant since changes are made to the
** FuncDef.pHash elements at start-time. The elements of this array
** are read-only after initialization is complete.
**
** For peak efficiency, put the most frequently used function last.
label: code-design
Absolute level to delete from
Comparison affinity
expr ::= MINUS expr
Ignore wal frames before this one
** Fill the Index.aiRowEst[] array with default information - information
** to be used when we have not run the ANALYZE command.
**
** aiRowEst[0] is supposed to contain the number of elements in the index.
** Since we do not know, guess 1 million. aiRowEst[1] is an estimate of the
** number of rows in the table that match any particular value of the
** first column of the index. aiRowEst[2] is an estimate of the number
** of rows that match any particular combination of the first 2 columns
** of the index. And so forth. It must always be the case that
*
** aiRowEst[N]<=aiRowEst[N-1]
** aiRowEst[N]>=1
**
** Apart from that, we have little to go on besides intuition as to
** how aiRowEst[] should be initialized. The numbers generated here
** are based on typical values found in actual indices.
** 2008 August 18
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains routines used for walking the parser tree and
** resolve all identifiers by associating them with a particular
** table and column.
Number of bytes in text at z
synopsis: if r[P3]=null halt
Right subnode
If there are other active statements that belong to this database
** handle, downgrade to a read-only transaction. The other statements
** may still be reading from the database.
** This function is called on every node of an expression tree used as an
** argument to the OP_CursorHint instruction. If the node is a TK_COLUMN
** that accesses any table other than the one identified by
** CCurHint.iTabCur, then do the following:
**
** 1) allocate a register and code an OP_Column instruction to read
** the specified column into the new register, and
**
** 2) transform the expression node to a TK_REGISTER node that reads
** from the newly populated register.
**
** Also, if the node is a TK_COLUMN that does access the table idenified
** by pCCurHint.iTabCur, and an index is being used (which we will
** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
** an access of the index rather than the original table.
ifexists ::=
** Walk the parse trees associated with all subqueries in the
** FROM clause of SELECT statement p. Do not invoke the select
** callback on p, but do invoke it on each FROM clause subquery
** and on any subqueries further down in the tree. Return
** WRC_Abort or WRC_Continue;
The new rowid is not NULL (in this case the rowid will be
** automatically assigned and there is no chance of a conflict), and
** the statement is either an INSERT or an UPDATE that modifies the
** rowid column. So if the conflict mode is REPLACE, then delete any
** existing row with rowid=pNewRowid.
**
** Or, if the conflict mode is not REPLACE, insert the new record into
** the %_content table. If we hit the duplicate rowid constraint (or any
** other error) while doing so, return immediately.
**
** This branch may also run if pNewRowid contains a value that cannot
** be losslessly converted to an integer. In this case, the eventual
** call to fts3InsertData() (either just below or further on in this
** function) will return SQLITE_MISMATCH. If fts3DeleteByRowid is
** invoked, it will delete zero rows (since no row will have
** docid=$pNewRowid if $pNewRowid is not an integer value).
Value of k is out of range. Database corruption
downgrading to a shared lock on NFS involves clearing the write lock
** before establishing the readlock - to avoid a race condition we downgrade
** the lock in 2 blocks, so that part of the range will be covered by a
** write lock until the rest is covered by a read lock:
** 1: [WWWWW]
** 2: [....W]
** 3: [RRRRW]
** 4: [RRRR.]
** Return the index of the cell containing a pointer to node pNode
** in its parent. If pNode is the root node, return -1.
** Unlink the given table from the hash tables and the delete the
** table structure with all its indices and foreign keys.
Current parse context
end loop over pSrcList
comment:
** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
** defined. We need to defend against those failures when testing with
** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
** during a normal build. The following macro can be used to disable tests
** that are always false except when SQLITE_TEST_REALLOC_STRESS is set.
label: test
Score of best snippet
Both tables must have the same INTEGER PRIMARY KEY
This block ensures that all data required to recreate the original
** database has been stored in the journal for pDestPager and the
** journal synced to disk. So at this point we may safely modify
** the database file in any way, knowing that if a power failure
** occurs, the original database will be reconstructed from the
** journal file.
Memory allocation function
** Invalidate the current position list for phrase pPhrase.
Create a new change object containing all the old values (if
** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
** values (if this is an INSERT).
Matching left table
** Generate code for the start of the iLevel-th loop in the WHERE clause
** implementation described by pWInfo.
199
True if currently busy
Document store
Parse context (for malloc() and error reporting)
Mark the table as Ephemeral prior to deleting it, so that the
** sqlite3DeleteTable() routine will know that it is not stored in
** the schema.
comment:
** Make copies of relevant WHERE clause terms of the outer query into
** the WHERE clause of subquery. Example:
**
** SELECT * FROM (SELECT a AS x, c-d AS y FROM t1) WHERE x=5 AND y=10;
**
** Transformed into:
**
** SELECT * FROM (SELECT a AS x, c-d AS y FROM t1 WHERE a=5 AND c-d=10)
** WHERE x=5 AND y=10;
**
** The hope is that the terms added to the inner query will make it more
** efficient.
**
** Do not attempt this optimization if:
**
** (1) The inner query is an aggregate. (In that case, we'd really want
** to copy the outer WHERE-clause terms onto the HAVING clause of the
** inner query. But they probably won't help there so do not bother.)
**
** (2) The inner query is the recursive part of a common table expression.
**
** (3) The inner query has a LIMIT clause (since the changes to the WHERE
** close would change the meaning of the LIMIT).
**
** (4) The inner query is the right operand of a LEFT JOIN. (The caller
** enforces this restriction since this routine does not have enough
** information to know.)
**
** (5) The WHERE clause expression originates in the ON or USING clause
** of a LEFT JOIN.
**
** Return 0 if no changes are made and non-zero if one or more WHERE clause
** terms are duplicated into the subquery.
label: code-design
If this statement was prepared using saved SQL and an
** error has occurred, then return the error code in p->rc to the
** caller. Set the error code in the database handle to the same value.
Estimated number of rows returned
comment:
** CAPI3REF: Destroy A Prepared Statement Object
** DESTRUCTOR: sqlite3_stmt
**
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
** ^If the most recent evaluation of the statement encountered no errors
** or if the statement is never been evaluated, then sqlite3_finalize() returns
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
** sqlite3_finalize(S) returns the appropriate [error code] or
** [extended error code].
**
** ^The sqlite3_finalize(S) routine can be called at any point during
** the life cycle of [prepared statement] S:
** before statement S is ever evaluated, after
** one or more calls to [sqlite3_reset()], or after any call
** to [sqlite3_step()] regardless of whether or not the statement has
** completed execution.
**
** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
**
** The application must finalize every [prepared statement] in order to avoid
** resource leaks. It is a grievous error for the application to try to use
** a prepared statement after it has been finalized. Any use of a prepared
** statement after it has been finalized can result in undefined and
** undesirable behavior such as segfaults and heap corruption.
label: code-design
The database to store the trigger in
** Buffer (a/n) is assumed to contain a list of serialized varints. Read
** each varint and append its string representation to buffer pBuf. Return
** after either the input buffer is exhausted or a 0 value is read.
**
** The return value is the number of bytes read from the input buffer.
Checksum value to return
COMMA => nothing
comment: Omit unused tables in joins
label: code-design
** Unregister a VFS so that it is no longer accessible.
The connection to be opened
Function to reinitialize pages
Index within level, or 0x7FFFFFFF for PT
True if wrong number of arguments
** Continue the search on cursor pCur until the front of the queue
** contains an entry suitable for returning as a result-set row,
** or until the RtreeSearchPoint queue is empty, indicating that the
** query has completed.
X costs more than Y
Implemented as a co-routine
** Flags that make up the mask passed to sqlite3PagerGet().
272
** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
** interface.
**
** For each FROM-clause subquery, add Column.zType and Column.zColl
** information to the Table structure that represents the result set
** of that subquery.
**
** The Table structure that represents the result set was constructed
** by selectExpander() but the type and collation information was omitted
** at that point because identifiers had not yet been resolved. This
** routine is called after identifier resolution.
Opcode: SeekGE P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as the key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the smallest entry that
** is greater than or equal to the key value. If there are no records
** greater than or equal to the key and P2 is not zero, then jump to P2.
**
** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
** opcode will always land on a record that equally equals the key, or
** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this
** opcode must be followed by an IdxLE opcode with the same arguments.
** The IdxLE opcode will be skipped if this opcode succeeds, but the
** IdxLE opcode will be used on subsequent loop iterations.
**
** This opcode leaves the cursor configured to move in forward order,
** from the beginning toward the end. In other words, the cursor is
** configured to use Next, not Prev.
**
** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
Opcode: DropTrigger P1 * * P4 *
**
** Remove the internal (in-memory) data structures that describe
** the trigger named P4 in database P1. This is called after a trigger
** is dropped from disk (using the Destroy opcode) in order to keep
** the internal representation of the
** schema consistent with what is on disk.
File name
xFullPathname
** A trigger is either a BEFORE or an AFTER trigger. The following constants
** determine which.
**
** If there are multiple triggers, you might of some BEFORE and some AFTER.
** In that cases, the constants below can be ORed together.
comment: The term of the WHERE clause to be coded
label: code-design
Second argument to matchinfo() function
740
** Tokenize some text using the ascii tokenizer.
Make sure all the indices are constructed correctly.
JOIN
390
This routine constructs a binary expression node out of two ExprSpan
** objects and uses the result to populate a new ExprSpan object.
** Return TRUE if the cursor is not pointing at an entry of the table.
**
** TRUE will be returned after a call to sqlite3BtreeNext() moves
** past the last entry in the table or sqlite3BtreePrev() moves past
** the first entry. TRUE is also returned if the table is empty.
Append the non-PK part of the WHERE clause
Address where integer counter is initialized
** Make sure the given Mem is \u0000 terminated.
** Check to see if the CreateFileMappingA function is supported on the
** target system. It is unavailable when using "mincore.lib" on Win10.
** When compiling for Windows 10, always assume "mincore.lib" is in use.
For an INSERT, memory cell p->iNewReg contains the serialized record
** that is being inserted. Deserialize it.
comment: A base allocation. Not from malloc.
label: code-design
NDEBUG
If this is a new term, query for it. Update cksum3 with the results.
Previous row content
insert_cmd ::= INSERT orconf
Bytes of new data
Document text to extract snippet from
The table to rename.
** Advance the iterator to the next coalesced phrase instance. Return
** an SQLite error code if an error occurs, or SQLITE_OK otherwise.
Handle for sqlite3DbMallocRawNN()
One of the CURTYPE_* values above
Index.aiRowLogEst
Next input in pMerge
Support sqlite3WhereIsSorted()
orconf ::=
** "*val" is a double such that 0.1 <= *val < 10.0
** Return the ascii code for the leading digit of *val, then
** multiply "*val" by 10.0 to renormalize.
**
** Example:
** input: *val = 3.14159
** output: *val = 1.4159 function return = '3'
**
** The counter *cnt is incremented each time. After counter exceeds
** 16 (the number of significant digits in a 64-bit float) '0' is
** always returned.
Parsing & code generating context
A "special" INSERT op. These are handled separately.
Index of WhereLoop in pPath being processed
Remove all entries from a hash table. Reclaim all memory.
** Call this routine to delete a hash table or to reset a hash table
** to the empty state.
SQL used to find output index
Page data
same as TK_BITAND, in1, in2, out3
FTS5_NOT node to advance
SQLITE_MAX_MMAP_SIZE>0
Fts3 cursor for current query
** Free memory.
Name of the open file
JNODE flags
Pointer to changeset buffer
True if a m-j name has been written to jrnl
Segment to delete
** CAPI3REF: Flush caches to disk mid-transaction
**
** ^If a write-transaction is open on [database connection] D when the
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
** pages in the pager-cache that are not currently in use are written out
** to disk. A dirty page may be in use if a database cursor created by an
** active SQL statement is reading from it, or if it is page 1 of a database
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
** interface flushes caches for all schemas - "main", "temp", and
** any [attached] databases.
**
** ^If this function needs to obtain extra database locks before dirty pages
** can be flushed to disk, it does so. ^If those locks cannot be obtained
** immediately and there is a busy-handler callback configured, it is invoked
** in the usual manner. ^If the required lock still cannot be obtained, then
** the database is skipped and an attempt made to flush any dirty pages
** belonging to the next (if any) database. ^If any databases are skipped
** because locks cannot be obtained, but no other error occurs, this
** function returns SQLITE_BUSY.
**
** ^If any other error occurs while flushing dirty pages to disk (for
** example an IO error or out-of-memory condition), then processing is
** abandoned and an SQLite [error code] is returned to the caller immediately.
**
** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
**
** ^This function does not set the database handle error code or message
** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
Column number of matching column on the left
SQLITE_CHECKPOINT_* value
** 2008 Nov 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This module contains code that implements a parser for fts3 query strings
** (the right-hand argument to the MATCH operator). Because the supported
** syntax is relatively simple, the whole tokenizer/parser system is
** hand-coded.
0 = main program, 1 = first sub-program etc.
True when aMatchinfo[] needs filling in
Open file descriptor
Error code from db file unlock operation
** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
** parameters) to see if it outputs rows in the requested ORDER BY
** (or GROUP BY) without requiring a separate sort operation. Return N:
**
** N>0: N terms of the ORDER BY clause are satisfied
** N==0: No terms of the ORDER BY clause are satisfied
** N<0: Unknown yet how many terms of ORDER BY might be satisfied.
**
** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
** strict. With GROUP BY and DISTINCT the only requirement is that
** equivalent rows appear immediately adjacent to one another. GROUP BY
** and DISTINCT do not require rows to appear in any particular order as long
** as equivalent rows are grouped together. Thus for GROUP BY and DISTINCT
** the pOrderBy terms can be matched in any order. With ORDER BY, the
** pOrderBy terms must be matched in strict left-to-right order.
** Copy the contents of object (*pFrom) into (*pTo).
Opcode: SeekLT P1 P2 P3 P4 *
** Synopsis: key=r[P3@P4]
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as a key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the largest entry that
** is less than the key value. If there are no records less than
** the key and P2 is not zero, then jump to P2.
**
** This opcode leaves the cursor configured to move in reverse order,
** from the end toward the beginning. In other words, the cursor is
** configured to use Prev, not Next.
**
** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
Before doing anything else, call the xSync() callback for any
** virtual module tables written in this transaction. This has to
** be done before determining whether a master journal file is
** required, as an xSync() callback may add an attached database
** to the transaction.
Result from sqlite3Reprepare()
Index.aiRowEst may already be set here if there are duplicate
** sqlite_stat1 entries for this index. In that case just clobber
** the old data with the new instead of allocating a new array.
** The parser calls this routine in order to create a new VIEW
Parent table of foreign key pFKey
(324) vtabarglist ::= vtabarglist COMMA vtabarg
** Instances of this structure are used to build strings or binary records.
Opcode: MakeRecord P1 P2 P3 P4 *
** Synopsis: r[P3]=mkrec(r[P1@P2])
**
** Convert P2 registers beginning with P1 into the [record format]
** use as a data record in a database table or as a key
** in an index. The OP_Column opcode can decode the record later.
**
** P4 may be a string that is P2 characters long. The N-th character of the
** string indicates the column affinity that should be used for the N-th
** field of the index key.
**
** The mapping from character to affinity is given by the SQLITE_AFF_
** macros defined in sqliteInt.h.
**
** If P4 is NULL then all index fields have the affinity BLOB.
SELECTRACE_ENABLED
Number of pages in the database according to hdr
Insert an implicit AND operator.
************* Begin file mutex_noop.c *************************************
ON DELETE and ON UPDATE actions, respectively
same as TK_LE, jump, in1, in3
Docid to read size data for
ifndef SQLITE_OMIT_AUTOVACUUM
(term <= $zLeTerm) paramater, or NULL
How to dispose of the results
synopsis: r[P2]=P4
Number of pages in pList
Table structure
The main DB, main journal, WAL file and master journal are never
** automatically deleted. Nor are they ever temporary files.
Size of term suffix in bytes
Adjust downward, as appropriate
OUT: Bytes stored locally
If this instruction implements a COMMIT and other VMs are writing
** return an error indicating that the other VMs must complete first.
Parsing contexts
Type of the RHS
Cursor open on pIdx
** PRAGMA wal_autocheckpoint
** PRAGMA wal_autocheckpoint = N
**
** Configure a database connection to automatically checkpoint a database
** after accumulating N frames in the log. Or query for the current value
** of N.
FTS3 table cursor
Number of columns in the result set
** sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
**
** Set the PENDING byte to the value in the argument, if X>0.
** Make no changes if X==0. Return the value of the pending byte
** as it existing before this routine was called.
**
** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
** an incompatible database file format. Changing the PENDING byte
** while any database connection is open results in undefined and
** deleterious behavior.
Used to iterate through zArg
One-time setup cost (ex: create transient index)
If an EXCLUSIVE lock can be obtained on the database file (using the
** ordinary, rollback-mode locking methods, this guarantees that the
** connection associated with this log file is the only connection to
** the database. In this case checkpoint the database and unlink both
** the wal and wal-index files.
**
** The EXCLUSIVE lock is not released before returning.
comment: Clean up before exiting
label: code-design
** This is the xFilter implementation for the virtual table.
Collision detection may be omitted if all of the following are true:
** (1) The conflict resolution algorithm is REPLACE
** (2) The table is a WITHOUT ROWID table
** (3) There are no secondary indexes on the table
** (4) No delete triggers need to be fired if there is a conflict
** (5) No FK constraint counters need to be updated if a conflict occurs.
Pointer to buffer containing changeset B
Register containing index name
440
** Internal types used by SQLite.
Number of trailing arguments for rank()
Number of entries currently in hash
comment:
** Growing our own isspace() routine this way is twice as fast as
** the library isspace() function, resulting in a 7% overall performance
** increase for the parser. (Ubuntu14.10 gcc 4.8.4 x64 with -Os).
label: code-design
comment:
** Close a file descriptor.
**
** We assume that close() almost always works, since it is only in a
** very sick application or on a very sick platform that it might fail.
** If it does fail, simply leak the file descriptor, but do log the
** error.
**
** Note that it is not safe to retry close() after EINTR since the
** file descriptor might have already been reused by another thread.
** So we don't even try to recover from an EINTR. Just log the error
** and move on.
label: code-design
Flags this file descriptor was opened with
** The makefile scans the vdbe.c source file and creates the "opcodes.h"
** header file that defines a number for each opcode used by the VDBE.
flags = BTREE_INTKEY;
** Parameters z and n contain a pointer to and length of a buffer containing
** an fts3 query expression, respectively. This function attempts to parse the
** query expression and create a tree of Fts3Expr structures representing the
** parsed expression. If successful, *ppExpr is set to point to the head
** of the parsed expression tree and SQLITE_OK is returned. If an error
** occurs, either SQLITE_NOMEM (out-of-memory error) or SQLITE_ERROR (parse
** error) is returned and *ppExpr is set to 0.
**
** If parameter n is a negative number, then z is assumed to point to a
** nul-terminated string and the length is determined using strlen().
**
** The first parameter, pTokenizer, is passed the fts3 tokenizer module to
** use to normalize query tokens while parsing the expression. The azCol[]
** array, which is assumed to contain nCol entries, should contain the names
** of each column in the target fts3 table, in order from left to right.
** Column names must be nul-terminated strings.
**
** The iDefaultCol parameter should be passed the index of the table column
** that appears on the left-hand-side of the MATCH operator (the default
** column to match against for tokens for which a column name is not explicitly
** specified as part of the query string), or -1 if tokens may by default
** match any table column.
Set iRoot to the index in pWriter->aNodeWriter[] of the output segment
** root node. If the segment fits entirely on a single leaf node, iRoot
** will be set to 0. If the root node is the parent of the leaves, iRoot
** will be 1. And so on.
228
.flags =
************* End of os_win.c *********************************************
CPU clock count at start of opcode
Full scan via index
comment: If the cursor is currently on the last row and we are appending a
** new row onto the end, set the "loc" to avoid an unnecessary
** btreeMoveto() call
label: code-design
If no data has been written to disk, then do not do so now. Instead,
** sort the VdbeSorter.pRecord list. The vdbe layer will read data directly
** from the in-memory list.
FROM clause item
Bytes required to hold database name
Count the number of possible WHERE clause constraints referring
** to this virtual table
Iterates through snippet candidates
True if last 0x00 counts
Authorization denied
** The journal file must be open when this is called. A journal header file
** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
** file. The current location in the journal file is given by
** pPager->journalOff. See comments above function writeJournalHdr() for
** a description of the journal header format.
**
** If the header is read successfully, *pNRec is set to the number of
** page records following this header and *pDbSize is set to the size of the
** database before the transaction began, in pages. Also, pPager->cksumInit
** is set to the value read from the journal header. SQLITE_OK is returned
** in this case.
**
** If the journal header file appears to be corrupted, SQLITE_DONE is
** returned and *pNRec and *PDbSize are undefined. If JOURNAL_HDR_SZ bytes
** cannot be read from the journal file an error code is returned.
Write up to this many output leaves
List of triggers on table pTab
X not a subset of Y since term X[i] not used by Y
** An instance of this structure is used to iterate through the terms on
** a contiguous set of segment b-tree leaf nodes. Although the details of
** this structure are only manipulated by code in this file, opaque handles
** of type Fts3SegReader* are also used by code in fts3.c to iterate through
** terms when querying the full-text index. See functions:
**
** sqlite3Fts3SegReaderNew()
** sqlite3Fts3SegReaderFree()
** sqlite3Fts3SegReaderIterate()
**
** Methods used to manipulate Fts3SegReader structures:
**
** fts3SegReaderNext()
** fts3SegReaderFirstDocid()
** fts3SegReaderNextDocid()
Flush the hash table to disk if required
If the NEAR expression does not match any rows, zero the doclist for
** all phrases involved in the NEAR. This is because the snippet(),
** offsets() and matchinfo() functions are not supposed to recognize
** any instances of phrases that are part of unmatched NEAR queries.
** For example if this expression:
**
** ... MATCH 'a OR (b NEAR c)'
**
** is matched against a row containing:
**
** 'a b d e'
**
** then any snippet() should ony highlight the "a" term, not the "b"
** (as "b" is part of a non-matching NEAR clause).
320
** Enlarge a memory allocation. If an out-of-memory allocation occurs,
** then free the old allocation.
The path to search
comment:
** CAPI3REF: Test To See If The Library Is Threadsafe
**
** ^The sqlite3_threadsafe() function returns zero if and only if
** SQLite was compiled with mutexing code omitted due to the
** [SQLITE_THREADSAFE] compile-time option being set to 0.
**
** SQLite can be compiled with or without mutexes. When
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
** are enabled and SQLite is threadsafe. When the
** [SQLITE_THREADSAFE] macro is 0,
** the mutexes are omitted. Without the mutexes, it is not safe
** to use SQLite concurrently from more than one thread.
**
** Enabling mutexes incurs a measurable performance penalty.
** So if speed is of utmost importance, it makes sense to disable
** the mutexes. But for maximum safety, mutexes should be enabled.
** ^The default behavior is for mutexes to be enabled.
**
** This interface can be used by an application to make sure that the
** version of SQLite that it is linking against was compiled with
** the desired setting of the [SQLITE_THREADSAFE] macro.
**
** This interface only reports on the compile-time mutex setting
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
** can be fully or partially disabled using a call to [sqlite3_config()]
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
** sqlite3_threadsafe() function shows only the compile-time setting of
** thread safety, not any run-time changes to that setting made by
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
** is unchanged by calls to sqlite3_config().)^
**
** See the [threading mode] documentation for additional information.
label: requirement
Hash table buckets
** End a write transaction. The commit has already been done. This
** routine merely releases the lock.
Number of index columns w/o the pk/rowid
Used by VdbeSorterCompare()
Array of phrase freq. for current row
comment:
** Generate a human-readable description of a WITH clause.
label: code-design
IMP: R-20520-54086
Set the error code of the destination database handle.
** Functions to serialize a 16 bit integer, 32 bit real number and
** 64 bit integer. The value returned is the number of bytes written
** to the argument buffer (always 2, 4 and 8 respectively).
value_type() of apVal[0]
True if info.nKey is valid
Columns for imposter table
This routine implements an SQL function that returns the "depth" parameter
** from the front of a blob that is an r-tree node. For example:
**
** SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
**
** The depth value is 0 for all nodes other than the root node, and the root
** node always has nodeno=1, so the example above is the primary use for this
** routine. This routine is intended for testing and analysis only.
sortorder ::= DESC
rowid <= ? expression (or NULL)
If this path name begins with "/X:", where "X" is any alphabetic
** character, discard the initial "/" from the pathname.
same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2]
Number of key columns
Zero the contents of pRoot. Then install pChild as the right-child.
Index to consider domain of
porter rule condition: (m > 1)
Name of the trigger
Make sure the database schema is loaded if the pragma requires that
Tokenization callback context object
UTF-8 encoded SQL statement.
Byte offset to previous journal header
column list if this is an UPDATE OF trigger
Next element of the cell pointer array
(pKey1/nKey1) is a blob
Index of function argument.
True to omit %_docsize table
OUT: New db size (or 0 if not commit)
** Given a wildcard parameter name, return the index of the variable
** with that name. If there is no variable with the given name,
** return 0.
Add additional columns needed to make the automatic index into
** a covering index
The phrase extracted from pExpr
#include <stdio.h>
** Set up a cursor object for iterating through a full-text index or a
** single level therein.
Main database page size
It is not possible to release (commit) a savepoint if there are
** active write statements.
Language id for current row
Mask of trigger times
A single level in pWInfo->a[]
Index.nSample is non-zero at this point if data has already been
** loaded from the stat4 table. In this case ignore stat3 data.
Node number to load
SQLITE_PROTOCOL? SQLITE_MISUSE?
Number of columns in index being sampled
An ORDER/GROUP BY clause of more than 63 terms cannot be optimized
Output array
Size of previous chunk in Mem3Block elements
Value of julianday('now') for this statement
Max database page to write
** Exported version of applyAffinity(). This one works on sqlite3_value*,
** not the internal Mem* type.
** Insert an OP_CursorHint instruction if it is appropriate to do so.
Output of stat() on database file
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
** Read the first N bytes from the beginning of the file into memory
** that pDest points to.
**
** If the pager was opened on a transient file (zFilename==""), or
** opened on a file less than N bytes in size, the output buffer is
** zeroed and SQLITE_OK returned. The rationale for this is that this
** function is used to read database headers, and a new transient or
** zero sized database has a header than consists entirely of zeroes.
**
** If any IO error apart from SQLITE_IOERR_SHORT_READ is encountered,
** the error code is returned to the caller and the contents of the
** output buffer undefined.
The result set must have exactly one column
Eponymous table for this module
An array to map all upper-case characters into their corresponding
** lower-case character.
**
** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
** handle case conversions for the UTF character set since the tables
** involved are nearly as big or bigger than SQLite itself.
Token (or prefix) to query for
Fix the pointer map entries associated with the right-child of each
** sibling page. All other pointer map entries have already been taken
** care of.
** Unless this is an in-memory or temporary database, clear the pager cache.
(2a)
** Tokenize the text passed via the second and third arguments.
**
** The callback is invoked once for each token in the input text. The
** arguments passed to it are, in order:
**
** void *pCtx // Copy of 4th argument to sqlite3Fts5Tokenize()
** const char *pToken // Pointer to buffer containing token
** int nToken // Size of token in bytes
** int iStart // Byte offset of start of token within input text
** int iEnd // Byte offset of end of token within input text
** int iPos // Position of token in input (first token is 0)
**
** If the callback returns a non-zero value the tokenization is abandoned
** and no further callbacks are issued.
**
** This function returns SQLITE_OK if successful or an SQLite error code
** if an error occurs. If the tokenization was abandoned early because
** the callback returned SQLITE_DONE, this is not an error and this function
** still returns SQLITE_OK. Or, if the tokenization was abandoned early
** because the callback returned another non-zero value, it is assumed
** to be an SQLite error code and returned to the caller.
True for xCreate, false for xConnect
It is possible to append to this segment. Set up the IncrmergeWriter
** object to do so.
** Return TRUE if the named file is really a directory. Return false if
** it is something other than a directory, or if there is any kind of memory
** allocation failure.
cmd ::= COMMIT|END trans_opt
a
Added by the optimizer. Do not code
defined(_MSC_VER) && _MSC_VER>=1400
Loop counter: Next table in schema
iArg:
The following variables are used by fts3SegReaderNextDocid() to iterate
** through the current doclist (aDoclist/nDoclist).
Wal frame to lock to
31
comment:
** Iterator pIter currently points to the first rowid of a doclist.
** There is a doclist-index associated with the final term on the current
** page. If the current term is the last term on the page, load the
** doclist-index from disk and initialize an iterator at (pIter->pDlidx).
label: code-design
Following a rollback, the database file should be back in its original
** state prior to the start of the transaction, so invoke the
** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
** assertion that the transaction counter was modified.
payload
** Allocate and populate an UnpackedRecord structure based on the serialized
** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure
** if successful, or a NULL pointer if an OOM error is encountered.
List of explicit column names, or NULL
Size of the zMalloc allocation
100
GROUPBY cover of ORDERBY
Do not delete the table until the reference count reaches zero.
Query the WAL sub-system for the database size. The WalDbsize()
** function returns zero if the WAL is not open (i.e. Pager.pWal==0), or
** if the database size is not available. The database size is not
** available from the WAL sub-system if the log file is empty or
** contains no valid committed transactions.
Loop over all indices
** Object used to represent an shared memory buffer.
**
** When multiple threads all reference the same wal-index, each thread
** has its own unixShm object, but they all point to a single instance
** of this unixShmNode object. In other words, each wal-index is opened
** only once per process.
**
** Each unixShmNode object is connected to a single unixInodeInfo object.
** We could coalesce this object into unixInodeInfo, but that would mean
** every open file that does not use shared memory (in other words, most
** open files) would have to carry around this extra information. So
** the unixInodeInfo object contains a pointer to this unixShmNode object
** and the unixShmNode object is created only when needed.
**
** unixMutexHeld() must be true when creating or destroying
** this object or while reading or writing the following fields:
**
** nRef
**
** The following fields are read-only after the object is created:
**
** fid
** zFilename
**
** Either unixShmNode.mutex must be held or unixShmNode.nRef==0 and
** unixMutexHeld() is true when reading or writing any other field
** in this structure.
** Test a register to see if it exceeds the current maximum blob size.
** If it does, record the new maximum blob size.
number of rows in the table
** Macros to Set(), Clear() and Test() cursor flags.
SELECT may not have an ORDER BY clause
Inequality constraint at range end
True if OP_Affinity has been run already
Opcode: HaltIfNull P1 P2 P3 P4 P5
** Synopsis: if r[P3]=null halt
**
** Check the value in register P3. If it is NULL then Halt using
** parameter P1, P2, and P4 as if this were a Halt instruction. If the
** value in register P3 is not NULL, then this routine is a no-op.
** The P5 parameter should be 1.
Current index for apPage[iPage]
Continue rolling back records out of the main journal starting at
** the first journal header seen and continuing until the effective end
** of the main journal file. Continue to skip out-of-range pages and
** continue adding pages rolled back to pDone.
This virtual table always delivers results in ascending order of
** the "term" column (column 0). So if the user has requested this
** specifically - "ORDER BY term" or "ORDER BY term ASC" - set the
** sqlite3_index_info.orderByConsumed flag to tell the core the results
** are already in sorted order.
Comparing signed and unsigned
** Generate code for a boolean expression such that a jump is made
** to the label "dest" if the expression is false but execution
** continues straight thru if the expression is true.
**
** If the expression evaluates to NULL (neither true nor false) then
** jump if jumpIfNull is SQLITE_JUMPIFNULL or fall through if jumpIfNull
** is 0.
** Register all built-in tokenizers with FTS5.
If a journal file exists, and there is no RESERVED lock on the
** database file, then it either needs to be played back or deleted.
Bytes of space to allocate
sqlite3_create_collation only
Document being tokenized
Unless i==pIdx->nSample, indicating that pRec is larger than
** all samples in the aSample[] array, pRec must be smaller than the
** (iCol+1) field prefix of sample i.
** Maximum depth of recursion for triggers.
**
** A value of 1 means that a trigger program will not be able to itself
** fire any triggers. A value of 0 means that no trigger programs at all
** may be executed.
Code an OP_Transaction and OP_TableLock for <table>.
** Call sqlite3WalkExpr() for every expression in Select statement p.
** Invoke sqlite3WalkSelect() for subqueries in the FROM clause and
** on the compound select chain, p->pPrior.
**
** If it is not NULL, the xSelectCallback() callback is invoked before
** the walk of the expressions and FROM clause. The xSelectCallback2()
** method is invoked following the walk of the expressions and FROM clause,
** but only if both xSelectCallback and xSelectCallback2 are both non-NULL
** and if the expressions and FROM clause both return WRC_Continue;
**
** Return WRC_Continue under normal conditions. Return WRC_Abort if
** there is an abort request.
**
** If the Walker does not have an xSelectCallback() then this routine
** is a no-op returning WRC_Continue.
Return code from subroutines
If pPrior is part of the data area of pPage, then make sure pPage
** is still writeable
Path to this page
If an expression is an integer literal that fits in a signed 32-bit
** integer, then the EP_IntValue flag will have already been set
Used for rounding floating point values
** Return information regarding the PRIMARY KEY and number of columns in
** the database table affected by the change that pIter currently points
** to. This function may only be called after changeset_next() returns
** SQLITE_ROW.
Trigger Name Table Name
** These macros can be used to test, set, or clear bits in the
** Db.pSchema->flags field.
Call the progress callback if it is configured and the required number
** of VDBE ops have been executed (either since this invocation of
** sqlite3VdbeExec() or since last time the progress callback was called).
** If the progress callback returns non-zero, exit the virtual machine with
** a return code SQLITE_ABORT.
178
Vdbe to add code to
"nlt" column of stat[34] entry
** pEList is the SET clause of an UPDATE statement. Each entry
** in pEList is of the format <id>=<expr>. If any of the entries
** in pEList have an <id> which matches an identifier in pIdList,
** then return TRUE. If pIdList==NULL, then it is considered a
** wildcard that matches anything. Likewise if pEList==NULL then
** it matches anything so always return true. Return false only
** if there is no match.
** Create an iterator used to iterate through the contents of a changeset.
Open the target, RBU and state databases
************* Begin file prepare.c ****************************************
Built-in affinity() function
The longest decimal representation of a 32 bit integer is 10 digits:
**
** 1234567890
** 2^31 -> 2147483648
page-size bytes of space for parent ovfl
Parent table of FK pFKey
Rowid of last value written
All (named) indices indexed by name
comment:
** A call to this routine tells the pager that it is not necessary to
** write the information on page pPg back to the disk, even though
** that page might be marked as dirty. This happens, for example, when
** the page has been added as a leaf of the freelist and so its
** content no longer matters.
**
** The overlying software layer calls this routine when all of the data
** on the given page is unused. The pager marks the page as clean so
** that it does not get written to disk.
**
** Tests show that this optimization can quadruple the speed of large
** DELETE operations.
**
** This optimization cannot be used with a temp-file, as the page may
** have been dirty at the start of the transaction. In that case, if
** memory pressure forces page pPg out of the cache, the data does need
** to be written out to disk so that it may be read back in if the
** current transaction is rolled back.
label: code-design
************* End of vdbe.c ***********************************************
** CAPI3REF: Collation Needed Callbacks
** METHOD: sqlite3
**
** ^To avoid having to register all collation sequences before a database
** can be used, a single callback function may be registered with the
** [database connection] to be invoked whenever an undefined collation
** sequence is required.
**
** ^If the function is registered using the sqlite3_collation_needed() API,
** then it is passed the names of undefined collation sequences as strings
** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
** the names are passed as UTF-16 in machine native byte order.
** ^A call to either function replaces the existing collation-needed callback.
**
** ^(When the callback is invoked, the first argument passed is a copy
** of the second argument to sqlite3_collation_needed() or
** sqlite3_collation_needed16(). The second argument is the database
** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
** sequence function required. The fourth parameter is the name of the
** required collation sequence.)^
**
** The callback function should register the desired collation using
** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
** [sqlite3_create_collation_v2()].
Open the sub-journal, if it has not already been opened
Size of the free slot
Result codes from subroutines
same as TK_LSHIFT, in1, in2, out3
Operational flags
To get here, there need to be 2^(N_SORT_BUCKET) elements in
** the input list. But that is impossible.
Key for ARRAY objects in json_tree()
Even though the Mem structure contains an element
** of type i64, on certain architectures (x86) with certain compiler
** switches (-Os), gcc may align this Mem object on a 4-byte boundary
** instead of an 8-byte one. This all works fine, except that when
** running with SQLITE_DEBUG defined the SQLite code sometimes assert()s
** that a Mem structure is located on an 8-byte boundary. To prevent
** these assert()s from failing, when building with SQLITE_DEBUG defined
** using gcc, we force nullMem to be 8-byte aligned using the magical
** __attribute__((aligned(8))) macro.
** Return an expression that can be used in a WHERE clause to match the
** primary key of the current table. For example, if the table is:
**
** CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c));
**
** Return the string:
**
** "b = ?1 AND c = ?2"
case_else ::=
***********************************************************************
** Above is constant between recursions. Below is reset before and after
** each recursion. The boundary between these two regions is determined
** using offsetof(Parse,sLastToken) so the sLastToken field must be the
** first field in the recursive region.
***********************************************************************
Array of all phrases
Find the parent table of this foreign key. Also find a unique index
** on the parent key columns in the parent table. If either of these
** schema items cannot be located, set an error in pParse and return
** early.
** The following table defines various date transformations of the form
**
** 'NNN days'
**
** Where NNN is an arbitrary floating-point number and "days" can be one
** of several units of time.
comment:
** The maximum number of terms in a compound SELECT statement.
** The code generator for compound SELECT statements does one
** level of recursion for each term. A stack overflow can result
** if the number of terms is too large. In practice, most SQL
** never has more than 3 or 4 terms. Use a value of 0 to disable
** any limit on the number of terms in a compount SELECT.
label: code-design
Leaf node containing record iDelete
The OFFSET clause. May be null
Where to write results
************* End of fts3_hash.c ******************************************
** If the path name starts with a letter and a colon it is either a volume
** relative path or an absolute path. Callers of this function must not
** attempt to treat it as a relative path name (i.e. they should simply use
** it verbatim).
SQLITE3_H
The "table" is actually a sub-select or a view in the FROM clause
** of the SELECT statement. Return the declaration type and origin
** data for the result-set column of the sub-select.
Segment to check internal consistency
Case 2: expr IN (exprlist)
**
** For each expression, build an index key from the evaluation and
** store it in the temporary table. If <expr> is a column, then use
** that columns affinity when building index keys. If <expr> is not
** a column, use numeric affinity.
TUNING: Cost of a rowid lookup is 10
** NOTE: We are dealing with a relative path name and the data
** directory has been set. Therefore, use it as the basis
** for converting the relative path name to an absolute
** one by prepending the data directory and a slash.
Checksum failed.
Tables that must be scanned before this one
The major type of the error token
If the index name was unqualified, check if the table
** is a temp table. If so, set the database to 1. Do not do this
** if initialising a database schema.
Minimum entry in aFirst[] to set
Last zStr[] that might match zPattern[]
URI parameter sought
OUT: Filename component of URI
This occurs when the array of context pointers that need to
** be passed to the unlock-notify callback is larger than the
** aStatic[] array allocated on the stack and the attempt to
** allocate a larger array from the heap has failed.
**
** This is a difficult situation to handle. Returning an error
** code to the caller is insufficient, as even if an error code
** is returned the transaction on connection db will still be
** closed and the unlock-notify callbacks on blocked connections
** will go unissued. This might cause the application to wait
** indefinitely for an unlock-notify callback that will never
** arrive.
**
** Instead, invoke the unlock-notify callback with the context
** array already accumulated. We can then clear the array and
** begin accumulating any further context pointers without
** requiring any dynamic allocation. This is sub-optimal because
** it means that instead of one callback with a large array of
** context pointers the application will receive two or more
** callbacks with smaller arrays of context pointers, which will
** reduce the applications ability to prioritize multiple
** connections. But it is the best that can be done under the
** circumstances.
This call cannot fail. Unless the page for which the page number
** is passed as the second argument is (a) in the cache and
** (b) has an outstanding reference, then xUndo is either a no-op
** (if (a) is false) or simply expels the page from the cache (if (b)
** is false).
**
** If the upper layer is doing a rollback, it is guaranteed that there
** are no outstanding references to any page other than page 1. And
** page 1 is never written to the log until the transaction is
** committed. As a result, the call to xUndo may not fail.
True once a write-transaction is open on pDest
Invoke the update-hook if required.
** No-op routine for the parse-tree walker for SELECT statements.
** subquery in the parser tree.
Page number array
A PENDING lock is needed before acquiring a SHARED lock and before
** acquiring an EXCLUSIVE lock. For the SHARED lock, the PENDING will
** be released.
** This is the xRowid method. The SQLite core calls this routine to
** retrieve the rowid for the current row of the result set. fts5
** exposes %_content.rowid as the rowid for the virtual table. The
** rowid should be written to *pRowid.
The database being initialized
Do not allow non-admin users to modify the schema arbitrarily
Do not enforce check constraints
comment:
** This function is invoked by the vdbe to call the xCreate method
** of the virtual table named zTab in database iDb.
**
** If an error occurs, *pzErr is set to point to an English language
** description of the error and an SQLITE_XXX error code is returned.
** In this case the caller must call sqlite3DbFree(db, ) on *pzErr.
label: code-design
A cursor number
Routine for en/decoding data
22
OUT: Score of snippet pFragment
If nRec is 0xffffffff, then this journal was created by a process
** working in no-sync mode. This means that the rest of the journal
** file consists of pages, there are no more journal headers. Compute
** the value of nRec based on this assumption.
The expression to be analyzed
aSpare array
The module for this virtual table
The old journal mode
comment:
** This is the default collating function named "BINARY" which is always
** available.
**
** If the padFlag argument is not NULL then space padding at the end
** of strings is ignored. This implements the RTRIM collation.
label: code-design
Use of a hash implementation is OK
** Close the file.
Rowid to append
Allocate any page <= the parameter
no-op
If there is a table-filter configured, invoke it. If it returns 0,
** do not automatically add the new table.
The following value is the maximum cell size assuming a maximum page
** size give above.
For looping over sibling connections
0 for min() or 0xffffffff for max()
segdir.end_block
** Maximum length (in bytes) of the pattern in a LIKE or GLOB
** operator.
term ::= NULL|FLOAT|BLOB
HAVING to WHERE clause ctx
Left key
Default page size
** Adjust memory usage statistics
OP_Column: Ephemeral output is ok
"PRAGMA encoding = XXX"
NB: seekResult does not distinguish between "no seeks have ever occurred
** on this cursor" and "the most recent seek was an exact match".
cmd ::= ROLLBACK trans_opt TO savepoint_opt nm
Current offset in position list
** This routine translates a standard POSIX errno code into something
** useful to the clients of the sqlite3 functions. Specifically, it is
** intended to translate a variety of "try again" errors into SQLITE_BUSY
** and a variety of "please close the file descriptor NOW" errors into
** SQLITE_IOERR
**
** Errors during initialization of locks, or file system support for locks,
** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately.
149
************* Begin file sqlite3ext.h *************************************
** Interfaces for opening a shared library, finding entry points
** within the shared library, and closing the shared library.
SQLITE_STMTSTATUS_REPREPARE
Open the backend database driver
** The pExpr should be a TK_COLUMN expression. The table referred to
** is in pTabList or else it is the NEW or OLD table of a trigger.
** Check to see if it is OK to read this particular column.
**
** If the auth function returns SQLITE_IGNORE, change the TK_COLUMN
** instruction into a TK_NULL. If the auth function returns SQLITE_DENY,
** then generate an error.
OP_Column/OP_Rowid references to this table
Bytes of space required
Used by: lock_status
Select the column is extracted from
The file is empty (length 0 bytes)
** Return the device characteristic flags supported by an rbuVfs-file.
** CAPI3REF: Database Connection For Functions
** METHOD: sqlite3_context
**
** ^The sqlite3_context_db_handle() interface returns a copy of
** the pointer to the [database connection] (the 1st parameter)
** of the [sqlite3_create_function()]
** and [sqlite3_create_function16()] routines that originally
** registered the application defined function.
Determine how many of the segments actually point to zTerm/nTerm.
SQLITE_MSVC_H
Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
** prevents it from checkpointing the database from sqlite3_close().
The data
TO => nothing
comment:
** The SQLITE_*_BKPT macros are substitutes for the error codes with
** the same name but without the _BKPT suffix. These macros invoke
** routines that report the line-number on which the error originated
** using sqlite3_log(). The routines also provide a convenient place
** to set a debugger breakpoint.
label: code-design
Finalize all SQL statements
** Launch a background thread to populate aFile[1] of pIncr.
** This function is called before generating code to update or delete a
** row contained in table pTab.
EVIDENCE-OF: R-08308-17224 The default collating function for all
** strings is BINARY.
One bit for each page in the database file
Invoke the stat_init() function. The arguments are:
**
** (1) the number of columns in the index including the rowid
** (or for a WITHOUT ROWID table, the number of PK columns),
** (2) the number of columns in the key without the rowid/pk
** (3) the number of rows in the index,
**
**
** The third argument is only used for STAT3 and STAT4
** An instance of the following structure is used by the tree walker
** to determine if an expression can be evaluated by reference to the
** index only, without having to do a search for the corresponding
** table entry. The IdxCover.pIdx field is the index. IdxCover.iCur
** is the cursor for the table.
A b-tree rebalance will be required after deleting this entry.
** Save the cursor key.
Otherwise see if some other process holds it.
The principle used to locate the table name in the CREATE TRIGGER
** statement is that the table name is the first token that is immediately
** preceded by either TK_ON or TK_DOT and immediately followed by one
** of TK_WHEN, TK_BEGIN or TK_FOR.
Length of a field
** Convert a sorted list of elements (connected by pRight) into a binary
** tree with depth of iDepth. A depth of 1 means the tree contains a single
** node taken from the head of *ppList. A depth of 2 means a tree with
** three nodes. And so forth.
**
** Use as many entries from the input list as required and update the
** *ppList to point to the unused elements of the list. If the input
** list contains too few elements, then construct an incomplete tree
** and leave *ppList set to NULL.
**
** Return a pointer to the root of the constructed binary tree.
** Private objects used by the sorter
** Implementation of random(). Return a random integer.
Already thrown the error if VDBE alloc failed
** PRAGMA [schema.]journal_size_limit
** PRAGMA [schema.]journal_size_limit=N
**
** Get or set the size limit on rollback journal files.
The expression is a sub-select. Return the declaration type and
** origin info for the single column in the result set of the SELECT
** statement.
The strings are already in the correct encoding. Call the
** comparison function directly
VIEW
Parsed information on cells being balanced
colset ::= MINUS LCP colsetlist RCP
restriction (3)
Sequence counter
Opcode: TableLock P1 P2 P3 P4 *
** Synopsis: iDb=P1 root=P2 write=P3
**
** Obtain a lock on a particular table. This instruction is only used when
** the shared-cache feature is enabled.
**
** P1 is the index of the database in sqlite3.aDb[] of the database
** on which the lock is acquired. A readlock is obtained if P3==0 or
** a write lock if P3==1.
**
** P2 contains the root-page of the table to lock.
**
** P4 contains a pointer to the name of the table being locked. This is only
** used to generate an error message if the lock cannot be obtained.
Encode the database
logical database name
** Return the size of the common prefix (if any) shared by zPrev and
** zNext, in bytes. For example,
**
** fts3PrefixCompress("abc", 3, "abcdef", 6) // returns 3
** fts3PrefixCompress("abX", 3, "abcdef", 6) // returns 2
** fts3PrefixCompress("abX", 3, "Xbcdef", 6) // returns 0
EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
** stores the page number of the first page of the freelist, or zero if
** the freelist is empty.
comment: TODO(shess) Explore whether partially flushing the buffer on
** forced-flush would provide better performance. I suspect that if
** we ordered the doclists by size and flushed the largest until the
** buffer was half empty, that would let the less frequent terms
** generate longer doclists.
label: code-design
Cache size in bytes
Number of values in apVal[] array
Catch mismatch in the declared columns of a view and the number of
** columns in the SELECT on the RHS
The parse tree for this expression
The type of lock held on this fd
Action to take
Non-logarithmic number of rows in the index
(1)
If the page containing the entry to delete is not a leaf page, move
** the cursor to the largest entry in the tree that is smaller than
** the entry being deleted. This cell will replace the cell being deleted
** from the internal node. The 'previous' entry is used for this instead
** of the 'next' entry, as the previous entry is always a part of the
** sub-tree headed by the child page of the cell being deleted. This makes
** balancing the tree following the delete operation easier.
Case 5: Two or more separately indexed terms connected by OR
**
** Example:
**
** CREATE TABLE t1(a,b,c,d);
** CREATE INDEX i1 ON t1(a);
** CREATE INDEX i2 ON t1(b);
** CREATE INDEX i3 ON t1(c);
**
** SELECT * FROM t1 WHERE a=5 OR b=7 OR (c=11 AND d=13)
**
** In the example, there are three indexed terms connected by OR.
** The top of the loop looks like this:
**
** Null 1 # Zero the rowset in reg 1
**
** Then, for each indexed term, the following. The arguments to
** RowSetTest are such that the rowid of the current row is inserted
** into the RowSet. If it is already present, control skips the
** Gosub opcode and jumps straight to the code generated by WhereEnd().
**
** sqlite3WhereBegin(<term>)
** RowSetTest # Insert rowid into rowset
** Gosub 2 A
** sqlite3WhereEnd()
**
** Following the above, code to terminate the loop. Label A, the target
** of the Gosub above, jumps to the instruction right after the Goto.
**
** Null 1 # Zero the rowset in reg 1
** Goto B # The loop is finished.
**
** A: <loop body> # Return data, whatever.
**
** Return 2 # Jump back to the Gosub
**
** B: <after the loop>
**
** Added 2014-05-26: If the table is a WITHOUT ROWID table, then
** use an ephemeral index instead of a RowSet to record the primary
** keys of the rows we have already seen.
**
Autovac setting after VACUUM if >=0
** Make sure that rand_s() is available on Windows systems with MSVC 2005
** or higher.
EXISTS
LHS of comparison
IN operator used for membership test
0x07
** A complete page cache is an instance of this structure. Every
** entry in the cache holds a single page of the database file. The
** btree layer only operates on the cached copy of the database pages.
**
** A page cache entry is "clean" if it exactly matches what is currently
** on disk. A page is "dirty" if it has been modified and needs to be
** persisted to disk.
**
** pDirty, pDirtyTail, pSynced:
** All dirty pages are linked into the doubly linked list using
** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
** such that p was added to the list more recently than p->pDirtyNext.
** PCache.pDirty points to the first (newest) element in the list and
** pDirtyTail to the last (oldest).
**
** The PCache.pSynced variable is used to optimize searching for a dirty
** page to eject from the cache mid-transaction. It is better to eject
** a page that does not require a journal sync than one that does.
** Therefore, pSynced is maintained to that it *almost* always points
** to either the oldest page in the pDirty/pDirtyTail list that has a
** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
** (so that the right page to eject can be found by following pDirtyPrev
** pointers).
This is the first call to this function. Do initialization.
UNIQUE
FROM clause of the outer query
2: (end_constraints && bRev && !endEq)
Memory cell holding key of row to be deleted
Database handle.
comment:
** Check to make sure we have a valid db pointer. This test is not
** foolproof but it does provide some measure of protection against
** misuse of the interface such as passing in db pointers that are
** NULL or which have been previously closed. If this routine returns
** 1 it means that the db pointer is valid and 0 if it should not be
** dereferenced for any reason. The calling function should invoke
** SQLITE_MISUSE immediately.
**
** sqlite3SafetyCheckOk() requires that the db pointer be valid for
** use. sqlite3SafetyCheckSickOrOk() allows a db pointer that failed to
** open properly and is not fit for general use but which can be
** used as an argument to sqlite3_errmsg() or sqlite3_close().
label: code-design
** Initialize the iterator object indicated by the final parameter to
** iterate through coalesced phrase instances in column iCol.
b &= (0x7f<<14)|(0x7f);
If pSelect!=0, the id of the sub-select in EQP
Advance Pager.journalOff to the start of the next sector. If the
** journal file is too small for there to be a header stored at this
** point, return SQLITE_DONE.
Opcode: NextIfOpen P1 P2 P3 P4 P5
**
** This opcode works just like Next except that if cursor P1 is not
** open it behaves a no-op.
Reader whose cursor is to be moved
** Implementation of xSync() method.
** Obtain a buffer containing a changeset representing the concatenation
** of all changesets added to the group so far.
** This is the xEof method of the virtual table. SQLite calls this
** routine to find out if it has reached the end of a result set.
Get the size of the index entry. Only indices entries of less
** than 2GiB are support - anything large must be database corruption.
** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
** this code can safely assume that nCellKey is 32-bits
** This function is called to obtain a shared lock on the database file.
** It is illegal to call sqlite3PagerGet() until after this function
** has been successfully called. If a shared-lock is already held when
** this function is called, it is a no-op.
**
** The following operations are also performed by this function.
**
** 1) If the pager is currently in PAGER_OPEN state (no lock held
** on the database file), then an attempt is made to obtain a
** SHARED lock on the database file. Immediately after obtaining
** the SHARED lock, the file-system is checked for a hot-journal,
** which is played back if present. Following any hot-journal
** rollback, the contents of the cache are validated by checking
** the 'change-counter' field of the database file header and
** discarded if they are found to be invalid.
**
** 2) If the pager is running in exclusive-mode, and there are currently
** no outstanding references to any pages, and is in the error state,
** then an attempt is made to clear the error state by discarding
** the contents of the page cache and rolling back any open journal
** file.
**
** If everything is successful, SQLITE_OK is returned. If an IO error
** occurs while locking the database, checking for a hot-journal file or
** rolling back a journal file, the IO error code is returned.
List of triggers to return
Segment just written
Space characters
235
cmd ::= create_vtab
comment: Disallow the transfer optimization if the destination table constains
** any foreign key constraints. This is more restrictive than necessary.
** But the main beneficiary of the transfer optimization is the VACUUM
** command, and the VACUUM command disables foreign key constraints. So
** the extra complication to make this rule less restrictive is probably
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
label: code-design
Handle for accessing the file
Number of references to this structure
This is a threadsafe build, but strerror_r() is not available.
** Move the cursor up to the parent page.
**
** pCur->idx is set to the cell index that contains the pointer
** to the page we are coming from. If we are coming from the
** right-most child page then pCur->idx is set to one more than
** the largest cell index.
** CAPI3REF: Interrupt A Long-Running Query
** METHOD: sqlite3
**
** ^This function causes any pending database operation to abort and
** return at its earliest opportunity. This routine is typically
** called in response to a user action such as pressing "Cancel"
** or Ctrl-C where the user wants a long query operation to halt
** immediately.
**
** ^It is safe to call this routine from a thread different from the
** thread that is currently running the database operation. But it
** is not safe to call this routine with a [database connection] that
** is closed or might close before sqlite3_interrupt() returns.
**
** ^If an SQL operation is very nearly finished at the time when
** sqlite3_interrupt() is called, then it might not have an opportunity
** to be interrupted and might continue to completion.
**
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
** that is inside an explicit transaction, then the entire transaction
** will be rolled back automatically.
**
** ^The sqlite3_interrupt(D) call is in effect until all currently running
** SQL statements on [database connection] D complete. ^Any new SQL statements
** that are started after the sqlite3_interrupt() call and before the
** running statements reaches zero are interrupted as if they had been
** running prior to the sqlite3_interrupt() call. ^New SQL statements
** that are started after the running statement count reaches zero are
** not effected by the sqlite3_interrupt().
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
** SQL statements is a no-op and has no effect on SQL statements
** that are started after the sqlite3_interrupt() call returns.
Detach the ORDER BY clause from the compound SELECT
No sort order specified
Also fsync the directory containing the file if the DIRSYNC flag
** is set. This is a one-time occurrence. Many systems (examples: AIX)
** are unable to fsync a directory, so ignore errors on the fsync.
comment:
** The testcase() macro is used to aid in coverage testing. When
** doing coverage testing, the condition inside the argument to
** testcase() must be evaluated both true and false in order to
** get full branch coverage. The testcase() macro is inserted
** to help ensure adequate test coverage in places where simple
** condition/decision coverage is inadequate. For example, testcase()
** can be used to make sure boundary values are tested. For
** bitmask tests, testcase() can be used to make sure each bit
** is significant and used at least once. On switch statements
** where multiple cases go to the same block of code, testcase()
** can insure that all cases are evaluated.
**
label: test
All OP_Destroy operations occur on the same btree
OUT: Statement handle
The following block updates the change-counter. Exactly how it
** does this depends on whether or not the atomic-update optimization
** was enabled at compile time, and if this transaction meets the
** runtime criteria to use the operation:
**
** * The file-system supports the atomic-write property for
** blocks of size page-size, and
** * This commit is not part of a multi-file transaction, and
** * Exactly one page has been modified and store in the journal file.
**
** If the optimization was not enabled at compile time, then the
** pager_incr_changecounter() function is called to update the change
** counter in 'indirect-mode'. If the optimization is compiled in but
** is not applicable to this transaction, call sqlite3JournalCreate()
** to make sure the journal file has actually been created, then call
** pager_incr_changecounter() to update the change-counter in indirect
** mode.
**
** Otherwise, if the optimization is both enabled and applicable,
** then call pager_incr_changecounter() to update the change-counter
** in 'direct' mode. In this case the journal file will never be
** created for this transaction.
refarg ::= ON INSERT refact
** Before a virtual table xCreate() or xConnect() method is invoked, the
** sqlite3.pVtabCtx member variable is set to point to an instance of
** this struct allocated on the stack. It is used by the implementation of
** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
** are invoked only from within xCreate and xConnect methods.
Error code from system call errors
Value of the next token
TEMP => ID
Value returned by authorization callback
The BTREE_SEEK_EQ flag is only set on index cursors
Write the SQLite file handle here
Size, in bits, of the bitmap element.
Add the opcode to this VM
** Deserialize a single record from a buffer in memory. See "RECORD FORMAT"
** for details.
**
** When this function is called, *paChange points to the start of the record
** to deserialize. Assuming no error occurs, *paChange is set to point to
** one byte after the end of the same record before this function returns.
** If the argument abPK is NULL, then the record contains nCol values. Or,
** if abPK is other than NULL, then the record contains only the PK fields
** (in other words, it is a patchset DELETE record).
**
** If successful, each element of the apOut[] array (allocated by the caller)
** is set to point to an sqlite3_value object containing the value read
** from the corresponding position in the record. If that value is not
** included in the record (i.e. because the record is part of an UPDATE change
** and the field was not modified), the corresponding element of apOut[] is
** set to NULL.
**
** It is the responsibility of the caller to free all sqlite_value structures
** using sqlite3_free().
**
** If an error occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
** The apOut[] array may have been partially populated in this case.
Pointers to phrase objects
** Macros for troubleshooting. Normally turned off
** CAPI3REF: Obtain Values For URI Parameters
**
** These are utility routines, useful to VFS implementations, that check
** to see if a database file was a URI that contained a specific query
** parameter, and if so obtains the value of that query parameter.
**
** If F is the database filename pointer passed into the xOpen() method of
** a VFS implementation when the flags parameter to xOpen() has one or
** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
** P is the name of the query parameter, then
** sqlite3_uri_parameter(F,P) returns the value of the P
** parameter if it exists or a NULL pointer if P does not appear as a
** query parameter on F. If P is a query parameter of F
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
** a pointer to an empty string.
**
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
** parameter and returns true (1) or false (0) according to the value
** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
** value of query parameter P is one of "yes", "true", or "on" in any
** case or if the value begins with a non-zero number. The
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
** query parameter P is one of "no", "false", or "off" in any case or
** if the value begins with a numeric zero. If P is not a query
** parameter on F or if the value of P is does not match any of the
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
**
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
** 64-bit signed integer and returns that integer, or D if P does not
** exist. If the value of P is something other than an integer, then
** zero is returned.
**
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
** is not a database file pathname pointer that SQLite passed into the xOpen
** VFS method, then the behavior of this routine is undefined and probably
** undesirable.
Add the rowid of the row to be deleted to the RowSet
** Determine if we are dealing with WinRT, which provides only a subset of
** the full Win32 API.
Bitmask used by OP_Once
** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
** Compose a tcl-readable representation of expression pExpr. Return a
** pointer to a buffer containing that representation. It is the
** responsibility of the caller to at some point free the buffer using
** sqlite3_free().
If the database may grow as a result of this checkpoint, hint
** about the eventual size of the db file to the VFS layer.
Pointer to doclist buffer
Size of each free slot
IMP: R-11148-40995
Buffer containing previous term written
190
IMP: R-63666-48755
comment:
** CAPI3REF: Obtain Aggregate Function Context
** METHOD: sqlite3_context
**
** Implementations of aggregate SQL functions use this
** routine to allocate memory for storing their state.
**
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
** for a particular aggregate function, SQLite
** allocates N of memory, zeroes out that memory, and returns a pointer
** to the new memory. ^On second and subsequent calls to
** sqlite3_aggregate_context() for the same aggregate function instance,
** the same buffer is returned. Sqlite3_aggregate_context() is normally
** called once for each invocation of the xStep callback and then one
** last time when the xFinal callback is invoked. ^(When no rows match
** an aggregate query, the xStep() callback of the aggregate function
** implementation is never called and xFinal() is called exactly once.
** In those cases, sqlite3_aggregate_context() might be called for the
** first time from within xFinal().)^
**
** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
** when first called if N is less than or equal to zero or if a memory
** allocate error occurs.
**
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
** determined by the N parameter on first successful call. Changing the
** value of N in subsequent call to sqlite3_aggregate_context() within
** the same aggregate function instance will not resize the memory
** allocation.)^ Within the xFinal callback, it is customary to set
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
** pointless memory allocations occur.
**
** ^SQLite automatically frees the memory allocated by
** sqlite3_aggregate_context() when the aggregate query concludes.
**
** The first parameter must be a copy of the
** [sqlite3_context | SQL function context] that is the first parameter
** to the xStep or xFinal callback routine that implements the aggregate
** function.
**
** This routine must be called from the same thread in which
** the aggregate SQL function is running.
label: code-design
'?'. Numeric SQL variables
Used by vector == or <>
Background thread, if any
True if buffer zTerm must be copied
1050
** Return a 64-bit checksum for the FTS index entry specified by the
** arguments to this function.
Index of column zName applies to
No function of the specified name was found. Return 0.
Index of next byte to write to output
Reset a JsonEachCursor back to its original state. Free any memory
** held.
Connection shared memory
If any row exist in the result set, record that fact and abort.
Methods above are valid for version 2
OP_Column only used for typeof()
Schema containing this index
First cell to delete
Pager object
The table in the FROM clause of SELECT
176
SQLITE_ENABLE_PREUPDATE_HOOK
** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
** must be either NO_LOCK or SHARED_LOCK.
**
** If the locking level of the file descriptor is already at or below
** the requested locking level, this routine is a no-op.
Position
The virtual file system to use
** Add the changeset currently stored in buffer pData, size nData bytes,
** to changeset-group p.
** The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. If it returns NULL
** that means that a mutex could not be allocated.
First lock to acquire or release
Sector size
Num. columns already in colset object
** The proxyLockingContext has the path and file structures for the remote
** and local proxy files in it
Remove the sqlite3_vtab* from the aVTrans[] array, if applicable
1290
** Proxy locking is only available on MacOSX
Address of rows visited counter
Size of open blob, in bytes
A call to sqlite3BtreeMoveto() is needed
Beginning of keyword text in zKeyText[]
multiselect_op ::= UNION
Allocate new Fts5HashEntry and add it to the hash table.
Generate a subroutine that outputs a single row of the result
** set. This subroutine first looks at the iUseFlag. If iUseFlag
** is less than or equal to zero, the subroutine is a no-op. If
** the processing calls for the query to abort, this subroutine
** increments the iAbortFlag memory location before returning in
** order to signal the caller to abort.
Bias search to the high end
** Argument pIter is a changeset iterator that has been initialized, but
** not yet passed to sqlite3changeset_next(). This function applies the
** changeset to the main database attached to handle "db". The supplied
** conflict handler callback is invoked to resolve any conflicts encountered
** while applying the change.
Read a page from the write-ahead log, if it is present.
comment: This happens if a malloc() inside a call to sqlite3_column_text() or
** sqlite3_column_text16() failed.
label: code-design
comment: This is an error condition that can result, for example, when a SELECT
** on the right-hand side of an INSERT contains more result columns than
** there are columns in the table on the left. The error will be caught
** and reported later. But we need to make sure enough memory is allocated
** to avoid other spurious errors in the meantime.
label: code-design
LIKE range processing address
Saved value of the db->flags
Index in the parent table
The left operand, and output
xShmBarrier
Condition (a) is true. Promote the newest segment on level
** iLvl to level iTst.
same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1]
Update the schema version field in the destination database. This
** is to make sure that the schema-version really does change in
** the case where the source and destination databases have the
** same schema version.
UNIXFILE_* flags
If the YYNOERRORRECOVERY macro is defined, then do not attempt to
** do any kind of error recovery. Instead, simply invoke the syntax
** error routine and continue going as if nothing had happened.
**
** Applications can set this macro (for example inside %include) if
** they intend to abandon the parse upon the first syntax error seen.
Current term
** Free the contents of the With object passed as the second argument.
Address of the select-A coroutine
Column of last value written
COMPRESS
expr ::= VARIABLE
Integer primary key is autoincrement
A column-list is terminated by either a 0x01 or 0x00 byte that is
** not part of a multi-byte varint.
Number of characters in zName
** Unlock the database file to level eLock, which must be either NO_LOCK
** or SHARED_LOCK. Regardless of whether or not the call to xUnlock()
** succeeds, set the Pager.eLock variable to match the (attempted) new lock.
**
** Except, if Pager.eLock is set to UNKNOWN_LOCK when this function is
** called, do not modify it. See the comment above the #define of
** UNKNOWN_LOCK for an explanation of this.
** If compiling for a processor that lacks floating point support,
** substitute integer for floating-point
OPTIMIZATION-IF-FALSE
Each page cache is an instance of the following object. Every
** open database file (including each in-memory database and each
** temporary or transient database) has a single page cache which
** is an instance of this object.
**
** Pointers to structures of this type are cast and returned as
** opaque sqlite3_pcache* handles.
SQLite scalar function context
Obtain authorization to do a recursive query
Register holding root page number for new objects
Make pExpr point to the appropriate pAggInfo->aFunc[] entry
Allocation type code
** Free memory that might be associated with a particular database
** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
** Free the list of table objects passed as the first argument. The contents
** of the changed-rows hash tables are also deleted.
Context for active pre-update callback
** Return the size of a memory allocation previously obtained from
** sqlite3Malloc() or sqlite3_malloc().
Address register for select-A coroutine
* The size of the buffer used by sqlite3_win32_write_debug().
7 END:
comment:
** Playback the journal and thus restore the database file to
** the state it was in before we started making changes.
**
** The journal file format is as follows:
**
** (1) 8 byte prefix. A copy of aJournalMagic[].
** (2) 4 byte big-endian integer which is the number of valid page records
** in the journal. If this value is 0xffffffff, then compute the
** number of page records from the journal size.
** (3) 4 byte big-endian integer which is the initial value for the
** sanity checksum.
** (4) 4 byte integer which is the number of pages to truncate the
** database to during a rollback.
** (5) 4 byte big-endian integer which is the sector size. The header
** is this many bytes in size.
** (6) 4 byte big-endian integer which is the page size.
** (7) zero padding out to the next sector size.
** (8) Zero or more pages instances, each as follows:
** + 4 byte page number.
** + pPager->pageSize bytes of data.
** + 4 byte checksum
**
** When we speak of the journal header, we mean the first 7 items above.
** Each entry in the journal is an instance of the 8th item.
**
** Call the value from the second bullet "nRec". nRec is the number of
** valid page entries in the journal. In most cases, you can compute the
** value of nRec from the size of the journal file. But if a power
** failure occurred while the journal was being written, it could be the
** case that the size of the journal file had already been increased but
** the extra entries had not yet made it safely to disk. In such a case,
** the value of nRec computed from the file size would be too large. For
** that reason, we always use the nRec value in the header.
**
** If the nRec value is 0xffffffff it means that nRec should be computed
** from the file size. This value is used when the user selects the
** no-sync option for the journal. A power failure could lead to corruption
** in this case. But for things like temporary table (which will be
** deleted when the power is restored) we don't care.
**
** If the file opened as the journal file is not a well-formed
** journal file then all pages up to the first corrupted page are rolled
** back (or no pages if the journal header is corrupted). The journal file
** is then deleted and SQLITE_OK returned, just as if no corruption had
** been encountered.
**
** If an I/O or malloc() error occurs, the journal-file is not deleted
** and an error code is returned.
**
** The isHot parameter indicates that we are trying to rollback a journal
** that might be a hot journal. Or, it could be that the journal is
** preserved because of JOURNALMODE_PERSIST or JOURNALMODE_TRUNCATE.
** If the journal really is hot, reset the pager cache prior rolling
** back any content. If the journal is merely persistent, no reset is
** needed.
label: code-design
** Apply colset pColset to expression node pExpr and all of its descendents.
Functions used to query pager state and configuration.
** Macro IfNotOmitAV(x) returns (x) if SQLITE_OMIT_AUTOVACUUM is not
** defined, or 0 if it is. For example:
**
** bIncrVacuum = IfNotOmitAV(pBtShared->incrVacuum);
Insert data into the table of this cursor
OUT: Size of array *pazCol
137
** Add 1 to the reference count for page iPage. If this is the second
** reference to the page, add an error message to pCheck->zErrMsg.
** Return 1 if there are 2 or more references to the page and 0 if
** if this is the first reference to the page.
**
** Also check that the page number is in bounds.
47
Handle open on database file
same as TK_RSHIFT, in1, in2, out3
Check invariants on a PgHdr object
Space to unpack a record
In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
** implementation of malloc_good_size(), which must be called in debug
** mode and specifically when the DMD "Dark Matter Detector" is enabled
** or else a crash results. Hence, do not attempt to optimize out the
** following xRoundup() call.
Any deferred constraint violations have now been resolved.
WAL frames perhaps written, or maybe not
xBegin
Existing colset object
** This function is invoked once for each page that has already been
** written into the log file when a WAL transaction is rolled back.
** Parameter iPg is the page number of said page. The pCtx argument
** is actually a pointer to the Pager structure.
**
** If page iPg is present in the cache, and has no outstanding references,
** it is discarded. Otherwise, if there are one or more outstanding
** references, the page content is reloaded from the database. If the
** attempt to reload content from the database is required and fails,
** return an SQLite error code. Otherwise, SQLITE_OK.
comment: If the aStatic[] array is not large enough, allocate a large array
** using sqlite3_malloc(). This approach could be improved upon.
label: code-design
Bytes of leaf data in segment
Checkpoint on this pager
A Sub-term within the pOrWc
** Translate the P4.pExpr value for an OP_CursorHint opcode into text
** that can be displayed in the P4 column of EXPLAIN output.
Sync all the db files involved in the transaction. The same call
** sets the master journal pointer in each individual journal. If
** an error occurs here, do not delete the master journal file.
**
** If the error occurs during the first call to
** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
** master journal file will be orphaned. But we cannot delete it,
** in case the master journal file name was written into the journal
** file before the failure occurred.
Number of phrase instances
comment:
** Append the output of a printf() style formatting to an existing string.
label: code-design
Must have at least one page for the WAL commit flag.
** Ticket [2d1a5c67dfc2363e44f29d9bbd57f] 2011-05-18
Bytes required to hold table name
The ORDER BY clause. May be null
Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
** is a pointer to the sub-vdbe containing the trigger program.
Keep track of the maximum allocation request. Even unfulfilled
** requests are counted
117
xLock method
** Allocate and zero memory. If the allocation fails, make
** the mallocFailed flag in the connection pointer.
FTS5 global object for this database
** Return the PRIMARY KEY index of a table
comment: Check to see if another process is holding the dead-man switch.
** If not, truncate the file to zero length.
label: code-design
This routine is a no-op if the shared-cache is not enabled
Allocate a buffer large enough for an Fts3Cursor structure. If the
** allocation succeeds, zero it and return SQLITE_OK. Otherwise,
** if the allocation fails, return SQLITE_NOMEM.
szScratch
The pragma
If the journal needs to be sync()ed before page pPg->pgno can
** be written to, store pPg->pgno in local variable needSyncPgno.
**
** If the isCommit flag is set, there is no need to remember that
** the journal needs to be sync()ed before database page pPg->pgno
** can be written to. The caller has already promised not to write to it.
** Properties of opcodes. The OPFLG_INITIALIZER macro is
** created by mkopcodeh.awk during compilation. Data is obtained
** from the comments following the "case OP_xxxx:" statements in
** the vdbe.c file.
comment: There are no SHIFTREDUCE actions on nonterminals because the table
** generator has simplified them to pure REDUCE actions.
label: code-design
Memory cell hold array of subprogs
"SELECT * FROM %_segdir WHERE level BETWEEN ? AND ? ORDER BY ..."
Cursor number of the sorting index
End loop over indexes
Usable size of mapping at pMapRegion
Root of current AND/NEAR cluster
Copy the overflow cells from pRoot to pChild
** Attach subtrees pLeft and pRight to the Expr node pRoot.
**
** If pRoot==NULL that means that a memory allocation error has occurred.
** In that case, delete the subtrees pLeft and pRight.
3 integers per phrase instance
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
Size of the open journal file in bytes
Name of the database containing pTable
Spacer
Table cursor number
comment: At one point the code here called assertTruncateConstraint() to
** ensure that all pages being truncated away by this operation are,
** if one or more savepoints are open, present in the savepoint
** journal so that they can be restored if the savepoint is rolled
** back. This is no longer necessary as this function is now only
** called right before committing a transaction. So although the
** Pager object may still have open savepoints (Pager.nSavepoint!=0),
** they cannot be rolled back. So the assertTruncateConstraint() call
** is no longer correct.
label: code-design
Close with last statement close
No more retries.
** Enter a mutex on the given BTree object.
**
** If the object is not sharable, then no mutex is ever required
** and this routine is a no-op. The underlying mutex is non-recursive.
** But we keep a reference count in Btree.wantToLock so the behavior
** of this interface is recursive.
**
** To avoid deadlocks, multiple Btrees are locked in the same order
** by all database connections. The p->pNext is a list of other
** Btrees belonging to the same database connection as the p Btree
** which need to be locked after p. If we cannot get a lock on
** p, then first unlock all of the others on p->pNext, then wait
** for the lock to become available on p, then relock all of the
** subsequent Btrees that desire a lock.
The 0x7ffff00 limit term is explained in comments on sqlite3Malloc()
Frame corresponding to aPgno[0]
inProgress
TABLE.COLUMN if no AS clause and is a direct table ref
!defined(SQLITE_OMIT_DECLTYPE)
Extract the values to be compared.
Pointer to tokenizer hash table
If this process is running as root and if creating a new rollback
** journal or WAL file, set the ownership of the journal or WAL to be
** the same as the original database.
** 2004 May 22
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains code that is specific to Windows.
Bytes at zTerm
Column number of X in "X <op> <expr>"
** Return a pointer to the column affinity string associated with index
** pIdx. A column affinity string has one character for each column in
** the table, according to the affinity of the column:
**
** Character Column affinity
** ------------------------------
** 'A' BLOB
** 'B' TEXT
** 'C' NUMERIC
** 'D' INTEGER
** 'F' REAL
**
** An extra 'D' is appended to the end of the string to cover the
** rowid that appears as the last column in every index.
**
** Memory for the buffer containing the column index affinity string
** is managed along with the rest of the Index structure. It will be
** released when sqlite3DeleteIndex() is called.
Number of bytes required on leaf page
Cursor number from which to take column data
Write the data read from the journal back into the database file.
** This is usually safe even for an encrypted database - as the data
** was encrypted before it was written to the journal file. The exception
** is if the data was just read from an in-memory sub-journal. In that
** case it must be encrypted here before it is copied into the database
** file.
Journaled and ready to modify
** Free slots in the allocator used to divide up the global page cache
** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
************* Continuing where we left off in vdbe.h **********************
Database the cursor belongs to, or -1
** Print a WhereLoop object for debugging purposes
Output variables. zTbl==0 implies EOF.
Registers holding results of a co-routine
The two values have the same sign. Compare using memcmp().
Force exponential buffer size growth as long as it does not overflow,
** to avoid having to call this routine too often
** Gobble up the first bareword or quoted word from the input buffer zIn.
** Return a pointer to the character immediately following the last in
** the gobbled word if successful, or a NULL pointer otherwise (failed
** to find close-quote character).
**
** Before returning, set pzOut to point to a new buffer containing a
** nul-terminated, dequoted copy of the gobbled word. If the word was
** quoted, *pbQuoted is also set to 1 before returning.
**
** If *pRc is other than SQLITE_OK when this function is called, it is
** a no-op (NULL is returned). Otherwise, if an OOM occurs within this
** function, *pRc is set to SQLITE_NOMEM before returning. *pRc is *not*
** set if a parse error (failed to find close quote) occurs.
WHEN
pDestIdx has no corresponding index in pSrc
Implementation of the following:
**
** Rewind csr
** if eof(csr) goto end_of_scan;
** regChng = 0
** goto next_push_0;
**
FTS5 configuration
** This function outputs the specified (ANSI) string to the Win32 debugger
** (if available).
sqlite3_config() shall return SQLITE_MISUSE if it is invoked while
** the SQLite library is in use.
142
400
Round towards zero
0x09
Populate the argument registers.
DOUB
Collating sequence to on a column
And to delete index entries
Column of index to match
Next in the link-list
If p1 is at EOF
File-name for the master journal
** CAPI3REF: Declared Datatype Of A Query Result
** METHOD: sqlite3_stmt
**
** ^(The first parameter is a [prepared statement].
** If this statement is a [SELECT] statement and the Nth column of the
** returned result set of that [SELECT] is a table column (not an
** expression or subquery) then the declared type of the table
** column is returned.)^ ^If the Nth column of the result set is an
** expression or subquery, then a NULL pointer is returned.
** ^The returned string is always UTF-8 encoded.
**
** ^(For example, given the database schema:
**
** CREATE TABLE t1(c1 VARIANT);
**
** and the following statement to be compiled:
**
** SELECT c1 + 1, c1 FROM t1;
**
** this routine would return the string "VARIANT" for the second result
** column (i==1), and a NULL pointer for the first result column (i==0).)^
**
** ^SQLite uses dynamic run-time typing. ^So just because a column
** is declared to contain a particular type does not mean that the
** data stored in that column is of the declared type. SQLite is
** strongly typed, but the typing is dynamic not static. ^Type
** is associated with individual values, not with the containers
** used to hold those values.
sync directory after journal delete
comment: True in "cleanup" state
label: code-design
Number of '?' variables seen in the SQL so far
** Remove all data from the FTS3 table. Clear the hash table containing
** pending terms.
turn off proxy locking - already off - NOOP
IN/OUT: Right/output doclist
True if errors are benign
************* Begin file threads.c ****************************************
** This function is used to resize the hash table used by the cache passed
** as the first argument.
**
** The PCache mutex must be held when this function is called.
comment:
** Move an existing blob handle to point to a different row of the same
** database table.
**
** If an error occurs, or if the specified row does not exist or does not
** contain a blob or text value, then an error code is returned and the
** database handle error code and message set. If this happens, then all
** subsequent calls to sqlite3_blob_xxx() functions (except blob_close())
** immediately return SQLITE_ABORT.
label: code-design
Opcode: SetCookie P1 P2 P3 * *
**
** Write the integer value P3 into cookie number P2 of database P1.
** P2==1 is the schema version. P2==2 is the database format.
** P2==3 is the recommended pager cache
** size, and so forth. P1==0 is the main database file and P1==1 is the
** database file used to store temporary tables.
**
** A transaction must be started before executing this opcode.
OUT: Tokenizer (if applicable)
Tokens to the left of first highlight
Readr data from the file. Return early if an error occurs.
Extra space on the end of pIdx
Name of WAL file
Bytes of space to allocate here
When sqlite_stat3 histogram data is available an operator of the
** form "x IS NOT NULL" can sometimes be evaluated more efficiently
** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
** virtual term of that form.
**
** Note that the virtual term must be tagged with TERM_VNULL.
7x
Skip docid varint
** CAPI3REF: Start a read transaction on an historical snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
** read transaction for schema S of
** [database connection] D such that the read transaction
** refers to historical [snapshot] P, rather than the most
** recent change to the database.
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
** or an appropriate [error code] if it fails.
**
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
** the first operation following the [BEGIN] that takes the schema S
** out of [autocommit mode].
** ^In other words, schema S must not currently be in
** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
** database connection D must be out of [autocommit mode].
** ^A [snapshot] will fail to open if it has been overwritten by a
** [checkpoint].
** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
** database connection D does not know that the database file for
** schema S is in [WAL mode]. A database connection might not know
** that the database file is in [WAL mode] if there has been no prior
** I/O on that database connection, or if the database entered [WAL mode]
** after the most recent I/O on the database connection.)^
** (Hint: Run "[PRAGMA application_id]" against a newly opened
** database connection in order to make it ready to use snapshots.)
**
** The [sqlite3_snapshot_open()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
SQLITE_STMTSTATUS_SORT
Write the referenced table cursor & column here
Combined MEM_* flags from both inputs
The overall R-Tree
same as TK_NE, jump, in1, in3
expr ::= ID|INDEXED LP STAR RP
Either "ORDER" or "GROUP", as appropriate
** Free a page object allocated by pcache1AllocPage().
Desired snippet length
If no pending lock has been acquired, then acquire it
Write the comparison result here
zName:
Read the PK of the current row into an array of registers. In
** ONEPASS_OFF mode, serialize the array into a record and store it in
** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
** is not required) and leave the PK fields in the array of registers.
Highlight-mask for snippet
The remaining transformations only apply to b-tree tables, not to
** virtual tables
3 registers to hold a result row
Start a search on a new JSON string
** This is a wrapper around "sqlite3_mprintf(zFmt, ...)". If an OOM occurs,
** an error code is stored in the RBU handle passed as the first argument.
**
** If an error has already occurred (p->rc is already set to something other
** than SQLITE_OK), then this function returns NULL without modifying the
** stored error code. In this case it still calls sqlite3_free() on any
** printf() parameters associated with %z conversions.
Store SELECT results in intermediate table
1370
comment: Do not search for an unused file descriptor on vxworks. Not because
** vxworks would not benefit from the change (it might, we're not sure),
** but because no way to test it is currently available. It is better
** not to risk breaking vxworks support for the sake of such an obscure
** feature.
label: code-design
OUT: Pointer to output buffer
The function name
** Set the Expr.nHeight variable in the structure passed as an
** argument. An expression with no children, Expr.pList or
** Expr.pSelect member has a height of 1. Any other expression
** has a height equal to the maximum height of any other
** referenced Expr plus one.
**
** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
** if appropriate.
Get low-level information about the file that we can used to
** create a unique name for the file.
If this statement has violated immediate foreign key constraints, do
** not return the number of rows modified. And do not RELEASE the statement
** transaction. It needs to be rolled back.
Array of parsed cells
restriction 5
** Turn a relative pathname into a full pathname. Write the full
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
** bytes in size.
Parent VFS
if !defined(SQLITE_ENABLE_COLUMN_METADATA)
** Detect compound SELECT statements that use an ORDER BY clause with
** an alternative collating sequence.
**
** SELECT ... FROM t1 EXCEPT SELECT ... FROM t2 ORDER BY .. COLLATE ...
**
** These are rewritten as a subquery:
**
** SELECT * FROM (SELECT ... FROM t1 EXCEPT SELECT ... FROM t2)
** ORDER BY ... COLLATE ...
**
** This transformation is necessary because the multiSelectOrderBy() routine
** above that generates the code for a compound SELECT with an ORDER BY clause
** uses a merge algorithm that requires the same collating sequence on the
** result columns as on the ORDER BY clause. See ticket
** http://www.sqlite.org/src/info/6709574d2a
**
** This transformation is only needed for EXCEPT, INTERSECT, and UNION.
** The UNION ALL operator works fine with multiSelectOrderBy() even when
** there are COLLATE terms in the ORDER BY.
If there are any triggers to fire, allocate a range of registers to
** use for the old.* references in the triggers.
Pointer to token
Table list this loop refers to
#include "sqlite3.h" ** Required for error code definitions **
119
Like mgt0 above except we are looking for a value of m>1 instead
** or m>0
** CAPI3REF: Concatenate Two Changeset Objects
**
** This function is used to concatenate two changesets, A and B, into a
** single changeset. The result is a changeset equivalent to applying
** changeset A followed by changeset B.
**
** This function combines the two input changesets using an
** sqlite3_changegroup object. Calling it produces similar results as the
** following code fragment:
**
** sqlite3_changegroup *pGrp;
** rc = sqlite3_changegroup_new(&pGrp);
** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
** if( rc==SQLITE_OK ){
** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
** }else{
** *ppOut = 0;
** *pnOut = 0;
** }
**
** Refer to the sqlite3_changegroup documentation below for details.
Statement to return all language-ids
** Load content from the sqlite_stat4 and sqlite_stat3 tables into
** the Index.aSample[] arrays of all indices.
Delete any TriggerPrg structures allocated while parsing this statement.
Table with INTEGER PRIMARY KEY and nothing else
** Invoke either the xSavepoint, xRollbackTo or xRelease method of all
** virtual tables that currently have an open transaction. Pass iSavepoint
** as the second argument to the virtual table method invoked.
**
** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is
** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is
** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
** an open transaction is invoked.
**
** If any virtual table method returns an error code other than SQLITE_OK,
** processing is abandoned and the error returned to the caller of this
** function immediately. If all calls to virtual table methods are successful,
** SQLITE_OK is returned.
Pointer to interior tree structure
f8..ff ........
The LIMIT clause. May be null
Opcode to access the value of the IN constraint
New rowid value (for a rowid UPDATE)
SQL_SELECT_SEGDIR
** Read a single entry from the %_segdir table. The entry from absolute
** level :1 with index value :2.
True to auto-attach tables
xRename
** Terminate the current execution of an SQL statement and reset it
** back to its starting state so that it can be reused. A success code from
** the prior execution is returned.
**
** This routine sets the error code and string returned by
** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
Do FK processing. This call checks that any FK constraints that
** refer to this table (i.e. constraints attached to other tables)
** are not violated by deleting this row.
szPage
Adjust pTemplate cost downward so that it is cheaper than its
** subset p.
If this is a converted compound query, move the ORDER BY clause from
** the sub-query back to the parent query. At this point each term
** within the ORDER BY clause has been transformed to an integer value.
** These integers will be replaced by copies of the corresponding result
** set expressions by the call to resolveOrderGroupBy() below.
** 2005-07-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** The ANALYZE command gather statistics about the content of tables
** and indices. These statistics are made available to the query planner
** to help it make better decisions about how to perform queries.
**
** The following system tables are or have been supported:
**
** CREATE TABLE sqlite_stat1(tbl, idx, stat);
** CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
** CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
** CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
**
** Additional tables might be added in future releases of SQLite.
** The sqlite_stat2 table is not created or used unless the SQLite version
** is between 3.6.18 and 3.7.8, inclusive, and unless SQLite is compiled
** with SQLITE_ENABLE_STAT2. The sqlite_stat2 table is deprecated.
** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
** created and used by SQLite versions 3.7.9 and later and with
** SQLITE_ENABLE_STAT3 defined. The functionality of sqlite_stat3
** is a superset of sqlite_stat2. The sqlite_stat4 is an enhanced
** version of sqlite_stat3 and is only available when compiled with
** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is
** not possible to enable both STAT3 and STAT4 at the same time. If they
** are both enabled, then STAT4 takes precedence.
**
** For most applications, sqlite_stat1 provides all the statistics required
** for the query planner to make good choices.
**
** Format of sqlite_stat1:
**
** There is normally one row per index, with the index identified by the
** name in the idx column. The tbl column is the name of the table to
** which the index belongs. In each such row, the stat column will be
** a string consisting of a list of integers. The first integer in this
** list is the number of rows in the index. (This is the same as the
** number of rows in the table, except for partial indices.) The second
** integer is the average number of rows in the index that have the same
** value in the first column of the index. The third integer is the average
** number of rows in the index that have the same value for the first two
** columns. The N-th integer (for N>1) is the average number of rows in
** the index which have the same value for the first N-1 columns. For
** a K-column index, there will be K+1 integers in the stat column. If
** the index is unique, then the last integer will be 1.
**
** The list of integers in the stat column can optionally be followed
** by the keyword "unordered". The "unordered" keyword, if it is present,
** must be separated from the last integer by a single space. If the
** "unordered" keyword is present, then the query planner assumes that
** the index is unordered and will not use the index for a range query.
**
** If the sqlite_stat1.idx column is NULL, then the sqlite_stat1.stat
** column contains a single integer which is the (estimated) number of
** rows in the table identified by sqlite_stat1.tbl.
**
** Format of sqlite_stat2:
**
** The sqlite_stat2 is only created and is only used if SQLite is compiled
** with SQLITE_ENABLE_STAT2 and if the SQLite version number is between
** 3.6.18 and 3.7.8. The "stat2" table contains additional information
** about the distribution of keys within an index. The index is identified by
** the "idx" column and the "tbl" column is the name of the table to which
** the index belongs. There are usually 10 rows in the sqlite_stat2
** table for each index.
**
** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
** inclusive are samples of the left-most key value in the index taken at
** evenly spaced points along the index. Let the number of samples be S
** (10 in the standard build) and let C be the number of rows in the index.
** Then the sampled rows are given by:
**
** rownumber = (i*C*2 + C)/(S*2)
**
** For i between 0 and S-1. Conceptually, the index space is divided into
** S uniform buckets and the samples are the middle row from each bucket.
**
** The format for sqlite_stat2 is recorded here for legacy reference. This
** version of SQLite does not support sqlite_stat2. It neither reads nor
** writes the sqlite_stat2 table. This version of SQLite only supports
** sqlite_stat3.
**
** Format for sqlite_stat3:
**
** The sqlite_stat3 format is a subset of sqlite_stat4. Hence, the
** sqlite_stat4 format will be described first. Further information
** about sqlite_stat3 follows the sqlite_stat4 description.
**
** Format for sqlite_stat4:
**
** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
** to aid the query planner in choosing good indices based on the values
** that indexed columns are compared against in the WHERE clauses of
** queries.
**
** The sqlite_stat4 table contains multiple entries for each index.
** The idx column names the index and the tbl column is the table of the
** index. If the idx and tbl columns are the same, then the sample is
** of the INTEGER PRIMARY KEY. The sample column is a blob which is the
** binary encoding of a key from the index. The nEq column is a
** list of integers. The first integer is the approximate number
** of entries in the index whose left-most column exactly matches
** the left-most column of the sample. The second integer in nEq
** is the approximate number of entries in the index where the
** first two columns match the first two columns of the sample.
** And so forth. nLt is another list of integers that show the approximate
** number of entries that are strictly less than the sample. The first
** integer in nLt contains the number of entries in the index where the
** left-most column is less than the left-most column of the sample.
** The K-th integer in the nLt entry is the number of index entries
** where the first K columns are less than the first K columns of the
** sample. The nDLt column is like nLt except that it contains the
** number of distinct entries in the index that are less than the
** sample.
**
** There can be an arbitrary number of sqlite_stat4 entries per index.
** The ANALYZE command will typically generate sqlite_stat4 tables
** that contain between 10 and 40 samples which are distributed across
** the key space, though not uniformly, and which include samples with
** large nEq values.
**
** Format for sqlite_stat3 redux:
**
** The sqlite_stat3 table is like sqlite_stat4 except that it only
** looks at the left-most column of the index. The sqlite_stat3.sample
** column contains the actual value of the left-most column instead
** of a blob encoding of the complete index key as is found in
** sqlite_stat4.sample. The nEq, nLt, and nDLt entries of sqlite_stat3
** all contain just a single integer which is the same as the first
** integer in the equivalent columns in sqlite_stat4.
Minimum PMA size, in bytes
** Append a string to the string-buffer passed as the first argument.
**
** If nAppend is negative, then the length of the string zAppend is
** determined using strlen().
Tracing routines for the RtreeSearchPoint queue
Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**
** "pNew" is a pointer to the hash table that is to be initialized.
** keyClass is one of the constants
** FTS3_HASH_BINARY or FTS3_HASH_STRING. The value of keyClass
** determines what kind of key the hash table will use. "copyKey" is
** true if the hash table should make its own private copy of keys and
** false if it should just use the supplied pointer.
Version 3.7.16 and later
** Delete an entire expression list.
expr ::= NOT expr
** The input to this routine is an WhereTerm structure with only the
** "pExpr" field filled in. The job of this routine is to analyze the
** subexpression and populate all the other fields of the WhereTerm
** structure.
**
** If the expression is of the form "<expr> <op> X" it gets commuted
** to the standard form of "X <op> <expr>".
**
** If the expression is of the form "X <op> Y" where both X and Y are
** columns, then the original expression is unchanged and a new virtual
** term of the form "Y <op> X" is added to the WHERE clause and
** analyzed separately. The original term is marked with TERM_COPIED
** and the new term is marked with TERM_DYNAMIC (because it's pExpr
** needs to be freed with the WhereClause) and TERM_VIRTUAL (because it
** is a commuted copy of a prior term.) The original term has nChild=1
** and the copy has idxParent set to the index of the original term.
The transaction counter has changed
Array of column names
** A structure defining how to do GLOB-style comparisons.
** Move the cursor down to the right-most leaf entry beneath the
** page to which it is currently pointing. Notice the difference
** between moveToLeftmost() and moveToRightmost(). moveToLeftmost()
** finds the left-most entry beneath the *entry* whereas moveToRightmost()
** finds the right-most entry beneath the *page*.
**
** The right-most entry is the one with the largest key - the last
** key in ascending order.
New temp space
Write the MergeEngine here
** Transfer content from the second pLoop into the first.
comment: One of the FTSQUERY_XXX values defined below
label: code-design
The IN, SELECT, or EXISTS operator
Number of bytes in buffer zTerm
Merge-writer object
Loop termination flag
Input: Mask of columns used by statement
Size of input list
** Attempt to apply the change that the iterator passed as the first argument
** currently points to to the database. If a conflict is encountered, invoke
** the conflict handler callback.
**
** The difference between this function and sessionApplyOne() is that this
** function handles the case where the conflict-handler is invoked and
** returns SQLITE_CHANGESET_REPLACE - indicating that the change should be
** retried in some manner.
True if this constraint is on docid
Value configured by 'automerge'
Prepared statement for which info desired
True to disable triggers
Database page size
True to dequote pCollName
** CAPI3REF: Generate A Patchset From A Session Object
**
** The differences between a patchset and a changeset are that:
**
** <ul>
** <li> DELETE records consist of the primary key fields only. The
** original values of other fields are omitted.
** <li> The original values of any modified fields are omitted from
** UPDATE records.
** </ul>
**
** A patchset blob may be used with up to date versions of all
** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
** attempting to use a patchset blob with old versions of the
** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
**
** Because the non-primary key "old.*" fields are omitted, no
** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
** is passed to the sqlite3changeset_apply() API. Other conflict types work
** in the same way as for changesets.
**
** Changes within a patchset are ordered in the same way as for changesets
** generated by the sqlite3session_changeset() function (i.e. all changes for
** a single table are grouped together, tables appear in the order in which
** they were attached to the session object).
Stat4Accum.anEq
Boolean array - true for PK columns
** SQLite will invoke this method one or more times while planning a query
** that uses the stmt virtual table. This routine needs to create
** a query plan for each invocation and compute an estimated cost for that
** plan.
moved CSE1 up
Used by: foreign_key_check
for AFP simulated shared lock
If a NULL pointer was passed as the collate function, fall through
** to the blob case and use memcmp().
** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof
** to true if EOF is reached.
Determine the type of a table.
**
** peType is of type (int*), a pointer to an output parameter of type
** (int). This call sets the output parameter as follows, depending
** on the type of the table specified by parameters dbName and zTbl.
**
** RBU_PK_NOTABLE: No such table.
** RBU_PK_NONE: Table has an implicit rowid.
** RBU_PK_IPK: Table has an explicit IPK column.
** RBU_PK_EXTERNAL: Table has an external PK index.
** RBU_PK_WITHOUT_ROWID: Table is WITHOUT ROWID.
** RBU_PK_VTAB: Table is a virtual table.
**
** Argument *piPk is also of type (int*), and also points to an output
** parameter. Unless the table has an external primary key index
** (i.e. unless *peType is set to 3), then *piPk is set to zero. Or,
** if the table does have an external primary key index, then *piPk
** is set to the root page number of the primary key index before
** returning.
**
** ALGORITHM:
**
** if( no entry exists in sqlite_master ){
** return RBU_PK_NOTABLE
** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
** return RBU_PK_VTAB
** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
** if( the index that is the pk exists in sqlite_master ){
** *piPK = rootpage of that index.
** return RBU_PK_EXTERNAL
** }else{
** return RBU_PK_WITHOUT_ROWID
** }
** }else if( "PRAGMA table_info()" lists one or more "pk" columns ){
** return RBU_PK_IPK
** }else{
** return RBU_PK_NONE
** }
Length of TOP vector
** Open a file descriptor to the directory containing file zFilename.
** If successful, *pFd is set to the opened file descriptor and
** SQLITE_OK is returned. If an error occurs, either SQLITE_NOMEM
** or SQLITE_CANTOPEN is returned and *pFd is set to an undefined
** value.
**
** The directory file descriptor is used for only one thing - to
** fsync() a directory to make sure file creation and deletion events
** are flushed to disk. Such fsyncs are not needed on newer
** journaling filesystems, but are required on older filesystems.
**
** This routine can be overridden using the xSetSysCall interface.
** The ability to override this routine was added in support of the
** chromium sandbox. Opening a directory is a security risk (we are
** told) so making it overrideable allows the chromium sandbox to
** replace this routine with a harmless no-op. To make this routine
** a no-op, replace it with a stub that returns SQLITE_OK but leaves
** *pFd set to a negative number.
**
** If SQLITE_OK is returned, the caller is responsible for closing
** the file descriptor *pFd using close().
Argument to the progress callback
EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
** increasing offset.
expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr
** Register a callback to be invoked each time a row is updated,
** inserted or deleted using this database connection.
Thread that will run pMerger
Change to compare to
comment: 0x2000 not currently used
label: code-design
Local cache of vfs pointer
The table whose column is desired
** CAPI3REF: Virtual Table Constraint Operator Codes
**
** These macros defined the allowed values for the
** [sqlite3_index_info].aConstraint[].op field. Each value represents
** an operator that is part of a constraint term in the wHERE clause of
** a query that uses a [virtual table].
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
** "win32" VFSes. Return SQLITE_OK opon successfully updating the
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
** system call named zName.
No additional checks needed for this table
Starting offset in main journal
Locate the pragma in the lookup table
Any terms specified as part of the ON(...) clause for any LEFT
** JOIN for which the current table is not the rhs are omitted
** from the cursor-hint.
**
** If this table is the rhs of a LEFT JOIN, "IS" or "IS NULL" terms
** that were specified as part of the WHERE clause must be excluded.
** This is to address the following:
**
** SELECT ... t1 LEFT JOIN t2 ON (t1.a=t2.b) WHERE t2.c IS NULL;
**
** Say there is a single row in t2 that matches (t1.a=t2.b), but its
** t2.c values is not NULL. If the (t2.c IS NULL) constraint is
** pushed down to the cursor, this row is filtered out, causing
** SQLite to synthesize a row of NULL values. Which does match the
** WHERE clause, and so the query returns a row. Which is incorrect.
**
** For the same reason, WHERE terms such as:
**
** WHERE 1 = (t2.c IS NULL)
**
** are also excluded. See codeCursorHintIsOrFunction() for details.
Space used in zNewRecord[] content
** 2003 April 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
** Remove node pNode from the node hash table.
Value passed to FCNTL_SIZE_HINT call
** One or more segments have just been removed from absolute level iAbsLevel.
** Update the 'idx' values of the remaining segments in the level so that
** the idx values are a contiguous sequence starting from 0.
** Carve a piece off of the end of the mem3.iMaster free chunk.
** Return a pointer to the new allocation. Or, if the master chunk
** is not large enough, return 0.
Verify condition (1): If cells are moving left, update iPg
** only after iPg-1 has already been updated.
** Initialize the object pIter to point to term pTerm/nTerm within segment
** pSeg. If there is no such term in the index, the iterator is set to EOF.
**
** If an error occurs, Fts5Index.rc is set to an appropriate error code. If
** an error has already occurred when this function is called, it is a no-op.
0: off 1: simple 2: cache dumps
Page into which we are copying
** Query status information for a single database connection
List of all WhereLoop objects
** An instance of the following structure serves as the key used
** to locate a particular unixInodeInfo object.
** Add all WhereLoop objects for a table of the join identified by
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
**
** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and
** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause
** entries that occur before the virtual table in the FROM clause and are
** separated from it by at least one LEFT or CROSS JOIN. Similarly, the
** mUnusable mask contains all FROM clause entries that occur after the
** virtual table and are separated from it by at least one LEFT or
** CROSS JOIN.
**
** For example, if the query were:
**
** ... FROM t1, t2 LEFT JOIN t3, t4, vt CROSS JOIN t5, t6;
**
** then mPrereq corresponds to (t1, t2) and mUnusable to (t5, t6).
**
** All the tables in mPrereq must be scanned before the current virtual
** table. So any terms for which all prerequisites are satisfied by
** mPrereq may be specified as "usable" in all calls to xBestIndex.
** Conversely, all tables in mUnusable must be scanned after the current
** virtual table, so any terms for which the prerequisites overlap with
** mUnusable should always be configured as "not-usable" for xBestIndex.
API oddity: If successful, SetFilePointer() returns a dword
** containing the lower 32-bits of the new file-offset. Or, if it fails,
** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
** whether an error has actually occurred, it is also necessary to call
** GetLastError().
True if a leaf page
** CAPI3REF: Error Logging Interface
**
** ^The [sqlite3_log()] interface writes a message into the [error log]
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
** ^If logging is enabled, the zFormat string and subsequent arguments are
** used with [sqlite3_snprintf()] to generate the final output string.
**
** The sqlite3_log() interface is intended for use by extensions such as
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
**
** The zFormat string must not be NULL.
**
** To avoid deadlocks and other threading problems, the sqlite3_log() routine
** will not use dynamically allocated memory. The log message is stored in
** a fixed-length buffer on the stack. If the log message is longer than
** a few hundred characters, it will be truncated to the length of the
** buffer.
Add number of Cells freed to this counter
** Begin a write-transaction on the specified pager object. If a
** write-transaction has already been opened, this function is a no-op.
**
** If the exFlag argument is false, then acquire at least a RESERVED
** lock on the database file. If exFlag is true, then acquire at least
** an EXCLUSIVE lock. If such a lock is already held, no locking
** functions need be called.
**
** If the subjInMemory argument is non-zero, then any sub-journal opened
** within this transaction will be opened as an in-memory file. This
** has no effect if the sub-journal is already opened (as it may be when
** running in exclusive mode) or if the transaction does not require a
** sub-journal. If the subjInMemory argument is zero, then any required
** sub-journal is implemented in-memory if pPager is an in-memory database,
** or using a temporary file otherwise.
Allocated size of zTerm buffer
Figure out the rowid of the new row.
************* Include mutex.h in the middle of sqliteInt.h ****************
copy a maximum of nBuf chars to output buffer
The btree
Abandon the tree walk
OUT: Number of leaf pages in b-tree
** The lower 16-bits of the sqlite3_index_info.idxNum value set by
** the xBestIndex() method contains the Fts3Cursor.eSearch value described
** above. The upper 16-bits contain a combination of the following
** bits, used to describe extra constraints on full-text searches.
** The caller must be holding a SHARED lock on the database file to call
** this function.
**
** If the pager passed as the first argument is open on a real database
** file (not a temp file or an in-memory database), and the WAL file
** is not already open, make an attempt to open it now. If successful,
** return SQLITE_OK. If an error occurs or the VFS used by the pager does
** not support the xShmXXX() methods, return an error code. *pbOpen is
** not modified in either case.
**
** If the pager is open on a temp-file (or in-memory database), or if
** the WAL file is already open, set *pbOpen to 1 and return SQLITE_OK
** without doing anything.
** Pragma virtual table module xDisconnect method.
!defined(SQLITE_MUTEX_OMIT)
If this database supports auto-vacuum and iPage is not the last
** page in this overflow list, check that the pointer-map entry for
** the following page matches iPage.
Block number of first allocated block
Destructor for a jsonEachCursor object
The number of notReady tables
Range of registers hold conent for pIdx
comment:
** Free all resources held by the schema structure. The void* argument points
** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the
** pointer itself, it just cleans up subsidiary resources (i.e. the contents
** of the schema hash tables).
**
** The Schema.cache_size variable is not cleared.
label: code-design
** This function is used to estimate the number of rows that will be visited
** by scanning an index for a range of values. The range may have an upper
** bound, a lower bound, or both. The WHERE clause terms that set the upper
** and lower bounds are represented by pLower and pUpper respectively. For
** example, assuming that index p is on t1(a):
**
** ... FROM t1 WHERE a > ? AND a < ? ...
** |_____| |_____|
** | |
** pLower pUpper
**
** If either of the upper or lower bound is not present, then NULL is passed in
** place of the corresponding WhereTerm.
**
** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
** column subject to the range constraint. Or, equivalently, the number of
** equality constraints optimized by the proposed index scan. For example,
** assuming index p is on t1(a, b), and the SQL query is:
**
** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
**
** then nEq is set to 1 (as the range restricted column, b, is the second
** left-most column of the index). Or, if the query is:
**
** ... FROM t1 WHERE a > ? AND a < ? ...
**
** then nEq is set to 0.
**
** When this function is called, *pnOut is set to the sqlite3LogEst() of the
** number of rows that the index scan is expected to visit without
** considering the range constraints. If nEq is 0, then *pnOut is the number of
** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
** to account for the range constraints pLower and pUpper.
**
** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
** used, a single range inequality reduces the search space by a factor of 4.
** and a pair of constraints (x>? AND x<?) reduces the expected number of
** rows visited by a factor of 64.
** Each node of an expression in the parse tree is an instance
** of this structure.
**
** Expr.op is the opcode. The integer parser token codes are reused
** as opcodes here. For example, the parser defines TK_GE to be an integer
** code representing the ">=" operator. This same integer code is reused
** to represent the greater-than-or-equal-to operator in the expression
** tree.
**
** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
** or TK_STRING), then Expr.token contains the text of the SQL literal. If
** the expression is a variable (TK_VARIABLE), then Expr.token contains the
** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
** then Expr.token contains the name of the function.
**
** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
** binary operator. Either or both may be NULL.
**
** Expr.x.pList is a list of arguments if the expression is an SQL function,
** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)".
** Expr.x.pSelect is used if the expression is a sub-select or an expression of
** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the
** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is
** valid.
**
** An expression of the form ID or ID.ID refers to a column in a table.
** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is
** the integer cursor number of a VDBE cursor pointing to that table and
** Expr.iColumn is the column number for the specific column. If the
** expression is used as a result in an aggregate SELECT, then the
** value is also stored in the Expr.iAgg column in the aggregate so that
** it can be accessed after all aggregates are computed.
**
** If the expression is an unbound variable marker (a question mark
** character '?' in the original SQL) then the Expr.iTable holds the index
** number for that variable.
**
** If the expression is a subquery then Expr.iColumn holds an integer
** register number containing the result of the subquery. If the
** subquery gives a constant result, then iTable is -1. If the subquery
** gives a different answer at different times during statement processing
** then iTable is the address of a subroutine that computes the subquery.
**
** If the Expr is of type OP_Column, and the table it is selecting from
** is a disk table or the "old.*" pseudo-table, then pTab points to the
** corresponding table definition.
**
** ALLOCATION NOTES:
**
** Expr objects can use a lot of memory space in database schema. To
** help reduce memory requirements, sometimes an Expr object will be
** truncated. And to reduce the number of memory allocations, sometimes
** two or more Expr objects will be stored in a single memory allocation,
** together with Expr.zToken strings.
**
** If the EP_Reduced and EP_TokenOnly flags are set when
** an Expr object is truncated. When EP_Reduced is set, then all
** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
** are contained within the same memory allocation. Note, however, that
** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately
** allocated, regardless of whether or not EP_Reduced is set.
Write the number of rows in the result here
Pointer to data part of aFrame buffer
Pointer to next docid
322
comment: unused parameter
label: code-design
File handle from CreateFileMapping
SQLITE_MAX_WORKER_THREADS!=0
cmd ::= ROLLBACK trans_opt
Cookie value for main db files
** These routines are available for the mem2.c debugging memory allocator
** only. They are used to verify that different "types" of memory
** allocations are properly tracked by the system.
**
** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
** the MEMTYPE_* macros defined below. The type must be a bitmask with
** a single bit set.
**
** sqlite3MemdebugHasType() returns true if any of the bits in its second
** argument match the type set by the previous sqlite3MemdebugSetType().
** sqlite3MemdebugHasType() is intended for use inside assert() statements.
**
** sqlite3MemdebugNoType() returns true if none of the bits in its second
** argument match the type set by the previous sqlite3MemdebugSetType().
**
** Perhaps the most important point is the difference between MEMTYPE_HEAP
** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
** it might have been allocated by lookaside, except the allocation was
** too large or lookaside was already full. It is important to verify
** that allocations that might have been satisfied by lookaside are not
** passed back to non-lookaside free() routines. Asserts such as the
** example above are placed on the non-lookaside free() routines to verify
** this constraint.
**
** All of this is no-op for a production build. It only comes into
** play when the SQLITE_MEMDEBUG compile-time option is used.
Valid if eType==FTSQUERY_NEAR
** This is the xRowid method. The SQLite core calls this routine to
** retrieve the rowid for the current row of the result set. fts3
** exposes %_content.docid as the rowid for the virtual table. The
** rowid should be written to *pRowid.
Pointer to next record in list
** Lock a file region.
Generate code for the left and right SELECT statements.
** Like sqlite3ExprIfFalse() except that a copy is made of pExpr before
** code generation, and that copy is deleted after code generation. This
** ensures that the original pExpr is unchanged.
** The xShmUnmap method.
Open the pager file.
Used only when flags==MEM_Agg
(287) nm ::= STRING
The ptrmapCheckPages() contains assert() statements that verify that
** all pointer map pages are set correctly. This is helpful while
** debugging. This is usually disabled because a corrupt database may
** cause an assert() statement to fail.
************* Include pager.h in the middle of sqliteInt.h ****************
OUT: Temp register to free
ERROR: size integer not terminated by "\n"
If control flows to here, it was not possible to append zTerm to the
** current node. Create a new node (a right-sibling of the current node).
** If this is the first node in the tree, the term is added to it.
**
** Otherwise, the term is not added to the new node, it is left empty for
** now. Instead, the term is inserted into the parent of pTree. If pTree
** has no parent, one is created here.
The new virtual table
cmdx ::= cmd
** Allowed values of WhereTerm.wtFlags
Skip any separator characters.
Creating a virtual table invokes the authorization callback twice.
** The first invocation, to obtain permission to INSERT a row into the
** sqlite_master table, has already been made by sqlite3StartTable().
** The second call, to obtain permission to create the table, is made now.
Contains agg functions or a GROUP BY
11
Initialize the master block.
Value is NULL (or a pointer)
************* End of pager.c **********************************************
Number of VM memory registers
Floating point value
************* End of json1.c **********************************************
Node type
Column number
Each cursor uses a memory cell. The first cursor (cursor 0) can
** use aMem[0] which is not otherwise used by the VDBE program. Allocate
** space at the end of aMem[] for cursors 1 and greater.
** See also: allocateCursor().
Largest idx in level (iAbsLevel+1)
4
** Parse the fts3 query expression found in buffer z, length n. This function
** returns either when the end of the buffer is reached or an unmatched
** closing bracket - ')' - is encountered.
**
** If successful, SQLITE_OK is returned, *ppExpr is set to point to the
** parsed form of the expression and *pnConsumed is set to the number of
** bytes read from buffer z. Otherwise, *ppExpr is set to 0 and SQLITE_NOMEM
** (out of memory error) or SQLITE_ERROR (parse error) is returned.
Input array
Second doclist
IN/OUT: Probe record
2nd input operand
Disabled if not using stat3
** This function is used to populate an allocated Fts3TokenAndCost array.
**
** If *pRc is not SQLITE_OK when this function is called, it is a no-op.
** Otherwise, if an error occurs during execution, *pRc is set to an
** SQLite error code.
** Unless it is NULL, argument zSql points to a buffer allocated using
** sqlite3_malloc containing an SQL statement. This function prepares the SQL
** statement against database db and frees the buffer. If statement
** compilation is successful, *ppStmt is set to point to the new statement
** handle and SQLITE_OK is returned.
**
** Otherwise, if an error occurs, *ppStmt is set to NULL and an error code
** returned. In this case, *pzErrmsg may also be set to point to an error
** message. It is the responsibility of the caller to free this error message
** buffer using sqlite3_free().
**
** If argument zSql is NULL, this function assumes that an OOM has occurred.
** In this case SQLITE_NOMEM is returned and *ppStmt set to NULL.
The table cursor. Or the PK cursor for WITHOUT ROWID
Resolve the ORDER BY on a compound SELECT after all terms of
** the compound have been resolved.
same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2])
** Process a "special" query. A special query is identified as one with a
** MATCH expression that begins with a '*' character. The remainder of
** the text passed to the MATCH operator are used as the special query
** parameters.
** Return a list of all dirty pages in the cache, sorted by page number.
** file_format==1 Version 3.0.0.
** file_format==2 Version 3.1.3. // ALTER TABLE ADD COLUMN
** file_format==3 Version 3.1.4. // ditto but with non-NULL defaults
** file_format==4 Version 3.3.0. // DESC indices. Boolean constants
** Flags for sqlite3PagerSetFlags()
**
** Value constraints (enforced via assert()):
** PAGER_FULLFSYNC == SQLITE_FullFSync
** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
** PAGER_CACHE_SPILL == SQLITE_CacheSpill
Column names
Tokens to the right of last highlight
One of the SRT_ operations to apply to self
No subqueries or non-deterministic functions allowed
** Code an OP_Halt that causes the vdbe to return an SQLITE_CONSTRAINT
** error. The onError parameter determines which (if any) of the statement
** and/or current transaction is rolled back.
** Close a tokenization cursor previously opened by a call to
** simpleOpen() above.
** TBD: Insert subroutine calls to close cursors on incomplete
**** subqueries ***
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code to implement a pseudo-random number
** generator (PRNG) for SQLite.
**
** Random numbers are used by some of the database backends in order
** to generate random integer keys for tables or random filenames.
0x14
INSERT statement
Update the database size and return.
************* End of loadext.c ********************************************
** Free the MergeEngine object passed as the only argument.
expr ::= LP select RP
** This function is used by the matchinfo() module to query a phrase
** expression node for the following information:
**
** 1. The total number of occurrences of the phrase in each column of
** the FTS table (considering all rows), and
**
** 2. For each column, the number of rows in the table for which the
** column contains at least one instance of the phrase.
**
** If no error occurs, SQLITE_OK is returned and the values for each column
** written into the array aiOut as follows:
**
** aiOut[iCol*3 + 1] = Number of occurrences
** aiOut[iCol*3 + 2] = Number of rows containing at least one instance
**
** Caveats:
**
** * If a phrase consists entirely of deferred tokens, then all output
** values are set to the number of documents in the table. In other
** words we assume that very common tokens occur exactly once in each
** column of each row of the table.
**
** * If a phrase contains some deferred tokens (and some non-deferred
** tokens), count the potential occurrence identified by considering
** the non-deferred tokens instead of actual phrase occurrences.
**
** * If the phrase is part of a NEAR expression, then only phrase instances
** that meet the NEAR constraint are included in the counts.
** Set *pCurrent to the total cache hits or misses encountered by all
** pagers the database handle is connected to. *pHighwater is always set
** to zero.
** This function is called before modifying the contents of a table
** to invalidate any incrblob cursors that are open on the
** row or one of the rows being modified.
**
** If argument isClearTable is true, then the entire contents of the
** table is about to be deleted. In this case invalidate all incrblob
** cursors open on any row within the table with root-page pgnoRoot.
**
** Otherwise, if argument isClearTable is false, then the row with
** rowid iRow is being replaced or deleted. In this case invalidate
** only those incrblob cursors open on that specific row.
Opcode, P3 & P5 of the opcode that ends the loop
table internal
Bytes remaining to copy
Index in a[] of entry with minimum score
Once all the other databases have been initialized, load the schema
** for the TEMP database. This is loaded last, as the TEMP database
** schema may contain references to objects in other databases.
comment:
** CAPI3REF: Streaming Versions of API functions.
**
** The six streaming API xxx_strm() functions serve similar purposes to the
** corresponding non-streaming API functions:
**
** <table border=1 style="margin-left:8ex;margin-right:8ex">
** <tr><th>Streaming function<th>Non-streaming equivalent</th>
** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
** </table>
**
** Non-streaming functions that accept changesets (or patchsets) as input
** require that the entire changeset be stored in a single buffer in memory.
** Similarly, those that return a changeset or patchset do so by returning
** a pointer to a single large buffer allocated using sqlite3_malloc().
** Normally this is convenient. However, if an application running in a
** low-memory environment is required to handle very large changesets, the
** large contiguous memory allocations required can become onerous.
**
** In order to avoid this problem, instead of a single large buffer, input
** is passed to a streaming API functions by way of a callback function that
** the sessions module invokes to incrementally request input data as it is
** required. In all cases, a pair of API function parameters such as
**
** <pre>
** int nChangeset,
** void *pChangeset,
** </pre>
**
** Is replaced by:
**
** <pre>
** int (*xInput)(void *pIn, void *pData, int *pnData),
** void *pIn,
** </pre>
**
** Each time the xInput callback is invoked by the sessions module, the first
** argument passed is a copy of the supplied pIn context pointer. The second
** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
** error occurs the xInput method should copy up to (*pnData) bytes of data
** into the buffer and set (*pnData) to the actual number of bytes copied
** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
** should be set to zero to indicate this. Or, if an error occurs, an SQLite
** error code should be returned. In all cases, if an xInput callback returns
** an error, all processing is abandoned and the streaming API function
** returns a copy of the error code to the caller.
**
** In the case of sqlite3changeset_start_strm(), the xInput callback may be
** invoked by the sessions module at any point during the lifetime of the
** iterator. If such an xInput callback returns an error, the iterator enters
** an error state, whereby all subsequent calls to iterator functions
** immediately fail with the same error code as returned by xInput.
**
** Similarly, streaming API functions that return changesets (or patchsets)
** return them in chunks by way of a callback function instead of via a
** pointer to a single large buffer. In this case, a pair of parameters such
** as:
**
** <pre>
** int *pnChangeset,
** void **ppChangeset,
** </pre>
**
** Is replaced by:
**
** <pre>
** int (*xOutput)(void *pOut, const void *pData, int nData),
** void *pOut
** </pre>
**
** The xOutput callback is invoked zero or more times to return data to
** the application. The first parameter passed to each call is a copy of the
** pOut pointer supplied by the application. The second parameter, pData,
** points to a buffer nData bytes in size containing the chunk of output
** data being returned. If the xOutput callback successfully processes the
** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
** it should return some other SQLite error code. In this case processing
** is immediately abandoned and the streaming API function returns a copy
** of the xOutput error code to the application.
**
** The sessions module never invokes an xOutput callback with the third
** parameter set to a value less than or equal to zero. Other than this,
** no guarantees are made as to the size of the chunks of data returned.
label: code-design
** Compare the 19-character string zNum against the text representation
** value 2^63: 9223372036854775808. Return negative, zero, or positive
** if zNum is less than, equal to, or greater than the string.
** Note that zNum must contain exactly 19 characters.
**
** Unlike memcmp() this routine is guaranteed to return the difference
** in the values of the last digit if the only difference is in the
** last digit. So, for example,
**
** compare2pow63("9223372036854775800", 1)
**
** will return -8.
Changeset iterator to read change from
Register SQL function on this connection
************* End of vdbeapi.c ********************************************
Insert the i-th overflow cell before the aiOvfl-th
** non-overflow cell
Generate a subroutine that will reset the group-by accumulator
Stmt under construction
** Routine to transform a unixFile into a proxy-locking unixFile.
** Implementation in the proxy-lock division, but used by unixOpen()
** if SQLITE_PREFER_PROXY_LOCKING is defined.
Write result into this Mem object
New cell becomes the i-th cell of the page
Search for the index that has the lowest scan cost.
**
** (2011-04-15) Do not do a full scan of an unordered index.
**
** (2013-10-03) Do not count the entries in a partial index.
**
** In practice the KeyInfo structure will not be used. It is only
** passed to keep OP_OpenRead happy.
************* End of whereInt.h *******************************************
Actual size of mapped region
** Query to see if Btree handle p may obtain a lock of type eLock
** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return
** SQLITE_OK if the lock may be obtained (by calling
** setSharedCacheTableLock()), or SQLITE_LOCKED if not.
Set of best costs
Offset of entry in pointer map
** Usage:
**
** assert( assert_pager_state(pPager) );
**
** This function runs many asserts to try to find inconsistencies in
** the internal state of the Pager object.
The source or pattern file
Do not issue error messages if true
** CAPI3REF: Status Parameters
** KEYWORDS: {status parameters}
**
** These integer constants designate various run-time status parameters
** that can be returned by [sqlite3_status()].
**
** <dl>
** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
** <dd>This parameter is the current amount of memory checked out
** using [sqlite3_malloc()], either directly or indirectly. The
** figure includes calls made to [sqlite3_malloc()] by the application
** and internal memory usage by the SQLite library. Scratch memory
** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
** this parameter. The amount returned is the sum of the allocation
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
**
** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
** internal equivalents). Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
** <dd>This parameter records the number of separate memory allocations
** currently checked out.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
** <dd>This parameter returns the number of pages used out of the
** [pagecache memory allocator] that was configured using
** [SQLITE_CONFIG_PAGECACHE]. The
** value returned is in pages, not in bytes.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
** <dd>This parameter returns the number of bytes of page cache
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
** buffer and where forced to overflow to [sqlite3_malloc()]. The
** returned value includes allocations that overflowed because they
** where too large (they were larger than the "sz" parameter to
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
** no space was left in the page cache.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [pagecache memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
** <dd>This parameter returns the number of allocations used out of the
** [scratch memory allocator] configured using
** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
** in bytes. Since a single thread may only have one scratch allocation
** outstanding at time, this parameter also reports the number of threads
** using scratch memory at the same time.</dd>)^
**
** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
** <dd>This parameter returns the number of bytes of scratch memory
** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
** returned include overflows because the requested allocation was too
** larger (that is, because the requested allocation was larger than the
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
** slots were available.
** </dd>)^
**
** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [scratch memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
** <dd>The *pHighwater parameter records the deepest parser stack.
** The *pCurrent value is undefined. The *pHighwater value is only
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
** </dl>
**
** New status parameters may be added from time to time.
165
comment: The print_pager_state() routine is intended to be used by the debugger
** only. We invoke it once here to suppress a compiler warning.
label: code-design
The setup query
Fill the automatic index with content
If the plan produced by the earlier call uses an IN(...) term, call
** xBestIndex again, this time with IN(...) terms disabled.
EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
** is NULL, then SQLite reverts to using its default memory allocator
** (the system malloc() implementation), undoing any prior invocation of
** SQLITE_CONFIG_MALLOC.
**
** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
** revert to its default implementation when sqlite3_initialize() is run
porter rule condition: (m > 0)
'|'. Bitwise OR or concatenate
OUT: Permissions of zFile
SQLITE_NOLFS
************* End of sqliteicu.h ******************************************
** SQL is translated into a sequence of instructions to be
** executed by a virtual machine. Each instruction is an instance
** of the following structure.
***************************************************************************
** Scalar SQL function implementations
***************************************************************************
Whether or not a database might need a master journal depends upon
** its journal mode (among other things). This matrix determines which
** journal modes use a master journal and which do not
Number of slots of aNode[] allocated
Database connection
Destination b-tree file
88
Table being updated
Pointer to cell-pointer area
Doclist (or NULL) to write
** Verify that the VM passed as the only argument does not contain
** an OP_ResultRow opcode. Fail an assert() if it does. This is used
** by code in pragma.c to ensure that the implementation of certain
** pragmas comports with the flags specified in the mkpragmatab.tcl
** script.
277
The following block is a no-op unless SQLITE_DEBUG is defined. Its only
** purpose is to execute assert() statements to verify that if the
** PragFlg_NoColumns1 flag is set and the caller specified an argument
** to the PRAGMA, the implementation has not added any OP_ResultRow
** instructions to the VM.
** Write data from a buffer into a file. Return SQLITE_OK on success
** or some other error code on failure.
Colset to filter on (or NULL)
Pointer to mapping of entire file
** Return TRUE if the cursor has been moved off of the last
** row of output.
** Record the fact that we want to lock a table at run-time.
**
** The table to be locked has root page iTab and is found in database iDb.
** A read or a write lock can be taken depending on isWritelock.
**
** This routine just records the fact that the lock is desired. The
** code to make the lock occur is generated by a later call to
** codeTableLocks() which occurs during sqlite3FinishCoding().
Allocate exact page if possible
3 EXPLAIN:
storage for current token
comment: No longer used
label: code-design
Skip the "sqlite_altertab_" prefix on the name
Max pending data before flush to disk
Number of TryBeginRead attempts
Make sure all SELECTs in the statement have the same number of elements
** in their result sets.
OUT: Deserialized object
(294) carglist ::=
Schema restricts name search if present
cached details from statfs()
********** End %parse_accept code ******************************************
** Return the number of the wal-index page that contains the hash-table
** and page-number array that contain entries corresponding to WAL frame
** iFrame. The wal-index is broken up into 32KB pages. Wal-index pages
** are numbered starting from 0.
in1, out2, in3
UTF-8 -> UTF-16 Little-endian
Character iIn and iIn+1 form an escaped quote character. Skip
** the input cursor past both and copy a single quote character
** to the output buffer.
Cache used by auxiliary functions xInst() and xInstCount()
Tables marked isRecursive have only a single row that is stored in
** a pseudo-cursor. No need to Rewind or Next such cursors.
If possible, improve on the iUpper estimate using ($P:$U).
no-op if possible
Only operate the lookaside when zero
Output variables. Containing the current node entry.
#include "sqlite3.h"
Direct rendering mode means take data directly
** from source tables rather than from accumulators
******* Begin %stack_overflow code *****************************************
0: hits. 1: size misses. 2: full misses
** Serialize and store the "structure" record.
**
** If an error occurs, leave an error code in the Fts5Index object. If an
** error has already occurred, this function is a no-op.
INTERSECT
** Load the doclist for phrase p into p->doclist.aAll/nAll. The loaded doclist
** does not take deferred tokens into account.
**
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
Collect arguments into local variables
paren_exprlist
Output value
Buffer containing previous term
Current 'pos' value
Masks of old.*, new.* columns accessed
pWLoop is a winner. Add it to the set of best so far
This is not VxWorks.
comment: Remove the redundant segments from the input level
label: code-design
Number of unused bytes at end of each page
Need to read this page properly. It contains some of the
** range of data that is being read (eOp==0) or written (eOp!=0).
SQLITE_ENABLE_COLUMN_METADATA
Comment
Index of free page to move pLastPg to
Flags passed to OsOpen()
Index on parent covering the foreign key
** Return true if the buffer z[0..n-1] contains all spaces.
** This version of the memory allocator is only built into the library
** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
** mean that the library will use a memory-pool by default, just that
** it is available. The mempool allocator is activated by calling
** sqlite3_config().
** Ensure these symbols were not defined by some previous header file.
REINDEX
a0..a7 ........
************* End of walker.c *********************************************
** This function is called as part of committing a transaction within which
** one or more frames have been overwritten. It updates the checksums for
** all frames written to the wal file by the current transaction starting
** with the earliest to have been overwritten.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
** This function is called to merge two changes to the same row together as
** part of an sqlite3changeset_concat() operation. A new change object is
** allocated and a pointer to it stored in *ppNew.
************* End of btree.h **********************************************
** Do we need to manually define the Win32 file mapping APIs for use with WAL
** mode or memory mapped files (e.g. these APIs are available in the Windows
** CE SDK; however, they are not present in the header file)?
Link pParent into the free node list. It will be used as an
** internal node of the new tree.
Assume single column records only
Jump destination for skipping partial index entries
YYWILDCARD
Description of the table we are reading from
Fire any BEFORE UPDATE triggers. This happens before constraints are
** verified. One could argue that this is wrong.
** Allocate space for a file-handle and open a temporary file. If successful,
** set *ppFd to point to the malloc'd file-handle and return SQLITE_OK.
** Otherwise, set *ppFd to 0 and return an SQLite error code.
Contains NOT NULL constraints
temp ::=
Opcode: SequenceTest P1 P2 * * *
** Synopsis: if( cursor[P1].ctr++ ) pc = P2
**
** P1 is a sorter cursor. If the sequence counter is currently zero, jump
** to P2. Regardless of whether or not the jump is taken, increment the
** the sequence value.
0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
** reaching the VFS.
Cannot be both MEM_Int and MEM_Real at the same time
Insert an element into the hash table pH. The key is pKey,nKey
** and the data is "data".
**
** If no element exists with a matching key, then a new
** element is created. A copy of the key is made if the copyKey
** flag is set. NULL is returned.
**
** If another element already exists with the same key, then the
** new data replaces the old data and the old data is returned.
** The key is not copied in this instance. If a malloc fails, then
** the new data is returned and the hash table is unchanged.
**
** If the "data" parameter to this function is NULL, then the
** element corresponding to "key" is removed from the hash table.
Buffer in which to assemble leaf page
** An implementation of the UnlockFile API of Windows for CE
** Run a checkpoint on the Btree passed as the first argument.
**
** Return SQLITE_LOCKED if this or any other connection has an open
** transaction on the shared-cache the argument Btree is connected to.
**
** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
An element of aFrom[] that we are working on
600
Register to allocate runtime space
Drop the cell from the parent page. apDiv[i] still points to
** the cell within the parent, even though it has been dropped.
** This is safe because dropping a cell only overwrites the first
** four bytes of it, and this function does not need the first
** four bytes of the divider cell. So the pointer is safe to use
** later on.
**
** But not if we are in secure-delete mode. In secure-delete mode,
** the dropCell() routine will overwrite the entire cell with zeroes.
** In this case, temporarily copy the cell into the aOvflSpace[]
** buffer. It will be copied out again as soon as the aSpace[] buffer
** is allocated.
Right table being joined
Allocated index object
Step 5b
** CAPI3REF: Write-Ahead Log Commit Hook
** METHOD: sqlite3
**
** ^The [sqlite3_wal_hook()] function is used to register a callback that
** is invoked each time data is committed to a database in wal mode.
**
** ^(The callback is invoked by SQLite after the commit has taken place and
** the associated write-lock on the database released)^, so the implementation
** may read, write or [checkpoint] the database as required.
**
** ^The first parameter passed to the callback function when it is invoked
** is a copy of the third parameter passed to sqlite3_wal_hook() when
** registering the callback. ^The second is a copy of the database handle.
** ^The third parameter is the name of the database that was written to -
** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
** is the number of pages currently in the write-ahead log file,
** including those that were just committed.
**
** The callback function should normally return [SQLITE_OK]. ^If an error
** code is returned, that error will propagate back up through the
** SQLite code base to cause the statement that provoked the callback
** to report an error, though the commit will have still occurred. If the
** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
** that does not correspond to any valid SQLite error code, the results
** are undefined.
**
** A single database handle may have at most a single write-ahead log callback
** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
** previously registered write-ahead log callback. ^Note that the
** [sqlite3_wal_autocheckpoint()] interface and the
** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
** overwrite any prior [sqlite3_wal_hook()] settings.
If this is an RBU vacuum handle and the vacuum has either finished
** successfully or encountered an error, delete the contents of the
** state table. This causes the next call to sqlite3rbu_vacuum()
** specifying the current target and state databases to start a new
** vacuum from scratch.
** Generate code to return a single text value.
A-overwrites-S
100 for page 1. 0 otherwise
Top of the delete loop
read the conch content
The following block sets the new values of Mem.z and Mem.xDel. It
** also sets a flag in local variable "flags" to indicate the memory
** management (one of MEM_Dyn or MEM_Static).
The current candidate is no better than any of the mxChoice
** paths currently in the best-so-far buffer. So discard
** this candidate as not viable.
*****************************************************************************
************************** Begin flock Locking ********************************
**
** Use the flock() system call to do file locking.
**
** flock() locking is like dot-file locking in that the various
** fine-grain locking levels supported by SQLite are collapsed into
** a single exclusive lock. In other words, SHARED, RESERVED, and
** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite
** still works when you do this, but concurrency is reduced since
** only a single process can be reading the database at a time.
**
** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off
Allocate and populate a new Parse context to use for coding the
** trigger sub-program.
Verify correct alignment of TK_ and OP_ constants
Set delete-flag @ iSzPoslist
First argument for the conflict handler
True if at end of search
if SystemTimeToFileTime() fails, it returns zero.
Type of value from change record
** This function is used to access the current position list for phrase
** iPhrase.
Do not allow the total number of threads (main thread + all workers)
** to exceed the maximum merge count
** Here are all of the sqlite3_io_methods objects for each of the
** locking strategies. Functions that return pointers to these methods
** are also created.
Number of cursors for child frame
Part of a compound query
** Expr pIn is an IN(...) expression. This function checks that the
** sub-select on the RHS of the IN() operator has the same number of
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
** a sub-query, that the LHS is a vector of size 1.
Number of columns in the sorting index
comment: Type of the array "element" for the bitmap representation.
** Should be a power of 2, and ideally, evenly divide into BITVEC_USIZE.
** Setting this to the "natural word" size of your CPU may improve
** performance.
label: code-design
Index number
** If argument pOrig is NULL, or if (*pRc) is set to anything other than
** SQLITE_OK when this function is called, NULL is returned.
**
** Otherwise, a copy of (*pOrig) is made into memory obtained from
** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
** Mutex to control access to the memory allocation subsystem.
Number of entries in aFirst[]
************************************************************************
**************************************************************************
** Below this point is the implementation of the fts5_decode() scalar
** function only.
** CAPI3REF: Return The Size Of An Open BLOB
** METHOD: sqlite3_blob
**
** ^Returns the size in bytes of the BLOB accessible via the
** successfully opened [BLOB handle] in its only argument. ^The
** incremental blob I/O routines can only read or overwriting existing
** blob content; they cannot change the size of a blob.
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
** SQLite supports many different ways to resolve a constraint
** error. ROLLBACK processing means that a constraint violation
** causes the operation in process to fail and for the current transaction
** to be rolled back. ABORT processing means the operation in process
** fails and any prior changes from that one operation are backed out,
** but the transaction is not rolled back. FAIL processing means that
** the operation in progress stops and returns an error code. But prior
** changes due to the same operation are not backed out and no rollback
** occurs. IGNORE means that the particular row that caused the constraint
** error is not inserted or updated. Processing continues and no error
** is returned. REPLACE means that preexisting database rows that caused
** a UNIQUE constraint violation are removed so that the new insert or
** update can proceed. Processing continues and no error is reported.
**
** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
** referenced table row is propagated into the row that holds the
** foreign key.
**
** The following symbolic values are used to record which type
** of action to take.
** The input pointer currently points to the second byte of a table-header.
** Specifically, to the following:
**
** + number of columns in table (varint)
** + array of PK flags (1 byte per column),
** + table name (nul terminated).
**
** This function decodes the table-header and populates the p->nCol,
** p->zTab and p->abPK[] variables accordingly. The p->apValue[] array is
** also allocated or resized according to the new value of p->nCol. The
** input pointer is left pointing to the byte following the table header.
**
** If successful, SQLITE_OK is returned. Otherwise, an SQLite error code
** is returned and the final values of the various fields enumerated above
** are undefined.
comment: Issue SQLITE_READ authorizations with a fake column name for any tables that
** are referenced but from which no values are extracted. Examples of where these
** kinds of null SQLITE_READ authorizations would occur:
**
** SELECT count(*) FROM t1; -- SQLITE_READ t1.""
** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2.""
**
** The fake column name is an empty string. It is possible for a table to
** have a column named by the empty string, in which case there is no way to
** distinguish between an unreferenced table and an actual reference to the
** "" column. The original design was for the fake column name to be a NULL,
** which would be unambiguous. But legacy authorization callbacks might
** assume the column name is non-NULL and segfault. The use of an empty string
** for the fake column name seems safer.
label: code-design
Tables that must be scanned after this one
Tokenizer functions
************* End of rtree.h **********************************************
paren_exprlist ::= LP exprlist RP
** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q)
** 1) PRAGMA index_list = ?
** 2) SELECT count(*) FROM sqlite_master where name=%Q
** 3) PRAGMA table_info = ?
OUT: Compiled statement
** Set the time to the current time reported by the VFS.
**
** Return the number of errors.
If a column from a table in pSrcList is referenced, then record
** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
** bit 0 to be set. Column 1 sets bit 1. And so forth. If the
** column number is greater than the number of bits in the bitmask
** then set the high-order bit of the bitmask.
Non-recursive part
zNum is a 19-digit numbers. Compare it against 9223372036854775808.
The table being dropped does not have the largest root-page
** number in the database. So move the page that does into the
** gap left by the deleted root-page.
** Load the content of the sqlite_stat1 and sqlite_stat3/4 tables. The
** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
** arrays. The contents of sqlite_stat3/4 are used to populate the
** Index.aSample[] arrays.
**
** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
** is returned. In this case, even if SQLITE_ENABLE_STAT3/4 was defined
** during compilation and the sqlite_stat3/4 table is present, no data is
** read from it.
**
** If SQLITE_ENABLE_STAT3/4 was defined during compilation and the
** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
** returned. However, in this case, data is read from the sqlite_stat1
** table (if it is present) before returning.
**
** If an OOM error occurs, this function always sets db->mallocFailed.
** This means if the caller does not care about other errors, the return
** code may be ignored.
OUT: New value object (or NULL)
comment: The database connection used for malloc()
label: code-design
Case 6: There is no usable index. We must do a complete
** scan of the entire table.
wherecode.c:
WHERE clause processing context
Affinity used when eDest==SRT_Set
0x1f
Locks obtained by this instance of winFile
** An instance of the following structure is allocated for each active
** savepoint and statement transaction in the system. All such structures
** are stored in the Pager.aSavepoint[] array, which is allocated and
** resized using sqlite3Realloc().
**
** When a savepoint is created, the PagerSavepoint.iHdrOffset field is
** set to 0. If a journal-header is written into the main journal while
** the savepoint is active, then iHdrOffset is set to the byte offset
** immediately following the last journal record written into the main
** journal before the journal-header. This is required during savepoint
** rollback (see pagerPlaybackSavepoint()).
comment: Mark a function parameter as unused, to suppress nuisance compiler
** warnings.
label: code-design
Set the maximum error count
Collating sequence for the result set
Extra data passed into the callback
Creating a new table may probably require moving an existing database
** to make room for the new tables root page. In case this page turns
** out to be an overflow page, delete all overflow page-map caches
** held by open cursors.
Number of integers output by cArg
comment:
** This function is used to create a SELECT list (the list of SQL
** expressions that follows a SELECT keyword) for a SELECT statement
** used to read from an data_xxx or rbu_tmp_xxx table while updating the
** index object currently indicated by the iterator object passed as the
** second argument. A "PRAGMA index_xinfo = <idxname>" statement is used
** to obtain the required information.
**
** If the index is of the following form:
**
** CREATE INDEX i1 ON t1(c, b COLLATE nocase);
**
** and "t1" is a table with an explicit INTEGER PRIMARY KEY column
** "ipk", the returned string is:
**
** "`c` COLLATE 'BINARY', `b` COLLATE 'NOCASE', `ipk` COLLATE 'BINARY'"
**
** As well as the returned string, three other malloc'd strings are
** returned via output parameters. As follows:
**
** pzImposterCols: ...
** pzImposterPk: ...
** pzWhere: ...
label: code-design
** Used when SQLITE_NO_SYNC is not defined and by the assert() and/or
** OSTRACE() macros.
This page from bulk local storage
Automatically generated. Do not edit
Table structure column is extracted from
zFilename is a temporary or immutable file
Begin flattening the iFrom-th entry of the FROM clause
** in the outer query.
Compute the old pre-UPDATE content of the row being changed, if that
** information is needed
go back to the do {} while start point, try again
In this case the pcache already contains an initialized copy of
** the page. Return without further ado.
This is the bogus content
No. of coordinates
Write any error message here
sqlite3SelectNew() guarantees this
The attached database containing the blob
** fts3ExprIterate() callback used to collect the "global" matchinfo stats
** for a single query.
**
** fts3ExprIterate() callback to load the 'global' elements of a
** FTS3_MATCHINFO_HITS matchinfo array. The global stats are those elements
** of the matchinfo array that are constant for all rows returned by the
** current query.
**
** Argument pCtx is actually a pointer to a struct of type MatchInfo. This
** function populates Matchinfo.aMatchinfo[] as follows:
**
** for(iCol=0; iCol<nCol; iCol++){
** aMatchinfo[3*iPhrase*nCol + 3*iCol + 1] = X;
** aMatchinfo[3*iPhrase*nCol + 3*iCol + 2] = Y;
** }
**
** where X is the number of matches for phrase iPhrase is column iCol of all
** rows of the table. Y is the number of rows for which column iCol contains
** at least one instance of phrase iPhrase.
**
** If the phrase pExpr consists entirely of deferred tokens, then all X and
** Y values are set to nDoc, where nDoc is the number of documents in the
** file system. This is done because the full-text index doclist is required
** to calculate these values properly, and the full-text index doclist is
** not available for deferred tokens.
Do not load data from disk
READ UNCOMMITTED in shared-cache
Allocate the change object
The PATCH
Parse object
** Free up as much memory as we can from the given database
** connection.
Create extra terms on the WHERE clause for each column named
** in the USING clause. Example: If the two tables to be joined are
** A and B and the USING clause names X, Y, and Z, then add this
** to the WHERE clause: A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
** Report an error if any column mentioned in the USING clause is
** not contained in both tables to be joined.
pIter now points just past the 0x00 that terminates the position-
** list for document pDL->iDocid. However, if this position-list was
** edited in place by fts3EvalNearTrim(), then pIter may not actually
** point to the start of the next docid value. The following line deals
** with this case by advancing pIter past the zero-padding added by
** fts3EvalNearTrim().
Merge the two position lists.
** Erase the given database page and all its children. Return
** the page to the freelist.
If SQLITE_UTF16 is specified as the encoding type, transform this
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
One release per successful fetch. Page is pinned until released.
** Reference counted.
Register to hold key for checking the FK
Increase the leaves written counter
SQLITE_OMIT_TRUNCATE_OPTIMIZATION
which columns to include in the result
Different collating sequences
defined(SQLITE_ENABLE_STAT3_OR_STAT4)
800
True to use onepass strategy
Index scan is using
** If pFile holds a lock on a conch file, then release that lock.
** Implementation of the substr() function.
**
** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
** p1 is 1-indexed. So substr(x,1,1) returns the first character
** of x. If x is text, then we actually count UTF-8 characters.
** If x is a blob, then we count bytes.
**
** If p1 is negative, then we begin abs(p1) from the end of x[].
**
** If p2 is negative, return the p2 characters preceding p1.
** Check that there is no open read-transaction on the b-tree passed as the
** second argument. If there is not, return SQLITE_OK. Otherwise, if there
** is an open read-transaction, return SQLITE_ERROR and leave an error
** message in database handle db.
Alternative data destination
The number of integers to decode
True if cursor is at EOF
** Compute the number of pages of cache requested. p->szCache is the
** cache size requested by the "PRAGMA cache_size" statement.
Opcode: Prev P1 P2 P3 P4 P5
**
** Back up cursor P1 so that it points to the previous key/data pair in its
** table or index. If there is no previous key/value pairs then fall through
** to the following instruction. But if the cursor backup was successful,
** jump immediately to P2.
**
**
** The Prev opcode is only valid following an SeekLT, SeekLE, or
** OP_Last opcode used to position the cursor. Prev is not allowed
** to follow SeekGT, SeekGE, or OP_Rewind.
**
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
** not open then the behavior is undefined.
**
** The P3 value is a hint to the btree implementation. If P3==1, that
** means P1 is an SQL index and that this instruction could have been
** omitted if that index had been unique. P3 is usually 0. P3 is
** always either 0 or 1.
**
** P4 is always of type P4_ADVANCE. The function pointer points to
** sqlite3BtreePrevious().
**
** If P5 is positive and the jump is taken, then event counter
** number P5-1 in the prepared statement is incremented.
aXRef[i] is the index in pChanges->a[] of the
** an expression for the i-th column of the table.
** aXRef[i]==-1 if the i-th column is not changed.
comment:
** Lookaside malloc is a set of fixed-size buffers that can be used
** to satisfy small transient memory allocation requests for objects
** associated with a particular database connection. The use of
** lookaside malloc provides a significant performance enhancement
** (approx 10%) by avoiding numerous malloc/free requests while parsing
** SQL statements.
**
** The Lookaside structure holds configuration information about the
** lookaside malloc subsystem. Each available memory allocation in
** the lookaside subsystem is stored on a linked list of LookasideSlot
** objects.
**
** Lookaside allocations are only allowed for objects that are associated
** with a particular database connection. Hence, schema information cannot
** be stored in lookaside because in shared cache mode the schema information
** is shared by multiple database connections. Therefore, while parsing
** schema information, the Lookaside.bEnabled flag is cleared so that
** lookaside allocations are not used to construct the schema objects.
label: code-design
Changes list for any UPDATE OF triggers
get sign of significand
** Lock the database file to level eLock, which must be either SHARED_LOCK,
** RESERVED_LOCK or EXCLUSIVE_LOCK. If the caller is successful, set the
** Pager.eLock variable to the new locking state.
**
** Except, if Pager.eLock is set to UNKNOWN_LOCK when this function is
** called, do not modify it unless the new locking state is EXCLUSIVE_LOCK.
** See the comment above the #define of UNKNOWN_LOCK for an explanation
** of this.
** The hashing function.
Shortcut for the case when the freelist is empty
** Read part of the payload for the row at which that cursor pCur is currently
** pointing. "amt" bytes will be transferred into pBuf[]. The transfer
** begins at "offset".
**
** pCur can be pointing to either a table or an index b-tree.
** If pointing to a table btree, then the content section is read. If
** pCur is pointing to an index b-tree then the key section is read.
**
** For sqlite3BtreePayload(), the caller must ensure that pCur is pointing
** to a valid row in the table. For sqlite3BtreePayloadChecked(), the
** cursor might be invalid or might need to be restored before being read.
**
** Return SQLITE_OK on success or an error code if anything goes
** wrong. An error is returned if "offset+amt" is larger than
** the available payload.
** Function getNextNode(), which is called by fts3ExprParse(), may itself
** call fts3ExprParse(). So this forward declaration is required.
Recursive part
The number of overflow pages to load for this (and therefore all
** subsequent) tokens is greater than the estimated number of pages
** that will be loaded if all subsequent tokens are deferred.
Virtual tables must be handled separately
* The maximum size of the Win32-specific heap. This value may be zero.
** Check the leaf RTree cell given by pCellData against constraint p.
** If this constraint is not satisfied, set *peWithin to NOT_WITHIN.
** If the constraint is satisfied, leave *peWithin unchanged.
**
** The constraint is of the form: xN op $val
**
** The op is given by p->op. The xN is p->iCoord-th coordinate in
** pCellData. $val is given by p->u.rValue.
Create a new ephemeral function definition for the overloaded
** function
** The variable-length integer encoding is as follows:
**
** KEY:
** A = 0xxxxxxx 7 bits of data and one flag bit
** B = 1xxxxxxx 7 bits of data and one flag bit
** C = xxxxxxxx 8 bits of data
**
** 7 bits - A
** 14 bits - BA
** 21 bits - BBA
** 28 bits - BBBA
** 35 bits - BBBBA
** 42 bits - BBBBBA
** 49 bits - BBBBBBA
** 56 bits - BBBBBBBA
** 64 bits - BBBBBBBBC
comment: Consider using a skip-scan if there are no WHERE clause constraints
** available for the left-most terms of the index, and if the average
** number of repeats in the left-most terms is at least 18.
**
** The magic number 18 is selected on the basis that scanning 17 rows
** is almost always quicker than an index seek (even though if the index
** contains fewer than 2^17 rows we assume otherwise in other parts of
** the code). And, even if it is not, it should not be too much slower.
** On the other hand, the extra seeks could end up being significantly
** more expensive.
label: code-design
FTS3 table handle
We got the time
Buffer to read position list from
comment: previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused.
label: code-design
109
Results of parsing argc/argv
Check that the virtual-table is not already being initialized
True for a prefix term
** Allocate a new hash table.
** Drop every cache entry whose page number is greater than "pgno". The
** caller must ensure that there are no outstanding references to any pages
** other than page 1 with a page number greater than pgno.
**
** If there is a reference to page 1 and the pgno parameter passed to this
** function is 0, then the data area associated with page 1 is zeroed, but
** the page object is not dropped.
Pager state (OPEN, READER, WRITER_LOCKED..)
If >=0, filter for this column
Record a pointer to the logger function and its first argument.
** The default is NULL. Logging is disabled if the function pointer is
** NULL.
Absolute level of input segments
True if arguments are desc
216
** json_type(JSON)
** json_type(JSON, PATH)
**
** Return the top-level "type" of a JSON string. Throw an error if
** either the JSON or PATH inputs are not well-formed.
**************************************************************************
** The "pragma.h" include file is an automatically generated file that
** that includes the PragType_XXXX macro definitions and the aPragmaName[]
** object. This ensures that the aPragmaName[] table is arranged in
** lexicographical order to facility a binary search of the pragma name.
** Do not edit pragma.h directly. Edit and rerun the script in at
** ../tool/mkpragmatab.tcl.
At the pager level, a statement transaction is a savepoint with
** an index greater than all savepoints created explicitly using
** SQL statements. It is illegal to open, release or rollback any
** such savepoints while the statement transaction savepoint is active.
comment: This case could be removed without changing the results of running
** this code. Including it causes gcc to generate a faster switch
** statement (since the range of switch targets now starts at zero and
** is contiguous) but does not cause any duplicate code to be generated
** (as gcc is clever enough to combine the two like cases). Other
** compilers might be similar.
label: code-design
First absolute level for iLangid/iIndex
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Low level access to the FTS index stored in the database file. The
** routines in this file file implement all read and write access to the
** %_data table. Other parts of the system access this functionality via
** the interface defined in fts5Int.h.
************* Continuing where we left off in sqlite3rbu.c ****************
Try to avoid a seek in BtreeInsert()
Number of function parameters
comment: If necessary, remove sample iMin to make room for the new sample.
label: code-design
SQLITE_USE_FCNTL_TRACE
GOTO label for next WHEN clause
470
Fill in the abNotindexed array
Total number of segments on level
Ok to return a row more than once
Clear any prior statistics
Used to iterate through aAll
#define SQLITE_ABORT 4 // Also an error code
Page number to read
If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
** starting at pg1, then it needs to be set for all of them. Because
** writing to any of these nPage pages may damage the others, the
** journal file must contain sync()ed copies of all of them
** before any of them can be written out to the database file.
SQLITE_DEBUG - the sqlite3AssertMayAbort() function
List of nodes removed during a CondenseTree operation. List is
** linked together via the pointer normally used for hash chains -
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
** headed by the node (leaf nodes have RtreeNode.iNode==0).
Text of the token
The destructor
LCS value for this column
Bytes of memory for in-memory hash
OUT: User data for *pxFunc
Index of the new VdbeCursor
If true, LHS of IN operator is a rowid
This test function is not currently used by the automated test-suite.
** Hence it is only available in debug builds.
** Add a new element to the pAggInfo->aCol[] array. Return the index of
** the new element. Return a negative number if malloc fails.
One of the PAGER_JOURNALMODE_* values
Recovery action to do in case of an error
Opcode: AddImm P1 P2 * * *
** Synopsis: r[P1]=r[P1]+P2
**
** Add the constant P2 to the value in register P1.
** The result is always an integer.
**
** To force any register to be an integer, just add 0.
Agg finalizer
154
refarg ::= ON UPDATE refact
col
First argument to xInput
** This function registered all of the above C functions as SQL
** functions. This should be the only routine in this file with
** external linkage.
** This function is an fts3ExprIterate() callback used by sqlite3Fts3Offsets().
Number of u32 elements in match-info
** Information is passed from codeCursorHint() down to individual nodes of
** the expression tree (by sqlite3WalkExpr()) using an instance of this
** structure.
This call is Ok even if this savepoint is actually a transaction
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
** If this is a transaction savepoint being opened, it is guaranteed
** that the db->aVTrans[] array is empty.
Number of objects on pFresh
Inserting a single row into a parent table cannot cause (or fix)
** an immediate foreign key violation. So do nothing in this case.
INSTEAD => ID
True if inside write transaction
The progress callback
** Return true if, for the purposes of tokenizing with the tokenizer
** passed as the first argument, codepoint iCode is considered a token
** character (not a separator).
Set iBlock to the index of the block pointed to by pOld in
** the array of mem5.szAtom byte blocks pointed to by mem5.zPool.
************* Begin file util.c *******************************************
Do not allow a transition to journal_mode=WAL for a database
** in temporary storage or if the VFS does not support shared memory
** Names of the various JSON types:
Pointer to buffer
Used when p4type is P4_FUNCCTX
Integer 0
Node pPhrase belongs to
Do substitutes on p->pPrior too
the prepared statement
Name of system call to override
************* End of sqlite3session.c *************************************
** Lock the file with the lock specified by parameter eFileLock - one
** of the following:
**
** (1) SHARED_LOCK
** (2) RESERVED_LOCK
** (3) PENDING_LOCK
** (4) EXCLUSIVE_LOCK
**
** Sometimes when requesting one lock state, additional lock states
** are inserted in between. The locking might fail on one of the later
** transitions leaving the lock state different from what it started but
** still short of its goal. The following chart shows the allowed
** transitions and the inserted intermediate states:
**
** UNLOCKED -> SHARED
** SHARED -> RESERVED
** SHARED -> (PENDING) -> EXCLUSIVE
** RESERVED -> (PENDING) -> EXCLUSIVE
** PENDING -> EXCLUSIVE
**
** This routine will only increase a lock. Use the sqlite3OsUnlock()
** routine to lower a locking level.
**
** With dotfile locking, we really only support state (4): EXCLUSIVE.
** But we track the other locking levels internally.
Pointer to buffer containing name
The level of the FROM clause we are working on
in case we need to try again for an :auto: named lock file
"view", "trigger", or "index"
Loop through table entries that match term pOrTerm.
The pSpace buffer will be freed after the next call to
** balance_nonroot(), or just before this function returns, whichever
** comes first.
Unix file with file desc used in the key
Update nBackfill
tconscomma ::= COMMA
Initialize the PCache object.
Length of the apDef[] list
** xNext - Advance the cursor to the next row, if any.
Index of column to read value from
The specific database being pragmaed
This condition is true when pItem is the FROM clause term on the
** right-hand-side of a LEFT or CROSS JOIN.
Opcode: If P1 P2 P3 * *
**
** Jump to P2 if the value in register P1 is true. The value
** is considered true if it is numeric and non-zero. If the value
** in P1 is NULL then take the jump if and only if P3 is non-zero.
** Append content to pParse that will complete zPath. Return a pointer
** to the inserted node, or return NULL if the append fails.
** Set or clear the access authorization function.
**
** The access authorization function is be called during the compilation
** phase to verify that the user has read and/or write access permission on
** various fields of the database. The first argument to the auth function
** is a copy of the 3rd argument to this routine. The second argument
** to the auth function is one of these constants:
**
** SQLITE_CREATE_INDEX
** SQLITE_CREATE_TABLE
** SQLITE_CREATE_TEMP_INDEX
** SQLITE_CREATE_TEMP_TABLE
** SQLITE_CREATE_TEMP_TRIGGER
** SQLITE_CREATE_TEMP_VIEW
** SQLITE_CREATE_TRIGGER
** SQLITE_CREATE_VIEW
** SQLITE_DELETE
** SQLITE_DROP_INDEX
** SQLITE_DROP_TABLE
** SQLITE_DROP_TEMP_INDEX
** SQLITE_DROP_TEMP_TABLE
** SQLITE_DROP_TEMP_TRIGGER
** SQLITE_DROP_TEMP_VIEW
** SQLITE_DROP_TRIGGER
** SQLITE_DROP_VIEW
** SQLITE_INSERT
** SQLITE_PRAGMA
** SQLITE_READ
** SQLITE_SELECT
** SQLITE_TRANSACTION
** SQLITE_UPDATE
**
** The third and fourth arguments to the auth function are the name of
** the table and the column that are being accessed. The auth function
** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE. If
** SQLITE_OK is returned, it means that access is allowed. SQLITE_DENY
** means that the SQL statement will never-run - the sqlite3_exec() call
** will return with an error. SQLITE_IGNORE means that the SQL statement
** should run but attempts to read the specified column will return NULL
** and attempts to write the column will be ignored.
**
** Setting the auth function to NULL disables this hook. The default
** setting of the auth function is NULL.
** Write mapping (iRowid->iNode) to the <rtree>_rowid table.
Docid for entry to add
Tables in outer loops of the join
Number of entries in the hash table
comment:
** Implementation of a scalar function that decodes r-tree nodes to
** human readable strings. This can be used for debugging and analysis.
**
** The scalar function takes two arguments: (1) the number of dimensions
** to the rtree (between 1 and 5, inclusive) and (2) a blob of data containing
** an r-tree node. For a two-dimensional r-tree structure called "rt", to
** deserialize all nodes, a statement like:
**
** SELECT rtreenode(2, data) FROM rt_node;
**
** The human readable string takes the form of a Tcl list with one
** entry for each cell in the r-tree node. Each entry is itself a
** list, containing the 8-byte rowid/pageno followed by the
** <num-dimension>*2 coordinates.
label: code-design
Find new rows
** A different comparison function for SegReader structures. In this
** version, it is assumed that each SegReader points to an entry in
** a doclist for identical terms. Comparison is made as follows:
**
** 1) EOF (end of doclist in this case) is greater than not EOF.
**
** 2) By current docid.
**
** 3) By segment age. An older segment is considered larger.
Check that a table or index named 'zName' does not already exist
** in database iDb. If so, this is an error.
Leave any error code here
Est. number of rows where key is less than this sample
Effective size of the main journal
** Locate the in-memory structure that describes a particular database
** table given the name of that table and (optionally) the name of the
** database containing the table. Return NULL if not found.
**
** If zDatabase is 0, all databases are searched for the table and the
** first matching table is returned. (No checking for duplicate table
** names is done.) The search order is TEMP first, then MAIN, then any
** auxiliary databases added using the ATTACH command.
**
** See also sqlite3LocateTable().
The VDBE cursor used to access the table
seltablist ::= stl_prefix LP select RP as on_opt using_opt
Reader object
No encoding change
** Move the current position of the file handle passed as the first
** argument to offset iOffset within the file. If successful, return 0.
** Otherwise, set pFile->lastErrno and return non-zero.
Number of pages in the database
expr ::= expr NOT expr
** Generate VDBE code for the statements inside the body of a single
** trigger.
allocated even if there is no FROM clause
comment:
** Helper function for sqlite3Error() - called rarely. Broken out into
** a separate routine to avoid unnecessary register saves on entry to
** sqlite3Error().
label: code-design
** json_set(JSON, PATH, VALUE, ...)
**
** Set the value at PATH to VALUE. Create the PATH if it does not already
** exist. Overwrite existing values that do exist.
** If JSON or PATH is malformed, throw an error.
**
** json_insert(JSON, PATH, VALUE, ...)
**
** Create PATH and initialize it to VALUE. If PATH already exists, this
** routine is a no-op. If JSON or PATH is malformed, throw an error.
For a single-column UNIQUE index, once we have found a non-NULL
** row, we know that all the rest will be distinct, so skip
** subsequent distinctness tests.
pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
** normal rowid tables. nPkField is the number of key fields in the
** pPk index or 1 for a rowid table. In other words, nPkField is the
** number of fields in the true primary key of the table.
** Read a 64-bit variable-length integer from memory starting at p[0].
** Return the number of bytes read. The value is stored in *v.
If successful, populate the output variables. Otherwise, zero them and
** free any allocation made. An error code will be returned in this case.
** Routines to implement the count() aggregate function.
Current table
Allocate and initialize space for aTo, aFrom and aSortCost[]
** Return non-zero if the table pTab in database iDb or any of its indices
** have been opened at any point in the VDBE program. This is used to see if
** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
** run without using a temporary table for the results of the SELECT.
Previous row data is stored here
no, really unlock.
nArg
Source of new entry objects
caller will handle out of memory
** If the RBU database contains the rbu_count table, use it to initialize
** the sqlite3rbu.nPhaseOneStep variable. The schema of the rbu_count table
** is assumed to contain the same columns as:
**
** CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
**
** There should be one row in the table for each data_xxx table in the
** database. The 'tbl' column should contain the name of a data_xxx table,
** and the cnt column the number of rows it contains.
**
** sqlite3rbu.nPhaseOneStep is initialized to the sum of (1 + nIndex) * cnt
** for all rows in the rbu_count table, where nIndex is the number of
** indexes on the corresponding target database table.
Used by: collation_list
Largest possible freeblock offset
The following state variables are used as part of the incremental
** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
** function rbuSetupCheckpoint() for details.
Size of buffer pRec in bytes
Array of overflow page numbers
************* End of alter.c **********************************************
Maximum NNN value for this transform
OUT: error message
The next page to be freed
comment:
** 2003 September 6
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This is the header file for information that is private to the
** VDBE. This information used to all be at the top of the single
** source code file "vdbe.c". When that file became too big (over
** 6000 lines long) it was split up into several smaller files and
** this header information was factored out.
label: code-design
.pScopyFrom =
Number of db changes made since last reset
comment:
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file. The
** arguments specify the block of memory to manage.
**
** This routine is only called by sqlite3_config(), and therefore
** is not required to be threadsafe (it is not).
label: code-design
SQL statement for the OP_SqlExec opcode
First 8 bytes will be zeroed
** Advance a stmt_cursor to its next row of output.
** An object of this type contains the state required to create or append
** to an appendable b-tree segment.
Case 1: The table is a virtual-table. Use the VFilter and VNext
** to access the data.
Non-zero if this is a v-tab with an xRename()
** Perform a read or write operation on a blob
** A bit in a Bitmask
** iMaster is the index of the master chunk. Most new allocations
** occur off of this chunk. szMaster is the size (in Mem3Blocks)
** of the current master. iMaster is 0 if there is not master chunk.
** The master chunk is not in either the aiHash[] or aiSmall[].
Set the new 'max-root-page' value in the database header. This
** is the old value less one, less one more if that happens to
** be a root-page number, less one again if that is the
** PENDING_BYTE_PAGE.
create a new path by replace the trailing '-conch' with '-break'
If the cursor does not yet have a statement handle, obtain one now.
** This macro is used inside of assert() statements to indicate that
** the assert is only valid on a well-formed database. Instead of:
**
** assert( X );
**
** One writes:
**
** assert( X || CORRUPT_DB );
**
** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate
** that the database is definitely corrupt, only that it might be corrupt.
** For most test cases, CORRUPT_DB is set to false using a special
** sqlite3_test_control(). This enables assert() statements to prove
** things that are always true for well-formed databases.
290
** Return true if the Mem object contains a TEXT or BLOB that is
** too large - whose size exceeds SQLITE_MAX_LENGTH.
** Copy the current sorter key into the memory cell pOut.
Number of hash collisions
Resolve the column names in all the expressions in the
** WHERE clause.
** current_date()
**
** This function returns the same value as date('now').
** Deprecated external interface. It used to set an alarm callback
** that was invoked when memory usage grew too large. Now it is a
** no-op.
** Advance iterator pIter to the next entry.
**
** This version of fts5SegIterNext() is only used if detail=none and the
** iterator is not a reverse direction iterator.
** Make sure we can call this stuff from C++.
************* Include sqlite3.h in the middle of sqliteInt.h **************
COLUMN
************* Begin file mutex_w32.c **************************************
Handle for sqlite3DbMallocZero() (may be null)
same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2]
The SHM file is readonly
True if table b-trees. False for index b-trees
Number of matching table names
Columns in zFrom.zTbl
Btree cursor used for pTab
A buffer to hold the data for the new record
d0..d7 ........
** Set the collating sequence for expression pExpr to be the collating
** sequence named by pToken. Return a pointer to a new Expr node that
** implements the COLLATE operator.
**
** If a memory allocation error occurs, that fact is recorded in pParse->db
** and the pExpr parameter is returned unchanged.
31
IMPLEMENTATION-OF: R-61436-13639 If the argument N is negative, then
** the number of cache pages is adjusted to use approximately abs(N*1024)
** bytes of memory.
space allocated at zToken
Race condition here: Another process might have been holding the
** the RESERVED lock and have a journal open at the sqlite3OsAccess()
** call above, but then delete the journal and drop the lock before
** we get to the following sqlite3OsCheckReservedLock() call. If that
** is the case, this routine might think there is a hot journal when
** in fact there is none. This results in a false-positive which will
** be dealt with by the playback routine. Ticket #3883.
comment: The GCC_VERSION and MSVC_VERSION macros are used to
** conditionally include optimizations for each of these compilers. A
** value of 0 means that compiler is not being used. The
** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
** optimizations, and hence set all compiler macros to 0
**
** There was once also a CLANG_VERSION macro. However, we learn that the
** version numbers in clang are for "marketing" only and are inconsistent
** and unreliable. Fortunately, all versions of clang also recognize the
** gcc version numbers and have reasonable settings for gcc version numbers,
** so the GCC_VERSION macro will be set to a correct non-zero value even
** when compiling with clang.
label: code-design
Zero or more UNIXFILE_* values
Template WhereLoop
Session object that owns pTab
Mask of inner loops
Opcode: OpenAutoindex P1 P2 * P4 *
** Synopsis: nColumn=P2
**
** This opcode works the same as OP_OpenEphemeral. It has a
** different name to distinguish its use. Tables created using
** by this opcode will be used for automatically created transient
** indices in joins.
Error message if rc!=SQLITE_OK
Next database page to write
Do not try to use skip-scan if true
A connection to shared-memory
synopsis: intkey=P3 data=r[P2]
True if the table is not BTREE_UNORDERED
"x IN (SELECT ...)": TUNING: the SELECT returns 25 rows
Trying to read or write past the end of the data is an error. The
** conditional above is really:
** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize]
** but is recast into its current form to avoid integer overflow problems
If the LIMIT is less than or equal to zero, loop forever. This
** is documented. But also, if the LIMIT+OFFSET exceeds 2^63 then
** also loop forever. This is undocumented. In fact, one could argue
** that the loop should terminate. But assuming 1 billion iterations
** per second (far exceeding the capabilities of any current hardware)
** it would take nearly 300 years to actually reach the limit. So
** looping forever is a reasonable approximation.
************* End of sqlite3rbu.h *****************************************
1080
Step 2.
We failed long ago if this is not so
sqlite3_step() has finished executing
Opcode: IdxLT P1 P2 P3 P4 P5
** Synopsis: key=r[P3@P4]
**
** The P4 register values beginning with P3 form an unpacked index
** key that omits the PRIMARY KEY or ROWID. Compare this key value against
** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
** ROWID on the P1 index.
**
** If the P1 index entry is less than the key value then jump to P2.
** Otherwise fall through to the next instruction.
If an xFilter() callback was specified, invoke it now. If the
** xFilter callback returns zero, skip this table. If it returns
** non-zero, proceed.
**************************************************************************
** Routines with file scope above. Interface to the rest of the where.c
** subsystem follows.
**************************************************************************
The check expression
One or more tables used to resolve names
See ticket [98d973b8f5]
setlist ::= setlist COMMA LP idlist RP EQ expr
Temp register to free before returning
** Streaming versions of changegroup_output().
************* Begin file fkey.c *******************************************
** Report the allocated size of a prior return from xMalloc()
** or xRealloc().
Total number of bytes on a page
WHERE
** Delete a "ascii" tokenizer.
Value might be numeric
comment:
** The %_segments table is declared as follows:
**
** CREATE TABLE %_segments(blockid INTEGER PRIMARY KEY, block BLOB)
**
** This function reads data from a single row of the %_segments table. The
** specific row is identified by the iBlockid parameter. If paBlob is not
** NULL, then a buffer is allocated using sqlite3_malloc() and populated
** with the contents of the blob stored in the "block" column of the
** identified table row is. Whether or not paBlob is NULL, *pnBlob is set
** to the size of the blob in bytes before returning.
**
** If an error occurs, or the table does not contain the specified row,
** an SQLite error code is returned. Otherwise, SQLITE_OK is returned. If
** paBlob is non-NULL, then it is the responsibility of the caller to
** eventually free the returned buffer.
**
** This function may leave an open sqlite3_blob* handle in the
** Fts3Table.pSegments variable. This handle is reused by subsequent calls
** to this function. The handle may be closed by calling the
** sqlite3Fts3SegmentsClose() function. Reusing a blob handle is a handy
** performance improvement, but the blob handle should always be closed
** before control is returned to the user (to prevent a lock being held
** on the database file for longer than necessary). Thus, any virtual table
** method (xFilter etc.) that may directly or indirectly call this function
** must call sqlite3Fts3SegmentsClose() before returning.
label: code-design
Length of zInput in bytes
xBestIndex
True for DESC. False for ASC.
Indicates a pending lock has been obtained
Low accuracy coordinate
Rowid argument passed to stat_push()
Used to set error string on failure.
Hash table representation
Foreign key support may not be enabled or disabled while not
** in auto-commit mode.
Max leading 0 in anEq[] for any a[] entry
The "x IN (SELECT rowid FROM table)" case
Size of the cell being deleted
If there are outstanding locks, do not actually close the file just
** yet because that would clear those locks. Instead, add the file
** descriptor to pInode->aPending. It will be automatically closed when
** the last lock is cleared.
comment:
** This object contains information needed to implement a single nested
** loop in WHERE clause.
**
** Contrast this object with WhereLoop. This object describes the
** implementation of the loop. WhereLoop describes the algorithm.
** This object contains a pointer to the WhereLoop algorithm as one of
** its elements.
**
** The WhereInfo object contains a single instance of this object for
** each term in the FROM clause (which is to say, for each of the
** nested loops as implemented). The order of WhereLevel objects determines
** the loop nested order, with WhereInfo.a[0] being the outer loop and
** WhereInfo.a[WhereInfo.nLevel-1] being the inner loop.
label: code-design
WHERE clause to scan with
********** Begin %parse_accept code ****************************************
comment: Not needed. Silence a compiler warning.
label: requirement
aKWLen[i] is the length (in bytes) of the i-th keyword
Execute the recursive SELECT taking the single row in Current as
** the value for the recursive-table. Store the results in the Queue.
** Memory available for allocation
The request was for a RESERVED or EXCLUSIVE lock. It is
** assumed that there is a SHARED or greater lock on the file
** already.
Name of the function. zero-terminated
** If compiling for a processor that lacks floating point support,
** substitute integer for floating-point.
** CAPI3REF: Test For Auto-Commit Mode
** KEYWORDS: {autocommit mode}
** METHOD: sqlite3
**
** ^The sqlite3_get_autocommit() interface returns non-zero or
** zero if the given database connection is or is not in autocommit mode,
** respectively. ^Autocommit mode is on by default.
** ^Autocommit mode is disabled by a [BEGIN] statement.
** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
**
** If certain kinds of errors occur on a statement within a multi-statement
** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
** transaction might be rolled back automatically. The only way to
** find out whether SQLite automatically rolled back the transaction after
** an error is to use this function.
**
** If another thread changes the autocommit status of the database
** connection while this routine is running, then the return value
** is undefined.
** CAPI3REF: Retrieve the mutex for a database connection
** METHOD: sqlite3
**
** ^This interface returns a pointer the [sqlite3_mutex] object that
** serializes access to the [database connection] given in the argument
** when the [threading mode] is Serialized.
** ^If the [threading mode] is Single-thread or Multi-thread then this
** routine returns a NULL pointer.
Object completely outside of query region
comment:
** CAPI3REF: Setting The Result Of An SQL Function
** METHOD: sqlite3_context
**
** These routines are used by the xFunc or xFinal callbacks that
** implement SQL functions and aggregates. See
** [sqlite3_create_function()] and [sqlite3_create_function16()]
** for additional information.
**
** These functions work very much like the [parameter binding] family of
** functions used to bind values to host parameters in prepared statements.
** Refer to the [SQL parameter] documentation for additional information.
**
** ^The sqlite3_result_blob() interface sets the result from
** an application-defined function to be the BLOB whose content is pointed
** to by the second parameter and which is N bytes long where N is the
** third parameter.
**
** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
** interfaces set the result of the application-defined function to be
** a BLOB containing all zero bytes and N bytes in size.
**
** ^The sqlite3_result_double() interface sets the result from
** an application-defined function to be a floating point value specified
** by its 2nd argument.
**
** ^The sqlite3_result_error() and sqlite3_result_error16() functions
** cause the implemented SQL function to throw an exception.
** ^SQLite uses the string pointed to by the
** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
** as the text of an error message. ^SQLite interprets the error
** message string from sqlite3_result_error() as UTF-8. ^SQLite
** interprets the string from sqlite3_result_error16() as UTF-16 in native
** byte order. ^If the third parameter to sqlite3_result_error()
** or sqlite3_result_error16() is negative then SQLite takes as the error
** message all text up through the first zero character.
** ^If the third parameter to sqlite3_result_error() or
** sqlite3_result_error16() is non-negative then SQLite takes that many
** bytes (not characters) from the 2nd parameter as the error message.
** ^The sqlite3_result_error() and sqlite3_result_error16()
** routines make a private copy of the error message text before
** they return. Hence, the calling function can deallocate or
** modify the text after they return without harm.
** ^The sqlite3_result_error_code() function changes the error code
** returned by SQLite as a result of an error in a function. ^By default,
** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
**
** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
** error indicating that a string or BLOB is too long to represent.
**
** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
** error indicating that a memory allocation failed.
**
** ^The sqlite3_result_int() interface sets the return value
** of the application-defined function to be the 32-bit signed integer
** value given in the 2nd argument.
** ^The sqlite3_result_int64() interface sets the return value
** of the application-defined function to be the 64-bit signed integer
** value given in the 2nd argument.
**
** ^The sqlite3_result_null() interface sets the return value
** of the application-defined function to be NULL.
**
** ^The sqlite3_result_text(), sqlite3_result_text16(),
** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
** set the return value of the application-defined function to be
** a text string which is represented as UTF-8, UTF-16 native byte order,
** UTF-16 little endian, or UTF-16 big endian, respectively.
** ^The sqlite3_result_text64() interface sets the return value of an
** application-defined function to be a text string in an encoding
** specified by the fifth (and last) parameter, which must be one
** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
** ^SQLite takes the text result from the application from
** the 2nd parameter of the sqlite3_result_text* interfaces.
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
** is negative, then SQLite takes result text from the 2nd parameter
** through the first zero character.
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
** is non-negative, then as many bytes (not characters) of the text
** pointed to by the 2nd parameter are taken as the application-defined
** function result. If the 3rd parameter is non-negative, then it
** must be the byte offset into the string where the NUL terminator would
** appear if the string where NUL terminated. If any NUL characters occur
** in the string at a byte offset that is less than the value of the 3rd
** parameter, then the resulting string will contain embedded NULs and the
** result of expressions operating on strings with embedded NULs is undefined.
** ^If the 4th parameter to the sqlite3_result_text* interfaces
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
** function as the destructor on the text or BLOB result when it has
** finished using that result.
** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
** assumes that the text or BLOB result is in constant space and does not
** copy the content of the parameter nor call a destructor on the content
** when it has finished using that result.
** ^If the 4th parameter to the sqlite3_result_text* interfaces
** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
** then SQLite makes a copy of the result into space obtained
** from [sqlite3_malloc()] before it returns.
**
** ^The sqlite3_result_value() interface sets the result of
** the application-defined function to be a copy of the
** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
** so that the [sqlite3_value] specified in the parameter may change or
** be deallocated after sqlite3_result_value() returns without harm.
** ^A [protected sqlite3_value] object may always be used where an
** [unprotected sqlite3_value] object is required, so either
** kind of [sqlite3_value] object can be used with this interface.
**
** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
** SQL NULL value, just like [sqlite3_result_null(C)], except that it
** also associates the host-language pointer P or type T with that
** NULL value such that the pointer can be retrieved within an
** [application-defined SQL function] using [sqlite3_value_pointer()].
** ^If the D parameter is not NULL, then it is a pointer to a destructor
** for the P parameter. ^SQLite invokes D with P as its only argument
** when SQLite is finished with P. The T parameter should be a static
** string and preferably a string literal. The sqlite3_result_pointer()
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
**
** If these routines are called from within the different thread
** than the one containing the application-defined function that received
** the [sqlite3_context] pointer, the results are undefined.
label: code-design
** CAPI3REF: OS Interface Open File Handle
**
** An [sqlite3_file] object represents an open file in the
** [sqlite3_vfs | OS interface layer]. Individual OS interface
** implementations will
** want to subclass this object by appending additional fields
** for their own use. The pMethods entry is a pointer to an
** [sqlite3_io_methods] object that defines methods for performing
** I/O operations on the open file.
comment:
** EXTENSION API FUNCTIONS
**
** xUserData(pFts):
** Return a copy of the context pointer the extension function was
** registered with.
**
** xColumnTotalSize(pFts, iCol, pnToken):
** If parameter iCol is less than zero, set output variable *pnToken
** to the total number of tokens in the FTS5 table. Or, if iCol is
** non-negative but less than the number of columns in the table, return
** the total number of tokens in column iCol, considering all rows in
** the FTS5 table.
**
** If parameter iCol is greater than or equal to the number of columns
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
** an OOM condition or IO error), an appropriate SQLite error code is
** returned.
**
** xColumnCount(pFts):
** Return the number of columns in the table.
**
** xColumnSize(pFts, iCol, pnToken):
** If parameter iCol is less than zero, set output variable *pnToken
** to the total number of tokens in the current row. Or, if iCol is
** non-negative but less than the number of columns in the table, set
** *pnToken to the number of tokens in column iCol of the current row.
**
** If parameter iCol is greater than or equal to the number of columns
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
** an OOM condition or IO error), an appropriate SQLite error code is
** returned.
**
** This function may be quite inefficient if used with an FTS5 table
** created with the "columnsize=0" option.
**
** xColumnText:
** This function attempts to retrieve the text of column iCol of the
** current document. If successful, (*pz) is set to point to a buffer
** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
** if an error occurs, an SQLite error code is returned and the final values
** of (*pz) and (*pn) are undefined.
**
** xPhraseCount:
** Returns the number of phrases in the current query expression.
**
** xPhraseSize:
** Returns the number of tokens in phrase iPhrase of the query. Phrases
** are numbered starting from zero.
**
** xInstCount:
** Set *pnInst to the total number of occurrences of all phrases within
** the query within the current row. Return SQLITE_OK if successful, or
** an error code (i.e. SQLITE_NOMEM) if an error occurs.
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option. If the FTS5 table is created
** with either "detail=none" or "detail=column" and "content=" option
** (i.e. if it is a contentless table), then this API always returns 0.
**
** xInst:
** Query for the details of phrase match iIdx within the current row.
** Phrase matches are numbered starting from zero, so the iIdx argument
** should be greater than or equal to zero and smaller than the value
** output by xInstCount().
**
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
** to the column in which it occurs and *piOff the token offset of the
** first token of the phrase. The exception is if the table was created
** with the offsets=0 option specified. In this case *piOff is always
** set to -1.
**
** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
** if an error occurs.
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option.
**
** xRowid:
** Returns the rowid of the current row.
**
** xTokenize:
** Tokenize text using the tokenizer belonging to the FTS5 table.
**
** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
** This API function is used to query the FTS table for phrase iPhrase
** of the current query. Specifically, a query equivalent to:
**
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
**
** with $p set to a phrase equivalent to the phrase iPhrase of the
** current query is executed. Any column filter that applies to
** phrase iPhrase of the current query is included in $p. For each
** row visited, the callback function passed as the fourth argument
** is invoked. The context and API objects passed to the callback
** function may be used to access the properties of each matched row.
** Invoking Api.xUserData() returns a copy of the pointer passed as
** the third argument to pUserData.
**
** If the callback function returns any value other than SQLITE_OK, the
** query is abandoned and the xQueryPhrase function returns immediately.
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
** Otherwise, the error code is propagated upwards.
**
** If the query runs to completion without incident, SQLITE_OK is returned.
** Or, if some error occurs before the query completes or is aborted by
** the callback, an SQLite error code is returned.
**
**
** xSetAuxdata(pFts5, pAux, xDelete)
**
** Save the pointer passed as the second argument as the extension functions
** "auxiliary data". The pointer may then be retrieved by the current or any
** future invocation of the same fts5 extension function made as part of
** of the same MATCH query using the xGetAuxdata() API.
**
** Each extension function is allocated a single auxiliary data slot for
** each FTS query (MATCH expression). If the extension function is invoked
** more than once for a single FTS query, then all invocations share a
** single auxiliary data context.
**
** If there is already an auxiliary data pointer when this function is
** invoked, then it is replaced by the new pointer. If an xDelete callback
** was specified along with the original pointer, it is invoked at this
** point.
**
** The xDelete callback, if one is specified, is also invoked on the
** auxiliary data pointer after the FTS5 query has finished.
**
** If an error (e.g. an OOM condition) occurs within this function, an
** the auxiliary data is set to NULL and an error code returned. If the
** xDelete parameter was not NULL, it is invoked on the auxiliary data
** pointer before returning.
**
**
** xGetAuxdata(pFts5, bClear)
**
** Returns the current auxiliary data pointer for the fts5 extension
** function. See the xSetAuxdata() method for details.
**
** If the bClear argument is non-zero, then the auxiliary data is cleared
** (set to NULL) before this function returns. In this case the xDelete,
** if any, is not invoked.
**
**
** xRowCount(pFts5, pnRow)
**
** This function is used to retrieve the total number of rows in the table.
** In other words, the same value that would be returned by:
**
** SELECT count(*) FROM ftstable;
**
** xPhraseFirst()
** This function is used, along with type Fts5PhraseIter and the xPhraseNext
** method, to iterate through all instances of a single query phrase within
** the current row. This is the same information as is accessible via the
** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
** to use, this API may be faster under some circumstances. To iterate
** through instances of phrase iPhrase, use the following code:
**
** Fts5PhraseIter iter;
** int iCol, iOff;
** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
** iCol>=0;
** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
** ){
** // An instance of phrase iPhrase at offset iOff of column iCol
** }
**
** The Fts5PhraseIter structure is defined above. Applications should not
** modify this structure directly - it should only be used as shown above
** with the xPhraseFirst() and xPhraseNext() API methods (and by
** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" or "detail=column" option. If the FTS5 table is created
** with either "detail=none" or "detail=column" and "content=" option
** (i.e. if it is a contentless table), then this API always iterates
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
**
** xPhraseNext()
** See xPhraseFirst above.
**
** xPhraseFirstColumn()
** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
** and xPhraseNext() APIs described above. The difference is that instead
** of iterating through all instances of a phrase in the current row, these
** APIs are used to iterate through the set of columns in the current row
** that contain one or more instances of a specified phrase. For example:
**
** Fts5PhraseIter iter;
** int iCol;
** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
** iCol>=0;
** pApi->xPhraseNextColumn(pFts, &iter, &iCol)
** ){
** // Column iCol contains at least one instance of phrase iPhrase
** }
**
** This API can be quite slow if used with an FTS5 table created with the
** "detail=none" option. If the FTS5 table is created with either
** "detail=none" "content=" option (i.e. if it is a contentless table),
** then this API always iterates through an empty set (all calls to
** xPhraseFirstColumn() set iCol to -1).
**
** The information accessed using this API and its companion
** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
** (or xInst/xInstCount). The chief advantage of this API is that it is
** significantly more efficient than those alternatives when used with
** "detail=column" tables.
**
** xPhraseNextColumn()
** See xPhraseFirstColumn above.
label: code-design
Methods above are valid for version 2
int
Source database name
Pointer to application-specific data
** CAPI3REF: Obtaining SQL Values
** METHOD: sqlite3_value
**
** <b>Summary:</b>
** <blockquote><table border=0 cellpadding=0 cellspacing=0>
** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value
** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value
** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value
** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value
** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value
** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value
** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in
** the native byteorder
** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value
** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value
** <tr><td> <td> <td>
** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB
** or a UTF-8 TEXT in bytes
** <tr><td><b>sqlite3_value_bytes16 </b>
** <td>→ <td>Size of UTF-16
** TEXT in bytes
** <tr><td><b>sqlite3_value_type</b><td>→<td>Default
** datatype of the value
** <tr><td><b>sqlite3_value_numeric_type </b>
** <td>→ <td>Best numeric datatype of the value
** </table></blockquote>
**
** <b>Details:</b>
**
** These routines extract type, size, and content information from
** [protected sqlite3_value] objects. Protected sqlite3_value objects
** are used to pass parameter information into implementation of
** [application-defined SQL functions] and [virtual tables].
**
** These routines work only with [protected sqlite3_value] objects.
** Any attempt to use these routines on an [unprotected sqlite3_value]
** is not threadsafe.
**
** ^These routines work just like the corresponding [column access functions]
** except that these routines take a single [protected sqlite3_value] object
** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
**
** ^The sqlite3_value_text16() interface extracts a UTF-16 string
** in the native byte-order of the host machine. ^The
** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
** extract UTF-16 strings as big-endian and little-endian respectively.
**
** ^If [sqlite3_value] object V was initialized
** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
** and if X and Y are strings that compare equal according to strcmp(X,Y),
** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,
** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
**
** ^(The sqlite3_value_type(V) interface returns the
** [SQLITE_INTEGER | datatype code] for the initial datatype of the
** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
** Other interfaces might change the datatype for an sqlite3_value object.
** For example, if the datatype is initially SQLITE_INTEGER and
** sqlite3_value_text(V) is called to extract a text value for that
** integer, then subsequent calls to sqlite3_value_type(V) might return
** SQLITE_TEXT. Whether or not a persistent internal datatype conversion
** occurs is undefined and may change from one release of SQLite to the next.
**
** ^(The sqlite3_value_numeric_type() interface attempts to apply
** numeric affinity to the value. This means that an attempt is
** made to convert the value to an integer or floating point. If
** such a conversion is possible without loss of information (in other
** words, if the value is a string that looks like a number)
** then the conversion is performed. Otherwise no conversion occurs.
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
**
** Please pay particular attention to the fact that the pointer returned
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
** or [sqlite3_value_text16()].
**
** These routines must be called from the same thread as
** the SQL function that supplied the [sqlite3_value*] parameters.
** CAPI3REF: Extract Metadata About A Column Of A Table
** METHOD: sqlite3
**
** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
** information about column C of table T in database D
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
** interface returns SQLITE_OK and fills in the non-NULL pointers in
** the final five arguments with appropriate values if the specified
** column exists. ^The sqlite3_table_column_metadata() interface returns
** SQLITE_ERROR and if the specified column does not exist.
** ^If the column-name parameter to sqlite3_table_column_metadata() is a
** NULL pointer, then this routine simply checks for the existence of the
** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
** does not. If the table name parameter T in a call to
** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
** undefined behavior.
**
** ^The column is identified by the second, third and fourth parameters to
** this function. ^(The second parameter is either the name of the database
** (i.e. "main", "temp", or an attached database) containing the specified
** table or NULL.)^ ^If it is NULL, then all attached databases are searched
** for the table using the same algorithm used by the database engine to
** resolve unqualified table references.
**
** ^The third and fourth parameters to this function are the table and column
** name of the desired column, respectively.
**
** ^Metadata is returned by writing to the memory locations passed as the 5th
** and subsequent parameters to this function. ^Any of these arguments may be
** NULL, in which case the corresponding element of metadata is omitted.
**
** ^(<blockquote>
** <table border="1">
** <tr><th> Parameter <th> Output<br>Type <th> Description
**
** <tr><td> 5th <td> const char* <td> Data type
** <tr><td> 6th <td> const char* <td> Name of default collation sequence
** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
** </table>
** </blockquote>)^
**
** ^The memory pointed to by the character pointers returned for the
** declaration type and collation sequence is valid until the next
** call to any SQLite API function.
**
** ^If the specified table is actually a view, an [error code] is returned.
**
** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
** is not a [WITHOUT ROWID] table and an
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
** parameters are set for the explicitly declared column. ^(If there is no
** [INTEGER PRIMARY KEY] column, then the outputs
** for the [rowid] are set as follows:
**
** <pre>
** data type: "INTEGER"
** collation sequence: "BINARY"
** not null: 0
** primary key: 1
** auto increment: 0
** </pre>)^
**
** ^This function causes all database schemas to be read from disk and
** parsed, if that has not already been done, and returns an error if
** any errors are encountered while loading the schema.
** CAPI3REF: Test if a changeset has recorded any changes.
**
** Return non-zero if no changes to attached tables have been recorded by
** the session object passed as the first argument. Otherwise, if one or
** more changes have been recorded, return zero.
**
** Even if this function returns zero, it is possible that calling
** [sqlite3session_changeset()] on the session handle may still return a
** changeset that contains no changes. This can happen when a row in
** an attached table is modified and then later on the original values
** are restored. However, if this function returns non-zero, then it is
** guaranteed that a call to sqlite3session_changeset() will return a
** changeset containing zero changes.
int *psz
** CAPI3REF: Text Encodings
**
** These constant define integer codes that represent the various
** text encodings supported by SQLite.
** CAPI3REF: Evaluate An SQL Statement
** METHOD: sqlite3_stmt
**
** After a [prepared statement] has been prepared using any of
** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
** or [sqlite3_prepare16_v3()] or one of the legacy
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
** must be called one or more times to evaluate the statement.
**
** The details of the behavior of the sqlite3_step() interface depend
** on whether the statement was prepared using the newer "vX" interfaces
** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
** [sqlite3_prepare16_v2()] or the older legacy
** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
** new "vX" interface is recommended for new applications but the legacy
** interface will continue to be supported.
**
** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
** ^With the "v2" interface, any of the other [result codes] or
** [extended result codes] might be returned as well.
**
** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
** database locks it needs to do its job. ^If the statement is a [COMMIT]
** or occurs outside of an explicit transaction, then you can retry the
** statement. If the statement is not a [COMMIT] and occurs within an
** explicit transaction then you should rollback the transaction before
** continuing.
**
** ^[SQLITE_DONE] means that the statement has finished executing
** successfully. sqlite3_step() should not be called again on this virtual
** machine without first calling [sqlite3_reset()] to reset the virtual
** machine back to its initial state.
**
** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
** is returned each time a new row of data is ready for processing by the
** caller. The values may be accessed using the [column access functions].
** sqlite3_step() is called again to retrieve the next row of data.
**
** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
** violation) has occurred. sqlite3_step() should not be called again on
** the VM. More information may be found by calling [sqlite3_errmsg()].
** ^With the legacy interface, a more specific error code (for example,
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
** can be obtained by calling [sqlite3_reset()] on the
** [prepared statement]. ^In the "v2" interface,
** the more specific error code is returned directly by sqlite3_step().
**
** [SQLITE_MISUSE] means that the this routine was called inappropriately.
** Perhaps it was called on a [prepared statement] that has
** already been [sqlite3_finalize | finalized] or on one that had
** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
** be the case that the same database connection is being used by two or
** more threads at the same moment in time.
**
** For all versions of SQLite up to and including 3.6.23.1, a call to
** [sqlite3_reset()] was required after sqlite3_step() returned anything
** other than [SQLITE_ROW] before any subsequent invocation of
** sqlite3_step(). Failure to reset the prepared statement using
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
** sqlite3_step() began
** calling [sqlite3_reset()] automatically in this circumstance rather
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
** break because any application that ever receives an SQLITE_MISUSE error
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
** can be used to restore the legacy behavior.
**
** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
** API always returns a generic error code, [SQLITE_ERROR], following any
** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
** specific [error codes] that better describes the error.
** We admit that this is a goofy design. The problem has been fixed
** with the "v2" interface. If you prepare all of your SQL statements
** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
** then the more specific [error codes] are returned directly
** by sqlite3_step(). The use of the "vX" interfaces is recommended.
** CAPI3REF: String LIKE Matching
*
** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
** string X matches the [LIKE] pattern P with escape character E.
** ^The definition of [LIKE] pattern matching used in
** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without
** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
** insensitive - equivalent upper and lower case ASCII characters match
** one another.
**
** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
** only ASCII characters are case folded.
**
** Note that this routine returns zero on a match and non-zero if the strings
** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
**
** See also: [sqlite3_strglob()].
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
Database lock protocol error
** CAPI3REF: Checkpoint a database
** METHOD: sqlite3
**
** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
** operation on database X of [database connection] D in mode M. Status
** information is written back into integers pointed to by L and C.)^
** ^(The M parameter must be a valid [checkpoint mode]:)^
**
** <dl>
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
** ^Checkpoint as many frames as possible without waiting for any database
** readers or writers to finish, then sync the database file if all frames
** in the log were checkpointed. ^The [busy-handler callback]
** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
** ^On the other hand, passive mode might leave the checkpoint unfinished
** if there are concurrent readers or writers.
**
** <dt>SQLITE_CHECKPOINT_FULL<dd>
** ^This mode blocks (it invokes the
** [sqlite3_busy_handler|busy-handler callback]) until there is no
** database writer and all readers are reading from the most recent database
** snapshot. ^It then checkpoints all frames in the log file and syncs the
** database file. ^This mode blocks new database writers while it is pending,
** but new database readers are allowed to continue unimpeded.
**
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
** that after checkpointing the log file it blocks (calls the
** [busy-handler callback])
** until all readers are reading from the database file only. ^This ensures
** that the next writer will restart the log file from the beginning.
** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
** database writer attempts while it is pending, but does not impede readers.
**
** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
** addition that it also truncates the log file to zero bytes just prior
** to a successful return.
** </dl>
**
** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
** the log file or to -1 if the checkpoint could not run because
** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
** log file (including any that were already checkpointed before the function
** was called) or to -1 if the checkpoint could not run due to an error or
** because the database is not in WAL mode. ^Note that upon successful
** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
**
** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
** any other process is running a checkpoint operation at the same time, the
** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
** busy-handler configured, it will not be invoked in this case.
**
** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
** exclusive "writer" lock on the database file. ^If the writer lock cannot be
** obtained immediately, and a busy-handler is configured, it is invoked and
** the writer lock retried until either the busy-handler returns 0 or the lock
** is successfully obtained. ^The busy-handler is also invoked while waiting for
** database readers as described above. ^If the busy-handler returns 0 before
** the writer lock is obtained or while waiting for database readers, the
** checkpoint operation proceeds from that point in the same way as
** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
** without blocking any further. ^SQLITE_BUSY is returned in this case.
**
** ^If parameter zDb is NULL or points to a zero length string, then the
** specified operation is attempted on all WAL databases [attached] to
** [database connection] db. In this case the
** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
** an SQLITE_BUSY error is encountered when processing one or more of the
** attached WAL databases, the operation is still attempted on any remaining
** attached databases and SQLITE_BUSY is returned at the end. ^If any other
** error occurs while processing an attached database, processing is abandoned
** and the error code is returned to the caller immediately. ^If no error
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
** databases, SQLITE_OK is returned.
**
** ^If database zDb is the name of an attached database that is not in WAL
** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
** zDb is not NULL (or a zero length string) and is not the name of any
** attached database, SQLITE_ERROR is returned to the caller.
**
** ^Unless it returns SQLITE_MISUSE,
** the sqlite3_wal_checkpoint_v2() interface
** sets the error information that is queried by
** [sqlite3_errcode()] and [sqlite3_errmsg()].
**
** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
** from SQL.
** CAPI3REF: Virtual Table Constraint Operator Codes
**
** These macros defined the allowed values for the
** [sqlite3_index_info].aConstraint[].op field. Each value represents
** an operator that is part of a constraint term in the wHERE clause of
** a query that uses a [virtual table].
Unknown opcode in sqlite3_file_control()
sqlite3_pcache_methods2*
** CAPI3REF: Finding The Subtype Of SQL Values
** METHOD: sqlite3_value
**
** The sqlite3_value_subtype(V) function returns the subtype for
** an [application-defined SQL function] argument V. The subtype
** information can be used to pass a limited amount of context from
** one SQL function to another. Use the [sqlite3_result_subtype()]
** routine to set the subtype for the return value of an SQL function.
xFunc, void*
** CAPI3REF: Enable Or Disable Shared Pager Cache
**
** ^(This routine enables or disables the sharing of the database cache
** and schema data structures between [database connection | connections]
** to the same database. Sharing is enabled if the argument is true
** and disabled if the argument is false.)^
**
** ^Cache sharing is enabled and disabled for an entire process.
** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
** In prior versions of SQLite,
** sharing was enabled or disabled for each thread separately.
**
** ^(The cache sharing mode set by this interface effects all subsequent
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
** Existing database connections continue use the sharing mode
** that was in effect at the time they were opened.)^
**
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
** successfully. An [error code] is returned otherwise.)^
**
** ^Shared cache is disabled by default. But this might change in
** future releases of SQLite. Applications that care about shared
** cache setting should set it explicitly.
**
** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
** and will always return SQLITE_MISUSE. On those systems,
** shared cache mode should be enabled per-database connection via
** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
**
** This interface is threadsafe on processors where writing a
** 32-bit integer is atomic.
**
** See Also: [SQLite Shared-Cache Mode]
comment:
** CAPI3REF: Finalize A Changeset Iterator
**
** This function is used to finalize an iterator allocated with
** [sqlite3changeset_start()].
**
** This function should only be called on iterators created using the
** [sqlite3changeset_start()] function. If an application calls this
** function with an iterator passed to a conflict-handler by
** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
** call has no effect.
**
** If an error was encountered within a call to an sqlite3changeset_xxx()
** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
** to that error is returned by this function. Otherwise, SQLITE_OK is
** returned. This is to allow the following pattern (pseudo-code):
**
** sqlite3changeset_start();
** while( SQLITE_ROW==sqlite3changeset_next() ){
** // Do something with change.
** }
** rc = sqlite3changeset_finalize();
** if( rc!=SQLITE_OK ){
** // An error has occurred
** }
label: code-design
End of the 'extern "C"' block
** CAPI3REF: Virtual Table Interface Configuration
**
** This function may be called by either the [xConnect] or [xCreate] method
** of a [virtual table] implementation to configure
** various facets of the virtual table interface.
**
** If this interface is invoked outside the context of an xConnect or
** xCreate virtual table method then the behavior is undefined.
**
** At present, there is only one option that may be configured using
** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
** may be added in the future.
end of the 'extern "C"' block
** CAPI3REF: Cancel Automatic Extension Loading
**
** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
** initialization routine X that was registered using a prior call to
** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
** routine returns 1 if initialization routine X was successfully
** unregistered and it returns 0 if X was not on the list of initialization
** routines.
******* End of sqlite3rtree.h ********
** CAPI3REF: Initialize The SQLite Library
**
** ^The sqlite3_initialize() routine initializes the
** SQLite library. ^The sqlite3_shutdown() routine
** deallocates any resources that were allocated by sqlite3_initialize().
** These routines are designed to aid in process initialization and
** shutdown on embedded systems. Workstation applications using
** SQLite normally do not need to invoke either of these routines.
**
** A call to sqlite3_initialize() is an "effective" call if it is
** the first time sqlite3_initialize() is invoked during the lifetime of
** the process, or if it is the first time sqlite3_initialize() is invoked
** following a call to sqlite3_shutdown(). ^(Only an effective call
** of sqlite3_initialize() does any initialization. All other calls
** are harmless no-ops.)^
**
** A call to sqlite3_shutdown() is an "effective" call if it is the first
** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
** an effective call to sqlite3_shutdown() does any deinitialization.
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
**
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
** is not. The sqlite3_shutdown() interface must only be called from a
** single thread. All open [database connections] must be closed and all
** other SQLite resources must be deallocated prior to invoking
** sqlite3_shutdown().
**
** Among other things, ^sqlite3_initialize() will invoke
** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
** will invoke sqlite3_os_end().
**
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
** ^If for some reason, sqlite3_initialize() is unable to initialize
** the library (perhaps it is unable to allocate a needed resource such
** as a mutex) it returns an [error code] other than [SQLITE_OK].
**
** ^The sqlite3_initialize() routine is called internally by many other
** SQLite interfaces so that an application usually does not need to
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
** calls sqlite3_initialize() so the SQLite library will be automatically
** initialized when [sqlite3_open()] is called if it has not be initialized
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
** compile-time option, then the automatic calls to sqlite3_initialize()
** are omitted and the application must call sqlite3_initialize() directly
** prior to using any other SQLite interface. For maximum portability,
** it is recommended that applications always invoke sqlite3_initialize()
** directly prior to using any other SQLite interface. Future releases
** of SQLite may require this. In other words, the behavior exhibited
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
** default behavior in some future release of SQLite.
**
** The sqlite3_os_init() routine does operating-system specific
** initialization of the SQLite library. The sqlite3_os_end()
** routine undoes the effect of sqlite3_os_init(). Typical tasks
** performed by these routines include allocation or deallocation
** of static resources, initialization of global variables,
** setting up a default [sqlite3_vfs] module, or setting up
** a default configuration using [sqlite3_config()].
**
** The application should never invoke either sqlite3_os_init()
** or sqlite3_os_end() directly. The application should only invoke
** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
** interface is called automatically by sqlite3_initialize() and
** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
** implementations for sqlite3_os_init() and sqlite3_os_end()
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
** When [custom builds | built for other platforms]
** (using the [SQLITE_OS_OTHER=1] compile-time
** option) the application must supply a suitable implementation for
** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
** implementation of sqlite3_os_init() or sqlite3_os_end()
** must return [SQLITE_OK] on success and some other [error code] upon
** failure.
Copy of third arg to preupdate_hook()
Called by SQLite to clean up pUser
** CAPI3REF: Virtual Table Configuration Options
**
** These macros define the various options to the
** [sqlite3_vtab_config()] interface that [virtual table] implementations
** can use to customize and optimize their behavior.
**
** <dl>
** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
** <dd>Calls of the form
** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
** where X is an integer. If X is zero, then the [virtual table] whose
** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
** support constraints. In this configuration (which is the default) if
** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
** specified as part of the users SQL statement, regardless of the actual
** ON CONFLICT mode specified.
**
** If X is non-zero, then the virtual table implementation guarantees
** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
** any modifications to internal or persistent data structures have been made.
** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
** is able to roll back a statement or database transaction, and abandon
** or continue processing the current SQL statement as appropriate.
** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
** had been ABORT.
**
** Virtual table implementations that are required to handle OR REPLACE
** must do so within the [xUpdate] method. If a call to the
** [sqlite3_vtab_on_conflict()] function indicates that the current ON
** CONFLICT policy is REPLACE, the virtual table implementation should
** silently replace the appropriate rows within the xUpdate callback and
** return SQLITE_OK. Or, if this is not possible, it may return
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
** constraint handling.
** </dl>
comment:
** CAPI3REF: Low-Level Control Of Database Files
** METHOD: sqlite3
**
** ^The [sqlite3_file_control()] interface makes a direct call to the
** xFileControl method for the [sqlite3_io_methods] object associated
** with a particular database identified by the second argument. ^The
** name of the database is "main" for the main database or "temp" for the
** TEMP database, or the name that appears after the AS keyword for
** databases that are added using the [ATTACH] SQL command.
** ^A NULL pointer can be used in place of "main" to refer to the
** main database file.
** ^The third and fourth parameters to this routine
** are passed directly through to the second and third parameters of
** the xFileControl method. ^The return value of the xFileControl
** method becomes the return value of this routine.
**
** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
** a pointer to the underlying [sqlite3_file] object to be written into
** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER
** case is a short-circuit path which does not actually invoke the
** underlying sqlite3_io_methods.xFileControl method.
**
** ^If the second parameter (zDbName) does not match the name of any
** open database file, then SQLITE_ERROR is returned. ^This error
** code is not remembered and will not be recalled by [sqlite3_errcode()]
** or [sqlite3_errmsg()]. The underlying xFileControl method might
** also return SQLITE_ERROR. There is no way to distinguish between
** an incorrect zDbName and an SQLITE_ERROR return from the underlying
** xFileControl method.
**
** See also: [SQLITE_FCNTL_LOCKSTATE]
label: code-design
comment: ************************************************************************
** CUSTOM TOKENIZERS
**
** Applications may also register custom tokenizer types. A tokenizer
** is registered by providing fts5 with a populated instance of the
** following structure. All structure methods must be defined, setting
** any member of the fts5_tokenizer struct to NULL leads to undefined
** behaviour. The structure methods are expected to function as follows:
**
** xCreate:
** This function is used to allocate and initialize a tokenizer instance.
** A tokenizer instance is required to actually tokenize text.
**
** The first argument passed to this function is a copy of the (void*)
** pointer provided by the application when the fts5_tokenizer object
** was registered with FTS5 (the third argument to xCreateTokenizer()).
** The second and third arguments are an array of nul-terminated strings
** containing the tokenizer arguments, if any, specified following the
** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
** to create the FTS5 table.
**
** The final argument is an output variable. If successful, (*ppOut)
** should be set to point to the new tokenizer handle and SQLITE_OK
** returned. If an error occurs, some value other than SQLITE_OK should
** be returned. In this case, fts5 assumes that the final value of *ppOut
** is undefined.
**
** xDelete:
** This function is invoked to delete a tokenizer handle previously
** allocated using xCreate(). Fts5 guarantees that this function will
** be invoked exactly once for each successful call to xCreate().
**
** xTokenize:
** This function is expected to tokenize the nText byte string indicated
** by argument pText. pText may or may not be nul-terminated. The first
** argument passed to this function is a pointer to an Fts5Tokenizer object
** returned by an earlier call to xCreate().
**
** The second argument indicates the reason that FTS5 is requesting
** tokenization of the supplied text. This is always one of the following
** four values:
**
** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
** or removed from the FTS table. The tokenizer is being invoked to
** determine the set of tokens to add to (or delete from) the
** FTS index.
**
** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
** against the FTS index. The tokenizer is being called to tokenize
** a bareword or quoted string specified as part of the query.
**
** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
** followed by a "*" character, indicating that the last token
** returned by the tokenizer will be treated as a token prefix.
**
** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
** satisfy an fts5_api.xTokenize() request made by an auxiliary
** function. Or an fts5_api.xColumnSize() request made by the same
** on a columnsize=0 database.
** </ul>
**
** For each token in the input string, the supplied callback xToken() must
** be invoked. The first argument to it should be a copy of the pointer
** passed as the second argument to xTokenize(). The third and fourth
** arguments are a pointer to a buffer containing the token text, and the
** size of the token in bytes. The 4th and 5th arguments are the byte offsets
** of the first byte of and first byte immediately following the text from
** which the token is derived within the input.
**
** The second argument passed to the xToken() callback ("tflags") should
** normally be set to 0. The exception is if the tokenizer supports
** synonyms. In this case see the discussion below for details.
**
** FTS5 assumes the xToken() callback is invoked for each token in the
** order that they occur within the input text.
**
** If an xToken() callback returns any value other than SQLITE_OK, then
** the tokenization should be abandoned and the xTokenize() method should
** immediately return a copy of the xToken() return value. Or, if the
** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
** if an error occurs with the xTokenize() implementation itself, it
** may abandon the tokenization and return any error code other than
** SQLITE_OK or SQLITE_DONE.
**
** SYNONYM SUPPORT
**
** Custom tokenizers may also support synonyms. Consider a case in which a
** user wishes to query for a phrase such as "first place". Using the
** built-in tokenizers, the FTS5 query 'first + place' will match instances
** of "first place" within the document set, but not alternative forms
** such as "1st place". In some applications, it would be better to match
** all instances of "first place" or "1st place" regardless of which form
** the user specified in the MATCH query text.
**
** There are several ways to approach this in FTS5:
**
** <ol><li> By mapping all synonyms to a single token. In this case, the
** In the above example, this means that the tokenizer returns the
** same token for inputs "first" and "1st". Say that token is in
** fact "first", so that when the user inserts the document "I won
** 1st place" entries are added to the index for tokens "i", "won",
** "first" and "place". If the user then queries for '1st + place',
** the tokenizer substitutes "first" for "1st" and the query works
** as expected.
**
** <li> By adding multiple synonyms for a single term to the FTS index.
** In this case, when tokenizing query text, the tokenizer may
** provide multiple synonyms for a single term within the document.
** FTS5 then queries the index for each synonym individually. For
** example, faced with the query:
**
** <codeblock>
** ... MATCH 'first place'</codeblock>
**
** the tokenizer offers both "1st" and "first" as synonyms for the
** first token in the MATCH query and FTS5 effectively runs a query
** similar to:
**
** <codeblock>
** ... MATCH '(first OR 1st) place'</codeblock>
**
** except that, for the purposes of auxiliary functions, the query
** still appears to contain just two phrases - "(first OR 1st)"
** being treated as a single phrase.
**
** <li> By adding multiple synonyms for a single term to the FTS index.
** Using this method, when tokenizing document text, the tokenizer
** provides multiple synonyms for each token. So that when a
** document such as "I won first place" is tokenized, entries are
** added to the FTS index for "i", "won", "first", "1st" and
** "place".
**
** This way, even if the tokenizer does not provide synonyms
** when tokenizing query text (it should not - to do would be
** inefficient), it doesn't matter if the user queries for
** 'first + place' or '1st + place', as there are entires in the
** FTS index corresponding to both forms of the first token.
** </ol>
**
** Whether it is parsing document or query text, any call to xToken that
** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
** is considered to supply a synonym for the previous token. For example,
** when parsing the document "I won first place", a tokenizer that supports
** synonyms would call xToken() 5 times, as follows:
**
** <codeblock>
** xToken(pCtx, 0, "i", 1, 0, 1);
** xToken(pCtx, 0, "won", 3, 2, 5);
** xToken(pCtx, 0, "first", 5, 6, 11);
** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);
** xToken(pCtx, 0, "place", 5, 12, 17);
**</codeblock>
**
** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
** xToken() is called. Multiple synonyms may be specified for a single token
** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
** There is no limit to the number of synonyms that may be provided for a
** single token.
**
** In many cases, method (1) above is the best approach. It does not add
** extra data to the FTS index or require FTS5 to query for multiple terms,
** so it is efficient in terms of disk space and query speed. However, it
** does not support prefix queries very well. If, as suggested above, the
** token "first" is subsituted for "1st" by the tokenizer, then the query:
**
** <codeblock>
** ... MATCH '1s*'</codeblock>
**
** will not match documents that contain the token "1st" (as the tokenizer
** will probably not map "1s" to any prefix of "first").
**
** For full prefix support, method (3) may be preferred. In this case,
** because the index contains entries for both "first" and "1st", prefix
** queries such as 'fi*' or '1s*' will match correctly. However, because
** extra entries are added to the FTS index, this method uses more space
** within the database.
**
** Method (2) offers a midpoint between (1) and (3). Using this method,
** a query such as '1s*' will match documents that contain the literal
** token "1st", but not "first" (assuming the tokenizer is not able to
** provide synonyms for prefixes). However, a non-prefix query like '1st'
** will match against "1st" and "first". This method does not require
** extra disk space, as no extra entries are added to the FTS index.
** On the other hand, it may require more CPU cycles to run MATCH queries,
** as separate queries of the FTS index are required for each synonym.
**
** When using methods (2) or (3), it is important that the tokenizer only
** provide synonyms when tokenizing document text (method (2)) or query
** text (method (3)), not both. Doing so will not cause any errors, but is
** inefficient.
label: code-design
Information desired. SQLITE_SCANSTAT_*
int nByte
OUTPUT: True if column is auto-increment
Ok for sqlite3_open_v2()
OUT: Total number of frames checkpointed
sqlite3_int64, sqlite3_int64
Flags
IMP: R-37514-35566
Name of the database
boolean
Number used to identify the index
Input changeset
******* Begin file sqlite3rtree.h ********
Byte offset of token within input text
Used internally - xBestIndex should ignore
Data type mismatch
** CAPI3REF: Delete A Changegroup Object
** CAPI3REF: Virtual File System Objects
**
** A virtual filesystem (VFS) is an [sqlite3_vfs] object
** that SQLite uses to interact
** with the underlying operating system. Most SQLite builds come with a
** single default VFS that is appropriate for the host computer.
** New VFSes can be registered and existing VFSes can be unregistered.
** The following interfaces are provided.
**
** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
** ^Names are case sensitive.
** ^Names are zero-terminated UTF-8 strings.
** ^If there is no match, a NULL pointer is returned.
** ^If zVfsName is NULL then the default VFS is returned.
**
** ^New VFSes are registered with sqlite3_vfs_register().
** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
** ^The same VFS can be registered multiple times without injury.
** ^To make an existing VFS into the default VFS, register it again
** with the makeDflt flag set. If two different VFSes with the
** same name are registered, the behavior is undefined. If a
** VFS is registered with a name that is NULL or an empty string,
** then the behavior is undefined.
**
** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
** ^(If the default VFS is unregistered, another VFS is chosen as
** the default. The choice for the new VFS is arbitrary.)^
comment:
** CAPI3REF: Invert A Changeset
**
** This function is used to "invert" a changeset object. Applying an inverted
** changeset to a database reverses the effects of applying the uninverted
** changeset. Specifically:
**
** <ul>
** <li> Each DELETE change is changed to an INSERT, and
** <li> Each INSERT change is changed to a DELETE, and
** <li> For each UPDATE change, the old.* and new.* values are exchanged.
** </ul>
**
** This function does not change the order in which changes appear within
** the changeset. It merely reverses the sense of each individual change.
**
** If successful, a pointer to a buffer containing the inverted changeset
** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
** zeroed and an SQLite error code returned.
**
** It is the responsibility of the caller to eventually call sqlite3_free()
** on the *ppOut pointer to free the buffer allocation following a successful
** call to this function.
**
** WARNING/TODO: This function currently assumes that the input is a valid
** changeset. If it is not, the results are undefined.
label: code-design
************************************************************************
** FTS5 EXTENSION REGISTRATION API
comment:
** CAPI3REF: Result Values From A Query
** KEYWORDS: {column access functions}
** METHOD: sqlite3_stmt
**
** <b>Summary:</b>
** <blockquote><table border=0 cellpadding=0 cellspacing=0>
** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result
** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result
** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result
** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result
** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result
** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result
** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an
** [sqlite3_value|unprotected sqlite3_value] object.
** <tr><td> <td> <td>
** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB
** or a UTF-8 TEXT result in bytes
** <tr><td><b>sqlite3_column_bytes16 </b>
** <td>→ <td>Size of UTF-16
** TEXT in bytes
** <tr><td><b>sqlite3_column_type</b><td>→<td>Default
** datatype of the result
** </table></blockquote>
**
** <b>Details:</b>
**
** ^These routines return information about a single column of the current
** result row of a query. ^In every case the first argument is a pointer
** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
** that was returned from [sqlite3_prepare_v2()] or one of its variants)
** and the second argument is the index of the column for which information
** should be returned. ^The leftmost column of the result set has the index 0.
** ^The number of columns in the result can be determined using
** [sqlite3_column_count()].
**
** If the SQL statement does not currently point to a valid row, or if the
** column index is out of range, the result is undefined.
** These routines may only be called when the most recent call to
** [sqlite3_step()] has returned [SQLITE_ROW] and neither
** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
** If any of these routines are called after [sqlite3_reset()] or
** [sqlite3_finalize()] or after [sqlite3_step()] has returned
** something other than [SQLITE_ROW], the results are undefined.
** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
** are called from a different thread while any of these routines
** are pending, then the results are undefined.
**
** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
** each return the value of a result column in a specific data format. If
** the result column is not initially in the requested format (for example,
** if the query returns an integer but the sqlite3_column_text() interface
** is used to extract the value) then an automatic type conversion is performed.
**
** ^The sqlite3_column_type() routine returns the
** [SQLITE_INTEGER | datatype code] for the initial data type
** of the result column. ^The returned value is one of [SQLITE_INTEGER],
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
** The return value of sqlite3_column_type() can be used to decide which
** of the first six interface should be used to extract the column value.
** The value returned by sqlite3_column_type() is only meaningful if no
** automatic type conversions have occurred for the value in question.
** After a type conversion, the result of calling sqlite3_column_type()
** is undefined, though harmless. Future
** versions of SQLite may change the behavior of sqlite3_column_type()
** following a type conversion.
**
** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
** or sqlite3_column_bytes16() interfaces can be used to determine the size
** of that BLOB or string.
**
** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
** routine returns the number of bytes in that BLOB or string.
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
** the string to UTF-8 and then returns the number of bytes.
** ^If the result is a numeric value then sqlite3_column_bytes() uses
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
** the number of bytes in that string.
** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
**
** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
** routine returns the number of bytes in that BLOB or string.
** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
** the string to UTF-16 and then returns the number of bytes.
** ^If the result is a numeric value then sqlite3_column_bytes16() uses
** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
** the number of bytes in that string.
** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
**
** ^The values returned by [sqlite3_column_bytes()] and
** [sqlite3_column_bytes16()] do not include the zero terminators at the end
** of the string. ^For clarity: the values returned by
** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
** bytes in the string, not the number of characters.
**
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
** even empty strings, are always zero-terminated. ^The return
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
**
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
** [unprotected sqlite3_value] object. In a multithreaded environment,
** an unprotected sqlite3_value object may only be used safely with
** [sqlite3_bind_value()] and [sqlite3_result_value()].
** If the [unprotected sqlite3_value] object returned by
** [sqlite3_column_value()] is used in any other way, including calls
** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
** or [sqlite3_value_bytes()], the behavior is not threadsafe.
** Hence, the sqlite3_column_value() interface
** is normally only useful within the implementation of
** [application-defined SQL functions] or [virtual tables], not within
** top-level application code.
**
** The these routines may attempt to convert the datatype of the result.
** ^For example, if the internal representation is FLOAT and a text result
** is requested, [sqlite3_snprintf()] is used internally to perform the
** conversion automatically. ^(The following table details the conversions
** that are applied:
**
** <blockquote>
** <table border="1">
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
**
** <tr><td> NULL <td> INTEGER <td> Result is 0
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
** <tr><td> TEXT <td> BLOB <td> No change
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
** </table>
** </blockquote>)^
**
** Note that when type conversions occur, pointers returned by prior
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
** sqlite3_column_text16() may be invalidated.
** Type conversions and pointer invalidations might occur
** in the following cases:
**
** <ul>
** <li> The initial content is a BLOB and sqlite3_column_text() or
** sqlite3_column_text16() is called. A zero-terminator might
** need to be added to the string.</li>
** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
** sqlite3_column_text16() is called. The content must be converted
** to UTF-16.</li>
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
** sqlite3_column_text() is called. The content must be converted
** to UTF-8.</li>
** </ul>
**
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
** not invalidate a prior pointer, though of course the content of the buffer
** that the prior pointer references will have been modified. Other kinds
** of conversion are done in place when it is possible, but sometimes they
** are not possible and in those cases prior pointers are invalidated.
**
** The safest policy is to invoke these routines
** in one of the following ways:
**
** <ul>
** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
** </ul>
**
** In other words, you should call sqlite3_column_text(),
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
** into the desired format, then invoke sqlite3_column_bytes() or
** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
** to sqlite3_column_text() or sqlite3_column_blob() with calls to
** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
** with calls to sqlite3_column_bytes().
**
** ^The pointers returned are valid until a type conversion occurs as
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
** and BLOBs is freed automatically. Do not pass the pointers returned
** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
** [sqlite3_free()].
**
** ^(If a memory allocation error occurs during the evaluation of any
** of these routines, a default value is returned. The default value
** is either the integer 0, the floating point number 0.0, or a NULL
** pointer. Subsequent calls to [sqlite3_errcode()] will return
** [SQLITE_NOMEM].)^
label: code-design
** CAPI3REF: Determine If An SQL Statement Writes The Database
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
** and only if the [prepared statement] X makes no direct changes to
** the content of the database file.
**
** Note that [application-defined SQL functions] or
** [virtual tables] might change the database indirectly as a side effect.
** ^(For example, if an application defines a function "eval()" that
** calls [sqlite3_exec()], then the following SQL statement would
** change the database file through side-effects:
**
** <blockquote><pre>
** SELECT eval('DELETE FROM t1') FROM t2;
** </pre></blockquote>
**
** But because the [SELECT] statement does not change the database file
** directly, sqlite3_stmt_readonly() would still return true.)^
**
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
** since the statements themselves do not actually modify the database but
** rather they control the timing of when other statements modify the
** database. ^The [ATTACH] and [DETACH] statements also cause
** sqlite3_stmt_readonly() to return true since, while those statements
** change the configuration of a database connection, they do not make
** changes to the content of the database files on disk.
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
** sqlite3_stmt_readonly() returns false for those commands.
Return the size of an allocation
sqlite3_mem_methods*
if >0, constraint is part of argv to xFilter
Database filename (UTF-16)
Attempt to write a readonly database
Input function
** CAPI3REF: Error Logging Interface
**
** ^The [sqlite3_log()] interface writes a message into the [error log]
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
** ^If logging is enabled, the zFormat string and subsequent arguments are
** used with [sqlite3_snprintf()] to generate the final output string.
**
** The sqlite3_log() interface is intended for use by extensions such as
** virtual tables, collating functions, and SQL functions. While there is
** nothing to prevent an application from calling sqlite3_log(), doing so
** is considered bad form.
**
** The zFormat string must not be NULL.
**
** To avoid deadlocks and other threading problems, the sqlite3_log() routine
** will not use dynamically allocated memory. The log message is stored in
** a fixed-length buffer on the stack. If the log message is longer than
** a few hundred characters, it will be truncated to the length of the
** buffer.
** CAPI3REF: Copy And Free SQL Values
** METHOD: sqlite3_value
**
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
** is a [protected sqlite3_value] object even if the input is not.
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
** memory allocation fails.
**
** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
** then sqlite3_value_free(V) is a harmless no-op.
** CAPI3REF: Automatically Load Statically Linked Extensions
**
** ^This interface causes the xEntryPoint() function to be invoked for
** each new [database connection] that is created. The idea here is that
** xEntryPoint() is the entry point for a statically linked [SQLite extension]
** that is to be automatically loaded into all new database connections.
**
** ^(Even though the function prototype shows that xEntryPoint() takes
** no arguments and returns void, SQLite invokes xEntryPoint() with three
** arguments and expects an integer result as if the signature of the
** entry point where as follows:
**
** <blockquote><pre>
** int xEntryPoint(
** sqlite3 *db,
** const char **pzErrMsg,
** const struct sqlite3_api_routines *pThunk
** );
** </pre></blockquote>)^
**
** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
** point to an appropriate error message (obtained from [sqlite3_mprintf()])
** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
** is NULL before calling the xEntryPoint(). ^SQLite will invoke
** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
**
** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
** on the list of automatic extensions is a harmless no-op. ^No entry point
** will be called more than once for each database connection that is opened.
**
** See also: [sqlite3_reset_auto_extension()]
** and [sqlite3_cancel_auto_extension()]
Use native byte order
!defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
comment:
** CAPI3REF: Name Of The Folder Holding Temporary Files
**
** ^(If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite when using a built-in [sqlite3_vfs | VFS]
** will be placed in that directory.)^ ^If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** Applications are strongly discouraged from using this global variable.
** It is required to set a temporary folder on Windows Runtime (WinRT).
** But for all other platforms, it is highly recommended that applications
** neither read nor write this variable. This global variable is a relic
** that exists for backwards compatibility of legacy applications and should
** be avoided in new projects.
**
** It is not safe to read or modify this variable in more than one
** thread at a time. It is not safe to read or modify this variable
** if a [database connection] is being used at the same time in a separate
** thread.
** It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been called and that this variable remain unchanged
** thereafter.
**
** ^The [temp_store_directory pragma] may modify this variable and cause
** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
** the [temp_store_directory pragma] always assumes that any string
** that this variable points to is held in memory obtained from
** [sqlite3_malloc] and the pragma may attempt to free that memory
** using [sqlite3_free].
** Hence, if this variable is modified directly, either it should be
** made NULL or made to point to memory obtained from [sqlite3_malloc]
** or else the use of the [temp_store_directory pragma] should be avoided.
** Except when requested by the [temp_store_directory pragma], SQLite
** does not free the memory that sqlite3_temp_directory points to. If
** the application wants that memory to be freed, it must do
** so itself, taking care to only do so after all [database connection]
** objects have been destroyed.
**
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
** features that require the use of temporary files may fail. Here is an
** example of how to do this using C++ with the Windows Runtime:
**
** <blockquote><pre>
** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
** TemporaryFolder->Path->Data();
** char zPathBuf[MAX_PATH + 1];
** memset(zPathBuf, 0, sizeof(zPathBuf));
** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
** NULL, NULL);
** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
** </pre></blockquote>
label: code-design
comment:
** CAPI3REF: Declare The Schema Of A Virtual Table
**
** ^The [xCreate] and [xConnect] methods of a
** [virtual table module] call this interface
** to declare the format (the names and datatypes of the columns) of
** the virtual tables they implement.
label: code-design
Callback implementation user data
Number of coordinates
Database name
** CAPI3REF: The pre-update hook.
**
** ^These interfaces are only available if SQLite is compiled using the
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
**
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
** on a database table.
** ^At most one preupdate hook may be registered at a time on a single
** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
** the previous setting.
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
** with a NULL pointer as the second parameter.
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
** the first parameter to callbacks.
**
** ^The preupdate hook only fires for changes to real database tables; the
** preupdate hook is not invoked for changes to [virtual tables] or to
** system tables like sqlite_master or sqlite_stat1.
**
** ^The second parameter to the preupdate callback is a pointer to
** the [database connection] that registered the preupdate hook.
** ^The third parameter to the preupdate callback is one of the constants
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
** kind of update operation that is about to occur.
** ^(The fourth parameter to the preupdate callback is the name of the
** database within the database connection that is being modified. This
** will be "main" for the main database or "temp" for TEMP tables or
** the name given after the AS keyword in the [ATTACH] statement for attached
** databases.)^
** ^The fifth parameter to the preupdate callback is the name of the
** table that is being modified.
**
** For an UPDATE or DELETE operation on a [rowid table], the sixth
** parameter passed to the preupdate callback is the initial [rowid] of the
** row being modified or deleted. For an INSERT operation on a rowid table,
** or any operation on a WITHOUT ROWID table, the value of the sixth
** parameter is undefined. For an INSERT or UPDATE on a rowid table the
** seventh parameter is the final rowid value of the row being inserted
** or updated. The value of the seventh parameter passed to the callback
** function is not defined for operations on WITHOUT ROWID tables, or for
** INSERT operations on rowid tables.
**
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
** provide additional information about a preupdate event. These routines
** may only be called from within a preupdate callback. Invoking any of
** these routines from outside of a preupdate callback or with a
** [database connection] pointer that is different from the one supplied
** to the preupdate callback results in undefined and probably undesirable
** behavior.
**
** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
** in the row that is being inserted, updated, or deleted.
**
** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row before it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed when the preupdate callback returns.
**
** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row after it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed when the preupdate callback returns.
**
** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
** callback was invoked as a result of a direct insert, update, or delete
** operation; or 1 for inserts, updates, or deletes invoked by top-level
** triggers; or 2 for changes resulting from triggers called by top-level
** triggers; and so forth.
**
** See also: [sqlite3_update_hook()]
Load the extension into this database connection
Estimated cost of using this index
comment:
** CAPI3REF: Add A Changeset To A Changegroup
**
** Add all changes within the changeset (or patchset) in buffer pData (size
** nData bytes) to the changegroup.
**
** If the buffer contains a patchset, then all prior calls to this function
** on the same changegroup object must also have specified patchsets. Or, if
** the buffer contains a changeset, so must have the earlier calls to this
** function. Otherwise, SQLITE_ERROR is returned and no changes are added
** to the changegroup.
**
** Rows within the changeset and changegroup are identified by the values in
** their PRIMARY KEY columns. A change in the changeset is considered to
** apply to the same row as a change already present in the changegroup if
** the two rows have the same primary key.
**
** Changes to rows that do not already appear in the changegroup are
** simply copied into it. Or, if both the new changeset and the changegroup
** contain changes that apply to a single row, the final contents of the
** changegroup depends on the type of each change, as follows:
**
** <table border=1 style="margin-left:8ex;margin-right:8ex">
** <tr><th style="white-space:pre">Existing Change </th>
** <th style="white-space:pre">New Change </th>
** <th>Output Change
** <tr><td>INSERT <td>INSERT <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>INSERT <td>UPDATE <td>
** The INSERT change remains in the changegroup. The values in the
** INSERT change are modified as if the row was inserted by the
** existing change and then updated according to the new change.
** <tr><td>INSERT <td>DELETE <td>
** The existing INSERT is removed from the changegroup. The DELETE is
** not added.
** <tr><td>UPDATE <td>INSERT <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>UPDATE <td>UPDATE <td>
** The existing UPDATE remains within the changegroup. It is amended
** so that the accompanying values are as if the row was updated once
** by the existing change and then again by the new change.
** <tr><td>UPDATE <td>DELETE <td>
** The existing UPDATE is replaced by the new DELETE within the
** changegroup.
** <tr><td>DELETE <td>INSERT <td>
** If one or more of the column values in the row inserted by the
** new change differ from those in the row deleted by the existing
** change, the existing DELETE is replaced by an UPDATE within the
** changegroup. Otherwise, if the inserted row is exactly the same
** as the deleted row, the existing DELETE is simply discarded.
** <tr><td>DELETE <td>UPDATE <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** <tr><td>DELETE <td>DELETE <td>
** The new change is ignored. This case does not occur if the new
** changeset was recorded immediately after the changesets already
** added to the changegroup.
** </table>
**
** If the new changeset contains changes to a table that is already present
** in the changegroup, then the number of columns and the position of the
** primary key columns for the table must be consistent. If this is not the
** case, this function fails with SQLITE_SCHEMA. If the input changeset
** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
** returned. Or, if an out-of-memory condition occurs during processing, this
** function returns SQLITE_NOMEM. In all cases, if an error occurs the
** final contents of the changegroup is undefined.
**
** If no error occurs, SQLITE_OK is returned.
label: code-design
Outputs
** CAPI3REF: Device Characteristics
**
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
** object returns an integer which is a vector of these
** bit values expressing I/O characteristics of the mass storage
** device that holds the file that the [sqlite3_io_methods]
** refers to.
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
** after reboot following a crash or power loss, the only bytes in a
** file that were written at the application level might have changed
** and that adjacent bytes, even bytes within the same sector are
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
** flag indicates that a file cannot be deleted when open. The
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
** read-only media and cannot be changed even by processes with
** elevated privileges.
function to free pUser
Number of result rows written here
Name of attached database (or NULL)
Number of pending entries in the queue
comment:
** These no-op macros are used in front of interfaces to mark those
** interfaces as either deprecated or experimental. New applications
** should not use deprecated interfaces - they are supported for backwards
** compatibility only. Application writers should be aware that
** experimental interfaces are subject to change in point releases.
**
** These macros used to resolve to various kinds of compiler magic that
** would generate warning messages when they were used. But that
** compiler magic ended up generating such a flurry of bug reports
** that we have taken it all out and gone back to using simple
** noop macros.
label: code-design
** CAPI3REF: Session Object Handle
** CAPI3REF: Obtain A Composite Changeset From A Changegroup
**
** Obtain a buffer containing a changeset (or patchset) representing the
** current contents of the changegroup. If the inputs to the changegroup
** were themselves changesets, the output is a changeset. Or, if the
** inputs were patchsets, the output is also a patchset.
**
** As with the output of the sqlite3session_changeset() and
** sqlite3session_patchset() functions, all changes related to a single
** table are grouped together in the output of this function. Tables appear
** in the same order as for the very first changeset added to the changegroup.
** If the second or subsequent changesets added to the changegroup contain
** changes for tables that do not appear in the first changeset, they are
** appended onto the end of the output changeset, again in the order in
** which they are first encountered.
**
** If an error occurs, an SQLite error code is returned and the output
** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
** is returned and the output variables are set to the size of and a
** pointer to the output buffer, respectively. In this case it is the
** responsibility of the caller to eventually free the buffer using a
** call to sqlite3_free().
int int
Database to be rekeyed
Connection handle
Pointer to buffer containing changeset A
** CAPI3REF: Return The Filename For A Database Connection
** METHOD: sqlite3
**
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
** associated with database N of connection D. ^The main database file
** has the name "main". If there is no attached database N on the database
** connection D, or if database N is a temporary or in-memory database, then
** a NULL pointer is returned.
**
** ^The filename returned by this function is the output of the
** xFullPathname method of the [VFS]. ^In other words, the filename
** will be an absolute pathname, even if the filename used
** to open the database originally was a URI or relative pathname.
The content of the page
** CAPI3REF: Compare the ages of two snapshot handles.
** EXPERIMENTAL
**
** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
** of two valid snapshot handles.
**
** If the two snapshot handles are not associated with the same database
** file, the result of the comparison is undefined.
**
** Additionally, the result of the comparison is only valid if both of the
** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
** last time the wal file was deleted. The wal file is deleted when the
** database is changed back to rollback mode or when the number of database
** clients drops to zero. If either snapshot handle was obtained before the
** wal file was last deleted, the value returned by this function
** is undefined.
**
** Otherwise, this API returns a negative value if P1 refers to an older
** snapshot than P2, zero if the two handles refer to the same database
** snapshot, and a positive value if P1 is a newer snapshot than P2.
Zero or more SQLITE_PREPARE_ flags
Error message from sqlite3_mprintf()
Pointer to buffer containing token
Table Name Module Name
** CAPI3REF: Number Of SQL Parameters
** METHOD: sqlite3_stmt
**
** ^This routine can be used to find the number of [SQL parameters]
** in a [prepared statement]. SQL parameters are tokens of the
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
** placeholders for values that are [sqlite3_bind_blob | bound]
** to the parameters at a later time.
**
** ^(This routine actually returns the index of the largest (rightmost)
** parameter. For all forms except ?NNN, this will correspond to the
** number of unique parameters. If parameters of the ?NNN form are used,
** there may be gaps in the list.)^
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_name()], and
** [sqlite3_bind_parameter_index()].
comment:
** CAPI3REF: Configuring The SQLite Library
**
** The sqlite3_config() interface is used to make global configuration
** changes to SQLite in order to tune SQLite to the specific needs of
** the application. The default configuration is recommended for most
** applications and so this routine is usually not necessary. It is
** provided to support rare applications with unusual needs.
**
** <b>The sqlite3_config() interface is not threadsafe. The application
** must ensure that no other SQLite interfaces are invoked by other
** threads while sqlite3_config() is running.</b>
**
** The sqlite3_config() interface
** may only be invoked prior to library initialization using
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
** Note, however, that ^sqlite3_config() can be called as part of the
** implementation of an application-defined [sqlite3_os_init()].
**
** The first argument to sqlite3_config() is an integer
** [configuration option] that determines
** what property of SQLite is to be configured. Subsequent arguments
** vary depending on the [configuration option]
** in the first argument.
**
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
** ^If the option is unknown or SQLite is unable to set the option
** then this routine returns a non-zero [error code].
label: code-design
sqlite3_create_collation only
Byte offset of end of token within input text
** CAPI3REF: SQL Trace Hook
** METHOD: sqlite3
**
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
** function X against [database connection] D, using property mask M
** and context pointer P. ^If the X callback is
** NULL or if the M mask is zero, then tracing is disabled. The
** M argument should be the bitwise OR-ed combination of
** zero or more [SQLITE_TRACE] constants.
**
** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
**
** ^The X callback is invoked whenever any of the events identified by
** mask M occur. ^The integer return value from the callback is currently
** ignored, though this may change in future releases. Callback
** implementations should return zero to ensure future compatibility.
**
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
** ^The T argument is one of the [SQLITE_TRACE]
** constants to indicate why the callback was invoked.
** ^The C argument is a copy of the context pointer.
** The P and X arguments are pointers whose meanings depend on T.
**
** The sqlite3_trace_v2() interface is intended to replace the legacy
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
** are deprecated.
** CAPI3REF: File Locking Levels
**
** SQLite uses one of these integer values as the second
** argument to calls it makes to the xLock() and xUnlock() methods
** of an [sqlite3_io_methods] object.
Context for returning result/error
comment:
** CAPI3REF: Synchronization Type Flags
**
** When SQLite invokes the xSync() method of an
** [sqlite3_io_methods] object it uses a combination of
** these integer values as the second argument.
**
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
** sync operation only needs to flush data to mass storage. Inode
** information need not be flushed. If the lower four bits of the flag
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
** If the lower four bits equal SQLITE_SYNC_FULL, that means
** to use Mac OS X style fullsync instead of fsync().
**
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
** settings. The [synchronous pragma] determines when calls to the
** xSync VFS method occur and applies uniformly across all platforms.
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
** energetic or rigorous or forceful the sync operations are and
** only make a difference on Mac OSX for the default SQLite code.
** (Third-party VFS implementations might also make the distinction
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
** operating systems natively supported by SQLite, only Mac OSX
** cares about the difference.)
label: code-design
OUT: Write the score here
comment: sqlite3_malloc()
label: code-design
** Structures used by the virtual table interface
comment:
** CAPI3REF: Memory Allocation Routines
**
** An instance of this object defines the interface between SQLite
** and low-level memory allocation routines.
**
** This object is used in only one place in the SQLite interface.
** A pointer to an instance of this object is the argument to
** [sqlite3_config()] when the configuration option is
** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
** By creating an instance of this object
** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
** during configuration, an application can specify an alternative
** memory allocation subsystem for SQLite to use for all of its
** dynamic memory needs.
**
** Note that SQLite comes with several [built-in memory allocators]
** that are perfectly adequate for the overwhelming majority of applications
** and that this object is only useful to a tiny minority of applications
** with specialized memory allocation requirements. This object is
** also used during testing of SQLite in order to specify an alternative
** memory allocator that simulates memory out-of-memory conditions in
** order to verify that SQLite recovers gracefully from such
** conditions.
**
** The xMalloc, xRealloc, and xFree methods must work like the
** malloc(), realloc() and free() functions from the standard C library.
** ^SQLite guarantees that the second argument to
** xRealloc is always a value returned by a prior call to xRoundup.
**
** xSize should return the allocated size of a memory allocation
** previously obtained from xMalloc or xRealloc. The allocated size
** is always at least as big as the requested size but may be larger.
**
** The xRoundup method returns what would be the allocated size of
** a memory allocation given a particular requested size. Most memory
** allocators round up memory allocations at least to the next multiple
** of 8. Some allocators round up to a larger multiple or to a power of 2.
** Every memory allocation request coming in through [sqlite3_malloc()]
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
** that causes the corresponding memory allocation to fail.
**
** The xInit method initializes the memory allocator. For example,
** it might allocate any require mutexes or initialize internal data
** structures. The xShutdown method is invoked (indirectly) by
** [sqlite3_shutdown()] and should deallocate any resources acquired
** by xInit. The pAppData pointer is used as the only parameter to
** xInit and xShutdown.
**
** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
** the xInit method, so the xInit method need not be threadsafe. The
** xShutdown method is only called from [sqlite3_shutdown()] so it does
** not need to be threadsafe either. For all other methods, SQLite
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
** it is by default) and so the methods are automatically serialized.
** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
** methods must be threadsafe or else make their own arrangements for
** serialization.
**
** SQLite will never invoke xInit() more than once without an intervening
** call to xShutdown().
label: code-design
Operation terminated by sqlite3_interrupt()
comment:
** CAPI3REF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
** KEYWORDS: {application-defined SQL function}
** KEYWORDS: {application-defined SQL functions}
** METHOD: sqlite3
**
** ^These functions (collectively known as "function creation routines")
** are used to add SQL functions or aggregates or to redefine the behavior
** of existing SQL functions or aggregates. The only differences between
** these routines are the text encoding expected for
** the second parameter (the name of the function being created)
** and the presence or absence of a destructor callback for
** the application data pointer.
**
** ^The first parameter is the [database connection] to which the SQL
** function is to be added. ^If an application uses more than one database
** connection then application-defined SQL functions must be added
** to each database connection separately.
**
** ^The second parameter is the name of the SQL function to be created or
** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
** representation, exclusive of the zero-terminator. ^Note that the name
** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
** ^Any attempt to create a function with a longer name
** will result in [SQLITE_MISUSE] being returned.
**
** ^The third parameter (nArg)
** is the number of arguments that the SQL function or
** aggregate takes. ^If this parameter is -1, then the SQL function or
** aggregate may take any number of arguments between 0 and the limit
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
** parameter is less than -1 or greater than 127 then the behavior is
** undefined.
**
** ^The fourth parameter, eTextRep, specifies what
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
** its parameters. The application should set this parameter to
** [SQLITE_UTF16LE] if the function implementation invokes
** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
** implementation invokes [sqlite3_value_text16be()] on an input, or
** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
** otherwise. ^The same SQL function may be registered multiple times using
** different preferred text encodings, with different implementations for
** each encoding.
** ^When multiple implementations of the same function are available, SQLite
** will pick the one that involves the least amount of data conversion.
**
** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
** to signal that the function will always return the same result given
** the same inputs within a single SQL statement. Most SQL functions are
** deterministic. The built-in [random()] SQL function is an example of a
** function that is not deterministic. The SQLite query planner is able to
** perform additional optimizations on deterministic functions, so use
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
**
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
** function can gain access to this pointer using [sqlite3_user_data()].)^
**
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
** pointers to C-language functions that implement the SQL function or
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
** callback only; NULL pointers must be passed as the xStep and xFinal
** parameters. ^An aggregate SQL function requires an implementation of xStep
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
** SQL function or aggregate, pass NULL pointers for all three function
** callbacks.
**
** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
** then it is destructor for the application data pointer.
** The destructor is invoked when the function is deleted, either by being
** overloaded or when the database connection closes.)^
** ^The destructor is also invoked if the call to
** sqlite3_create_function_v2() fails.
** ^When the destructor callback of the tenth parameter is invoked, it
** is passed a single argument which is a copy of the application data
** pointer which was the fifth parameter to sqlite3_create_function_v2().
**
** ^It is permitted to register multiple implementations of the same
** functions with the same name but with either differing numbers of
** arguments or differing preferred text encodings. ^SQLite will use
** the implementation that most closely matches the way in which the
** SQL function is used. ^A function implementation with a non-negative
** nArg parameter is a better match than a function implementation with
** a negative nArg. ^A function where the preferred text encoding
** matches the database encoding is a better
** match than a function where the encoding is different.
** ^A function where the encoding difference is between UTF16le and UTF16be
** is a closer match than a function where the encoding difference is
** between UTF8 and UTF16.
**
** ^Built-in functions may be overloaded by new application-defined functions.
**
** ^An application-defined function is permitted to call other
** SQLite interfaces. However, such calls must not
** close the database connection nor finalize or reset the prepared
** statement in which the function is running.
label: code-design
** CAPI3REF: A Handle To An Open BLOB
** KEYWORDS: {BLOB handle} {BLOB handles}
**
** An instance of this object represents an open BLOB on which
** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
** ^Objects of this type are created by [sqlite3_blob_open()]
** and destroyed by [sqlite3_blob_close()].
** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
** can be used to read or write small subsections of the BLOB.
** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
** CAPI3REF: Retrieving Statement SQL
** METHOD: sqlite3_stmt
**
** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
** SQL text used to create [prepared statement] P if P was
** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
** string containing the SQL text of prepared statement P with
** [bound parameters] expanded.
**
** ^(For example, if a prepared statement is created using the SQL
** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
** and parameter :xyz is unbound, then sqlite3_sql() will return
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
** will return "SELECT 2345,NULL".)^
**
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
** is available to hold the result, or if the result would exceed the
** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
**
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
** option causes sqlite3_expanded_sql() to always return NULL.
**
** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
** automatically freed when the prepared statement is finalized.
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
** is obtained from [sqlite3_malloc()] and must be free by the application
** by passing it to [sqlite3_free()].
** Specify the activation key for a CEROD database. Unless
** activated, none of the CEROD routines will work.
** CAPI3REF: Run-time Limits
** METHOD: sqlite3
**
** ^(This interface allows the size of various constructs to be limited
** on a connection by connection basis. The first parameter is the
** [database connection] whose limit is to be set or queried. The
** second parameter is one of the [limit categories] that define a
** class of constructs to be size limited. The third parameter is the
** new limit for that construct.)^
**
** ^If the new limit is a negative number, the limit is unchanged.
** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
** [limits | hard upper bound]
** set at compile-time by a C preprocessor macro called
** [limits | SQLITE_MAX_<i>NAME</i>].
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
** ^Attempts to increase a limit above its hard upper bound are
** silently truncated to the hard upper bound.
**
** ^Regardless of whether or not the limit was changed, the
** [sqlite3_limit()] interface returns the prior value of the limit.
** ^Hence, to find the current value of a limit without changing it,
** simply invoke this interface with the third parameter set to -1.
**
** Run-time limits are intended for use in applications that manage
** both their own internal database and also databases that are controlled
** by untrusted external sources. An example application might be a
** web browser that has its own databases for storing history and
** separate databases controlled by JavaScript applications downloaded
** off the Internet. The internal databases can be given the
** large, default limits. Databases managed by external sources can
** be given much smaller limits designed to prevent a denial of service
** attack. Developers might also want to use the [sqlite3_set_authorizer()]
** interface to further control untrusted SQL. The size of the database
** created by an untrusted script can be contained using the
** [max_page_count] [PRAGMA].
**
** New run-time limit categories may be added in future releases.
** CAPI3REF: Load The Difference Between Tables Into A Session
**
** If it is not already attached to the session object passed as the first
** argument, this function attaches table zTbl in the same manner as the
** [sqlite3session_attach()] function. If zTbl does not exist, or if it
** does not have a primary key, this function is a no-op (but does not return
** an error).
**
** Argument zFromDb must be the name of a database ("main", "temp" etc.)
** attached to the same database handle as the session object that contains
** a table compatible with the table attached to the session by this function.
** A table is considered compatible if it:
**
** <ul>
** <li> Has the same name,
** <li> Has the same set of columns declared in the same order, and
** <li> Has the same PRIMARY KEY definition.
** </ul>
**
** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
** are compatible but do not have any PRIMARY KEY columns, it is not an error
** but no changes are added to the session object. As with other session
** APIs, tables without PRIMARY KEYs are simply ignored.
**
** This function adds a set of changes to the session object that could be
** used to update the table in database zFrom (call this the "from-table")
** so that its content is the same as the table attached to the session
** object (call this the "to-table"). Specifically:
**
** <ul>
** <li> For each row (primary key) that exists in the to-table but not in
** the from-table, an INSERT record is added to the session object.
**
** <li> For each row (primary key) that exists in the to-table but not in
** the from-table, a DELETE record is added to the session object.
**
** <li> For each row (primary key) that exists in both tables, but features
** different non-PK values in each, an UPDATE record is added to the
** session.
** </ul>
**
** To clarify, if this function is called and then a changeset constructed
** using [sqlite3session_changeset()], then after applying that changeset to
** database zFrom the contents of the two compatible tables would be
** identical.
**
** It an error if database zFrom does not exist or does not contain the
** required compatible table.
**
** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
** may be set to point to a buffer containing an English language error
** message. It is the responsibility of the caller to free this buffer using
** sqlite3_free().
Trigger Name Table Name
comment: previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused.
label: code-design
The database file is locked
OUT: New session object
The methods above are in version 1 of the sqlite_module object. Those
** below are for version 2 and greater.
** CAPI3REF: Create An Iterator To Traverse A Changeset
**
** Create an iterator used to iterate through the contents of a changeset.
** If successful, *pp is set to point to the iterator handle and SQLITE_OK
** is returned. Otherwise, if an error occurs, *pp is set to zero and an
** SQLite error code is returned.
**
** The following functions can be used to advance and query a changeset
** iterator created by this function:
**
** <ul>
** <li> [sqlite3changeset_next()]
** <li> [sqlite3changeset_op()]
** <li> [sqlite3changeset_new()]
** <li> [sqlite3changeset_old()]
** </ul>
**
** It is the responsibility of the caller to eventually destroy the iterator
** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
** changeset (pChangeset) must remain valid until after the iterator is
** destroyed.
**
** Assuming the changeset blob was created by one of the
** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
** [sqlite3changeset_invert()] functions, all changes within the changeset
** that apply to a single table are grouped together. This means that when
** an application iterates through a changeset using an iterator created by
** this function, all changes that relate to a single table are visited
** consecutively. There is no chance that the iterator will visit a change
** the applies to table X, then one for table Y, and then later on visit
** another change for table X.
Copy of third arg to _filter_table()
** CAPI3REF: Error Codes And Messages
** METHOD: sqlite3
**
** ^If the most recent sqlite3_* API call associated with
** [database connection] D failed, then the sqlite3_errcode(D) interface
** returns the numeric [result code] or [extended result code] for that
** API call.
** If the most recent API call was successful,
** then the return value from sqlite3_errcode() is undefined.
** ^The sqlite3_extended_errcode()
** interface is the same except that it always returns the
** [extended result code] even when extended result codes are
** disabled.
**
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
** text that describes the error, as either UTF-8 or UTF-16 respectively.
** ^(Memory to hold the error message string is managed internally.
** The application does not need to worry about freeing the result.
** However, the error string might be overwritten or deallocated by
** subsequent calls to other SQLite interface functions.)^
**
** ^The sqlite3_errstr() interface returns the English-language text
** that describes the [result code], as UTF-8.
** ^(Memory to hold the error message string is managed internally
** and must not be freed by the application)^.
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
** interfaces always report the most recent result. To avoid
** this, each thread can obtain exclusive use of the [database connection] D
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
** all calls to the interfaces listed here are completed.
**
** If an interface fails with SQLITE_MISUSE, that means the interface
** was invoked incorrectly by the application. In that case, the
** error code and message may or may not be set.
String or BLOB exceeds size limit
** CAPI3REF: Data Change Notification Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_update_hook() interface registers a callback function
** with the [database connection] identified by the first argument
** to be invoked whenever a row is updated, inserted or deleted in
** a [rowid table].
** ^Any callback set by a previous call to this function
** for the same database connection is overridden.
**
** ^The second argument is a pointer to the function to invoke when a
** row is updated, inserted or deleted in a rowid table.
** ^The first argument to the callback is a copy of the third argument
** to sqlite3_update_hook().
** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
** or [SQLITE_UPDATE], depending on the operation that caused the callback
** to be invoked.
** ^The third and fourth arguments to the callback contain pointers to the
** database and table name containing the affected row.
** ^The final callback parameter is the [rowid] of the row.
** ^In the case of an update, this is the [rowid] after the update takes place.
**
** ^(The update hook is not invoked when internal system tables are
** modified (i.e. sqlite_master and sqlite_sequence).)^
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
**
** ^In the current implementation, the update hook
** is not invoked when conflicting rows are deleted because of an
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
** invoked when rows are deleted using the [truncate optimization].
** The exceptions defined in this paragraph might change in a future
** release of SQLite.
**
** The update hook implementation must not do anything that will modify
** the database connection that invoked the update hook. Any actions
** to modify the database connection must be deferred until after the
** completion of the [sqlite3_step()] call that triggered the update hook.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
** ^The sqlite3_update_hook(D,C,P) function
** returns the P argument from the previous call
** on the same [database connection] D, or NULL for
** the first call on D.
**
** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
** and [sqlite3_preupdate_hook()] interfaces.
Changeset blob
Inputs
comment:
** The interface to the virtual-table mechanism defined above (back up
** to a comment remarkably similar to this one) is currently considered
** to be experimental. The interface might change in incompatible ways.
** If this is a problem for you, do not use the interface at this time.
**
** When the virtual-table mechanism stabilizes, we will declare the
** interface fixed, support it indefinitely, and remove this comment.
label: code-design
** CAPI3REF: 64-Bit Integer Types
** KEYWORDS: sqlite_int64 sqlite_uint64
**
** Because there is no cross-platform way to specify 64-bit integer types
** SQLite includes typedefs for 64-bit signed and unsigned integers.
**
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
** compatibility only.
**
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
** sqlite3_uint64 and sqlite_uint64 types can store integer values
** between 0 and +18446744073709551615 inclusive.
** CAPI3REF: Prepare Flags
**
** These constants define various flags that can be passed into
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
** [sqlite3_prepare16_v3()] interfaces.
**
** New flags may be added in future releases of SQLite.
**
** <dl>
** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
** that the prepared statement will be retained for a long time and
** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
** and [sqlite3_prepare16_v3()] assume that the prepared statement will
** be used just once or at most a few times and then destroyed using
** [sqlite3_finalize()] relatively soon. The current implementation acts
** on this hint by avoiding the use of [lookaside memory] so as not to
** deplete the limited store of lookaside memory. Future versions of
** SQLite may act on this hint differently.
** </dl>
Wait for writers, then checkpoint
** CAPI3REF: Opening A New Database Connection
** CONSTRUCTOR: sqlite3
**
** ^These routines open an SQLite database file as specified by the
** filename argument. ^The filename argument is interpreted as UTF-8 for
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
** order for sqlite3_open16(). ^(A [database connection] handle is usually
** returned in *ppDb, even if an error occurs. The only exception is that
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
** object.)^ ^(If the database is opened (and/or created) successfully, then
** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
** an English language description of the error following a failure of any
** of the sqlite3_open() routines.
**
** ^The default encoding will be UTF-8 for databases created using
** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
** created using sqlite3_open16() will be UTF-16 in the native byte order.
**
** Whether or not an error occurs when it is opened, resources
** associated with the [database connection] handle should be released by
** passing it to [sqlite3_close()] when it is no longer required.
**
** The sqlite3_open_v2() interface works like sqlite3_open()
** except that it accepts two additional parameters for additional control
** over the new database connection. ^(The flags parameter to
** sqlite3_open_v2() can take one of
** the following three values, optionally combined with the
** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
**
** <dl>
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
** <dd>The database is opened in read-only mode. If the database does not
** already exist, an error is returned.</dd>)^
**
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
** <dd>The database is opened for reading and writing if possible, or reading
** only if the file is write protected by the operating system. In either
** case the database must already exist, otherwise an error is returned.</dd>)^
**
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
** <dd>The database is opened for reading and writing, and is created if
** it does not already exist. This is the behavior that is always used for
** sqlite3_open() and sqlite3_open16().</dd>)^
** </dl>
**
** If the 3rd parameter to sqlite3_open_v2() is not one of the
** combinations shown above optionally combined with other
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
** then the behavior is undefined.
**
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
** opens in the multi-thread [threading mode] as long as the single-thread
** mode has not been set at compile-time or start-time. ^If the
** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
** in the serialized [threading mode] unless single-thread was
** previously selected at compile-time or start-time.
** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
** eligible to use [shared cache mode], regardless of whether or not shared
** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
** participate in [shared cache mode] even if it is enabled.
**
** ^The fourth parameter to sqlite3_open_v2() is the name of the
** [sqlite3_vfs] object that defines the operating system interface that
** the new database connection should use. ^If the fourth parameter is
** a NULL pointer then the default [sqlite3_vfs] object is used.
**
** ^If the filename is ":memory:", then a private, temporary in-memory database
** is created for the connection. ^This in-memory database will vanish when
** the database connection is closed. Future versions of SQLite might
** make use of additional special filenames that begin with the ":" character.
** It is recommended that when a database filename actually does begin with
** a ":" character you should prefix the filename with a pathname such as
** "./" to avoid ambiguity.
**
** ^If the filename is an empty string, then a private, temporary
** on-disk database will be created. ^This private database will be
** automatically deleted as soon as the database connection is closed.
**
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
**
** ^If [URI filename] interpretation is enabled, and the filename argument
** begins with "file:", then the filename is interpreted as a URI. ^URI
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
** set in the fourth argument to sqlite3_open_v2(), or if it has
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
** As of SQLite version 3.7.7, URI filename interpretation is turned off
** by default, but future releases of SQLite might enable URI filename
** interpretation by default. See "[URI filenames]" for additional
** information.
**
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
** authority, then it must be either an empty string or the string
** "localhost". ^If the authority is not an empty string or "localhost", an
** error is returned to the caller. ^The fragment component of a URI, if
** present, is ignored.
**
** ^SQLite uses the path component of the URI as the name of the disk file
** which contains the database. ^If the path begins with a '/' character,
** then it is interpreted as an absolute path. ^If the path does not begin
** with a '/' (meaning that the authority section is omitted from the URI)
** then the path is interpreted as a relative path.
** ^(On windows, the first component of an absolute path
** is a drive specification (e.g. "C:").)^
**
** [[core URI query parameters]]
** The query component of a URI may contain parameters that are interpreted
** either by SQLite itself, or by a [VFS | custom VFS implementation].
** SQLite and its built-in [VFSes] interpret the
** following query parameters:
**
** <ul>
** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
** a VFS object that provides the operating system interface that should
** be used to access the database file on disk. ^If this option is set to
** an empty string the default VFS object is used. ^Specifying an unknown
** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
** present, then the VFS specified by the option takes precedence over
** the value passed as the fourth parameter to sqlite3_open_v2().
**
** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
** "rwc", or "memory". Attempting to set it to any other value is
** an error)^.
** ^If "ro" is specified, then the database is opened for read-only
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
** third argument to sqlite3_open_v2(). ^If the mode option is set to
** "rw", then the database is opened for read-write (but not create)
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
** been set. ^Value "rwc" is equivalent to setting both
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
** set to "memory" then a pure [in-memory database] that never reads
** or writes from disk is used. ^It is an error to specify a value for
** the mode parameter that is less restrictive than that specified by
** the flags passed in the third parameter to sqlite3_open_v2().
**
** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
** "private". ^Setting it to "shared" is equivalent to setting the
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
** a URI filename, its value overrides any behavior requested by setting
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
**
** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
** [powersafe overwrite] property does or does not apply to the
** storage media on which the database file resides.
**
** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
** which if set disables file locking in rollback journal modes. This
** is useful for accessing a database on a filesystem that does not
** support locking. Caution: Database corruption might result if two
** or more processes write to the same database and any one of those
** processes uses nolock=1.
**
** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
** parameter that indicates that the database file is stored on
** read-only media. ^When immutable is set, SQLite assumes that the
** database file cannot be changed, even by a process with higher
** privilege, and so the database is opened read-only and all locking
** and change detection is disabled. Caution: Setting the immutable
** property on a database file that does in fact change can result
** in incorrect query results and/or [SQLITE_CORRUPT] errors.
** See also: [SQLITE_IOCAP_IMMUTABLE].
**
** </ul>
**
** ^Specifying an unknown parameter in the query component of a URI is not an
** error. Future versions of SQLite might understand additional query
** parameters. See "[query parameters with special meaning to SQLite]" for
** additional information.
**
** [[URI filename examples]] <h3>URI filename examples</h3>
**
** <table border="1" align=center cellpadding=5>
** <tr><th> URI filenames <th> Results
** <tr><td> file:data.db <td>
** Open the file "data.db" in the current directory.
** <tr><td> file:/home/fred/data.db<br>
** file:///home/fred/data.db <br>
** file://localhost/home/fred/data.db <br> <td>
** Open the database file "/home/fred/data.db".
** <tr><td> file://darkstar/home/fred/data.db <td>
** An error. "darkstar" is not a recognized authority.
** <tr><td style="white-space:nowrap">
** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
** <td> Windows only: Open the file "data.db" on fred's desktop on drive
** C:. Note that the %20 escaping in this example is not strictly
** necessary - space characters can be used literally
** in URI filenames.
** <tr><td> file:data.db?mode=ro&cache=private <td>
** Open file "data.db" in the current directory for read-only access.
** Regardless of whether or not shared-cache mode is enabled by
** default, use a private cache.
** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
** that uses dot-files in place of posix advisory locking.
** <tr><td> file:data.db?mode=readonly <td>
** An error. "readonly" is not a valid option for the "mode" parameter.
** </table>
**
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
** query components of a URI. A hexadecimal escape sequence consists of a
** percent sign - "%" - followed by exactly two hexadecimal digits
** specifying an octet value. ^Before the path or query components of a
** URI filename are interpreted, they are encoded using UTF-8 and all
** hexadecimal escape sequences replaced by a single byte containing the
** corresponding octet. If this process generates an invalid UTF-8 encoding,
** the results are undefined.
**
** <b>Note to Windows users:</b> The encoding used for the filename argument
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
** codepage is currently defined. Filenames containing international
** characters must be converted to UTF-8 prior to passing them into
** sqlite3_open() or sqlite3_open_v2().
**
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
** features that require the use of temporary files may fail.
**
** See also: [sqlite3_temp_directory]
** CAPI3REF: Run-Time Limit Categories
** KEYWORDS: {limit category} {*limit categories}
**
** These constants define various performance limits
** that can be lowered at run-time using [sqlite3_limit()].
** The synopsis of the meanings of the various limits is shown below.
** Additional information is available at [limits | Limits in SQLite].
**
** <dl>
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
**
** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
**
** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
** <dd>The maximum number of columns in a table definition or in the
** result set of a [SELECT] or the maximum number of columns in an index
** or in an ORDER BY or GROUP BY clause.</dd>)^
**
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
**
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
**
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
** <dd>The maximum number of instructions in a virtual machine program
** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
** the equivalent tries to allocate space for more than this many opcodes
** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
**
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
** <dd>The maximum number of arguments on a function.</dd>)^
**
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
**
** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
** <dd>The maximum length of the pattern argument to the [LIKE] or
** [GLOB] operators.</dd>)^
**
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
**
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
** <dd>The maximum depth of recursion for triggers.</dd>)^
**
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
** <dd>The maximum number of auxiliary worker threads that a single
** [prepared statement] may start.</dd>)^
** </dl>
Do as much as possible w/o blocking
Number of terms in the ORDER BY clause
Flags that may be passed by the tokenizer implementation back to FTS5
** as the third argument to the supplied xToken callback.
** CAPI3REF: Database Connection Handle
** KEYWORDS: {database connection} {database connections}
**
** Each open SQLite database is represented by a pointer to an instance of
** the opaque structure named "sqlite3". It is useful to think of an sqlite3
** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
** and [sqlite3_close_v2()] are its destructors. There are many other
** interfaces (such as
** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
** [sqlite3_busy_timeout()] to name but three) that are methods on an
** sqlite3 object.
** CAPI3REF: Database Connection Status
** METHOD: sqlite3
**
** ^This interface is used to retrieve runtime status information
** about a single [database connection]. ^The first argument is the
** database connection object to be interrogated. ^The second argument
** is an integer constant, taken from the set of
** [SQLITE_DBSTATUS options], that
** determines the parameter to interrogate. The set of
** [SQLITE_DBSTATUS options] is likely
** to grow in future releases of SQLite.
**
** ^The current value of the requested parameter is written into *pCur
** and the highest instantaneous value is written into *pHiwtr. ^If
** the resetFlg is true, then the highest instantaneous value is
** reset back down to the current value.
**
** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
** non-zero [error code] on failure.
**
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
** CAPI3REF: Status Parameters for prepared statements
** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
**
** These preprocessor macros define integer codes that name counter
** values associated with the [sqlite3_stmt_status()] interface.
** The meanings of the various counters are as follows:
**
** <dl>
** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
** <dd>^This is the number of times that SQLite has stepped forward in
** a table as part of a full table scan. Large numbers for this counter
** may indicate opportunities for performance improvement through
** careful use of indices.</dd>
**
** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
** <dd>^This is the number of sort operations that have occurred.
** A non-zero value in this counter may indicate an opportunity to
** improvement performance through careful use of indices.</dd>
**
** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
** <dd>^This is the number of rows inserted into transient indices that
** were created automatically in order to help joins run faster.
** A non-zero value in this counter may indicate an opportunity to
** improvement performance by adding permanent indices that do not
** need to be reinitialized each time the statement is run.</dd>
**
** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
** <dd>^This is the number of virtual machine operations executed
** by the prepared statement if that number is less than or equal
** to 2147483647. The number of virtual machine operations can be
** used as a proxy for the total work done by the prepared statement.
** If the number of virtual machine operations exceeds 2147483647
** then the value returned by this statement status code is undefined.
**
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
** <dd>^This is the number of times that the prepare statement has been
** automatically regenerated due to schema changes or change to
** [bound parameters] that might affect the query plan.
**
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
** <dd>^This is the number of times that the prepared statement has
** been run. A single "run" for the purposes of this counter is one
** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
** The counter is incremented on the first [sqlite3_step()] call of each
** cycle.
**
** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
** <dd>^This is the approximate number of bytes of heap memory
** used to store the prepared statement. ^This value is not actually
** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
** </dd>
** </dl>
** CAPI3REF: Number Of Columns In A Result Set
** METHOD: sqlite3_stmt
**
** ^Return the number of columns in the result set returned by the
** [prepared statement]. ^If this routine returns 0, that means the
** [prepared statement] returns no data (for example an [UPDATE]).
** ^However, just because this routine returns a positive number does not
** mean that one or more rows of data will be returned. ^A SELECT statement
** will always have a positive sqlite3_column_count() but depending on the
** WHERE clause constraints and the table content, it might return no rows.
**
** See also: [sqlite3_data_count()]
Number of result columns written here
SQL statement, UTF-8 encoded
OUT: Size of WAL log in frames
The database disk image is malformed
Results of the query
Argument to xInit() and xShutdown()
Size of changeset in bytes
OUTPUT: True if column part of PK
** CAPI3REF: Collation Needed Callbacks
** METHOD: sqlite3
**
** ^To avoid having to register all collation sequences before a database
** can be used, a single callback function may be registered with the
** [database connection] to be invoked whenever an undefined collation
** sequence is required.
**
** ^If the function is registered using the sqlite3_collation_needed() API,
** then it is passed the names of undefined collation sequences as strings
** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
** the names are passed as UTF-16 in machine native byte order.
** ^A call to either function replaces the existing collation-needed callback.
**
** ^(When the callback is invoked, the first argument passed is a copy
** of the second argument to sqlite3_collation_needed() or
** sqlite3_collation_needed16(). The second argument is the database
** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
** sequence function required. The fourth parameter is the name of the
** required collation sequence.)^
**
** The callback function should register the desired collation using
** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
** [sqlite3_create_collation_v2()].
The double-precision datatype used by RTree depends on the
** SQLITE_RTREE_INT_ONLY compile-time option.
** 2014 May 31
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** Interfaces to extend FTS5. Using the interfaces defined in this file,
** FTS5 may be extended with:
**
** * custom tokenizers, and
** * custom auxiliary functions.
sqlite3_mutex_methods*
** Change the key on an open database. If the current database is not
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
** database is decrypted.
**
** The code to implement this API is not available in the public release
** of SQLite.
Number of function parameters
OUT: Number of columns in table
** CAPI3REF: Online Backup Object
**
** The sqlite3_backup object records state information about an ongoing
** online backup operation. ^The sqlite3_backup object is created by
** a call to [sqlite3_backup_init()] and is destroyed by a call to
** [sqlite3_backup_finish()].
**
** See Also: [Using the SQLite Online Backup API]
Number of bytes in buffer pB
** CAPI3REF: Authorizer Return Codes
**
** The [sqlite3_set_authorizer | authorizer callback function] must
** return either [SQLITE_OK] or one of these two constants in order
** to signal SQLite whether or not the action is permitted. See the
** [sqlite3_set_authorizer | authorizer documentation] for additional
** information.
**
** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
** returned from the [sqlite3_vtab_on_conflict()] interface.
Same position as prev. token
The database schema changed
comment:
** CAPI3REF: Tracing And Profiling Functions
** METHOD: sqlite3
**
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
** instead of the routines described here.
**
** These routines register callback functions that can be used for
** tracing and profiling the execution of SQL statements.
**
** ^The callback function registered by sqlite3_trace() is invoked at
** various times when an SQL statement is being run by [sqlite3_step()].
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
** SQL statement text as the statement first begins executing.
** ^(Additional sqlite3_trace() callbacks might occur
** as each triggered subprogram is entered. The callbacks for triggers
** contain a UTF-8 SQL comment that identifies the trigger.)^
**
** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
** the length of [bound parameter] expansion in the output of sqlite3_trace().
**
** ^The callback function registered by sqlite3_profile() is invoked
** as each SQL statement finishes. ^The profile callback contains
** the original statement text and an estimate of wall-clock time
** of how long that statement took to run. ^The profile callback
** time is in units of nanoseconds, however the current implementation
** is only capable of millisecond resolution so the six least significant
** digits in the time are meaningless. Future versions of SQLite
** might provide greater resolution on the profiler callback. The
** sqlite3_profile() function is considered experimental and is
** subject to change in future versions of SQLite.
label: code-design
Name of this virtual file system
Constraint operator
** CAPI3REF: User Data For Functions
** METHOD: sqlite3_context
**
** ^The sqlite3_user_data() interface returns a copy of
** the pointer that was the pUserData parameter (the 5th parameter)
** of the [sqlite3_create_function()]
** and [sqlite3_create_function16()] routines that originally
** registered the application defined function.
**
** This routine must be called from the same thread in which
** the application-defined function is running.
** CAPI3REF: Low-level system error code
**
** ^Attempt to return the underlying operating system error code or error
** number that caused the most recent I/O error or failure to open a file.
** The return value is OS-dependent. For example, on unix systems, after
** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
** called to get back the underlying "errno" that caused the problem, such
** as ENOSPC, EAUTH, EISDIR, and so forth.
** CAPI3REF: Delete A Session Object
**
** Delete a session object previously allocated using
** [sqlite3session_create()]. Once a session object has been deleted, the
** results of attempting to use pSession with any other session module
** function are undefined.
**
** Session objects must be deleted before the database handle to which they
** are attached is closed. Refer to the documentation for
** [sqlite3session_create()] for details.
** 2001-09-15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs. If a C-function, structure, datatype,
** or constant definition does not appear in this file, then it is
** not a published API of SQLite, is subject to change without
** notice, and should not be referenced by programs that use SQLite.
**
** Some of the definitions that are in this file are marked as
** "experimental". Experimental interfaces are normally new
** features recently added to SQLite. We do not anticipate changes
** to experimental interfaces but reserve the right to make minor changes
** if experience from use "in the wild" suggest such changes are prudent.
**
** The official C-language API documentation for SQLite is derived
** from comments in this file. This file is the authoritative source
** on how SQLite interfaces are supposed to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
Create a new auxiliary function
** CAPI3REF: Query Progress Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
** function X to be invoked periodically during long running calls to
** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
** database connection D. An example use for this
** interface is to keep a GUI updated during a large query.
**
** ^The parameter P is passed through as the only parameter to the
** callback function X. ^The parameter N is the approximate number of
** [virtual machine instructions] that are evaluated between successive
** invocations of the callback X. ^If N is less than one then the progress
** handler is disabled.
**
** ^Only a single progress handler may be defined at one time per
** [database connection]; setting a new progress handler cancels the
** old one. ^Setting parameter X to NULL disables the progress handler.
** ^The progress handler is also disabled by setting N to a value less
** than 1.
**
** ^If the progress callback returns non-zero, the operation is
** interrupted. This feature can be used to implement a
** "Cancel" button on a GUI progress dialog box.
**
** The progress handler callback must not do anything that will modify
** the database connection that invoked the progress handler.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
#define SQLITE_ABORT 4 // Also an error code
lru page list
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
** KEYWORDS: {busy-handler callback} {busy handler}
** METHOD: sqlite3
**
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
** that might be invoked with argument P whenever
** an attempt is made to access a database table associated with
** [database connection] D when another thread
** or process has the table locked.
** The sqlite3_busy_handler() interface is used to implement
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
**
** ^If the busy callback is NULL, then [SQLITE_BUSY]
** is returned immediately upon encountering the lock. ^If the busy callback
** is not NULL, then the callback might be invoked with two arguments.
**
** ^The first argument to the busy handler is a copy of the void* pointer which
** is the third argument to sqlite3_busy_handler(). ^The second argument to
** the busy handler callback is the number of times that the busy handler has
** been invoked previously for the same locking event. ^If the
** busy callback returns 0, then no additional attempts are made to
** access the database and [SQLITE_BUSY] is returned
** to the application.
** ^If the callback returns non-zero, then another attempt
** is made to access the database and the cycle repeats.
**
** The presence of a busy handler does not guarantee that it will be invoked
** when there is lock contention. ^If SQLite determines that invoking the busy
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
** to the application instead of invoking the
** busy handler.
** Consider a scenario where one process is holding a read lock that
** it is trying to promote to a reserved lock and
** a second process is holding a reserved lock that it is trying
** to promote to an exclusive lock. The first process cannot proceed
** because it is blocked by the second and the second process cannot
** proceed because it is blocked by the first. If both processes
** invoke the busy handlers, neither will make any progress. Therefore,
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
** will induce the first process to release its read lock and allow
** the second process to proceed.
**
** ^The default busy callback is NULL.
**
** ^(There can only be a single busy handler defined for each
** [database connection]. Setting a new busy handler clears any
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
** or evaluating [PRAGMA busy_timeout=N] will change the
** busy handler and thus clear any previously set busy handler.
**
** The busy callback should not take any actions which modify the
** database connection that invoked the busy handler. In other words,
** the busy handler is not reentrant. Any such actions
** result in undefined behavior.
**
** A busy handler must not close the database connection
** or [prepared statement] that invoked the busy handler.
OUT: Inverse of input
comment:
** CAPI3REF: Deprecated Functions
** DEPRECATED
**
** These functions are [deprecated]. In order to maintain
** backwards compatibility with older code, these functions continue
** to be supported. However, new applications should avoid
** the use of these functions. To encourage programmers to avoid
** these functions, we will not explain what they do.
label: code-design
An open database
** CAPI3REF: Read Data From A BLOB Incrementally
** METHOD: sqlite3_blob
**
** ^(This function is used to read data from an open [BLOB handle] into a
** caller-supplied buffer. N bytes of data are copied into buffer Z
** from the open BLOB, starting at offset iOffset.)^
**
** ^If offset iOffset is less than N bytes from the end of the BLOB,
** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is
** less than zero, [SQLITE_ERROR] is returned and no data is read.
** ^The size of the blob (and hence the maximum value of N+iOffset)
** can be determined using the [sqlite3_blob_bytes()] interface.
**
** ^An attempt to read from an expired [BLOB handle] fails with an
** error code of [SQLITE_ABORT].
**
** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
** Otherwise, an [error code] or an [extended error code] is returned.)^
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
**
** See also: [sqlite3_blob_write()].
comment:
** CAPI3REF: Mutex Types
**
** The [sqlite3_mutex_alloc()] interface takes a single argument
** which is one of these integer constants.
**
** The set of static mutexes may change from one SQLite release to the
** next. Applications that override the built-in mutex logic must be
** prepared to accommodate additional static mutexes.
label: code-design
Visibility of parent node
comment: Not used
label: code-design
Column number
Index Name Table Name
Text to tokenize
** CAPI3REF: Virtual Table Instance Object
** KEYWORDS: sqlite3_vtab
**
** Every [virtual table module] implementation uses a subclass
** of this object to describe a particular instance
** of the [virtual table]. Each subclass will
** be tailored to the specific needs of the module implementation.
** The purpose of this superclass is to define certain fields that are
** common to all module implementations.
**
** ^Virtual tables methods can set an error message by assigning a
** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should
** take care that any prior string is freed by a call to [sqlite3_free()]
** prior to assigning a new string to zErrMsg. ^After the error message
** is delivered up to the client application, the string will be automatically
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
** CAPI3REF: Conflict resolution modes
** KEYWORDS: {conflict resolution mode}
**
** These constants are returned by [sqlite3_vtab_on_conflict()] to
** inform a [virtual table] implementation what the [ON CONFLICT] mode
** is for the SQL statement being evaluated.
**
** Note that the [SQLITE_IGNORE] constant is also used as a potential
** return value from the [sqlite3_set_authorizer()] callback and that
** [SQLITE_ABORT] is also a [result code].
comment:
** CAPI3REF: Constants Defining Special Destructor Behavior
**
** These are special values for the destructor that is passed in as the
** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
** argument is SQLITE_STATIC, it means that the content pointer is constant
** and will never change. It does not need to be destroyed. ^The
** SQLITE_TRANSIENT value means that the content will likely change in
** the near future and that SQLite should make its own private copy of
** the content before returning.
**
** The typedef is necessary to work around problems in certain
** C++ compilers.
label: code-design
comment:
** CAPI3REF: Memory Allocator Statistics
**
** SQLite provides these two interfaces for reporting on the status
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
** routines, which form the built-in memory allocation subsystem.
**
** ^The [sqlite3_memory_used()] routine returns the number of bytes
** of memory currently outstanding (malloced but not freed).
** ^The [sqlite3_memory_highwater()] routine returns the maximum
** value of [sqlite3_memory_used()] since the high-water mark
** was last reset. ^The values returned by [sqlite3_memory_used()] and
** [sqlite3_memory_highwater()] include any overhead
** added by SQLite in its implementation of [sqlite3_malloc()],
** but not overhead added by the any underlying system library
** routines that [sqlite3_malloc()] may call.
**
** ^The memory high-water mark is reset to the current value of
** [sqlite3_memory_used()] if and only if the parameter to
** [sqlite3_memory_highwater()] is true. ^The value returned
** by [sqlite3_memory_highwater(1)] is the high-water mark
** prior to the reset.
label: code-design
Memory allocation function
Maximum file pathname length
sqlite3_randomness()
OUT: True for an 'indirect' change
comment:
** CAPI3REF: Obtain old.* Values From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
** Furthermore, it may only be called if the type of change that the iterator
** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the vector of
** original row values stored as part of the UPDATE or DELETE change and
** returns SQLITE_OK. The name of the function comes from the fact that this
** is similar to the "old.*" columns available to update or delete triggers.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
Virtual table of this cursor
Operation NULL
comment:
** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
** is not the case, this function returns [SQLITE_MISUSE].
**
** If argument pzTab is not NULL, then *pzTab is set to point to a
** nul-terminated utf-8 encoded string containing the name of the table
** affected by the current change. The buffer remains valid until either
** sqlite3changeset_next() is called on the iterator or until the
** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
** set to the number of columns in the table affected by the change. If
** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change
** is an indirect change, or false (0) otherwise. See the documentation for
** [sqlite3session_indirect()] for a description of direct and indirect
** changes. Finally, if pOp is not NULL, then *pOp is set to one of
** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
** type of change that the iterator currently points to.
**
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
** SQLite error code is returned. The values of the output variables may not
** be trusted in this case.
label: code-design
comment:
** CAPI3REF: Apply A Changeset To A Database
**
** Apply a changeset to a database. This function attempts to update the
** "main" database attached to handle db with the changes found in the
** changeset passed via the second and third arguments.
**
** The fourth argument (xFilter) passed to this function is the "filter
** callback". If it is not NULL, then for each table affected by at least one
** change in the changeset, the filter callback is invoked with
** the table name as the second argument, and a copy of the context pointer
** passed as the sixth argument to this function as the first. If the "filter
** callback" returns zero, then no attempt is made to apply any changes to
** the table. Otherwise, if the return value is non-zero or the xFilter
** argument to this function is NULL, all changes related to the table are
** attempted.
**
** For each table that is not excluded by the filter callback, this function
** tests that the target database contains a compatible table. A table is
** considered compatible if all of the following are true:
**
** <ul>
** <li> The table has the same name as the name recorded in the
** changeset, and
** <li> The table has at least as many columns as recorded in the
** changeset, and
** <li> The table has primary key columns in the same position as
** recorded in the changeset.
** </ul>
**
** If there is no compatible table, it is not an error, but none of the
** changes associated with the table are applied. A warning message is issued
** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
** one such warning is issued for each table in the changeset.
**
** For each change for which there is a compatible table, an attempt is made
** to modify the table contents according to the UPDATE, INSERT or DELETE
** change. If a change cannot be applied cleanly, the conflict handler
** function passed as the fifth argument to sqlite3changeset_apply() may be
** invoked. A description of exactly when the conflict handler is invoked for
** each type of change is below.
**
** Unlike the xFilter argument, xConflict may not be passed NULL. The results
** of passing anything other than a valid function pointer as the xConflict
** argument are undefined.
**
** Each time the conflict handler function is invoked, it must return one
** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
** if the second argument passed to the conflict handler is either
** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
** returns an illegal value, any changes already made are rolled back and
** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
** actions are taken by sqlite3changeset_apply() depending on the value
** returned by each invocation of the conflict-handler function. Refer to
** the documentation for the three
** [SQLITE_CHANGESET_OMIT|available return values] for details.
**
** <dl>
** <dt>DELETE Changes<dd>
** For each DELETE change, this function checks if the target database
** contains a row with the same primary key value (or values) as the
** original row values stored in the changeset. If it does, and the values
** stored in all non-primary key columns also match the values stored in
** the changeset the row is deleted from the target database.
**
** If a row with matching primary key values is found, but one or more of
** the non-primary key fields contains a value different from the original
** row value stored in the changeset, the conflict-handler function is
** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
** database table has more columns than are recorded in the changeset,
** only the values of those non-primary key fields are compared against
** the current database contents - any trailing database table columns
** are ignored.
**
** If no row with matching primary key values is found in the database,
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
** passed as the second argument.
**
** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
** (which can only happen if a foreign key constraint is violated), the
** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
** passed as the second argument. This includes the case where the DELETE
** operation is attempted because an earlier call to the conflict handler
** function returned [SQLITE_CHANGESET_REPLACE].
**
** <dt>INSERT Changes<dd>
** For each INSERT change, an attempt is made to insert the new row into
** the database. If the changeset row contains fewer fields than the
** database table, the trailing fields are populated with their default
** values.
**
** If the attempt to insert the row fails because the database already
** contains a row with the same primary key values, the conflict handler
** function is invoked with the second argument set to
** [SQLITE_CHANGESET_CONFLICT].
**
** If the attempt to insert the row fails because of some other constraint
** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
** This includes the case where the INSERT operation is re-attempted because
** an earlier call to the conflict handler function returned
** [SQLITE_CHANGESET_REPLACE].
**
** <dt>UPDATE Changes<dd>
** For each UPDATE change, this function checks if the target database
** contains a row with the same primary key value (or values) as the
** original row values stored in the changeset. If it does, and the values
** stored in all modified non-primary key columns also match the values
** stored in the changeset the row is updated within the target database.
**
** If a row with matching primary key values is found, but one or more of
** the modified non-primary key fields contains a value different from an
** original row value stored in the changeset, the conflict-handler function
** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
** UPDATE changes only contain values for non-primary key fields that are
** to be modified, only those fields need to match the original values to
** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
**
** If no row with matching primary key values is found in the database,
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
** passed as the second argument.
**
** If the UPDATE operation is attempted, but SQLite returns
** SQLITE_CONSTRAINT, the conflict-handler function is invoked with
** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
** This includes the case where the UPDATE operation is attempted after
** an earlier call to the conflict handler function returned
** [SQLITE_CHANGESET_REPLACE].
** </dl>
**
** It is safe to execute SQL statements, including those that write to the
** table that the callback related to, from within the xConflict callback.
** This can be used to further customize the applications conflict
** resolution strategy.
**
** All changes made by this function are enclosed in a savepoint transaction.
** If any other error (aside from a constraint failure when attempting to
** write to the target database) occurs, then the savepoint transaction is
** rolled back, restoring the target database to its original state, and an
** SQLite error code returned.
label: code-design
comment:
** CAPI3REF: Formatted String Printing Functions
**
** These routines are work-alikes of the "printf()" family of functions
** from the standard C library.
** These routines understand most of the common K&R formatting options,
** plus some additional non-standard formats, detailed below.
** Note that some of the more obscure formatting options from recent
** C-library standards are omitted from this implementation.
**
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
** results into memory obtained from [sqlite3_malloc()].
** The strings returned by these two routines should be
** released by [sqlite3_free()]. ^Both routines return a
** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
** memory to hold the resulting string.
**
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
** the standard C library. The result is written into the
** buffer supplied as the second parameter whose size is given by
** the first parameter. Note that the order of the
** first two parameters is reversed from snprintf().)^ This is an
** historical accident that cannot be fixed without breaking
** backwards compatibility. ^(Note also that sqlite3_snprintf()
** returns a pointer to its buffer instead of the number of
** characters actually written into the buffer.)^ We admit that
** the number of characters written would be a more useful return
** value but we cannot change the implementation of sqlite3_snprintf()
** now without breaking compatibility.
**
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
** guarantees that the buffer is always zero-terminated. ^The first
** parameter "n" is the total size of the buffer, including space for
** the zero terminator. So the longest string that can be completely
** written will be n-1 characters.
**
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
**
** These routines all implement some additional formatting
** options that are useful for constructing SQL statements.
** All of the usual printf() formatting options apply. In addition, there
** is are "%q", "%Q", "%w" and "%z" options.
**
** ^(The %q option works like %s in that it substitutes a nul-terminated
** string from the argument list. But %q also doubles every '\'' character.
** %q is designed for use inside a string literal.)^ By doubling each '\''
** character it escapes that character and allows it to be inserted into
** the string.
**
** For example, assume the string variable zText contains text as follows:
**
** <blockquote><pre>
** char *zText = "It's a happy day!";
** </pre></blockquote>
**
** One can use this text in an SQL statement as follows:
**
** <blockquote><pre>
** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
** sqlite3_exec(db, zSQL, 0, 0, 0);
** sqlite3_free(zSQL);
** </pre></blockquote>
**
** Because the %q format string is used, the '\'' character in zText
** is escaped and the SQL generated is as follows:
**
** <blockquote><pre>
** INSERT INTO table1 VALUES('It''s a happy day!')
** </pre></blockquote>
**
** This is correct. Had we used %s instead of %q, the generated SQL
** would have looked like this:
**
** <blockquote><pre>
** INSERT INTO table1 VALUES('It's a happy day!');
** </pre></blockquote>
**
** This second example is an SQL syntax error. As a general rule you should
** always use %q instead of %s when inserting text into a string literal.
**
** ^(The %Q option works like %q except it also adds single quotes around
** the outside of the total string. Additionally, if the parameter in the
** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
** single quotes).)^ So, for example, one could say:
**
** <blockquote><pre>
** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
** sqlite3_exec(db, zSQL, 0, 0, 0);
** sqlite3_free(zSQL);
** </pre></blockquote>
**
** The code above will render a correct SQL statement in the zSQL
** variable even if the zText variable is a NULL pointer.
**
** ^(The "%w" formatting option is like "%q" except that it expects to
** be contained within double-quotes instead of single quotes, and it
** escapes the double-quote character instead of the single-quote
** character.)^ The "%w" formatting option is intended for safely inserting
** table and column names into a constructed SQL statement.
**
** ^(The "%z" formatting option works like "%s" but with the
** addition that after the string has been read and copied into
** the result, [sqlite3_free()] is called on the input string.)^
label: code-design
** CAPI3REF: Fundamental Datatypes
** KEYWORDS: SQLITE_TEXT
**
** ^(Every value in SQLite has one of five fundamental datatypes:
**
** <ul>
** <li> 64-bit signed integer
** <li> 64-bit IEEE floating point number
** <li> string
** <li> BLOB
** <li> NULL
** </ul>)^
**
** These constants are codes for each of those types.
**
** Note that the SQLITE_TEXT constant was also used in SQLite version 2
** for a completely different meaning. Software that links against both
** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
** SQLITE_TEXT.
OUTPUT: Declared data type
Free idxStr using sqlite3_free() if true
** Provide the ability to override linkage features of the interface.
OUT: SQLite db handle
True if this constraint is usable
** CAPI3REF: Setting The Subtype Of An SQL Function
** METHOD: sqlite3_context
**
** The sqlite3_result_subtype(C,T) function causes the subtype of
** the result from the [application-defined SQL function] with
** [sqlite3_context] C to be the value T. Only the lower 8 bits
** of the subtype T are preserved in current versions of SQLite;
** higher order bits are discarded.
** The number of subtype bytes preserved by SQLite might increase
** in future releases of SQLite.
SQLITE3_H
Estimated number of rows returned
comment:
** CAPI3REF: Destroy A Prepared Statement Object
** DESTRUCTOR: sqlite3_stmt
**
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
** ^If the most recent evaluation of the statement encountered no errors
** or if the statement is never been evaluated, then sqlite3_finalize() returns
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
** sqlite3_finalize(S) returns the appropriate [error code] or
** [extended error code].
**
** ^The sqlite3_finalize(S) routine can be called at any point during
** the life cycle of [prepared statement] S:
** before statement S is ever evaluated, after
** one or more calls to [sqlite3_reset()], or after any call
** to [sqlite3_step()] regardless of whether or not the statement has
** completed execution.
**
** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
**
** The application must finalize every [prepared statement] in order to avoid
** resource leaks. It is a grievous error for the application to try to use
** a prepared statement after it has been finalized. Any use of a prepared
** statement after it has been finalized can result in undefined and
** undesirable behavior such as segfaults and heap corruption.
label: code-design
Callback function to invoke
comment:
** CAPI3REF: Standard File Control Opcodes
** KEYWORDS: {file control opcodes} {file control opcode}
**
** These integer constants are opcodes for the xFileControl method
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
** interface.
**
** <ul>
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
** opcode causes the xFileControl method to write the current state of
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
** into an integer that the pArg argument points to. This capability
** is used during testing and is only available when the SQLITE_TEST
** compile-time option is used.
**
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
** layer a hint of how large the database file will grow to be during the
** current transaction. This hint is not guaranteed to be accurate but it
** is often close. The underlying VFS might choose to preallocate database
** file space based on this hint in order to help writes to the database
** file run faster.
**
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
** extends and truncates the database file in chunks of a size specified
** by the user. The fourth argument to [sqlite3_file_control()] should
** point to an integer (type int) containing the new chunk-size to use
** for the nominated database. Allocating database file space in large
** chunks (say 1MB at a time), may reduce file-system fragmentation and
** improve performance on some systems.
**
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with a particular database
** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
**
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
** to the [sqlite3_file] object associated with the journal file (either
** the [rollback journal] or the [write-ahead log]) for a particular database
** connection. See also [SQLITE_FCNTL_FILE_POINTER].
**
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
** No longer in use.
**
** <li>[[SQLITE_FCNTL_SYNC]]
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
** sent to the VFS immediately before the xSync method is invoked on a
** database file descriptor. Or, if the xSync method is not invoked
** because the user has configured SQLite with
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
** of the xSync method. In most cases, the pointer argument passed with
** this file-control is NULL. However, if the database file is being synced
** as part of a multi-database commit, the argument points to a nul-terminated
** string containing the transactions master-journal file name. VFSes that
** do not need this signal should silently ignore this opcode. Applications
** should not call [sqlite3_file_control()] with this opcode as doing so may
** disrupt the operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
** and sent to the VFS after a transaction has been committed immediately
** but before the database is unlocked. VFSes that do not need this signal
** should silently ignore this opcode. Applications should not call
** [sqlite3_file_control()] with this opcode as doing so may disrupt the
** operation of the specialized VFSes that do require it.
**
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
** retry counts and intervals for certain disk I/O operations for the
** windows [VFS] in order to provide robustness in the presence of
** anti-virus programs. By default, the windows VFS will retry file read,
** file write, and file delete operations up to 10 times, with a delay
** of 25 milliseconds before the first retry and with the delay increasing
** by an additional 25 milliseconds with each subsequent retry. This
** opcode allows these two values (10 retries and 25 milliseconds of delay)
** to be adjusted. The values are changed for all database connections
** within the same process. The argument is a pointer to an array of two
** integers where the first integer is the new retry count and the second
** integer is the delay. If either integer is negative, then the setting
** is not changed but instead the prior value of that setting is written
** into the array entry, allowing the current retry settings to be
** interrogated. The zDbName parameter is ignored.
**
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
** write ahead log and shared memory files used for transaction control
** are automatically deleted when the latest connection to the database
** closes. Setting persistent WAL mode causes those files to persist after
** close. Persisting the files is useful when other processes that do not
** have write permission on the directory containing the database file want
** to read the database file, as the WAL and shared memory files must exist
** in order for the database to be readable. The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
** WAL mode. If the integer is -1, then it is overwritten with the current
** WAL persistence setting.
**
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
** xDeviceCharacteristics methods. The fourth parameter to
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
** mode. If the integer is -1, then it is overwritten with the current
** zero-damage mode setting.
**
** <li>[[SQLITE_FCNTL_OVERWRITE]]
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
** a write transaction to indicate that, unless it is rolled back for some
** reason, the entire database file will be overwritten by the current
** transaction. This is used by VACUUM operations.
**
** <li>[[SQLITE_FCNTL_VFSNAME]]
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
** all [VFSes] in the VFS stack. The names are of all VFS shims and the
** final bottom-level VFS are written into memory obtained from
** [sqlite3_malloc()] and the result is stored in the char* variable
** that the fourth parameter of [sqlite3_file_control()] points to.
** The caller is responsible for freeing the memory when done. As with
** all file-control actions, there is no guarantee that this will actually
** do anything. Callers should initialize the char* variable to a NULL
** pointer in case this file-control is not implemented. This file-control
** is intended for diagnostic use only.
**
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
** [VFSes] currently in use. ^(The argument X in
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
** of type "[sqlite3_vfs] **". This opcodes will set *X
** to a pointer to the top-level VFS.)^
** ^When there are multiple VFS shims in the stack, this opcode finds the
** upper-most shim only.
**
** <li>[[SQLITE_FCNTL_PRAGMA]]
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
** file control is sent to the open [sqlite3_file] object corresponding
** to the database file to which the pragma statement refers. ^The argument
** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
** pointers to strings (char**) in which the second element of the array
** is the name of the pragma and the third element is the argument to the
** pragma or NULL if the pragma has no argument. ^The handler for an
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
** or the equivalent and that string will become the result of the pragma or
** the error message if the pragma fails. ^If the
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
** file control returns [SQLITE_OK], then the parser assumes that the
** VFS has handled the PRAGMA itself and the parser generates a no-op
** prepared statement if result string is NULL, or that returns a copy
** of the result string if the string is non-NULL.
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
** that the VFS encountered an error while handling the [PRAGMA] and the
** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
** file control occurs at the beginning of pragma statement analysis and so
** it is able to override built-in [PRAGMA] statements.
**
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
** ^The [SQLITE_FCNTL_BUSYHANDLER]
** file-control may be invoked by SQLite on the database file handle
** shortly after it is opened in order to provide a custom VFS with access
** to the connections busy-handler callback. The argument is of type (void **)
** - an array of two (void *) values. The first (void *) actually points
** to a function of type (int (*)(void *)). In order to invoke the connections
** busy-handler, this function should be invoked with the second (void *) in
** the array as the only argument. If it returns non-zero, then the operation
** should be retried. If it returns zero, the custom VFS should abandon the
** current operation.
**
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
** to have SQLite generate a
** temporary filename using the same algorithm that is followed to generate
** temporary filenames for TEMP tables and other internal uses. The
** argument should be a char** which will be filled with the filename
** written into memory obtained from [sqlite3_malloc()]. The caller should
** invoke [sqlite3_free()] on the result to avoid a memory leak.
**
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
** maximum number of bytes that will be used for memory-mapped I/O.
** The argument is a pointer to a value of type sqlite3_int64 that
** is an advisory maximum number of bytes in the file to memory map. The
** pointer is overwritten with the old value. The limit is not changed if
** the value originally pointed to is negative, and so the current limit
** can be queried by passing in a pointer to a negative number. This
** file-control is used internally to implement [PRAGMA mmap_size].
**
** <li>[[SQLITE_FCNTL_TRACE]]
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
** to the VFS about what the higher layers of the SQLite stack are doing.
** This file control is used by some VFS activity tracing [shims].
** The argument is a zero-terminated string. Higher layers in the
** SQLite stack may generate instances of this file control if
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
**
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
** pointer to an integer and it writes a boolean into that integer depending
** on whether or not the file has been renamed, moved, or deleted since it
** was first opened.
**
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
** underlying native file handle associated with a file handle. This file
** control interprets its argument as a pointer to a native file handle and
** writes the resulting value there.
**
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
** opcode causes the xFileControl method to swap the file handle with the one
** pointed to by the pArg argument. This capability is used during testing
** and only needs to be supported when SQLITE_TEST is defined.
**
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
** be advantageous to block on the next WAL lock if the lock is not immediately
** available. The WAL subsystem issues this signal during rare
** circumstances in order to fix a problem with priority inversion.
** Applications should <em>not</em> use this file-control.
**
** <li>[[SQLITE_FCNTL_ZIPVFS]]
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
** VFS should return SQLITE_NOTFOUND for this opcode.
**
** <li>[[SQLITE_FCNTL_RBU]]
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
** this opcode.
** </ul>
label: code-design
Methods for an open file
comment:
** This is the obsolete pcache_methods object that has now been replaced
** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
** retained in the header file for backwards compatibility only.
label: code-design
String, possibly obtained from sqlite3_malloc
************************************************************************
** CUSTOM AUXILIARY FUNCTIONS
**
** Virtual table implementations may overload SQL functions by implementing
** the sqlite3_module.xFindFunction() method.
Fields below are only available in SQLite 3.10.0 and later
Name of the shared library containing extension
Destination database name
Array of trailing arguments
Callback
** CAPI3REF: Maximum xShmLock index
**
** The xShmLock method on [sqlite3_io_methods] may use values
** between 0 and this upper bound as its "offset" argument.
** The SQLite core will never attempt to acquire or release a
** lock outside of this range
comment:
** CAPI3REF: Count The Number Of Rows Modified
** METHOD: sqlite3
**
** ^This function returns the number of rows modified, inserted or
** deleted by the most recently completed INSERT, UPDATE or DELETE
** statement on the database connection specified by the only parameter.
** ^Executing any other type of SQL statement does not modify the value
** returned by this function.
**
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
**
** Changes to a view that are intercepted by
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
** DELETE statement run on a view is always zero. Only changes made to real
** tables are counted.
**
** Things are more complicated if the sqlite3_changes() function is
** executed while a trigger program is running. This may happen if the
** program uses the [changes() SQL function], or if some other callback
** function invokes sqlite3_changes() directly. Essentially:
**
** <ul>
** <li> ^(Before entering a trigger program the value returned by
** sqlite3_changes() function is saved. After the trigger program
** has finished, the original value is restored.)^
**
** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
** statement sets the value returned by sqlite3_changes()
** upon completion as normal. Of course, this value will not include
** any changes performed by sub-triggers, as the sqlite3_changes()
** value will be saved and restored after each sub-trigger has run.)^
** </ul>
**
** ^This means that if the changes() SQL function (or similar) is used
** by the first INSERT, UPDATE or DELETE statement within a trigger, it
** returns the value as set when the calling statement began executing.
** ^If it is used by the second or subsequent such statement within a trigger
** program, the value returned reflects the number of rows modified by the
** previous INSERT, UPDATE or DELETE statement within the same trigger.
**
** See also the [sqlite3_total_changes()] interface, the
** [count_changes pragma], and the [changes() SQL function].
**
** If a separate thread makes changes on the same database connection
** while [sqlite3_changes()] is running then the value returned
** is unpredictable and not meaningful.
label: code-design
Pragma Name 1st arg or NULL
Module destructor function
comment:
** The interface to the virtual-table mechanism is currently considered
** to be experimental. The interface might change in incompatible ways.
** If this is a problem for you, do not use the interface at this time.
**
** When the virtual-table mechanism stabilizes, we will declare the
** interface fixed, support it indefinitely, and remove this comment.
label: code-design
Client data for xCreate/xConnect
** CAPI3REF: Write Data Into A BLOB Incrementally
** METHOD: sqlite3_blob
**
** ^(This function is used to write data into an open [BLOB handle] from a
** caller-supplied buffer. N bytes of data are copied from the buffer Z
** into the open BLOB, starting at offset iOffset.)^
**
** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
** Otherwise, an [error code] or an [extended error code] is returned.)^
** ^Unless SQLITE_MISUSE is returned, this function sets the
** [database connection] error code and message accessible via
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
**
** ^If the [BLOB handle] passed as the first argument was not opened for
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
** this function returns [SQLITE_READONLY].
**
** This function may only modify the contents of the BLOB; it is
** not possible to increase the size of a BLOB using this API.
** ^If offset iOffset is less than N bytes from the end of the BLOB,
** [SQLITE_ERROR] is returned and no data is written. The size of the
** BLOB (and hence the maximum value of N+iOffset) can be determined
** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
** than zero [SQLITE_ERROR] is returned and no data is written.
**
** ^An attempt to write to an expired [BLOB handle] fails with an
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
** before the [BLOB handle] expired are not rolled back by the
** expiration of the handle, though of course those changes might
** have been overwritten by the statement that expired the BLOB handle
** or by other independent statements.
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
**
** See also: [sqlite3_blob_read()].
ifndef _SQLITE3RTREE_H_
NULL Function Name
** CAPI3REF: Determine if a database is read-only
** METHOD: sqlite3
**
** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
** the name of a database on connection D.
#define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback
** CAPI3REF: SQLite Runtime Status
**
** ^These interfaces are used to retrieve runtime status information
** about the performance of SQLite, and optionally to reset various
** highwater marks. ^The first argument is an integer code for
** the specific parameter to measure. ^(Recognized integer codes
** are of the form [status parameters | SQLITE_STATUS_...].)^
** ^The current value of the parameter is returned into *pCurrent.
** ^The highest recorded value is returned in *pHighwater. ^If the
** resetFlag is true, then the highest record value is reset after
** *pHighwater is written. ^(Some parameters do not record the highest
** value. For those parameters
** nothing is written into *pHighwater and the resetFlag is ignored.)^
** ^(Other parameters record only the highwater mark and not the current
** value. For these latter parameters nothing is written into *pCurrent.)^
**
** ^The sqlite3_status() and sqlite3_status64() routines return
** SQLITE_OK on success and a non-zero [error code] on failure.
**
** If either the current value or the highwater mark is too large to
** be represented by a 32-bit integer, then the values returned by
** sqlite3_status() are undefined.
**
** See also: [sqlite3_db_status()]
Level of current node or entry
comment:
** CAPI3REF: Record A Database Snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
** new [sqlite3_snapshot] object that records the current state of
** schema S in database connection D. ^On success, the
** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
** If there is not already a read-transaction open on schema S when
** this function is called, one is opened automatically.
**
** The following must be true for this function to succeed. If any of
** the following statements are false when sqlite3_snapshot_get() is
** called, SQLITE_ERROR is returned. The final value of *P is undefined
** in this case.
**
** <ul>
** <li> The database handle must be in [autocommit mode].
**
** <li> Schema S of [database connection] D must be a [WAL mode] database.
**
** <li> There must not be a write transaction open on schema S of database
** connection D.
**
** <li> One or more transactions must have been written to the current wal
** file since it was created on disk (by any connection). This means
** that a snapshot cannot be taken on a wal mode database with no wal
** file immediately after it is first opened. At least one transaction
** must be written to it first.
** </ul>
**
** This function may also return SQLITE_NOMEM. If it is called with the
** database handle in autocommit mode but fails for some other reason,
** whether or not a read transaction is opened on schema S is undefined.
**
** The [sqlite3_snapshot] object returned from a successful call to
** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
** to avoid a memory leak.
**
** The [sqlite3_snapshot_get()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
label: code-design
** CAPI3REF: Commit And Rollback Notification Callbacks
** METHOD: sqlite3
**
** ^The sqlite3_commit_hook() interface registers a callback
** function to be invoked whenever a transaction is [COMMIT | committed].
** ^Any callback set by a previous call to sqlite3_commit_hook()
** for the same database connection is overridden.
** ^The sqlite3_rollback_hook() interface registers a callback
** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
** ^Any callback set by a previous call to sqlite3_rollback_hook()
** for the same database connection is overridden.
** ^The pArg argument is passed through to the callback.
** ^If the callback on a commit hook function returns non-zero,
** then the commit is converted into a rollback.
**
** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
** return the P argument from the previous call of the same function
** on the same [database connection] D, or NULL for
** the first call for each function on D.
**
** The commit and rollback hook callbacks are not reentrant.
** The callback implementation must not do anything that will modify
** the database connection that invoked the callback. Any actions
** to modify the database connection must be deferred until after the
** completion of the [sqlite3_step()] call that triggered the commit
** or rollback hook in the first place.
** Note that running any other SQL statements, including SELECT statements,
** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
** the database connections for the meaning of "modify" in this paragraph.
**
** ^Registering a NULL function disables the callback.
**
** ^When the commit hook callback routine returns zero, the [COMMIT]
** operation is allowed to continue normally. ^If the commit hook
** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
** ^The rollback hook is invoked on a rollback that results from a commit
** hook returning non-zero, just as it would be with any other rollback.
**
** ^For the purposes of this API, a transaction is said to have been
** rolled back if an explicit "ROLLBACK" statement is executed, or
** an error or constraint causes an implicit rollback to occur.
** ^The rollback callback is not invoked if a transaction is
** automatically rolled back because the database connection is closed.
**
** See also the [sqlite3_update_hook()] interface.
comment:
** CAPI3REF: Dynamically Typed Value Object
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
**
** SQLite uses the sqlite3_value object to represent all values
** that can be stored in a database table. SQLite uses dynamic typing
** for the values it stores. ^Values stored in sqlite3_value objects
** can be integers, floating point values, strings, BLOBs, or NULL.
**
** An sqlite3_value object may be either "protected" or "unprotected".
** Some interfaces require a protected sqlite3_value. Other interfaces
** will accept either a protected or an unprotected sqlite3_value.
** Every interface that accepts sqlite3_value arguments specifies
** whether or not it requires a protected sqlite3_value. The
** [sqlite3_value_dup()] interface can be used to construct a new
** protected sqlite3_value from an unprotected sqlite3_value.
**
** The terms "protected" and "unprotected" refer to whether or not
** a mutex is held. An internal mutex is held for a protected
** sqlite3_value object but no mutex is held for an unprotected
** sqlite3_value object. If SQLite is compiled to be single-threaded
** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
** or if SQLite is run in one of reduced mutex modes
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
** then there is no distinction between protected and unprotected
** sqlite3_value objects and they can be used interchangeably. However,
** for maximum code portability it is recommended that applications
** still make the distinction between protected and unprotected
** sqlite3_value objects even when not strictly required.
**
** ^The sqlite3_value objects that are passed as parameters into the
** implementation of [application-defined SQL functions] are protected.
** ^The sqlite3_value object returned by
** [sqlite3_column_value()] is unprotected.
** Unprotected sqlite3_value objects may only be used with
** [sqlite3_result_value()] and [sqlite3_bind_value()].
** The [sqlite3_value_blob | sqlite3_value_type()] family of
** interfaces require protected sqlite3_value objects.
label: code-design
** CAPI3REF: Overload A Function For A Virtual Table
** METHOD: sqlite3
**
** ^(Virtual tables can provide alternative implementations of functions
** using the [xFindFunction] method of the [virtual table module].
** But global versions of those functions
** must exist in order to be overloaded.)^
**
** ^(This API makes sure a global version of a function with a particular
** name and number of parameters exists. If no such function exists
** before this API is called, a new function is created.)^ ^The implementation
** of the new function always causes an exception to be thrown. So
** the new function is not good for anything by itself. Its only
** purpose is to be a placeholder function that can be overloaded
** by a [virtual table].
OUTPUT: True if NOT NULL constraint exists
Unable to open the database file
** Specify the activation key for a SEE database. Unless
** activated, none of the SEE routines will work.
** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
comment:
** CAPI3REF: Streaming Versions of API functions.
**
** The six streaming API xxx_strm() functions serve similar purposes to the
** corresponding non-streaming API functions:
**
** <table border=1 style="margin-left:8ex;margin-right:8ex">
** <tr><th>Streaming function<th>Non-streaming equivalent</th>
** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
** </table>
**
** Non-streaming functions that accept changesets (or patchsets) as input
** require that the entire changeset be stored in a single buffer in memory.
** Similarly, those that return a changeset or patchset do so by returning
** a pointer to a single large buffer allocated using sqlite3_malloc().
** Normally this is convenient. However, if an application running in a
** low-memory environment is required to handle very large changesets, the
** large contiguous memory allocations required can become onerous.
**
** In order to avoid this problem, instead of a single large buffer, input
** is passed to a streaming API functions by way of a callback function that
** the sessions module invokes to incrementally request input data as it is
** required. In all cases, a pair of API function parameters such as
**
** <pre>
** int nChangeset,
** void *pChangeset,
** </pre>
**
** Is replaced by:
**
** <pre>
** int (*xInput)(void *pIn, void *pData, int *pnData),
** void *pIn,
** </pre>
**
** Each time the xInput callback is invoked by the sessions module, the first
** argument passed is a copy of the supplied pIn context pointer. The second
** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
** error occurs the xInput method should copy up to (*pnData) bytes of data
** into the buffer and set (*pnData) to the actual number of bytes copied
** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
** should be set to zero to indicate this. Or, if an error occurs, an SQLite
** error code should be returned. In all cases, if an xInput callback returns
** an error, all processing is abandoned and the streaming API function
** returns a copy of the error code to the caller.
**
** In the case of sqlite3changeset_start_strm(), the xInput callback may be
** invoked by the sessions module at any point during the lifetime of the
** iterator. If such an xInput callback returns an error, the iterator enters
** an error state, whereby all subsequent calls to iterator functions
** immediately fail with the same error code as returned by xInput.
**
** Similarly, streaming API functions that return changesets (or patchsets)
** return them in chunks by way of a callback function instead of via a
** pointer to a single large buffer. In this case, a pair of parameters such
** as:
**
** <pre>
** int *pnChangeset,
** void **ppChangeset,
** </pre>
**
** Is replaced by:
**
** <pre>
** int (*xOutput)(void *pOut, const void *pData, int nData),
** void *pOut
** </pre>
**
** The xOutput callback is invoked zero or more times to return data to
** the application. The first parameter passed to each call is a copy of the
** pOut pointer supplied by the application. The second parameter, pData,
** points to a buffer nData bytes in size containing the chunk of output
** data being returned. If the xOutput callback successfully processes the
** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
** it should return some other SQLite error code. In this case processing
** is immediately abandoned and the streaming API function returns a copy
** of the xOutput error code to the application.
**
** The sessions module never invokes an xOutput callback with the third
** parameter set to a value less than or equal to zero. Other than this,
** no guarantees are made as to the size of the chunks of data returned.
label: code-design
end-of-error-codes
Virtual table implementations will typically add additional fields
Mask of FTS5_TOKENIZE_* flags
comment:
** CAPI3REF: Mutex Handle
**
** The mutex module within SQLite defines [sqlite3_mutex] to be an
** abstract type for a mutex object. The SQLite core never looks
** at the internal representation of an [sqlite3_mutex]. It only
** deals with pointers to the [sqlite3_mutex] object.
**
** Mutexes are created using [sqlite3_mutex_alloc()].
label: code-design
OUT: Array of boolean - true for PK cols
** CAPI3REF: Checkpoint Mode Values
** KEYWORDS: {checkpoint mode}
**
** These constants define all valid values for the "checkpoint mode" passed
** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
** meaning of each of these checkpoint modes.
** CAPI3REF: Extended Result Codes
** KEYWORDS: {extended result code definitions}
**
** In its default configuration, SQLite API routines return one of 30 integer
** [result codes]. However, experience has shown that many of
** these result codes are too coarse-grained. They do not provide as
** much information about problems as programmers might like. In an effort to
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
** and later) include
** support for additional result codes that provide more detailed information
** about errors. These [extended result codes] are enabled or disabled
** on a per database connection basis using the
** [sqlite3_extended_result_codes()] API. Or, the extended code for
** the most recent error can be obtained using
** [sqlite3_extended_errcode()].
Methods for the module
OUT: Number of entries in output array
OUT: Visiblity
Column constrained. -1 for ROWID
Rowid of row about to be deleted/updated
** CAPI3REF: Prepared Statement Object
** KEYWORDS: {prepared statement} {prepared statements}
**
** An instance of this object represents a single SQL statement that
** has been compiled into binary form and is ready to be evaluated.
**
** Think of each SQL statement as a separate computer program. The
** original SQL text is source code. A prepared statement object
** is the compiled object code. All SQL must be converted into a
** prepared statement before it can be run.
**
** The life-cycle of a prepared statement object usually goes like this:
**
** <ol>
** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
** <li> Bind values to [parameters] using the sqlite3_bind_*()
** interfaces.
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
** <li> Reset the prepared statement using [sqlite3_reset()] then go back
** to step 2. Do this zero or more times.
** <li> Destroy the object using [sqlite3_finalize()].
** </ol>
Initialize the memory allocator
comment:
** CAPI3REF: Convenience Routines For Running Queries
** METHOD: sqlite3
**
** This is a legacy interface that is preserved for backwards compatibility.
** Use of this interface is not recommended.
**
** Definition: A <b>result table</b> is memory data structure created by the
** [sqlite3_get_table()] interface. A result table records the
** complete query results from one or more queries.
**
** The table conceptually has a number of rows and columns. But
** these numbers are not part of the result table itself. These
** numbers are obtained separately. Let N be the number of rows
** and M be the number of columns.
**
** A result table is an array of pointers to zero-terminated UTF-8 strings.
** There are (N+1)*M elements in the array. The first M pointers point
** to zero-terminated strings that contain the names of the columns.
** The remaining entries all point to query results. NULL values result
** in NULL pointers. All other values are in their UTF-8 zero-terminated
** string representation as returned by [sqlite3_column_text()].
**
** A result table might consist of one or more memory allocations.
** It is not safe to pass a result table directly to [sqlite3_free()].
** A result table should be deallocated using [sqlite3_free_table()].
**
** ^(As an example of the result table format, suppose a query result
** is as follows:
**
** <blockquote><pre>
** Name | Age
** -----------------------
** Alice | 43
** Bob | 28
** Cindy | 21
** </pre></blockquote>
**
** There are two column (M==2) and three rows (N==3). Thus the
** result table has 8 entries. Suppose the result table is stored
** in an array names azResult. Then azResult holds this content:
**
** <blockquote><pre>
** azResult[0] = "Name";
** azResult[1] = "Age";
** azResult[2] = "Alice";
** azResult[3] = "43";
** azResult[4] = "Bob";
** azResult[5] = "28";
** azResult[6] = "Cindy";
** azResult[7] = "21";
** </pre></blockquote>)^
**
** ^The sqlite3_get_table() function evaluates one or more
** semicolon-separated SQL statements in the zero-terminated UTF-8
** string of its 2nd parameter and returns a result table to the
** pointer given in its 3rd parameter.
**
** After the application has finished with the result from sqlite3_get_table(),
** it must pass the result table pointer to sqlite3_free_table() in order to
** release the memory that was malloced. Because of the way the
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
** function must not try to call [sqlite3_free()] directly. Only
** [sqlite3_free_table()] is able to release the memory properly and safely.
**
** The sqlite3_get_table() interface is implemented as a wrapper around
** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
** to any internal data structures of SQLite. It uses only the public
** interface defined here. As a consequence, errors that occur in the
** wrapper layer outside of the internal [sqlite3_exec()] call are not
** reflected in subsequent calls to [sqlite3_errcode()] or
** [sqlite3_errmsg()].
label: code-design
** CAPI3REF: Source Of Data In A Query Result
** METHOD: sqlite3_stmt
**
** ^These routines provide a means to determine the database, table, and
** table column that is the origin of a particular result column in
** [SELECT] statement.
** ^The name of the database or table or column can be returned as
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
** the database name, the _table_ routines return the table name, and
** the origin_ routines return the column name.
** ^The returned string is valid until the [prepared statement] is destroyed
** using [sqlite3_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite3_step()] for a particular run
** or until the same information is requested
** again in a different encoding.
**
** ^The names returned are the original un-aliased names of the
** database, table, and column.
**
** ^The first argument to these interfaces is a [prepared statement].
** ^These functions return information about the Nth result column returned by
** the statement, where N is the second function argument.
** ^The left-most column is column 0 for these routines.
**
** ^If the Nth column returned by the statement is an expression or
** subquery and is not a column value, then all of these functions return
** NULL. ^These routine might also return NULL if a memory allocation error
** occurs. ^Otherwise, they return the name of the attached database, table,
** or column that query result column was extracted from.
**
** ^As with all other SQLite APIs, those whose names end with "16" return
** UTF-16 encoded strings and the other functions return UTF-8.
**
** ^These APIs are only available if the library was compiled with the
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
**
** If two or more threads call one or more of these routines against the same
** prepared statement and column at the same time then the results are
** undefined.
**
** If two or more threads call one or more
** [sqlite3_column_database_name | column metadata interfaces]
** for the same [prepared statement] and result column
** at the same time then the results are undefined.
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
** Those below are for version 3 and greater.
** CAPI3REF: Configure an auto-checkpoint
** METHOD: sqlite3
**
** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
** [sqlite3_wal_hook()] that causes any database on [database connection] D
** to automatically [checkpoint]
** after committing a transaction if there are N or
** more frames in the [write-ahead log] file. ^Passing zero or
** a negative value as the nFrame parameter disables automatic
** checkpoints entirely.
**
** ^The callback registered by this function replaces any existing callback
** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
** configured by this function.
**
** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
** from SQL.
**
** ^Checkpoints initiated by this mechanism are
** [sqlite3_wal_checkpoint_v2|PASSIVE].
**
** ^Every new [database connection] defaults to having the auto-checkpoint
** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
** pages. The use of this interface
** is only necessary if the default setting is found to be suboptimal
** for a particular application.
Number of open cursors
comment:
** The type for a callback function.
** This is legacy and deprecated. It is included for historical
** compatibility and is not documented.
label: documentation
Original SQL values of parameters
comment:
** CAPI3REF: Loadable Extension Thunk
**
** A pointer to the opaque sqlite3_api_routines structure is passed as
** the third parameter to entry points of [loadable extensions]. This
** structure must be typedefed in order to work around compiler warnings
** on some platforms.
label: code-design
The module for this virtual table
callback can use this, if desired
File opened that is not a database file
comment: Warnings from sqlite3_log()
label: code-design
** CAPI3REF: Prepared Statement Scan Status Opcodes
** KEYWORDS: {scanstatus options}
**
** The following constants can be used for the T parameter to the
** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
** different metric for sqlite3_stmt_scanstatus() to return.
**
** When the value returned to V is a string, space to hold that string is
** managed by the prepared statement S and will be automatically freed when
** S is finalized.
**
** <dl>
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
** set to the total number of times that the X-th loop has run.</dd>
**
** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
** to the total number of rows examined by all iterations of the X-th loop.</dd>
**
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
** <dd>^The "double" variable pointed to by the T parameter will be set to the
** query planner's estimate for the average number of rows output from each
** iteration of the X-th loop. If the query planner's estimates was accurate,
** then this value will approximate the quotient NVISIT/NLOOP and the
** product of this value for all prior loops with the same SELECTID will
** be the NLOOP value for the current loop.
**
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
** <dd>^The "const char *" variable pointed to by the T parameter will be set
** to a zero-terminated UTF-8 string containing the name of the index or table
** used for the X-th loop.
**
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
** <dd>^The "const char *" variable pointed to by the T parameter will be set
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
** description for the X-th loop.
**
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
** <dd>^The "int" variable pointed to by the T parameter will be set to the
** "select-id" for the X-th loop. The select-id identifies which query or
** subquery the loop is part of. The main query has a select-id of zero.
** The select-id is the same value as is output in the first column
** of an [EXPLAIN QUERY PLAN] query.
** </dl>
Notifications from sqlite3_log()
** CAPI3REF: Constants Returned By The Conflict Handler
**
** A conflict handler callback must return one of the following three values.
**
** <dl>
** <dt>SQLITE_CHANGESET_OMIT<dd>
** If a conflict handler returns this value no special action is taken. The
** change that caused the conflict is not applied. The session module
** continues to the next change in the changeset.
**
** <dt>SQLITE_CHANGESET_REPLACE<dd>
** This value may only be returned if the second argument to the conflict
** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
** is not the case, any changes applied so far are rolled back and the
** call to sqlite3changeset_apply() returns SQLITE_MISUSE.
**
** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
** handler, then the conflicting row is either updated or deleted, depending
** on the type of change.
**
** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
** handler, then the conflicting row is removed from the database and a
** second attempt to apply the change is made. If this second attempt fails,
** the original row is restored to the database before continuing.
**
** <dt>SQLITE_CHANGESET_ABORT<dd>
** If this value is returned, any changes applied so far are rolled back
** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
** </dl>
1st argument to callback
** CAPI3REF: Status Parameters for database connections
** KEYWORDS: {SQLITE_DBSTATUS options}
**
** These constants are the available integer "verbs" that can be passed as
** the second argument to the [sqlite3_db_status()] interface.
**
** New verbs may be added in future releases of SQLite. Existing verbs
** might be discontinued. Applications should check the return code from
** [sqlite3_db_status()] to make sure that the call worked.
** The [sqlite3_db_status()] interface will return a non-zero error code
** if a discontinued or unsupported verb is invoked.
**
** <dl>
** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
** <dd>This parameter returns the number of lookaside memory slots currently
** checked out.</dd>)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
** <dd>This parameter returns the number malloc attempts that were
** satisfied using lookaside memory. Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
** <dd>This parameter returns the number malloc attempts that might have
** been satisfied using lookaside memory but failed due to the amount of
** memory requested being larger than the lookaside slot size.
** Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
** <dd>This parameter returns the number malloc attempts that might have
** been satisfied using lookaside memory but failed due to all lookaside
** memory already being in use.
** Only the high-water value is meaningful;
** the current value is always zero.)^
**
** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** memory used by all pager caches associated with the database connection.)^
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
**
** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
** pager cache is shared between two or more connections the bytes of heap
** memory used by that pager cache is divided evenly between the attached
** connections.)^ In other words, if none of the pager caches associated
** with the database connection are shared, this request returns the same
** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
** shared, the value returned by this call will be smaller than that returned
** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
**
** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** memory used to store the schema for all databases associated
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
** ^The full amount of memory used by the schemas is reported, even if the
** schema memory is shared with other database connections due to
** [shared cache mode] being enabled.
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
**
** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
** <dd>This parameter returns the approximate number of bytes of heap
** and lookaside memory used by all prepared statements associated with
** the database connection.)^
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
** <dd>This parameter returns the number of pager cache hits that have
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
** is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
** <dd>This parameter returns the number of pager cache misses that have
** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
** is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
** <dd>This parameter returns the number of dirty cache entries that have
** been written to disk. Specifically, the number of pages written to the
** wal file in wal mode databases, or the number of pages written to the
** database file in rollback mode databases. Any pages written as part of
** transaction rollback or database recovery operations are not included.
** If an IO or other error occurs while writing a page to disk, the effect
** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
** </dd>
**
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
** <dd>This parameter returns zero for the current value if and only if
** all foreign key constraints (deferred or immediate) have been
** resolved.)^ ^The highwater mark is always 0.
** </dd>
** </dl>
Name of db (e.g. "main")
** CAPI3REF: Set A Busy Timeout
** METHOD: sqlite3
**
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
** for a specified amount of time when a table is locked. ^The handler
** will sleep multiple times until at least "ms" milliseconds of sleeping
** have accumulated. ^After at least "ms" milliseconds of sleeping,
** the handler returns 0 which causes [sqlite3_step()] to return
** [SQLITE_BUSY].
**
** ^Calling this routine with an argument less than or equal to zero
** turns off all busy handlers.
**
** ^(There can only be a single busy handler for a particular
** [database connection] at any given moment. If another busy handler
** was defined (using [sqlite3_busy_handler()]) prior to calling
** this routine, that other busy handler is cleared.)^
**
** See also: [PRAGMA busy_timeout]
comment:
** CAPI3REF: Compiling An SQL Statement
** KEYWORDS: {SQL statement compiler}
** METHOD: sqlite3
** CONSTRUCTOR: sqlite3_stmt
**
** To execute an SQL statement, it must first be compiled into a byte-code
** program using one of these routines. Or, in other words, these routines
** are constructors for the [prepared statement] object.
**
** The preferred routine to use is [sqlite3_prepare_v2()]. The
** [sqlite3_prepare()] interface is legacy and should be avoided.
** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
** for special purposes.
**
** The use of the UTF-8 interfaces is preferred, as SQLite currently
** does all parsing using UTF-8. The UTF-16 interfaces are provided
** as a convenience. The UTF-16 interfaces work by converting the
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
**
** The first argument, "db", is a [database connection] obtained from a
** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
** [sqlite3_open16()]. The database connection must not have been closed.
**
** The second argument, "zSql", is the statement to be compiled, encoded
** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),
** and sqlite3_prepare_v3()
** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
** and sqlite3_prepare16_v3() use UTF-16.
**
** ^If the nByte argument is negative, then zSql is read up to the
** first zero terminator. ^If nByte is positive, then it is the
** number of bytes read from zSql. ^If nByte is zero, then no prepared
** statement is generated.
** If the caller knows that the supplied string is nul-terminated, then
** there is a small performance advantage to passing an nByte parameter that
** is the number of bytes in the input string <i>including</i>
** the nul-terminator.
**
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
** past the end of the first SQL statement in zSql. These routines only
** compile the first statement in zSql, so *pzTail is left pointing to
** what remains uncompiled.
**
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
** to NULL. ^If the input text contains no SQL (if the input is an empty
** string or a comment) then *ppStmt is set to NULL.
** The calling procedure is responsible for deleting the compiled
** SQL statement using [sqlite3_finalize()] after it has finished with it.
** ppStmt may not be NULL.
**
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
** otherwise an [error code] is returned.
**
** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
** are retained for backwards compatibility, but their use is discouraged.
** ^In the "vX" interfaces, the prepared statement
** that is returned (the [sqlite3_stmt] object) contains a copy of the
** original SQL text. This causes the [sqlite3_step()] interface to
** behave differently in three ways:
**
** <ol>
** <li>
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
** always used to do, [sqlite3_step()] will automatically recompile the SQL
** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
** retries will occur before sqlite3_step() gives up and returns an error.
** </li>
**
** <li>
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
** [error codes] or [extended error codes]. ^The legacy behavior was that
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
** and the application would have to make a second call to [sqlite3_reset()]
** in order to find the underlying cause of the problem. With the "v2" prepare
** interfaces, the underlying reason for the error is returned immediately.
** </li>
**
** <li>
** ^If the specific value bound to [parameter | host parameter] in the
** WHERE clause might influence the choice of query plan for a statement,
** then the statement will be automatically recompiled, as if there had been
** a schema change, on the first [sqlite3_step()] call following any change
** to the [sqlite3_bind_text | bindings] of that [parameter].
** ^The specific value of WHERE-clause [parameter] might influence the
** choice of query plan if the parameter is the left-hand side of a [LIKE]
** or [GLOB] operator or if the parameter is compared to an indexed column
** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
** </li>
**
** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
** the extra prepFlags parameter, which is a bit array consisting of zero or
** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The
** sqlite3_prepare_v2() interface works exactly the same as
** sqlite3_prepare_v3() with a zero prepFlags parameter.
** </ol>
label: code-design
Index of loop to report on
** CAPI3REF: Attach A Table To A Session Object
**
** If argument zTab is not NULL, then it is the name of a table to attach
** to the session object passed as the first argument. All subsequent changes
** made to the table while the session object is enabled will be recorded. See
** documentation for [sqlite3session_changeset()] for further details.
**
** Or, if argument zTab is NULL, then changes are recorded for all tables
** in the database. If additional tables are added to the database (by
** executing "CREATE TABLE" statements) after this call is made, changes for
** the new tables are also recorded.
**
** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
** defined as part of their CREATE TABLE statement. It does not matter if the
** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
** KEY may consist of a single column, or may be a composite key.
**
** It is not an error if the named table does not exist in the database. Nor
** is it an error if the named table does not have a PRIMARY KEY. However,
** no changes will be recorded in either of these scenarios.
**
** Changes are not recorded for individual rows that have NULL values stored
** in one or more of their PRIMARY KEY columns.
**
** SQLITE_OK is returned if the call completes without error. Or, if an error
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
comment:
** CAPI3REF: Binding Values To Prepared Statements
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
** METHOD: sqlite3_stmt
**
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
** literals may be replaced by a [parameter] that matches one of following
** templates:
**
** <ul>
** <li> ?
** <li> ?NNN
** <li> :VVV
** <li> @VVV
** <li> $VVV
** </ul>
**
** In the templates above, NNN represents an integer literal,
** and VVV represents an alphanumeric identifier.)^ ^The values of these
** parameters (also called "host parameter names" or "SQL parameters")
** can be set using the sqlite3_bind_*() routines defined here.
**
** ^The first argument to the sqlite3_bind_*() routines is always
** a pointer to the [sqlite3_stmt] object returned from
** [sqlite3_prepare_v2()] or its variants.
**
** ^The second argument is the index of the SQL parameter to be set.
** ^The leftmost SQL parameter has an index of 1. ^When the same named
** SQL parameter is used more than once, second and subsequent
** occurrences have the same index as the first occurrence.
** ^The index for named parameters can be looked up using the
** [sqlite3_bind_parameter_index()] API if desired. ^The index
** for "?NNN" parameters is the value of NNN.
** ^The NNN value must be between 1 and the [sqlite3_limit()]
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
**
** ^The third argument is the value to bind to the parameter.
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
** is ignored and the end result is the same as sqlite3_bind_null().
**
** ^(In those routines that have a fourth argument, its value is the
** number of bytes in the parameter. To be clear: the value is the
** number of <u>bytes</u> in the value, not the number of characters.)^
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
** is negative, then the length of the string is
** the number of bytes up to the first zero terminator.
** If the fourth parameter to sqlite3_bind_blob() is negative, then
** the behavior is undefined.
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
** that parameter must be the byte offset
** where the NUL terminator would occur assuming the string were NUL
** terminated. If any NUL characters occur at byte offsets less than
** the value of the fourth parameter then the resulting string value will
** contain embedded NULs. The result of expressions involving strings
** with embedded NULs is undefined.
**
** ^The fifth argument to the BLOB and string binding interfaces
** is a destructor used to dispose of the BLOB or
** string after SQLite has finished with it. ^The destructor is called
** to dispose of the BLOB or string even if the call to bind API fails.
** ^If the fifth argument is
** the special value [SQLITE_STATIC], then SQLite assumes that the
** information is in static, unmanaged space and does not need to be freed.
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
** SQLite makes its own private copy of the data immediately, before
** the sqlite3_bind_*() routine returns.
**
** ^The sixth argument to sqlite3_bind_text64() must be one of
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
** to specify the encoding of the text in the third parameter. If
** the sixth argument to sqlite3_bind_text64() is not one of the
** allowed values shown above, or if the text encoding is different
** from the encoding specified by the sixth parameter, then the behavior
** is undefined.
**
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
** (just an integer to hold its size) while it is being processed.
** Zeroblobs are intended to serve as placeholders for BLOBs whose
** content is later written using
** [sqlite3_blob_open | incremental BLOB I/O] routines.
** ^A negative value for the zeroblob results in a zero-length BLOB.
**
** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
** [prepared statement] S to have an SQL value of NULL, but to also be
** associated with the pointer P of type T. ^D is either a NULL pointer or
** a pointer to a destructor function for P. ^SQLite will invoke the
** destructor D with a single argument of P when it is finished using
** P. The T parameter should be a static string, preferably a string
** literal. The sqlite3_bind_pointer() routine is part of the
** [pointer passing interface] added for SQLite 3.20.0.
**
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
** for the [prepared statement] or with a prepared statement for which
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
** routine is passed a [prepared statement] that has been finalized, the
** result is undefined and probably harmful.
**
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
** ^Unbound parameters are interpreted as NULL.
**
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
** [error code] if anything goes wrong.
** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
** [SQLITE_MAX_LENGTH].
** ^[SQLITE_RANGE] is returned if the parameter
** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
**
** See also: [sqlite3_bind_parameter_count()],
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
label: code-design
pContext from when function registered
OUT: Buffer containing changeset
comment:
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
label: code-design
The largest iLevel value in the tree
** Register a 2nd-generation geometry callback named zScore that can be
** used as part of an R-Tree geometry query as follows:
**
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
IMP: R-51971-34154
comment:
** CAPI3REF: Configuration Options
** KEYWORDS: {configuration option}
**
** These constants are the available integer configuration options that
** can be passed as the first argument to the [sqlite3_config()] interface.
**
** New configuration options may be added in future releases of SQLite.
** Existing configuration options might be discontinued. Applications
** should check the return code from [sqlite3_config()] to make sure that
** the call worked. The [sqlite3_config()] interface will return a
** non-zero [error code] if a discontinued or unsupported configuration option
** is invoked.
**
** <dl>
** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Single-thread. In other words, it disables
** all mutexing and puts SQLite into a mode where it can only be used
** by a single thread. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to change the [threading mode] from its default
** value of Single-thread and so [sqlite3_config()] will return
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
** configuration option.</dd>
**
** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Multi-thread. In other words, it disables
** mutexing on [database connection] and [prepared statement] objects.
** The application is responsible for serializing access to
** [database connections] and [prepared statements]. But other mutexes
** are enabled so that SQLite will be safe to use in a multi-threaded
** environment as long as no two threads attempt to use the same
** [database connection] at the same time. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to set the Multi-thread [threading mode] and
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
**
** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
** <dd>There are no arguments to this option. ^This option sets the
** [threading mode] to Serialized. In other words, this option enables
** all mutexes including the recursive
** mutexes on [database connection] and [prepared statement] objects.
** In this mode (which is the default when SQLite is compiled with
** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
** to [database connections] and [prepared statements] so that the
** application is free to use the same [database connection] or the
** same [prepared statement] in different threads at the same time.
** ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** it is not possible to set the Serialized [threading mode] and
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
**
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
** a pointer to an instance of the [sqlite3_mem_methods] structure.
** The argument specifies
** alternative low-level memory allocation routines to be used in place of
** the memory allocation routines built into SQLite.)^ ^SQLite makes
** its own private copy of the content of the [sqlite3_mem_methods] structure
** before the [sqlite3_config()] call returns.</dd>
**
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
** The [sqlite3_mem_methods]
** structure is filled with the currently defined memory allocation routines.)^
** This option can be used to overload the default memory allocation
** routines with a wrapper that simulations memory allocation failure or
** tracks memory usage, for example. </dd>
**
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
** interpreted as a boolean, which enables or disables the collection of
** memory allocation statistics. ^(When memory allocation statistics are
** disabled, the following SQLite interfaces become non-operational:
** <ul>
** <li> [sqlite3_memory_used()]
** <li> [sqlite3_memory_highwater()]
** <li> [sqlite3_soft_heap_limit64()]
** <li> [sqlite3_status64()]
** </ul>)^
** ^Memory allocation statistics are enabled by default unless SQLite is
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
** allocation statistics are disabled by default.
** </dd>
**
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
** that SQLite can use for scratch memory. ^(There are three arguments
** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
** aligned memory buffer from which the scratch allocations will be
** drawn, the size of each scratch allocation (sz),
** and the maximum number of scratch allocations (N).)^
** The first argument must be a pointer to an 8-byte aligned buffer
** of at least sz*N bytes of memory.
** ^SQLite will not use more than one scratch buffers per thread.
** ^SQLite will never request a scratch buffer that is more than 6
** times the database page size.
** ^If SQLite needs needs additional
** scratch memory beyond what is provided by this configuration option, then
** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
** ^When the application provides any amount of scratch memory using
** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
** [sqlite3_malloc|heap allocations].
** This can help [Robson proof|prevent memory allocation failures] due to heap
** fragmentation in low-memory embedded systems.
** </dd>
**
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
** that SQLite can use for the database page cache with the default page
** cache implementation.
** This configuration option is a no-op if an application-define page
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
** and the number of cache lines (N).
** The sz argument should be the size of the largest database page
** (a power of two between 512 and 65536) plus some extra bytes for each
** page header. ^The number of extra bytes needed by the page header
** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
** ^It is harmless, apart from the wasted memory,
** for the sz parameter to be larger than necessary. The pMem
** argument must be either a NULL pointer or a pointer to an 8-byte
** aligned block of memory of at least sz*N bytes, otherwise
** subsequent behavior is undefined.
** ^When pMem is not NULL, SQLite will strive to use the memory provided
** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
** a page cache line is larger than sz bytes or if all of the pMem buffer
** is exhausted.
** ^If pMem is NULL and N is non-zero, then each database connection
** does an initial bulk allocation for page cache memory
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
** of -1024*N bytes if N is negative, . ^If additional
** page cache memory is needed beyond what is provided by the initial
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
** additional cache line. </dd>
**
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
** that SQLite will use for all of its dynamic memory allocation needs
** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
** [SQLITE_CONFIG_PAGECACHE].
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
** [SQLITE_ERROR] if invoked otherwise.
** ^There are three arguments to SQLITE_CONFIG_HEAP:
** An 8-byte aligned pointer to the memory,
** the number of bytes in the memory buffer, and the minimum allocation size.
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
** to using its default memory allocator (the system malloc() implementation),
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
** memory pointer is not NULL then the alternative memory
** allocator is engaged to handle all of SQLites memory allocation needs.
** The first pointer (the memory pointer) must be aligned to an 8-byte
** boundary or subsequent behavior of SQLite will be undefined.
** The minimum allocation size is capped at 2**12. Reasonable values
** for the minimum allocation size are 2**5 through 2**8.</dd>
**
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
** pointer to an instance of the [sqlite3_mutex_methods] structure.
** The argument specifies alternative low-level mutex routines to be used
** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
** the content of the [sqlite3_mutex_methods] structure before the call to
** [sqlite3_config()] returns. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** the entire mutexing subsystem is omitted from the build and hence calls to
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
** return [SQLITE_ERROR].</dd>
**
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
** [sqlite3_mutex_methods]
** structure is filled with the currently defined mutex routines.)^
** This option can be used to overload the default mutex allocation
** routines with a wrapper used to track mutex usage for performance
** profiling or testing, for example. ^If SQLite is compiled with
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
** the entire mutexing subsystem is omitted from the build and hence calls to
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
** return [SQLITE_ERROR].</dd>
**
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
** the default size of lookaside memory on each [database connection].
** The first argument is the
** size of each lookaside buffer slot and the second is the number of
** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
** option to [sqlite3_db_config()] can be used to change the lookaside
** configuration on individual connections.)^ </dd>
**
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
** the interface to a custom page cache implementation.)^
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
**
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
** the current page cache implementation into that object.)^ </dd>
**
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
** global [error log].
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
** function with a call signature of void(*)(void*,int,const char*),
** and a pointer to void. ^If the function pointer is not NULL, it is
** invoked by [sqlite3_log()] to process each logging event. ^If the
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
** passed through as the first parameter to the application-defined logger
** function whenever that function is invoked. ^The second parameter to
** the logger function is a copy of the first parameter to the corresponding
** [sqlite3_log()] call and is intended to be a [result code] or an
** [extended result code]. ^The third parameter passed to the logger is
** log message after formatting via [sqlite3_snprintf()].
** The SQLite logging interface is not reentrant; the logger function
** supplied by the application must not invoke any SQLite interface.
** In a multi-threaded application, the application-defined logger
** function must be threadsafe. </dd>
**
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
** If non-zero, then URI handling is globally enabled. If the parameter is zero,
** then URI handling is globally disabled.)^ ^If URI handling is globally
** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
** [sqlite3_open16()] or
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
** connection is opened. ^If it is globally disabled, filenames are
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
** database connection is opened. ^(By default, URI handling is globally
** disabled. The default value may be changed by compiling with the
** [SQLITE_USE_URI] symbol defined.)^
**
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
** argument which is interpreted as a boolean in order to enable or disable
** the use of covering indices for full table scans in the query optimizer.
** ^The default setting is determined
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
** if that compile-time option is omitted.
** The ability to disable the use of covering indices for full table scans
** is because some incorrectly coded legacy applications might malfunction
** when the optimization is enabled. Providing the ability to
** disable the optimization allows the older, buggy application code to work
** without change even with newer versions of SQLite.
**
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
** <dd> These options are obsolete and should not be used by new code.
** They are retained for backwards compatibility but are now no-ops.
** </dd>
**
** [[SQLITE_CONFIG_SQLLOG]]
** <dt>SQLITE_CONFIG_SQLLOG
** <dd>This option is only available if sqlite is compiled with the
** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
** The second should be of type (void*). The callback is invoked by the library
** in three separate circumstances, identified by the value passed as the
** fourth parameter. If the fourth parameter is 0, then the database connection
** passed as the second argument has just been opened. The third argument
** points to a buffer containing the name of the main database file. If the
** fourth parameter is 1, then the SQL statement that the third parameter
** points to has just been executed. Or, if the fourth parameter is 2, then
** the connection being passed as the second parameter is being closed. The
** third parameter is passed NULL In this case. An example of using this
** configuration option can be seen in the "test_sqllog.c" source file in
** the canonical SQLite source tree.</dd>
**
** [[SQLITE_CONFIG_MMAP_SIZE]]
** <dt>SQLITE_CONFIG_MMAP_SIZE
** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
** that are the default mmap size limit (the default setting for
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
** ^The default setting can be overridden by each database connection using
** either the [PRAGMA mmap_size] command, or by using the
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
** will be silently truncated if necessary so that it does not exceed the
** compile-time maximum mmap size set by the
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
** ^If either argument to this option is negative, then that argument is
** changed to its compile-time default.
**
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
** that specifies the maximum size of the created heap.
**
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
** is a pointer to an integer and writes into that integer the number of extra
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
** The amount of extra space required can change depending on the compiler,
** target platform, and SQLite version.
**
** [[SQLITE_CONFIG_PMASZ]]
** <dt>SQLITE_CONFIG_PMASZ
** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
** sorter to that integer. The default minimum PMA Size is set by the
** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
** to help with sort operations when multithreaded sorting
** is enabled (using the [PRAGMA threads] command) and the amount of content
** to be sorted exceeds the page size times the minimum of the
** [PRAGMA cache_size] setting and this value.
**
** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
** becomes the [statement journal] spill-to-disk threshold.
** [Statement journals] are held in memory until their size (in bytes)
** exceeds this threshold, at which point they are written to disk.
** Or if the threshold is -1, statement journals are always held
** exclusively in memory.
** Since many statement journals never become large, setting the spill
** threshold to a value such as 64KiB can greatly reduce the amount of
** I/O required to support statement rollback.
** The default value for this setting is controlled by the
** [SQLITE_STMTJRNL_SPILL] compile-time option.
** </dl>
label: code-design
** CAPI3REF: Closing A Database Connection
** DESTRUCTOR: sqlite3
**
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
** for the [sqlite3] object.
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
** the [sqlite3] object is successfully destroyed and all associated
** resources are deallocated.
**
** ^If the database connection is associated with unfinalized prepared
** statements or unfinished sqlite3_backup objects then sqlite3_close()
** will leave the database connection open and return [SQLITE_BUSY].
** ^If sqlite3_close_v2() is called with unfinalized prepared statements
** and/or unfinished sqlite3_backups, then the database connection becomes
** an unusable "zombie" which will automatically be deallocated when the
** last prepared statement is finalized or the last sqlite3_backup is
** finished. The sqlite3_close_v2() interface is intended for use with
** host languages that are garbage collected, and where the order in which
** destructors are called is arbitrary.
**
** Applications should [sqlite3_finalize | finalize] all [prepared statements],
** [sqlite3_blob_close | close] all [BLOB handles], and
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
** with the [sqlite3] object prior to attempting to close the object. ^If
** sqlite3_close_v2() is called on a [database connection] that still has
** outstanding [prepared statements], [BLOB handles], and/or
** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
** of resources is deferred until all [prepared statements], [BLOB handles],
** and [sqlite3_backup] objects are also destroyed.
**
** ^If an [sqlite3] object is destroyed while a transaction is open,
** the transaction is automatically rolled back.
**
** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
** must be either a NULL
** pointer or an [sqlite3] object pointer obtained
** from [sqlite3_open()], [sqlite3_open16()], or
** [sqlite3_open_v2()], and not previously closed.
** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
** argument is a harmless no-op.
no-op
** CAPI3REF: Status Parameters
** KEYWORDS: {status parameters}
**
** These integer constants designate various run-time status parameters
** that can be returned by [sqlite3_status()].
**
** <dl>
** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
** <dd>This parameter is the current amount of memory checked out
** using [sqlite3_malloc()], either directly or indirectly. The
** figure includes calls made to [sqlite3_malloc()] by the application
** and internal memory usage by the SQLite library. Scratch memory
** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
** this parameter. The amount returned is the sum of the allocation
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
**
** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
** internal equivalents). Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
** <dd>This parameter records the number of separate memory allocations
** currently checked out.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
** <dd>This parameter returns the number of pages used out of the
** [pagecache memory allocator] that was configured using
** [SQLITE_CONFIG_PAGECACHE]. The
** value returned is in pages, not in bytes.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
** <dd>This parameter returns the number of bytes of page cache
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
** buffer and where forced to overflow to [sqlite3_malloc()]. The
** returned value includes allocations that overflowed because they
** where too large (they were larger than the "sz" parameter to
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
** no space was left in the page cache.</dd>)^
**
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [pagecache memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
** <dd>This parameter returns the number of allocations used out of the
** [scratch memory allocator] configured using
** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
** in bytes. Since a single thread may only have one scratch allocation
** outstanding at time, this parameter also reports the number of threads
** using scratch memory at the same time.</dd>)^
**
** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
** <dd>This parameter returns the number of bytes of scratch memory
** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
** returned include overflows because the requested allocation was too
** larger (that is, because the requested allocation was larger than the
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
** slots were available.
** </dd>)^
**
** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [scratch memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
** <dd>The *pHighwater parameter records the deepest parser stack.
** The *pCurrent value is undefined. The *pHighwater value is only
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
** </dl>
**
** New status parameters may be added from time to time.
Filename NULL
** CAPI3REF: Constants Passed To The Conflict Handler
**
** Values that may be passed as the second argument to a conflict-handler.
**
** <dl>
** <dt>SQLITE_CHANGESET_DATA<dd>
** The conflict handler is invoked with CHANGESET_DATA as the second argument
** when processing a DELETE or UPDATE change if a row with the required
** PRIMARY KEY fields is present in the database, but one or more other
** (non primary-key) fields modified by the update do not contain the
** expected "before" values.
**
** The conflicting row, in this case, is the database row with the matching
** primary key.
**
** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
** The conflict handler is invoked with CHANGESET_NOTFOUND as the second
** argument when processing a DELETE or UPDATE change if a row with the
** required PRIMARY KEY fields is not present in the database.
**
** There is no conflicting row in this case. The results of invoking the
** sqlite3changeset_conflict() API are undefined.
**
** <dt>SQLITE_CHANGESET_CONFLICT<dd>
** CHANGESET_CONFLICT is passed as the second argument to the conflict
** handler while processing an INSERT change if the operation would result
** in duplicate primary key values.
**
** The conflicting row in this case is the database row with the matching
** primary key.
**
** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
** If foreign key handling is enabled, and applying a changeset leaves the
** database in a state containing foreign key violations, the conflict
** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
** exactly once before the changeset is committed. If the conflict handler
** returns CHANGESET_OMIT, the changes, including those that caused the
** foreign key constraint violation, are committed. Or, if it returns
** CHANGESET_ABORT, the changeset is rolled back.
**
** No current or conflicting row information is provided. The only function
** it is possible to call on the supplied sqlite3_changeset_iter handle
** is sqlite3changeset_fk_conflicts().
**
** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
** If any other constraint violation occurs while applying a change (i.e.
** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
** invoked with CHANGESET_CONSTRAINT as the second argument.
**
** There is no conflicting row in this case. The results of invoking the
** sqlite3changeset_conflict() API are undefined.
**
** </dl>
View Name NULL
** CAPI3REF: Flags For File Open Operations
**
** These bit values are intended for use in the
** 3rd parameter to the [sqlite3_open_v2()] interface and
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
sqlite3BtreeOpen()
** CAPI3REF: Determine If An SQL Statement Is Complete
**
** These routines are useful during command-line input to determine if the
** currently entered text seems to form a complete SQL statement or
** if additional input is needed before sending the text into
** SQLite for parsing. ^These routines return 1 if the input string
** appears to be a complete SQL statement. ^A statement is judged to be
** complete if it ends with a semicolon token and is not a prefix of a
** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
** string literals or quoted identifier names or comments are not
** independent tokens (they are part of the token in which they are
** embedded) and thus do not count as a statement terminator. ^Whitespace
** and comments that follow the final semicolon are ignored.
**
** ^These routines return 0 if the statement is incomplete. ^If a
** memory allocation fails, then SQLITE_NOMEM is returned.
**
** ^These routines do not parse the SQL statements thus
** will not detect syntactically incorrect SQL.
**
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
** automatically by sqlite3_complete16(). If that initialization fails,
** then the return value from sqlite3_complete16() will be non-zero
** regardless of whether or not the input SQL is complete.)^
**
** The input to [sqlite3_complete()] must be a zero-terminated
** UTF-8 string.
**
** The input to [sqlite3_complete16()] must be a zero-terminated
** UTF-16 string in native byte order.
** CAPI3REF: Virtual Table Object
** KEYWORDS: sqlite3_module {virtual table module}
**
** This structure, sometimes called a "virtual table module",
** defines the implementation of a [virtual tables].
** This structure consists mostly of methods for the module.
**
** ^A virtual table module is created by filling in a persistent
** instance of this structure and passing a pointer to that instance
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
** ^The registration remains valid until it is replaced by a different
** module or until the [database connection] closes. The content
** of this structure must not change while it is registered with
** any database connection.
API offered by current FTS version
Access permission denied
Table Name Column Name
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
** [prepared statement] S has been stepped at least once using
** [sqlite3_step(S)] but has neither run to completion (returned
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
** interface returns false if S is a NULL pointer. If S is not a
** NULL pointer and is not a pointer to a valid [prepared statement]
** object, then the behavior is undefined and probably undesirable.
**
** This interface can be used in combination [sqlite3_next_stmt()]
** to locate all prepared statements associated with a database
** connection that are in need of being reset. This can be used,
** for example, in diagnostic routines to search for prepared
** statements that are holding a transaction open.
comment: Unused
label: code-design
** CAPI3REF: Find the next prepared statement
** METHOD: sqlite3
**
** ^This interface returns a pointer to the next [prepared statement] after
** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
** then this interface returns a pointer to the first prepared statement
** associated with the database connection pDb. ^If no prepared statement
** satisfies the conditions of this routine, it returns NULL.
**
** The [database connection] pointer D in a call to
** [sqlite3_next_stmt(D,S)] must refer to an open database
** connection and in particular must not be a NULL pointer.
Extra information associated with the page
** A pointer to a structure of the following type is passed as the
** argument to scored geometry callback registered using
** sqlite3_rtree_query_callback().
**
** Note that the first 5 fields of this structure are identical to
** sqlite3_rtree_geometry. This structure is a subclass of
** sqlite3_rtree_geometry.
Fields below are only available in SQLite 3.9.0 and later
OUT: New changeset iterator handle
comment:
** CAPI3REF: Prepared Statement Scan Status
** METHOD: sqlite3_stmt
**
** This interface returns information about the predicted and measured
** performance for pStmt. Advanced applications can use this
** interface to compare the predicted and the measured performance and
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
**
** Since this interface is expected to be rarely used, it is only
** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
** compile-time option.
**
** The "iScanStatusOp" parameter determines which status information to return.
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
** of this interface is undefined.
** ^The requested measurement is written into a variable pointed to by
** the "pOut" parameter.
** Parameter "idx" identifies the specific loop to retrieve statistics for.
** Loops are numbered starting from zero. ^If idx is out of range - less than
** zero or greater than or equal to the total number of loops used to implement
** the statement - a non-zero value is returned and the variable that pOut
** points to is unchanged.
**
** ^Statistics might not be available for all loops in all statements. ^In cases
** where there exist loops with no available statistics, this function behaves
** as if the loop did not exist - it returns non-zero and leave the variable
** that pOut points to unchanged.
**
** See also: [sqlite3_stmt_scanstatus_reset()]
label: code-design
A malloc() failed
void*, int sz, int N
2nd parameter to sqlite3_bind out of range
** CAPI3REF: Register A Virtual Table Implementation
** METHOD: sqlite3
**
** ^These routines are used to register a new [virtual table module] name.
** ^Module names must be registered before
** creating a new [virtual table] using the module and before using a
** preexisting [virtual table] for the module.
**
** ^The module name is registered on the [database connection] specified
** by the first parameter. ^The name of the module is given by the
** second parameter. ^The third parameter is a pointer to
** the implementation of the [virtual table module]. ^The fourth
** parameter is an arbitrary client data pointer that is passed through
** into the [xCreate] and [xConnect] methods of the virtual table module
** when a new virtual table is be being created or reinitialized.
**
** ^The sqlite3_create_module_v2() interface has a fifth parameter which
** is a pointer to a destructor for the pClientData. ^SQLite will
** invoke the destructor function (if it is not NULL) when SQLite
** no longer needs the pClientData pointer. ^The destructor will also
** be invoked if the call to sqlite3_create_module_v2() fails.
** ^The sqlite3_create_module()
** interface is equivalent to sqlite3_create_module_v2() with a NULL
** destructor.
Abort the SQL statement with an error
Resize an allocation
** CAPI3REF: Pseudo-Random Number Generator
**
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
** select random [ROWID | ROWIDs] when inserting new records into a table that
** already uses the largest possible [ROWID]. The PRNG is also used for
** the build-in random() and randomblob() SQL functions. This interface allows
** applications to access the same PRNG for other purposes.
**
** ^A call to this routine stores N bytes of randomness into buffer P.
** ^The P parameter can be a NULL pointer.
**
** ^If this routine has not been previously called or if the previous
** call had N less than one or a NULL pointer for P, then the PRNG is
** seeded using randomness obtained from the xRandomness method of
** the default [sqlite3_vfs] object.
** ^If the previous call to this routine had an N of 1 or more and a
** non-NULL P then the pseudo-randomness is generated
** internally and without recourse to the [sqlite3_vfs] xRandomness
** method.
Database handle
Activation phrase
** CAPI3REF: Virtual Table Cursor Object
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
**
** Every [virtual table module] implementation uses a subclass of the
** following structure to describe cursors that point into the
** [virtual table] and are used
** to loop through the virtual table. Cursors are created using the
** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
** by the [sqlite3_module.xClose | xClose] method. Cursors are used
** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
** of the module. Each module implementation will define
** the content of a cursor structure to suit its own needs.
**
** This superclass exists in order to define fields of the cursor that
** are common to all implementations.
Column name
Currently always set to 2
First arg for xInput
comment:
** CAPI3REF: OS Interface Object
**
** An instance of the sqlite3_vfs object defines the interface between
** the SQLite core and the underlying operating system. The "vfs"
** in the name of the object stands for "virtual file system". See
** the [VFS | VFS documentation] for further information.
**
** The value of the iVersion field is initially 1 but may be larger in
** future versions of SQLite. Additional fields may be appended to this
** object when the iVersion value is increased. Note that the structure
** of the sqlite3_vfs object changes in the transaction between
** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
** modified.
**
** The szOsFile field is the size of the subclassed [sqlite3_file]
** structure used by this VFS. mxPathname is the maximum length of
** a pathname in this VFS.
**
** Registered sqlite3_vfs objects are kept on a linked list formed by
** the pNext pointer. The [sqlite3_vfs_register()]
** and [sqlite3_vfs_unregister()] interfaces manage this list
** in a thread-safe way. The [sqlite3_vfs_find()] interface
** searches the list. Neither the application code nor the VFS
** implementation should use the pNext pointer.
**
** The pNext field is the only field in the sqlite3_vfs
** structure that SQLite will ever modify. SQLite will only access
** or modify this field while holding a particular static mutex.
** The application should never modify anything within the sqlite3_vfs
** object once the object has been registered.
**
** The zName field holds the name of the VFS module. The name must
** be unique across all VFS modules.
**
** [[sqlite3_vfs.xOpen]]
** ^SQLite guarantees that the zFilename parameter to xOpen
** is either a NULL pointer or string obtained
** from xFullPathname() with an optional suffix added.
** ^If a suffix is added to the zFilename parameter, it will
** consist of a single "-" character followed by no more than
** 11 alphanumeric and/or "-" characters.
** ^SQLite further guarantees that
** the string will be valid and unchanged until xClose() is
** called. Because of the previous sentence,
** the [sqlite3_file] can safely store a pointer to the
** filename if it needs to remember the filename for some reason.
** If the zFilename parameter to xOpen is a NULL pointer then xOpen
** must invent its own temporary name for the file. ^Whenever the
** xFilename parameter is NULL it will also be the case that the
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
**
** The flags argument to xOpen() includes all bits set in
** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
** or [sqlite3_open16()] is used, then flags includes at least
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
** If xOpen() opens a file read-only then it sets *pOutFlags to
** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
**
** ^(SQLite will also add one of the following flags to the xOpen()
** call, depending on the object being opened:
**
** <ul>
** <li> [SQLITE_OPEN_MAIN_DB]
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
** <li> [SQLITE_OPEN_TEMP_DB]
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
** <li> [SQLITE_OPEN_TRANSIENT_DB]
** <li> [SQLITE_OPEN_SUBJOURNAL]
** <li> [SQLITE_OPEN_MASTER_JOURNAL]
** <li> [SQLITE_OPEN_WAL]
** </ul>)^
**
** The file I/O implementation can use the object type flags to
** change the way it deals with files. For example, an application
** that does not care about crash recovery or rollback might make
** the open of a journal file a no-op. Writes to this journal would
** also be no-ops, and any attempt to read the journal would return
** SQLITE_IOERR. Or the implementation might recognize that a database
** file will be doing page-aligned sector reads and writes in a random
** order and set up its I/O subsystem accordingly.
**
** SQLite might also add one of the following flags to the xOpen method:
**
** <ul>
** <li> [SQLITE_OPEN_DELETEONCLOSE]
** <li> [SQLITE_OPEN_EXCLUSIVE]
** </ul>
**
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
** will be set for TEMP databases and their journals, transient
** databases, and subjournals.
**
** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
** SQLITE_OPEN_CREATE, is used to indicate that file should always
** be created, and that it is an error if it already exists.
** It is <i>not</i> used to indicate the file should be opened
** for exclusive access.
**
** ^At least szOsFile bytes of memory are allocated by SQLite
** to hold the [sqlite3_file] structure passed as the third
** argument to xOpen. The xOpen method does not have to
** allocate the structure; it should just fill it in. Note that
** the xOpen method must set the sqlite3_file.pMethods to either
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
** element will be valid after xOpen returns regardless of the success
** or failure of the xOpen call.
**
** [[sqlite3_vfs.xAccess]]
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
** to test whether a file is at least readable. The file can be a
** directory.
**
** ^SQLite will always allocate at least mxPathname+1 bytes for the
** output buffer xFullPathname. The exact size of the output buffer
** is also passed as a parameter to both methods. If the output buffer
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
** handled as a fatal error by SQLite, vfs implementations should endeavor
** to prevent this by setting mxPathname to a sufficiently large value.
**
** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
** interfaces are not strictly a part of the filesystem, but they are
** included in the VFS structure for completeness.
** The xRandomness() function attempts to return nBytes bytes
** of good-quality randomness into zOut. The return value is
** the actual number of bytes of randomness obtained.
** The xSleep() method causes the calling thread to sleep for at
** least the number of microseconds given. ^The xCurrentTime()
** method returns a Julian Day Number for the current date and time as
** a floating point value.
** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
** Day Number multiplied by 86400000 (the number of milliseconds in
** a 24-hour day).
** ^SQLite will use the xCurrentTimeInt64() method to get the current
** date and time if that method is available (if iVersion is 2 or
** greater and the function pointer is not NULL) and will fall back
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
**
** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
** are not used by the SQLite core. These optional interfaces are provided
** by some VFSes to facilitate testing of the VFS code. By overriding
** system calls with functions under its control, a test program can
** simulate faults and error conditions that would otherwise be difficult
** or impossible to induce. The set of system calls that can be overridden
** varies from one VFS to another, and from one version of the same VFS to the
** next. Applications that use these interfaces must be prepared for any
** or all of these interfaces to be NULL or for their behavior to change
** from one release to the next. Applications must not attempt to access
** any of these methods if the iVersion of the VFS is less than 3.
label: code-design
** END OF REGISTRATION API
************************************************************************
Uses OS features not supported on host
SQL statement, UTF-16 encoded
value of function parameters
A table in the database is locked
** CAPI3REF: Total Number Of Rows Modified
** METHOD: sqlite3
**
** ^This function returns the total number of rows inserted, modified or
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
** since the database connection was opened, including those executed as
** part of trigger programs. ^Executing any other type of SQL statement
** does not affect the value returned by sqlite3_total_changes().
**
** ^Changes made as part of [foreign key actions] are included in the
** count, but those made as part of REPLACE constraint resolution are
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
** are not counted.
**
** See also the [sqlite3_changes()] interface, the
** [count_changes pragma], and the [total_changes() SQL function].
**
** If a separate thread makes changes on the same database connection
** while [sqlite3_total_changes()] is running then the value
** returned is unpredictable and not meaningful.
unsigned int szPma
Object partially overlaps query region
Database filename (UTF-8)
comment:
** CAPI3REF: Prepared Statement Status
** METHOD: sqlite3_stmt
**
** ^(Each prepared statement maintains various
** [SQLITE_STMTSTATUS counters] that measure the number
** of times it has performed specific operations.)^ These counters can
** be used to monitor the performance characteristics of the prepared
** statements. For example, if the number of table steps greatly exceeds
** the number of table searches or result rows, that would tend to indicate
** that the prepared statement is using a full table scan rather than
** an index.
**
** ^(This interface is used to retrieve and reset counter values from
** a [prepared statement]. The first argument is the prepared statement
** object to be interrogated. The second argument
** is an integer code for a specific [SQLITE_STMTSTATUS counter]
** to be interrogated.)^
** ^The current value of the requested counter is returned.
** ^If the resetFlg is true, then the counter is reset to zero after this
** interface call returns.
**
** See also: [sqlite3_status()] and [sqlite3_db_status()].
label: code-design
Operation Savepoint Name
** The methods above are in version 1 of the sqlite_vfs object
** definition. Those that follow are added in version 2 or later
** CAPI3REF: Database Connection Configuration Options
**
** These constants are the available integer configuration options that
** can be passed as the second argument to the [sqlite3_db_config()] interface.
**
** New configuration options may be added in future releases of SQLite.
** Existing configuration options might be discontinued. Applications
** should check the return code from [sqlite3_db_config()] to make sure that
** the call worked. ^The [sqlite3_db_config()] interface will return a
** non-zero [error code] if a discontinued or unsupported configuration option
** is invoked.
**
** <dl>
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
** <dd> ^This option takes three additional arguments that determine the
** [lookaside memory allocator] configuration for the [database connection].
** ^The first argument (the third parameter to [sqlite3_db_config()] is a
** pointer to a memory buffer to use for lookaside memory.
** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
** may be NULL in which case SQLite will allocate the
** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
** size of each lookaside buffer slot. ^The third argument is the number of
** slots. The size of the buffer in the first argument must be greater than
** or equal to the product of the second and third arguments. The buffer
** must be aligned to an 8-byte boundary. ^If the second argument to
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
** rounded down to the next smaller multiple of 8. ^(The lookaside memory
** configuration for a database connection can only be changed when that
** connection is not currently using lookaside memory, or in other words
** when the "current value" returned by
** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
** Any attempt to change the lookaside memory configuration when lookaside
** memory is in use leaves the configuration unchanged and returns
** [SQLITE_BUSY].)^</dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
** <dd> ^This option is used to enable or disable the enforcement of
** [foreign key constraints]. There should be two additional arguments.
** The first argument is an integer which is 0 to disable FK enforcement,
** positive to enable FK enforcement or negative to leave FK enforcement
** unchanged. The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether FK enforcement is off or on
** following this call. The second parameter may be a NULL pointer, in
** which case the FK enforcement setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
** There should be two additional arguments.
** The first argument is an integer which is 0 to disable triggers,
** positive to enable triggers or negative to leave the setting unchanged.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether triggers are disabled or enabled
** following this call. The second parameter may be a NULL pointer, in
** which case the trigger setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
** <dd> ^This option is used to enable or disable the two-argument
** version of the [fts3_tokenizer()] function which is part of the
** [FTS3] full-text search engine extension.
** There should be two additional arguments.
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
** positive to enable fts3_tokenizer() or negative to leave the setting
** unchanged.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
** following this call. The second parameter may be a NULL pointer, in
** which case the new setting is not reported back. </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
** interface independently of the [load_extension()] SQL function.
** The [sqlite3_enable_load_extension()] API enables or disables both the
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
** There should be two additional arguments.
** When the first argument to this interface is 1, then only the C-API is
** enabled and the SQL function remains disabled. If the first argument to
** this interface is 0, then both the C-API and the SQL function are disabled.
** If the first argument is -1, then no changes are made to state of either the
** C-API or the SQL function.
** The second parameter is a pointer to an integer into which
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
** is disabled or enabled following this call. The second parameter may
** be a NULL pointer, in which case the new setting is not reported back.
** </dd>
**
** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
** <dd> ^This option is used to change the name of the "main" database
** schema. ^The sole argument is a pointer to a constant UTF8 string
** which will become the new schema name in place of "main". ^SQLite
** does not make a copy of the new main schema name string, so the application
** must ensure that the argument passed into this DBCONFIG option is unchanged
** until after the database connection closes.
** </dd>
**
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
** <dd> Usually, when a database in wal mode is closed or detached from a
** database handle, SQLite checks if this will mean that there are now no
** connections at all to the database. If so, it performs a checkpoint
** operation before closing the connection. This option may be used to
** override this behaviour. The first parameter passed to this operation
** is an integer - non-zero to disable checkpoints-on-close, or zero (the
** default) to enable them. The second parameter is a pointer to an integer
** into which is written 0 or 1 to indicate whether checkpoints-on-close
** have been disabled - 0 if they are not disabled, 1 if they are.
** </dd>
**
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
** a single SQL query statement will always use the same algorithm regardless
** of values of [bound parameters].)^ The QPSG disables some query optimizations
** that look at the values of bound parameters, which can make some queries
** slower. But the QPSG has the advantage of more predictable behavior. With
** the QPSG active, SQLite will always use the same query plan in the field as
** was used during testing in the lab.
** </dd>
**
** </dl>
** CAPI3REF: Database Connection For Functions
** METHOD: sqlite3_context
**
** ^The sqlite3_context_db_handle() interface returns a copy of
** the pointer to the [database connection] (the 1st parameter)
** of the [sqlite3_create_function()]
** and [sqlite3_create_function16()] routines that originally
** registered the application defined function.
** CAPI3REF: Free Memory Used By A Database Connection
** METHOD: sqlite3
**
** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
** memory as possible from database connection D. Unlike the
** [sqlite3_release_memory()] interface, this interface is in effect even
** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
** omitted.
**
** See also: [sqlite3_release_memory()]
Create a new tokenizer
Session object
Database Name NULL
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
** but are associated with the library instead of the header file. ^(Cautious
** programmers might include assert() statements in their application to
** verify that values returned by these interfaces match the macros in
** the header, and thus ensure that the application is
** compiled with matching library and header files.
**
** <blockquote><pre>
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
** </pre></blockquote>)^
**
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
** macro. ^The sqlite3_libversion() function returns a pointer to the
** to the sqlite3_version[] string constant. The sqlite3_libversion()
** function is provided for use in DLLs since DLL users usually do not have
** direct access to string constants within the DLL. ^The
** sqlite3_libversion_number() function returns an integer equal to
** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
** a pointer to a string constant whose value is the same as the
** [SQLITE_SOURCE_ID] C preprocessor macro.
**
** See also: [sqlite_version()] and [sqlite_source_id()].
The ORDER BY clause
** CAPI3REF: Load An Extension
** METHOD: sqlite3
**
** ^This interface loads an SQLite extension library from the named file.
**
** ^The sqlite3_load_extension() interface attempts to load an
** [SQLite extension] library contained in the file zFile. If
** the file cannot be loaded directly, attempts are made to load
** with various operating-system specific extensions added.
** So for example, if "samplelib" cannot be loaded, then names like
** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
** be tried also.
**
** ^The entry point is zProc.
** ^(zProc may be 0, in which case SQLite will try to come up with an
** entry point name on its own. It first tries "sqlite3_extension_init".
** If that does not work, it constructs a name "sqlite3_X_init" where the
** X is consists of the lower-case equivalent of all ASCII alphabetic
** characters in the filename from the last "/" to the first following
** "." and omitting any initial "lib".)^
** ^The sqlite3_load_extension() interface returns
** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
** ^If an error occurs and pzErrMsg is not 0, then the
** [sqlite3_load_extension()] interface shall attempt to
** fill *pzErrMsg with error message text stored in memory
** obtained from [sqlite3_malloc()]. The calling function
** should free this memory by calling [sqlite3_free()].
**
** ^Extension loading must be enabled using
** [sqlite3_enable_load_extension()] or
** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
** prior to calling this API,
** otherwise an error will be returned.
**
** <b>Security warning:</b> It is recommended that the
** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
** interface. The use of the [sqlite3_enable_load_extension()] interface
** should be avoided. This will keep the SQL function [load_extension()]
** disabled and prevent SQL injections from giving attackers
** access to extension loading capabilities.
**
** See also the [load_extension() SQL function].
** CAPI3REF: Name Of A Host Parameter
** METHOD: sqlite3_stmt
**
** ^The sqlite3_bind_parameter_name(P,N) interface returns
** the name of the N-th [SQL parameter] in the [prepared statement] P.
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
** respectively.
** In other words, the initial ":" or "$" or "@" or "?"
** is included as part of the name.)^
** ^Parameters of the form "?" without a following integer have no name
** and are referred to as "nameless" or "anonymous parameters".
**
** ^The first host parameter has an index of 1, not 0.
**
** ^If the value N is out of range or if the N-th parameter is
** nameless, then NULL is returned. ^The returned string is
** always in UTF-8 encoding even if the named parameter was
** originally specified as UTF-16 in [sqlite3_prepare16()],
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_count()], and
** [sqlite3_bind_parameter_index()].
OUT: Size of buffer at *ppChangeset
Currently always set to 3
Score of parent node
First argument passed to xConflict
Generic error
** CAPI3REF: Create A New Changegroup Object
**
** An sqlite3_changegroup object is used to combine two or more changesets
** (or patchsets) into a single changeset (or patchset). A single changegroup
** object may combine changesets or patchsets, but not both. The output is
** always in the same format as the input.
**
** If successful, this function returns SQLITE_OK and populates (*pp) with
** a pointer to a new sqlite3_changegroup object before returning. The caller
** should eventually free the returned object using a call to
** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
**
** The usual usage pattern for an sqlite3_changegroup object is as follows:
**
** <ul>
** <li> It is created using a call to sqlite3changegroup_new().
**
** <li> Zero or more changesets (or patchsets) are added to the object
** by calling sqlite3changegroup_add().
**
** <li> The result of combining all input changesets together is obtained
** by the application via a call to sqlite3changegroup_output().
**
** <li> The object is deleted using a call to sqlite3changegroup_delete().
** </ul>
**
** Any number of calls to add() and output() may be made between the calls to
** new() and delete(), and in any order.
**
** As well as the regular sqlite3changegroup_add() and
** sqlite3changegroup_output() functions, also available are the streaming
** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
** CAPI3REF: Flush caches to disk mid-transaction
**
** ^If a write-transaction is open on [database connection] D when the
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
** pages in the pager-cache that are not currently in use are written out
** to disk. A dirty page may be in use if a database cursor created by an
** active SQL statement is reading from it, or if it is page 1 of a database
** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]
** interface flushes caches for all schemas - "main", "temp", and
** any [attached] databases.
**
** ^If this function needs to obtain extra database locks before dirty pages
** can be flushed to disk, it does so. ^If those locks cannot be obtained
** immediately and there is a busy-handler callback configured, it is invoked
** in the usual manner. ^If the required lock still cannot be obtained, then
** the database is skipped and an attempt made to flush any dirty pages
** belonging to the next (if any) database. ^If any databases are skipped
** because locks cannot be obtained, but no other error occurs, this
** function returns SQLITE_BUSY.
**
** ^If any other error occurs while flushing dirty pages to disk (for
** example an IO error or out-of-memory condition), then processing is
** abandoned and an SQLite [error code] is returned to the caller immediately.
**
** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
**
** ^This function does not set the database handle error code or message
** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
** CAPI3REF: Authorizer Action Codes
**
** The [sqlite3_set_authorizer()] interface registers a callback function
** that is invoked to authorize certain SQL statement actions. The
** second parameter to the callback is an integer code that specifies
** what action is being authorized. These are the integer action codes that
** the authorizer callback may be passed.
**
** These action code values signify what kind of operation is to be
** authorized. The 3rd and 4th parameters to the authorization
** callback function will be parameters or NULL depending on which of these
** codes is used as the second parameter. ^(The 5th parameter to the
** authorizer callback is the name of the database ("main", "temp",
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
** is the name of the inner-most trigger or view that is responsible for
** the access attempt or NULL if this access attempt is directly from
** top-level SQL code.
Entry point. Derived from zFile if 0
Mask of SQLITE_INDEX_SCAN_* flags
** CAPI3REF: SQL Function Context Object
**
** The context in which an SQL function executes is stored in an
** sqlite3_context object. ^A pointer to an sqlite3_context object
** is always first parameter to [application-defined SQL functions].
** The application-defined SQL function implementation will pass this
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
** and/or [sqlite3_set_auxdata()].
Copy of 2nd argument to xTokenize()
Table Name NULL
** A pointer to a structure of the following type is passed as the first
** argument to callbacks registered using rtree_geometry_callback().
comment:
** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
**
** This function should only be used with iterator objects passed to a
** conflict-handler callback by [sqlite3changeset_apply()] with either
** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
** is set to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the
** "conflicting row" associated with the current conflict-handler callback
** and returns SQLITE_OK.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
deprecated names
comment: No longer used
label: code-design
SQLITE_CHECKPOINT_* value
******* End of fts5.h ********
OUT: Pointer to table name
Put error message here if not 0
OUT: Value from conflicting row
VFS only
** CAPI3REF: Declared Datatype Of A Query Result
** METHOD: sqlite3_stmt
**
** ^(The first parameter is a [prepared statement].
** If this statement is a [SELECT] statement and the Nth column of the
** returned result set of that [SELECT] is a table column (not an
** expression or subquery) then the declared type of the table
** column is returned.)^ ^If the Nth column of the result set is an
** expression or subquery, then a NULL pointer is returned.
** ^The returned string is always UTF-8 encoded.
**
** ^(For example, given the database schema:
**
** CREATE TABLE t1(c1 VARIANT);
**
** and the following statement to be compiled:
**
** SELECT c1 + 1, c1 FROM t1;
**
** this routine would return the string "VARIANT" for the second result
** column (i==1), and a NULL pointer for the first result column (i==0).)^
**
** ^SQLite uses dynamic run-time typing. ^So just because a column
** is declared to contain a particular type does not mean that the
** data stored in that column is of the declared type. SQLite is
** strongly typed, but the typing is dynamic not static. ^Type
** is associated with individual values, not with the containers
** used to hold those values.
For use by extension VFS
comment: Do not code a test for this constraint
label: test
** CAPI3REF: Configure database connections
** METHOD: sqlite3
**
** The sqlite3_db_config() interface is used to make configuration
** changes to a [database connection]. The interface is similar to
** [sqlite3_config()] except that the changes apply to a single
** [database connection] (specified in the first argument).
**
** The second argument to sqlite3_db_config(D,V,...) is the
** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
** that indicates what aspect of the [database connection] is being configured.
** Subsequent arguments vary depending on the configuration verb.
**
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
** the call is considered successful.
comment:
** CAPI3REF: Name Of The Folder Holding Database Files
**
** ^(If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all database files
** specified with a relative pathname and created or accessed by
** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
** to be relative to that directory.)^ ^If this variable is a NULL
** pointer, then SQLite assumes that all database files specified
** with a relative pathname are relative to the current directory
** for the process. Only the windows VFS makes use of this global
** variable; it is ignored by the unix VFS.
**
** Changing the value of this variable while a database connection is
** open can result in a corrupt database.
**
** It is not safe to read or modify this variable in more than one
** thread at a time. It is not safe to read or modify this variable
** if a [database connection] is being used at the same time in a separate
** thread.
** It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been called and that this variable remain unchanged
** thereafter.
**
** ^The [data_store_directory pragma] may modify this variable and cause
** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
** the [data_store_directory pragma] always assumes that any string
** that this variable points to is held in memory obtained from
** [sqlite3_malloc] and the pragma may attempt to free that memory
** using [sqlite3_free].
** Hence, if this variable is modified directly, either it should be
** made NULL or made to point to memory obtained from [sqlite3_malloc]
** or else the use of the [data_store_directory pragma] should be avoided.
label: code-design
comment:
** CAPI3REF: Memory Allocation Subsystem
**
** The SQLite core uses these three routines for all of its own
** internal memory allocation needs. "Core" in the previous sentence
** does not include operating-system specific VFS implementation. The
** Windows VFS uses native malloc() and free() for some operations.
**
** ^The sqlite3_malloc() routine returns a pointer to a block
** of memory at least N bytes in length, where N is the parameter.
** ^If sqlite3_malloc() is unable to obtain sufficient free
** memory, it returns a NULL pointer. ^If the parameter N to
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
** a NULL pointer.
**
** ^The sqlite3_malloc64(N) routine works just like
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
** of a signed 32-bit integer.
**
** ^Calling sqlite3_free() with a pointer previously returned
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
** that it might be reused. ^The sqlite3_free() routine is
** a no-op if is called with a NULL pointer. Passing a NULL pointer
** to sqlite3_free() is harmless. After being freed, memory
** should neither be read nor written. Even reading previously freed
** memory might result in a segmentation fault or other severe error.
** Memory corruption, a segmentation fault, or other severe error
** might result if sqlite3_free() is called with a non-NULL pointer that
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
**
** ^The sqlite3_realloc(X,N) interface attempts to resize a
** prior memory allocation X to be at least N bytes.
** ^If the X parameter to sqlite3_realloc(X,N)
** is a NULL pointer then its behavior is identical to calling
** sqlite3_malloc(N).
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
** negative then the behavior is exactly the same as calling
** sqlite3_free(X).
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
** of at least N bytes in size or NULL if insufficient memory is available.
** ^If M is the size of the prior allocation, then min(N,M) bytes
** of the prior allocation are copied into the beginning of buffer returned
** by sqlite3_realloc(X,N) and the prior allocation is freed.
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
** prior allocation is not freed.
**
** ^The sqlite3_realloc64(X,N) interfaces works the same as
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
** of a 32-bit signed integer.
**
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
** sqlite3_msize(X) returns the size of that memory allocation in bytes.
** ^The value returned by sqlite3_msize(X) might be larger than the number
** of bytes requested when X was allocated. ^If X is a NULL pointer then
** sqlite3_msize(X) returns zero. If X points to something that is not
** the beginning of memory allocation, or if it points to a formerly
** valid memory allocation that has now been freed, then the behavior
** of sqlite3_msize(X) is undefined and possibly harmful.
**
** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
** sqlite3_malloc64(), and sqlite3_realloc64()
** is always aligned to at least an 8 byte boundary, or to a
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
** option is used.
**
** In SQLite version 3.5.0 and 3.5.1, it was possible to define
** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
** implementation of these routines to be omitted. That capability
** is no longer provided. Only built-in memory allocators can be used.
**
** Prior to SQLite version 3.7.10, the Windows OS interface layer called
** the system malloc() and free() directly when converting
** filenames between the UTF-8 encoding used by SQLite
** and whatever filename encoding is used by the particular Windows
** installation. Memory allocation errors were detected, but
** they were reported back as [SQLITE_CANTOPEN] or
** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
**
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
** must be either NULL or else pointers obtained from a prior
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
** not yet been released.
**
** The application must not read or write any part of
** a block of memory after it has been released using
** [sqlite3_free()] or [sqlite3_realloc()].
label: code-design
For use by application VFS
Size of array aParam[]
beginning-of-error-codes
** CAPI3REF: Reset A Prepared Statement Object
** METHOD: sqlite3_stmt
**
** The sqlite3_reset() function is called to reset a [prepared statement]
** object back to its initial state, ready to be re-executed.
** ^Any SQL statement variables that had values bound to them using
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
** Use [sqlite3_clear_bindings()] to reset the bindings.
**
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
** back to the beginning of its program.
**
** ^If the most recent call to [sqlite3_step(S)] for the
** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
** or if [sqlite3_step(S)] has never before been called on S,
** then [sqlite3_reset(S)] returns [SQLITE_OK].
**
** ^If the most recent call to [sqlite3_step(S)] for the
** [prepared statement] S indicated an error, then
** [sqlite3_reset(S)] returns an appropriate [error code].
**
** ^The [sqlite3_reset(S)] interface does not change the values
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
** CAPI3REF: Move a BLOB Handle to a New Row
** METHOD: sqlite3_blob
**
** ^This function is used to move an existing [BLOB handle] so that it points
** to a different row of the same database table. ^The new row is identified
** by the rowid value passed as the second argument. Only the row can be
** changed. ^The database, table and column on which the blob handle is open
** remain the same. Moving an existing [BLOB handle] to a new row is
** faster than closing the existing handle and opening a new one.
**
** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
** it must exist and there must be either a blob or text value stored in
** the nominated column.)^ ^If the new row is not present in the table, or if
** it does not contain a blob or text value, or if another error occurs, an
** SQLite error code is returned and the blob handle is considered aborted.
** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
** always returns zero.
**
** ^This function sets the database handle error code and message.
Iterator object
OUT: Buffer containing output changeset
Pointer to blob containing changeset
** 2010 August 30
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** CAPI3REF: Reset Automatic Extension Loading
**
** ^This interface disables all automatic extensions previously
** registered using [sqlite3_auto_extension()].
Name of VFS module to use
** CAPI3REF: String Globbing
*
** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
** string X matches the [GLOB] pattern P.
** ^The definition of [GLOB] pattern matching used in
** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function
** is case sensitive.
**
** Note that this routine returns zero on a match and non-zero if the strings
** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
**
** See also: [sqlite3_strlike()].
** CAPI3REF: Custom Page Cache Object
**
** The sqlite3_pcache_page object represents a single page in the
** page cache. The page cache will allocate instances of this
** object. Various methods of the page cache use pointers to instances
** of this object as parameters or as their return value.
**
** See [sqlite3_pcache_methods2] for additional information.
Number of entries in aConstraint
comment:
** CAPI3REF: Unlock Notification
** METHOD: sqlite3
**
** ^When running in shared-cache mode, a database operation may fail with
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
** individual tables within the shared-cache cannot be obtained. See
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
** ^This API may be used to register a callback that SQLite will invoke
** when the connection currently holding the required lock relinquishes it.
** ^This API is only available if the library was compiled with the
** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
**
** See Also: [Using the SQLite Unlock Notification Feature].
**
** ^Shared-cache locks are released when a database connection concludes
** its current transaction, either by committing it or rolling it back.
**
** ^When a connection (known as the blocked connection) fails to obtain a
** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
** identity of the database connection (the blocking connection) that
** has locked the required resource is stored internally. ^After an
** application receives an SQLITE_LOCKED error, it may call the
** sqlite3_unlock_notify() method with the blocked connection handle as
** the first argument to register for a callback that will be invoked
** when the blocking connections current transaction is concluded. ^The
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
** call that concludes the blocking connections transaction.
**
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
** there is a chance that the blocking connection will have already
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
** If this happens, then the specified callback is invoked immediately,
** from within the call to sqlite3_unlock_notify().)^
**
** ^If the blocked connection is attempting to obtain a write-lock on a
** shared-cache table, and more than one other connection currently holds
** a read-lock on the same table, then SQLite arbitrarily selects one of
** the other connections to use as the blocking connection.
**
** ^(There may be at most one unlock-notify callback registered by a
** blocked connection. If sqlite3_unlock_notify() is called when the
** blocked connection already has a registered unlock-notify callback,
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
** called with a NULL pointer as its second argument, then any existing
** unlock-notify callback is canceled. ^The blocked connections
** unlock-notify callback may also be canceled by closing the blocked
** connection using [sqlite3_close()].
**
** The unlock-notify callback is not reentrant. If an application invokes
** any sqlite3_xxx API functions from within an unlock-notify callback, a
** crash or deadlock may be the result.
**
** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
** returns SQLITE_OK.
**
** <b>Callback Invocation Details</b>
**
** When an unlock-notify callback is registered, the application provides a
** single void* pointer that is passed to the callback when it is invoked.
** However, the signature of the callback function allows SQLite to pass
** it an array of void* context pointers. The first argument passed to
** an unlock-notify callback is a pointer to an array of void* pointers,
** and the second is the number of entries in the array.
**
** When a blocking connections transaction is concluded, there may be
** more than one blocked connection that has registered for an unlock-notify
** callback. ^If two or more such blocked connections have specified the
** same callback function, then instead of invoking the callback function
** multiple times, it is invoked once with the set of void* context pointers
** specified by the blocked connections bundled together into an array.
** This gives the application an opportunity to prioritize any actions
** related to the set of unblocked database connections.
**
** <b>Deadlock Detection</b>
**
** Assuming that after registering for an unlock-notify callback a
** database waits for the callback to be issued before taking any further
** action (a reasonable assumption), then using this API may cause the
** application to deadlock. For example, if connection X is waiting for
** connection Y's transaction to be concluded, and similarly connection
** Y is waiting on connection X's transaction, then neither connection
** will proceed and the system may remain deadlocked indefinitely.
**
** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
** detection. ^If a given call to sqlite3_unlock_notify() would put the
** system in a deadlocked state, then SQLITE_LOCKED is returned and no
** unlock-notify callback is registered. The system is said to be in
** a deadlocked state if connection A has registered for an unlock-notify
** callback on the conclusion of connection B's transaction, and connection
** B has itself registered for an unlock-notify callback when connection
** A's transaction is concluded. ^Indirect deadlock is also detected, so
** the system is also considered to be deadlocked if connection B has
** registered for an unlock-notify callback on the conclusion of connection
** C's transaction, where connection C is waiting on connection A. ^Any
** number of levels of indirection are allowed.
**
** <b>The "DROP TABLE" Exception</b>
**
** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
** always appropriate to call sqlite3_unlock_notify(). There is however,
** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
** SQLite checks if there are any currently executing SELECT statements
** that belong to the same connection. If there are, SQLITE_LOCKED is
** returned. In this case there is no "blocking connection", so invoking
** sqlite3_unlock_notify() results in the unlock-notify callback being
** invoked immediately. If the application then re-attempts the "DROP TABLE"
** or "DROP INDEX" query, an infinite loop might be the result.
**
** One way around this problem is to check the extended error code returned
** by an sqlite3_step() call. ^(If there is a blocking connection, then the
** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
** the special "DROP TABLE/INDEX" case, the extended error code is just
** SQLITE_LOCKED.)^
label: code-design
Fields below are only available in SQLite 3.8.2 and later
comment: OUT: Pointer to unused portion of zSql
label: code-design
Abort due to constraint violation
Library used incorrectly
OUT: New value (or NULL pointer)
const char*
** CAPI3REF: Generate A Changeset From A Session Object
**
** Obtain a changeset containing changes to the tables attached to the
** session object passed as the first argument. If successful,
** set *ppChangeset to point to a buffer containing the changeset
** and *pnChangeset to the size of the changeset in bytes before returning
** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
** zero and return an SQLite error code.
**
** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
** each representing a change to a single row of an attached table. An INSERT
** change contains the values of each field of a new database row. A DELETE
** contains the original values of each field of a deleted database row. An
** UPDATE change contains the original values of each field of an updated
** database row along with the updated values for each updated non-primary-key
** column. It is not possible for an UPDATE change to represent a change that
** modifies the values of primary key columns. If such a change is made, it
** is represented in a changeset as a DELETE followed by an INSERT.
**
** Changes are not recorded for rows that have NULL values stored in one or
** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
** no corresponding change is present in the changesets returned by this
** function. If an existing row with one or more NULL values stored in
** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
** only an INSERT is appears in the changeset. Similarly, if an existing row
** with non-NULL PRIMARY KEY values is updated so that one or more of its
** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
** DELETE change only.
**
** The contents of a changeset may be traversed using an iterator created
** using the [sqlite3changeset_start()] API. A changeset may be applied to
** a database with a compatible schema using the [sqlite3changeset_apply()]
** API.
**
** Within a changeset generated by this function, all changes related to a
** single table are grouped together. In other words, when iterating through
** a changeset or when applying a changeset to a database, all changes related
** to a single table are processed before moving on to the next table. Tables
** are sorted in the same order in which they were attached (or auto-attached)
** to the sqlite3_session object. The order in which the changes related to
** a single table are stored is undefined.
**
** Following a successful call to this function, it is the responsibility of
** the caller to eventually free the buffer that *ppChangeset points to using
** [sqlite3_free()].
**
** <h3>Changeset Generation</h3>
**
** Once a table has been attached to a session object, the session object
** records the primary key values of all new rows inserted into the table.
** It also records the original primary key and other column values of any
** deleted or updated rows. For each unique primary key value, data is only
** recorded once - the first time a row with said primary key is inserted,
** updated or deleted in the lifetime of the session.
**
** There is one exception to the previous paragraph: when a row is inserted,
** updated or deleted, if one or more of its primary key columns contain a
** NULL value, no record of the change is made.
**
** The session object therefore accumulates two types of records - those
** that consist of primary key values only (created when the user inserts
** a new record) and those that consist of the primary key values and the
** original values of other table columns (created when the users deletes
** or updates a record).
**
** When this function is called, the requested changeset is created using
** both the accumulated records and the current contents of the database
** file. Specifically:
**
** <ul>
** <li> For each record generated by an insert, the database is queried
** for a row with a matching primary key. If one is found, an INSERT
** change is added to the changeset. If no such row is found, no change
** is added to the changeset.
**
** <li> For each record generated by an update or delete, the database is
** queried for a row with a matching primary key. If such a row is
** found and one or more of the non-primary key fields have been
** modified from their original values, an UPDATE change is added to
** the changeset. Or, if no such row is found in the table, a DELETE
** change is added to the changeset. If there is a row with a matching
** primary key in the database, but all fields contain their original
** values, no change is added to the changeset.
** </ul>
**
** This means, amongst other things, that if a row is inserted and then later
** deleted while a session object is active, neither the insert nor the delete
** will be present in the changeset. Or if a row is deleted and then later a
** row with the same primary key values inserted while a session object is
** active, the resulting changeset will contain an UPDATE change instead of
** a DELETE and an INSERT.
**
** When a session object is disabled (see the [sqlite3session_enable()] API),
** it does not accumulate records when rows are inserted, updated or deleted.
** This may appear to have some counter-intuitive effects if a single row
** is written to more than once during a session. For example, if a row
** is inserted while a session object is enabled, then later deleted while
** the same session object is disabled, no INSERT record will appear in the
** changeset, even though the delete took place while the session was disabled.
** Or, if one field of a row is updated while a session is disabled, and
** another field of the same row is updated while the session is enabled, the
** resulting changeset will contain an UPDATE change that updates both fields.
Index Name NULL
Copy of pContext passed to s_r_g_c()
Callback function
Number of bytes in buffer pA
Like RESTART but also truncate WAL
****************************************** 3rd ************ 4th **********
Database name or NULL
** CAPI3REF: Start a read transaction on an historical snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
** read transaction for schema S of
** [database connection] D such that the read transaction
** refers to historical [snapshot] P, rather than the most
** recent change to the database.
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
** or an appropriate [error code] if it fails.
**
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
** the first operation following the [BEGIN] that takes the schema S
** out of [autocommit mode].
** ^In other words, schema S must not currently be in
** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
** database connection D must be out of [autocommit mode].
** ^A [snapshot] will fail to open if it has been overwritten by a
** [checkpoint].
** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
** database connection D does not know that the database file for
** schema S is in [WAL mode]. A database connection might not know
** that the database file is in [WAL mode] if there has been no prior
** I/O on that database connection, or if the database entered [WAL mode]
** after the most recent I/O on the database connection.)^
** (Hint: Run "[PRAGMA application_id]" against a newly opened
** database connection in order to make it ready to use snapshots.)
**
** The [sqlite3_snapshot_open()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
Copy of sixth arg to _apply()
** CAPI3REF: Set a table filter on a Session Object.
**
** The second argument (xFilter) is the "filter callback". For changes to rows
** in tables that are not attached to the Session object, the filter is called
** to determine whether changes to the table's rows should be tracked or not.
** If xFilter returns 0, changes is not tracked. Note that once a table is
** attached, xFilter will not be called again.
** CAPI3REF: Virtual Table Indexing Information
** KEYWORDS: sqlite3_index_info
**
** The sqlite3_index_info structure and its substructures is used as part
** of the [virtual table] interface to
** pass information into and receive the reply from the [xBestIndex]
** method of a [virtual table module]. The fields under **Inputs** are the
** inputs to xBestIndex and are read-only. xBestIndex inserts its
** results into the **Outputs** fields.
**
** ^(The aConstraint[] array records WHERE clause constraints of the form:
**
** <blockquote>column OP expr</blockquote>
**
** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is
** stored in aConstraint[].op using one of the
** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
** ^(The index of the column is stored in
** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the
** expr on the right-hand side can be evaluated (and thus the constraint
** is usable) and false if it cannot.)^
**
** ^The optimizer automatically inverts terms of the form "expr OP column"
** and makes other simplifications to the WHERE clause in an attempt to
** get as many WHERE clause terms into the form shown above as possible.
** ^The aConstraint[] array only reports WHERE clause terms that are
** relevant to the particular virtual table being queried.
**
** ^Information about the ORDER BY clause is stored in aOrderBy[].
** ^Each term of aOrderBy records a column of the ORDER BY clause.
**
** The colUsed field indicates which columns of the virtual table may be
** required by the current scan. Virtual table columns are numbered from
** zero in the order in which they appear within the CREATE TABLE statement
** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
** the corresponding bit is set within the colUsed mask if the column may be
** required by SQLite. If the table has at least 64 columns and any column
** to the right of the first 63 is required, then bit 63 of colUsed is also
** set. In other words, column iCol may be required if the expression
** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
** non-zero.
**
** The [xBestIndex] method must fill aConstraintUsage[] with information
** about what parameters to pass to xFilter. ^If argvIndex>0 then
** the right-hand side of the corresponding aConstraint[] is evaluated
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
** is true, then the constraint is assumed to be fully handled by the
** virtual table and is not checked again by SQLite.)^
**
** ^The idxNum and idxPtr values are recorded and passed into the
** [xFilter] method.
** ^[sqlite3_free()] is used to free idxPtr if and only if
** needToFreeIdxPtr is true.
**
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
** the correct order to satisfy the ORDER BY clause so that no separate
** sorting step is required.
**
** ^The estimatedCost value is an estimate of the cost of a particular
** strategy. A cost of N indicates that the cost of the strategy is similar
** to a linear scan of an SQLite table with N rows. A cost of log(N)
** indicates that the expense of the operation is similar to that of a
** binary search on a unique indexed field of an SQLite table with N rows.
**
** ^The estimatedRows value is an estimate of the number of rows that
** will be returned by the strategy.
**
** The xBestIndex method may optionally populate the idxFlags field with a
** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
** assumes that the strategy may visit at most one row.
**
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
** SQLite also assumes that if a call to the xUpdate() method is made as
** part of the same statement to delete or update a virtual table row and the
** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
** any database changes. In other words, if the xUpdate() returns
** SQLITE_CONSTRAINT, the database contents must be exactly as they were
** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
** the xUpdate method are automatically rolled back by SQLite.
**
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
** If a virtual table extension is
** used with an SQLite version earlier than 3.8.2, the results of attempting
** to read or write the estimatedRows field are undefined (but are likely
** to included crashing the application). The estimatedRows field should
** therefore only be used if [sqlite3_libversion_number()] returns a
** value greater than or equal to 3008002. Similarly, the idxFlags field
** was added for [version 3.9.0] ([dateof:3.9.0]).
** It may therefore only be used if
** sqlite3_libversion_number() returns a value greater than or equal to
** 3009000.
IMP: R-03371-37637
Callback routine requested an abort
OUTPUT: Collation sequence name
Size of subclassed sqlite3_file
Source database handle
Changeset iterator
OUT: Size of output buffer in bytes
** The methods above are in versions 1 through 3 of the sqlite_vfs object.
** New fields may be appended in future versions. The iVersion
** value will increment whenever this happens.
sqlite3_step() has another row ready
Rowid for current entry
nil
Apply change to "main" db of this handle
The new key
Number of values in apVal[] array
comment:
** CAPI3REF: One-Step Query Execution Interface
** METHOD: sqlite3
**
** The sqlite3_exec() interface is a convenience wrapper around
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
** that allows an application to run multiple statements of SQL
** without having to use a lot of C code.
**
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
** semicolon-separate SQL statements passed into its 2nd argument,
** in the context of the [database connection] passed in as its 1st
** argument. ^If the callback function of the 3rd argument to
** sqlite3_exec() is not NULL, then it is invoked for each result row
** coming out of the evaluated SQL statements. ^The 4th argument to
** sqlite3_exec() is relayed through to the 1st argument of each
** callback invocation. ^If the callback pointer to sqlite3_exec()
** is NULL, then no callback is ever invoked and result rows are
** ignored.
**
** ^If an error occurs while evaluating the SQL statements passed into
** sqlite3_exec(), then execution of the current statement stops and
** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
** is not NULL then any error message is written into memory obtained
** from [sqlite3_malloc()] and passed back through the 5th parameter.
** To avoid memory leaks, the application should invoke [sqlite3_free()]
** on error message strings returned through the 5th parameter of
** sqlite3_exec() after the error message string is no longer needed.
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
** NULL before returning.
**
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
** routine returns SQLITE_ABORT without invoking the callback again and
** without running any subsequent SQL statements.
**
** ^The 2nd argument to the sqlite3_exec() callback function is the
** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
** callback is an array of pointers to strings obtained as if from
** [sqlite3_column_text()], one for each column. ^If an element of a
** result row is NULL then the corresponding string pointer for the
** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
** sqlite3_exec() callback is an array of pointers to strings where each
** entry represents the name of corresponding result column as obtained
** from [sqlite3_column_name()].
**
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
** to an empty string, or a pointer that contains only whitespace and/or
** SQL comments, then no SQL statements are evaluated and the database
** is not changed.
**
** Restrictions:
**
** <ul>
** <li> The application must ensure that the 1st parameter to sqlite3_exec()
** is a valid and open [database connection].
** <li> The application must not close the [database connection] specified by
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
** <li> The application must not modify the SQL statement text passed into
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
** </ul>
label: code-design
** CAPI3REF: Function Flags
**
** These constants may be ORed together with the
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
** [sqlite3_create_function_v2()].
Size of token in bytes
Used by PRAGMA temp_store_directory
Object fully contained within query region
** CAPI3REF: SQL Trace Event Codes
** KEYWORDS: SQLITE_TRACE
**
** These constants identify classes of events that can be monitored
** using the [sqlite3_trace_v2()] tracing logic. The third argument
** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
** the following constants. ^The first argument to the trace callback
** is one of the following constants.
**
** New tracing constants may be added in future releases.
**
** ^A trace callback has four arguments: xCallback(T,C,P,X).
** ^The T argument is one of the integer type codes above.
** ^The C argument is a copy of the context pointer passed in as the
** fourth argument to [sqlite3_trace_v2()].
** The P and X arguments are pointers whose meanings depend on T.
**
** <dl>
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
** first begins running and possibly at other times during the
** execution of the prepared statement, such as at the start of each
** trigger subprogram. ^The P argument is a pointer to the
** [prepared statement]. ^The X argument is a pointer to a string which
** is the unexpanded SQL text of the prepared statement or an SQL comment
** that indicates the invocation of a trigger. ^The callback can compute
** the same text that would have been returned by the legacy [sqlite3_trace()]
** interface by using the X argument when X begins with "--" and invoking
** [sqlite3_expanded_sql(P)] otherwise.
**
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
** information as is provided by the [sqlite3_profile()] callback.
** ^The P argument is a pointer to the [prepared statement] and the
** X argument points to a 64-bit integer which is the estimated of
** the number of nanosecond that the prepared statement took to run.
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
**
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
** statement generates a single row of result.
** ^The P argument is a pointer to the [prepared statement] and the
** X argument is unused.
**
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
** connection closes.
** ^The P argument is a pointer to the [database connection] object
** and the X argument is unused.
** </dl>
comment:
** CAPI3REF: Application Defined Page Cache.
** KEYWORDS: {page cache}
**
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
** register an alternative page cache implementation by passing in an
** instance of the sqlite3_pcache_methods2 structure.)^
** In many applications, most of the heap memory allocated by
** SQLite is used for the page cache.
** By implementing a
** custom page cache using this API, an application can better control
** the amount of memory consumed by SQLite, the way in which
** that memory is allocated and released, and the policies used to
** determine exactly which parts of a database file are cached and for
** how long.
**
** The alternative page cache mechanism is an
** extreme measure that is only needed by the most demanding applications.
** The built-in page cache is recommended for most uses.
**
** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
** the application may discard the parameter after the call to
** [sqlite3_config()] returns.)^
**
** [[the xInit() page cache method]]
** ^(The xInit() method is called once for each effective
** call to [sqlite3_initialize()])^
** (usually only once during the lifetime of the process). ^(The xInit()
** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
** The intent of the xInit() method is to set up global data structures
** required by the custom page cache implementation.
** ^(If the xInit() method is NULL, then the
** built-in default page cache is used instead of the application defined
** page cache.)^
**
** [[the xShutdown() page cache method]]
** ^The xShutdown() method is called by [sqlite3_shutdown()].
** It can be used to clean up
** any outstanding resources before process shutdown, if required.
** ^The xShutdown() method may be NULL.
**
** ^SQLite automatically serializes calls to the xInit method,
** so the xInit method need not be threadsafe. ^The
** xShutdown method is only called from [sqlite3_shutdown()] so it does
** not need to be threadsafe either. All other methods must be threadsafe
** in multithreaded applications.
**
** ^SQLite will never invoke xInit() more than once without an intervening
** call to xShutdown().
**
** [[the xCreate() page cache methods]]
** ^SQLite invokes the xCreate() method to construct a new cache instance.
** SQLite will typically create one cache instance for each open database file,
** though this is not guaranteed. ^The
** first parameter, szPage, is the size in bytes of the pages that must
** be allocated by the cache. ^szPage will always a power of two. ^The
** second parameter szExtra is a number of bytes of extra storage
** associated with each page cache entry. ^The szExtra parameter will
** a number less than 250. SQLite will use the
** extra szExtra bytes on each page to store metadata about the underlying
** database page on disk. The value passed into szExtra depends
** on the SQLite version, the target platform, and how SQLite was compiled.
** ^The third argument to xCreate(), bPurgeable, is true if the cache being
** created will be used to cache database pages of a file stored on disk, or
** false if it is used for an in-memory database. The cache implementation
** does not have to do anything special based with the value of bPurgeable;
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
** never invoke xUnpin() except to deliberately delete a page.
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
** false will always have the "discard" flag set to true.
** ^Hence, a cache created with bPurgeable false will
** never contain any unpinned pages.
**
** [[the xCachesize() page cache method]]
** ^(The xCachesize() method may be called at any time by SQLite to set the
** suggested maximum cache-size (number of pages stored by) the cache
** instance passed as the first argument. This is the value configured using
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
** parameter, the implementation is not required to do anything with this
** value; it is advisory only.
**
** [[the xPagecount() page cache methods]]
** The xPagecount() method must return the number of pages currently
** stored in the cache, both pinned and unpinned.
**
** [[the xFetch() page cache methods]]
** The xFetch() method locates a page in the cache and returns a pointer to
** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
** The pBuf element of the returned sqlite3_pcache_page object will be a
** pointer to a buffer of szPage bytes used to store the content of a
** single database page. The pExtra element of sqlite3_pcache_page will be
** a pointer to the szExtra bytes of extra storage that SQLite has requested
** for each entry in the page cache.
**
** The page to be fetched is determined by the key. ^The minimum key value
** is 1. After it has been retrieved using xFetch, the page is considered
** to be "pinned".
**
** If the requested page is already in the page cache, then the page cache
** implementation must return a pointer to the page buffer with its content
** intact. If the requested page is not already in the cache, then the
** cache implementation should use the value of the createFlag
** parameter to help it determined what action to take:
**
** <table border=1 width=85% align=center>
** <tr><th> createFlag <th> Behavior when page is not already in cache
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
** Otherwise return NULL.
** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
** NULL if allocating a new page is effectively impossible.
** </table>
**
** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
** will only use a createFlag of 2 after a prior call with a createFlag of 1
** failed.)^ In between the to xFetch() calls, SQLite may
** attempt to unpin one or more cache pages by spilling the content of
** pinned pages to disk and synching the operating system disk cache.
**
** [[the xUnpin() page cache method]]
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
** as its second argument. If the third parameter, discard, is non-zero,
** then the page must be evicted from the cache.
** ^If the discard parameter is
** zero, then the page may be discarded or retained at the discretion of
** page cache implementation. ^The page cache implementation
** may choose to evict unpinned pages at any time.
**
** The cache must not perform any reference counting. A single
** call to xUnpin() unpins the page regardless of the number of prior calls
** to xFetch().
**
** [[the xRekey() page cache methods]]
** The xRekey() method is used to change the key value associated with the
** page passed as the second argument. If the cache
** previously contains an entry associated with newKey, it must be
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
** to be pinned.
**
** When SQLite calls the xTruncate() method, the cache must discard all
** existing cache entries with page numbers (keys) greater than or equal
** to the value of the iLimit parameter passed to xTruncate(). If any
** of these pages are pinned, they are implicitly unpinned, meaning that
** they can be safely discarded.
**
** [[the xDestroy() page cache method]]
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
** All resources associated with the specified cache should be freed. ^After
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
** handle invalid, and will not use it with any other sqlite3_pcache_methods2
** functions.
**
** [[the xShrink() page cache method]]
** ^SQLite invokes the xShrink() method when it wants the page cache to
** free up as much of heap memory as possible. The page cache implementation
** is not obligated to free any memory, but well-behaved implementations should
** do their best.
label: code-design
void*, int nByte, int min
** CAPI3REF: Database Snapshot
** KEYWORDS: {snapshot} {sqlite3_snapshot}
** EXPERIMENTAL
**
** An instance of the snapshot object records the state of a [WAL mode]
** database for some specific point in history.
**
** In [WAL mode], multiple [database connections] that are open on the
** same database file can each be reading a different historical version
** of the database file. When a [database connection] begins a read
** transaction, that connection sees an unchanging copy of the database
** as it existed for the point in time when the transaction first started.
** Subsequent changes to the database from other connections are not seen
** by the reader until a new read transaction is started.
**
** The sqlite3_snapshot object records state information about an historical
** version of the database file so that it is possible to later open a new read
** transaction that sees that historical version of the database rather than
** the most recent version.
**
** The constructor for this object is [sqlite3_snapshot_get()]. The
** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
** to an historical snapshot (if possible). The destructor for
** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
comment:
** CAPI3REF: Function Auxiliary Data
** METHOD: sqlite3_context
**
** These functions may be used by (non-aggregate) SQL functions to
** associate metadata with argument values. If the same value is passed to
** multiple invocations of the same SQL function during query execution, under
** some circumstances the associated metadata may be preserved. An example
** of where this might be useful is in a regular-expression matching
** function. The compiled version of the regular expression can be stored as
** metadata associated with the pattern string.
** Then as long as the pattern string remains the same,
** the compiled regular expression can be reused on multiple
** invocations of the same function.
**
** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
** value to the application-defined function. ^N is zero for the left-most
** function argument. ^If there is no metadata
** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
** returns a NULL pointer.
**
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
** argument of the application-defined function. ^Subsequent
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
** NULL if the metadata has been discarded.
** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
** SQLite will invoke the destructor function X with parameter P exactly
** once, when the metadata is discarded.
** SQLite is free to discard the metadata at any time, including: <ul>
** <li> ^(when the corresponding function parameter changes)^, or
** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
** SQL statement)^, or
** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
** parameter)^, or
** <li> ^(during the original sqlite3_set_auxdata() call when a memory
** allocation error occurs.)^ </ul>
**
** Note the last bullet in particular. The destructor X in
** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
** should be called near the end of the function implementation and the
** function implementation should not make any use of P after
** sqlite3_set_auxdata() has been called.
**
** ^(In practice, metadata is preserved between function calls for
** function parameters that are compile-time constants, including literal
** values and [parameters] and expressions composed from the same.)^
**
** The value of the N parameter to these interfaces should be non-negative.
** Future enhancements may make use of negative N values to define new
** kinds of function caching behavior.
**
** These routines must be called from the same thread in which
** the SQL function is running.
label: code-design
** CAPI3REF: Changegroup Handle
OUT: Pointer to output buffer
Waiting connection
** CAPI3REF: Result Codes
** KEYWORDS: {result code definitions}
**
** Many SQLite functions return an integer result code from the set shown
** here in order to indicate success or failure.
**
** New error codes may be added in future versions of SQLite.
**
** See also: [extended result code definitions]
OUT: SQLITE_INSERT, DELETE or UPDATE
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
**
** ^The sqlite3_compileoption_used() function returns 0 or 1
** indicating whether the specified option was defined at
** compile time. ^The SQLITE_ prefix may be omitted from the
** option name passed to sqlite3_compileoption_used().
**
** ^The sqlite3_compileoption_get() function allows iterating
** over the list of options that were defined at compile time by
** returning the N-th compile time option string. ^If N is out of range,
** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
** prefix is omitted from any strings returned by
** sqlite3_compileoption_get().
**
** ^Support for the diagnostic functions sqlite3_compileoption_used()
** and sqlite3_compileoption_get() may be omitted by specifying the
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
**
** See also: SQL functions [sqlite_compileoption_used()] and
** [sqlite_compileoption_get()] and the [compile_options pragma].
** CAPI3REF: Recover snapshots from a wal file
** EXPERIMENTAL
**
** If all connections disconnect from a database file but do not perform
** a checkpoint, the existing wal file is opened along with the database
** file the next time the database is opened. At this point it is only
** possible to successfully call sqlite3_snapshot_open() to open the most
** recent snapshot of the database (the one at the head of the wal file),
** even though the wal file may contain other valid snapshots for which
** clients have sqlite3_snapshot handles.
**
** This function attempts to scan the wal file associated with database zDb
** of database handle db and make all valid snapshots available to
** sqlite3_snapshot_open(). It is an error if there is already a read
** transaction open on the database, or if the database is not a wal mode
** database.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
** CAPI3REF: Index Of A Parameter With A Given Name
** METHOD: sqlite3_stmt
**
** ^Return the index of an SQL parameter given its name. ^The
** index value returned is suitable for use as the second
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
** is returned if no matching parameter is found. ^The parameter
** name must be given in UTF-8 even if the original statement
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
** [sqlite3_prepare16_v3()].
**
** See also: [sqlite3_bind_blob|sqlite3_bind()],
** [sqlite3_bind_parameter_count()], and
** [sqlite3_bind_parameter_name()].
comment:
** CAPI3REF: Online Backup API.
**
** The backup API copies the content of one database into another.
** It is useful either for creating backups of databases or
** for copying in-memory databases to or from persistent files.
**
** See Also: [Using the SQLite Online Backup API]
**
** ^SQLite holds a write transaction open on the destination database file
** for the duration of the backup operation.
** ^The source database is read-locked only while it is being read;
** it is not locked continuously for the entire backup operation.
** ^Thus, the backup may be performed on a live source database without
** preventing other database connections from
** reading or writing to the source database while the backup is underway.
**
** ^(To perform a backup operation:
** <ol>
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
** backup,
** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
** the data between the two databases, and finally
** <li><b>sqlite3_backup_finish()</b> is called to release all resources
** associated with the backup operation.
** </ol>)^
** There should be exactly one call to sqlite3_backup_finish() for each
** successful call to sqlite3_backup_init().
**
** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
**
** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
** [database connection] associated with the destination database
** and the database name, respectively.
** ^The database name is "main" for the main database, "temp" for the
** temporary database, or the name specified after the AS keyword in
** an [ATTACH] statement for an attached database.
** ^The S and M arguments passed to
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
** and database name of the source database, respectively.
** ^The source and destination [database connections] (parameters S and D)
** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
** an error.
**
** ^A call to sqlite3_backup_init() will fail, returning NULL, if
** there is already a read or read-write transaction open on the
** destination database.
**
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
** returned and an error code and error message are stored in the
** destination [database connection] D.
** ^The error code and message for the failed call to sqlite3_backup_init()
** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
** [sqlite3_errmsg16()] functions.
** ^A successful call to sqlite3_backup_init() returns a pointer to an
** [sqlite3_backup] object.
** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
** sqlite3_backup_finish() functions to perform the specified backup
** operation.
**
** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
**
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
** the source and destination databases specified by [sqlite3_backup] object B.
** ^If N is negative, all remaining source pages are copied.
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
** are still more pages to be copied, then the function returns [SQLITE_OK].
** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
** from source to destination, then it returns [SQLITE_DONE].
** ^If an error occurs while running sqlite3_backup_step(B,N),
** then an [error code] is returned. ^As well as [SQLITE_OK] and
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
**
** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
** <ol>
** <li> the destination database was opened read-only, or
** <li> the destination database is using write-ahead-log journaling
** and the destination and source page sizes differ, or
** <li> the destination database is an in-memory database and the
** destination and source page sizes differ.
** </ol>)^
**
** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
** the [sqlite3_busy_handler | busy-handler function]
** is invoked (if one is specified). ^If the
** busy-handler returns non-zero before the lock is available, then
** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
** sqlite3_backup_step() can be retried later. ^If the source
** [database connection]
** is being used to write to the source database when sqlite3_backup_step()
** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
** case the call to sqlite3_backup_step() can be retried later on. ^(If
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
** [SQLITE_READONLY] is returned, then
** there is no point in retrying the call to sqlite3_backup_step(). These
** errors are considered fatal.)^ The application must accept
** that the backup operation has failed and pass the backup operation handle
** to the sqlite3_backup_finish() to release associated resources.
**
** ^The first call to sqlite3_backup_step() obtains an exclusive lock
** on the destination file. ^The exclusive lock is not released until either
** sqlite3_backup_finish() is called or the backup operation is complete
** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to
** sqlite3_backup_step() obtains a [shared lock] on the source database that
** lasts for the duration of the sqlite3_backup_step() call.
** ^Because the source database is not locked between calls to
** sqlite3_backup_step(), the source database may be modified mid-way
** through the backup process. ^If the source database is modified by an
** external process or via a database connection other than the one being
** used by the backup operation, then the backup will be automatically
** restarted by the next call to sqlite3_backup_step(). ^If the source
** database is modified by the using the same database connection as is used
** by the backup operation, then the backup database is automatically
** updated at the same time.
**
** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
**
** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
** application wishes to abandon the backup operation, the application
** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
** ^The sqlite3_backup_finish() interfaces releases all
** resources associated with the [sqlite3_backup] object.
** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
** active write-transaction on the destination database is rolled back.
** The [sqlite3_backup] object is invalid
** and may not be used following a call to sqlite3_backup_finish().
**
** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
** sqlite3_backup_step() errors occurred, regardless or whether or not
** sqlite3_backup_step() completed.
** ^If an out-of-memory condition or IO error occurred during any prior
** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
** sqlite3_backup_finish() returns the corresponding [error code].
**
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
** is not a permanent error and does not affect the return value of
** sqlite3_backup_finish().
**
** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
**
** ^The sqlite3_backup_remaining() routine returns the number of pages still
** to be backed up at the conclusion of the most recent sqlite3_backup_step().
** ^The sqlite3_backup_pagecount() routine returns the total number of pages
** in the source database at the conclusion of the most recent
** sqlite3_backup_step().
** ^(The values returned by these functions are only updated by
** sqlite3_backup_step(). If the source database is modified in a way that
** changes the size of the source database or the number of pages remaining,
** those changes are not reflected in the output of sqlite3_backup_pagecount()
** and sqlite3_backup_remaining() until after the next
** sqlite3_backup_step().)^
**
** <b>Concurrent Usage of Database Handles</b>
**
** ^The source [database connection] may be used by the application for other
** purposes while a backup operation is underway or being initialized.
** ^If SQLite is compiled and configured to support threadsafe database
** connections, then the source database connection may be used concurrently
** from within other threads.
**
** However, the application must guarantee that the destination
** [database connection] is not passed to any other API (by any thread) after
** sqlite3_backup_init() is called and before the corresponding call to
** sqlite3_backup_finish(). SQLite does not currently check to see
** if the application incorrectly accesses the destination [database connection]
** and so no error code is reported, but the operations may malfunction
** nevertheless. Use of the destination database connection while a
** backup is in progress might also also cause a mutex deadlock.
**
** If running in [shared cache mode], the application must
** guarantee that the shared cache used by the destination database
** is not accessed while the backup is running. In practice this means
** that the application must guarantee that the disk file being
** backed up to is not accessed by any connection within the process,
** not just the specific connection that was passed to sqlite3_backup_init().
**
** The [sqlite3_backup] object itself is partially threadsafe. Multiple
** threads may safely make multiple concurrent calls to sqlite3_backup_step().
** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
** APIs are not strictly speaking threadsafe. If they are invoked at the
** same time as another thread is invoking sqlite3_backup_step() it is
** possible that they return invalid values.
label: code-design
** Register a geometry callback named zGeom that can be used as part of an
** R-Tree geometry query as follows:
**
** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
** CAPI3REF: Zero Scan-Status Counters
** METHOD: sqlite3_stmt
**
** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
**
** This API is only available if the library is built with pre-processor
** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
** CAPI3REF: Testing Interface
**
** ^The sqlite3_test_control() interface is used to read out internal
** state of SQLite and to inject faults into SQLite for testing
** purposes. ^The first parameter is an operation code that determines
** the number, meaning, and operation of all subsequent parameters.
**
** This interface is not for use by applications. It exists solely
** for verifying the correct operation of the SQLite library. Depending
** on how the SQLite library is compiled, this interface might not exist.
**
** The details of the operation codes, their meanings, the parameters
** they take, and what they do are all subject to change without notice.
** Unlike most of the SQLite API, this function is not guaranteed to
** operate consistently from one release to the next.
Database Name Table Name
Internal logic error in SQLite
Pointer to buffer containing changeset B
Additional methods may be added in future releases
First argument passed to xFilter
comment:
** CAPI3REF: Mutex Methods Object
**
** An instance of this structure defines the low-level routines
** used to allocate and use mutexes.
**
** Usually, the default mutex implementations provided by SQLite are
** sufficient, however the application has the option of substituting a custom
** implementation for specialized deployments or systems for which SQLite
** does not provide a suitable implementation. In this case, the application
** creates and populates an instance of this structure to pass
** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
** Additionally, an instance of this structure can be used as an
** output variable when querying the system for the current mutex
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
**
** ^The xMutexInit method defined by this structure is invoked as
** part of system initialization by the sqlite3_initialize() function.
** ^The xMutexInit routine is called by SQLite exactly once for each
** effective call to [sqlite3_initialize()].
**
** ^The xMutexEnd method defined by this structure is invoked as
** part of system shutdown by the sqlite3_shutdown() function. The
** implementation of this method is expected to release all outstanding
** resources obtained by the mutex methods implementation, especially
** those obtained by the xMutexInit method. ^The xMutexEnd()
** interface is invoked exactly once for each call to [sqlite3_shutdown()].
**
** ^(The remaining seven methods defined by this structure (xMutexAlloc,
** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
** xMutexNotheld) implement the following interfaces (respectively):
**
** <ul>
** <li> [sqlite3_mutex_alloc()] </li>
** <li> [sqlite3_mutex_free()] </li>
** <li> [sqlite3_mutex_enter()] </li>
** <li> [sqlite3_mutex_try()] </li>
** <li> [sqlite3_mutex_leave()] </li>
** <li> [sqlite3_mutex_held()] </li>
** <li> [sqlite3_mutex_notheld()] </li>
** </ul>)^
**
** The only difference is that the public sqlite3_XXX functions enumerated
** above silently ignore any invocations that pass a NULL pointer instead
** of a valid mutex handle. The implementations of the methods defined
** by this structure are not required to handle this case, the results
** of passing a NULL pointer instead of a valid mutex handle are undefined
** (i.e. it is acceptable to provide an implementation that segfaults if
** it is passed a NULL pointer).
**
** The xMutexInit() method must be threadsafe. It must be harmless to
** invoke xMutexInit() multiple times within the same process and without
** intervening calls to xMutexEnd(). Second and subsequent calls to
** xMutexInit() must be no-ops.
**
** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
** memory allocation for a fast or recursive mutex.
**
** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
** called, but only if the prior call to xMutexInit returned SQLITE_OK.
** If xMutexInit fails in any way, it is expected to clean up after itself
** prior to returning.
label: code-design
** CAPI3REF: Concatenate Two Changeset Objects
**
** This function is used to concatenate two changesets, A and B, into a
** single changeset. The result is a changeset equivalent to applying
** changeset A followed by changeset B.
**
** This function combines the two input changesets using an
** sqlite3_changegroup object. Calling it produces similar results as the
** following code fragment:
**
** sqlite3_changegroup *pGrp;
** rc = sqlite3_changegroup_new(&pGrp);
** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
** if( rc==SQLITE_OK ){
** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
** }else{
** *ppOut = 0;
** *pnOut = 0;
** }
**
** Refer to the sqlite3_changegroup documentation below for details.
** CAPI3REF: Checkpoint a database
** METHOD: sqlite3
**
** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
**
** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
** [write-ahead log] for database X on [database connection] D to be
** transferred into the database file and for the write-ahead log to
** be reset. See the [checkpointing] documentation for addition
** information.
**
** This interface used to be the only way to cause a checkpoint to
** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
** interface was added. This interface is retained for backwards
** compatibility and as a convenience for applications that need to manually
** start a callback but which do not need the full power (and corresponding
** complication) of [sqlite3_wal_checkpoint_v2()].
******* End of sqlite3session.h ********
** CAPI3REF: Set the Last Insert Rowid value.
** METHOD: sqlite3
**
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
** set the value returned by calling sqlite3_last_insert_rowid(D) to R
** without inserting a row into the database.
** CAPI3REF: Mutex Verification Routines
**
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
** are intended for use inside assert() statements. The SQLite core
** never uses these routines except inside an assert() and applications
** are advised to follow the lead of the core. The SQLite core only
** provides implementations for these routines when it is compiled
** with the SQLITE_DEBUG flag. External mutex implementations
** are only required to provide these routines if SQLITE_DEBUG is
** defined and if NDEBUG is not defined.
**
** These routines should return true if the mutex in their argument
** is held or not held, respectively, by the calling thread.
**
** The implementation is not required to provide versions of these
** routines that actually work. If the implementation does not provide working
** versions of these routines, it should at least provide stubs that always
** return true so that one does not get spurious assertion failures.
**
** If the argument to sqlite3_mutex_held() is a NULL pointer then
** the routine should return 1. This seems counter-intuitive since
** clearly the mutex cannot be held if it does not exist. But
** the reason the mutex does not exist is because the build is not
** using mutexes. And we do not want the assert() containing the
** call to sqlite3_mutex_held() to fail, so a non-zero return is
** the appropriate thing to do. The sqlite3_mutex_notheld()
** interface should also return 1 when given a NULL pointer.
** Make sure we can call this stuff from C++.
** CAPI3REF: Flags for the xShmLock VFS method
**
** These integer constants define the various locking operations
** allowed by the xShmLock method of [sqlite3_io_methods]. The
** following are the only legal combinations of flags to the
** xShmLock method:
**
** <ul>
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
** </ul>
**
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
** was given on the corresponding lock.
**
** The xShmLock method can transition between unlocked and SHARED or
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
** and EXCLUSIVE.
Deprecated
** CAPI3REF: String Comparison
**
** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
** and extensions to compare the contents of two buffers containing UTF-8
** strings in a case-independent fashion, using the same definition of "case
** independence" that SQLite uses internally when comparing identifiers.
Needed for the definition of va_list
OUT: Old value (or NULL pointer)
sqlite3PageMalloc()
** CAPI3REF: Enable Or Disable Extended Result Codes
** METHOD: sqlite3
**
** ^The sqlite3_extended_result_codes() routine enables or disables the
** [extended result codes] feature of SQLite. ^The extended result
** codes are disabled by default for historical compatibility.
SQLITE_UPDATE, DELETE or INSERT
comment:
** CAPI3REF: Flags for the xAccess VFS method
**
** These integer constants can be used as the third parameter to
** the xAccess method of an [sqlite3_vfs] object. They determine
** what kind of permissions the xAccess method is looking for.
** With SQLITE_ACCESS_EXISTS, the xAccess method
** simply checks whether the file exists.
** With SQLITE_ACCESS_READWRITE, the xAccess method
** checks whether the named directory is both readable and writable
** (in other words, if files can be added, removed, and renamed within
** the directory).
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
** [temp_store_directory pragma], though this could change in a future
** release of SQLite.
** With SQLITE_ACCESS_READ, the xAccess method
** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
** currently unused, though it might be used in a future release of
** SQLite.
label: code-design
** Ensure these symbols were not defined by some previous header file.
Scan visits at most 1 row
For use by built-in VFS
New rowid value (for a rowid UPDATE)
** CAPI3REF: Last Insert Rowid
** METHOD: sqlite3
**
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
** has a unique 64-bit signed
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
** names are not also used by explicitly declared columns. ^If
** the table has a column of type [INTEGER PRIMARY KEY] then that column
** is another alias for the rowid.
**
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
** the most recent successful [INSERT] into a rowid table or [virtual table]
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
** on the database connection D, then sqlite3_last_insert_rowid(D) returns
** zero.
**
** As well as being set automatically as rows are inserted into database
** tables, the value returned by this function may be set explicitly by
** [sqlite3_set_last_insert_rowid()]
**
** Some virtual table implementations may INSERT rows into rowid tables as
** part of committing a transaction (e.g. to flush data accumulated in memory
** to disk). In this case subsequent calls to this function return the rowid
** associated with these internal INSERT operations, which leads to
** unintuitive results. Virtual table implementations that do write to rowid
** tables in this way can avoid this problem by restoring the original
** rowid value using [sqlite3_set_last_insert_rowid()] before returning
** control to the user.
**
** ^(If an [INSERT] occurs within a trigger then this routine will
** return the [rowid] of the inserted row as long as the trigger is
** running. Once the trigger program ends, the value returned
** by this routine reverts to what it was before the trigger was fired.)^
**
** ^An [INSERT] that fails due to a constraint violation is not a
** successful [INSERT] and does not change the value returned by this
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
** and INSERT OR ABORT make no changes to the return value of this
** routine when their insertion fails. ^(When INSERT OR REPLACE
** encounters a constraint violation, it does not fail. The
** INSERT continues to completion after deleting rows that caused
** the constraint problem so INSERT OR REPLACE will always change
** the return value of this interface.)^
**
** ^For the purposes of this routine, an [INSERT] is considered to
** be successful even if it is subsequently rolled back.
**
** This function is accessible to SQL statements via the
** [last_insert_rowid() SQL function].
**
** If a separate thread performs a new [INSERT] on the same
** database connection while the [sqlite3_last_insert_rowid()]
** function is running and thus changes the last insert [rowid],
** then the value returned by [sqlite3_last_insert_rowid()] is
** unpredictable and might not equal either the old or the new
** last insert [rowid].
SQL to be evaluated
** CAPI3REF: Virtual Table Scan Flags
** CAPI3REF: Testing Interface Operation Codes
**
** These constants are the valid operation code parameters used
** as the first argument to [sqlite3_test_control()].
**
** These parameters and their meanings are subject to change
** without notice. These values are for testing purposes only.
** Applications should not use any of these parameters or the
** [sqlite3_test_control()] interface.
** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
**
** This function may only be called with an iterator passed to an
** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
** it sets the output variable to the total number of known foreign key
** violations in the destination database and returns SQLITE_OK.
**
** In all other cases this function returns SQLITE_MISUSE.
Some kind of disk I/O error occurred
** CAPI3REF: Obtain The Primary Key Definition Of A Table
**
** For each modified table, a changeset includes the following:
**
** <ul>
** <li> The number of columns in the table, and
** <li> Which of those columns make up the tables PRIMARY KEY.
** </ul>
**
** This function is used to find which columns comprise the PRIMARY KEY of
** the table modified by the change that iterator pIter currently points to.
** If successful, *pabPK is set to point to an array of nCol entries, where
** nCol is the number of columns in the table. Elements of *pabPK are set to
** 0x01 if the corresponding column is part of the tables primary key, or
** 0x00 if it is not.
**
** If argument pnCol is not NULL, then *pnCol is set to the number of columns
** in the table.
**
** If this function is called when the iterator does not point to a valid
** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
** SQLITE_OK is returned and the output variables populated as described
** above.
Maximum length of zSql in bytes.
Largest defined DBSTATUS
** CAPI3REF: Custom Page Cache Object
**
** The sqlite3_pcache type is opaque. It is implemented by
** the pluggable module. The SQLite core has no knowledge of
** its size or internal structure and never deals with the
** sqlite3_pcache object except by holding and passing pointers
** to the object.
**
** See [sqlite3_pcache_methods2] for additional information.
******* Begin file fts5.h ********
First arg to pass to pApi functions
comment:
** CAPI3REF: Mutexes
**
** The SQLite core uses these routines for thread
** synchronization. Though they are intended for internal
** use by SQLite, code that links against SQLite is
** permitted to use any of these routines.
**
** The SQLite source code contains multiple implementations
** of these mutex routines. An appropriate implementation
** is selected automatically at compile-time. The following
** implementations are available in the SQLite core:
**
** <ul>
** <li> SQLITE_MUTEX_PTHREADS
** <li> SQLITE_MUTEX_W32
** <li> SQLITE_MUTEX_NOOP
** </ul>
**
** The SQLITE_MUTEX_NOOP implementation is a set of routines
** that does no real locking and is appropriate for use in
** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
** and Windows.
**
** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
** implementation is included with the library. In this case the
** application must supply a custom mutex implementation using the
** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
** before calling sqlite3_initialize() or any other public sqlite3_
** function that calls sqlite3_initialize().
**
** ^The sqlite3_mutex_alloc() routine allocates a new
** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
** routine returns NULL if it is unable to allocate the requested
** mutex. The argument to sqlite3_mutex_alloc() must one of these
** integer constants:
**
** <ul>
** <li> SQLITE_MUTEX_FAST
** <li> SQLITE_MUTEX_RECURSIVE
** <li> SQLITE_MUTEX_STATIC_MASTER
** <li> SQLITE_MUTEX_STATIC_MEM
** <li> SQLITE_MUTEX_STATIC_OPEN
** <li> SQLITE_MUTEX_STATIC_PRNG
** <li> SQLITE_MUTEX_STATIC_LRU
** <li> SQLITE_MUTEX_STATIC_PMEM
** <li> SQLITE_MUTEX_STATIC_APP1
** <li> SQLITE_MUTEX_STATIC_APP2
** <li> SQLITE_MUTEX_STATIC_APP3
** <li> SQLITE_MUTEX_STATIC_VFS1
** <li> SQLITE_MUTEX_STATIC_VFS2
** <li> SQLITE_MUTEX_STATIC_VFS3
** </ul>
**
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
** cause sqlite3_mutex_alloc() to create
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
** The mutex implementation does not need to make a distinction
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
** not want to. SQLite will only request a recursive mutex in
** cases where it really needs one. If a faster non-recursive mutex
** implementation is available on the host platform, the mutex subsystem
** might return such a mutex in response to SQLITE_MUTEX_FAST.
**
** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
** a pointer to a static preexisting mutex. ^Nine static mutexes are
** used by the current version of SQLite. Future versions of SQLite
** may add additional static mutexes. Static mutexes are for internal
** use by SQLite only. Applications that use SQLite mutexes should
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
** SQLITE_MUTEX_RECURSIVE.
**
** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
** returns a different mutex on every call. ^For the static
** mutex types, the same mutex is returned on every call that has
** the same type number.
**
** ^The sqlite3_mutex_free() routine deallocates a previously
** allocated dynamic mutex. Attempting to deallocate a static
** mutex results in undefined behavior.
**
** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex. ^If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
** upon successful entry. ^(Mutexes created using
** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
** In such cases, the
** mutex must be exited an equal number of times before another thread
** can enter.)^ If the same thread tries to enter any mutex other
** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
**
** ^(Some systems (for example, Windows 95) do not support the operation
** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
** will always return SQLITE_BUSY. The SQLite core only ever uses
** sqlite3_mutex_try() as an optimization so this is acceptable
** behavior.)^
**
** ^The sqlite3_mutex_leave() routine exits a mutex that was
** previously entered by the same thread. The behavior
** is undefined if the mutex is not currently entered by the
** calling thread or is not currently allocated.
**
** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
** sqlite3_mutex_leave() is a NULL pointer, then all three routines
** behave as no-ops.
**
** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
label: code-design
Like FULL but wait for for readers
OUT: Number of FK violations
Name of the module
Flags that may be passed as the third argument to xTokenize()
SQLite connection to register module with
void* int int
The following fields are only available in 3.8.11 and later
** CAPI3REF: Interrupt A Long-Running Query
** METHOD: sqlite3
**
** ^This function causes any pending database operation to abort and
** return at its earliest opportunity. This routine is typically
** called in response to a user action such as pressing "Cancel"
** or Ctrl-C where the user wants a long query operation to halt
** immediately.
**
** ^It is safe to call this routine from a thread different from the
** thread that is currently running the database operation. But it
** is not safe to call this routine with a [database connection] that
** is closed or might close before sqlite3_interrupt() returns.
**
** ^If an SQL operation is very nearly finished at the time when
** sqlite3_interrupt() is called, then it might not have an opportunity
** to be interrupted and might continue to completion.
**
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
** that is inside an explicit transaction, then the entire transaction
** will be rolled back automatically.
**
** ^The sqlite3_interrupt(D) call is in effect until all currently running
** SQL statements on [database connection] D complete. ^Any new SQL statements
** that are started after the sqlite3_interrupt() call and before the
** running statements reaches zero are interrupted as if they had been
** running prior to the sqlite3_interrupt() call. ^New SQL statements
** that are started after the running statement count reaches zero are
** not effected by the sqlite3_interrupt().
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
** SQL statements is a no-op and has no effect on SQL statements
** that are started after the sqlite3_interrupt() call returns.
comment: NOT USED
label: code-design
comment:
** CAPI3REF: Advance A Changeset Iterator
**
** This function may only be used with iterators created by function
** [sqlite3changeset_start()]. If it is called on an iterator passed to
** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
** is returned and the call has no effect.
**
** Immediately after an iterator is created by sqlite3changeset_start(), it
** does not point to any change in the changeset. Assuming the changeset
** is not empty, the first call to this function advances the iterator to
** point to the first change in the changeset. Each subsequent call advances
** the iterator to point to the next change in the changeset (if any). If
** no error occurs and the iterator points to a valid change after a call
** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
** Otherwise, if all changes in the changeset have already been visited,
** SQLITE_DONE is returned.
**
** If an error occurs, an SQLite error code is returned. Possible error
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
** SQLITE_NOMEM.
label: code-design
** CAPI3REF: Compile-Time Authorization Callbacks
** METHOD: sqlite3
** KEYWORDS: {authorizer callback}
**
** ^This routine registers an authorizer callback with a particular
** [database connection], supplied in the first argument.
** ^The authorizer callback is invoked as SQL statements are being compiled
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
** and [sqlite3_prepare16_v3()]. ^At various
** points during the compilation process, as logic is being created
** to perform various actions, the authorizer callback is invoked to
** see if those actions are allowed. ^The authorizer callback should
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
** specific action but allow the SQL statement to continue to be
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
** rejected with an error. ^If the authorizer callback returns
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
** the authorizer will fail with an error message.
**
** When the callback returns [SQLITE_OK], that means the operation
** requested is ok. ^When the callback returns [SQLITE_DENY], the
** [sqlite3_prepare_v2()] or equivalent call that triggered the
** authorizer will fail with an error message explaining that
** access is denied.
**
** ^The first parameter to the authorizer callback is a copy of the third
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
** to the callback is an integer [SQLITE_COPY | action code] that specifies
** the particular action to be authorized. ^The third through sixth parameters
** to the callback are either NULL pointers or zero-terminated strings
** that contain additional details about the action to be authorized.
** Applications must always be prepared to encounter a NULL pointer in any
** of the third through the sixth parameters of the authorization callback.
**
** ^If the action code is [SQLITE_READ]
** and the callback returns [SQLITE_IGNORE] then the
** [prepared statement] statement is constructed to substitute
** a NULL value in place of the table column that would have
** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
** return can be used to deny an untrusted user access to individual
** columns of a table.
** ^When a table is referenced by a [SELECT] but no column values are
** extracted from that table (for example in a query like
** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
** is invoked once for that table with a column name that is an empty string.
** ^If the action code is [SQLITE_DELETE] and the callback returns
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
** [truncate optimization] is disabled and all rows are deleted individually.
**
** An authorizer is used when [sqlite3_prepare | preparing]
** SQL statements from an untrusted source, to ensure that the SQL statements
** do not try to access data they are not allowed to see, or that they do not
** try to execute malicious statements that damage the database. For
** example, an application may allow a user to enter arbitrary
** SQL queries for evaluation by a database. But the application does
** not want the user to be able to make arbitrary changes to the
** database. An authorizer could then be put in place while the
** user-entered SQL is being [sqlite3_prepare | prepared] that
** disallows everything except [SELECT] statements.
**
** Applications that need to process SQL from untrusted sources
** might also consider lowering resource limits using [sqlite3_limit()]
** and limiting database size using the [max_page_count] [PRAGMA]
** in addition to using an authorizer.
**
** ^(Only a single authorizer can be in place on a database connection
** at a time. Each call to sqlite3_set_authorizer overrides the
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
** The authorizer is disabled by default.
**
** The authorizer callback must not do anything that will modify
** the database connection that invoked the authorizer callback.
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
** database connections for the meaning of "modify" in this paragraph.
**
** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
** statement might be re-prepared during [sqlite3_step()] due to a
** schema change. Hence, the application should ensure that the
** correct authorizer callback remains in place during the [sqlite3_step()].
**
** ^Note that the authorizer callback is invoked only during
** [sqlite3_prepare()] or its variants. Authorization is not
** performed during statement evaluation in [sqlite3_step()], unless
** as stated in the previous paragraph, sqlite3_step() invokes
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
Argument to pass to xNotify
comment:
** CAPI3REF: Destroy a snapshot
** EXPERIMENTAL
**
** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
** The application must eventually free every [sqlite3_snapshot] object
** using this routine to avoid a memory leak.
**
** The [sqlite3_snapshot_free()] interface is only available when the
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
label: code-design
NULL NULL
Authorization denied
OUT: Statement handle
** CAPI3REF: Create A New Session Object
**
** Create a new session object attached to database handle db. If successful,
** a pointer to the new object is written to *ppSession and SQLITE_OK is
** returned. If an error occurs, *ppSession is set to NULL and an SQLite
** error code (e.g. SQLITE_NOMEM) is returned.
**
** It is possible to create multiple session objects attached to a single
** database handle.
**
** Session objects created using this function should be deleted using the
** [sqlite3session_delete()] function before the database handle that they
** are attached to is itself closed. If the database handle is closed before
** the session object is deleted, then the results of calling any session
** module function, including [sqlite3session_delete()] on the session object
** are undefined.
**
** Because the session module uses the [sqlite3_preupdate_hook()] API, it
** is not possible for an application to register a pre-update hook on a
** database handle that has one or more session objects attached. Nor is
** it possible to create a session object attached to a database handle for
** which a pre-update hook is already defined. The results of attempting
** either of these things are undefined.
**
** The session object will be used to create changesets for tables in
** database zDb, where zDb is either "main", or "temp", or the name of an
** attached database. It is not an error if database zDb is not attached
** to the database when the session object is created.
** CAPI3REF: Deprecated Soft Heap Limit Interface
** DEPRECATED
**
** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
** interface. This routine is provided for historical compatibility
** only. All new applications should use the
** [sqlite3_soft_heap_limit64()] interface rather than this one.
Context passed to xToken()
Deinitialize the memory allocator
** CAPI3REF: Close A BLOB Handle
** DESTRUCTOR: sqlite3_blob
**
** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
** unconditionally. Even if this routine returns an error code, the
** handle is still closed.)^
**
** ^If the blob handle being closed was opened for read-write access, and if
** the database is in auto-commit mode and there are no other open read-write
** blob handles or active write statements, the current transaction is
** committed. ^If an error occurs while committing the transaction, an error
** code is returned and the transaction rolled back.
**
** Calling this function with an argument that is not a NULL pointer or an
** open blob handle results in undefined behaviour. ^Calling this routine
** with a null pointer (such as would be returned by a failed call to
** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
** is passed a valid open blob handle, the values returned by the
** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
** CAPI3REF: Write-Ahead Log Commit Hook
** METHOD: sqlite3
**
** ^The [sqlite3_wal_hook()] function is used to register a callback that
** is invoked each time data is committed to a database in wal mode.
**
** ^(The callback is invoked by SQLite after the commit has taken place and
** the associated write-lock on the database released)^, so the implementation
** may read, write or [checkpoint] the database as required.
**
** ^The first parameter passed to the callback function when it is invoked
** is a copy of the third parameter passed to sqlite3_wal_hook() when
** registering the callback. ^The second is a copy of the database handle.
** ^The third parameter is the name of the database that was written to -
** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
** is the number of pages currently in the write-ahead log file,
** including those that were just committed.
**
** The callback function should normally return [SQLITE_OK]. ^If an error
** code is returned, that error will propagate back up through the
** SQLite code base to cause the statement that provoked the callback
** to report an error, though the commit will have still occurred. If the
** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
** that does not correspond to any valid SQLite error code, the results
** are undefined.
**
** A single database handle may have at most a single write-ahead log callback
** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
** previously registered write-ahead log callback. ^Note that the
** [sqlite3_wal_autocheckpoint()] interface and the
** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
** overwrite any prior [sqlite3_wal_hook()] settings.
comment:
** CAPI3REF: Suspend Execution For A Short Time
**
** The sqlite3_sleep() function causes the current thread to suspend execution
** for at least a number of milliseconds specified in its parameter.
**
** If the operating system does not support sleep requests with
** millisecond time resolution, then the time will be rounded up to
** the nearest second. The number of milliseconds of sleep actually
** requested from the operating system is returned.
**
** ^SQLite implements this interface by calling the xSleep()
** method of the default [sqlite3_vfs] object. If the xSleep() method
** of the default VFS is not implemented correctly, or not implemented at
** all, then the behavior of sqlite3_sleep() may deviate from the description
** in the previous paragraphs.
label: code-design
comment:
** CAPI3REF: Attempt To Free Heap Memory
**
** ^The sqlite3_release_memory() interface attempts to free N bytes
** of heap memory by deallocating non-essential memory allocations
** held by the database library. Memory used to cache database
** pages to improve performance is an example of non-essential memory.
** ^sqlite3_release_memory() returns the number of bytes actually freed,
** which might be more or less than the amount requested.
** ^The sqlite3_release_memory() routine is a no-op returning zero
** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
**
** See also: [sqlite3_db_release_memory()]
label: code-design
comment:
** CAPI3REF: OS Interface File Virtual Methods Object
**
** Every file opened by the [sqlite3_vfs.xOpen] method populates an
** [sqlite3_file] object (or, more commonly, a subclass of the
** [sqlite3_file] object) with a pointer to an instance of this object.
** This object defines the methods used to perform various operations
** against the open file represented by the [sqlite3_file] object.
**
** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
** to NULL.
**
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
** flag may be ORed in to indicate that only the data of the file
** and not its inode needs to be synced.
**
** The integer values to xLock() and xUnlock() are one of
** <ul>
** <li> [SQLITE_LOCK_NONE],
** <li> [SQLITE_LOCK_SHARED],
** <li> [SQLITE_LOCK_RESERVED],
** <li> [SQLITE_LOCK_PENDING], or
** <li> [SQLITE_LOCK_EXCLUSIVE].
** </ul>
** xLock() increases the lock. xUnlock() decreases the lock.
** The xCheckReservedLock() method checks whether any database connection,
** either in this process or in some other process, is holding a RESERVED,
** PENDING, or EXCLUSIVE lock on the file. It returns true
** if such a lock exists and false otherwise.
**
** The xFileControl() method is a generic interface that allows custom
** VFS implementations to directly control an open file using the
** [sqlite3_file_control()] interface. The second "op" argument is an
** integer opcode. The third argument is a generic pointer intended to
** point to a structure that may contain arguments or space in which to
** write return values. Potential uses for xFileControl() might be
** functions to enable blocking locks with timeouts, to change the
** locking strategy (for example to use dot-file locks), to inquire
** about the status of a lock, or to break stale locks. The SQLite
** core reserves all opcodes less than 100 for its own use.
** A [file control opcodes | list of opcodes] less than 100 is available.
** Applications that define a custom xFileControl method should use opcodes
** greater than 100 to avoid conflicts. VFS implementations should
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
** recognize.
**
** The xSectorSize() method returns the sector size of the
** device that underlies the file. The sector size is the
** minimum write that can be performed without disturbing
** other bytes in the file. The xDeviceCharacteristics()
** method returns a bit vector describing behaviors of the
** underlying device:
**
** <ul>
** <li> [SQLITE_IOCAP_ATOMIC]
** <li> [SQLITE_IOCAP_ATOMIC512]
** <li> [SQLITE_IOCAP_ATOMIC1K]
** <li> [SQLITE_IOCAP_ATOMIC2K]
** <li> [SQLITE_IOCAP_ATOMIC4K]
** <li> [SQLITE_IOCAP_ATOMIC8K]
** <li> [SQLITE_IOCAP_ATOMIC16K]
** <li> [SQLITE_IOCAP_ATOMIC32K]
** <li> [SQLITE_IOCAP_ATOMIC64K]
** <li> [SQLITE_IOCAP_SAFE_APPEND]
** <li> [SQLITE_IOCAP_SEQUENTIAL]
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
** <li> [SQLITE_IOCAP_IMMUTABLE]
** </ul>
**
** The SQLITE_IOCAP_ATOMIC property means that all writes of
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
** mean that writes of blocks that are nnn bytes in size and
** are aligned to an address which is an integer multiple of
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
** that when data is appended to a file, the data is appended
** first then the size of the file is extended, never the other
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
** information is written to disk in the same order as calls
** to xWrite().
**
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
** in the unread portions of the buffer with zeros. A VFS that
** fails to zero-fill short reads might seem to work. However,
** failure to zero-fill short reads will eventually lead to
** database corruption.
label: code-design
Free a prior allocation
** CAPI3REF: Enable Or Disable A Session Object
**
** Enable or disable the recording of changes by a session object. When
** enabled, a session object records changes made to the database. When
** disabled - it does not. A newly created session object is enabled.
** Refer to the documentation for [sqlite3session_changeset()] for further
** details regarding how enabling and disabling a session object affects
** the eventual changesets.
**
** Passing zero to this function disables the session. Passing a value
** greater than zero enables it. Passing a value less than zero is a
** no-op, and may be used to query the current state of the session.
**
** The return value indicates the final state of the session object: 0 if
** the session is disabled, or 1 if it is enabled.
Find an existing tokenizer
** CAPI3REF: Set Or Clear the Indirect Change Flag
**
** Each change recorded by a session object is marked as either direct or
** indirect. A change is marked as indirect if either:
**
** <ul>
** <li> The session object "indirect" flag is set when the change is
** made, or
** <li> The change is made by an SQL trigger or foreign key action
** instead of directly as a result of a users SQL statement.
** </ul>
**
** If a single row is affected by more than one operation within a session,
** then the change is considered indirect if all operations meet the criteria
** for an indirect change above, or direct otherwise.
**
** This function is used to set, clear or query the session object indirect
** flag. If the second argument passed to this function is zero, then the
** indirect flag is cleared. If it is greater than zero, the indirect flag
** is set. Passing a value less than zero does not modify the current value
** of the indirect flag, and may be used to query the current state of the
** indirect flag for the specified session object.
**
** The return value indicates the final state of the indirect flag: 0 if
** it is clear, or 1 if it is set.
OUT: Number of bytes in output changeset
comment:
** CAPI3REF: Test To See If The Library Is Threadsafe
**
** ^The sqlite3_threadsafe() function returns zero if and only if
** SQLite was compiled with mutexing code omitted due to the
** [SQLITE_THREADSAFE] compile-time option being set to 0.
**
** SQLite can be compiled with or without mutexes. When
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
** are enabled and SQLite is threadsafe. When the
** [SQLITE_THREADSAFE] macro is 0,
** the mutexes are omitted. Without the mutexes, it is not safe
** to use SQLite concurrently from more than one thread.
**
** Enabling mutexes incurs a measurable performance penalty.
** So if speed is of utmost importance, it makes sense to disable
** the mutexes. But for maximum safety, mutexes should be enabled.
** ^The default behavior is for mutexes to be enabled.
**
** This interface can be used by an application to make sure that the
** version of SQLite that it is linking against was compiled with
** the desired setting of the [SQLITE_THREADSAFE] macro.
**
** This interface only reports on the compile-time mutex setting
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
** can be fully or partially disabled using a call to [sqlite3_config()]
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
** sqlite3_threadsafe() function shows only the compile-time setting of
** thread safety, not any run-time changes to that setting made by
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
** is unchanged by calls to sqlite3_config().)^
**
** See the [threading mode] documentation for additional information.
label: requirement
Don't allow access, but don't generate an error
** CAPI3REF: Compile-Time Library Version Numbers
**
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
** evaluates to a string literal that is the SQLite version in the
** format "X.Y.Z" where X is the major version number (always 3 for
** SQLite3) and Y is the minor version number and Z is the release number.)^
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
** numbers used in [SQLITE_VERSION].)^
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
** be larger than the release from which it is derived. Either Y will
** be held constant and Z will be incremented or else Y will be incremented
** and Z will be reset to zero.
**
** Since [version 3.6.18] ([dateof:3.6.18]),
** SQLite source code has been stored in the
** <a href="http://www.fossil-scm.org/">Fossil configuration management
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
** a string which identifies a particular check-in of SQLite
** within its configuration management system. ^The SQLITE_SOURCE_ID
** string contains the date and time of the check-in (UTC) and a SHA1
** or SHA3-256 hash of the entire source tree.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
******* Begin file sqlite3session.h ********
Methods above are valid for version 3
sqlite3_step() has finished executing
True if output is already ordered
Round up request size to allocation size
comment:
** CAPI3REF: Obtain new.* Values From A Changeset Iterator
**
** The pIter argument passed to this function may either be an iterator
** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
** created by [sqlite3changeset_start()]. In the latter case, the most recent
** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
** Furthermore, it may only be called if the type of change that the iterator
** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
**
** Argument iVal must be greater than or equal to 0, and less than the number
** of columns in the table affected by the current change. Otherwise,
** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
**
** If successful, this function sets *ppValue to point to a protected
** sqlite3_value object containing the iVal'th value from the vector of
** new row values stored as part of the UPDATE or INSERT change and
** returns SQLITE_OK. If the change is an UPDATE and does not include
** a new value for the requested column, *ppValue is set to NULL and
** SQLITE_OK returned. The name of the function comes from the fact that
** this is similar to the "new.*" columns available to update or delete
** triggers.
**
** If some other error occurs (e.g. an OOM condition), an SQLite error code
** is returned and *ppValue is set to NULL.
label: code-design
Size of changeset blob in bytes
Reserved: 0x00F00000
comment:
** CAPI3REF: Open A BLOB For Incremental I/O
** METHOD: sqlite3
** CONSTRUCTOR: sqlite3_blob
**
** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
** in row iRow, column zColumn, table zTable in database zDb;
** in other words, the same BLOB that would be selected by:
**
** <pre>
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
** </pre>)^
**
** ^(Parameter zDb is not the filename that contains the database, but
** rather the symbolic name of the database. For attached databases, this is
** the name that appears after the AS keyword in the [ATTACH] statement.
** For the main database file, the database name is "main". For TEMP
** tables, the database name is "temp".)^
**
** ^If the flags parameter is non-zero, then the BLOB is opened for read
** and write access. ^If the flags parameter is zero, the BLOB is opened for
** read-only access.
**
** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
** in *ppBlob. Otherwise an [error code] is returned and, unless the error
** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
** the API is not misused, it is always safe to call [sqlite3_blob_close()]
** on *ppBlob after this function it returns.
**
** This function fails with SQLITE_ERROR if any of the following are true:
** <ul>
** <li> ^(Database zDb does not exist)^,
** <li> ^(Table zTable does not exist within database zDb)^,
** <li> ^(Table zTable is a WITHOUT ROWID table)^,
** <li> ^(Column zColumn does not exist)^,
** <li> ^(Row iRow is not present in the table)^,
** <li> ^(The specified column of row iRow contains a value that is not
** a TEXT or BLOB value)^,
** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
** constraint and the blob is being opened for read/write access)^,
** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
** column zColumn is part of a [child key] definition and the blob is
** being opened for read/write access)^.
** </ul>
**
** ^Unless it returns SQLITE_MISUSE, this function sets the
** [database connection] error code and message accessible via
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
**
** A BLOB referenced by sqlite3_blob_open() may be read using the
** [sqlite3_blob_read()] interface and modified by using
** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
** different row of the same table using the [sqlite3_blob_reopen()]
** interface. However, the column, table, or database of a [BLOB handle]
** cannot be changed after the [BLOB handle] is opened.
**
** ^(If the row that a BLOB handle points to is modified by an
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
** then the BLOB handle is marked as "expired".
** This is true if any column of the row is changed, even a column
** other than the one the BLOB handle is open on.)^
** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
** ^(Changes written into a BLOB prior to the BLOB expiring are not
** rolled back by the expiration of the BLOB. Such changes will eventually
** commit if the transaction continues to completion.)^
**
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
** the opened blob. ^The size of a blob may not be changed by this
** interface. Use the [UPDATE] SQL command to change the size of a
** blob.
**
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
** and the built-in [zeroblob] SQL function may be used to create a
** zero-filled blob to read or write using the incremental-blob interface.
**
** To avoid a resource leak, every open [BLOB handle] should eventually
** be released by a call to [sqlite3_blob_close()].
**
** See also: [sqlite3_blob_close()],
** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
label: code-design
Input: Mask of columns used by statement
** CAPI3REF: Number of columns in a result set
** METHOD: sqlite3_stmt
**
** ^The sqlite3_data_count(P) interface returns the number of columns in the
** current row of the result set of [prepared statement] P.
** ^If prepared statement P does not have results ready to return
** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
** interfaces) then sqlite3_data_count(P) returns 0.
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
** will return non-zero if previous call to [sqlite3_step](P) returned
** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
** where it always returns zero since each step of that multi-step
** pragma returns 0 columns of data.
**
** See also: [sqlite3_column_count()]
Handle describing change and conflict
comment:
** CAPI3REF: Define New Collating Sequences
** METHOD: sqlite3
**
** ^These functions add, remove, or modify a [collation] associated
** with the [database connection] specified as the first argument.
**
** ^The name of the collation is a UTF-8 string
** for sqlite3_create_collation() and sqlite3_create_collation_v2()
** and a UTF-16 string in native byte order for sqlite3_create_collation16().
** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
** considered to be the same name.
**
** ^(The third argument (eTextRep) must be one of the constants:
** <ul>
** <li> [SQLITE_UTF8],
** <li> [SQLITE_UTF16LE],
** <li> [SQLITE_UTF16BE],
** <li> [SQLITE_UTF16], or
** <li> [SQLITE_UTF16_ALIGNED].
** </ul>)^
** ^The eTextRep argument determines the encoding of strings passed
** to the collating function callback, xCallback.
** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
** force strings to be UTF16 with native byte order.
** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
** on an even byte address.
**
** ^The fourth argument, pArg, is an application data pointer that is passed
** through as the first argument to the collating function callback.
**
** ^The fifth argument, xCallback, is a pointer to the collating function.
** ^Multiple collating functions can be registered using the same name but
** with different eTextRep parameters and SQLite will use whichever
** function requires the least amount of data transformation.
** ^If the xCallback argument is NULL then the collating function is
** deleted. ^When all collating functions having the same name are deleted,
** that collation is no longer usable.
**
** ^The collating function callback is invoked with a copy of the pArg
** application data pointer and with two strings in the encoding specified
** by the eTextRep argument. The collating function must return an
** integer that is negative, zero, or positive
** if the first string is less than, equal to, or greater than the second,
** respectively. A collating function must always return the same answer
** given the same inputs. If two or more collating functions are registered
** to the same collation name (using different eTextRep values) then all
** must give an equivalent answer when invoked with equivalent strings.
** The collating function must obey the following properties for all
** strings A, B, and C:
**
** <ol>
** <li> If A==B then B==A.
** <li> If A==B and B==C then A==C.
** <li> If A<B THEN B>A.
** <li> If A<B and B<C then A<C.
** </ol>
**
** If a collating function fails any of the above constraints and that
** collating function is registered and used, then the behavior of SQLite
** is undefined.
**
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
** with the addition that the xDestroy callback is invoked on pArg when
** the collating function is deleted.
** ^Collating functions are deleted when they are overridden by later
** calls to the collation creation functions or when the
** [database connection] is closed using [sqlite3_close()].
**
** ^The xDestroy callback is <u>not</u> called if the
** sqlite3_create_collation_v2() function fails. Applications that invoke
** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
** check the return code and dispose of the application data pointer
** themselves rather than expecting SQLite to deal with it for them.
** This is different from every other SQLite interface. The inconsistency
** is unfortunate but cannot be changed without breaking backwards
** compatibility.
**
** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
label: code-design
** CAPI3REF: Determine The Virtual Table Conflict Policy
**
** This function may only be called from within a call to the [xUpdate] method
** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
** of the SQL statement that triggered the call to the [xUpdate] method of the
** [virtual table].
_FTS5_H
** CUSTOM AUXILIARY FUNCTIONS
************************************************************************
Table name
int int*
** CAPI3REF: Obtain Values For URI Parameters
**
** These are utility routines, useful to VFS implementations, that check
** to see if a database file was a URI that contained a specific query
** parameter, and if so obtains the value of that query parameter.
**
** If F is the database filename pointer passed into the xOpen() method of
** a VFS implementation when the flags parameter to xOpen() has one or
** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
** P is the name of the query parameter, then
** sqlite3_uri_parameter(F,P) returns the value of the P
** parameter if it exists or a NULL pointer if P does not appear as a
** query parameter on F. If P is a query parameter of F
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
** a pointer to an empty string.
**
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
** parameter and returns true (1) or false (0) according to the value
** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
** value of query parameter P is one of "yes", "true", or "on" in any
** case or if the value begins with a non-zero number. The
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
** query parameter P is one of "no", "false", or "off" in any case or
** if the value begins with a numeric zero. If P is not a query
** parameter on F or if the value of P is does not match any of the
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
**
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
** 64-bit signed integer and returns that integer, or D if P does not
** exist. If the value of P is something other than an integer, then
** zero is returned.
**
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
** is not a database file pathname pointer that SQLite passed into the xOpen
** VFS method, then the behavior of this routine is undefined and probably
** undesirable.
True for DESC. False for ASC.
Coordinates of node or entry to check
Structure version number (currently 3)
Table of WHERE clause constraints
** CAPI3REF: Changeset Iterator Handle
Successful result
Prepared statement for which info desired
Next registered VFS
DATA, MISSING, CONFLICT, CONSTRAINT
For use by application
Result written here
** CAPI3REF: Generate A Patchset From A Session Object
**
** The differences between a patchset and a changeset are that:
**
** <ul>
** <li> DELETE records consist of the primary key fields only. The
** original values of other fields are omitted.
** <li> The original values of any modified fields are omitted from
** UPDATE records.
** </ul>
**
** A patchset blob may be used with up to date versions of all
** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
** attempting to use a patchset blob with old versions of the
** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
**
** Because the non-primary key "old.*" fields are omitted, no
** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
** is passed to the sqlite3changeset_apply() API. Other conflict types work
** in the same way as for changesets.
**
** Changes within a patchset are ordered in the same way as for changesets
** generated by the sqlite3session_changeset() function (i.e. all changes for
** a single table are grouped together, tables appear in the order in which
** they were attached to the session object).
Destination database handle
comment:
** CAPI3REF: Obtain Aggregate Function Context
** METHOD: sqlite3_context
**
** Implementations of aggregate SQL functions use this
** routine to allocate memory for storing their state.
**
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
** for a particular aggregate function, SQLite
** allocates N of memory, zeroes out that memory, and returns a pointer
** to the new memory. ^On second and subsequent calls to
** sqlite3_aggregate_context() for the same aggregate function instance,
** the same buffer is returned. Sqlite3_aggregate_context() is normally
** called once for each invocation of the xStep callback and then one
** last time when the xFinal callback is invoked. ^(When no rows match
** an aggregate query, the xStep() callback of the aggregate function
** implementation is never called and xFinal() is called exactly once.
** In those cases, sqlite3_aggregate_context() might be called for the
** first time from within xFinal().)^
**
** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
** when first called if N is less than or equal to zero or if a memory
** allocate error occurs.
**
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
** determined by the N parameter on first successful call. Changing the
** value of N in subsequent call to sqlite3_aggregate_context() within
** the same aggregate function instance will not resize the memory
** allocation.)^ Within the xFinal callback, it is customary to set
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
** pointless memory allocations occur.
**
** ^SQLite automatically frees the memory allocated by
** sqlite3_aggregate_context() when the aggregate query concludes.
**
** The first parameter must be a copy of the
** [sqlite3_context | SQL function context] that is the first parameter
** to the xStep or xFinal callback routine that implements the aggregate
** function.
**
** This routine must be called from the same thread in which
** the aggregate SQL function is running.
label: code-design
** END OF CUSTOM TOKENIZERS
************************************************************************
Error msg written here
** CAPI3REF: Return The Size Of An Open BLOB
** METHOD: sqlite3_blob
**
** ^Returns the size in bytes of the BLOB accessible via the
** successfully opened [BLOB handle] in its only argument. ^The
** incremental blob I/O routines can only read or overwriting existing
** blob content; they cannot change the size of a blob.
**
** This routine only works on a [BLOB handle] which has been created
** by a prior successful call to [sqlite3_blob_open()] and which has not
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
** to this routine results in undefined and probably undesirable behavior.
Insertion failed because database is full
The key
** CAPI3REF: Find The Database Handle Of A Prepared Statement
** METHOD: sqlite3_stmt
**
** ^The sqlite3_db_handle interface returns the [database connection] handle
** to which a [prepared statement] belongs. ^The [database connection]
** returned by sqlite3_db_handle is the same [database connection]
** that was the first argument
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
** create the statement in the first place.
xSqllog, void*
** CAPI3REF: Reset All Bindings On A Prepared Statement
** METHOD: sqlite3_stmt
**
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
** ^Use this routine to reset all host parameters to NULL.
Methods above are valid for version 1
comment:
** CAPI3REF: Column Names In A Result Set
** METHOD: sqlite3_stmt
**
** ^These routines return the name assigned to a particular column
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
** interface returns a pointer to a zero-terminated UTF-8 string
** and sqlite3_column_name16() returns a pointer to a zero-terminated
** UTF-16 string. ^The first parameter is the [prepared statement]
** that implements the [SELECT] statement. ^The second parameter is the
** column number. ^The leftmost column is number 0.
**
** ^The returned string pointer is valid until either the [prepared statement]
** is destroyed by [sqlite3_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite3_step()] for a particular run
** or until the next call to
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
**
** ^If sqlite3_malloc() fails during the processing of either routine
** (for example during a conversion from UTF-8 to UTF-16) then a
** NULL pointer is returned.
**
** ^The name of a result column is the value of the "AS" clause for
** that column, if there is an AS clause. If there is no AS clause
** then the name of the column is unspecified and may change from
** one release of SQLite to the next.
label: code-design
Parameters passed to SQL geom function
Mask of FTS5_TOKEN_* flags
** CAPI3REF: Enable Or Disable Extension Loading
** METHOD: sqlite3
**
** ^So as not to open security holes in older applications that are
** unprepared to deal with [extension loading], and as a means of disabling
** [extension loading] while evaluating user-entered SQL, the following API
** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
**
** ^Extension loading is off by default.
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
** to turn extension loading on and call it with onoff==0 to turn
** it back off again.
**
** ^This interface enables or disables both the C-API
** [sqlite3_load_extension()] and the SQL function [load_extension()].
** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
** to enable or disable only the C-API.)^
**
** <b>Security warning:</b> It is recommended that extension loading
** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
** rather than this interface, so the [load_extension()] SQL function
** remains disabled. This will prevent SQL injections from giving attackers
** access to extension loading capabilities.
** CAPI3REF: Impose A Limit On Heap Size
**
** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
** soft limit on the amount of heap memory that may be allocated by SQLite.
** ^SQLite strives to keep heap memory utilization below the soft heap
** limit by reducing the number of pages held in the page cache
** as heap memory usages approaches the limit.
** ^The soft heap limit is "soft" because even though SQLite strives to stay
** below the limit, it will exceed the limit rather than generate
** an [SQLITE_NOMEM] error. In other words, the soft heap limit
** is advisory only.
**
** ^The return value from sqlite3_soft_heap_limit64() is the size of
** the soft heap limit prior to the call, or negative in the case of an
** error. ^If the argument N is negative
** then no change is made to the soft heap limit. Hence, the current
** size of the soft heap limit can be determined by invoking
** sqlite3_soft_heap_limit64() with a negative argument.
**
** ^If the argument N is zero then the soft heap limit is disabled.
**
** ^(The soft heap limit is not enforced in the current implementation
** if one or more of following conditions are true:
**
** <ul>
** <li> The soft heap limit is set to zero.
** <li> Memory accounting is disabled using a combination of the
** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
** <li> An alternative page cache implementation is specified using
** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
** <li> The page cache allocates from its own memory pool supplied
** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
** from the heap.
** </ul>)^
**
** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]),
** the soft heap limit is enforced
** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
** the soft heap limit is enforced on every memory allocation. Without
** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
** when memory is allocated by the page cache. Testing suggests that because
** the page cache is the predominate memory user in SQLite, most
** applications will achieve adequate soft heap limit enforcement without
** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
**
** The circumstances under which SQLite will enforce the soft heap limit may
** changes in future releases of SQLite.
comment: TODO: Do we really need to unlock the mutex, before
* destroying it, if it's destroyed by the thread currently
* owning the mutex?
label: code-design
HCP24: moving all timers > next_time
HCP24: if is_relative = 0 and next_time < now
* action will be called so fast as possible
* if additional period > 0
* action will be called so fast as possible
* n times until (next_time + (n * period)) > now
* then the period is working
* Solution:
* if next_time < now then we set next_time = now.
* The first callback will be so fast as possible (now)
* but the next callback on period
Timer thread
_WIN32
Current size of timer list
Timer thread ID
Protects timer lists
List of timers
GetTickCount returns milliseconds since system start as
* unsigned 32 bit value. It will wrap around every 49.7 days.
* We need to use a 64 bit counter (will wrap in 500 mio. years),
* by adding the 32 bit difference since the last call to a
* 64 bit counter. This algorithm will only work, if this
* function is called at least once every 7 weeks.
Start timer thread
You can not set timers into the past
This file is part of the CivetWeb web server.
* See https://github.com/civetweb/civetweb/
* (C) 2014-2017 by the CivetWeb authors, MIT license.
Insert new timer into a sorted list.
comment: The linear list is still most efficient for short lists (small
* number of timers) - if there are many timers, different
* algorithms will work better.
label: code-design
10 ms seems reasonable.
* A faster loop (smaller sleep value) increases CPU load,
* a slower loop (higher sleep value) decreases timer accuracy.
End of timer.inl
Test case description:
This test contains 100 small images in a table.
Once a browser opens the html file, it will request
all these images from the server very quickly.
Depending on the "keep-alive" settings, it will
either open/close 100 connections quite rapidly
if keep-alive=no, or otherwise establish only a few
connections, typically one or two, and reuse them.
If the test succeeds, all 100 images are displayed.
The loading time is measured automatically in the
browser using JavaScript. Note that the load times
also differs between HTTP and HTTPS.
http://www.restpatterns.org/HTTP_Methods
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
!/bin/sh
,bM=/\?/,bN=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cv(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cu("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cu("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b]&&g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:cu("show",1),slideUp:cu("hide",1),slideToggle:cu("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=cr||cs(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){e.options.hide&&f._data(e.elem,"fxshow"+e.prop)===b&&f._data(e.elem,"fxshow"+e.prop,e.start)},h()&&f.timers.push(h)&&!cp&&(cp=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=cr||cs(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cp),cp=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(["width","height"],function(a,b){f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now)+a.unit)}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cw=/^t(?:able|d|h)$/i,cx=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cy(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.support.fixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cw.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.support.fixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window);
! jQuery v1.7.1 jquery.com | jquery.org/license
function mbox() {
alert('Javascript OK');
}
var totalCount = 10;
var pendingCount = 0;
var errorCount = 0;
var pushCount = 0;
var allErrorCount = 0;
var autoTest = false;
var testType = "cgi";
function NextTestType() {
if (testType == "cgi") testType = "lp";
else if (testType == "lp") testType = "lua";
else testType = "cgi";
}
function runTest(method, isAsync) {
++pushCount;
document.getElementById('start').innerHTML = 'Test: ' + pushCount;
document.getElementById('resTotal').innerHTML = 'running';
for (var i = 1; i <= totalCount; ++i) {
document.getElementById('res'+i).innerHTML = "ready";
}
errorCount = 0;
pendingCount = totalCount;
for (var i = 1; i <= totalCount; ++i) {
fetch(i, method, isAsync);
}
}
function runAutoTest() {
if (autoTest) {
runTest("POST", true)
setTimeout("runAutoTest()", 250)
}
}
function fetch(id, method, isAsync) {
document.getElementById('res'+id).innerHTML = "pending";
$.ajax({
async: isAsync,
url: 'echo.' + testType + '?id=' + id,
type: method,
timeout: 2000,
data: { 'id' : id ,
'longText1' : "adfsdfasdklkjlgasfdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText2' : "bsdfsdfasdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText3' : "sdfsadagsdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText4' : "q34sdfas3fhbkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText5' : "askj2kjcvxychklgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText6' : "asdfjklhlkjhv8öajsdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'async' : isAsync
},
dataType: 'json',
succes: function(data) {
},
error: function() {
++errorCount;
},
complete: function(jqXHR, textStatus) {
--pendingCount;
document.getElementById('res'+id).innerHTML = textStatus;
console.log('id: ' + id + ' (' + pendingCount + '/' + totalCount + '), status: ' + textStatus);
if (pendingCount == 0) {
document.getElementById('resTotal').innerHTML = 'done';
console.log('complete, error count: ' + errorCount);
allErrorCount = allErrorCount + errorCount;
document.getElementById('resSAll').innerHTML = 'total errors: ' + allErrorCount + "/" + (pushCount*totalCount);
}
}
});
}
//
-->
!/bin/sh
Read all data from stdin and send it to stdout
Write the response header with \r\n
Headline for generated reply:
Disable until Warning returns to Travis CI or AppVeyor
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wno-variadic-macros"
#pragma GCC diagnostic ignored "-Wreserved-id-macro"
A default timeout for all tests running multiple requests to a server.
All unit tests use the "check" framework.
* Download from https://libcheck.github.io/check/
comment: FIXME: check uses GCC specific variadic macros that are non-standard
label: code-design
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
A minimal timeout for all tests starting a server.
Disable warnings for defining _CRT_SECURE_NO_* (here) and
* _CHECK_CHECK_STDINT_H (in check.h)
A minimal timeout used for all tests with the "check" framework.
TEST_CIVETWEB_CHECK_H_
comment: When using -Weverything, clang does not accept it's own headers
* in a release build configuration. Disable what is too much in
* -Weverything.
label: code-design
Unreferenced formal parameter. START_TEST has _i
conditional expression is constant . asserts use while(0)
Make the actual CORS request.
XHR for Chrome/Firefox/Opera/Safari.
Create the XHR object.
Helper method to parse the title tag from the response.
Response handlers.
XDomainRequest for IE.
CORS not supported.
http://www.html5rocks.com/en/tutorials/cors/
!/bin/sh
Read in two pieces, to test continuation
Copyright (c) 2004-2009 Sergey Lyubka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Unit test for the civetweb web server. Tests embedded API.
HTML forms can use GET or POST, and the encoding can be application/x-www-form-urlencoded or multipart/form-data.
If no method is specified (like <form method="method">), GET should be the default method.
If no encoding is specified, application/x-www-form-urlencoded should be the default.
Submit buttons may overwrite action, method and enctype by using formaction, formmethod and formenctype.
References:
http://www.w3.org/TR/html401/interact/forms.html
http://www.w3schools.com/html/html_forms.asp,
http://www.w3schools.com/html/html_form_attributes.asp
http://www.w3.org/TR/html401/interact/forms.html#adef-enctype
www.w3.org/TR/html401/interact/forms.html
www.w3schools.com/html/html_forms.asp,
www.w3schools.com/html/html_form_attributes.asp
www.w3.org/TR/html401/interact/forms.html#adef-enctype
!/bin/sh
!/bin/sh
!/bin/sh
!/bin/sh
Determine what tests to run
This unit test file uses the excellent Check unit testing library.
* The API documentation is available here:
* http://check.sourceforge.net/doc/check_html/index.html
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Write test logs to a file
Run up the tests
CK_NORMAL offers not enough diagnosis during setup phase
Adapted from unit_test.c
req3 is a complete and valid request
Test helper function - adapted from unit_test.c
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
*
* We include the source file so that we have access to the internal private
* static functions
Copyright (c) 2004-2013 Sergey Lyubka
req12 is a valid request with body data
invalid
req1 minus 1 byte at the end is incomplete
req10 is a valid request
req1 is a valid request
Multiline header are obsolete, so return an error
* (https://tools.ietf.org/html/rfc7230#section-3.2.4).
req5 is a complete and valid request (also somewhat malformed,
* since it uses \n\n instead of \r\n\r\n)
comment: len could be unused, if base64_decode is not tested because USE_LUA is
* not defined
label: code-design
This unit test file uses the excellent Check unit testing library.
* The API documentation is available here:
* http://check.sourceforge.net/doc/check_html/index.html
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
req7 is invalid, but not yet complete
a million "a" in blocks of 10
Same is true for a leading space
Used to debug test cases without using the check framework
comment: TODO: adapt test for big endian
label: test
req8 is a valid response
comment: Pass small buffer, make sure alloc_printf allocates
label: code-design
req2 is a complete, but invalid request
a million "a"
An empty string is neither a complete request nor a complete
* response, so it must return 0
Test alternative implementation
is_valid_uri is superseeded by get_uri_type
req11 is a complete but valid request
length without body
req9 is a valid response
Valid request
comment: TODO: check this for big endian
label: requirement
comment: Can not test, if SHA1 is not included
label: test
But a control character (like 0) makes it invalid
req6 is incomplete
req1 minus 1 byte at the start is complete but invalid
Copyright (c) 2013-2015 the Civetweb developers
test_parse_port_string requires WSAStartup for IPv6
empty string
"abc"
part of "Thu, 01 Jan 1970 00:00:00 GMT"
If the string is truncated, mg_snprintf calls mg_cry.
* If DEBUG is defined, mg_cry calls DEBUG_TRACE.
* In DEBUG_TRACE_FUNC, flockfile(stdout) is called.
* For Windows, flockfile/funlockfile calls Enter-/
* LeaveCriticalSection(&global_log_file_lock).
* So, we need to initialize global_log_file_lock:
TEST_PRIVATE_H_
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
This unit test file uses the excellent Check unit testing library.
* The API documentation is available here:
* http://check.sourceforge.net/doc/check_html/index.html
test sdup
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
This is required for "realpath". According to
* http://man7.org/linux/man-pages/man3/realpath.3.html
* defining _XOPEN_SOURCE 600 should be enough, but in
* practice this does not work.
main is already used in the test suite,
* so this define will rename main in main.c
*
* We include the source file so that we have access to the internal private
* static functions.
TEST_PRIVATE_H_
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
This is a redefine for "main" in main.c
comment: TODO: mg_get_cookie and mg_get_var(2) should have the same behavior
label: code-design
current version is 1.8
zero size result buffer
keys are found as first, middle and last key
comment: ck_assert_int_eq(ret, -3);
--> TODO: mg_get_cookie returns -3, mg_get_var -2. This should be
unified.
label: code-design
invalid result buffer
key not found in string
This unit test file uses the excellent Check unit testing library.
* The API documentation is available here:
* http://check.sourceforge.net/doc/check_html/index.html
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
space is valid
a-z is valid
check feature
comment: TODO: this is the same situation as with mg_get_value
label: code-design
longer value in the middle of a longer string - seccond occurance of key
key with = but without value in the middle of a longer string
A-Z is valid
longer value in the middle of a longer string
too small result buffer
check structure of version string
get system information
hyphen is valid
key without = and without value in the middle of a longer string
mg_get_var call mg_get_var2 with last argument 0
TEST_PUBLIC_H_
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
return 0 to accept every connection
HTTP 1.1 GET request
Read file before a .htpasswd file has been created
This test should ensure the minimum server example in
* docs/Embedding.md is still running.
send some kilobyte of data
TODO: fix path in CI test environment
Can not send a websocket goodbye message here -
* the connection is already closed
Get data from callback using https://127.0.0.1
Remove log files (they may exist from previous incomplete runs of
* this test)
TODO: ck_assert_str_eq(client_ri->request_method, "HTTP/1.0");
Handle form: "POST x-www-form-urlencoded"
Repeat test after .htpasswd is created
Set options and start server
Ask for something not existing - should get error404.htm
Websocket test
Elapsed time in ms - in most systems
* only with second resolution
www.github.com
Stop the server
Disconnect client 3
Server start parameters for HTTPS
HTTPS port - required
Call a test client
This unit test file uses the excellent Check unit testing library.
* The API documentation is available here:
* http://check.sourceforge.net/doc/check_html/index.html
Wait for the websocket acknowledge message
defined(MG_USE_OPEN_FILE)
set minimum SSL version to TLS 1.2 - recommended
TODO: Check this problem on AppVeyor
ck_assert_int_le(retry_fail_cnt, 2);
ck_assert_int_ge(retry_ok_cnt, 1);
Ask in a malformed way - should get error4xx.htm
set "HTTPS only" header - recommended
timing test
Start server with bad options
Try to copy the files required for AppVeyor
Connect client 4
not authorized
comment: Stop the server and clean up
label: code-design
Handle form: "POST multipart/form-data" with chunked transfer encoding
HTTP 1.1 GET request - must not work, since server is already stopped
Client data
return 1 to keep the connetion open
comment: Remove log files
label: code-design
e.g.: ck_assert_str_eq(client_ri->request_uri, "200");
Return 1 means "already handled"
strlen(websocket_goodbye_msg)
Handle form: "POST multipart/form-data", chunked, store
comment: Time estimation: Data size is 10 kB, with 1 kB/s speed limit.
* The first block (1st kB) is transferred immediately, the second
* block (2nd kB) one second later, the third block (3rd kB) two
* seconds later, .. the last block (10th kB) nine seconds later.
* The resolution of time measurement using the "time" C library
* function is 1 second, so we should add +/- one second tolerance.
* Thus, download of 10 kB with 1 kB/s should not be faster than
* 8 seconds.
label: code-design
Free test data
Response must be 505 HTTP Version not supported
Error replies will close the connection, even if keep-alive is set.
Get CGI generated data
Try to access the file again. Expected: 401 error
Response must be 400 Bad Request
Try downloading several times
full length string compare will reach limit in the implementation
* of the check unit test framework
Ask for something not existing - should get error4xx.htm
Don't need to do this if mg_start failed
Used to debug test cases without using the check framework
Get directory listing
Get data from callback
Check error.log
set some modern ciphers - recommended
Get data from callback using mg_connect_client instead of mg_download
Create an error4xx.htm file
The check unit test library does not have build in memcmp functions.
Start with default options
It seems to be impossible to find out what the actual working
* directory of the CI test environment is. Before breaking another
* dozen of builds by trying blindly with different paths, just
* create the file here
File is in memory
comment: TODO: add test for windows, check with POST
label: test
**************************************************************************
Do not set this on Travis CI, since the build containers
* contain older SSL libraries
Build command for Linux:
gcc test/public_server.c src/civetweb.c -I include/ -I test/ -l pthread -l dl -D
LOCAL_TEST -D REPLACE_CHECK_FOR_LOCAL_DEBUGGING -D MAIN_PUBLIC_SERVER=main
comment: TODO: the different paths
* used in the different test
* system is an unsolved
* problem.
label: test
Set to a number - but use a number above the limit
Connect client 3
chunks from 1 byte to strlen(boundary)-1
File content check var
Filename is required
Response must be 200 OK
Server var
ck_assert_int_eq(i, (int)strlen(expected_cgi_result));
comment: Remove invalid option
label: code-design
Debug output for tests
Handle form: "POST multipart/form-data", chunked, store, with files
Get zipped static data - with Accept-Encoding
assume there is enough space left in our
typical 255 character string buffers
Try to load non existing file
Write long data (16 bit size header)
Run the server for 15 seconds
Get the current working directory
Server context handle
PUT to static file (will not work)
We don't need the original anymore, the server has a private copy
Get data from callback using https://[::1]
Get data from callback using http://127.0.0.1
strlen(websocket_welcome_msg)
comment: TODO: A client API using a client certificate is missing
label: code-design
stop the server without closing this connection
Call the form handler
Check the test dir
First test with GET
Handle form: "POST x-www-form-urlencoded", chunked, store
HTTP 1.7 GET request - this HTTP version does not exist
Initialize the library
Start the server
File is not in memory
path to certificate file - required
nonce is from including (auth_request + len) to excluding (str)
Remove error files (in case they exist)
Ask for something not existing - should get error.htm
Not a valid HTTP response code,
* but it should be written to the log and passed to
* end_request.
Add some handler
Get redirect from callback using http://127.0.0.1
CGI_ENVIRONMENT_SIZE
Wait for the response
Add large env field, so the server
* must reallocate buffers.
This time start the server with a valid configuration
Create an error.htm file
Retry DELETE with authorization of a user not authorized for DELETE
Abort test with diagnostic message
Ask for something not existing - should get default 404
USE_WEBSOCKET
Travis
Read PUT response
The Linux builds on Travis CI work fine with TLS1.2
Send websocket welcome message
HTTP request with multiline header.
* Multiline header are obsolete with RFC 7230 section-3.2.4
* and must return "400 Bad Request"
__MACH__
Access to the file must work like before
Get data from callback using mg_connect_client and absolute URI with a
* sub-domain
Check if there are at least 8 seconds
comment: not required
label: requirement
Create an error404.htm file
WEBSOCKET SERVER
This test should show a HTTPS server with enhanced
* security settings.
*
* Articles:
* https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
*
* Scanners:
* https://securityheaders.io/
* https://www.htbridge.com/ssl/
* https://www.htbridge.com/websec/
* https://www.ssllabs.com/ssltest/
* https://www.qualys.com/forms/freescan/
test with unknown option
Get zipped static data - will not work if Accept-Encoding is not set
Check if CGI test executable exists
comment: Return codes of the tested functions are evaluated. Checking all other
* functions, used only to prepare the test environment seems redundant.
* If they fail, the test fails anyway.
label: code-design
Handle form: "POST multipart/form-data"
HTTP 1.0 GET request
Get data from callback using mg_connect_client and absolute URI
For unknown reasons, there are sporadic hands
* for OSX if mark_point is called here
Now connect a second client
Create a default file in the document root
Give the server some time to start in the test VM
Won't get any message
Then connect a first client
Check access.log
Closed
Prepare test data
Test with CGI test executable
Now test form_store
Un-initialize the library
breakpoint here !
Close the server
comment: Copy the untruncated value, so string compare functions can be used.
label: code-design
method not allowed
comment: TODO: request a file and keep alive
* (will only work if NO_FILES is not set).
label: code-design
First store the length information in a text buffer.
Create a .htpasswd file
Server is running now
comment: TODO: not yet available
label: requirement
Write long data (64 bit size header)
Remove the user from the .htpasswd file again
Wait for the websocket goodbye message
sending megabytes to localhost does not allways work in CI test
* environments (depending on the network stack)
send some strings that are almost boundaries
Get static data
Appveyor
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Then send length information, chunk and terminating \r\n.
Now remove the password file
HTTP 1.0 GET request - server is not running
Run the server for 5 seconds
End test
Handle form: "GET"
WEBSOCKET CLIENT
Get data from callback using http://[::1]
comment: Test with bad num_thread option
label: test
Free data in ws_client4_conn
end of options - required
comment: Return 0 means "not yet handled"
label: requirement
Retry with authorization
Not closed
Send websocket goodbye message
Handle form: "POST multipart/form-data" with chunked transfer
* encoding, using a quoted boundary string
connect client
Wait for the websocket welcome message
Remove all error files created by this test
Error message detail may vary - it may not be empty ans should contain
* some information "connect" failed
The Apple builds on Travis CI seem to have problems with TLS1.x
* Allow SSLv3 and TLS
Client var
Nothing left to read
Details of errmsg may vary, but it may not be empty
Check the pem file
POST to static file (will not work)
initializer list here is rejected by CI test
Close the client connection
TEST_PUBLIC_H_
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
Copyright (c) 2015-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
TEST_SHARED_H_
#exec "cd"
#include "hello.txt"
#include virtual="hello.txt"
#include abspath="C:\Windows\system.ini"
#exec "pwd"
#include file="./hello.shtml"
#include abspath="/etc/issue"
#include file="hello.txt"
Create a socket
Connect to the server
3 --> 2, an absolute timer in the past (-123.456) will still
* run once at start, and then with the period
3 --> 3, will not run at start
Copyright (c) 2016-2017 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
3 --> 1, an absolute timer in the past (-123.456) will still
* run once at start, and then with the period
If this test runs in a virtual environment, like the CI unit test
* containers, there might be some timing deviations, so check the
* counter with some tolerance.
End timer thread
3 --> 2, because it is a single shot timer
Sleep 1 second - timer will not run
*
* We include the source file so that we have access to the internal private
* static functions
Sleep 10 second - timers will run
3 --> 0, because it will run until c[1] = 0 and then stop
Sleep 2 second - timers will not run
3 --> 2, will run at start, but no cyclic in 1 second
Used to debug test cases without using the check framework
Sleep 1 second - timer will run
3 --> 1, with 750 ms period, it will run once at start,
* then once 750 ms later, but not 1500 ms later, since the
* timer is already stopped then.
return 0 here would be unreachable code
Copyright (c) 2015 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
TEST_TIMER_H_
!/usr/bin/env bash
Create a tmp directory for the test to use
measure fillseq with bunch of column families
comment: measure overwrite performance
label: code-design
measure readrandom with 6GB block cache
comment: On the production build servers, set data and stat
files/directories not in /tmp or else the tempdir cleaning
scripts will make you very unhappy.
label: code-design
Readwhilewriting
measure readwhilewriting after load with filluniquerandom with 6GB block cache
Seekrandomwhilewriting
comment: measure memtable performance -- none of the data gets flushed to disk
label: code-design
-eq 2 ];then
send data to ods
fill up the db for readrandom benchmark with filluniquerandom (1GB total size)
running on devbox, just print out the values
measure readrandom with 100MB block cache
comment: measure overwrite performance with bunch of column families
label: code-design
measure fillseq + fill up the DB for overwrite benchmark
prepare a in-memory DB with 50M keys, total DB size is ~6G
-eq 1 ];then
measure readrandom with 6GB block cache and tailing iterator
dummy test just to compact the data
measure readrandom with 8k data in memtable
!/usr/bin/env bash
measure readrandom after load with filluniquerandom with 6GB block cache
fill up the db for readrandom benchmark (1GB total size)
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Have deleter which will erase item from cache, which will re-enter
the cache at that point.
release remaining 5 to keep valgrind happy
cache is under capacity now since elements were released
test1: increase capacity
lets create a cache with capacity 5,
then, insert 5 elements, then increase capacity
to 10, returned capacity should be 10, usage=5
the cache is over capacity since nothing could be evicted
delete the key from the cache
Add a bunch of light and heavy entries and then count the combined
size of items still in the cache, which must be approximately the
same as the total capacity.
Insert item large than capacity to trigger eviction on empty cache.
comment: Cleaning up all the handles
label: code-design
First release (i == 1) corresponds to Ref(), second release (i == 2)
corresponds to Lookup(). Then, since all external refs are released,
the below insertions should push out the cache entry.
namespace rocksdb
This tests that deleter is not called. When cache has free capacity it is
not expected to immediately erase the released items.
test3: init with flag being true.
AS if the key have been inserted into cache but get evicted immediately.
Frequently used entry must be kept around
SUPPORT_CLOCK_CACHE
test2: decrease capacity
insert 5 more elements to cache, then release 5,
then decrease capacity to 7, final capacity should be 7
and usage should be 7
comment: cache is shared_ptr and will be automatically cleaned up.
label: code-design
namespace
test1: set the flag to false. Insert more keys than capacity. See if they
all go through.
If i % 2 == 0, then the entry was unpinned before Lookup, so pinned
usage increased
the usage should be close to the capacity
Check whether the entries inserted in the beginning
are evicted. Ones without extra ref are evicted and
those with are not.
make sure the cache will be overloaded
test insert without handle
comment: release handles for pinned entries to prevent memory leaks
label: code-design
can no longer find in the cache
Add entries. Unpin some of them after insertion. Then, pin some of them
again. Check GetPinnedUsage().
Guess what's in the cache now?
This tests that deleter has been called
Make sure eviction is triggered.
Insert 5 entries, but not releasing.
Insert n+1 entries, but not releasing.
double cache size because the usage bit in block cache prevents 100 from
being evicted in the first kCacheSize iterations
a LRUCache with n entries and one shard only
release one handle
test2: set the flag to true. Insert and check if it fails.
Conversions between numeric keys/values and the types expected by Cache.
Insert entries much more than Cache capacity
element 0 is evicted and the rest is there
This is consistent with the LRU policy since the element 0
was released first
check that overloading the cache does not change the pinned usage
insert a key and get two handles
still can't find in cache
make sure everything will be cached
Low-pri entries will be inserted to head of low-pri pool.
charge
Low-pri entries can take high-pri pool capacity if available
hash
Low-pri entries will be inserted to head of low-pri pool after lookup.
High-pri entries will be inserted to the head of the list after lookup.
Allocate 2 cache entries to high-pri pool.
deleter
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
High-pri entries can overflow to low-pri pool.
handle
comment: TODO: we also need to get the files of the latest commits.
Get the most recently committed files.
label: code-design
comment: Find all gcno files to generate the coverage report
label: test
Fetch right version of gcov
Generate the html report. If we cannot find lcov in this machine, we'll simply
skip this step.
comment: Parse the raw gcov report to more human readable form.
label: code-design
Unless otherwise specified, we'll not generate html report by default
Exit on error.
!/usr/bin/env bash
Write the output to both stdout and report file.
write batch into TransactionDB
put
begin a transaction
need a change to trigger a new backup
Delete all keys we just ingested
First run uses custom filter, second run uses bloom filter
read from outside transaction, after commit
Ok for uniqueness
Reset the policy
Custom merge operator
Callback from rocksdb_writebatch_iterate()
testing basic case with no iterate_upper_bound and no prefix_extractor
testing iterate_upper_bound and forward iterator
to make sure it stops at bound
put outside a transaction
bingo
Create new empty database
should stop here...
Create new database
normal not found
ok
Column families.
close and destroy
read from outside transaction, before commit
iterate_upper_bound points beyond the last expected entry
rollback
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
!ROCKSDB_LITE
If we do not compact here, then the lazy deletion of
files (https://reviews.facebook.net/D6123) would leave
around deleted files and the repair process will find
those files and put them back into the database.
open a TransactionDB
Custom compaction filter
snapshot
Custom filter policy
Simple sanity check that options setting db_paths work.
should have filtered bar, but not foo
reuse old transaction
Must not find value when custom filter returns false
wrong cf
Simple sanity check that setting memtable rep works.
Lite does not support C API
start a new database from the checkpoint
delete from outside transaction
commit
Can not use port/port.h macros as this is a c file
Simple check cache usage
Merge of a non-existing value
delete
iterate
Force compaction
Create database with vector memtable.
Create database with hash skiplist memtable.
Ugh. Random seed of 0 used to produce no entropy. This code
preserves the implementation that was in place when all of the
magic values in this file were picked.
[0, (1)] [0, (1), (2)] [(2)] [(1), 2, 3] [1]
[0, (1)] [0, 1, (2)] [(2)] [1, 2, 3]
Compare against saved keys
disable flushing stale column families
[0, (1)] [1]
Write to log file D
seqID 7
seqID 8
[(1), 2, 3] [1, (0)], [(0)] [0]
[0, 1]
WaitForFlush() is not supported
1. check consistency
2. copy the logs from backup back to WAL dir. if the recovery happens
again on the same log files, this should lead to incorrect results
due to applying merge operator twice
3. check consistency
delete obsolete files always
Add three column families - one with no comparator and two
with comparators specified
GetProperty is not supported in lite
RocksDBLite does not support GetDescriptor
Verify the CF options of the returned CF handle.
[0, (1)] [0, 1, (2)] [2]
Write batch should be atomic.
Since we didn't delete CF handle, RocksDB's contract guarantees that
we're still able to read dropped CF
64KB
GetLiveFilesMetaData is not supported
base
WaitForCompaction() is not supported in lite
comment: SETUP column family "two" -- level style with 4 levels
label: code-design
Drop CF two
1MB should create ~10 files for each CF
Not sure how easy it is to make this data driven.
need to read back the WAL file and truncate last 10
entries
Make sure Sanitize options sets arena_block_size to 1/8 of
the write_buffer_size, rounded up to a multiple of 4k.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
[0, (1)] [0, 1]
iter == 0 -- no tailing
iter == 2 -- tailing
[(1), (2), 3] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2]
comment: Speed up threshold = min(4 * 2, 4 + (36 - 4)/4) = 8
label: code-design
Can't open without specifying default column family
TEST functions are not supported in lite
Sync points not supported in RocksDB Lite
Hold super version.
If it's the main thread hitting this sync-point, then it
will be blocked until some other thread update the test_stage.
10 bytes for key, rest is value
10 bytes
comment: [(1), (2), (3)] [(1), (0)] [(0)] [0, (1)] [1, (2)], [2, (3)] [3]
delete obsolete logs -->
[0, (1)] [1, (2)], [2, (3)] [3]
label: code-design
Add bunch more data to other CFs
namespace
off
[(1), 2, 3] [(1), (0)] [(0)] [0, (1)] [1]
Add more L0 files and force another manual compaction
fill up the DB
default argument means copy everything
Tailing interator not supported
can't open dropped column family
Create a database with four column families
delete CF two
This means a thread doing DropColumnFamily() is waiting for
other thread to finish persisting options.
In such case, we update the test_stage to unblock the main thread.
comment: cleanup
label: code-design
Return spread of files per level
iter 0 -- drop CF, don't reopen
iter 1 -- delete CF, reopen
seqID 4
seqID 5
comment: [(0), (1)] [(0), (1), (2)] [(2)] [(1), 2, 3] [1, (0)] [0]
delete obsolete logs -->
[(1), 2, 3] [1, (0)] [0]
label: code-design
Each bracket is one log file. if number is in (), it means
we don't need it anymore (it's been flushed)
[]
SETUP column family "one" -- universal style
Add a column family with no comparator specified
test newiterators
Log file A is not dropped after reopening because default column family's
min log number is 0.
It flushes to SST file X
seqID 2
seqID 3
Current log file is file B now. While flushing, a new log file C is created
and is set to current. Both CFs' min log number is set to file C so after
flushing file B is deleted. Log file A still remains.
Flushed to SST file Y.
VERIFY compaction "one"
comment: Speed up threshold = min(4 * 2, 4 + (12 - 4)/4) = 6
label: code-design
Before opening, there are four files:
Log file A contains seqID 1
Log file C contains seqID 4, 5
SST file X contains seqID 1
SST file Y contains seqID 2, 3
Min log number:
default CF: 0
CF one, two: C
When opening the DB, all the seqID should be preserved.
third flush. now, CF [two] should be detected as stale and flushed
column family 1 should not be flushed since it's empty
flush
namespace rocksdb
flush
Flush the 0th column family to force a roll of the wal log
no tailing
Test that we can retrieve the comparator from a created CF
100KB
Block flush jobs from running
tailing
Add a column family that doesn't support snapshot
now we sleep again. this is just so we're certain that flush job finished
Note that based on the test setting, this must not be the
main thread.
Disable on windows because SyncWAL requires env->IsSyncThreadSafe()
to return true which is not so in unbuffered mode.
!ROCKSDB_LITE
GetSortedWalFiles is not supported
setup options. all column families have max_write_buffer_number setup to 10
"default" -> 100KB memtable, start flushing immediatelly
"one" -> 200KB memtable, start flushing with two immutable memtables
"two" -> 1MB memtable, start flushing with three immutable memtables
"three" -> 90KB memtable, start flushing with four immutable memtables
not a multiple of 4k, round up 4k
[0, (1)] [0, 1, 2]
this test is placed here, because the infrastructure for Column Family
test is being used to ensure a roll of wal files.
Basic idea is to test that WAL truncation is being detected and not
ignored
WAIT for compactions
Create an iterator holding the current super version.
Cuckoo is not supported in lite
Do n memtable flushes, each of which produces an sstable
covering the range [small,large].
copy the logs to backup
Before opening, there are two logfiles:
Log file A contains seqID 1
Log file D contains seqID 7, 8
Min log number:
default CF: D
CF one, two: D
When opening the DB, log file D should be replayed using the seqID
specified in the file.
In this test, we generate enough files to trigger automatic compactions.
The automatic compaction waits in NonTrivial:AfterRun
We generate more files and then trigger an automatic compaction
This will wait because the automatic compaction has files it needs.
Once the conflict is hit, the automatic compaction starts and ends
Then the manual will run and end.
TRIGGER compaction "one"
first iteration - dont reopen DB before dropping
second iteration - reopen DB before dropping
delete old files in backup_logs directory
only 10 files in file cache
assert consistency
This test checks for automatic getting a conflict if there is a
manual which has not yet been scheduled.
The manual compaction waits in NotScheduled
We generate more files and then trigger an automatic compaction
This will wait because there is an unscheduled manual compaction.
Once the conflict is hit, the manual compaction starts and ends
Then another automatic will start and end.
SETUP column family "one" -- level style
this will trigger the flushes
copy the logs from backup back to wal dir
make sure all background compaction jobs can be scheduled
[0]
TEST functions used are not supported
comment: ID 3 that was used for dropped column family "three" should not be reused
label: code-design
Speedup threshold = 200 / 4 = 50
skipped as persisting options is not supported in ROCKSDB_LITE
3 files for default column families, 1 file for column family [two], zero
files for column family [one], because it's empty
anonymous namespace
Flush jobs will close previous WAL files after finishing. By
block flush jobs from running, we trigger a condition where
the iterator destructor should close the WAL files.
small write buffer size
make sure that all files are deleted when we drop the column family
Add more L0 files and force automatic compaction
Add a column family that supports snapshot. Snapshot stays not supported.
open only a subset of column families
Generate log file A.
seqID 1
Log file A is not dropped after reopening because default column family's
min log number is 0.
It flushes to SST file X
seqID 2
seqID 3
Current log file is file B now. While flushing, a new log file C is created
and is set to current. Boths' min log number is set to file C in memory, so
after flushing file B is deleted. At the same time, the min log number of
default CF is not written to manifest. Log file A still remains.
Flushed to SST file Y.
A flush will make `it` hold the last reference of its super version.
recover the DB
Deleting the iterator will clear its super version, triggering
closing all files
Allow both of flush and purge job to schedule.
collect wal files
TEST functions in DB are not supported in lite
[0, (1)] [0, 1, (2)] [(2)] [2, 3]
Return the value to associate with the specified key
Start a thread that will drop the first column family
and its comparator
counts how many operations were performed
Add some more entries
comment: Make sure iterator created can still be used.
label: code-design
this tests if max_column_family is correctly persisted with
WriteSnapshot()
ReadOnlyDB is not supported
Required if inheriting from testing::WithParamInterface<>
WaitForFlush() is not supported in lite
Add another L0 file and force automatic compaction
Take the last but one file, and truncate it
TRIGGER compaction "two"
Makes sure that obsolete log files get deleted
Create an iterator holding the current super version, as well as
the SST file just flushed.
[0, (1)] [0, 1, (2)] [(2)] [2]
WaitForFlush() is not supported
Makes sure that obsolete log files get deleted
VERIFY compaction "two"
comment: GetSortedWalFiles is a flakey function -- it gets all the wal_dir
children files and then later checks for their existence. if some of the
log files doesn't exist anymore, it reports an error. it does all of this
without DB mutex held, so if a background process deletes the log file
while the function is being executed, it returns an error. We retry the
function 10 times to avoid the error failing the test
label: test
trigger compaction if there are >= 4 files
Preserve file system state up to here to simulate a crash condition.
seqID 4
seqID 5
seqID 6
Flushing all column families. This forces all CFs' min log to current. This
is written to the manifest file. Log file C is cleared.
namespace rocksdb
Compact all L0 files using CompactFiles
Add listener
Small slowdown and stop trigger for experimental purpose.
no assertion failure
Another thread starts a compact files and creates an L0 compaction
The background compaction then notices that there is an L0 compaction
already in progress and doesn't do an L0 compaction
Once the background compaction finishes, the compact files finishes
!ROCKSDB_LITE
create couple files
Background compaction starts and waits in BackgroundCallCompaction:0
A class which remembers the name of each flushed file.
Start compacting files.
Add listener.
verify all compaction input files are deleted
comment: to trigger compaction more easily
label: code-design
Always do full scans for obsolete files (needed to reproduce the issue).
Create 5 files.
Write one L0 file
Disable RocksDB background compaction.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
create couple files
Make sure we can reopen the DB.
In the meantime flush another file.
c should invoke FullMerge due to kTypeValue at the beginning.
Compaction should output just "a", "e" and "h" keys.
keep
skip to "f", aka keep
skip to "g+"
keep
skip to "z"
Same as ShuttingDownInFilter, but shutdown happens during filter call for
a merge operand, not for a value.
If there is a corruption after a single deletion, the corrupted key should
be preserved.
Last key the filter was called with.
skip to "d+"
namespace rocksdb
Wait until the filter sees a key >= k and stalls at that key.
If `exact`, asserts that the seen key is equal to k.
Expects no merging attempts.
Don't leave tombstones (kTypeDeletion) for filtered keys.
Check that filter was never called again.
b should invoke PartialMergeMulti with two operands.
Unstall filter and wait for SeekToFirst() to return.
Let key 1 through.
See InitIterators() call below for the sequence of keys and their
filtering decisions. Here we closely assert that compaction filter is
called with the expected keys and only them, and with the right values.
Compaction filter that gets stuck when it sees a particular key,
then gets unstuck when told to.
Always returns Decition::kRemove.
Check that the compaction iterator did the correct sequence of calls on
the underlying iterator.
keep
It is possible that the output of the compaction iterator is empty even if
the input is not.
Shutdown during compaction filter call for key 2.
Filter will stall on key >= stall_at. Advance stall_at to unstall.
See InitIterators() call below for why "c" is the only key for which
FullMergeV2 should be called.
a should invoke PartialMergeMulti with a single merge operand.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Destroy using last options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Send these L0 files to L1
Whenever a compaction completes, this listener will try to
verify whether the returned CompactionJobStats matches
what we expect. The expected CompactionJobStats is added
via AddExpectedStats().
4th Phase: perform L0 -> L1 compaction again, expect higher write amp
When subcompactions are enabled, the number of output files increases
by 1 because multiple threads are consuming the input and generating
output files without coordinating to see if the output could fit into
a smaller number of files like it does when it runs sequentially
namespace rocksdb
Insert some deletions for keys that don't exist that
are both in and out of the key range
time
Do n memtable compactions, each of which produces an sstable
covering the range [small,large].
3rd Phase: generate sparse L0 files (wider key-range, same num of keys)
Stage 1: Generate several L0 files and then send them to L2 by
using CompactRangeOptions and CompactRange(). These files will
have a strict subset of the keys from the full key-range
just enough setting to hold off auto-compaction.
namespace
A helper function which verifies whether two CompactionJobStats
match. The verification of all compaction stats are done by
ASSERT_EQ except for the total input / output bytes, which we
use ASSERT_GE and ASSERT_LE with a reasonable bias ---
10% in uncompressed case and 20% when compression is used.
5th Phase: Do a full compaction, which involves in two sub-compactions.
Here we expect to have 1 L0 files and 4 L1 files
In the first sub-compaction, we expect L0 compaction.
Here we treat one newly flushed file as an unit.
For example, if a newly flushed file is 100k, and a compaction has
4 input units, then this compaction inputs 400k.
1st Phase: generate "num_L0_files" L0 files.
Destroy it for not alternative WAL dir is used.
Generates the expected CompactionJobStats for each compaction
!ROCKSDB_LITE
!defined(IOS_CROSS_COMPILE)
2nd Phase: perform L0 -> L1 compaction.
Required if inheriting from testing::WithParamInterface<>
compact two files into one in the last L0 -> L1 compaction
This function behaves with the implicit understanding that two
rounds of keys are inserted into the database, as per the behavior
of the DeletionStatsTest.
Once a compaction completed, this function will verify the returned
CompactionJobInfo with the oldest CompactionJobInfo added earlier
in "expected_stats_" which has not yet being used for verification.
Note: key_base must be multiple of num_keys_per_L0_file
Add an expected compaction stats, which will be used to
verify the CompactionJobStats returned by the OnCompactionCompleted()
callback.
default cfd
Whenever a compaction completes, this listener will try to
verify whether the returned CompactionJobStats matches
what we expect.
interval needs to be >= 2 so that deletion entries can be inserted
that are intended to not result in an actual key deletion by using
an offset of 1 from another existing key
Stage 4: Trigger compaction and verify the stats
Return spread of files per level
Verifies whether two CompactionJobStats match.
Add a new record and flush so now there is a L0 file
with a value too (not just deletions from the next step)
make sure this is even
Stage 3: Generate L0 files with some deletions so now
there are files with the same key range in L0, L1, and L2
An EventListener which helps verify the compaction results in
test CompactionJobStatsTest.
filter block
index block
Stage 2: Generate files including keys from the entire key range
An EventListener which helps verify the compaction statistics in
the test DeletionStatsTest.
file size
disallow trivial move
1/3 of the data will be updated.
The following statement determines the expected smallest key
based on whether it is a full compaction. A full compaction only
happens when the number of flushes equals to the number of compaction
input runs.
!defined(IOS_CROSS_COMPILE)
namespace rocksdb
comment: This test documents the behavior where a corrupt key follows a deletion or a
single deletion and the (single) deletion gets removed while the corrupt key
gets written out. TODO(noetzli): We probably want a better way to treat
corrupt keys.
label: code-design
Tests three scenarios involving multiple single delete/put pairs:
A: Put Snapshot SDel Put SDel -> Put Snapshot SDel
B: Snapshot Put SDel Put SDel Snapshot -> Snapshot SDel Snapshot
C: SDel Put SDel Snapshot Put -> Snapshot Put
D: (Put) SDel Snapshot Put SDel -> (Put) SDel Snapshot SDel
E: Put SDel Snapshot Put SDel -> Snapshot SDel
F: Put SDel Put Sdel Snapshot -> removed
G: Snapshot SDel Put SDel Put -> Snapshot Put SDel
H: (Put) Put SDel Put Sdel Snapshot -> Removed
I: (Put) Snapshot Put SDel Put SDel -> SDel
J: Put Put SDel Put SDel SDel Snapshot Put Put SDel SDel Put
-> Snapshot Put
K: SDel SDel Put SDel Put Put Snapshot SDel Put SDel SDel Put SDel
-> Snapshot Put Snapshot SDel
L: SDel Put Del Put SDel Snapshot Del Put Del SDel Put SDel
-> Snapshot SDel
M: (Put) SDel Put Del Put SDel Snapshot Put Del SDel Put SDel Del
-> SDel Snapshot Del
b does not appear because the operands are filtered
ROCKSDB_LITE
This is how the key will look like once it's written in bottommost
file
Because level 1 is not the last level, the sequence numbers of a and b
cannot be set to 0
Filtered
Test multiple snapshots where the earliest snapshot is not a
write-conflic-snapshot.
Make "CURRENT" file that points to the new manifest file.
comment: TODO(icanadi) Make it simpler once we mock out VersionSet
label: code-design
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
returns expected result after compaction
Filters merge operands with value 10.
Test where all operands/merge results are filtered out.
Level 0 files overlap
If no file in L1 being compacted, L0->L1 compaction will be scheduled.
being_compacted flag is cleared here.
Tests if the files can be trivially moved in multi level
universal compaction when allow_trivial_move option is set
In this test as the input files doesn't overlaps, they should
be trivially moved.
num_levels - 2 is over target by 1100 + 200
Level 1 size will be 10000 after merging with L0
Universal and FIFO Compactions are not supported in ROCKSDB_LITE
does not own FileMetaData
A compaction should be triggered and pick file 2
file_number
Level 3 score slightly larger than 1
Level 1 is over target by 200
Level 4 exceeds target 1,000,000 by 900 after adding size from level 3
Size ratio L4/L3 is 9.9
After merge from L3, L4 size is 1000900
Level 2 is less than target 10000 even added size of level 1
Level 1 files overlap
ROCKSDB_LITE
num_levels - 3 is over target by 100 + 1000
Tests if the files can be trivially moved in multi level
universal compaction when allow_trivial_move option is set
In this test as the input files overlaps, they cannot
be trivially moved.
Level 1 size will be 1400 after merging with L0
This test exhibits the bug where we don't properly reset parent_index in
PickCompaction()
file_size
Chain of overlapping user key ranges (forces ExpandWhileOverlapping() to
expand multiple times)
case 3.1: Higher levels (level 3) have overlap
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
case 3.3: Higher levels (level 5) have overlap, but it's only overlapping
one key ("d")
Locked file encountered when pulling in extra input-level files with same
user keys. Verify we pick the next-best file from the same input level.
output level should be the one above the bottom-most
Locked file encountered when pulling in extra output-level files with same
user keys. Expected to skip that compaction and pick the next-best choice.
6 L0 files, score 3.
Level 2 score 1.8. File 7 is the largest. Should be picked
File not overlapping
Overlapping user keys
Picking file 8 because overlapping ratio is the biggest.
A compaction should be triggered and pick file 2 and 5.
and it expands to file 1 and 3 too.
No compaction should be scheduled, if L0 has higher priority than L1
but L0->L1 compaction is blocked by a file in L1 being compacted.
L1 score more than 6.
A compaction should be triggered and pick all files from level 1
Level 3 exceeds target 100,000 of 1000
largest
score(L1) = 3.7
score(L2) = 1.85
There is no eligible file in L1 to compact since both candidates pull in
file_number 5U, which overlaps with a file pending compaction (6U). The
first eligible compaction is from L2->L3.
Overlapping user keys on same level and output level
Overlaps with file 28, 29, total size 521M
namespace rocksdb
verify whether compaction is needed based on the current
size of L0 files.
Merging to the second last level: (5200 / 2100 + 1) * 1100
Merging to the last level: (50000 / 6300 + 1) * 1300
release the version storage
Pick file 8 because it overlaps with 0 files on level 3.
file 7 and 8 over lap with the same file, but file 8 is smaller so
it will be picked.
Overlaps with file 26, 27
Overlaps with file 27
Overlaps with file 28, but the file
itself is larger. Should be picked.
<- marked for compaction
<- this one needs compacting
Level 2 is less than target 10000 even added size of level 1
Size ratio of L2/L1 is 9600 / 1200 = 8
case 3.2: Higher levels (level 5) have overlap
estimated L1->L2 merge: 400 * (9100.0 / 1400.0 + 1.0)
Set Last level size 50000
num_levels - 1 target 5000
num_levels - 2 is base level with target 1000 (rounded up to
max_bytes_for_level_base).
verify the trigger given different number of L0 files.
File 5 has to be included in the compaction
Output level overlaps with the beginning and the end of the chain
Picking file 7 because overlapping ratio is the biggest.
grow the number of inputs in "level" without
changing the number of "level+1" files we pick up
Expand input level as much as possible
no overlapping case
case 1: Higher levels are empty
Level 3 over the target, but since level 4 is empty, we assume it will be
a trivial move.
smallest_seq
file_number 2U is largest and thus first choice. But it overlaps with
file_number 1U which is being compacted. So instead we pick the next-
biggest file, 3U, which is eligible for compaction.
start a brand new version in each test.
smallest
This test checks ExpandWhileOverlapping() by having overlapping user keys
ranges (with different sequence numbers) in the input files.
If score in L1 is larger than L0, L1 compaction goes through despite
there is pending L0 compaction.
largest_seq
Level 0 files don't overlap
A compaction should be triggered and pick file 2 and 5.
It can expand because adding file 1 and 3, the compaction size will
exceed mutable_cf_options_.max_bytes_for_level_base.
Level 1 score 1.2
L1 total size 2GB, score 2.2. If one file being comapcted, score 1.1.
case 2: Higher levels have no overlap
must return false when there's no files.
input files to compaction process.
comment: grow the number of inputs in "level" without
changing the number of "level+1" files we pick up
Expand input level as much as possible
overlapping case
label: code-design
<- being compacted
Overlaps with file 26, 27, total size 521M
Overlaps with file 27, 28, total size
520M, the smalelst overlapping
Next
Seek to random key
Random walk and make sure iter and result_iter returns the
same key and value
Return the current option configuration.
Destroy using last options
put
Measuring operations on DB (expect to be empty).
source_strings are candidate keys
Randomly generate source keys
Seek to last
Prev
delete
endptr
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace
Randomly generate 5 prefixes
namespace rocksdb
Seek to First
Ugh. Random seed of 0 used to produce no entropy. This code
preserves the implementation that was in place when all of the
magic values in this file were picked.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Fill levels >= 1
build 2 tables, flush at 5000
if ((i % 100) == 0) fprintf(stderr, "@ %d of %d\n", i, n);
Do it
corrupt an index block of an entire file
namespace rocksdb
corrupt file size
Force compactions by writing lots of values
Write something. If sequence number was not recovered properly,
it will be hidden by an earlier write.
Pick file to corrupt
Return the value to associate with the specified key
Pick latest file
WriteBatch tag for first record
Somewhere in second block
!ROCKSDB_LITE
very big, we'll trigger flushes manually
make unit test pass for now
Do enough writing to force minor compaction
Do not verify checksums. If we verify checksums then the
db itself will raise errors because data is corrupted.
Instead, we want the reads to be successful and this test
will detect whether the appropriate corruptions have
occurred.
The 64 records in the first two log blocks are completely lost.
if one write failed, every subsequent write must fail, too
delete the file
Return the ith key
On Wndows OS Disk cache does not behave properly
We do not call FlushBuffers on every Flush. If we do not close
the log file prior to the corruption we end up with the first
block not corrupted but only the second. However, under the debugger
things work just fine but never pass when running normally
For that reason people may want to run with unbuffered I/O. That option
is not available for WAL though.
Write must eventually fail because of corrupted table
If LRU cache shard bit is smaller than 2 (or -1 which will automatically
set it to 0), test SequenceNumberRecovery will fail, likely because of a
bug in recovery code. Keep it 4 for now to make the test passes.
Relative to end of file; make it absolute
corrupts exactly one file at level `level`. if no file found at level,
asserts
comment: one full file should be readable, since only one was corrupted
the other file should be fully non-readable, since index was corrupted
label: code-design
Create a big L0 file and check it compacts into multiple files in L1.
namespace.
Write some keys using plain table.
Write some keys using block based table.
Generate one more file in level-0, and should trigger level-0 compaction
namespace rocksdb
Add some values to db.
The following util methods are copied from plain_table_db_test.
100KB
Write 28 values, each 10016 B ~ 10KB
ROCKSDB_LITE
Add more keys.
Delete.
Write 11 values, each 10016 B
Try with empty DB first.
Now add more keys and flush.
Two SST files should be created, each containing 14 keys.
Number of buckets will be 16. Total size ~156 KB.
Return spread of files per level
Write some keys using cuckoo table.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
disallow trivial move
Duplicate
Update.
Insert same key twice so that they go to different SST files. Then wait for
compaction and check if the latest value is stored and old value removed.
Now check keys in read only mode.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Does not exist, and create_if_missing == false: error
Does exist, and error_if_exists == true: error
Add a key
Skip HashCuckooRep as it does not support single delete. FIFO and
universal compaction do not apply to the test case. Skip MergePut
because single delete does not get removed when it encounters a merge.
comment: After a flush, "second", "third" and "fifth" should
be removed
label: code-design
CompactedDB
Add more keys
Block flush thread and disable compaction thread
id1 should match id2 because identity was not regenerated
second open should fail
Compaction can still go through even if no thread can flush the
mem table.
Add more L0 files
namespace rocksdb
Insert can go through
Full compaction
generate one table with each type of checksum
change when new checksum type added
Unsupported case.
Case 5: snapshot followed by a put followed by another Put
Only the last put should remain.
disable compaction
Empty Key Set
this will now also flush the last 2 writes
skip HashCuckooRep as it does not support snapshot
Case1: Delete followed by a put
10 bytes
after we release the snapshot1, only two values left
verify data with each type of checksum
Fallback to read-only DB
Case 3: Put followed by a delete
This should trigger LogAndApply.
MultiGet
Empty Database, Empty Key Set
Skip HashCuckooRep as it does not support single delete. FIFO and
universal compaction do not apply to the test case. Skip MergePut
because merges cannot be combined with single deletions.
ROCKSDB_LITE
After the current memtable is flushed, the DEL should
have been removed
Write two new keys
Empty Database, Search for Keys
Does not exist, and create_if_missing == true: OK
It is possible to produce empty flushes when using single deletes. Tests
whether empty flushes cause issues.
Reopen and flush memtable.
All other combinations are acceptable
after we release the snapshot2, only one value should be left
id1 should NOT match id3 because identity was regenerated
Case 5: Put followed by snapshot followed by another Put
Both puts should remain.
four kv pairs * two bytes per value
We have only one valid snapshot snapshot2. Since snapshot1 is
not valid anymore, "first" should be removed by a compaction.
'foo' should be there because its put
has WAL enabled.
All entries (including duplicates) exist
before any compaction or flush is triggered.
Case 4: Put followed by another Put
Try with both a short key and a long key
Flush can still go through.
comment: On Windows you can have either memory mapped file or a file
with unbuffered access. So this asserts and does not make
sense to run
label: code-design
1 L0 file, use CompactedDB if max_open_files = -1
clear database
check if a new manifest file got inserted or not.
Does exist, and error_if_exists == false: OK
Case 2: Delete followed by another delete
05
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
11
12
kAllTiers
Should be able to write kTypeBlobIndex to memtables and SST files.
Avoid values from being purged.
Disable auto flushes.
Normal iterator
value_found
16
namespace rocksdb
Avoid blob values from being purged.
SeekForPrev
Next
02
allow_blob
Verify normal value
fill data
Iterator with blob support
Get should be able to return blob index if is_blob_index is provided,
otherwise return Status::NotSupported status.
Prev
Iterator should get blob value if allow_blob flag is set,
otherwise return Status::NotSupported status.
Verify blob index
!ROCKSDB_LITE
10
04
kTypeBlobIndex is a value type used by BlobDB only. The base rocksdb
should accept the value type on write, and report not supported value
for reads, unless caller request for it explicitly. The base rocksdb
doesn't understand format of actual blob index (the value).
13
03
08
14
Get should NOT return Status::NotSupported if blob index is updated with
a normal value.
06
01
00
07
15
09
Seek
small write buffer
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Make sure filter block is in cache.
flush all data from memtable so that reads are from block cache
read and cache data block
Clear strict capacity limit flag. This time we shall hit compressed block
cache.
namespace rocksdb
options.compression = kNoCompression;
Release interators and access cache again.
compressed doesn't have any hits since blocks are not compressed on
storage
anonymous namespace
adding data block
cache evicted old index and block entries
both block cache and compressed cache, but DB is not compressed
also, make block cache sizes bigger, to trigger block cache hits
high compression ratio
set the cache capacity to the current usage
index/filter blocks added to block cache right after table creation.
A mock cache wraps LRUCache, and record how many entries have been
inserted for each priority.
Make sure index block is in cache.
Set a small enough block size so that each key-value get its own block.
check that we triggered the appropriate code paths in the cache
Load blocks into cache.
SNAPPY
Write 8MB (80 values, each 100K)
Miss count should remain the same.
ROCKSDB_LITE
no block cache, only compressed cache
Totally 3 files created up to now
Make sure that when options.block_cache is set, after a new table is
created its index/filter blocks are added to block cache.
Data block should be inserted with low priority.
Run this test three iterations.
Iteration 1: only a uncompressed block cache
Iteration 2: only a compressed block cache
Iteration 3: both block cache and compressed cache
Iteration 4: both block cache and compressed cache, but DB is not
compressed
default column family doesn't have block cache
After disabling options.paranoid_file_checks. NO further block
is added after generating a new file.
Create a new SST file. This will further trigger a compaction
and generate another file.
Access data block.
both compressed and uncompressed block cache
Compressed block cache cannot be pinned.
200 bytes are enough to hold the first two blocks
only uncompressed block cache
only index/filter were added
Test with strict capacity limit.
Create a new table.
Create a new table
Set strict capacity limit flag. Now block will only load into compressed
block cache.
DB tests related to bloom filter.
Full Filter Block
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
11 RAND I/Os
Restart with only prefix bloom is allowed.
Lookup present keys. Should rarely read from either sstable.
Now that we know the filter blocks exist in the last level files, see if
filter caching is skipped for this optimization
Needs insert some keys to make sure files are not filtered out by key
ranges.
Reopen with the same setting: only whole key is used
sanity checks
GROUP 1
Try to create a DB with mixed files:
In this case needs insert some keys to make sure files are
not filtered out by key ranges.
Generate randomly shuffled keys, so the updates are almost
random.
Check filter block ignored for files preloaded during DB::Open()
namespace rocksdb
public testing::WithParamInterface<bool> {
ChangeCompactOptions() only changes compaction style, which does not
trigger reset of table_factory
comment: Lookup present keys. Should rarely read from small sstable.
label: code-design
Part 2 (read path): rewrite last level with blooms, then verify they get
cached only if !optimize_filters_for_hits
Write DB with only full key filtering.
Create with full filter
In the current implementation partitioned filters depend on partitioned
indexes
comment: KeyMayExist function only checks data in block caches, which is not used
by plain table format.
label: code-design
Check db with partitioned full filter
index and data block
prefix will be x????
Block Filter Block
GROUP 0
GROUP 2
Reopen with both of whole key off and prefix extractor enabled.
Still no bloom filter should be used.
namespace
Now we have two files:
File 1: An older file with prefix bloom.
File 2: A newer file with whole bloom filter.
move to level 1
Restart with both filters are allowed
With partitioned filter we read one extra filter per level per each
missed read.
Populate multiple layers
1 Insert 2 K-V pairs into DB
2 Call Get() for both keys - expext memtable bloom hit stat to be 2
3 Call Get() for nonexisting key - expect memtable bloom miss stat to be 1
4 Call Flush() to create SST
5 Call Get() for both keys - expext SST bloom hit stat to be 2
6 Call Get() for nonexisting key - expect SST bloom miss stat to be 1
Test both: block and plain SST
not supported in plain table
end of while
Check SST bloom stats
assert that no new files were opened and no new blocks were
read into block cache.
Was not added to filter but rocksdb will try to read it from the filter
Required if inheriting from testing::WithParamInterface<>
Same scenario as in BloomStatsTest but using an iterator
ROCKSDB_LITE
File 1 will has it filtered out.
File 2 will not, as prefix `foo` exists in the file.
Check db with block_based filter
Reopen with whole key filtering enabled and prefix extractor
NULL. Bloom filter should be off for both of whole key and
prefix bloom.
Without block cache, we read an extra partition filter per each
level*read and a partition index per each read
A wrapped bloom over default FilterPolicy
not in DB
Check db with full filter
setting > -1 makes it not preload all files
Check if filter is useful
comment: KeyMayExist can lead to a few false positives, but not false negatives.
To make test deterministic, use a much larger number of bits per key-20 than
bits in the key, so that false positives are eliminated
label: code-design
Create with block based filter
Add a large key to make the file contain wide range
Check filter block ignored for file trivially-moved to bottom level
No Level 0 file. Create one.
Try to create a DB with mixed files.
check memtable bloom stats
Check filter block not cached for iterator
Seek to a key that was not in Domain
Not in domain, wont be added to filter
check SST bloom stats
Check if they can be found
column family index
disallow trivial move
Generate 11 sst files with the following prefix ranges.
GROUP 0: [0,10] (level 1)
GROUP 1: [1,2], [2,3], [3,4], [4,5], [5, 6] (level 0)
GROUP 2: [0,6], [0,7], [0,8], [0,9], [0,10] (level 0)
A seek with the previous API would do 11 random I/Os (to all the
files). With the new API and a prefix filter enabled, we should
only do 2 random I/O, to the 2 files containing the key.
db configs
Prevent auto compactions triggered by seeks
Now we have three sorted run, L0, L5 and L6 with most files in L6 have
no bloom filter. Most keys be checked bloom filters twice.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
overwrite all the 100K keys once again.
All the files are in the lowest level.
Verify that all but the 100001st record
has sequence number zero. The 100001st record
is at the tip of this snapshot and cannot
be zeroed out.
Put some data.
create a new database with the compaction
filter in such a way that it deletes all keys
Compaction filters should only be applied to records that are newer than the
latest snapshot. However, if the compaction filter asks to ignore snapshots
records newer than the snapshot will also be processed
namespace rocksdb
empty db
push all files to the highest level L2. This
means that all keys should pass at least once
via the compaction filter
write all the keys once again.
push all files to lower levels
Number of skips in tables: 2, 3, 3, 3.
this will produce empty file (delete compaction filter)
Make sure next file is much smaller so automatic compaction will not
be triggered.
Filter out keys with value is 2.
Scan the entire database to ensure that nothing is left
Compaction filter never applies to merge keys.
The filter should delete 10 records.
Write 100K+1 keys, these are written to a few files
in L0. We do this so that the current snapshot points
to the 100001 key.The compaction filter is not invoked
on keys that are visible via a snapshot because we
anyways cannot delete it.
put some data
Delete Filter Factory which ignores snapshots
verify that all keys now have the new value that
was set by the compaction process.
The filter should delete 40 records.
The sequence number of the remaining record
is not zeroed out even though it is at the
level Lmax because this record is at the tip
In the same compaction, both of value type and merge type keys need to be
deleted based on compaction filter, and there is a merge type for the key.
For both keys, compaction filter results are ignored.
ROCKSDB_LITE
Scan the entire database as of the snapshot to ensure
that nothing is left
We have deleted 10 keys from 40 using the compaction filter
Keys 6-9 before the snapshot and 100-105 after the snapshot
This is a static filter used for filtering
kvs during the compaction process.
Key ranges in tables are [0, 38], [106, 149], [212, 260], [318, 371].
re-write all data again
Push all files to the highest level L2. Verify that
the compaction is each level invokes the filter for
all the keys in that level.
In the same compaction, a value type needs to be deleted based on
compaction filter, and there is a merge type for the key. compaction
filter result is ignored.
Force a manual compaction
value key can be deleted based on compaction filter, leaving only
merge keys.
Write 100K keys, these are written to a few files in L0.
Write several keys.
Compaction filters should only be applied to records that are newer than the
latest snapshot. This test inserts records and applies a delete filter.
Skip x if floor(x/10) is even, use range skips. Requires that keys are
zero-padded to length 10.
Push all files to the highest level L2. This
triggers the compaction filter to delete all keys,
verify that at the end of the compaction process,
nothing is left.
snapshots
push all files to lower levels. This should
invoke the compaction filter for all 100000 keys.
Verify total number of keys is correct after manual compaction.
Release the snapshot and compact again -> now all records should be
removed.
Tests the edge case where compaction does not produce any output -- all
entries are deleted. The compaction should create bunch of 'DeleteFile'
entries in VersionEdit, but none of the 'AddFile's.
skipped
must have much smaller db size.
filter out cases for table properties queries.
Wait for compaction to finish
Second non-trivial compaction is triggered
comment: Create two more files for one column family, which triggers speed up
condition, three compactions will be scheduled.
label: code-design
Since data is non-overlapping we expect compaction to initiate
a trivial move
500KB
8 MB
Verify all L0 files are still there.
Multiple files in L0
No files in L1
2 files in L2
b.smallestkey <= a.smallestkey <= b.largestkey
If update stats on DB::Open is disable, we don't expect
deletion entries taking effect.
level1_file.name
(1, 4, 1)
Eventually the cancelled compaction will be rescheduled and executed.
This test triggers move compaction and verifies that the file is not
deleted when it's part of move compaction
github issue #2249
Another 110KB triggers a compaction to 400K file to fill up first path
iter 1 -- delete_obsolete_files_period_micros == 0
Create 1MB sst file
block compactions
Add 2 non-overlapping files
Delete keys in range [1, 4]. These L0 files will be compacted with L1:
- Tombstones for keys 2 and 4 can be dropped early.
- Tombstones for keys 1 and 3 must be kept due to L2 files' key-ranges.
Stage 1: generate a db with level compaction
Reopen the DB with stats-update disabled
level1_files
file 5 [400 => 500)
make sure all key-values are still there.
stop the compaction thread until we simulate the file creation failure.
Stage 2: reopen with universal compaction - should fail
Trivial move the two non-overlapping files to level 6
L0 file meta
this range overlap with the next one
One for compaction input, one for verifying compaction results.
compaction options
Compact all
regression test for issue #2722: L0->L0 compaction can resurrect deleted
keys from older L0 files if L1+ files' key-ranges do not include the key.
Compaction will do L0=>L1 L1=>L2 L2=>L3 (3 trivial moves)
Same ranges as above but overlapping
Create new iterator for:
(1) 1 for verifying flush results
(2) 3 for compaction input files
(3) 1 for verifying compaction results.
First three 110KB files are not going to second path.
After that, (100K, 200K)
disallow trivial move
File moved From L0 to L1
0 files in L0
1 file in L1
Push data from level 0 to level 1 to force all data to be deleted
Note that we don't delete level 0 files
release snap so that first instance of key(3) can have seqId=0
File with keys [ 100 => 199 ]
Trigger a long memtable compaction and reopen the database during it
Goes to 1st log file
Fills memtable
Triggers compaction
Goes to new log file
Compact just the new range
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
create two files in l1 that we can compact
index: 0 1 2 3 4 5 6 7 8 9
size: 1MB 1MB 1MB 1MB 1MB 2MB 1MB 1MB 1MB 1MB
score: 1.5 1.3 1.5 2.0 inf
Files 0-4 will be included in an L0->L1 compaction.
L0->L0 will be triggered since the sync points guarantee compaction to base
level is still blocked when files 5-9 trigger another compaction.
Files 6-9 are the longest span of available files for which
work-per-deleted-file decreases (see "score" row above).
note CompactionOptions::output_file_size_limit is unset.
trigger compaction when we have 2 files
this time we're expecting significant drop in size.
round 3 --- reopen db with auto_compaction on and see if
deletion compensation still work.
1 files in L0
Make sure the number of L0 files can trigger compaction.
Only 1 file in L0
this file should have been compacted away
each value is 10K
The auto compaction is scheduled but waited until here
make l0 files' ranges overlap to avoid trivial move
10 KB
(1, 4, 4)
key 0 serves both to prevent trivial move and as the key we want to
verify is not resurrected by L0->L0 compaction.
the following only disable stats update in DB::Open()
and should not affect the result of this test.
Otherwise, we should see a significant drop in db size.
file 3 [ 0 => 200]
a.smallestkey < b.smallestkey <= a.largestkey
comment: Disable as the test is flaky.
label: test
Verify number of compactions allowed will come back to 1.
Expect compaction to fail here as one file will fail its
creation.
(1, 4, 7)
2 files in L2, 1 in L1
fill up the DB
Compaction will do L0=>L1 L1=>L2 L2=>L3 (3 trivial moves)
then compacte the bottommost level L3=>L3 (non trivial move)
1 MB
lookup iterator from table cache and no need to create a new one.
Compaction will do L0=>L1 (trivial move) then move L1 files to L3
Unblock all threads to unblock all compactions.
move both files down to l1
SYNC_POINT is not supported in released Windows mode.
File with keys [ 0 => 99 ]
this should execute L1->L2 (move)
110KB
Create two 1MB sst files
First non-trivial compaction is triggered
Check level comapction with compact files
Verify again after reopen.
We expect that all the files were trivially moved from L0 to L1
at least L0 and L1
L0 has the 2MB file (not compacted) and 4MB file (output of L0->L0)
Preloading iterator issues one table cache lookup and creates
a new table reader. One file is created for flush and one for compaction.
Compaction inputs make no table cache look-up for data/range deletion
iterators
Create several column families. Make compaction triggers in all of them
and see number of compactions scheduled to be less than allowed.
trigger L0 compaction
Verify level sizes
Infinitely large
second non-trivial compaction
comment: Now all column families qualify compaction but only one should be
scheduled, because no column family hits speed up condition.
label: code-design
Delete archival files.
comment: Currently, the test relies on the number of calls to
InputCompressionMatchesOutput() per compaction.
label: code-design
comment: This tests for a bug that could cause two level0 compactions running
concurrently
TODO(aekmekji): Make sure that the reason this fails when run with
max_subcompactions > 1 is not a correctness issue but just inherent to
running parallel L0-L1 compactions
label: code-design
index: 0 1 2 3 4 5 6 7 8 9
size: 1MB 1MB 1MB 1MB 1MB 1MB 1MB 1MB 1MB 1MB
score: 1.25 1.33 1.5 2.0 inf
Files 0-4 will be included in an L0->L1 compaction.
L0->L0 will be triggered since the sync points guarantee compaction to base
level is still blocked when files 5-9 trigger another compaction. All files
5-9 are included in the L0->L0 due to work-per-deleted file decreasing.
Put a key-value in files 0-4. Delete that key in files 5-9. Verify the
L0->L0 preserves the deletion such that the key remains deleted.
this should execute both L0->L1 and L1->L2 (merge with previous file)
round 1 --- insert key/value pairs.
file 4 [300 => 400)
All the TEST_P tests run once with sub_compactions disabled (i.e.
options.max_subcompactions = 1) and once with it enabled
(1, 4, 3)
create first file and flush to l0
nowait
create second file and flush to l0
file 2 [100 => 300]
iterator is holding the file
create 3 files in l0 so to trigger compaction
Only verifying compaction outputs issues one table cache lookup
for both data block and range deletion block).
!defined(ROCKSDB_LITE)
namespace rocksdb
at least L0 and L1
L0 has a single output file from L0->L0
Compaction range falls after files
put key 1 and 3 in separate L1, L2 files.
So key 0, 2, and 4+ fall outside these levels' key-ranges.
Compaction will initiate a trivial move from L0 to L1
(1, 4, 6)
2 files in L2, 1 in L0
Reopening moves updates to level-0
Compaction will do L0=>L1 L1=>L2 L2=>L3 (3 trivial moves)
and will skip bottommost level compaction
Fail the first file creation.
third pass with universal compaction
non overlapping ranges
let compactions go
Identifies all files between level "min_level" and "max_level"
which has overlapping key range with "input_file_meta".
(1, 4, 2)
All key-values must exist after compaction fails.
Since we do a normal stats update on db-open, there
will be more random open files.
As stats-update is disabled, we expect a very low number of
random file open.
Note that this number must be changed accordingly if we change
the number of files needed to be opened in the DB::Open process.
level1_file.size
Many files 4 [300 => 4300)
prevents trivial move
file 1 [0 => 300]
The auto compaction will wait until the manual compaction is registerd
before processing so that it will be cancelled.
second pass with universal compaction
file 1 [0 => 100]
Large write buffer
put extra key to trigger flush
Make sure RocksDB will not get into corrupted state.
First three 110KB files are going to level 0
After that, (100K, 200K)
Verify manual compaction doesn't fill block cache
This test verify UpdateAccumulatedStats is not on
if options.skip_stats_update_on_db_open = true
The test will need to be updated if the internal behavior changes.
make sure all background compaction jobs can be scheduled
Compaction range falls before files
Stage 4: re-open in universal compaction style and do some db operations
Another 110KB triggers a compaction to 400K file to fill up level 0
Populate a different range
Write 100KB (100 values, each 1K)
Check that writes done during a memtable compaction are recovered
if the database is shutdown during the memtable compaction.
Create two more 1MB sst files
options = CurrentOptions(options);
Block all threads in thread pool.
Verify L0 -> L1 compaction does fail.
Repeat the reopen process, but this time we enable
stats-update.
insert relatively small amount of data to trigger auto compaction.
2 files in L6, 1 file in L5
Make sure all overlapping files do not exist after compaction
comment: Should speed up compaction when there are 4 files.
label: code-design
2 files in L6
2 files in L0
anonymous namespace
200KB
b.smallestkey <= a.largestkey <= b.largestkey
round 2 --- disable auto-compactions and issue deletions.
Before two non-trivial compactions are installed, there are 3 files in L0
(1, 4)
file 2 [600 => 700]
Purpose of dependencies:
4 -> 1: ensure the order of two non-trivial compactions
5 -> 2 and 5 -> 3: ensure we do a check before two non-trivial compactions
are installed
comment: First two levels have no compression, so that a trivial move between
them will be allowed. Level 2 has Zlib compression so that a trivial
move to level 3 will not be allowed
label: code-design
file 6 [500 => 600)
(1, 4, 8)
sentinel to prevent trivial move
a.smallestkey <= b.largestkey < a.largestkey
Required if inheriting from testing::WithParamInterface<>
After two non-trivial compactions are installed, there is 1 file in L6, and
1 file in L1
Write 8MB (80 values, each 100K)
Generate four files in CF 0, which should trigger an auto compaction
verify keys inserted in both level compaction style and universal
compaction style
Try deleting files in range which contain no keys
Always gets compacted into 1 Level1 file,
0/1 Level 0 file
preloading iterator issues one table cache lookup and create
a new table reader.
iter - 0 with 7 levels
iter - 1 with 3 levels
1 file in L0
0 files in L1
100 KB
File with keys [ 200 => 299 ]
Reopening moves updates to L0
Stage 3: compact into a single file and move the file to level 0
this should execute L0->L1
Compaction range overlaps files
(1, 4, 5)
Deletions can be dropped when compacted to non-last level if they fall
outside the lower-level files' key-ranges.
generate one more file in level-0, and should trigger level-0 compaction
as auto_compaction is off, we shouldn't see too much reduce
in db size.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Initial base level is the last level
Base level is not level 1
Test compact range works
namespace rocksdb
Write about 40K more
Verify DB
A manual compaction will trigger the base level to become L2
Keep Writing data until base level changed 2->1. There will be L0->L2
compaction going on at the same time.
Trigger a condition that the compaction changes base level and L0->Lbase
happens at the same time.
We try to make last levels' targets to be 40K, 160K, 640K, add triggers
another compaction from 40K->160K.
Put about 28K to L0
Wait for 200 milliseconds before proceeding compactions to make sure two
parallel ones are executed.
Put about 7K to L0
comment: Use InMemoryEnv, or it would be too slow.
label: code-design
Introduction of SyncPoint effectively disabled building and running this test
in Release build.
which is a pity, it is a good test
Trigger parallel compaction, and the first one would change the base
level.
Hold compaction jobs to make sure
All data should be in the last level.
Issue manual compaction in one thread and still verify DB state
in main thread.
Insert extra about 28K to L0. After they are compacted to L4, base level
should be changed to L3.
Test specific cases in dynamic max bytes
comment: Without it, valgrind may choose not to give another
thread a chance to run before finishing the function,
causing the test to be extremely slow.
label: code-design
Base level is still level 3.
!defined(ROCKSDB_LITE)
Write about 650K more.
Each file is about 11KB, with 9KB of data.
Make sure level 0 is not empty
Force not expanding in compactions
Compact against empty DB
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
std::cout << "Hit in " << filePath << "\n";
ROCKSDB_LITE
Open all files and look for the values we've put in there.
They should not be found if encrypted, otherwise
they should be found.
namespace rocksdb
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Verify setting an empty high-pri (flush) thread pool causes flushes to be
scheduled in the low-pri (compaction) thread pool.
ROCKSDB_LITE
flush failed.
ROCKSDB_LITE
Flush job should release ref count to current version.
If the issue is hit we will wait here forever.
We had issue when two background threads trying to flush at the same time,
only one of them get committed. The test verifies the issue is fixed.
No inplace updates. All updates are puts with new seq number
All 10 updates exist in the internal iterator
Update key with values of smaller size
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Callback function requests no actions from db
Only 1 instance for that key.
Update key with values of smaller varint size
All 10 updates exist in the internal iterator
Update key with values of larger size
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Check that compaction attempts slept after errors
TODO @krad: Figure out why ASSERT_EQ 5 keeps failing in certain compiler
versions
Test the following:
(a) A random put fails in paranoid mode (simulate by sync fail)
(b) All other puts have to fail, even if writes would succeed
(c) All of that should happen ONLY if paranoid_checks = true
Check background error counter bumped on flush failures.
Try again with paranoid_checks=false
the next put should NOT fail
Check that CompactRange() returns failure if there is not enough space left
on device
Merging compaction (will fail)
but we're still able to read
Memtable compaction (will succeed)
simulate error
!(defined NDEBUG) || !defined(OS_WIN)
ROCKSDB_LITE
namespace rocksdb
Recovery: should not lose data
do the same thing with paranoid checks off
Check that number of files does not grow when writes are dropped
We iterate twice. In the second iteration, everything is the
same except the log record never makes it to the MANIFEST file.
Since paranoid_checks=true, writes should fail
Should fail
the next put should fail, too
ROCKSDB_LITE
First 1MB doesn't get range synced
Following writes should fail as compaction failed.
Insert foo=>bar mapping
Test for the following problem:
(a) Compaction produces file F
(b) Log record containing F is written to MANIFEST file, but Sync() fails
(c) GC deletes F
(d) After reopening DB, reads fail since deleted F is named in log record
foo=>bar is now in last level
Background error count is 0 now.
generate 5 tables
Force out-of-space errors
disallow trivial move
Following writes should fail as flush failed.
Since paranoid_checks=false, writes should succeed
Test to make sure that the request will *not* fail as incomplete if
num_internal_keys_skipped is *equal* to max_skippable_internal_keys
threshold. (It will fail as incomplete only when the threshold is
exceeded.)
Test call back inserts two keys before "z" in mem table after
MergeIterator::Prev() calls mem table iterator's Seek() and
before calling Prev()
Test that the num_internal_keys_skipped counter resets after a successful
read.
Test to check the SeekToLast() with iterate_upper_bound set to the
first key
Test for large number of skippable internal keys with a *non-default*
max_sequential_skip_in_iterations.
Test to check the SeekToLast() with the iterate_upper_bound set to the
key that is deleted
namespace rocksdb
Test to check the SeekToLast() with iterate_upper_bound set
(Deletion cases - Lot of internal keys after the upper_bound
is deleted)
Test call back inserts entries for update a key in the end of the
mem table after MergeIterator::Prev() realized the mem tableiterator is at
its end and before an SeekToLast() is called.
num_internal_keys_skipped counter resets here.
comment: TODO(3.13): fix the issue of Seek() then Prev() which might not necessary
return the biggest element smaller than the seek key.
label: code-design
Test call back inserts entries for update a key in the end of the
mem table after MergeIterator::Prev() realized the mem table iterator is at
its end and before an SeekToLast() is called.
Test if alternating puts and deletes of the same key are handled correctly.
put, singledelete, merge
comment: Test Prev() when one child iterator is at its end but more rows
are added.
label: code-design
Test that skipping separate keys is handled
Test case to check SeekToLast with iterate_upper_bound set
(same key put may times - SeekToLast should start with the
maximum sequence id of the upper bound)
data_[iter_] is not anymore the current element of the iterator.
Increment it to reposition it to the right position.
Test for large number of skippable internal keys with *default*
max_sequential_skip_in_iterations.
Fail the request as incomplete when num_internal_keys_skipped >
max_skippable_internal_keys
Test call back inserts entries for update a key before "z" in
mem table after MergeIterator::Prev() calls mem table iterator's
Seek() and before calling Prev()
force seek
internal_iter1_: a, f, g
internal_iter2_: a, b, c, d, adding (z)
should be called before operations with iterator
Test call back inserts an entry for update a key before "z" in
mem table after MergeIterator::Prev() calls mem table iterator's
Seek() and before calling Prev()
insert a key smaller than current key
Test Prev() when one child iterator is at its end.
Test call back inserts a key in the end of the mem table after
MergeIterator::Prev() realized the mem table iterator is at its end
and before an SeekToLast() is called.
Test to check the SeekToLast() with iterate_upper_bound set
Test to check the SeekToLast() with iterate_upper_bound not set
Basic test case ... Make sure explicityly passing the default value works.
Skipping internal keys is disabled by default, when the value is 0.
Test Prev() when one child iterator is at its end but more rows
are added and max_skipped is triggered.
read data earlier than seqId 8
Test Prev() when one child iterator has more rows inserted
between Seek() and Prev() when changing directions.
Test that the num_internal_keys_skipped counter resets after a successful
read.
Reverse direction
Test to check the SeekToLast() with the iterate_upper_bound set
(Deletion cases)
Test to check the SeekToLast() iterate_upper_bound set to a key that
is not Put yet
Test to check the SeekToLast() with the iterate_upper_bound set
(Checking the value of the key which has sequence ids greater than
and less that the iterator's sequence id)
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
max iterators before reseek
Separate values and merge operands in different file so that we
make sure that we dont merge them while flushing but actually
merge them in the read path
Testing reverse iterator
At this point, we have three versions of "a" and one version of "b".
The reseek statistics is already at 1.
Check that iterator did something like what we expect.
Restore original position using Prev()
Putting such deletes will force DBIter::Prev() to fallback to a Seek
Insert a lot.
comment: Check that the seek didn't do too much work.
Checks are not tight, just make sure that everything is well below 100.
label: code-design
+2 all keys divisible by 2 in range [ 0 => 999]
doesn't support SeekToLast
Generate Random data
Create a key that needs to be skipped for Seq too new
base case with no bound
comment: This test verifies block cache behaviors, which is not used by plain
table format.
Exclude kHashCuckoo as it does not support iteration currently
label: code-design
comment: TODO(gzh): merge operator does not support backward iteration yet
label: code-design
ROCKSDB_LITE
Verify that all keys slices are valid (backward)
Create iterator.
100K values
Generate 4 sst files in L2
Dont give merge operations for some keys
10 Mb
+3 all keys divisible by 5 in range [ 0 => 999]
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
+1 all keys in range [ 0 => 999]
20% of keys will be used to test seek()
20% of keys will be deleted
20% of keys will be added using Merge()
skip as HashCuckooRep does not support snapshot
Restore orignal position using Seek()
read in the specified block via a regular get
testing that iterate_upper_bound prevents iterating over deleted items
if the bound has already reached
namespace
iterate_upper_bound points beyond the last expected entry
Check that memtable wasn't flushed.
Small number of merge operands to make sure that DBIter::Prev() dont
fall back to Seek()
The test needs to be changed if kPersistedTier is supported in iterator.
Write to force compactions
Percentage of keys that wont get merge operations
Testing SeekToLast with iterate_upper_bound set
Insert another version of b and assert that reseek is not invoked
insert a total of three keys with same userkey and verify
that reseek is still not invoked.
the iteration should stop as soon as the bound key is reached
even though the key is deleted
hence internal_delete_skipped_count should be 0
Put more values after the snapshot
Key 10 bytes / Value 10 bytes
Seek will bump ITER_BYTES_READ
Verify that all keys slices are valid
the previous Prev call should have invoked reseek
For half of the key range we will write multiple deletes first to
force DBIter::Prev() to fall back to Seek()
insert three keys with same userkey and verify that
reseek is not invoked. For each of these test cases,
verify that we can find the next key "b".
Pick random keys to be used to test Seek()
scan using non-blocking iterator. We should find it because
it is in memtable.
Generate 4 sst files in L0
Test SeekForPrev to random keys
Add some keys/values in memtables
Delete 50% of the keys and update the other 50%
namespace rocksdb
comment: TODO: merge operator does not support backward iteration yet
label: code-design
testing iterate_upper_bound and forward iterator
to make sure it stops at bound
Percentage of keys that will be deleted
Test Seek to random keys
should stop here...
First File containing 5 blocks of puts
verify that we can find it via a non-blocking scan
!ROCKSDB_LITE
Use value size that will make sure that every block contain 1 key
Insert a key, create a snapshot iterator, overwrite key lots of times,
seek to a smaller key. Expect DBIter to fall back to a seek instead of
going through all the overwrites linearly.
Check that we can skip over a run of user keys
by using reseek rather than sequential scan
Verify key/value of current position
Switch from forward to reverse
Get iterator that will yield the current contents of the DB.
Delete some random keys
big enough to avoid flush
Second file containing 9 blocks of merge operands
Verify correctness.
write one kv to the database.
Enable prefix bloom for SST files
Switch from reverse to forward
write three entries with different keys using Merge()
testing basic case with no iterate_upper_bound and no prefix_extractor
prefix is the first letter of the key
verify that a non-blocking iterator does not find any
kvs. Neither does it do any IOs to storage.
Do some Next() operations the restore the iterator to orignal position
Insert.
comment: TODO(3.13): fix the issue of Seek() + Prev() which might not necessary
return the biggest key which is smaller than the seek key.
label: code-design
Make sure iter stays at snapshot
every block will contain one entry
Test iterating all data forward
insert two more versions of b. This makes a total of 4 versions
of b and 4 versions of a.
now testing with iterate_bound
Seek iterator to a smaller key.
testing with iterate_upper_bound and prefix_extractor
Seek target and iterate_upper_bound are not is same prefix
This should be an error
Insert data to true_data map and to DB
Test iterating all data backward
insert a total of four keys with same userkey and verify
that reseek is invoked.
flush memtable to storage. Now, the key should not be in the
memtable neither in the block cache.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Setup sync point dependency to reproduce the race condition of
a log file moved to archived dir, in the middle of GetSortedWalFiles
sync point is not included with DNDEBUG build
Corrupt this log to create a gap
this iter would miss "key4" if not fixed
Introduction of SyncPoint effectively disabled building and running this test
in Release build.
which is a pity, it is a good test
"key5" would be written in a new memtable and log
Insert a new entry to a new log file
trigger async flush, and log move. Well, log move will
wait until the GetSortedWalFiles:1 to reproduce the race
condition
namespace
Try to read past the gap, should be able to seek to key1025
!defined(ROCKSDB_LITE)
namespace rocksdb
Try to read from the beginning. Should stop before the gap and read less
than 1025 entries
Verifies MemTableRepFactory is told the right column family id.
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
comment: workaround since there's no port::kMaxUint32 yet.
label: code-design
10% value
10% overwrite
10% delete
Skip HashCuckoo since it does not support merge operators
namespace rocksdb
Code executed before merge operation
Overwrite random kNumPutAfter keys
Do kTotalMerges merges
Decrease cache capacity to force all unrefed blocks to be evicted
Filse to write in L0 before compacting to lower level
kNumPutBefore keys will have base values
Keep last batch in memtable and stop
Every key gets ~10 operands
Evict all tables from cache before every merge operation
Will trigger a merge when hitting max_successive_merges and the merge
will fail. The delta will be inserted nevertheless.
ROCKSDB_LITE
3 L0 files
1 L1 file
3 L2 files
1 L3 file
3 L4 Files
Increase capacity again after doing the merge
Code executed after merge operation
every block will contain one entry
wait for the key to be written
Data should stay unmerged after the error.
Delete random kNumDelete keys
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test merge operator functionality.
1000 keys every key have 30 operands, every operand is in a different file
comment: After delete_obsolete_files_period_micros updated to 0, the next call
to FindObsoleteFiles should make a full scan
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Verify if DB can be reopen after setting options.
RocksDB lite don't support dynamic options.
test with level0_stop_writes_trigger
ROCKSDB_LITE
Background compaction executed.
Need to insert two keys to avoid trivial move.
default value
examine the table cache (actual size should be 1014)
Wait for stall condition recalculate.
Block background compaction.
GetOptions should be able to get latest option changed by SetOptions.
Verify that candidate files set is empty when no full scan requested.
namespace rocksdb
Phase 1. Simply issue Put() and expect "cur-size-all-mem-tables" equals to
"size-all-mem-tables"
small write buffer
compression ratio is -1.0 when no open files at level
Restart the DB. Although number of files didn't reach
options.level0_file_num_compaction_trigger, compaction should
still be triggered because of the need-compaction hint.
After reopening, no table reader is loaded, so no memory for table readers
"192" is the size of the metadata of two empty skiplists, this would
break if we change the default skiplist implementation
Trigger automatic compactions.
Small write buffer
This ensures there no compaction happening when we call GetProperty().
Clear internal stats
Trigger compaction
Block sync calls
In the second round, add iterators.
Come back to write to default column family
Close before mock_env destructs.
Set sizes to both background thread pool to be 1 and block them.
ROCKSDB_LITE
namespace rocksdb
Verify the same set of properties through GetIntProperty
anonymous namespace
Reopen and issue iterating. See thee latency tracked
Fill memtable
Put common data ("key") at end to prevent delta encoding from
compressing the key effectively
no compression at L0, so ratio is less than one
comment: TODO(techdept) : Disabled flaky test #12863555
label: test
Reopen and issue Get(). See thee latency tracked
Phase 5. Reopen, and expect all these three counters to be the same again.
comment: TODO(noetzli) kFlushesPerRound does not really correlate with how many
flushes happen.
label: code-design
Use an iterator to hold current version
Test rocksdb.num-live-versions
comment: Data at L1 should be highly compressed thanks to Snappy and redundant data
in values (ratio is 12.846 as of 4/19/2016).
label: code-design
Make sure that there is no flush between getting the two properties.
comment: Issue flush and expect larger memory usage of table readers.
label: code-design
Phase 3. Delete iterators and expect "size-all-mem-tables" shrinks
whenever we release an iterator.
Gives larger bias here as index block size, filter block size,
and data block size become much harder to estimate in this test.
Expect all these three counters to be the same.
ROCKSDB_LITE
"rocksdb.estimate-oldest-key-time" only available to fifo compaction.
default CF
Create 4 tables in default column family
Phase 0. The verify the initial value of all these properties are the same
as we have no mem-tables.
After reading a key, at least one table reader is loaded.
CF 1 should show no histogram.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
If C++ gets a std::string_literal, this would be better to check at
compile-time using static_assert.
We iterate every key twice. Is it a bug?
Expect the size shrinking
put something and read it back , CF 1 should show histogram.
Force flush to prevent flush from happening between getting the
properties or after getting the properties and before the new round.
Phase 2. Keep issuing Put() but also create new iterators. This time we
expect "size-all-mem-tables" > "cur-size-all-mem-tables".
Get() after flushes, See latency histogram tracked.
Create 4 tables
Wait for compaction to be done. This is important because otherwise RocksDB
might schedule a compaction when reopening the database, failing assertion
(A) as a result.
Create 2 files
Release sync calls
Make them never flush
When "max_open_files" is -1, we read all the files for
"rocksdb.estimate-num-keys" computation, which is the ground truth.
Otherwise, we sample 20 newest files to make an estimation.
Formula: lastest_20_files_active_key_ratio * total_files
in no iterator case, these two number should be the same.
(A)
Clear Level 0 so that when later flush a file with deletions,
we don't trigger an organic compaction.
options.max_open_files preloads table readers.
Write 100KB (100 values, each 1K)
When i == 1, compaction will output some files to L1, at which point
L1 is not bottommost so range deletions cannot be compacted away. The
new L1 files must be generated with non-overlapping key ranges even
though multiple subcompactions see the same ranges deleted, else an
assertion will fail.
Only enable auto-compactions when we're ready; otherwise, the
oversized L0 (relative to base_level) causes the compaction to run
earlier.
Write 1MB (256 values, each 4K)
Regression test for bug where sentinel range deletions (i.e., ones with
sequence number of zero) were included in output files.
snapshot protects range tombstone from dropping due to becoming obsolete.
input_level
During compaction to bottommost level, verify range tombstones older than
the oldest snapshot are removed, while others are preserved.
we need to prevent trivial move using Puts so compaction will actually
process the merge operands.
Make sure a given key appears in each file so compaction won't be able to
use trivial move, which would happen if the ranges were non-overlapping.
Also, we need an extra element since flush is only triggered when the
number of keys is one greater than SpecialSkipListFactory's limit.
We choose a key outside the key-range used by the test to avoid conflict.
put enough keys to fill up the first subcompaction, and later range-delete
them so that the first subcompaction outputs no key-values. In that case
it'll consider making an SST file dedicated to range deletions.
background compaction may happen early for kFilesPerLevel'th file
Delete merge operands from all but the last file
Write half of the keys before the tombstone and half after the tombstone.
Only covered keys (i.e., within the range and older than the tombstone)
should be deleted.
give files overlapping key-ranges to prevent trivial move
This puts table caches in the state of being externally referenced only
so they are destroyed immediately upon iterator unreferencing.
regression test for exactly filled compaction output files. Previously
another file would be generated containing all range deletions, which
could invalidate the non-overlapping file boundary invariant.
Want max_compaction_bytes to trigger the end of compaction output file, not
target_file_size_base, so make the latter much bigger
disallow_trivial_move
range tombstone covers first half of the previous file
0+1+2+...+9
PlainTableFactory and NumTableFilesAtLevel() are not supported in
ROCKSDB_LITE
namespace rocksdb
output_level
snapshot prevents key from being deleted during flush
Now L1-L3 are full, when we compact L1->L2 we should see (1) subcompactions
happen since input level > 0; (2) range deletions are not dropped since
output level is not bottommost. If no file boundary assertion fails, that
probably means universal compaction + subcompaction + range deletion are
compatible.
the above range tombstone can be dropped, so that one alone won't cause a
dedicated file to be opened. We can make one protected by snapshot that
must be considered. Make its range outside the first subcompaction's range
to exercise the tricky part of the code.
delete [95,105) in two files, [295,305) in next two
end
Regression test for #2752. Range delete tombstones between
different snapshot stripes are not stored in order, so the first
tombstone of each snapshot stripe should be checked as a smallest
candidate.
The RangeDelAggregator holds pointers into range deletion blocks created by
table readers. This test ensures the aggregator can still access those
blocks even if it outlives the table readers that created them.
DBIter always keeps readers open for L0 files. So, in order to test
aggregator outliving reader, we need to have deletions in L1 files, which
are opened/closed on-demand during the scan. This is accomplished by
setting kNumRanges > level0_stop_writes_trigger, which prevents deletions
from all lingering in L0 (there is at most one range deletion per L0 file).
The first L1 file will contain a range deletion since its begin key is 0.
SeekToFirst() references that table's reader and adds its range tombstone
to the aggregator. Upon advancing beyond that table's key-range via Next(),
the table reader will be unreferenced by the iterator. Since we manually
call Evict() on all readers before the full scan, this unreference causes
the reader's refcount to drop to zero and thus be destroyed.
When it is destroyed, we do not remove its range deletions from the
aggregator. So, subsequent calls to Next() must be able to use these
deletions to decide whether a key is covered. This will work as long as
the aggregator properly references the range deletion block.
6+7+8+9
make sure compaction treats files containing a split range deletion in the
input level as an atomic unit. I.e., compacting any input-level file(s)
containing a portion of the range deletion causes all other input-level
files containing portions of that same range deletion to be included in the
compaction.
Ensures range deletion spanning multiple compaction output files that are
cut by max_compaction_bytes will have non-overlapping key-ranges.
https://github.com/facebook/rocksdb/issues/1778
6+7+8+9 (earlier operands covered by tombstone)
snapshot protects range tombstone from dropping due to becoming obsolete.
insert range deletions [95,105) in two files, [295,305) in next two
to prepare L1 for later manual compaction.
Must be > 1 so the first L1 file can be closed before scan finishes
exclusive
1+2+...+9
first iteration verifies query correctness in memtable, second verifies
query correctness for a single SST file
background compaction may happen early for kNumFiles'th file
num_entries_flush
ROCKSDB_LITE
each block holds two keys
For L1+, iterators over files are created on-demand, so need seek
!ROCKSDB_UBSAN_RUN
put extra key to trigger final flush
It spans the whole key-range, thus will be included in all output files
Hold a snapshot to separate these two delete ranges.
i == 0: CompactFiles
i == 1: CompactRange
i == 2: automatic compaction
Write 12K (4 values, each 3K)
iterations check unsupported in memtable, l0, and then l1
prevents empty after compaction
deletes [0, 5]
obsolete after compaction
gaps between ranges creates sentinels in our internal representation
regression test for #2743. the range delete tombstones in memtable should
be added even when Get() skips searching due to its prefix bloom filter
1MB
8KB
Write a third before snapshot, a third between snapshot and tombstone, and
a third after the tombstone. Keys older than snapshot or newer than the
tombstone should be preserved.
need a L1 file for subcompaction to be triggered
put extra key to trigger flush
Hold a snapshot so range deletions can't become obsolete during compaction
to bottommost level (i.e., L1).
SpecialSkipListFactory lets us specify maximum number of elements the
memtable can hold. It switches the active memtable to immutable (flush is
prevented by the above options) upon inserting an element that would
overflow the memtable.
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
begin
NumTableFilesAtLevel() is not supported in ROCKSDB_LITE
protected by snapshot
output_path_id
Iterates kNumFiles * kNumPerFile + 1 times since flushing the last file
requires an extra entry.
Keep clearing block cache's LRU so range deletion block can be freed as
soon as its refcount drops to zero.
Put a snapshot before the range tombstone, verify an iterator using that
snapshot sees all inserted keys.
extra entry to trigger SpecialSkipListFactory's flush
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
If pending output guard does not work correctly, PurgeObsoleteFiles() will
delete the file that Compaction is trying to create, causing this: error
db/db_test.cc:975: IO error:
/tmp/rocksdbtest-1552237650/db_test/000009.sst: No such file or directory
Randomly sleep shortly
This flush will cause bg_error_ and will fail
used in the main loop assert
Live SST files = 0
Total SST files = 0
Compaction will do trivial move from L0 to L1
Close DB and destroy it using DeleteScheduler
Verify the total files size
Hold BackgroundEmptyTrash
Live SST files = 0
Total SST files = 5 (used in 2 version)
clear error to ensure compaction callback is called
Compaction will delete files from L0 in first db path and generate a new
file in L1 in second db path
trigger compaction when we have 2 files
If the moved file is actually deleted (the move-safeguard in
~Version::Version() is not there), we get this failure:
Corruption: Can't access /000009.sst
namespace rocksdb
1 Create some SST files by inserting K-V pairs into DB
2 Close DB and change suffix from ".sst" to ".ldb" for every other SST file
3 Open DB and check if all key can be read
comment: File just flushed is too big for L0 and L1 so gets moved to L2.
label: code-design
Create a DB with 2 db_paths, and generate multiple files in the 2
db_paths using CompactRangeOptions, make sure that files that were
deleted from first db_path were deleted using DeleteScheduler and
files in the second path were not.
This file should have been deleted during last compaction
We have deleted the 4 sst files in the delete_scheduler
this should execute both L0->L1 and L1->(move)->L2 compactions
Generate 5 files in L0
This test triggers move compaction and verifies that the file is not
deleted when it's part of move compaction
finish the flush!
Live SST files = 5
Total SST files = 5
No files were moved
Open DB with infinite max open files
- First iteration use 1 thread to open files
- Second iteration use 5 threads to open files
2 MB
1 MB
Compaction will move the 4 files in L0 to trash and create 1 L1 file
Close db before mock_env destruct.
Set wait until time to before current to force not to sleep.
Generate a file containing 100 keys.
Check the estimated db size vs the db limit just to make sure we
dont run into an infinite loop
~60 bytes per key
Verify that we are tracking all sst files in dbname_
Reopening the DB will load all existing files
low limit for size calculated using sst files
1 MB
Turn timed wait into a simulated sleep
hold current version
Live SST files = 1 (compacted file)
Total SST files = 6 (5 original files + compacted file)
Delete all keys and compact, this will delete all live files
block the flush
Compact 5 files into 1 file in L0
Live SST files = 0
Total SST files = 1 (compacted file)
ROCKSDB_LITE
Set the maximum allowed space usage to the current total size
This reproduces a bug where we don't delete a file because when it was
supposed to be deleted, it was blocked by pending_outputs
Consider:
1. current file_number is 13
2. compaction (1) starts, blocks deletion of all files starting with 13
(pending outputs)
3. file 13 is created by compaction (2)
4. file 13 is consumed by compaction (3) and file 15 was created. Since file
13 has no references, it is put into VersionSet::obsolete_files_
5. FindObsoleteFiles() gets file 13 from VersionSet::obsolete_files_. File 13
is deleted from obsolete_files_ set.
6. PurgeObsoleteFiles() tries to delete file 13, but this file is blocked by
pending outputs since compaction (1) is still running. It is not deleted and
it is not present in obsolete_files_ anymore. Therefore, we never delete it.
Create 4 files in L0
comment: We don't propagate oldest-key-time table property on compaction and
just write 0 as default value. This affect the exact table size, since
we encode table properties as varint64. Force time to be 0 to work around
it. Should remove the workaround after we propagate the property on
compaction.
label: code-design
Live SST files = 0
Total SST files = 6 (5 original files + compacted file)
Every time we write to a table file, call FOF/POF with full DB scan. This
will make sure our pending_outputs_ protection work correctly
110KB
Verify that we track all the files again after the DB is closed and opened
Create two 1MB sst files
512 Kb
Insert 2.5MB data, which should trigger a flush because we exceed
write_buffer_size. The flush will be blocked with block_first_time
pending_file is protecting all the files created after
Create 12 Files in L0 (then move then to L2)
Create 12 Files in L0
1 Mb / Sec
force
Live SST files = 5
Total SST files = 5 (used in 2 version)
10 Kbs / Sec
We created 4 sst files in L0
We flushed at least 25 files
This test will set a maximum allowed space for the DB, then it will
keep filling the DB until the limit is reached and bg_error_ is set.
When bg_error_ is set we will verify that the DB size is greater
than the limit.
disallow trivial move
Create 1MB sst file
Compaction must have deleted some files
Check that compressions occur and are counted when compression is turned on
Check that compressions do not occur when turned off
pick arbitrary ticker and histogram. On first iteration they're zero
because db is unused. On second iteration they're zero due to Reset().
The Put() makes some of the ticker/histogram stats nonzero until we
Reset().
compressible string
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Query the largest range
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
build a decent LSM
fetch key from 1st and 2nd table, which will internally place that table to
the table cache.
namespace rocksdb
run the query
Indirect test
Make sure that we've received properties for those and for those files
only which fall within requested ranges
Random returns numbers with zero included
when we pass empty ranges TestGetPropertiesOfTablesInRange()
derefs random memory in the empty ranges[0]
so want to be greater than zero and even since
the below loop requires that random_keys.size() to be even.
namespace
2. Put two tables to table cache and
Query the empty range
ROCKSDB_LITE
A helper function that ensures the table properties returned in
`GetPropertiesOfAllTablesTest` is correct.
This test assumes entries size is different for each of the tables.
Since we deref zero element in the vector it can not be empty
otherwise we pass an address to some random memory
Create one table per CF, then verify it was created with the column family
name property.
Query the middle rangee
smallestkey < limit && largestkey >= start
1. Read table properties directly from file
create a bunch of ranges
Create 4 tables
Ensure that we have at least L0, L1 and L2
3. Put all tables to table cache
Query a bunch of random ranges
Fixed random sead
flush all those keys to an immutable SST file
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
force a flush to make sure that no records are read from memtable
skip "0test"
Now seek to the same key. The iterator should remain in the same
position.
should still be true after compaction
namespace rocksdb
Write rows with keys 00000, 00002, 00004 etc.
This keeps track of the number of times NeedToSeekImmutable() was true.
Sets iterate_upper_bound and verifies that ForwardIterator doesn't call
Seek() on immutable iterators when target key is >= prev_key and all
iterators, including the memtable iterator, are over the upper bound.
Not valid since "21" is over the upper bound.
Introduction of SyncPoint effectively disabled building and running this test
in Release build.
which is a pity, it is a good test
Seek(0102) shouldn't find any records since 0202 has a different prefix
1st L0 file
2nd L0 file
write a single record, read it using the iterator, then delete it
!defined(ROCKSDB_LITE)
make sure we can read all new records using the existing iterator
we either see the entry or it's not in cache
Seek to 13. This should not require any immutable seeks.
Seek to 00001. We expect to find 00002.
write many more records
add a record and check that iter can see it
level 1: [20, 25] [35, 40]
level 2: [10 - 15] [45 - 50]
level 3: [20, 30, 40]
Previously there is a bug in tailing_iterator that if there is a gap in
lower level, the key will be skipped if it is within the range between
the largest key of index n file and the smallest key of index n+1 file
if both file fit in that gap. In this example, 25 < key < 35
https://github.com/facebook/rocksdb/issues/1372
Add another key to the memtable.
Entry is already in cache, lookup will remove the element from lru
Small write buffer
ignore merge for now
(*map_)[key.ToString()] = value.ToString();
3GB value
8MB key
Test for check of prefix_extractor when hash index is used for
block-based table
Produce two L0 files with overlapping ranges.
compact it three times
comment: Test max_bytes_for_level_multiplier and
max_bytes_for_level_base. Now, reduce both mulitplier and level base,
After filling enough data that can fit in L1 - L3, we should see L1 size
reduces to 128KB from 256KB which was asserted previously. Same for L2.
label: code-design
Trigger reseek
Start threads
put some data
find the new manifest file. assert that this manifest file is
the same one as in the previous snapshot. But its size should be
larger because we added an extra key after taking the
previous shapshot.
Generating 360KB in Level 2
our clients require that GetLiveFiles returns
files with "/" as first character!
Unblock background threads
Do a memtable compaction. Before bug-fix, the compaction would
not detect the overlap with level-0 files and would incorrectly place
the deletion in a deeper level.
If thread tracking is not enabled, compaction count should be 0.
2nd round: flush and put a new value in memtable.
Within (0.5, 1.5) of 4MB.
Check if deletion worked.
the second half of the test involves in random failure
of file creation.
Release sync calls
Create 1 more file to trigger TTL compaction. The old files are dropped.
Block background threads
skip as HashCuckooRep does not support snapshot
Now there is a file in L1.
Only allow one compactin going through.
table with xxhash checksum
Fill levels 1 and 2 to disable the pushing of new memtables to levels >
0.
only 5 files should survive
Initialize state
skip cuckoo hash as it does not support snapshot.
ROCKSDB_USING_THREAD_STATUS
iter == 0 -- leveled
iter == 1 -- leveled, but throw in a flush between two levels compacting
iter == 2 -- universal
We need the 2nd write to trigger delay. This is because delay is
estimated based on the last write size which is 0 for the first write.
Now there is one L1 file (around 90KB) which exceeds 50KB base by 40KB
L2 size is 360KB, so the estimated level fanout 4, estimated pending
compaction is around 200KB
triggerring soft_pending_compaction_bytes_limit
TEST_FlushMemTable() is not supported in ROCKSDB_LITE
Block compaction again
Delete archival files.
Create 3 L0 files, making score of L0 to be 3.
Start with 200MB/s
Check that the writer thread counter is >= the counter in the value
Compaction range falls after files
Github issue #595
Large write batch with column families
Check that there are no extra characters.
20K
1.5MB
Stop the threads and wait for them to finish
comment:
* This test is not reliable enough as it heavily depends on disk behavior.
* Disable as it is flaky.
label: test
only the non-default column family has non-matching comparator
Check sizes across recovery by reopening a few times
Compact more often
each column family will have 5 thread, each thread generating 2 memtables.
each column family should end up with 10 table files
Now there is one L1 file (around 60KB) which exceeds 50KB base by 10KB
Given level multiplier 10, estimated pending compaction is around 100KB
doesn't trigger soft_pending_compaction_bytes_limit
copy these files to a new snapshot directory
Record the number of compactions at a time.
Put
Block sync calls
comment: ApproximateOffsetOf() is not yet implemented in plain table format.
label: requirement
comment: Test level0_stop_writes_trigger.
Clean up memtable and L0. Block compaction threads. If continue to write
and flush memtables. We should see put stop after 8 memtable flushes
since level0_stop_writes_trigger = 8
label: code-design
once the data has been flushed, we are able to get the
data when kPersistedTier is used.
now it's done
returns false if the calling-Test should be skipped
(Single) delete hidden by a put
Compaction related options
Compact away the placeholder files we created initially
Test with TTL + Intra-L0 compactions.
Fill one mem table
inf
Required if inheriting from testing::WithParamInterface<>
Each file contains a different key which will be dropped later.
Skip HashCuckooRep as it does not support single delete. FIFO and
universal compaction do not apply to the test case. Skip MergePut
because merges cannot be combined with single deletions.
Insert 400KB. Some data will be compressed
iter - 0 with 7 levels
iter - 1 with 3 levels
comment: After base level turn L4->L3, L3 becomes LZ4 and L4 becomes Zlib
label: code-design
Test report_bg_io_stats
Test disable_auto_compactions
Compaction thread is unblocked but auto compaction is disabled. Write
4 L0 files and compaction should be triggered. If auto compaction is
disabled, then TEST_WaitForCompact will be waiting for nothing. Number of
L0 files do not change after the call.
generate one more file in level-0, and should trigger level-0 compaction
comment: Short sometimes to encourage collisions
label: code-design
10KB
Decrease buffer size below current usage
Test compression
sanity check
500KB
Block flush thread and disable compaction thread
# rate limiting with 0.7 x threshold
1 hour
These writes will be slowed down to 1KB/s
writing 96 x 64KB => 6 * 1024KB
(L1 + L2) = (1 + 4) * 1024KB
1st round: put but not flush
After PinnableSlice destruction element is added back in LRU
The first sync point is to make sure there's one flush job
running when we perform VerifyOperationCount().
2MB
2MB
Test max_write_buffer_number
Block compaction thread, which will also block the flushes because
max_background_flushes == 0, so flushes are getting executed by the
compaction thread
Only the new 10 files remain.
Promote L0 level to L2.
Insert 5 tasks to low priority queue and 5 tasks to high priority queue
Check DB is not in read-only state.
Destroy previous versions if they exist. Using the long way.
Compact just the new range
Slow down twice. One for memtable switch and one for flush finishes.
Skip HashCuckooRep as it does not support single delete. FIFO and
universal compaction do not apply to the test case. Skip MergePut
because single delete does not get removed when it encounters a merge.
Multiget
The Put Phase.
Skip HashCuckooRep as it does not support single delete. FIFO and
universal compaction do not apply to the test case. Skip MergePut
because single delete does not get removed when it encounters a merge.
Generate and flush a file about 20KB.
Step 4: Wait for compaction to finish
repeat the test with differet number of high / low priority threads
Multi-element batch
Increase
Create 10 more files. The old 5 files are dropped as their ttl expired.
namespace
Delete databases
Make rocksdb busy
Try up to 60 seconds.
Block compaction
Place a table at level last-1 to prevent merging with preceding mutation
Don't trigger compact/slowdown/stop
110KB
release file snapshot
Occasionally sleep a while
Github issue #596
For DB instances that use the hash index + block-based table, the
iterator will be invalid right when seeking a non-existent key, right
than return a key that is close to it.
look at the new live files after we added an 'extra' key
and after we took the first snapshot.
Let them run for a while
Generating 360KB in Level 3
1MB
4MB
the oldest wal should now be getting_flushed
100KB
Multi-threaded test:
With Intra-L0 compaction, out of 10 files, 6 files will be compacted to 1
(due to level0_file_num_compaction_trigger = 6).
So total files = 1 + remaining 4 = 5.
only 2 memtables will be alive, so logs_to_free needs to always be below
2
comment: TODO(yhchiang): adding assert to verify each compaction stage.
label: test
Reopen it without prefix extractor, make sure everything still works.
RocksDB should just fall back to the binary index.
first iteration -- auto compaction
second iteration -- manual compaction
Test that shows the fall back to size-based FIFO compaction if TTL-based
deletion doesn't move the total size to be less than max_table_files_size.
nonoverlapping with the file on level 0
Write approximately 100MB of "B" values
Group commit test:
Test max_bytes_for_level_base
Increase level base size to 256KB and write enough data that will
fill L1 and L2. L1 size should be around 256KB while L2 size should be
around 256KB x 4.
they are either both ok or both not-found
flush should happen here
Put until writes are stopped, bounded by 256 puts. We should see stop at
~128KB
DEL eliminated, but v1 remains because we aren't compacting that level
(DEL can be eliminated because v2 hides v1).
Test to check whether flushing preserves a single delete hidden
behind a put.
do not compress L0
Half of the time directly use WriteBatch. Half of the time use
WriteBatchWithIndex.
This second sync point is to ensure the flush job will not
be completed until we already perform VerifyOperationCount().
Test with large TTL + Intra-L0 compactions.
Files dropped based on size, as ttl doesn't kick in.
Wait 100 milliseconds for they are scheduled.
writing 20 x 64KB = 10 x 128KB
(L1 + L2 + L3) = (1 + 2 + 4) * 128KB
comment: make sure the thread is not done
label: requirement
Read a value and verify that it matches the pattern written above
and that writes to all column families were atomic (unique_id is the
same)
Change the number of threads in high / low priority pool.
We must have at most one file per level except for level-0,
which may have up to kL0_StopWritesTrigger files.
About 200KB/s limited rate
Since no flushes and compactions have run, the db should still be in
the same state even after considerable time has passed.
Do we own map_
Inserting a new entry would create a new mem table, triggering slow down.
Write values of the form <key, my id, counter, cf, unique_id>.
into each of the CFs
We add some padding for force compactions.
comment: ApproximateOffsetOf() is not yet implemented in plain table format,
which is used by Size().
skip HashCuckooRep as it does not support snapshot
label: requirement
Compact all files.
Write 120KB (12 values, each 10K)
Save a snapshot from each DB this time that we'll use next
time we compare things, to make sure the current state is
preserved with the snapshot
here we expect some of the Put fails.
Check that we process level-0 files in correct order. The code
below generates two level-0 files where the earlier one comes
before the later one in the level-0 file list since the earlier
one has a smaller "smallest" key.
CURRENT, MANIFEST, OPTIONS, *.sst files (one for each CF)
Try if CreateColumnFamily also fails
1MB
Does not exist, and create_if_missing == true: OK
comment: The existing memtable became eligible for flush when we reduced its
capacity to 64KB. Two keys need to be added to trigger flush: first causes
memtable to be marked full, second schedules the flush. Then we should have
a 128KB L0 file, a 64KB L0 file, and a memtable with just one key.
label: code-design
This makes sure at least one compaction is running.
Fill memtable
Trigger flush
Not Supported directly
Start from scratch and disable compaction/flush. Flush can only happen
during compaction but trigger is pretty high
Advance sequence number one more
Compact all
very small
only two memtables allowed ==> only two log files
Verify the total number of threades
get a file snapshot
comment: Cleaning up
label: code-design
comment: Insert more than 80K. L4 should be base level. Neither L0 nor L4 should
be compressed, so total data size should be more than 80K.
label: code-design
This test may fail because of a legit case that multiple L0 files
are trivial moved to L1.
repeat the test with multiple column families
No files in L1
Create 3 L0 files, making score of L0 to be 3
new wal should have been created
(A)
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
all flushes should now do nothing because their CF is dropped
Estimate the total sleep time fall into the rough range.
Single deletes that encounter the matching put in a flush should get
removed.
10 KB
Check that it is not supported with max_open_files != -1.
When base level is L4, L4 is LZ4.
Enable auto compaction and perform the same test, # of L0 files should be
reduced after compaction.
Make files spanning the following ranges in level-0:
files[0] 200 .. 900
files[1] 300 .. 500
Note that files are sorted by smallest key.
make sure we can re-open it.
Schedule a sleeping task.
No reseek
Decrease
comment: Speed up the test
label: test
This makes sure a compaction won't be scheduled until
we have done with the above Put Phase.
Wait to ensure the all threads has been registered
Setup databases
this has to start a flush. if flushes are blocked, this will try to
create
3 memtables, and that will fail because max_write_buffer_number is 2
The existing memtable inflated 64KB->128KB when we invoked SetOptions().
Write 192KB, we should have a 128KB L0 file and a memtable with 64KB data.
namespace rocksdb
Make sparse update
Still expect finding the value as its delete has not yet being
flushed.
Check format
It should be compacted to no more than 20 files.
comment: The following condition prevents a race condition between flush jobs
acquiring work and this thread filling up multiple memtables. Without
this, the flush might produce less files than expected because
multiple memtables are flushed into a single L0 file. This race
condition affects assertion (A).
label: code-design
Stop trigger = 8
But everything before we simulate the failure-test should succeed.
If rocksdb does not do the correct job, internal assert will fail here.
no need to call this
Size limit is still guaranteed.
verify we have the latest successful update
this checks that updates across column families happened
atomically -- all unique ids are the same
should not compact the level 0 file
comment: Clean up L0
label: code-design
Does exist, and error_if_exists == false: OK
Compaction range falls before files
Populate a different range
this should fill up 2 memtables
Test compaction trigger and target_file_size_base
Reduce compaction trigger to 2, and reduce L1 file size to 32KB.
Writing to 64KB L0 files should trigger a compaction. Since these
2 L0 files have the same key range, compaction merge them and should
result in 2 32KB L1 files.
Read directly from persited data.
pool size 2, total task 4. Queue size should be 2.
Delay both flush and compaction
If we compact:
Put(A, v1) Snapshot SingleDelete(A) Put(A, v2)
We do not want to end up with:
Put(A, v1) Snapshot Put(A, v2)
Because a subsequent SingleDelete(A) would delete the Put(A, v2)
but not Put(A, v1), so Get(A) would return v1.
record the number and the size of the
latest manifest file
Delete
Zero if not including mem table
# rate limiting with half of the raw_rate
Make sure that Flushes can proceed in parallel with CompactRange()
Step 3: read a bunch of times
update the latest successful put
reopen and reverify we have the latest successful update
Periodically re-use the same key from the previous iter, so
we have multiple entries in the write batch for the same key
comment: Use a small number to ensure a large delay that is still effective
when we do Put
TODO(myabandeh): this is time dependent and could potentially make
the test flaky
label: test
Arrange for the following to happen:
* sstable A in level 0
* nothing in level 1
* sstable B in level 2
Then do enough Get() calls to arrange for an automatic compaction
of sstable A. A bug would cause the compaction to be marked as
occurring at level 1 (instead of the correct level 0).
these keys should be deleted in previous compaction
now it should compact the level 0 file
Just to make sure that we are in the same state even after sleeping.
Check that FIFO-with-TTL is supported only with BlockBasedTableFactory.
comment: Sleep for 2 hours -- which is much greater than TTL.
Note: Couldn't use SleepForMicroseconds because it takes an int instead
of uint64_t. Hence used addon_time_ directly.
env_->SleepForMicroseconds(2 * 60 * 60 * 1000 * 1000);
label: code-design
Now there is one L1 file but doesn't trigger soft_rate_limit
The L1 file size is around 30KB.
0 because GetApproximateSizes() does not account for memtable space
Verify the number of low-priority threads
Unblock
Clear memtable and make new option effective
Suppose there is:
small amount of data with prefix A
large amount of data with prefix B
small amount of data with prefix C
and that recent updates have made small changes to all three prefixes.
Check that we do not do a compaction that merges all of B in one shot.
Does exist, and error_if_exists == true: error
create a DB with block prefix index
Most intervals should've been drained (interval time is 100ms, elapsed is
micros)
Fails because L1 is non-empty.
do not compress L0 and L1
Fails because L0 has overlapping files.
Test paranoid_file_checks already done in db_block_cache_test
Test max_sequential_skip_in_iterations
overwrite one key, this key should not appear in the snapshot
First three 110KB files are not going to level 2
After that, (100K, 200K)
Enable time profiling
Write 3 files that have the same key range.
Since level0_file_num_compaction_trigger is 3, compaction should be
triggered. The compaction should result in one L1 file
as data has not yet being flushed, we expect not found.
Test to make sure that all files with expired ttl are deleted on next
manual compaction.
ROCKSDB_LITE
Disable because not all platform can run it.
It requires more than 9GB memory to run it, With single allocation
of more than 3GB.
sanity check
expecting one single L0 to L1 compaction
Create 3 L0 files, making score of L0 to be 3, higher than L0.
comment: Step 2: clear level 1 if necessary.
label: code-design
Wake up sleep task to enable compaction to run and waits
for it to go to sleep state again to make sure one compaction
goes through.
DEL kept: "last" file overlaps
comment: TODO(sanjay): Test Get() works
label: test
Put values on second level (so that they will not be in the same
compaction as the other operations.
150KB
Make sure data in files in L3 is not compacted by removing all files
in L4 and calculate number of rows
Not very large
Sleep for 2 hours -- which is much greater than TTL.
Check that FIFO-with-TTL is not supported with max_open_files != -1.
Flush the file. File size is around 30KB.
shrink level base so L2 will hit soft limit easier.
Assuming each files' metadata is at least 50 bytes/
Now reduce level0_stop_writes_trigger to 6. Clear up memtables and L0.
Block compaction thread again. Perform the put and memtable flushes
until we see the stop after 6 memtable flushes.
foo => v1 is now in last level
Generate and flush a file about 10KB.
compressible string
Expect same result in multiget
Test write_buffer_size
We expect that all the files were trivially moved from L0 to L2
Arrange to have multiple files in a non-level-0 level.
iter 0 -- zlib
iter 1 -- bzip2
iter 2 -- lz4
iter 3 -- lz4HC
iter 4 -- xpress
pool size 3, total task 4. Queue size should be 1.
Step 1: First place sstables in levels 0 and 2
Moves to level last-2
Test to make sure that all files with expired ttl are deleted on next
automatic compaction.
NewMemEnv returns nullptr in ROCKSDB_LITE since class InMemoryEnv isn't
defined.
Key has not yet been written
Does not exist, and create_if_missing == false: error
assert that nothing makes it to disk yet.
Allow some expansion from metadata
Block flushes
nowait
Test soft_pending_compaction_bytes_limit,
hard_pending_compaction_bytes_limit
Introduction of SyncPoint effectively disabled building and running this test
in Release build.
which is a pity, it is a good test
comment: Clean up memtable and L0
label: code-design
# no rate limiting
non overlapping ranges
Verify non of the column family info exists
Block compactions
Wait for compaction so that put won't stop
Write ~96M data
Increase buffer size
Large write buffer
3rd round: delete and flush
Verify the number of high-priority threads
Check format
Check format
Merging last-1 w/ last, so we are the base level for "foo", so
DEL is removed. (as is v1).
seconds
Spread the size range to more.
not supported, we should fail the Open()
10KB
150KB
repeat the test with disabling thread tracking.
record the lognumber and the size of the
latest manifest file
XXX
verify that data in the snapshot are correct
all statuses have to be the same
first_table_version 1 -- generate with table_version == 1, read with
table_version == 2
first_table_version 2 -- generate with table_version == 2, read with
table_version == 1
For mode (1), test DestroyDB() to delete all the logs under DB dir.
For mode (2), no info log file should have been put under DB dir.
check how many threads are doing compaction using GetThreadList
All into one file
copy only valid MANIFEST data
Windows fails this test. Will tune in the future and figure out
approp number
Write 8MB (80 values, each 100K)
20K
It should be compacted to 10 files.
table with crc checksum
minimum write buffer size is enforced at 64KB
comment: Compactions should not cause us to create a situation where
a file overlaps too much data at the next level.
label: code-design
All files are compacted
Compaction range overlaps files
Small write buffer
r124+
arg
The first dependency enforces Marker can be loaded before MarkedPoint.
The second checks that thread 1's MarkedPoint should be disabled here.
Execution order:
| Thread 1 | Thread 2 |
| | Marker |
| MarkedPoint | |
| Thread1First | |
| | MarkedPoint |
only index/filter were added
column_family_name -> column_family_id map (provided to WALFilter)
We expect the record with apply_option_for_record_index to be not
found.
Make sure that we wrote enough to check all 7 levels
Processing option that is requested to be applied at the given index
We want to make sure to call this callback only once
default column-family, only post_flush keys are expected
comment: GetUniqueIdFromFile is not implemented
label: requirement
On Recovery we should only find the second batch applicable to default CF
But both batches applicable to pikachu CF
Create a test filter that would apply wal_processing_option at the first
record
Read keys/values randomly and verify that reported read amp error
is less than 2%
Get base cache values
ROCKSDB_LITE
Use Snappy except for bottommost level use ZLib
Triggering flush in DB2.
Infinite for full compaction.
While the compaction is running, we will create 2 new files that
can fit in L2, these 2 files will be moved to L2 and overlap with
the running compaction and break the LSM consistency.
Fill memtable
Trigger flush
Start a non-exclusive manual compaction in a bg thread
Miss and hit count should remain the same, they're all pinned.
Ensure that given keys don't exist
Filter is passed as a const object for RocksDB to not modify the
object, however we modify it for our own purpose here and hence
cast the constness away.
Ensure that expected keys exists
and not expected keys don't exist after recovery
Reopen database. If max_open_files is set as -1, table readers will be
preloaded. This will trigger a BlockBasedTable::Open() and prefetch
L0 index and filter. Level 1's prefetching is disabled in DB::Open()
Create 3 batches with two keys each
If max_open_files is -1, we have pinned index and filter in Rep, so there
will not be changes in index and filter misses or hits. If max_open_files
is not -1, Get() will open a TableReader and prefetch index and filter.
Callback is only executed once
pikachu column-family, all keys are expected
Hold NotifyOnCompactionCompleted in the unlock mutex section
Write 10 random files
After reopen, cache miss are increased by one because we read (and only
read) filter and index on L0
/dev/shm dont support getting a unique file id, this mean that
running this test on /dev/shm will fail because lru_cache will load
the blocks again regardless of them being already in the cache
Do some more writes
bytes read for user iterator shouldn't count against the rate limit.
Reopen without filter, now reopen should succeed - previous
attempt to open must not have altered the db.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Compaction pressure should trigger since 6 files
Wait for compaction to be triggered
10KiB
Current record index, incremented with each record encountered.
Figure out last level with files
compaction input has 512KB data
This ensures that there is no ref to block cache entries
this is never hit
Use a write buffer total size so that the soft limit is about
105000.
Clear "DBImpl::BGWorkCompaction" SYNC_POINT since we want to hold it again
at DBTest2::CompactionStall::1
column_family_name -> keys_found_in_wal map
We store keys that are applicable to the column_family
during recovery (i.e. aren't already flushed to SST file(s))
for verification against the keys we expect.
this should be read from L0
This manual compaction conflict with the other manual compaction
so it should wait until the first compaction finish
Add a key to memtable
comment: Error between reported read amp and real read amp should be less than
2%
label: code-design
namespace
Iter2: Read half the DB, Read odd keys
Key(1), Key(3), Key(5), Key(7), Key(9), ...
Index at which to start changing records
get base cache values
Memtable-only iterator (read_tier=kMemtableTier); data not flushed yet.
Block compaction
Ensure that expected keys exist
verify that handles_[0] only has post_flush keys
while handles_[1] has pre and post flush keys
When compact from Ln -> Ln+1, cut a file if the file overlaps with
more than three files in Ln+1.
this should be read from L1
the file is opened, prefetching results in a cache filter miss
the block is loaded and added to the cache,
then the get results in a cache hit for L1
When we have inifinite max_files, there is still cache miss because we have
reset the block cache
Reopen database with option to use WAL filter
Index at which to apply wal_processing_option_
At other indexes default wal_processing_option::kContinueProcessing is
returned.
Make sure to use any custom env that the test is configured with.
Make sure we read every thing in the DB (which is smaller than our cache)
Use Snappy everywhere
takes roughly one second, split into 100 x 10ms intervals. Each interval
permits 5.12KB, which is smaller than the block size, so this test
exercises the code for chunking reads.
4 Files in L0
Trivial move 2 files to L1
Without hitting the threshold, no flush should trigger.
comment: Huge block cache to make it easier to calculate read amplification
label: code-design
column_family_id -> log_number map (provided to WALFilter)
Batch to insert keys in
Run a manual compaction that will compact the 2 files in L2
into 1 file in L2
small write buffer
Before flushing
point lookups
unhandled case
Trivial move 2 files to L2
While the compaction is running, we will create 2 new files that
can fit in L1, these 2 files will be moved to L1 and overlap with
the running compaction and break the LSM consistency.
flush all data from memtable so that reads are from block cache
Test with all WAL processing options
Include the explict prefetch of the footer in direct I/O case.
namespace rocksdb
move this table to L1
Number of keys to add in the new batch
Compute which keys we expect to be found
and which we expect not to be found after recovery.
Create a test filter that would add extra keys
high compression ratio
If max_open_files is not -1, we do not preload table readers, so there is
no change.
Write given keys in given batches
After flushing
point lookups
In case of corruption we can turn off paranoid_checks to reopen
databse
Test that the stats GetMapProperty API reporting 1 file in L2
!ROCKSDB_LITE
we expect all records to be processed
fairness
no block cache
Trigger another flush. This time "dobrynia". "pikachu" should not
be flushed, althrough it was never flushed.
should be slightly above 512KB due to non-data blocks read. Arbitrarily
chose 1MB as the upper bound on the total bytes read.
default column family doesn't have block cache
In this case, cache miss will be increased by one in
BlockBasedTable::Open() because this is not in DB::Open() code path so we
will prefetch L1's index and filter. Cache hit will also be increased by
one because Get() will read index and filter from the block cache
prefetched in previous Open() call.
rate_bytes_per_sec
Create some data and flush "default" and "nikitich" so that they
are newer CFs created.
LZ4_VERSION_NUMBER >= 10400
this is the real limit
Insert to DB2
We expect records beyond apply_option_for_record_index to be not
found.
Destroy old statistics obj that the blocks in lru_cache are pointing to
compressed
Output files to L1 are cut to three pieces, according to
options.max_compaction_bytes
create new table at L0
make sure all background compaction jobs can be scheduled
reset block cache
1M
!OS_SOLARIS
Trigger a flush on cf2
Create a new table.
In inifinite max files case, there's a cache miss in executing Get()
because index and filter are not prefetched before.
The total soft write buffer size is about 105000
Avoid undeterministic value by malloc_usable_size();
Force arena block size to 1
uncompressed
Iter1: Read half the DB, Read even keys
Key(0), Key(2), Key(4), Key(6), Key(8), ...
Use different compression algorithms for different levels but
always use Zlib for bottommost level
Run a manual compaction that will compact the 2 files in L1
into 1 file in L1
Read amp is on average 100% since we read all what we loaded in memory
refill_period_us
Hit the write buffer limit again. "default"
will have been flushed.
Add three more small files that overlap with the previous file
No flush should trigger
Flush default column-family
Ensure that all keys exist before change_records_from_index_
And after that index only single key exists
as our filter adds only single key for each batch
this should be read from L0
so cache values don't change
Triggering to flush another CF in DB1
Use the statistics object that we just created
Make sure DB can be reopen with reduced number of levels, given no file
is on levels higher than the new num_levels.
empty vector
index/filter blocks added to block cache right after table creation.
Also test that the stats GetMapProperty API reporting the same result
comment: Disable delta encoding to make it easier to calculate read amplification
label: code-design
reopen database again to make sure previous log(s) are not used
(even if they were skipped)
reopn database with option to use WAL filter
This snapshot will have sequence number 0 what is expected behaviour.
Number of keys added to new batch
Write 8MB (80 values, each 100K)
this should be read from L1
this is never hit
Get() is issued after the first Put(), so it should see either
"v1" or "v2".
If the current record is applicable for column_family_id
(i.e. isn't flushed to SST file(s) for column_family_id)
add it to the cf_wal_keys_ map for verification.
This ensures that db does not ref anything in the block cache, so
EraseUnRefEntries could clear them up.
nothing should be returned using memtable-only iterator after flushing.
Another 6 L0 files to trigger compaction again
Wait for another compaction to be triggered
Trigger a flush. Flushing "nikitich".
First iteration: compress without preset dictionary
Second iteration: compress with preset dictionary
To make sure the compression dictionary was actually used, we verify
the compressed size is smaller in the second iteration. Also in the
second iteration, verify the data we get out is the same data we put
in.
Return the current option configuration.
Destroy using last options
This options optimize 2PC commit path
Switch between different WAL settings
Return a string that contains all key,value pairs in order,
formatted like "(k1->v1)(k2->v2)".
Prevent pushing of new sstables into deeper levels by adding
tables that cover a specified range to all levels.
Special Env used to delay background operations
comment: Verify Iterator::Prev()
Use a new iterator to make sure its status is clean.
label: code-design
Used to test InplaceUpdate
namespace rocksdb
Do n memtable compactions, each of which produces an sstable
covering the range [small,large].
Verify Iterator::Next()
These options are not supported in ROCKSDB_LITE
Verify ForwardIterator::Next()
comment: Note: operator= is an unsafe approach here since it destructs shared_ptr in
the same order of their creation, in contrast to destructors which
destructs them in the opposite order of creation. One particular problme is
that the cache destructor might invoke callback functions that use Option
members such as statistics. To work around this problem, we manually call
destructor of table_facotry which eventually clears the block cache.
label: code-design
Destroy it for not alternative WAL dir is used.
If previous value is nullptr or delta is > than previous value,
sets newValue with delta
If previous value is not empty,
updates previous value with 'b' string of previous value size - 1.
Verify Iterator::Seek()
default argument means copy everything
Tailing iterator
ROCKSDB_LITE
comment: TODO(3.13) -- test more options
label: test
mmap reads should be orthogonal to WalDir setting, so we piggyback to
this option config to test mmap reads as well
50 bytes
comment: this redundant copy is to minimize code change w/o having lint error.
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Verify ForwardIterator::Seek()
default cfd
this will generate non-overlapping files since it keeps increasing key_idx
Switch between different compaction styles.
Check reverse iteration results are the reverse of forward results
Switch between different filter policy
Jump from kDefault to kFilter to kFullFilter
Return spread of files per level
keep it the same as kTypeValue for testing kMergePut
Normal Iterator
snapshots
Switch to a fresh database with the next option configuration to
test. Return false if there are no more configurations to test.
checks sequence number for updates
Utility method to test InplaceUpdate
Return the current option configuration.
Sequence of option configurations to try
Number of WAL files that are still open for write.
comment: A hacky skip list mem table that triggers flush after number of entries.
label: code-design
comment: The factory for the hacky skip list mem table that triggers flush after
number of entries exceeds a threshold.
label: code-design
Drop writes on the floor
Return a string that contains all key,value pairs in order,
formatted like "(k1->v1)(k2->v2)".
Prevent pushing of new sstables into deeper levels by adding
tables that cover a specified range to all levels.
Check preallocation size
preallocation size is never passed to base file.
Special Env used to delay background operations
namespace rocksdb
Used to test InplaceUpdate
Utility method to test InplaceUpdate
Returns true iff an entry that compares equal to key is in the list.
Skip some options, as they may not be applicable to a specific test.
To add more skip constants, use values 4, 8, 16, etc.
Simulate no-space errors while this pointer is non-nullptr.
Do n memtable compactions, each of which produces an sstable
covering the range [small,large].
Slow down every log write, in micro-seconds.
Force write to log files to fail while this pointer is non-nullptr
Return a high memory usage when number of entries exceeds the threshold
to trigger a flush.
namespace anon
These will be used only if filter_policy is set
comment: Used as a bit mask of individual enums in which to skip an XF test point
label: test
If previous value is nullptr or delta is > than previous value,
sets newValue with delta
If previous value is not empty,
updates previous value with 'b' string of previous value size - 1.
A test merge operator mimics put but also fails if one of merge operands is
"corrupted".
ROCKSDB_LITE
!(defined NDEBUG) || !defined(OS_WIN)
Lock to pretect rnd_
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
this will generate non-overlapping files since it keeps increasing key_idx
Force write to manifest files to fail while this pointer is non-nullptr
Switch between different compaction styles.
Force sync of manifest files to fail while this pointer is non-nullptr
Switch between different filter policy
Jump from kDefault to kFilter to kFullFilter
Return spread of files per level
sstable Sync() calls are blocked while this pointer is non-nullptr.
Drop writes on the floor while this pointer is non-nullptr.
10s
1s
After number of inserts exceeds `num_entries_flush` in a mem table, trigger
flush.
Switch to a fresh database with the next option configuration to
test. Return false if there are no more configurations to test.
Simulate non-writable file system while this pointer is non-nullptr
SyncPoint is not supported in Released Windows Mode.
Insert key into the list.
REQUIRES: nothing that compares equal to key is currently in the list.
Switch between different WAL-realted options.
Write 3 files while 1st compaction is held
These 3 files have different sizes to avoid compacting based on size_ratio
Tests universal compaction with trivial move enabled
Hold the 1st compaction from finishing
All files at level 0 will be compacted into a single one.
Make sure bloom filter is used at least once.
Compact all to level 0
(1, 4, 8) -> (5, 8)
Write 120KB (12 values, each 10K)
expect ok and verify the compacted files no longer exist.
Compact all files into 1 file and put it in L4
1MB
Suppose each file flushed from mem table has size 1. Now we compact
(level0_file_num_compaction_trigger+1)=4 files and should have a big
file of size 4.
block compaction from happening
Write 8 files while 1st compaction is held
These 8 files have different sizes to avoid compacting based on size_ratio
Pick the first and the last file, expect everything is
compacted into one single file.
Before compaction, we have 4 files at level 0, with size 4, 2.4, 1, 1.
After compaction, we should have 3 files, with size 4, 2.4, 2.
Trigger compaction if size amplification exceeds 110%
Stage 1:
Generate a set of files at level 0, but don't trigger level-0
compaction.
When we start for the compaction up to (2 4 8), the latest
compressed is not compressed.
Disable size amplifiction compaction
Stop SyncPoint and destroy the DB and reopen it again
Make sure bloom filter is used for all but the last L0 file when looking
up a non-existent key that's in the range of all L0 files.
First three 110KB files are not going to second path.
After that, (100K, 200K)
Wait for the 1st background compaction process to start
Insert more keys
Another 110KB triggers a compaction to 400K file to second path
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
comment: Stage 2:
Now we have one file at level 0, with size 4. We also have some data in
mem table. Let's continue generating new files at level 0, but don't
trigger level-0 compaction.
First, clean up memtable before inserting new data. This will generate
a level-0 file, with size around 0.4 (according to previously written
data amount).
label: code-design
Write 100KB file. And immediately it should be compacted to one file.
no_wait
1KB
(1, 2, 8) -> (3, 8)
each value is 10K
When we start for the compaction up to (2 4 8), the latest
compressed is compressed given the size ratio to compress.
namespace
This time we will trigger a compaction because of size ratio and
another compaction because of number of files that are not compacted
greater than 7
!defined(ROCKSDB_LITE)
Hold the 1st and 2nd compaction from finishing
Make sure we don't trigger a problem if the trigger condtion is given
to be 0, which is invalid.
Wait for the 2nd background compaction process to start
comment: Regression test for extra compactions scheduled. Once enough compactions
have been scheduled to bring the score below one, we should stop
scheduling more; otherwise, other CFs/DBs may be delayed unnecessarily.
label: code-design
Before compaction, we have 4 files at level 0, with size 4, 0.4, 1, 1.
After compaction, we should have 2 files, with size 4, 2.4.
Config universal compaction to always compact to one single sorted run.
Generate 3 overlapping files
wait for the full compaction to be picked before adding files intended
for the second one.
Write 110KB (11 values, each 10K)
Delete archival files.
Generate two files in Level 0. Both files are approx the same size.
(1, 1, 8) -> (2, 8)
105KB
Reopen and check.
namespace rocksdb
Test that checks trivial move in universal compaction
Compaction to non-L0 has happened.
100KB
There should only be one picked compaction as the score drops below one
after the first one is picked.
Big size
Fail when compacting to an invalid path ID
Write 100KB
the full (bottom-pri) compaction waits until a partial (low-pri)
compaction has started to verify they can run in parallel.
expect fail since universal compaction only allow L0 output
The same queries will not trigger bloom filter
Stage 5:
Now we have 4 files at level 0, with size 4, 2.4, 2, 1. Let's generate
a new file of size 1.
(1, 2, 4) -> (3, 4)
Stage 3:
Now we have 2 files at level 0, with size 4 and 2.4. Continue
generating new files at level 0.
Need to restart it once to remove higher level records in manifest.
use no_wait above because that one waits for flush and compaction. We
don't want to wait for compaction because the full compaction is
intentionally blocked while more files are flushed.
Compacting the first four files was enough to bring the score below one so
there's no need to schedule any more compactions.
100KB
32KB
Query set of non existing keys
Final reopen
The third compaction (2 4) is compressed since this time it is
(1 1 3.2) and 3.2/5.2 doesn't reach ratio.
Level-0 compaction is triggered, but no file will be picked up.
The second compaction (4) is compressed
114KB
105KB
4KB
32KB
trigger compaction if there are >= 4 files
Generate one more file at level-0, which should trigger level-0
compaction.
Write 100KB (100 values, each 1K)
Flush whatever is remaining in memtable. This is typically
small, which should not trigger size ratio based compaction
but will instead trigger size amplification.
for single-level universal, everything's bottom level so nothing should
be executed in bottom-pri thread pool.
32KB
trigger compaction if there are >= 4 files
Stage 4:
Now we have 3 files at level 0, with size 4, 2.4, 2. Let's generate a
new file of size 1.
comment: TODO(kailiu) The tests on UniversalCompaction has some issues:
1. A lot of magic numbers ("11" or "12").
2. Made assumption on the memtable flush conditions, which may change from
time to time.
label: code-design
200KB
The first compaction (2) is compressed.
Full compaction to DB path 0
Unblock compaction and wait it for happening.
Write 7 files to trigger compaction
(1, 4)
Stage 3:
Now we have 3 files at level 0, with size 4, 0.4, 2. Generate one
more file at level-0, which should trigger level-0 compaction.
(1, 3, 8) -> (4, 8)
Verify that size amplification did occur
(1,1,4) -> (2, 4)
First compaction should output to bottom level. Second should output to L0
since older L0 files pending compaction prevent it from being placed lower.
105KB
4KB
32KB
allow_ingest_behind increases number of levels while sanitizing.
(1, 3, 4) -> (8)
Before compaction, we have 4 files at level 0, with size 4, 0.4, 1, 1.
After compaction, we should have 3 files, with size 4, 0.4, 2.
Delay every compaction so multiple compactions will happen.
Stage 2: reopen with universal compaction, num_levels=4
Stage 3: Revert it back to one level and revert to num_levels=1.
Stage 1: open a DB with universal compaction, num_levels=1
(1, 8)
again both values should be present.
4 memtable are not flushed, 1 sst file
Reopen, insert and flush.
First 4 keys goes to separate SSTs + 1 more SST for 2 smaller keys
Reopen twice and validate.
Make sure that if we re-open with a small write buffer size that
we flush table files in the middle of a large log file.
Verify clean slate behavior
Flush() triggers deletion of obsolete tracked files
Check, that records for 'default', 'dobrynia' and 'pikachu' from
first, second and third WALs went to the same SST.
So, there is 6 SSTs: three for 'nikitich', one for 'default', one for
'dobrynia', one for 'pikachu'
seq id 4
verify
Simulate a crash.
Verify behavior
fill with new date
Manuall corrupt the specified WAL
New WAL file
ROCKSDB_LITE
Create corrupted WAL
assert that we successfully recovered only from logs, even though we
destroyed the DB
Test scope:
- We expect to open data store under all circumstances
- We expect only data upto the point where the first error was encountered
Destroy DB before destruct fault_env.
Read back all the keys we wrote and return the number of keys found
corrupt the wal
Reopen DB. Check if WAL logs flushed.
Corruption offset position
len%=
1 SST for big key + 1 SST for small one
Starting number for the WAL file name like 00010.log
Write to new WAL file
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Create WAL files with values filled in
Corrupt the WAL
Insert some data without flush
Prior to the fix, we may incorrectly recover "v5" with sequence id = 3.
Since we will reopen DB with smaller write_buffer_size,
each key will go to new SST file
There are still 4 memtable not flushed, and 2 sst tables
Append some more data.
comment: On windows long is 32-bit
label: code-design
Github issue 1339. Prior the fix we read sequence id from the first log to
a local variable, then keep increase the variable as we replay logs,
ignoring actual sequence id of the records. This is incorrect if some writes
come with WAL disabled.
Reopen DB. WAL logs should not be flushed this time.
WAL file
fill up the DB
Test scope:
- We expect to open the data store under all scenarios
- We expect to have recovered records past the corruption zone
Both value's should be present.
manual flush and insert again
make sure we can re-open it.
Number of WAL files to generate
Test scope:
We don't expect the data store to be opened if there is any corruption
(leading, middle or trailing -- incomplete writes or corruption)
Moving this to SyncWAL before the actual fsync
TEST_SYNC_POINT("DBWALTest::SyncWALNotWaitWrite:1");
Keys to be written per WAL file
Corruption offset
In this test we are trying to do the following:
1. Create a DB with corrupted WAL log;
2. Open with avoid_flush_during_recovery = true;
3. Append more data without flushing, which creates new WAL log.
4. Open again. See if it can correctly handle previous corruption.
Corrupt the wal
seq id 1
Recreate and fill the store with some data
Recovery will fail if DB directory doesn't exist.
Fill data for testing
wal files
Test with flush after recovery.
No inserts => default is empty
Create DB with multiple column families and multiple log files.
namespace rocksdb
Overwrite data with 'a' from offset for length len
wal=
this should ignore the log files, recovery should not happen again
if the recovery happens, the same merge operator would be called twice,
leading to incorrect results
seq id 5
Test without flush after recovery.
Moving this to SyncWAL after actual fsync
TEST_SYNC_POINT("DBWALTest::SyncWALNotWaitWrite:2");
Make 'nikitich' memtable to be flushed
Test scope:
- We expect to open the data store when there is incomplete trailing writes
at the end of any of the logs
- We do not expect to open the data store for corruption
Insert again and reopen
Now the original WAL is in log_files[0] and should be marked for
recycling.
Verify full purge cannot remove this file.
In https://reviews.facebook.net/D20661 we change
recovery behavior: previously for each log file each column family
memtable was flushed, even it wasn't empty. Now it's changed:
we try to create the smallest number of table files by merging
updates from multiple logs
Save data for comparison.
Skip the test if DB won't open.
force
Test WAL recovery for the various modes available
copy the logs to backup
delete old files in backup_logs directory
Memtable for 'nikitich' has flushed, new WAL file has opened
4 memtable still not flushed
copy the logs from backup back to wal dir
off=
make it flush
Reopen. Verify data.
Make sure 'dobrynia' was flushed: check sst files amount
Probe data for invariants
1 SST for all keys
recover the DB
For github issue #1303
Fill up 'nikitich' one more time
Verifies WAL files that were present during recovery, but not flushed due
to avoid_flush_during_recovery, will be considered for deletion at a later
stage. We check at least one such file is deleted during Flush().
comment: Check at least the first WAL was cleaned up during the recovery.
label: code-design
Force flush with allow_2pc.
Size of the value
!(defined NDEBUG) || !defined(OS_WIN)
Make 'dobrynia' to be flushed and new WAL file to be created
test checksum failure or parsing
Offset of corruption
Windows disk cache behaves differently. When we truncate
the original content is still in the cache due to the original
handle is still open. Generally, in Windows, one prohibits
shared access to files and it is not needed for WAL but we allow
it to induce corruption at various tests.
comment: Test for regression of WAL cleanup missing files that don't contain data
for every column family.
label: code-design
comment: Corruption style
label: code-design
Insert more data.
In https://reviews.facebook.net/D20661 we change
recovery behavior: previously for each log file each column family
memtable was flushed, even it was empty. Now it's changed:
we try to create the smallest number of table files by merging
updates from multiple logs
Verify
we won't be needing this file no more
Test variations of WriteImpl.
Check each sequence is used once and only once.
Sequence number should be return through input write batch.
The sequence isn't consumed by someone else.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
When user keys are same
When limit user key is prefix of start user key
Size going up, memory allocation is triggered
When start user key is prefix of limit user key
namespace rocksdb
When user keys are misordered
When user keys are different, but correctly ordered
namespace rocksdb
comment: clean up all the files that might have been there before
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
2 ssts, 1 manifest
Make sure all background purges are executed
1 sst after iterator deletion
3 sst after compaction with live iterator
~DBImpl should wait until all BGWorkPurge are finished
this time, we keep an iterator alive
Take the last log file which is expected to be alive and try to delete it
Should not succeed because live logs are not allowed to be deleted
Call Flush to bring about a new working log file and add more keys
Call Flush again to flush out memtable and move alive log to archived log
and try to delete the archived log file
Make sure no purges are executed foreground
!ROCKSDB_LITE
intermediate level files cannot be deleted.
This test is to reproduce a bug that read invalid ReadOption in iterator
cleanup function
COntrolled setup. Levels 1 and 2 should both have 50K files.
This is a little fragile as it depends on the current
compaction heuristics.
5 sst files after 2 compactions with 2 live iterators
always do full purge
Used to test log files
Used to test log files
An empty job to guard all jobs are processed
there should be only one (empty) log file because CreateTwoLevels()
flushes the memtables to disk
1 sst after compaction
We keep an iterator alive
comment: ReadOptions is deleted, but iterator cleanup function should not be
affected
label: code-design
Lowest level file deletion should succeed.
file3.sst (110 => 124) .. overlap with file2.sst
Write some keys through normal write path
File dont overwrite any keys, No seqno needed
we only use TestPutOperator in this test
overlaps with memtable, so flush is triggered (thus file count increases by
two at this step).
namespace rocksdb
copy file
file2.sst (100 => 299)
File overwrite some keys, a seqno will be assigned
move file
fadvise disabled
Add file using file path
We will need a seqno for the file regardless if the file overwrite
keys in the DB or not because we have a snapshot
A global seqno will be assigned anyway because of the snapshot
fadvise enabled
Current file size should be 0 after sst_file_writer init and before open a
file.
ROCKSDB_LITE
overlaps with nothing, so places at bottom level and skips incrementing
seqnum.
overlaps with L0 file but not memtable, so flush is skipped
prevent range deletions from being dropped due to becoming obsolete.
This file have overlapping values with the existing data
snapshot unneeded now that both range deletions are persisted
No snapshot anymore, no need to assign a seqno
sst_file_writer already finished, cannot add this value
Current file size should be non-zero after success write.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
file1.sst (0 => 99)
range del [0, 50) in L0 file, [50, 100) in memtable
check that we have change the old key
Start ingesting and extrnal file in the background
This file overlap with files in L4, we will ingest it in L3
We intentionally add every file twice, and assert that it was added
only once and the other add failed
Verify data in files
L3
L2
L1
L0
L3
L2
SST CF unknown
Flush / Compact the DB
file5.sst (200 => 299)
Add file while holding a snapshot will fail
file4.sst (30 => 39)
This file values overlap with file1 values
This thread will try to insert into the memtable but since we have 4 L0
files this thread will be blocked and hold the writer thread
This file has overlapping values with the existing data
Start a thread that will ingest a new file
SST CF match
files[0].sst (0 => 99)
files[1].sst (100 => 199)
...
file[8].sst (800 => 899)
this time ingest should fail as the file doesn't fit to the bottom level
Use DB::AddFile to insert range
Make sure DelayWrite is called first
file5.sst (400 => 499)
Thread 0 -> Load {f0,f1}
Thread 1 -> Load {f0,f1}
Thread 2 -> Load {f2,f3}
Thread 3 -> Load {f2,f3}
Thread 4 -> Load {f4,f5}
Thread 5 -> Load {f4,f5}
...
Now let compaction start
Generate the file containing the range
We can add the file after releaseing the snapshot
Generate file names
Can't ingest behind since allow_ingest_behind isn't set to true
Write range [5 => 10] to L0
CF was not dropped, ok to Ingest
Flush and read from L0
These 2 files dont overlap with each other
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
file3.sst (300 => 399)
file #1 in L0
This test reporduce a bug that can happen in some cases if the DB started
purging obsolete files when we are adding an external sst file.
This situation may result in deleting the file while it's being added.
Universal picker should go at second from the bottom level
This range overlap with data already exist in DB
Current file size should be 0 after sst_file_writer init and before open a file.
Use DB::Put to insert range (insert into memtable)
Wait for IngestExternalFile() to start and aquire mutex
This file dont overlap with anything in the DB, will go to L4
Now we can add the file
file #2 in L0
Generate a file id if not provided
This file does not overlap with any file or with the running compaction
This file dont overlap with anything in the DB and fit in L4 as well
Insert 100 -> 200 using IngestExternalFile
Update true_data map to include the new inserted data
Output of the compaction will go to L3
Insert 30 -> 50 using AddFile
SST CF dont match
Add file using file path
atomic conter of currently running bg threads
Write num_files files in parallel
Bulk load 10 files every file contain 1000 keys
This file overlap with the memtable, so it will flush it and add
it self to L0
File 7 overlaps with file 4 (L3)
Sort data if asked to do so
file2.sst (100 => 199)
Delete keys in range (200 => 299)
While writing the MANIFEST start a thread that will ask for compaction
cf1.sst
Verify values of file5 in DB
Current file size should be non-zero after success write.
file1.sst (0 => 500)
Generate files with these key ranges
{14 -> 0}
{24 -> 10}
{34 -> 20}
{44 -> 30}
..
This file overlaps with the output of the compaction (going to L3)
so the file will be added to L0 since L3 is the base level
Insert 80 -> 130 using AddFile
bottom level should be empty
25% of writes go through memtable
Ingest into cf1
We need to verify that no compactions can run while AddFile is
ingesting the files into the levels it find suitable. So we will
wait for 2 seconds to give a chance for compactions to run during
this period, and then make sure that no compactions where able to run
This file does not overlap with the current running compactiong
Make sure the values are correct before and after flush/compaction
Insert 100 -> 200 into the memtable
namespace rocksdb
File 5 overlaps with file 2 (L3 / base level)
file2.sst (100 => 299)
Compacting the DB will remove the tombstones
No need for flush, this file keys fit between the memtable keys
File 1 will go to level L2 (since it overlap with file 0 in L3)
Files dont overlap and dont overlap with DB key range
Overwrite what we added using external files
cf_unknown.sst
list 1 has internal key range conflict
check that we still can open the DB, as num_levels should be
sanitized to 3
Flush 4 files containing the same keys
Hold AddFile from finishing writing the MANIFEST
fit in L3 but will overlap with compaction so will be added
to L2 but a compaction will trivially move it to L3
and break LSM consistency
!ROCKSDB_LITE
`DBImpl::AddFile:Start` will wait until we be here
We have 2 overlapping files in L0
Wait for BackgroundCompaction() to be called
Cannot add this key because it's not after last added key
No Flush needed, but need a global seqno, Ingest in L0
Overwrite values of keys divisible by 100
default_cf.sst
Verify the correctness of the data
Read values from memtable
Destruct SstFileWriter with a failing Finish
file3.sst (195 => 199)
This file values overlap with file2 values
Delete keys in range (400 => 499)
Insert 10 -> 40 using AddFile
These 2nd and 3rd files overlap with each other
sst_file_writer already finished, cannot add this value
Current file size should be non-zero after success finish.
file1.sst (0 => 99)
This list of files have key ranges are overlapping with each other
sometimes we use copy, sometimes link .. the result should be the same
Insert 0 -> 20 using AddFile
Add files using file path list
We deleted range (200 => 299) but cannot add file5 because
of the range tombstones
This file will flush the memtable
Make sure values are correct before and after flush/compaction
No Flush needed, No global seqno needed, Ingest in L1
Wait for max 5 seconds, if we did not finish all bg threads
then we hit the deadlock bug
Wait for AddFile to start picking levels and writing MANIFEST
This file overlaps with file 0 (L3), file 1 (L2) and the
output of compaction going to L1
Ingest into cf2
Cannot ingest a file into a dropped CF
This file list has overlapping values with the existing data
Insert the generated file
Add file will fail when holding snapshot and use the default
skip_snapshot_check to false
Insert keys using normal path and take a snapshot
No need for flush
Bulk load num_files files in parallel
Key range of file5 (400 => 499) dont overlap with any keys in DB
File 6 overlaps with file 2 (L3 / base level) and file 5 (L0)
Destruct SstFileWriter without calling Finish()
Overwrite values of keys divisible by 5
Ingest into default cf
Overwrite all keys using IngestExternalFile
Cannot create an empty sst file
file3.sst (195 => 299)
This file values overlap with file2 values
File 0 will go to last level (L3)
Add file will success when set skip_snapshot_check to true even db holding
snapshot
For 20% of ranges we use DB::Put, for 80% we use DB::AddFile
We deleted range (400 => 499) but cannot add file5 because
of the range tombstones
Hold compaction from finishing
These 2 files dont overlap with each other but overlap with keys in DB
Return the current option configuration.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright 2014 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
This test uses a custom Env to keep track of the state of a filesystem as of
the last "sync". It then checks for data loss errors by purposely dropping
file data (or entire files) not protected by a "sync".
When need to make sure data is persistent, sync WAL
Return the ith key
rnd cannot be null for kResetDropRandomUnsyncedData
100KB
Block the job queue to prevent flush job from running.
Setting a separate data path won't pass the test as we don't sync
it after creating new files,
When need to make sure data is persistent, call DB::CompactRange()
random transfer
Return the value to associate with the specified key
namespace rocksdb
Previous log file is not fsynced if sync is forced after log rolling.
No new files created so we expect all values since no files will be
dropped.
Case 4: mixed
Case 1: no overlap, files are on the left of next level files
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace rocksdb
level 2
0
1
2
3
4
level 3
level 1, 0
level 2, 1
level 2, [2 - 4], no overlap
level 2
Case 2: no overlap, files are on the right of next level files
Case 3: empty L2
level 1, 1
level 1, 2
level 2, 0
level 3
level 1
Case 0: Empty
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Successful parses
Errors
range tombstone end key
a key is visible only if:
1. it's the last one written (j == insertions - 1)
2. there's a snapshot pointing at it
comment: TODO(icanadi) Remove this once we mock out VersionSet
label: requirement
range tombstone seqnum 10000
Make "CURRENT" file that points to the new manifest file.
comment: TODO(icanadi) Mock out everything else:
1. VersionSet
2. Memtable
label: requirement
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Test data:
seqno [ 1, 2 ... 8998, 8999, 9000, 9001, 9002 ... 9999 ]
key [ 1001, 1002 ... 9998, 9999, 0, 1, 2 ... 999 ]
range-delete "9995" -> "9999" at seqno 10000
Write 8 files in L0
suppress the first error and disable write-dropping such that a retry
can succeed.
BG compaction is disabled. Number of L0 files will simply keeps
increasing in this test.
trigger flush so compaction is triggered again; this time it succeeds
Small write buffer
db
the usual TEST_WaitForFlushMemTable() doesn't work for failed flushes, so
forge a custom one for the failed flush case.
namespace rocksdb
verify whether the previously created file matches the flushed file.
make sure call-back functions are called in the right order
Do a trivial move from L0 -> L1
ROCKSDB_USING_THREAD_STATUS
ROCKSDB_LITE
This simple Listener can only handle one flush at a time.
keep writing until writes are forced to stop.
Verify the id of the current thread that created this table
file matches the id of any active flush or compaction thread.
Write 3 non-overlapping files in L0
Write 4 files in L0
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
remember the info for later checking the FlushJobInfo.
third iteration triggers the second memtable's flush
Least significant size byte is stored in header[4].
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Drop all payload as well as a header byte
Remove the LAST block, including header.
Write records that span two blocks
Return a skewed potentially long string
If an error occurs during Read() in UnmarkEOF(), the records contained
in the buffer should be returned on subsequent calls of ReadRecord()
until no more full records are left, whereafter ReadRecord() should return
false to indicate that it cannot read any further.
test is only valid for recycled logs
checksum
Returns OK iff recorded error message contains "msg"
initial_offset
Two sizable records in first block
Construct a string of the specified length made out of the supplied
partial string.
Compute crc of type/len/data
Make a trailer that is exactly the same length as an empty record.
Span three blocks
namespace log
namespace rocksdb
Truncated last record is ignored, not treated as an error
Type is stored in header[6]
Consider two fragmented records:
first(R1) last(R1) first(R2) last(R2)
where the middle two fragments disappear. We do not want
first(R1),last(R2) to get joined and returned as a valid record.
Tests of all the error paths in log_reader.cc follow:
Cause a bad record length in the LAST block.
Wipe the middle block
Construct a string from a number
Record metadata for testing initial offset functionality
By using scratch we ensure that caller has control over the
lifetime of result.data()
Make sure reads at eof work
compact database
universal compaction
create first key range
close database
create second key range
Get rid of any state from an old run.
level compaction
delete second key range
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test for issue 178: a manual compaction causes deleted data to reappear.
commenting out the line below causes the example to work correctly
Open database. Disable compression since it affects the creation
of layers and the code below is trying to test against a very
specific scenario.
count the keys
anonymous namespace
Create a mock VersionSet
Add a third memtable to push the first memtable out of the history
Create an empty MemTableList and validate basic functions.
Create a test db if not yet created
Attempt to 'flush' to clear request for flush
namespace rocksdb
Verify keys are no longer in MemTableList
Note: now to_flush contains tables[0,1,2,4]. to_flush2 contains
tables[3].
Current implementation will only commit memtables in the order they were
created. So InstallMemtableFlushResults will install the first 3 tables
in to_flush and stop when it encounters a table not yet flushed.
Calls MemTableList::InstallMemtableFlushResults() and sets up all
structures needed to call this function.
comment: nothing not in progress of being flushed
label: requirement
Request a flush again
column_family_id
Create some MemTables
Add another table
No flush pending since the list is empty.
Create a mock Logger
Request a flush even though there is nothing to flush
Request a flush again. Should be nothing to flush
Verify that key2 from the first memtable is no longer in the history
Verify that the second memtable's keys are in the history
This will actually install 2 tables. The 1 we told it to flush, and also
tables[4] which has been waiting for tables[3] to commit.
Create a MemTable
Flush second memtable
Verify keys are present in history
Should pick 4 of 5 since 1 table has been picked in to_flush2
We now have the minimum to flush regardles of whether FlushRequested()
comment: Even though we have less than the minimum to flush, a flush is
pending since we had previously requested a flush and never called
PickMemtablesToFlush() to clear the flush.
label: code-design
Create MemTableList
Pick tables to flush
Add another tables
Fetch the newly written keys
Flush the 4 memtables that were picked in to_flush
Add 2 tables
We now have the minimum to flush regardles of whether FlushRequested()
was called.
Add second memtable to list
Create dummy mutex.
Write some keys to this memtable.
Add memtable to list
Nothing to flush
MemTable found out that this key is *not* found (at this sequence#)
Flush the 1 memtable that was picked in to_flush2
Revert flush
comment: Cleanup
label: code-design
Rollback first pick of tables
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
snapshots
Flush this memtable from the list.
(It will then be a part of the memtable history).
Create another memtable and write some keys to it
Refcount should be 0 after calling InstallMemtableFlushResults.
Verify this, by Ref'ing then UnRef'ing:
Fetch keys via MemTableList
Pick tables to flush again
Create mock default ColumnFamilyData
Make sure that merge operands are not filtered out if there's a snapshot
pointing at them
Merging with a value results in a successful merge.
The merge helper stops upon encountering a corrupt key
we have one operand that will survive because it's a delete
Filtered
make sure that we're passing user keys into the filter
namespace rocksdb
A single operand can not be merged.
<- iter_ after merge
Merging with a deletion turns the deletion into a value
sequence number is 29 here, because the first merge operand got filtered
out
when all merge operands are filtered out, we leave the iterator pointing to
the Put/Delete that survived
Filtered
Filtered
next user key
range_del_agg
filtered out all
Make sure that merge operands are filtered at the beginning
Filtered
Filtered
The compaction filter is called on every merge operand
Corrupt key
<- iter_ after merge
MergeHelper preserves the operand stack for merge operators that
cannot do a partial merge.
Merging stops before a snapshot.
If MergeHelper encounters a new key on the last level, we know that
the key has no more history and it can merge keys.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Implement 'add' directly with the new Merge operation
in this case, FullMerge should be called instead.
Imagine we are maintaining a set of uint64 counters.
Each counter has a distinct name. And we would like
to support four high level operations:
set, add, get and remove
This is a quick implementation without a Merge operation.
just treat the internal rep of int64 as the string
Apply to memtable and count the number of merges
for merge
mapped to a rocksdb Delete
namespace
DBWithTTL is not supported in ROCKSDB_LITE
Run test on TTL database
!ROCKSDB_LITE
public interface of Counters.
All four functions return false
if the underlying level db operation failed.
comment: TODO: Make this test like a general rocksdb unit-test
label: test
!ROCKSDB_LITE
mapped to a rocksdb Get
Check for any errors found during the scan
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
1+...+49 = ?
Test case 1: partial merge should be called when the number of merge
operands exceeds the threshold.
Create the batch
comment: Disable unused variable warning.
label: code-design
mapped to a rocksdb Merge operation
defaut value is 0 if non-existent
Test case 2: partial merge should not be called when a put is found.
deserialization
comment: Min merge is hard-coded to 2.
label: code-design
mapped to a levedb Put
if count >= min_merge, then partial merge should be called once.
convenience functions for testing
return default value if not found;
Get the value
Temporary remove this test
{
std::cout << "Test merge-operator not set after reopen (recovery case)\n";
{
auto db = OpenDb(dbname);
MergeBasedCounters counters(db, 0);
counters.add("test-key", 1);
counters.add("test-key", 1);
counters.add("test-key", 1);
}
DB* reopen_db;
ASSERT_TRUE(DB::Open(Options(), dbname, &reopen_db).IsInvalidArgument());
}
'add' is implemented as get -> modify -> set
An alternative is a single merge operation, see MergeBasedCounters
1+2 = 3
Verify whether the current Options Files are the latest ones.
!(defined NDEBUG) || !defined(OS_WIN)
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Make sure we always keep the latest option files.
!ROCKSDB_LITE
profile the timer cost by itself!
make perf_context_test
export ROCKSDB_TESTS=PerfContextTest.SeekKeyComparison
For one memtable:
./perf_context_test --write_buffer_size=500000 --total_keys=10000
For two memtables:
./perf_context_test --write_buffer_size=250000 --total_keys=10000
Specify --random_key=1 to shuffle the key before insertion
Results show that, for sequential insertion, worst-case Seek Key comparison
is close to the total number of keys (linear), when there is only one
memtable. When there are two memtables, even the avg Seek Key comparison
starts to become linear to the input size.
reset
Issuing a flush in the middle.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
ROCKSDB_LITE
increment the counter only when it's a DB Mutex
Path to the database on file system
In read-only mode Get(), no super version operation is needed
Start this test with a fresh DB
Return the current option configuration.
Destroy using last options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
column_family_id
Return spread of files per level
Neither key nor value should exist.
Write 120KB (10 values, each 12K)
Key doesn't exist any more but prefix exists.
100KB
namespace
generate one more file in level-0, and should trigger level-0 compaction
namespace rocksdb
Test Bloom Filter
Set only one bucket to force bucket conflict.
Test index interval for the same prefix to be 1, 2 and 4
!ROCKSDB_LITE
Compare needs to be aware of the possibility of a and/or b is
prefix only
2. Insert an entry for the same prefix as the last entry in the bucket.
4. Insert an entry with a larger prefix
Verify seeking past the prefix won't return a result.
GFLAGS
Path to the database on file system
end namespace rocksdb
both a and b are prefix
Insert keys with common prefix and one key with different
skip some options
insert x random prefix, each with y continuous element.
1. Insert one row.
note, both a and b could be prefix only
5. Insert an entry with a smaller prefix
namespace
!ROCKSDB_LITE
6. Insert to the beginning and the end of the first prefix
Show results in prefix
Only for SkipListFactory
one of them is prefix
test non-existing keys
return a slice backed by test_key
3. Insert an entry for the same prefix as the head of the bucket.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
test seek existing keys
both a and b are whole key
Only for SkipListFactory
test SeekToLast() with iterate_upper_bound_ in prefix_seek_mode
Only for SkipListFactory
test the case
iter1 iter2
| prefix | suffix | | prefix | suffix |
| 1 | 1 | | 1 | 2 |
| 1 | 3 | | 1 | 4 |
| 2 | 1 | | 3 | 3 |
| 2 | 2 | | 3 | 4 |
after seek(15), iter1 will be at 21 and iter2 will be 33.
Then if call Prev() in prefix mode where SeekForPrev(21) gets called,
iter2 should turn to invalid state because of bloom filter.
Test same result regardless of which order the range deletions are added.
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Note the Cover* tests also test cases where tombstones are inserted under a
larger one when VerifyRangeDels() runs them in reverse
snapshots
namespace rocksdb
anonymous namespace
Leave one unflushed so we can verify RepairDB's flush logic
Examine table properties to verify RepairDB() used the right options when
converting WAL->SST
Need to get path before Close() deletes db_, but delete it after Close() to
ensure Close() doesn't re-create the manifest.
ROCKSDB_LITE
namespace rocksdb
Exactly one of the key-value pairs should be in the DB now.
Need to get path before Close() deletes db_, but overwrite it after Close()
to ensure Close() didn't change the manifest.
Corrupt one of the SST files but preserve the manifest that refers to it,
then verify the DB is still usable for the intact SST.
Verify repair logic uses correct ColumnFamilyOptions when repairing a
database with different options for column families.
Replace the manifest with one that is only aware of the first SST file.
Add a couple SST files, delete the manifest, and verify RepairDB() saves
the day.
unknown_cf_opts
ROCKSDB_LITE
make sure that all WALs are converted to SSTables.
This test case invokes repair while some data is unflushed, then verifies
that data is in the db.
In this case, the manifest is valid but does not reference all of the SST
files. Expect a full recovery.
Leave one unflushed so we can verify WAL entries are properly
associated with column families.
Delete one of the SST files but preserve the manifest that refers to it,
then verify the DB is still usable for the intact SST.
Need to get path before Close() deletes db_, but delete it after Close() to
ensure Close() didn't change the manifest.
RepairDB() records the comparator in the manifest, and DB::Open would fail
if a different comparator were used.
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Verify repair logic associates SST files with their original column
families.
Also check comparator when it's provided via "unknown" CF options
Manifest is in an invalid format. Expect a full recovery.
-- Step 2: Read properties
not sanitize
PlainTable is not supported in Lite
namespace rocksdb
make sure the entries will be inserted with order.
Test properties collectors with internal keys or regular keys
for block based table
Collects keys that starts with "A" in a table.
namespace
!ROCKSDB_LITE
PlainTable is not supported in Lite
test plain table
comment: HACK: Set options.info_log to avoid writing log in
SanitizeOptions().
label: code-design
starts with 'A'
starts with 'A'
starts with 'A'
Collects keys that starts with "A" in a table. Backward compatible mode
It is also used to test internal key table property collector
deletes + single-deletes
Utilities test functions
with sanitization, even regular properties collector will be able to
handle internal keys.
sanitize
simply asssume all user keys are not empty.
-- Step 1: build table
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
just a place holder
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
minus 2X for the number of deletion entries because:
1x for deletion entry does not count as a data entry.
1x for each deletion entry will actually remove one data entry.
Call back function to add extra customized builds.
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Level 0 is not ordered
Ignored because of [5,6] in l1
Ignored because of [2,3] in l2
Ignored because of [2,3] in l2
Test whether the overlaps are detected as expected
Perfect overlap with last level
Partial overlap with last level
Partial overlap with last level
Contains range of last level
Inside range of last level
Inside range of last level
add to file_level_
comment: NOT thread safe
label: requirement
comment: TODO(icanadi) mock out VersionSet
TODO(icanadi) move other WalManager-specific tests from db_test here
label: test
did a read
TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here
ASSERT_EQ(env_->sequential_read_counter_.Read(), 1);
TEST : Create WalManager with a ttl and no size limit.
Create some archived log files and call PurgeObsoleteWALFiles().
Assert that files are not deleted
Reopen db with small ttl.
Assert that all archived logs was removed.
!ROCKSDB_LITE
Create a zero record WAL file.
Check that an empty iterator is returned
number
no new reads since the value is cached
TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here
ASSERT_EQ(env_->sequential_read_counter_.Read(), 1);
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
TEST : Create WalManager with huge size limit and no ttl.
Create some archived files and call PurgeObsoleteWALFiles().
Count the archived log files that survived.
Assert that all of them did.
Change size limit. Re-open WalManager.
Assert that archive is not greater than wal_size_limit_mb after
PurgeObsoleteWALFiles()
Set ttl and time_to_check_ to small values. Re-open db.
Assert that there are no archived logs left.
TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here.
Waiting for lei to finish with db_test
env_->count_sequential_reads_ = true;
sequential_read_counter_ sanity test
ASSERT_EQ(env_->sequential_read_counter_.Read(), 0);
column_family_id
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Try a write where the key is one slice but the value is two
One where the key is composite but the value is a single slice
It requires more than 30GB of memory to run the test. With single memory
allocation of more than 30GB.
Not all platform can run it. Also it runs a long time. So disable it.
Insert key and value of 3GB and push total batch size to 12GB.
The test requires more than 18GB memory to run it, with single memory
allocation of more than 12GB. Not all the platform can run it. So disable it.
namespace anonymous
The header size is 12 bytes. The two Puts take 8 bytes which gives total
of 12 + 8 * 2 = 28 bytes.
wal only
namespace rocksdb
!ROCKSDB_LITE
Wait here until all verification in this sync-point
callback finish for all writers.
Writers that have linked to the queue
Make sure db is a DBImpl
namespace rocksdb
Wait for the last joined writer to link to the queue.
In this way the writers link to the queue one by one.
This allows us to confidently detect the first writer
who increases threads_linked as the leader.
Verification once writers call JoinBatchGroup.
Test a simple Write
Test WriteWithCallback
check my state
check for keys
In each scenario we'll launch multiple threads to write.
The size of each array equals to number of threads, and
each boolean in it denote whether callback of corresponding
thread should succeed or fail.
who am i
!ROCKSDB_LITE
insert some keys
grab unique key
leaders gotta lead
Writers that have called JoinBatchGroup.
Test WriteWithCallback for a callback that fails
Writers that pass WriteThread::JoinBatchGroup:Wait sync-point.
no batching so everyone should be a leader
(meta test) the first WriteOP should indeed be the first
and the last should be the last (all others can be out of
order)
do all the writes
Each write thread create a random write batch and write to DB
with a write callback.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
loser has to lose
This is more than max rate. Max delayed rate will be used.
also set max delayed rate
1720 left
4170 left
1720 balance + 20000 credit = 20170 left
Use 8000, 12170 left
sleep credit 200
One refill: 10240 fileed, sleep credit generates 2000. 8000 used
7240 + 10240 + 2000 - 8000 = 11480 left
namespace rocksdb
sleep credit 2000
1000 used, 8240 left
sleep credit 300
One refill, credit 4480 balance + 3000 credit + 10240 refill
Use 8000, 9720 left
One refill: 10240 bytes allowed, 1000 used, 9240 left
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
sleep debt 624
Out of bound sleep, still 10480 left
sleep debt 0
sleep credit 100
1000 used, 7240 left
sleep credit 100
6000 used, 4480 left.
Need a refill
sleep debt 824
1000 used, 10480 left.
sleep debt 1000
Rate reset after changing the token.
Read "foo".
empty folder returns empty vector
if dir is a file, returns IOError
Returns a vector of 0 or 1 Env*, depending whether an Env is registered for
TEST_ENV_URI.
The purpose of returning an empty vector (instead of nullptr) is that gtest
ValuesIn() will skip running tests when given an empty collection.
Normalizes trivial differences across Envs such that these test cases can
run on all Envs.
Check that the file exists.
necessary for default POSIX env
Read "d".
namespace rocksdb
Read "hello".
anonymous namespace
Check that the directory is empty.
non-exist directory returns IOError
Write to the file.
Try to skip past end of file.
don't know whether it's file or directory, try both. The tests must
only create files or empty directories, so one must succeed, else the
directory's corrupted.
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Removes . and .. from directory listing
Check that opening non-existent file fails.
Random reads.
Check that renaming works.
Read "world".
Too high offset.
ROCKSDB_LITE
Check that deleting works.
Read sequentially.
fail because file already exists
Check that renaming overwriting works
These are no-ops, but we test they return success.
Check for expected size.
Create a file.
folder with contents returns relative path to test dir
Try reading past EOF.
Create file.
To ensure that Env::GetUniqueId-related tests work correctly, the files
should be stored in regular storage like "hard disk" or "flash device",
and not on a tmpfs file system (like /dev/shm and /tmp on some systems).
Otherwise we cannot get the correct id.
This function serves as the replacement for test::TmpDir(), which may be
customized to be on a file system that doesn't work with GetUniqueId().
Write a page worth of 'b' right after the first sector
Shrink to 1 thread
If $TEST_IOCTL_FRIENDLY_TMPDIR/rocksdb.XXXXXX fits, use
$TEST_IOCTL_FRIENDLY_TMPDIR; subtract 2 for the "%s", and
add 1 for the trailing NUL byte.
The last task finishes. Task 0 running, 2 waiting.
Create the files
Test that all WritableFileWrapper forwards all calls to WritableFile.
Delete the files
call IncBackgroundThreadsIfNeeded to two pools. One increasing and
the other decreasing
Write to file
Enqueue 5 more tasks. Thread pool size now is 4.
Task 0, 3, 4, 5 running;6, 7 waiting.
Increase to 5 threads. Task 0 and 2 running.
comment: Clean up
label: code-design
Schedule 3 tasks. 0 running; Task 1, 2 waiting.
Only works in linux platforms
Small write should preallocate one block
use $TEST_IOCTL_FRIENDLY_TMPDIR value
only works in linux platforms
Get Unique ID again after waiting some time.
ignore failure
Wake up the last thread
Try fallocate in a file to see whether the target file system supports
it.
Skip the test if fallocate is not supported.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
verify that preallocated blocks were deallocated on file close
Because the FS might give us more blocks, we add a full page to the size
and expect the number of blocks to be less or equal to that.
Write an entire preallocation block, make sure we increased by two.
!defined(ROCKSDB_LITE) && !defined(OS_WIN)
Remove it with a different tag
Wake up task 0, 3 and 4. Task 5, 6, 7 running.
48 bytes for extra information + bytes allocated
Data structures to signal tasks to run.
Wait until the thread pools are empty.
namespace
Pointer to shared slot
Order# for the execution of this callback
Hold jobs to schedule;
Set number of thread to 1 first.
!defined(ROCKSDB_LITE)
Change number of threads a couple of times while there is no sufficient
tasks.
No writes should mean no preallocation
Wake up thread 8
ROCKSDB_FALLOCATE_PRESENT
Wake up thread 9.
Enqueue thread 8 and 9. Task 5 running; one of 8, 9 might be running.
comment: Determine whether we can use the FS_IOC_GETVERSION ioctl
on a file in directory DIR. Create a temporary file therein,
try to apply the ioctl (save that result), cleanup and
return the result. Return true if it is supported, and
false if anything fails.
Note that this function "knows" that dir has just been created
and is empty, so we create a simply-named test file: "f".
label: code-design
Shrink back to 1 thread. Still task 0, 1 running, 2 waiting
Remove it from the queue with the right tag
not TRAVIS
OS_LINUX || OS_WIN
mkdtemp failed: diagnose it, but don't give up.
Delete the file
namespace rocksdb
Write a page worth of 'a'
Diagnose ioctl-related failure only if this is the
directory specified via that envvar.
Returns true if any of the strings in ss are the prefix of another string.
Trigger jobs to run.
Schedule in different order than start time
!ROCKSDB_LITE
Travis doesn't support fallocate or getting unique ID from files for whatever
reason.
When we have n == -1 there is not a terminating zero expected
verify that blocks are preallocated
Note here that we don't check the exact number of blocks preallocated --
we only require that number of allocated blocks is at least what we
expect.
It looks like some FS give us more blocks that we asked for. That's fine.
It might be worth investigating further.
Write five more blocks at once, ensure we're where we need to be.
Only works in linux and WIN platforms
wait for all jobs to finish
Test that the two ways to get children file attributes (in bulk or
individually) behave consistently.
Unblock background thread
Genrate random data
Random Read
Write to mirror string
Increase to 2 threads. Task 0, 1 running; 2 waiting
Pick random offset for read
Wake up threads 7. Task 5 running
Schedule another task
make sure we don't have more than pool_size_ jobs running.
Shrink back to 1 thread. Still task 5, 6, 7 running
Check whether a bunch of concurrently existing files have unique IDs.
Check that after file is deleted we don't get same ID again in a new
file.
Pick random offset for write
Block the low priority queue
Wait a short while for the jobs to be dispatched.
allocate 100 MB
Get Unique ID
Reopen the file every 500 iters
The filesystem containing the file does not support fallocate
Verify the above
Check IDs are the same.
"[DEBUG] "
Get Unique ID again
schedule same number of jobs in each pool
Wake up task 6. Task 5, 7 running
Close file and reopen it
close the file, should deallocate the blocks
Increase to 4 threads. Task 5, 8, 9 running.
Collect and check whether the IDs are unique.
The file now has 1 sector worth of a followed by a page worth of b
comment: clean up
label: code-design
Sequential Read
Sync + corrupt => no change
Corrupted
Add new data and corrupt it
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
this will be true unless test runs for 2 seconds
namespace rocksdb
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseException
* Signature: ()V
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseExceptionWithStatusCodeSubCode
* Signature: ()V
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseExceptionWithStatusCodeState
* Signature: ()V
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseExceptionWithStatusCode
* Signature: ()V
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseExceptionNoMsgWithStatusCodeSubCode
* Signature: ()V
* Class: org_rocksdb_RocksDBExceptionTest
* Method: raiseExceptionNoMsgWithStatusCode
* Signature: ()V
column_family_id
* Class: org_rocksdb_WriteBatchTestInternalHelper
* Method: setSequence
* Signature: (JJ)V
comment: todo: Currently the following code is directly copied from
db/write_bench_test.cc. It could be implemented in java once
all the necessary components can be accessed via jni api.
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
This file implements the "bridge" between Java and C++ and enables
calling c++ rocksdb::WriteBatch methods testing from Java side.
* Class: org_rocksdb_WriteBatchTest
* Method: getContents
* Signature: (J)[B
exception thrown: ArrayIndexOutOfBoundsException
exception thrown: OutOfMemoryError
* Class: org_rocksdb_WriteBatchTestInternalHelper
* Method: append
* Signature: (JJ)V
* Class: org_rocksdb_WriteBatchTestInternalHelper
* Method: sequence
* Signature: (J)J
re-open db and read from start to end
integer keys should be in ascending
order as defined by SimpleIntComparator
*
* Abstract tests for both Comparator and DirectComparator
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Get a comparator which will expect Integer keys
* and determine an ascending order
*
* @return An integer ascending order key comparator
*
* Compares integer keys
* so that they are in ascending order
*
* @param a 4-bytes representing an integer key
* @param b 4-bytes representing an integer key
*
* @return negative if a < b, 0 if a == b, positive otherwise
does key already exist (avoid duplicates)
generate a different key
*
* Test which stores random keys into a column family
* in the database
* using an @see getAscendingIntKeyComparator
* it then checks that these keys are read back in
* ascending order
*
* @param db_path A path where we can store database
* files temporarily
*
* @throws java.io.IOException if IO error happens.
store 10,000 random integer keys
protect against int key calculation overflow
does key already exist (avoid duplicates)
generate a different key
*
* Test which stores random keys into the database
* using an @see getAscendingIntKeyComparator
* it then checks that these keys are read back in
* ascending order
*
* @param db_path A path where we can store database
* files temporarily
*
* @throws java.io.IOException if IO error happens.
Verify that backups exist
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
restore the backup
restore db from latest backup
Fill database with some test values
Create four backups
close the database
Values must have suffix V2 because of restoring latest backup.
Create two backups
The latest backup must remain.
*
* Verify backups.
*
* @param be {@link BackupEngine} instance.
* @param expectedNumberOfBackups numerical value
* @throws RocksDBException thrown if an error occurs within the native
* part of the library.
Open empty database.
restore db from first backup
Open database again.
The second backup must remain.
*
* Fill database with some test values.
*
* @param db {@link RocksDB} instance.
* @throws RocksDBException thrown if an error occurs within the native
* part of the library.
Delete everything except the latest backup
Delete the first backup
negative will be mapped to 0
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
no-op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
no op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Size has to be positive
setup sample properties
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
iterate over new_cf key/value pairs
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
found value which fits in outValue
found value which fits partially
check if key is merged
Test listColumnFamilies
Test open database with column family names
not found value
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
UseAdaptiveMutex test
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Will be abc3 because the next one after abc999
is abc3
Seek for abc
Will be invalid because abc is after abc1
test the round-tripability of keys written and read with the Comparator
Iterate over keys using a iterator
Get last one
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
setup sample properties
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
no-op
Test with parameter initialization
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
test the round-tripability of keys written and read with the DirectComparator
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
clear first slice
get first char in otherslice
remove prefix
make sure we don't double-free
no-op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
new Bloom filter
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Identify the last line of the header
As InfoLogLevel is set to FATAL_LEVEL, here we expect the log
content to be empty.
*
* Read LOG file contents into String.
*
* @return LOG file contents as String.
* @throws IOException if file is not found.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
KeyMayExist in CF1 must return false
Test with column family
Test without column family
Test without column family but with readOptions
Test with column family and readOptions
no op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Set custom logger to options
messages shall be received due to previous actions.
change log level to debug level
Create new logger with max log level passed by options
comment: there should be more than zero received log messages in
debug level.
label: code-design
there should be zero messages
using fatal level as log level.
comment: there should be zero messages
using warn level as log level.
label: code-design
Test HashSkipListMemTableConfig
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
writing aa under key
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test also with createColumnFamily
test replace one with another merge operator instance
merge bb under key
writing xx under cfkey2
test param init
merge yy under cfkey2
comment: test reuse
label: code-design
Writing aa under key
Writing bb under key
no-op
Test Optimize for statements
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Set a table factory and check the names
Free instances
Initialize a dbOptions object from cf options and
db options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Size has to be positive
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test with parameter initialization
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Determine if OS is 32-Bit/64-Bit
*
* @return boolean value indicating if operating system is 64 Bit.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Helper class to get the appropriate Random class instance dependent
* on the current platform architecture (32bit vs 64bit)
*
* Factory to get a platform specific Random instance
*
* @return {@link java.util.Random} instance.
*
* Random32Bit is a class which overrides {@code nextLong} to
* provide random numbers which fit in size_t. This workaround
* is necessary because there is no unsigned_int < Java 8
*
* Utility class constructor
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
test that put fails in readonly mode
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
no-op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
open database
fill database with key/value pairs
found value which fits in outValue
Because we only compacted those keys we issued
in this round, there shouldn't be any L1 -> L2
compaction. So we expect zero L2 files here.
add non existing key
test same call with readOptions
test same method with ReadOptions
Making sure there isn't any L0 files.
not found value
Making sure there are some L1 files.
Here we only use != 0 instead of a specific number
as we don't want the test make any assumption on
how compaction works.
Disable auto L0 -> L1 compaction
Make sure we do create one more L0 files.
merge key1 with another value portion
Compact all L0 files we just created
To disable auto compaction
merge on non existent key shall insert the value
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
found value which fits partially
remove existing key
a slightly bigger write buffer than L0 file
so that we can ensure manual flush always
go before background flush happens.
default rocksenv will always return zero for compaction pool
no matter what was set via setBackgroundThreads
default rocksenv will always return zero for flush pool
no matter what was set via setBackgroundThreads
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
verify otherDb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
read key/value pairs after flush using MemEnv
shall throw an exception because db dir does not
exist.
write key/value pairs using MemEnv
to db and to otherDb.
db - keys
Check iterator access
write key/value pairs using MemEnv
values
After reopen the values shall still be in the mem env.
as long as the env is not freed.
read key/value pairs using MemEnv
verify key/value pairs after flush using MemEnv
reached end of database
flush
otherDb - keys
verify db
*
* Resource to trigger garbage collection after each test
* run.
*
* @deprecated Will be removed with the implementation of
* {@link RocksObject#finalize()}
make sure we don't double-free
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
setting null to snapshot in ReadOptions leads
to no Snapshot being used.
read with previously created snapshot will
read previous version of key value pair
results must be the same with new Snapshot
instance using the same native pointer
iterate using a snapshot
snapshopot was created before newkey
retrieve key value pair created before
the snapshot was made
set snapshot in ReadOptions
iterate over current state of db
Get new Snapshot of database
set snapshot in ReadOptions
add new key/value pair
iterate using a snapshot on default column family
Retrieve snapshot from read options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
release Snapshot
iterate over current state of column family
using no snapshot the latest db entries
will be taken into account
update key value pair to newvalue
retrieve key value pair
Get new Snapshot of database
read for newkey using the snapshot must be
null
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
insert 5 writes into a cf
the latest sequence number is 5 because 5 puts
were written beforehand
Get updates since the beginning
the latest sequence number is 10 because
(5 + 5) puts were written beforehand
The first sequence number is 1
reopen
no-op
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Convert an int to 4 bytes
*
* @param v The int
*
* @return A byte array containing 4 bytes
*
* Simple type conversion methods
* for use in tests
*
* Convert first 4 bytes of a byte array to an int
*
* @param data The byte array
*
* @return An integer
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Returns a copy of the current events list
*
* @return a list of the events which have happened upto now
compare the results to the test data
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* A simple WriteBatch Handler which adds a record
* of each event that it receives to a list
attempt to read test data back from the WriteBatch by iterating
with a handler
setup test data
load test data to the write batch
*
* Enumeration of Write Batch
* event actions
without previous corresponding setSavePoint
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
*
* This class mimics the db/write_batch_test.cc
* in the c++ rocksdb library.
* <p/>
* Not ported yet:
* <p/>
* Continue();
* PutGatherSlices();
*
* Package-private class which provides java api to access
* c++ WriteBatchInternal.
submit the callables
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
put data to the write batch and make sure we can read it.
add zero byte value
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
update k2 in the write batch and check the value
add put records
remove k1 and make sure we can read back the write
reverse iterative access
add a deletion record
forward iterative access
reinsert k1 and make sure we see the new value
without previous corresponding setSavePoint
Arrays.equals(key, iterator.key()) ensures an exact match in Rocks,
instead of a nearest match
direct access - seek to key offsets
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
*
* Custom Junit Runner to print also Test classes
* and executed methods to command prompt.
*
* Listener which overrides default functionality
* to print class and method to system out.
*
* Main method to execute tests
*
* @param args Test classes as String names
*
* RocksJunitListener constructor
*
* @param system JUnitSystem
*
* Is `a` a prefix of `b`
*
* @return The length of the matching prefix, or 0 if it is not a prefix
put
*
* Open the database using the Java ReverseBytewiseComparator
* and test the results against another Java ReverseBytewiseComparator
Seek to First
Next
Seek to random key
Random walk and make sure iter and result_iter returns the
same key and value
Prev
*
* Open the database using the C++ BytewiseComparatorImpl
* and test the results against our Java DirectBytewiseComparator
*
* Open the database using the C++ BytewiseComparatorImpl
* and test the results against our Java BytewiseComparator
*
* Open the database using a C++ Comparator
Seek to last
note that calling value on a non-valid iterator from the Java API
results in a SIGSEGV
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
delete
*
* Open the database using the Java BytewiseComparator
* and test the results against another Java BytewiseComparator
*
* Open the database using a Java Comparator
*
* Open the database using the Java DirectBytewiseComparator
* and test the results against another Java DirectBytewiseComparator
*
* Open the database using the C++ ReverseBytewiseComparatorImpl
* and test the results against our Java ReverseBytewiseComparator
*
* This is a direct port of various C++
* tests from db/comparator_db_test.cc
* and some code to adapt it to RocksJava
UNIX
Linux
AIX
Copyright (c) 2014, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Check keys exist.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Advance to next key in the valid key space
Our test skip list stores 8-byte unsigned integers
Seek to middle
Backward iteration test
Simple iterator tests
namespace rocksdb
comment: Simple test that does single-threaded testing of the ConcurrentTest
scaffolding.
label: test
Remember the initial committed state of the skiplist.
Seek to end
Compare against model iterator
InlineSkipList is not protected by mu_. We just use a single writer
thread to modify it.
Note that generation 0 is never inserted, so it is ok if
<*,0,*> is missing.
Iterate over the list, make sure keys appears in order and no extra
keys exist.
REQUIRES: No concurrent calls to WriteStep or ConcurrentWriteStep
Validate the list is well-formed.
Seek to beginning
REQUIRES: No concurrent calls for the same k
Per-key generation
Verify that everything in [pos,current) was not present in
initial_state.
Current state of the test
We sometimes pass K to seek to the end of the skiplist
comment: We want to make sure that with a single writer and multiple
concurrent readers (with no synchronization other than when a
reader's iterator is created), the reader always observes all the
data that was present in the skip list when the iterator was
constructor. Because insertions are happening concurrently, we may
also observe new values that were inserted since the iterator was
constructed, but we should never miss any values that were present
at iterator construction time.
We generate multi-part keys:
<key,gen,hash>
where:
key is in range [0..K-1]
gen is a generation number for key
hash is hash(key,gen)
The insertion code picks a random key, sets gen to be 1 + the last
generation number inserted for that key, and sets hash to Hash(key,gen).
At the beginning of a read, we snapshot the last inserted
generation number for each key. We then iterate, including random
calls to Next() and Seek(). For every key we encounter, we
check that it is either expected given the initial snapshot or has
been concurrently added since the iterator started.
label: code-design
Forward iteration test
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
SkipList is not protected by mu_. We just use a single writer
thread to modify it.
Advance to next key in the valid key space
Seek to middle
Backward iteration test
Simple iterator tests
namespace rocksdb
comment: Simple test that does single-threaded testing of the ConcurrentTest
scaffolding.
label: test
Remember the initial committed state of the skiplist.
Seek to end
Compare against model iterator
Note that generation 0 is never inserted, so it is ok if
<*,0,*> is missing.
Seek to beginning
Per-key generation
REQUIRES: External synchronization
Verify that everything in [pos,current) was not present in
initial_state.
Current state of the test
We sometimes pass K to seek to the end of the skiplist
comment: We want to make sure that with a single writer and multiple
concurrent readers (with no synchronization other than when a
reader's iterator is created), the reader always observes all the
data that was present in the skip list when the iterator was
constructor. Because insertions are happening concurrently, we may
also observe new values that were inserted since the iterator was
constructed, but we should never miss any values that were present
at iterator construction time.
We generate multi-part keys:
<key,gen,hash>
where:
key is in range [0..K-1]
gen is a generation number for key
hash is hash(key,gen)
The insertion code picks a random key, sets gen to be 1 + the last
generation number inserted for that key, and sets hash to Hash(key,gen).
At the beginning of a read, we snapshot the last inserted
generation number for each key. We then iterate, including random
calls to Next() and Seek(). For every key we encounter, we
check that it is either expected given the initial snapshot or has
been concurrently added since the iterator started.
label: code-design
Forward iteration test
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Allocate another 2MB
90% of the hard limit will hit the condition
A write buffer manager of size 256MB
1GB cache
Still need flush as the hard limit hits
Allocate another 20MB
Free 2MB will not cause any change in cache cost
ROCKSDB_LITE
namespace rocksdb
15 MB total, 8MB mutable.
A write buffer manager of size 50MB
Allocate another 30MB
Allocate 1.5MB will allocate 2MB
Every free will release 1MB if still not hit 3/4
Scheduling for freeing will release the condition
Destory write buffer manger should free everything
9MB total, 8MB mutable.
Free 20MB will releae 1MB from cache
A write buffer manager of size 10MB
11MB total, 6MB mutable. hard limit still hit
11MB total, 4MB mutable. hard limit stills but won't flush because more
than half data is already being flushed.
99 * 250 / 100
95 * 250 / 100
50 * 250 / 100
(1 + 250) / 2
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
dropping oldest window with value 2, remaining 3 ~ 5
99 * 110 / 100
95 * 110 / 100
50 * 110 / 100
(1 + 110) / 2
dropping oldest window with value 1, remaining 2 ~ 4
namespace rocksdb
fill up to bucket [70, 110)
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Sanity check to make sure that contents and order of TickersNameMap
match Tickers enum
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
If the test fails, likely a new option is added to DBOptions
but it cannot be set through GetDBOptionsFromString(), or the test is not
updated accordingly.
After adding an option, we need to make sure it is settable by
GetDBOptionsFromString() and add the option to the input string passed to
DBOptionsFromString()in this test.
If it is a complicated type, you also need to add the field to
kDBOptionsBlacklist, and maybe add customized verification for it.
namespace rocksdb
Items in the form of <offset, size>. Need to be in ascending order
and not overlapping. Need to updated if new pointer-option is added.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
GFLAGS
Need to update the option string if a new option is added.
This option is not setable:
comment: It based on the behavior of compiler that padding bytes are not changed
when copying the struct. It's prone to failure when compiler behavior
changes. We verify there is unset bytes to detect the case.
label: code-design
Following options are not settable through
GetColumnFamilyOptionsFromString():
!__clang__
OS_LINUX || OS_WIN
!ROCKSDB_LITE
In this test, we catch a new option of BlockBasedTableOptions that is not
settable through GetBlockBasedTableOptionsFromString().
We count padding bytes of the option struct, and assert it to be the same
as unset bytes of an option struct initialized by
GetBlockBasedTableOptionsFromString().
Construct the base option passed into
GetBlockBasedTableOptionsFromString().
If the test fails, likely a new option is added to BlockBasedTableOptions
but it cannot be set through GetBlockBasedTableOptionsFromString(), or the
test is not updated accordingly.
After adding an option, we need to make sure it is settable by
GetBlockBasedTableOptionsFromString() and add the option to the input string
passed to the GetBlockBasedTableOptionsFromString() in this test.
If it is a complicated type, you also need to add the field to
kBbtoBlacklist, and maybe add customized verification for it.
Verify options are settable from options strings.
We take the approach that depends on compiler behavior that copy constructor
won't touch implicit padding bytes, so that the test is fragile.
As a result, we only run the tests to verify new fields in options are
settable through string on limited platforms as it depends on behavior of
compilers.
options in the blacklist need to appear in the same order as in
ColumnFamilyOptions.
If the test fails, likely a new option is added to ColumnFamilyOptions
but it cannot be set through GetColumnFamilyOptionsFromString(), or the
test is not updated accordingly.
After adding an option, we need to make sure it is settable by
GetColumnFamilyOptionsFromString() and add the option to the input
string passed to GetColumnFamilyOptionsFromString()in this test.
If it is a complicated type, you also need to add the field to
kColumnFamilyOptionsBlacklist, and maybe add customized verification
for it.
Count padding bytes by setting all bytes in the memory to a special char,
copy a well constructed struct to this memory and see how many special
bytes left.
Deprecatd option which is not initialized. Need to set it to avoid
Valgrind error
persist the change of prefix_extractor
table_factory
only digits and dots are allowed
Missing option name
Phase 1: randomly assign base_opt
custom type options
Invalid chars after closing curly brace
change the compaction filter
GetColumnFamilyOptionsFromString is not supported in
ROCKSDB_LITE
Random Construct a string
Further verify pointer-typed options
Wrong name "max_write_buffer_number_"
default for VerifyDBOptions
compaction_filter_factory
Empty key
unrecognized filter policy name
unrecognized checksum type
Phase 3: Set new_options from the derived string and expect
new_options == base_options
new_opt_mat
Error Paring value
merge_operator
change the compaction filter factory
Multi-level nested options
ROCKSDB_LITE
use same prefix extractor but with different parameter
Phase 2: obtain a string from base_opt
change the merge operator
Units (m)
Nested plain table options
Empty
unrecognized index type
Empty value
change the name of merge operator back-and-forth
if true, '\' together with str[i + 1] is not a valid escape.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
However this is valid!
This two transformations should be canceled and should output
the original input.
Value with '='
GetPlainTableOptionsFromString is not supported
Units (k)
Phase 3: Set new_opt from the derived string and expect
new_opt == base_opt
Overwrriten option
namespace
input_strings_escaped
Regular options
!ROCKSDB_LITE
namespace rocksdb
Phase 2: obtain a string from base_option
set compaction_filter to nullptr and expect non-ok status
Make sure block-based table factory options was deserialized correctly
if there're two consecutive '\'s, skip the second one.
must have at least one digit before each dot
must have at least one digit after each dot
set the value back and expect ok status
Units (g)
from CheckOptionsCompatibility
Invalid block based table option
change the name of the compaction filter factory back-and-forth
new_opt_map
Add a random character
Change prefix extractor from non-nullptr to nullptr
Wrong key/value pair
can only contains at most one dot.
options_file_version must be at least one
GetOptionsFromMap is not supported in ROCKSDB_LITE
GetBlockBasedTableOptionsFromString is not supported
don't overwrite block based table options
!ROCKSDB_LITE
Last one
change the name and expect non-ok status
Phase 1: Make big change in base_options
change the name and expect non-ok status
Non-empty
make sure default values are overwritten by something else
change the name back and expect ok status
Okay to change prefix_extractor form nullptr to non-nullptr
default for VerifyCFOptions
memtable factory
Empty nested options
unrecognized filter policy config
change the table factory
expect pass only in kSanityLevelLooselyCompatible
expect pass as it's safe to change prefix_extractor
from non-null to null
With random spaces
prefix_extractor
GFLAGS
persist the change
StringToMap is not supported in ROCKSDB_LITE
comment: repeat the test with FixedPrefixTransform
label: test
set table_factory to nullptr and expect non-ok status
default ColumnFamilyOptions
test by setting memtable_factory to nullptr
test by setting table_factory to nullptr
compaction_filter
ignore_unknown_options
Unexpected chars after closing curly brace
GetMemTableRepFactoryFromString is not supported
comment: Mismatch curly braces
label: code-design
since we already handle those two consecutive '\'s in
the next if-then branch, any '\' appear at the end
of an escaped string in such case is not valid.
Units (t)
test by setting compaction_filter to nullptr
from CheckOptionsCompatibility
Nested block based table options
Empty
GetOptionsFromString is not supported in RocksDB Lite
Regular nested options
set memtable_factory to nullptr and expect non-ok status
unknow options should fail parsing without ignore_unknown_options = true
Make sure segfault is not hit by semi-random strings
unknown option
unrecognized EncodingType
comment: Garbage inside curly braces
label: code-design
Replace random position to space
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Global operators to be replaced by a linker when this file is
a part of the build
Second filter
Test for block based filter block
use new interface in FilterPolicy to create filter builder/reader
For testing: emit an array with one hash value per key
Last filter
Check third filter (empty)
Check first filter
Check last filter
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2012 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace rocksdb
Third filter is empty
Check second filter
First filter
Return true if any byte in this range was Marked
Generate random key value pairs.
The generated key will be sorted. You can tune the parameters to generated
different kinds of test key/value pairs for different scenario.
read contents of block sequentially
read block contents randomly
generate different prefix
create block reader
In this test case, no two key share same prefix.
search in block for this key
find a random key in the lookaside array
namespace rocksdb
compare with lookaside array
Seek existent keys
A slow and accurate version of BlockReadAmpBitmap that simply store
all the marked ranges in a set.
last key id
step
Generate keys with same prefix.
first key id
last key id
step
padding size,
Add only half of the keys
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Error in read amplification will be less than 2% if we are reading
randomly
restart interval
Error in read amplification will be less than 1% if we are reading
sequentially
generating keys that shares the prefix
read serialized contents of the block
read kv from block
Read the block sequentially using Seek()
first key id
Seek non-existent keys.
For hash index, if no key with a given prefix is not found, iterator will
simply be set as invalid; whereas the binary search based iterator will
return the one that is closest.
padding size (8 bytes randomly generated suffix)
add a bunch of records to a block
1 byte
32 bytes
61 bytes
64 bytes
0.5 KB
1 KB
4 KB
10 KB
50 KB
1 MB
4 MB
10 MB
Read the block randomly
for each prefix, there will be 5 keys starts with it.
return the block contents
block test
Generate some random entries
100 bytes values
Read the block sequentially using Next()
res = 5;
namespace rocksdb
res = 2;
res = 2 * 3;
res = 5;
res = 5 * 7;
comment: the first Cleanup is on stack and the rest on heap,
so test all the combinations of them
label: code-design
comment: Putting the PinnableSlice tests here due to similarity to Cleanable tests
label: test
~Cleanable
res = 5 * 7;
comment: Test the Reset does cleanup
label: code-design
res = 2;
res = 2;
res = 2 * 5 * 7;
comment: the first Cleanup is on stack and the rest on heap, so test with both cases
label: code-design
res = 2 * 3;
Test Clenable is usable after Reset
res = 2;
res = 2 * 3;
res = 2 * 3 * 5 * 7;
res = 2;
res = 2 * 3;
res = 2 * 3 * 5;
comment: Use this to keep track of the cleanups that were actually performed
label: code-design
comment: ~Cleanable
cleanups must have be delegated to value
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
column_family_id
i is not one of the expected locations. Empty bucket.
Assert Table Properties.
Have two hash functions. Insert elements with overlapping hashes.
Finally insert an element with hash value somewhere in the middle
so that it displaces all the elements after that.
comment: Need to have a temporary variable here as VS compiler does not currently
support operator= with initializer_list as a parameter
label: code-design
ROCKSDB_LITE
comment: Check unused bucket.
label: code-design
Check that all keys wereReader found.
Check contents of the bucket.
Have two hash functions. Insert elements with overlapping hashes.
Finally try inserting an element with hash value somewhere in the middle
and it should fail because the no. of elements to displace is too high.
namespace
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Read file
Give disjoint hash values.
namespace.
Give disjoint hash values, in reverse order.
Methods, variables related to Hash functions.
comment: Test read when key is unused key.
label: code-design
Last level file.
Check reader now.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Create last level file as we are interested in measuring performance of
last level file only.
namespace rocksdb
GFLAGS.
column_family_id
Search for a key with colliding hash values.
Value is just a part of key.
Assume only the fast path is triggered
namespace
Assume no merge/deletion
Search for a key with an independent hash value.
ROCKSDB_LITE
Test with collision. Make all hash values collide.
Add hash values that map to empty buckets.
These numbers are chosen to have a hash utilization % close to
0.9, 0.75, 0.6 and 0.5 respectively.
They all create 128 M buckets.
Add keys with colliding hash values.
Make all hash values collide.
Performance tests
Remain same symantic with blockbased filter
Generate the filter using the keys that are added
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Add Key to filter
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
1 is 2nd level index
assuming a good hash function
comment: unused
label: code-design
A low number ensures cutting a block after each key
querying missing keys
querying a key twice
Querying added keys
Initialize what Open normally does as much as necessary for the test
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
last two keys make one flush
namespace rocksdb
Otherwise BlockBasedTable::Close
will access variable that are not
initialized in our mocked version
Assuming a block is cut, add an entry to the index
handle
A regression test to avoid data race described in
https://github.com/facebook/rocksdb/issues/1267
Use shorter block size for tests to exercise block boundary
conditions more.
reset the cache and reopen the table
the key is greater than any existing keys.
Only data block will be accessed
-- Find keys do not exist, but have common prefix.
rerun with different block cache
Close the table
Open the block
small block size to get big index block
Enable the cache for index/filter blocks
8 is seq size, 9 k-v totally
keys_not_in_cache=
invalid
Get non-existing key
comment: Check if the fetched props matches the expected ones.
TODO(kailiu) Use this only when you disabled filter policy!
label: code-design
Cache hit, bytes read from cache should increase
global_seqno
convert_to_internal_key_
Make each key/value an individual block
Helper function to get version, global_seqno, global_seqno_offset
ROCKSDB_LITE
Binary search index
preloading filter/index blocks is prohibited.
the key/val are slightly smaller than block size, so that each block
holds roughly one key/value pair.
The purpose of this test is to test the prefetching operation built into
BlockBasedTable.
prefixes that don't exist
Tests against all kinds of tables
Verify Seek
Create a bunch of keys with 10 filters.
no filter policy is used
version
NOTE: to help better highlight the "detla" of each ticker, I use
<last_value> + <added_value> to indicate the increment of changed
value; other numbers remain the same.
index block hit
find the upper bound of prefixes
assert our expectation in cache warmup
comment: a hack that just to trigger BlockBasedTable::GetFilter.
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
seqno=4 is less than 3 so we still should get our key
Default comparator
Test iterating
Return reverse of "key".
Used to test non-lexicographic comparators.
column_family_id
ASSERT_OK(regular_iter->status());
Each time we load one more key to the table. the table index block
size is expected to be larger than last time's.
Test point lookup
only one kv
This test serves as the living tutorial for the prefix scan of user collected
properties.
with block-based, we read index and then the filter
namespace
data block hit
Both index and data block get accessed.
It first cache index block then data block. But since the cache size
is only 1, index block will be purged after data block is inserted.
A helper class that converts internal format keys into user keys
Generate table without filter policy
Test the empty key
-- PART 1: Open with regular block cache.
Since block_cache is disabled, no cache activities will be involved.
We get the following data spread :
Data block Index
========================
[ k01 k02 k03 ] k03
[ k04 ] k04
[ k05 ] k05
[ k06 k07 ] k07
Update global sequence number to 3
No merge operator
In order to make all tests run for plain table format, including
those operating on empty keys, create a new prefix transformer which
return fixed prefix if the slice is not shorter than the prefix length,
and the full slice if it is shorter.
No property collectors
if DB is opened with a prefix extractor of a different name,
prefix bloom is skipped when read the file
release the iterator so that the block cache can reset correctly.
upconvert legacy block based
A simple PrefixExtractor that only works for test PrefixAndWholeKeyTest
No filter policy is used
Create a table
index block miss
Generate table with filter policy
Data block will be in cache
null keys
nothing happens in the beginning
find keys with prefix that don't match any of the existing prefixes.
Block cache can contain raw data blocks as well as general objects. If an
object depends on the table to be live, it then must be destructed before the
table is closed. This test makes sure that the only items remains in the
cache after the table is closed are raw data blocks.
namespace rocksdb
Construct the data structure from the data in "data"
DummyPropertiesCollector used to test BlockBasedTableProperties
version == 2
Helper function to get the contents of the table InternalIterator
prefetch
data, index and filter block
bloom_filter_type = 0 -- block-based filter
bloom_filter_type = 0 -- full filter
invalid values for block_restart_interval (<1) are silently set to 1
key_range=
Hash search index with hash_index_allow_collision
find existing keys
At first, no block will be accessed.
This test include all the basic checks except those for index size and block
size, which will be conducted in separated unit tests.
preloading filter/index blocks is enabled.
!ROCKSDB_LITE
Plain table is not supported in ROCKSDB_LITE
filter is already in memory and it figures out that the key doesn't
exist
k04 and k05 will be in two consecutive blocks, the index is
an arbitrary slice between k04 and k05, either before or after k04a
Trigger compaction.
In the second round, turn whole_key_filtering off and expect
rocksdb still works.
seek the first element in the block
xxhash block based
prefixes that exist
ASSERT_TRUE(regular_iter->Valid());
A wrapper around LRICache that also keeps track of data blocks (in contrast
with the objects) in the cache. The class is very simple and can be used only
for trivial tests.
invalid values for block_size_deviation (<0 or >100) are silently set to 0
Check that when we reopen a table we don't lose access to blocks already
in the cache. This test checks whether the Table actually makes use of the
unique ID from the file.
big enough so we don't ever lose cached values.
Hash search index with filter policy
Due to the difficulities of the intersaction between statistics, this test
only tests the case when "index block is put to block cache"
Cache miss, Bytes read from cache should not change
Release pinnable slice reousrces
just the data block
Something small to force merging
Hash search index
keys_in_cache=
Returns nullptr if not running against a DB
Verify data size.
PlainTable expects internal key structure
Replace the deleter with our own so that we keep track of data blocks
erased from the cache
last key
For second iteration, delete the table reader object and verify the
iterator can still access its metablock's range tombstones.
data block miss
odd
index will be added to block cache.
index block miss
If the item was marked for being data block, decrease its usage from the
total data block usage of the cache
Return something larger than an existing key
Overridden in DBConstructor
Make sure, by default, index/filter blocks were pre-loaded (meaning we won't
use block cache to store them).
if (!BZip2_Supported()) {
fprintf(stderr, "skipping bzip2 compression tests\n");
} else {
compression_state.push_back(kBZip2Compression);
}
A simple tool that takes the snapshot of block cache statistics.
Edge cases
Attempt to return something smaller than an existing key
This is called by the application right after inserting a data block
-- PART 2: Open with very small block cache
In this test, no block will ever get hit since the block cache is
too small to fit even one entry.
Test point lookup
Finish constructing the data structure with all the keys that have
been added so far. Returns the keys in sorted order in "*keys"
and stores the key/value pairs in "*kvmap"
The only usage must be for marked data blocks
comment: we need to use random keys since the pure human readable texts
may be well compressed, resulting insignifcant change of index
block size.
label: code-design
with full-filter, we read filter first and then we stop
No prefix extractor
comment: Wrap around to invalid value
label: code-design
We must have created enough data to force merging
find the lower bound of the prefix
-- PART 3: Open table with bloom filter enabled but not in SST file
BlockBasedTableTest::PrefetchTest
upconvert legacy plain table
Doing a read to make index/filter loaded into the cache
Helper function to update the value of the global seqno in the file
regular_iter->Seek(prefix);
Open the table
Plain table doesn't use restart index or compression.
index block miss
data block miss
keys with prefix length 3, make sure the key/value is big enough to fill
one block
It's very hard to figure out the index block size of a block accurately.
To make sure we get the index size, we just make sure as key number
grows, the filter block size also grows.
Compression type == that set:
To tickle the PrefixMayMatch bug it is important that the
user-key is a single byte so that the index key exactly matches
the user-key.
Only index block will be accessed
Then call the origianl deleter
index block hit
Update global sequence number to 10
Return an existing key
Helper class for tests to unify the interface between
BlockBuilder/TableBuilder and Block/Table.
Only add compression if it is supported
Open table with filter policy
There must be some pinned data since PinnableSlice has not
released them yet
SeekToFirst() accesses data block. With similar reason, we expect data
block's cache miss.
-- Table construction
comment: TODO(kailiu) DoCompressionTest() doesn't work with BZip2.
label: requirement
Simple
Seek to non-existing prefixes should yield either invalid, or a
key with prefix greater than the target.
Reads and returns the string environment variable corresponding to
the given flag; if it's not set, returns default_value.
Deletes the test object.
iteration
class Test
Class UnitTestOptions.
This class contains functions for processing options the user
specifies when running the tests. It has only static members.
In most cases, the user can specify an option using either an
environment variable or a command line flag. E.g. you can set the
test filter using either GTEST_FILTER or --gtest_filter. If both
the variable and the flag are present, the latter overrides the
former.
comment: MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
(deprecated function) there.
TODO(kenton@google.com): Use GetTickCount()? Or use
SystemTimeToFileTime()
label: code-design
comment: When compiled with MSVC 7.1 in optimized mode, destroying the
UnitTest object upon exiting the program messes up the exit code,
causing successful tests to appear failed. We have to use a
different implementation in this case to bypass the compiler bug.
This implementation makes the compiler happy, at the cost of
leaking the UnitTest object.
label: code-design
Compares two wide C strings, ignoring case. Returns true iff they
have the same content.
Unlike wcscasecmp(), this function can handle NULL argument(s).
A NULL C string is considered different to any non-NULL wide C string,
including the empty string.
NB: The implementations on different platforms slightly differ.
On windows, this method uses _wcsicmp which compares according to LC_CTYPE
environment variable. On GNU platform this method uses wcscasecmp
which compares according to LC_CTYPE category of the current locale.
On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
current locale.
The following two functions only make sense if the system
uses UTF-16 for wide string encoding. All supported systems
with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16.
Allows user supplied key value pairs to be recorded for later output.
comment: However, we want to clean up as much as possible. Hence we will
always call TearDown(), even if SetUp() or the test body has
failed.
label: code-design
comment: Converting via modulus introduces a bit of downward bias, but
it's simple, and a linear congruential generator isn't too good
to begin with.
label: code-design
The time of the test program start, in ms from the start of the
UNIX epoch.
Creates a client socket and connects to the server.
comment: The default death test style.
label: test
A working implementation of the OsStackTraceGetterInterface interface.
When we fork the process below, the log file buffers are copied, but the
file descriptors are shared. We flush all log files here so that closing
the file descriptors in the child process doesn't throw off the
synchronization between descriptors and buffers in the parent process.
This is as close to the fork as possible to avoid a race condition in case
there are multiple threads running before the death test, and another
thread writes to the log file.
Prints a ::string object.
Clean up the ThreadLocalValues data structure while holding the lock, but
defer the destruction of the ThreadLocalValueHolderBases.
comment: Clears the results of all tests, except the ad hoc tests.
label: test
comment: For more convenience, we print c's code again in hexidecimal,
unless c was already printed in the form '\x##' or the code is in
[1, 9].
label: code-design
Continue only if the next hunk is very close.
Our random number generator.
GTEST_HAS_TYPED_TEST_P
Formats a source file path and a line number as they would appear
in an error message from the compiler used to compile this code.
Formats the count of tests.
Add a spacer if no FAILURE banner is displayed.
Sets the default_result_printer attribute to the provided listener.
The listener is also added to the listener list and previous
default_result_printer is removed from it and deleted. The listener can
also be NULL in which case it will not be added to the list. Does
nothing if the previous and the current listener objects are the same.
Sets the TestCase object for the test that's currently running.
comment: TODO(vladl@google.com): Replace the following check with a
compile-time assertion when available.
label: code-design
Prints the given array of characters to the ostream. CharType must be either
char or wchar_t.
The array starts at begin, the length is len, it may include '\0' characters
and may not be NUL-terminated.
comment: We create the exception message on the heap because VC++ prohibits
creation of objects with destructors on stack in functions using __try
(see error C2712).
label: code-design
Prints a string containing code-encoded text. The following escape
sequences can be used in the string to control the text color:
@@ prints a single '@' character.
@R changes the color to red.
@G changes the color to green.
@Y changes the color to yellow.
@D changes to the default terminal text color.
TODO(wan@google.com): Write tests for this once we add stdout
capturing to Google Test.
Don't strip off trailing separator if path is a root directory on
Windows (like "C:\\").
Prints a (const) wchar_t array of 'len' elements, starting at address
'begin'.
Returns true iff Google Test should use colors in the output.
comment: Helper class that holds the state for one hunk and prints it out to the
stream.
It reorders adds/removes when possible to group all removes before all
adds. It also adds the hunk header before printint into the stream.
label: code-design
Returns the message describing the last system error, regardless of the
platform.
Runs the test only if the test object was created and its
constructor didn't generate a fatal failure.
It is an error to pass this method a listener that is already in the
list.
namespace testing
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: mheule@google.com (Markus Heule)
The Google C++ Testing Framework (Google Test)
comment: How many times to repeat the tests? We don't want to repeat them
when we are inside the subprocess of a death test.
label: test
Constructs and returns the message for an equality assertion
(e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
The first four parameters are the expressions used in the assertion
and their values, as strings. For example, for ASSERT_EQ(foo, bar)
where foo is 5 and bar is 6, we have:
expected_expression: "foo"
actual_expression: "bar"
expected_value: "5"
actual_value: "6"
The ignoring_case parameter is true iff the assertion is a
*_STRCASEEQ*. When it's true, the string " (ignoring case)" will
be inserted into the message.
comment: Assume other platforms have gettimeofday().
TODO(kenton@google.com): Use autoconf to detect availability of
gettimeofday().
label: requirement
Information about a Google Test trace point.
GTEST_HAS_CLONE
Functions for processing the gtest_filter flag.
Prints a (const) char array of 'len' elements, starting at address 'begin'.
We are on Windows proper.
Given the total number of shards, the shard index, and the test id,
returns true iff the test should be run on this shard. The test id is
some arbitrary but unique non-negative integer assigned to each test
method. Assumes that 0 <= shard_index < total_shards.
Ensures that this function does not execute more than once.
Shuffles the death test cases.
If *pstr starts with the given prefix, modifies *pstr to be right
past the prefix and returns true; otherwise leaves *pstr unchanged
and returns false. None of pstr, *pstr, and prefix can be NULL.
Waits for the child process to exit if it haven't already. This
returns immediately if the child has already exited, regardless of
whether previous calls to WaitForMultipleObjects synchronized on this
handle or not.
This helper class can be used to mock out Google Test failure reporting
so that we can test Google Test or code that builds on Google Test.
An object of this class appends a TestPartResult object to the
TestPartResultArray object given in the constructor whenever a Google Test
failure is reported. It can either intercept only failures that are
generated in the same thread that created this object or it can intercept
all generated failures. The scope of this mock object can be controlled with
the second argument to the two arguments constructor.
Creates a Unicode code point from UTF16 surrogate pair.
The vector of TestCases in their original order. It owns the
elements in the vector.
Destructor of TestCase.
class PrettyUnitTestResultPrinter
max_depth
Gets the value of the flag as a string.
comment: TODO(kenton@google.com): Shouldn't this just use
GetSystemTimeAsFileTime()?
label: code-design
Creates a new TestInfo object and registers it with Google Test;
returns the created object.
Arguments:
test_case_name: name of the test case
name: name of the test
type_param: the name of the test's type parameter, or NULL if
this is not a typed or a type-parameterized test.
value_param: text representation of the test's value parameter,
or NULL if this is not a value-parameterized test.
fixture_class_id: ID of the test fixture class
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
factory: pointer to the factory that creates a test object.
The newly created TestInfo instance will assume
ownership of the factory object.
Creates an ANSI string from the given wide string, allocating
memory using new. The caller is responsible for deleting the return
value using delete[]. Returns the ANSI string, or NULL if the
input is NULL.
The text used in failure messages to indicate the start of the
stack trace.
Checks if str contains '=', '&', '%' or '\n' characters. If yes,
replaces them by "%xx" where xx is their hexadecimal value. For
example, replaces "=" with "%3D". This algorithm is O(strlen(str))
in both time and space -- important as the input str may contain an
arbitrarily long test failure message and stack trace.
getcwd will likely fail in NaCl due to the sandbox, so return something
reasonable. The user may have provided a shim implementation for getcwd,
however, so fallback only when failure is detected.
Returns true iff regex matches a prefix of str. regex must be a
valid simple regular expression and not start with "^", or the
result is undefined.
We also need to decrement the iterator as we just removed
an element.
comment: Returns true iff regex matches any substring of str. regex must be
a valid simple regular expression, or the result is undefined.
The algorithm is recursive, but the recursion depth doesn't exceed
the regex length, so we won't need to worry about running out of
stack space normally. In rare cases the time complexity can be
exponential with respect to the regex length + the string length,
but usually it's must faster (often close to linear).
label: code-design
The helper function for {ASSERT|EXPECT}_EQ with int or enum
arguments.
Use the getaddrinfo() to get a linked list of IP addresses for
the given host name.
Makes sure full_pattern_ starts with '^'.
Makes sure full_pattern_ ends with '$'.
Has strtol() consumed all characters in the string?
Returns true iff the test name of test_info matches name_.
WindowsDeathTest uses an anonymous pipe to communicate results of
a death test.
Getters for the per-thread Google Test trace stack.
In order to support thread-safe death tests, we need to
remember the original working directory when the test program
was first invoked. We cannot do this in RUN_ALL_TESTS(), as
the user may have changed the current directory before calling
RUN_ALL_TESTS(). Therefore we capture the current directory in
AddTestInfo(), which is called to register a TEST or TEST_F
before main() is reached.
Clears the results of ad-hoc test assertions.
Returns true iff str ends with the given suffix, ignoring case.
Any string is considered to end with an empty suffix.
Formats a countable noun. Depending on its quantity, either the
singular form or the plural form is used. e.g.
FormatCountableNoun(1, "formula", "formuli") returns "1 formula".
FormatCountableNoun(5, "book", "books") returns "5 books".
Mutex for linked pointers.
Helper template for implementing FloatLE() and DoubleLE().
End PrettyUnitTestResultPrinter
or if val1 is almost equal to val2.
comment: Returns an XML-escaped copy of the input string str. If is_attribute
is true, the text is meant to appear as an attribute value, and
normalizable whitespace is preserved by replacing it with character
references.
Invalid XML characters in str, if any, are stripped from the output.
It is expected that most, if not all, of the text processed by this
module will consist of ordinary English text.
If this module is ever modified to produce version 1.1 XML output,
most invalid characters can be retained using character references.
TODO(wan): It might be nice to have a minimally invasive, human-readable
escaping scheme for invalid characters, rather than dropping them.
label: code-design
Gets the random seed used at the start of the current test iteration.
class UnitTest
Adds a TestPartResult to the current TestResult object. All Google Test
assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
this to report their results. The user code should use the
assertion macros instead of calling this directly.
str and flag must not be NULL.
ParseInternalRunDeathTestFlag() has performed all the necessary
processing.
A concrete death test class that forks, then immediately runs the test
in the child process.
Symbian OpenC has PATH_MAX in sys/syslimits.h
Returns true iff the test case failed.
Parses the command line for Google Test flags, without initializing
other parts of Google Test.
comment: A struct that encompasses the arguments to the child process of a
threadsafe-style death test process.
label: code-design
Gets the number of all tests.
IsSubstring() and IsNotSubstring() check whether needle is a
substring of haystack (NULL is considered a substring of itself
only), and return an appropriate error message when they fail.
!GTEST_OS_QNX
Google Test - The Google C++ Testing Framework
This file implements a universal value printer that can print a
value of any type T:
void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
It uses the << operator when possible, and prints the bytes in the
object otherwise. A user can override its behavior for a class
type Foo by defining either operator<<(::std::ostream&, const Foo&)
or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
defines Foo.
Restores the current working directory.
Converts a wide string to a narrow string in UTF-8 encoding.
The wide string is assumed to have the following encoding:
UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
UTF-32 if sizeof(wchar_t) == 4 (on Linux)
Parameter str points to a null-terminated wide string.
Parameter num_chars may additionally limit the number
of wchar_t characters processed. -1 is used when the entire string
should be processed.
If the string contains code points that are not valid Unicode code points
(i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
and contains invalid UTF-16 surrogate pairs, values in those pairs
will be encoded as individual Unicode characters from Basic Normal Plane.
A function for deleting an object. Handy for being used as a
functor.
Pushes a trace defined by SCOPED_TRACE() on to the per-thread
Google Test trace stack.
Gets the number of failed tests in this test case.
Returns a pathname for a file that does not currently exist. The pathname
will be directory/base_name.extension or
directory/base_name_<number>.extension if directory/base_name.extension
already exists. The number will be incremented until a pathname is found
that does not already exist.
Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
There could be a race condition if two or more processes are calling this
function at the same time -- they could both pick the same filename.
Death test constructor. Increments the running death test count
for the current test.
True iff at least one test has failed.
The output file.
Returns a copy of the FilePath with the directory part removed.
Example: FilePath("path/to/file").RemoveDirectoryName() returns
FilePath("file"). If there is no directory part ("just_a_file"), it returns
the FilePath unmodified. If there is no file part ("just_a_dir/") it
returns an empty FilePath ("").
On Windows platform, '\' is the path separator, otherwise it is '/'.
Dynamic mutexes are initialized in the constructor.
The following methods override what's in the TestEventListener class.
Runs the given method and catches and reports C++ and/or SEH-style
exceptions, if they are supported; returns the 0-value for type
Result in case of an SEH exception.
An error is OK if the directory exists.
The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
starts.
Reads the entire content of a file as an std::string.
NOTE: The user code can affect the way in which Google Test handles
exceptions by setting GTEST_FLAG(catch_exceptions), but only before
RUN_ALL_TESTS() starts. It is technically possible to check the flag
after the exception is caught and either report or re-throw the
exception based on the flag's value:
try {
// Perform the test method.
} catch (...) {
if (GTEST_FLAG(catch_exceptions))
// Report the exception as failure.
else
throw; // Re-throws the original exception.
}
However, the purpose of this flag is to allow the program to drop into
the debugger when the exception is thrown. On most platforms, once the
control enters the catch block, the exception origin information is
lost and the debugger will stop the program at the point of the
re-throw in this function -- instead of at the point of the original
throw statement in the code under test. For this reason, we perform
the check early, sacrificing the ability to affect Google Test's
exception handling in the method where the exception is thrown.
End XmlUnitTestResultPrinter
comment: If we are in the child process of a death test, don't
create/delete the premature exit file, as doing so is unnecessary
and will confuse the parent process. Otherwise, create/delete
the file upon entering/leaving this function. If the program
somehow exits before this function has a chance to return, the
premature-exit file will be left undeleted, causing a test runner
that understands the premature-exit-file protocol to report the
test as having failed.
label: code-design
Index of the last death test case registered. Initially -1.
In the debug version, Visual Studio pops up a separate dialog
offering a choice to debug the aborted program. We need to suppress
this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
executed. Google Test will notify the user of any unexpected
failure via stderr.
VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
Users of prior VC versions shall suffer the agony and pain of
clicking through the countless debug dialogs.
TODO(vladl@google.com): find a way to suppress the abort dialog() in the
debug mode when compiled with VC 7.1 or lower.
The AssumeRole process for a fork-and-exec death test. It re-executes the
main program from the beginning, setting the --gtest_filter
and --gtest_internal_run_death_test flags to cause only the current
death test to be re-run.
class TestEventRepeater
This class forwards events to other event listeners.
Print failure message from the assertion (e.g. expected this and got that).
We don't use snprintf or strncpy, as they trigger a warning when
compiled with VC++ 8.0.
Tells the unit test event listener that the tests have just finished.
The parsed value overflows as an Int32.
Parses a string for an Int32 flag, in the form of "--flag=value".
On success, stores the value of the flag in *value, and returns
true. On failure, returns false without changing *value.
namespace posix
GTEST_OS_WINDOWS_MOBILE
When def_optional is true, it's OK to not have a "=value" part.
Sets the test part result reporter for the current thread.
NOLINT
GTEST_OS_WINDOWS
The environment variable name for the test shard status file.
comment: Prints an XML representation of a TestInfo object.
TODO(wan): There is also value in printing properties with the plain printer.
label: code-design
Returns the current OS stack trace as an std::string.
The maximum number of stack frames to be included is specified by
the gtest_stack_trace_depth flag. The skip_count parameter
specifies the number of top frames to be skipped, which doesn't
count against the number of frames to be included.
For example, if Foo() calls Bar(), which in turn calls
CurrentOsStackTraceExceptTop(1), Foo() will be included in the
trace but Bar() and CurrentOsStackTraceExceptTop() won't.
This doesn't throw as all user code that can throw are wrapped into
exception handling code.
Yes. Shift the remainder of the argv list left by one. Note
that argv has (*argc + 1) elements, the last one always being
NULL. The following loop moves the trailing NULL element as
well.
RemoveFileName returns the directory path with the filename removed.
Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
If the FilePath is "a_file" or "/a_file", RemoveFileName returns
FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
not have a file, like "just/a/dir/", it returns the FilePath unmodified.
On Windows platform, '\' is the path separator, otherwise it is '/'.
A valid random seed must be in [1, kMaxRandomSeed].
class UnitTestImpl
comment: Since most methods are very similar, use macros to reduce boilerplate.
This defines a member that forwards the call to all listeners.
label: code-design
Helper function for *_STREQ on wide strings.
Returns the message describing the last system error in errno.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Is the parsed value in the range of an Int32?
Prints the given C string to the ostream.
The list of reserved attributes used in the <testcase> element of XML output.
A test case whose name matches this filter is considered a death
test case and will be run before test cases whose name doesn't
match this filter.
comment: We cannot call numeric_limits::max() as it conflicts with the
max() macro on Windows.
label: code-design
Windows CE doesn't define INVALID_FILE_ATTRIBUTES
Prints a TestPartResult object.
Converts the given epoch time in milliseconds to a date string in the ISO
8601 format, without the timezone information.
Prints an XML summary of unit_test to output stream out.
Initializes the event listener for streaming test results to a socket.
Must not be called before InitGoogleTest.
Returns the current time in milliseconds.
Returns ParameterizedTestCaseRegistry object used to keep track of
value-parameterized tests and instantiate and register them.
Runs all tests in this UnitTest object, prints the result, and
returns true if all tests are successful. If any exception is
thrown during a test, this test is considered to be failed, but
the rest of the tests will still be run.
The newly initialized handle is accessible only in in the parent
process. To obtain one accessible within the child, we need to use
DuplicateHandle.
Adds a TestInfo to the unit test.
Arguments:
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
test_info: the TestInfo object
The parent process considers the death test to be a failure if
it finds any data in our pipe. So, here we write a single flag byte
to the pipe, then exit.
The c'tor sets this object as the test part result reporter used
by Google Test. The 'result' parameter specifies where to report the
results. This reporter will only catch failures generated in the current
thread. DEPRECATED
Converts an array of wide chars to a narrow string using the UTF-8
encoding, and streams the result to the given Message object.
Fired before each iteration of tests starts.
Returns the current OS stack trace as an std::string.
The maximum number of stack frames to be included is specified by
the gtest_stack_trace_depth flag. The skip_count parameter
specifies the number of top frames to be skipped, which doesn't
count against the number of frames to be included.
For example, if Foo() calls Bar(), which in turn calls
GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
The current color.
GTEST_HAS_GLOBAL_STRING
_MSC_VER
The decomposed components of the gtest_internal_run_death_test flag,
parsed when RUN_ALL_TESTS is called.
comment: MinGW has gettimeofday() but not _ftime64().
TODO(kenton@google.com): Use autoconf to detect availability of
gettimeofday().
TODO(kenton@google.com): There are other ways to get the time on
Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW
supports these. consider using them instead.
label: code-design
Increments the test part result count and remembers the result.
This method is from the TestPartResultReporterInterface interface.
Note that Google Test current only report elapsed time for each
test iteration, not for the entire test program.
May c appear in a well-formed XML document?
Possibly yields the rest of the thread's time slice to other
threads.
Prints a segment of bytes in the given object.
Everything up to the dash
Everything after the dash
comment: Name of the temporary file holding the stderr output.
label: code-design
Info about the current test.
Prints a wchar_t c as if it's part of a string literal, escaping it when
necessary; returns how c was formatted.
Appends a TestPartResult to the array.
Some Linux distributions define PATH_MAX here.
GTEST_OS_WINDOWS_MOBILE
Notify the streaming server to stop.
Google Test implements this protocol for catching that a test
program exits before returning control to Google Test:
1. Upon start, Google Test creates a file whose absolute path
is specified by the environment variable
TEST_PREMATURE_EXIT_FILE.
2. When Google Test has finished its work, it deletes the file.
This allows a test runner to set TEST_PREMATURE_EXIT_FILE before
running a Google-Test-based test program and check the existence
of the file at the end of the test execution to see if it has
exited prematurely.
This is called from a death test parent process to read a failure
message from the death test child process and log it with the FATAL
severity. On Windows, the message is read from a pipe handle. On other
platforms, it is read from a file descriptor.
Returns the name of the requested output file, or the default if none
was explicitly specified.
Generates a textual description of a given exit code, in the format
specified by wait(2).
Same as above, but you can choose the interception scope of this object.
True if the death test child process has been successfully spawned.
No need to calculate the full pattern when the regex is invalid.
wchar_t is native
A filter is a colon-separated list of patterns. It matches a
test if any pattern in it matches the test.
This code is unreachable but some compilers may not realizes that.
Restores the original stream.
Converts a wide C string to an std::string using the UTF-8 encoding.
NULL will be converted to "(null)".
Deletes every Environment.
Sets the OS stack trace getter.
Does nothing if the input and the current OS stack trace getter are
the same; otherwise, deletes the old getter and makes the input the
current getter.
Appends the user message if it's non-empty.
Returns true if pathname describes something findable in the file-system,
either a file, directory, or whatever.
Restores the text color.
Returns the current OS stack trace getter if it is not NULL;
otherwise, creates an OsStackTraceGetter, makes it the current
getter, and returns it.
Gets the number of disabled tests.
Parses 'str' for a 32-bit signed integer. If successful, writes
the result to *value and returns true; otherwise leaves *value
unchanged and returns false.
comment: Helpers for printing colored strings to stdout. Note that on Windows, we
cannot simply emit special characters and have the terminal change colors.
This routine must actually emit the characters rather than return a string
that would be colored when printed, as can be done on Linux.
label: code-design
The d'tor restores the values of all Google Test flags.
Clears the object.
iteration
These constants are the same as are used in glibc's rand(3).
Appends the TestPartResult object to the TestPartResultArray
received in the constructor.
This method is from the TestPartResultReporterInterface
interface.
comment: Shuffles the tests in this test case.
label: test
Implements the helper function for {ASSERT|EXPECT}_GE with int or
enum arguments.
!GTEST_OS_WINDOWS
The exit status of the child process.
Maximum stack alignment in bytes: For a downward-growing stack, this
amount is subtracted from size of the stack space to get an address
that is within the stack space and is aligned on all systems we care
about. As far as I know there is no ABI with stack alignment greater
than 64. We assume stack and stack_size already have alignment of
kMaxStackAlignment.
Sets up the test fixture.
A sub-class may override this.
GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
part of Google Test's implementation; otherwise it's undefined.
Dereference NULL through a volatile pointer to prevent the compiler
from removing. We use this rather than abort() or __builtin_trap() for
portability: Symbian doesn't implement abort() well, and some debuggers
don't correctly trap abort().
Matches a repeated regex atom followed by a valid simple regular
expression. The regex atom is defined as c if escaped is false,
or \c otherwise. repeat is the repetition meta character (?, *,
or +). The behavior is undefined if str contains too many
characters to be indexable by size_t, in which case the test will
probably time out anyway. We are fine with this limitation as
std::string has it too.
AssertionResult constructors.
Used in EXPECT_TRUE/FALSE(assertion_result).
Make sure AddressSanitizer does not tamper with the stack here.
comment: Constructs an empty Message.
We allocate the stringstream separately because otherwise each use of
ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
stack frame leading to huge stack frames in some cases; gcc does not reuse
the stack space.
label: code-design
comment: TODO(wan@google.com): fix the source file location in the
assertion failures to match where the regex is used in user
code.
label: code-design
MSVC and C++ Builder define __int64 instead of the standard long long.
Obtains the current directory and sets it to be closed in the child
process.
Assesses the success or failure of a death test, using both private
members which have previously been set, and one argument:
Private data members:
outcome: An enumeration describing how the death test
concluded: DIED, LIVED, THREW, or RETURNED. The death test
fails in the latter three cases.
status: The exit status of the child process. On *nix, it is in the
in the format specified by wait(2). On Windows, this is the
value supplied to the ExitProcess() API or a numeric code
of the exception that terminated the program.
regex: A regular expression object to be applied to
the test's captured standard error output; the death test
fails if it does not match.
Argument:
status_ok: true if exit_status is acceptable in the context of
this particular death test, which fails if it is false
Returns true iff all of the above conditions are met. Otherwise, the
first failing condition, in the order given above, is the one that is
reported. Also sets the last death test message string.
YYYY-MM-DDThh:mm:ss
Verifies that the given attribute belongs to the given element and
streams the attribute as XML.
Clears the results of all tests in this test case.
Makes a failed assertion result.
Used in ThreadLocal.
comment: Returns the TestResult for the test that's currently running, or
the TestResult for the ad hoc test if no test is running.
label: test
Returns the current OS stack trace as an std::string. Parameters:
max_depth - the maximum number of stack frames to be included
in the trace.
skip_count - the number of top frames to be skipped; doesn't count
against max_depth.
Returns true iff the test case passed.
The returned handle will be kept in thread_map and closed by
watcher_thread in WatcherThreadFunc.
By default, we want there to be enough precision when printing
a double to a Message.
Non-special character. Matches itself.
GTEST_HAS_STD_WSTRING
Parses the command line for Google Test flags, without initializing
other parts of Google Test. The type parameter CharType can be
instantiated to either char or wchar_t.
Returns the TestInfo object for the test that's currently running,
or NULL if no test is running.
class SocketWriter
Gets the random number generator.
The child has acquired the write end of the pipe or exited.
We release the handle on our side and continue.
comment: First, print c as a literal in the most readable form we can find.
label: code-design
gtest_break_on_failure takes precedence over
gtest_throw_on_failure. This allows a user to set the latter
in the code (perhaps in order to use Google Test assertions
with another testing framework) and specify the former on the
command line for debugging.
Iterate the edits until we found enough suffix for the hunk or the input
is over.
No. Let's create one.
__clang_analyzer__
A successful match can be anywhere in str.
Skips to the first non-space char in str. Returns an empty string if str
contains only whitespace characters.
Returns the i-th test property. i can range from 0 to
test_property_count() - 1. If i is not in that range, aborts the
program.
Implements the helper function for {ASSERT|EXPECT}_GT with int or
enum arguments.
The helper function for {ASSERT|EXPECT}_STRCASENE.
Ensure that Google Test output is printed before, e.g., heapchecker output.
Adds a TestProperty to the current TestResult object when invoked in a
context of a test, to current test case's ad_hoc_test_result when invoke
from SetUpTestCase/TearDownTestCase, or to the global property set
otherwise. If the result already contains a property with the same key,
the value will be updated.
class TestResult
We don't want to run the initialization code twice.
An escape sequence
Determines whether a string has a prefix that Google Test uses for its
flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_.
If Google Test detects that a command line flag has its prefix but is not
recognized, it will print its help message. Flags starting with
GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test
internal flags and do not trigger the help message.
Non-inheritable.
Routine for aborting the program which is safe to call from an
exec-style death test child process, in which case the error
message is propagated back to the parent process. Otherwise, the
message is simply printed to stderr. In either case, the program
then exits with status 1.
GTEST_SRC_GTEST_INTERNAL_INL_H_
Resetting with the same handle we already own is invalid.
Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
if the variable is present. If a file already exists at this location, this
function will write over it. If the variable is present, but the file cannot
be created, prints an error and exits.
Parses the environment variable var as an Int32. If it is unset,
returns default_val. If it is not an Int32, prints an error and
aborts.
Waits for the child in a death test to exit, returning its exit
status, or 0 if no child process exists. As a side effect, sets the
outcome data member.
Default security.
Default stack size
MINGW <time.h> provides neither localtime_r nor localtime_s, but uses
Windows' localtime(), which has a thread-local tm buffer.
NOLINT
NOLINT
NOLINT
NOLINT
NOLINT
The vector of environments that need to be set-up/torn-down
before/after the tests are run.
Returns whether the given character is a valid path separator.
Stops capturing stdout and returns the captured string.
Reads the entire content of a file as a string.
comment: WindowsDeathTest implements death tests on Windows. Due to the
specifics of starting new processes on Windows, death tests there are
always threadsafe, and Google Test considers the
--gtest_death_test_style=fast setting to be equivalent to
--gtest_death_test_style=threadsafe there.
A few implementation notes: Like the Linux version, the Windows
implementation uses pipes for child-to-parent communication. But due to
the specifics of pipes on Windows, some extra steps are required:
1. The parent creates a communication pipe and stores handles to both
ends of it.
2. The parent starts the child and provides it with the information
necessary to acquire the handle to the write end of the pipe.
3. The child acquires the write end of the pipe and signals the parent
using a Windows event.
4. Now the parent can release the write end of the pipe on its side. If
this is done before step 3, the object's reference count goes down to
0 and it is destroyed, preventing the child from acquiring it. The
parent now has to release it, or read operations on the read end of
the pipe will not return when the child terminates.
5. The parent reads child's output through the pipe (outcome code and
any possible error messages) from the pipe, and its stderr and then
determines whether to fail the test.
Note: to distinguish Win32 API calls from the local method and function
calls, the former are explicitly resolved in the global namespace.
label: code-design
Prints a char c as if it's part of a string literal, escaping it when
necessary; returns how c was formatted.
Returns an XML-escaped copy of the input string str. If
is_attribute is true, the text is meant to appear as an attribute
value, and normalizable whitespace is preserved by replacing it
with character references.
class String.
comment: GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
label: test
comment: There's no portable way to detect the number of threads, so we just
return 0 to indicate that we cannot detect it.
label: code-design
Looks up the human-readable system message for the HRESULT code
and since we're not passing any params to FormatMessage, we don't
want inserts expanded.
Returns the test part result reporter for the current thread.
Creates the test object.
Finds and returns a TestCase with the given name. If one doesn't
exist, creates one and returns it.
Arguments:
test_case_name: name of the test case
type_param: the name of the test's type parameter, or NULL if
this is not a typed or a type-parameterized test.
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
Helper functions for implementing IsSubString() and IsNotSubstring().
Compares the name of each test with the user-specified filter to
decide whether the test should be run, then records the result in
each TestCase and TestInfo object.
If shard_tests == true, further filters tests based on sharding
variables in the environment - see
http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide.
Returns the number of tests that should run.
There's no guarantee that a test has write access to the current
directory, so we create the temporary file in the /tmp directory
instead. We use /tmp on most systems, and /sdcard on Android.
That's because Android doesn't have /tmp.
Returns the type ID of ::testing::Test. We should always call this
instead of GetTypeId< ::testing::Test>() to get the type ID of
testing::Test. This is to work around a suspected linker bug when
using Google Test as a framework on Mac OS X. The bug causes
GetTypeId< ::testing::Test>() to return different values depending
on whether the call is from the Google Test framework itself or
from user test code. GetTestTypeId() is guaranteed to always
return the same value, as it always calls GetTypeId<>() from the
gtest.cc, which is within the Google Test framework.
Returns the standard listener responsible for the default console
output. Can be removed from the listeners list to shut down default
console output. Note that removing this object from the listener list
with Release transfers its ownership to the user.
Registers thread_local_instance as having value on the current thread.
Returns a value that can be used to identify the thread from other threads.
Internal helper for printing the list of failed tests.
Function for supporting the gtest_catch_exception flag.
Conceptually, we split the string into segments divided by escape
sequences. Then we print one segment at a time. At the end of
each iteration, the str pointer advances to the beginning of the
next segment.
Utility functions for encoding Unicode text (wide strings) in
UTF-8.
Maps a thread to a set of ThreadIdToThreadLocals that have values
instantiated on that thread and notifies them when the thread exits. A
ThreadLocal instance is expected to persist until all threads it has
values on have terminated.
Will be overridden by the flag before first use.
An empty regex matches a prefix of anything.
comment: CodeGear C++Builder insists on a public destructor for the
default implementation. Use this implementation to keep good OO
design with private destructor.
label: code-design
Iterates over a vector of TestCases, keeping a running sum of the
results of calling a given int-returning method on each.
Returns the sum.
Internal helper functions for implementing the simple regular
expression matcher.
Matches the full name of each test against the user-specified
filter to decide whether the test should run, then records the
result in each TestCase and TestInfo object.
If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
based on sharding variables in the environment.
Returns the number of tests that should run.
The default output file for XML output.
Compares two C strings. Returns true iff they have the same content.
Unlike strcmp(), this function can handle NULL argument(s). A NULL
C string is considered different to any non-NULL C string,
including the empty string.
Names of the flags (needed for parsing Google Test flags).
GTEST_USES_SIMPLE_RE
If this file is included from the user's code, just say no.
Returns true iff ch belongs to the given classification. Unlike
similar functions in <ctype.h>, these aren't affected by the
current locale.
Implements the helper function for {ASSERT|EXPECT}_LT with int or
enum arguments.
NOLINT
GTEST_OS_WINDOWS_MINGW
Implemented as an explicit loop since std::count_if() in libCstd on
Solaris has a non-standard signature.
Command-line arguments for the child's call to exec
File descriptor to close; the read end of a pipe
Gets the number of failed tests.
Destructor of UnitTest.
Gets the number of all test cases.
Returns a newly created InternalRunDeathTestFlag object with fields
initialized from the GTEST_FLAG(internal_run_death_test) flag if
the flag is specified; otherwise returns NULL.
Returns true iff the test part non-fatally failed.
Utility functions and classes used by the Google C++ testing framework.
Author: wan@google.com (Zhanyong Wan)
This file contains purely Google Test's internal implementation. Please
DO NOT #INCLUDE IT IN A USER PROGRAM.
Registers all parameterized tests defined using TEST_P and
INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
combination. This method can be called more then once; it has guards
protecting from registering the tests more then once. If
value-parameterized tests are disabled, RegisterParameterizedTests is
present but does nothing.
Streams test results to the given port on the given host machine.
Sets the TestInfo object for the test that's currently running. If
current_test_info is NULL, the assertion results will be stored in
ad_hoc_test_result_.
This 'if' can only be successful at most once, so theoretically we
could break out of the loop here, but we don't bother doing so.
A test whose test case name or test name matches this filter is
disabled and not run.
Makes a failed assertion result with the given failure message.
Deprecated; use AssertionFailure() << message.
comment: We make replace a little more expensive than add/remove to lower
their priority.
label: code-design
Constructor.
TestNameIs has NO default constructor.
Creates the test object, runs it, records its result, and then
deletes it.
Performs an in-place shuffle of a range of the vector's elements.
'begin' and 'end' are element indices as an STL-style range;
i.e. [begin, end) are shuffled, where 'end' == size() means to
shuffle to the end of the vector.
Signals that the death test code which should have exited, didn't.
Should be called only in a death test child process.
Writes a status byte to the child's status file descriptor, then
calls _exit(1).
comment: Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to
suppress unreachable code warnings.
label: code-design
Default security attributes.
Do not reset automatically.
Initially unset.
Anonymous event.
Protects access to GetThreadLocalsMapLocked() and its return value.
namespace internal
namespace testing
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Generates non-fatal failures and returns false if regex is invalid;
otherwise returns true.
Implements the RE class.
Configures listeners for XML output. This makes it possible for users
to shut down the default XML output before invoking RUN_ALL_TESTS.
Rounds up to 2-byte boundary.
End of class Streaming Listener
GTEST_CAN_STREAM_RESULTS__
If a path to the premature-exit file is specified...
Provides cross platform implementation for some death functionality.
Returns true iff the current test has a non-fatal failure.
# of bytes read in the last fread()
# of bytes read so far
The code
const char kFoo[] = "foo";
generates an array of 4, not 3, elements, with the last one being '\0'.
Therefore when printing a char array, we don't print the last element if
it's '\0', such that the output matches the string literal as it's
written in the source code.
regfree'ing an invalid regex might crash because the content
of the regex is undefined. Since the regex's are essentially
the same, one cannot be valid (or invalid) without the other
being so too.
Runs all tests in this UnitTest object, prints the result, and
returns true if all tests are successful. If any exception is
thrown during a test, the test is considered to be failed, but the
rest of the tests will still be run.
When parameterized tests are enabled, it expands and registers
parameterized tests first in RegisterParameterizedTests().
All other functions called from RunAllTests() may safely assume that
parameterized tests are ready to be counted and run.
comment: Valid only for fast death tests. Indicates the code is running in the
child process of a fast style death test.
label: test
On Windows, '\\' is the standard path separator, but many tools and the
Windows API also accept '/' as an alternate path separator. Unless otherwise
noted, a file path can contain either kind of path separators, or a mixture
of them.
Concrete class for actually writing strings to a socket.
Returns true iff the wildcard pattern matches the string. The
first ':' or '\0' character in pattern marks the end of it.
This recursive algorithm isn't very efficient, but is clear and
works well enough for matching test names, which are short.
comment: Two fixture classes with the same name appear in two different
namespaces, which is not allowed. Tell the user how to fix this.
label: code-design
The regular expression which test output must match. DeathTestImpl
doesn't own this object and should not attempt to delete it.
Stores all ThreadIdToThreadLocals having values in a thread, indexed by
thread's ID.
Helpers for setting up / tearing down the given environment. They
are for use in the ForEach() function.
Helper function for implementing ASSERT_NEAR.
End TestEventRepeater
GTEST_HAS_DEATH_TEST
class OsStackTraceGetter
!GTEST_OS_WINDOWS_MOBILE
Shuffles the tests inside each test case.
Descriptor to the read end of the pipe to the child process. It is
always -1 in the child process. The child keeps its write end of the
pipe in write_fd_.
Suppress clang analyzer warnings.
Streams an XML representation of a TestInfo object.
Parses a string for a string flag, in the form of
"--flag=value".
On success, stores the value of the flag in *value, and returns
true. On failure, returns false without changing *value.
Called in the parent process only. Reads the result code of the death
test child process via a pipe, interprets it to set the outcome_
member, and closes read_fd_. Outputs diagnostics and terminates in
case of unexpected codes.
Stops capturing the output stream and returns the captured string.
The working directory when the first TEST() or TEST_F() was
executed.
We print the help here instead of in RUN_ALL_TESTS(), as the
latter may not be called at all if the user is using Google
Test with another testing framework.
namespace
Formats the given time in milliseconds as seconds.
MSVC and C++Builder do not provide a definition of STDERR_FILENO.
MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
Compares two wide C strings. Returns true iff they have the same
content.
Unlike wcscmp(), this function can handle NULL argument(s). A NULL
C string is considered different to any non-NULL C string,
including the empty string.
UponLeavingGTest() should be called immediately before Google Test calls
user code. It saves some information about the current stack that
CurrentStackTrace() will use to find and hide Google Test stack frames.
This class generates an XML output file.
In a particular thread, maps a ThreadLocal object to its value.
Prints the given C-string on a single line by replacing all '\n'
characters with string "\\n". If the output takes more than
max_length characters, only prints the first max_length characters
and "...".
comment: Returns true iff test_case contains at least one test that should
run.
label: test
Returns true iff the test failed.
"\\p" where p is pattern_char.
Fields for saving the original values of flags.
Gets the number of all test cases that contain at least one test
that should run.
Shuffles the non-death test cases.
This condition is always false so AlwaysTrue() never actually throws,
but it makes the compiler think that it may throw.
comment: Spawns a child process with the same executable as the current process in
a thread-safe manner and instructs it to run the death test. The
implementation uses fork(2) + exec. On systems where clone(2) is
available, it is used instead, being slightly more thread-safe. On QNX,
fork supports only single-threaded environments, so this function uses
spawn(2) there instead. The function dies with an error message if
anything goes wrong.
label: code-design
A macro for implementing the helper functions needed to implement
ASSERT_?? and EXPECT_?? with integer or enum arguments. It is here
just to avoid copy-and-paste of similar code.
Returns the i-th element of the vector, or default_value if i is not
in range [0, v.size()).
NOLINT
This exception type can only be thrown by a failed Google
Test assertion with the intention of letting another testing
framework catch it. Therefore we just re-throw it.
comment: Gets the system's human readable message string for this HRESULT.
label: code-design
Gets the time of the test program start, in ms from the start of the
UNIX epoch.
NOLINT
NOLINT
NOLINT
Declares vsnprintf(). This header is not available on Windows.
NOLINT
NOLINT
NOLINT
NOLINT
Determines if the arguments constitute UTF-16 surrogate pair
and thus should be combined into a single Unicode code point
using CreateCodePointFromUtf16SurrogatePair.
GTEST_OS_WINDOWS && !defined(__GNUC__)
Protects read and write access to global_test_part_result_reporter_.
Yes. Inserts the test case after the last death test case
defined so far. This only works when the test cases haven't
been shuffled. Otherwise we may end up running a death test
after a non-death test.
comment: TODO(wan@google.com): on Windows \some\path is not an absolute
path (as its meaning depends on the current drive), yet the
following logic for turning it into an absolute path is wrong.
Fix it.
label: code-design
Does not return.
comment: Print a unified diff header for one hunk.
The format is
"@@ -<left_start>,<left_length> +<right_start>,<right_length> @@"
where the left/right parts are omitted if unnecessary.
label: code-design
True iff PostFlagParsingInit() has been called.
The private implementation of the UnitTest class. We don't protect
the methods under a mutex, as this class is not accessible by a
user and the UnitTest class that delegates work to this class does
proper locking.
Wait until the child either signals that it has acquired the write end
of the pipe or it dies.
A concrete death test class that forks and re-executes the main
program from the beginning, with command-line flags set that cause
only this specific death test to be run.
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: mheule@google.com (Markus Heule)
Google C++ Testing Framework (Google Test)
Sometimes it's desirable to build Google Test by compiling a single file.
This file serves this purpose.
Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
On Windows, uses \ as the separator rather than /.
This predicate-formatter checks that 'results' contains a test part
failure of the given type and that the failure message contains the
given substring.
Tears down the test fixture.
A sub-class may override this.
We are leaking the descriptor here because on some platforms (i.e.,
when built as Windows DLL), destructors of global objects will still
run after calling _exit(). On such systems, write_fd_ will be
indirectly closed from the destructor of UnitTestImpl, causing double
close if it is also closed here. On debug configurations, double close
may assert. As there are no in-process buffers to flush here, we are
relying on the OS to close the descriptor after the process terminates
when the destructors are not run.
Exits w/o any normal exit hooks (we were supposed to crash)
Formats an int value as "%X".
namespace internal2
class TestEventListeners
The helper function for {ASSERT|EXPECT}_STRCASEEQ.
Initializes an RE from its string representation.
If input name has a trailing separator character, remove it and return the
name, otherwise return the name string unmodified.
On Windows platform, uses \ as the separator, other platforms use /.
GTEST_CAN_STREAM_RESULTS_
Is c a whitespace character that is normalized to a space character
when it appears in an XML attribute value?
Skips the pattern separater (the ':' character).
Returns the output format, or "" for normal printed output.
The parsed value overflows as a long. (strtol() returns
LONG_MAX or LONG_MIN when the input overflows.)
Returns the current application's name, removing directory path if that
is present. Used by UnitTestOptions::GetOutputFile.
regex isn't empty, isn't "$", and doesn't start with a
repetition. We match the first atom of regex with the first
character of str and recurse.
SetErrorMode doesn't exist on CE.
MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so
here's an indirect recursion. It terminates as the regex gets
shorter in each recursion.
comment: TODO(wan): report the reason of the failure.
We don't do it for now as:
1. There is no urgent need for it.
2. It's a bit involved to make the errno variable thread-safe on
all three operating systems (Linux, Windows, and Mac OS).
3. To interpret the meaning of errno in a thread-safe way,
we need the strerror_r() function, which is not available on
Windows.
label: requirement
comment: task_threads allocates resources in thread_list and we need to free them
to avoid leaks.
label: code-design
PID of child process during death test; 0 in the child process itself.
ForkingDeathTest provides implementations for most of the abstract
methods of the DeathTest interface. Only the AssumeRole method is
left undefined.
Sets *value to the value of the flag.
namespace internal
namespace testing
type_expr
Converts the string value to a bool.
The AssumeRole process for a Windows death test. It creates a child
process with the same executable as the current process to run the
death test. The child process is given the --gtest_filter and
--gtest_internal_run_death_test flags such that it knows to run the
current death test only.
unit_test
Returns the i-th test among all the tests. i can range from 0 to
total_test_count() - 1. If i is not in that range, returns NULL.
Returns the vector of environments that need to be set-up/torn-down
before/after the tests are run.
Returns true if FilePath ends with a path separator, which indicates that
it is intended to represent a directory. Returns false otherwise.
This does NOT check that a directory (or file) actually exists.
comment: Converts the given time in milliseconds to a date string in the ISO 8601
format, without the timezone information. N.B.: due to the use the
non-reentrant localtime() function, this function is not thread safe. Do
not use it in any code that can be called from multiple threads.
label: code-design
MSVC compiler can be configured to define whar_t as a typedef
of unsigned short. Defining an overload for const wchar_t* in that case
would cause pointers to unsigned shorts be printed as wide strings,
possibly accessing more memory than intended and causing invalid
memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
wchar_t is implemented as a native type.
Prints a (const) char/wchar_t array of 'len' elements, starting at address
'begin'. CharType must be either char or wchar_t.
Disables event forwarding if the control is currently in a death test
subprocess. Must not be called before InitGoogleTest.
Returns a pointer to the last occurrence of a valid path separator in
the FilePath. On Windows, for example, both '/' and '\' are valid path
separators. Returns NULL if no path separator was found.
comment: Notifies the unit test event listener that a test has just finished.
label: test
comment: Adds a test to this test case. Will delete the test upon
destruction of the TestCase object.
label: test
No error.
comment: NOLINT - this is more readable than unbalanced brackets inside #if.
label: code-design
Returns true if pathname describes a directory in the file-system
that exists.
Returns true iff regular expression re matches the entire str.
GTEST_OS_QNX
Converts a TestPartResult::Type enum to human-friendly string
representation. Both kNonFatalFailure and kFatalFailure are translated
to "Failure", as the user usually doesn't care about the difference
between the two when viewing the test result.
comment: An enumeration describing all of the possible ways that a death test can
conclude. DIED means that the process died while executing the test
code; LIVED means that process lived beyond the end of the test code;
RETURNED means that the test statement attempted to execute a return
statement, which is not allowed; THREW means that the test statement
returned control by throwing an exception. IN_PROGRESS means the test
has not yet concluded.
TODO(vladl@google.com): Unify names and possibly values for
AbortReason, DeathTestOutcome, and flag characters above.
label: code-design
Creates and returns a death test by dispatching to the current
death test factory.
The list of reserved attributes used in the <testsuites> element of XML
output.
Prints a wchar_t as a symbol if it is printable or as its internal
code otherwise and also as its code. L'\0' is printed as "L'\\0'".
Even if sharding is not on, test runners may want to use the
GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding
protocol.
Connect the client socket to the server socket.
comment: Static mutexes are leaked intentionally. It is not thread-safe to try
to clean them up.
TODO(yukawa): Switch to Slim Reader/Writer (SRW) Locks, which requires
nothing to clean it up but is available only on Vista and later.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa904937.aspx
label: requirement
A helper class that creates the premature-exit file in its
constructor and deletes the file in its destructor.
Different Windows APIs may use either of these values to represent an
invalid handle.
Info about the first test in the current test case.
Generates a textual failure message when a death test finds more than
one thread running, or cannot determine the number of threads, prior
to executing the given statement. It is the responsibility of the
caller not to pass a thread_count of 1.
Object that captures an output stream (stdout/stderr).
A test filter that matches everything.
GTEST_OS_LINUX
AssertHelper constructor.
comment: We want to call regcomp(&partial_regex_, ...) even if the
previous expression returns false. Otherwise partial_regex_ may
not be properly initialized can may cause trouble when it's
freed.
Some implementation of POSIX regex (e.g. on at least some
versions of Cygwin) doesn't accept the empty string as a valid
regex. We change it to an equivalent form "()" to be safe.
label: code-design
Previous character is of '\x..' form and this character can be
interpreted as another hexadecimal digit in its number. Break string to
disambiguate.
Formats a file location for compiler-independent XML output.
Although this function is not platform dependent, we put it next to
FormatFileLocation in order to contrast the two functions.
Note that FormatCompilerIndependentFileLocation() does NOT append colon
to the file location it produces, unlike FormatFileLocation().
A predicate that checks the name of a TestCase against a known
value.
This is used for implementation of the UnitTest class only. We put
it in the anonymous namespace to prevent polluting the outer
namespace.
TestCaseNameIs is copyable.
Asserts that val1 is less than, or almost equal to, val2. Fails
otherwise. In particular, it fails if either val1 or val2 is NaN.
Clear the close-on-exec flag on the write end of the pipe, lest
it be closed when the child process does an exec:
Should not get here.
The following lines pull in the real gtest *.cc files.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
The Google C++ Testing Framework (Google Test)
Repeats the call to the post-flag parsing initialization in case the
user didn't call InitGoogleTest.
Generate unique file name.
Captures the value of GTEST_FLAG(catch_exceptions). This value will be
used for the duration of the program.
GTEST_HAS_GLOBAL_WSTRING
Configures listeners for streaming test results to the specified server.
Gets the name of the TEST and the name of the TEST_F. Note
that first_is_TEST and this_is_TEST cannot both be true, as
the fixture IDs are different for the two tests.
Deletes every Test in the collection.
comment: Is this a death test case?
label: test
The role interface for getting the OS stack trace as a string.
If def_optional is true and there are more characters after the
flag name, or if def_optional is false, there must be a '=' after
the flag name.
comment: Notifies the unit test event listeners that a test is about to start.
label: test
This class saves the values of all Google Test flags in its c'tor, and
restores them in its d'tor.
using this in initializer
This group of overloaded functions return true iff needle is a
substring of haystack. NULL is considered a substring of itself
only.
Returns map of thread local instances.
comment: Compares the full test names with the filter to decide which
tests to run.
label: test
On Windows, death tests are thread-safe regardless of the value of the
death_test_style flag.
Returns repeater that broadcasts the TestEventListener events to all
subscribers.
Set close_fd to be closed after spawn.
Returns true iff the test name of test property matches on key_.
Returns true iff ch appears anywhere in str (excluding the
terminating '\0' character).
Returns the number of elements in the given container that satisfy
the given predicate.
Parses the environment variable as a decimal integer.
Points to (but doesn't own) the per-thread test part result reporter.
Prints an XML representation of a TestCase object
Converts a Unicode code point to a narrow string in UTF-8 encoding.
code_point parameter is of type UInt32 because wchar_t may not be
wide enough to contain a code point.
If the code_point is not a valid Unicode code point
(i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
to "(Invalid Unicode 0xXXXXXXXX)".
all done with this structure
A copy of all command line arguments. Set by InitGoogleTest().
Utilities needed for death tests.
Returns a random seed in range [1, kMaxRandomSeed] based on the
given --gtest_random_seed flag value.
Points to (but doesn't own) the global test part result reporter.
Child process handle.
Returns the working directory when the first TEST() or TEST_F() was
executed.
GTEST_OS_MAC
no source, we're asking system
the error
no line width restrictions
output buffer
buf size
no arguments for inserts
Trims tailing white space (FormatMessage leaves a trailing CR-LF)
The destructor of SingleFailureChecker verifies that the given
TestPartResultArray contains exactly one failure that has the given
type and contains the given substring. If that's not the case, a
non-fatal failure will be generated.
Default buffer size.
Parses a string as a command line flag. The string should have
the format "--flag=value". When def_optional is true, the "=value"
part can be omitted.
Returns the value of the flag, or NULL if the parsing failed.
GTEST_INCLUDE_GTEST_GTEST_SPI_H_
If the test part succeeded, we don't need to do anything.
comment: Gets the number of disabled tests that will be reported in the XML report.
label: test
The internal implementation of InitGoogleTest().
The type parameter CharType can be instantiated to either char or
wchar_t.
Loop through all the results and connect to the first we can.
Used by UnitTest::Run() to capture the state of
GTEST_FLAG(catch_exceptions) at the moment it starts.
We print the type parameter on a single line to make
the output easy to parse by a program.
Returns the random seed used at the start of the current test run.
Create directories so that path exists. Returns true if successful or if
the directories already exist; returns false if unable to create directories
for any reason.
Returns the current application's name, removing directory path if that
is present.
Finds the next pattern in the filter.
We have enough matches at the head, and the tail matches too.
Since we only care about *whether* the pattern matches str
(as opposed to *how* it matches), there is no need to find a
greedy match.
Text printed in Google Test's text output and --gunit_list_tests
output to label the type parameter and value parameter for a test.
This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
evaluating any system call that fulfills two conditions: it must return
-1 on failure, and set errno to EINTR when it is interrupted and
should be tried again. The macro expands to a loop that repeatedly
evaluates the expression as long as it evaluates to -1 and sets
errno to EINTR. If the expression evaluates to -1 but errno is
something other than EINTR, DeathTestAbort is called.
Skips the stack frame for this function itself.
NOLINT
Do we see a Google Test flag?
Find first edit.
Restores the original test order after the iteration. This
allows the user to quickly repro a failure that happens in the
N-th iteration without repeating the first (N - 1) iterations.
This is not enclosed in "if (GTEST_FLAG(shuffle)) { ... }", in
case the user somehow changes the value of the flag somewhere
(it's always safe to unshuffle the tests).
Adds a failure if the key is a reserved attribute of the element named
xml_element. Returns true if the property is valid.
Signals the parent that the write end of the pipe has been acquired
so the parent can release its own write end.
Lists the tests and exits if the --gtest_list_tests flag was specified.
Decrements the argument count.
Gets the number of tests that should run.
The list of event listeners that can be used to track events inside
Google Test.
size_t has the same width as pointers on both 32-bit and 64-bit
Windows platforms.
See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
Implements RE. Currently only needed for death tests.
Returns true if pathname describes an absolute path.
Reserves enough bytes to hold the regular expression used for a
full match: we need space to prepend a '^', append a '$', and
terminate the string with '\0'.
Reads and returns a 32-bit integer stored in the environment
variable corresponding to the given flag; if it isn't set or
doesn't represent a valid 32-bit integer, returns default_value.
Does not own.
We take "yes", "true", "t", and "1" as meaning "yes". If the
value is neither one of these nor "auto", we treat it as "no" to
be conservative.
Convenience wrapper around EscapeXml when str is not an attribute value.
Both help flag and unrecognized Google Test flags (excluding
internal ones) trigger help display.
Returns true if exit_status describes a process that was terminated
by a signal, or exited normally with a nonzero exit code.
A predicate that checks the key of a TestProperty against a known key.
TestPropertyKeyIs is copyable.
Gets the number of successful test cases.
comment: TODO(wan): do not print the value of an expression if it's
already a literal.
label: code-design
GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS
The '!= 0' comparison is necessary to satisfy MSVC 7.1.
GTEST_OS_WINDOWS
Convenience function for accessing the global UnitTest
implementation object.
Parses a string for an Int32 flag, in the form of
"--flag=value".
On success, stores the value of the flag in *value, and returns
true. On failure, returns false without changing *value.
The name of the file in which the death test is located.
Protects access to GetThreadMapLocked() and its return value.
Owned.
Creates a Test object.
On z/OS we additionally need strings.h for strcasecmp.
NOLINT
STL container utilities.
comment: Returns the TestCase object for the test that's currently running,
or NULL if no test is running.
label: test
GTEST_HAS_STREAM_REDIRECTION
Tells UnitTest where to store test result.
A test is disabled if test case name or test name matches
kDisableTestFilter.
Reserves enough bytes to hold the regular expression used for a
full match.
Checks whether sharding is enabled by examining the relevant
environment variable values. If the variables are present,
but inconsistent (e.g., shard_index >= total_shards), prints
an error and exits. If in_subprocess_for_death_test, sharding is
disabled because it must only be applied to the original test
process. Otherwise, we could filter out death tests we intended to execute.
namespace internal
Registers and returns a global test environment. When a test
program is run, all global test environments will be set-up in the
order they were registered. After all tests in the program have
finished, all global test environments will be torn-down in the
*reverse* order they were registered.
The UnitTest object takes ownership of the given environment.
We don't protect this under mutex_, as we only support calling it
from the main thread.
This is the default global test part result reporter used in UnitTestImpl.
This class should only be used by UnitTestImpl.
comment: Returns the given string with all characters invalid in XML removed.
Currently invalid characters are dropped from the string. An
alternative is to replace them with certain characters such as . or ?.
label: code-design
This should be done before calling OnTestIterationStart(),
such that a test event listener can see the actual test order
in the event.
Event the child process uses to signal the parent that it has
acquired the handle to the write end of the pipe. After seeing this
event the parent can release its own handles to make sure its
ReadFile() calls return when the child terminates.
num_runnable_tests are the number of tests that will
run across all shards (i.e., match filter and are not disabled).
num_selected_tests are the number of tests to be run on
this shard.
We cannot call abort() as it generates a pop-up in debug mode
that cannot be suppressed in VC 7.1 or below.
NOLINT
NOLINT
Monitors exit from a given thread and notifies those
ThreadIdToThreadLocals about thread termination.
This line ensures that gtest.h can be compiled on its own, even
when it's fused.
GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
Fisher-Yates shuffle, from
http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
The random number seed used at the beginning of the test run.
comment: Gets the singleton UnitTest object. The first time this method is
called, a UnitTest object is constructed and returned. Consecutive
calls will return the same object.
We don't protect this under mutex_ as a user is not supposed to
call this before main() starts, from which point on the return
value will never change.
label: code-design
Returns the current working directory, or "" if unsuccessful.
The ctor redirects the stream to a temporary file.
To aid user debugging, we also print c's code in decimal, unless
it's 0 (in which case c was printed as '\\0', making the code
obvious).
Creates a UTF-16 wide string from the given ANSI string, allocating
memory using new. The caller is responsible for deleting the return
value using delete[]. Returns the wide string, or NULL if the
input is NULL.
A stream to capture.
This points to the TestInfo for the currently running test. It
changes as Google Test goes through one test after another. When
no test is running, this is set to NULL and Google Test stores
assertion results in ad_hoc_test_result_. Initially NULL.
Returns a pointer to the current death test factory.
This function implements either IsSubstring() or IsNotSubstring(),
depending on the value of the expected_to_be_substring parameter.
StringType here can be const char*, const wchar_t*, ::std::string,
or ::std::wstring.
Returns true if c is a printable ASCII character. We test the
value of c directly instead of calling isprint(), which is buggy on
Windows Mobile.
NOLINT
The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
Converts the buffer in a stringstream to an std::string, converting NUL
bytes to "\\0" along the way.
Helper function for IsHRESULT{SuccessFailure} predicates
Waits for any of the handles.
Returns true iff the name of test_case matches name_.
Gets the summary of the failure message by omitting the stack trace
in it.
The following routines generate an XML representation of a UnitTest
object.
This is how Google Test concepts map to the DTD:
<testsuites name="AllTests"> <-- corresponds to a UnitTest object
<testsuite name="testcase-name"> <-- corresponds to a TestCase object
<testcase name="test-name"> <-- corresponds to a TestInfo object
<failure message="...">...</failure>
<failure message="...">...</failure>
<failure message="...">...</failure>
<-- individual assertion failures
</testcase>
</testsuite>
</testsuites>
comment: TODO(wan@google.com): on Windows a network share like
\\server\share can be a root directory, although it cannot be the
current directory. Handle this properly.
label: code-design
Returns the number of threads running in the process, or 0 to indicate that
we cannot detect it.
The environment variable name for the test shard index.
Do nothing.
Somebody else is already initializing the mutex; spin until they
are done.
D'tor.
We pass skip_count + 1 to skip this wrapper function in addition
to what the user really wants to skip.
When Google Test is built as a framework on MacOS X, the environ variable
is unavailable. Apple's documentation (man environ) recommends using
_NSGetEnviron() instead.
GTEST_HAS_PARAM_TEST
Repeats forever if the repeat count is negative.
Attempts to parse a string into a positive integer pointed to by the
number parameter. Returns true if that is possible.
GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
it here.
Gets the elapsed time, in milliseconds.
Sets up all environments beforehand.
Windows CE doesn't support FormatMessage.
Handle to the write end of the pipe to the child process.
No - an invalid character was encountered.
How long the test took to run, in milliseconds.
Redirects all logging to stderr in the child process to prevent
concurrent writes to the log files. We capture stderr in the parent
process and append the child process' output to a log.
GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
can use it here.
Formats a byte as "%02X".
This function should not be called when the condition is
false, but we provide a sensible default in case it is.
The c'tor sets this object as the test part result reporter used by
Google Test. The 'result' parameter specifies where to report the
results.
comment: Removes any redundant separators that might be in the pathname.
For example, "bar///foo" becomes "bar/foo". Does not eliminate other
redundancies that might be in a pathname involving "." or "..".
TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
label: code-design
GTEST_USES_POSIX_RE
Note that the above two checks will both fail if either val1 or
val2 is NaN, as the IEEE floating-point standard requires that
any predicate involving a NaN must return false.
Splits a given string on a given delimiter, populating a given
vector with the fields. GTEST_HAS_DEATH_TEST implies that we have
::std::string, so we can use it here.
namespace edit_distance
comment: Unshuffles the tests in each test case.
label: test
When a SIGPROF signal is received while fork() or clone() are executing,
the process may hang. To avoid this, we ignore SIGPROF here and re-enable
it after the call to fork()/clone() is complete.
Adds an "exception thrown" fatal failure to the current test. This
function returns its result via an output parameter pointer because VC++
prohibits creation of objects with destructors on stack in functions
using __try (see error C2712).
skip_count
Prohibit instantiation.
Google Test should handle a SEH exception if:
1. the user wants it to, AND
2. this is not a breakpoint exception, AND
3. this is not a C++ exception (VC++ implements them via SEH,
apparently).
SEH exception code for C++ exceptions.
(see http://support.microsoft.com/kb/185294 for more information).
Sets the global test part result reporter.
Provides access to the event listener list.
Implements the TestPartResultReporterInterface. The implementation just
delegates to the current global test part result reporter of *unit_test_.
Sets the OS stack trace getter.
Does nothing if the input and the current OS stack trace getter
are the same; otherwise, deletes the old getter and makes the
input the current getter.
Whole string is a positive filter
We are done. We don't want this hunk.
Outside the lock, let the destructor for 'value_holders' deallocate the
ThreadLocalValueHolderBases.
Returns true iff regular expression re matches a substring of str
(including str itself).
This string is inserted in place of stack frames that are part of
Google Test's implementation.
A set of macros for testing Google Test assertions or code that's expected
to generate Google Test fatal failures. It verifies that the given
statement will cause exactly one fatal Google Test failure with 'substr'
being part of the failure message.
There are two different versions of this macro. EXPECT_FATAL_FAILURE only
affects and considers failures generated in the current thread and
EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
The verification of the assertion is done correctly even when the statement
throws an exception or aborts the current function.
Known restrictions:
- 'statement' cannot reference local non-static variables or
non-static members of the current object.
- 'statement' cannot return a value.
- You cannot stream a failure message to this macro.
Note that even though the implementations of the following two
macros are much alike, we cannot refactor them to use a common
helper macro, due to some peculiarity in how the preprocessor
works. The AcceptsMacroThatExpandsToUnprotectedComma test in
gtest_unittest.cc will fail to compile if we do that.
Creates an empty UnitTest.
Organizes the bytes into groups of 2 for easy parsing by
human.
namespace testing
Copyright 2008 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Is the first thing in regex an escape sequence?
This class implements the TestEventListener interface.
Class PrettyUnitTestResultPrinter is copyable.
Constructor.
TestPropertyKeyIs has NO default constructor.
Implements the helper function for {ASSERT|EXPECT}_LE with int or
enum arguments.
class TestInfo
True iff we are in a subprocess for running a thread-safe-style
death test.
comment: Returns an indented copy of stderr output for a death test.
This makes distinguishing death test output lines from regular log lines
much easier.
label: code-design
Returns the ANSI color code for the given color. COLOR_DEFAULT is
an invalid input.
Returns the value of GTEST_FLAG(catch_exceptions) at the moment
UnitTest::Run() starts.
comment: TODO(kenton@google.com): Use autoconf to detect availability of
gettimeofday().
label: requirement
Gets the text streamed to this object so far as an std::string.
Each '\0' character in the buffer is replaced with "\\0".
Prints the filter if it's not *. This reminds the user that some
tests may be skipped.
Indicates that this translation unit is part of Google Test's
implementation. It must come before gtest-internal-inl.h is
included, or there will be a compiler error. This trick exists to
prevent the accidental inclusion of gtest-internal-inl.h in the
user's code.
Some POSIX platforms expect you to declare environ. extern "C" makes
it reside in the global namespace.
Parameter to ThreadMainStatic
Default creation flags.
Need a valid pointer for the call to work under Win98.
Give the watcher thread the same priority as ours to avoid being
blocked by it.
Starts capturing stdout.
Returns true iff the test fatally failed.
Performs an in-place shuffle of the vector's elements.
Pops a trace from the per-thread Google Test trace stack.
Returns true iff the user-specified filter matches the test case
name and the test name.
See the comment in NoExecDeathTest::AssumeRole for why the next line
is necessary.
namespace testing
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: keith.ray@gmail.com (Keith Ray)
OS selector
namespace internal
namespace testing
Copyright 2007, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Parses the environment variable var as an Int32. If it is unset,
returns default_val. If it is not an Int32, prints an error
and aborts.
comment: TODO(vladl@google.com): Factor the search functionality into Vector::Find.
label: code-design
Replaces NUL with "\\0";
Normally, a user only writes assertions inside a TEST or TEST_F,
or inside a function called by a TEST or TEST_F. Since Google
Test keeps track of which test is current running, it can
associate such an assertion with the test it belongs to.
If an assertion is encountered when no TEST or TEST_F is running,
Google Test attributes the assertion result to an imaginary "ad hoc"
test, and records the result in ad_hoc_test_result_.
10xxxxxx
10xxxxxx
1110xxxx
code_point <= kMaxCodePoint4
Returns true iff the unit test passed (i.e. all test cases passed).
Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
The string representation of the values received in EqFailure() are already
escaped. Split them on escaped '\n' boundaries. Leave all other escaped
characters the same.
To allow both IPv4 and IPv6 addresses.
Initializes Google Test. This must be called before calling
RUN_ALL_TESTS(). In particular, it parses a command line for the
flags that Google Test recognizes. Whenever a Google Test flag is
seen, it is removed from argv, and *argc is decremented.
No value is returned. Instead, the Google Test flag variables are
updated.
Calling the function for the second time has no user-visible effect.
Utility class for accumulating command-line arguments.
Converts the given wide string to a narrow string using the UTF-8
encoding, and streams the result to this Message object.
Returns the number of the test properties.
Initializes owner_thread_id_ and critical_section_ in static mutexes.
Returns the global test part result reporter.
cpplint thinks that the header is already included, so we want to
silence it.
NOLINT
All of these virtual functions are inherited from DeathTest.
create the file with a single "0" character in it. I/O
errors are ignored as there's nothing better we can do and we
don't want to fail the test because of this.
Prints a TestPartResult.
The constructor of SingleFailureChecker remembers where to look up
test part results, what type of failure we expect, and what
substring the failure message should contain.
There are two different ways to register your own TestPartResultReporter.
You can register your own repoter to listen either only for test results
from the current thread or for results from all threads.
By default, each per-thread test result repoter just passes a new
TestPartResult to the global test result reporter, which registers the
test part result for the currently running test.
Returns true if "name" matches the ':' separated list of glob-style
filters in "filter".
comment: Returns the TestResult for the ad hoc test.
label: test
This defines a member that forwards the call to all listeners in reverse
order.
Tells UnitTest to stop associating assertion results to this
test.
The AssumeRole process for a fork-and-run death test. It implements a
straightforward fork, with a simple pipe to transmit the status byte.
Generates a random number from [0, range), using a Linear
Congruential Generator (LCG). Crashes if 'range' is 0 or greater
than kMaxRange.
Pops the info pushed by the c'tor.
Aborts if the parsing failed.
Returns the name of the environment variable corresponding to the
given flag. For example, FlagToEnvVar("foo") will return
"GTEST_FOO" in the open-source version.
namespace testing
This is the default per thread test part result reporter used in
UnitTestImpl. This class should only be used by UnitTestImpl.
comment: Delegates to PrintBytesInObjectToImpl() to print the bytes in the
given object. The delegation simplifies the implementation, which
uses the << operator and thus is easier done outside of the
::testing::internal namespace, which contains a << operator that
sometimes conflicts with the one in STL.
label: code-design
The c'tor.
The helper function for {ASSERT|EXPECT}_STREQ.
spawn is a system call.
comment: We don't call OutputDebugString*() on Windows Mobile, as printing
to stdout is done by OutputDebugString() there already - we don't
want the same message printed twice.
label: code-design
Returns true if pathname describes a root directory. (Windows has one
root directory per disk drive.)
Declares the flags.
We don't want the users to modify this flag in the code, but want
Google Test's own unit tests to be able to access it. Therefore we
declare it here as opposed to in gtest.h.
The two possible mocking modes of this object.
Performs initialization dependent upon flag values obtained in
ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
this function is also called from RunAllTests. Since this function can be
called more than once, it has to be idempotent.
The c'tor sets this object as the test part result reporter used by
Google Test. The 'result' parameter specifies where to report the
results. Intercepts only failures from the current thread.
Message assignment, for assertion streaming support.
comment: Adds a test part result to the list.
label: test
Big enough for the largest valid code point.
If the test program runs in Visual Studio or a debugger, the
following statements add the test part result message to the Output
window such that the user can double-click on it to jump to the
corresponding source code location; otherwise they do nothing.
Shuffles test cases and tests if requested.
Initializes event listeners performing XML output as specified by
UnitTestOptions. Must not be called before InitGoogleTest.
!_WIN32_WCE
Tells the user how big the object is.
Runs the test and updates the test result.
Escapes '=', '&', '%', and '\n' characters in str as "%xx".
Flush the log buffers since the log streams are shared with the child.
Finds and returns a TestCase with the given name. If one doesn't
exist, creates one and returns it. It's the CALLER'S
RESPONSIBILITY to ensure that this function is only called WHEN THE
TESTS ARE NOT SHUFFLED.
Arguments:
test_case_name: name of the test case
type_param: the name of the test case's type parameter, or NULL if
this is not a typed or a type-parameterized test case.
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
Constructor.
ParameterizedTestRegistry object used to register value-parameterized
tests.
Returns true iff "\\c" is a supported escape sequence.
ExitedWithCode function-call operator.
The d'tor restores the previous test part result reporter.
Returns if no more pattern can be found.
Sends a string to the socket.
Returns a copy of the FilePath with the case-insensitive extension removed.
Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
FilePath("dir/file"). If a case-insensitive extension is not
found, returns a copy of the original FilePath.
read_fd_ is expected to be closed and cleared by a derived class.
Starts capturing an output stream (stdout/stderr).
Copyright 2007, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Utilities for testing Google Test itself and code that uses Google Test
(e.g. frameworks built on top of Google Test).
Holds the thread id and thread handle that we pass from
StartWatcherThreadFor to WatcherThreadFunc.
No. Appends to the end of the list.
Closes the socket.
A Unicode code-point can have upto 21 bits, and is encoded in UTF-8
like this:
Code-point length Encoding
0 - 7 bits 0xxxxxxx
8 - 11 bits 110xxxxx 10xxxxxx
12 - 16 bits 1110xxxx 10xxxxxx 10xxxxxx
17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
class StreamingListener
Makes sure InitGoogleTest() was called.
Reset count when a non match is found.
Formats an int value as "%02d".
Returns the absolute path of the requested output file, or the
default (test_detail.xml in the original working directory) if
none was explicitly specified.
Adds a TestProperty to the current TestResult object when invoked in a
context of a test or a test case, or to the global property set. If the
result already contains a property with the same key, the value will be
updated.
comment: The main function for a threadsafe-style death test child process.
This function is called in a clone()-ed process and thus must avoid
any potentially unsafe operations like malloc or libc functions.
label: code-design
Returns true iff the test part fatally failed.
GTEST_OS_NACL
Prints a wide or narrow char c as a character literal without the
quotes, escaping it when necessary; returns how c was formatted.
The template argument UnsignedChar is the unsigned version of Char,
which is the type of c.
Creates a concrete DeathTest-derived class that depends on the
--gtest_death_test_style flag, and sets the pointer pointed to
by the "test" argument to its address. If the test should be
skipped, sets that pointer to NULL. Returns true, unless the
flag is set to an invalid value.
Windows CE doesn't have a current directory, so we just return
something reasonable.
GTEST_IMPLEMENTATION_
10xxxxxx
110xxxxx
Restores the test cases and tests to their order before the first shuffle.
Called after an assertion failure.
Indicates whether RegisterParameterizedTests() has been called already.
Keeps reading the file until we cannot read further or the
pre-determined file size is reached.
Runs the tests only if there was no fatal failure during global
set-up.
Makes a successful assertion result.
Implements the helper function for {ASSERT|EXPECT}_NE with int or
enum arguments.
Constructs a TestInfo object. It assumes ownership of the test factory
object.
We are not on Windows.
Google Test requires all tests in the same test case to use the same test
fixture class. This function checks if the current test has the
same fixture class as the first test in the current test case. If
yes, it returns true; otherwise it generates a Google Test failure and
returns false.
comment: Gets the number of disabled tests in this test case.
label: test
KilledBySignal constructor.
Split --gtest_filter at '-', if there is one, to separate into
positive filter and negative filter portions
The maximum code-point a one-byte UTF-8 sequence can represent.
Updates the critical_section_init_phase_ to 2 to signal
initialization complete.
Returns the TestResult containing information on test failures and
properties logged outside of individual test cases.
Either ':' or '\0' marks the end of the pattern.
Using DebugBreak on Windows allows gtest to still break into a debugger
when a failure happens and both the --gtest_break_on_failure and
the --gtest_catch_exceptions flags are specified.
Get the number of tests in this test case that should run.
Returns true iff the current test has a fatal failure.
Tells the unit test event listeners that the tests are about to start.
The list of reserved attributes used in the <testsuite> element of XML
output.
Restores the test order to before the first shuffle.
Disable Microsoft deprecation warnings for POSIX functions called from
this class (creat, dup, dup2, and close)
Stops capturing stderr and returns the captured string.
Skips the flag name.
Controls whether events will be forwarded by the repeater to the
listeners in the list.
Returns true iff the given atom (specified by escaped and pattern)
matches ch. The result is undefined if the atom is invalid.
comment: On Windows the TERM variable is usually not set, but the
console there does support colors.
label: code-design
Returns the string after "=".
We print the value parameter on a single line to make the
output easy to parse by a program.
Class ScopedTrace
No stack trace, either.
Constructs a ForkingDeathTest.
The environment variable name for the total number of test shards.
Death test children can be terminated with _abort(). On Windows,
_abort() can show a dialog with a warning message. This forces the
abort message to go to stderr instead.
Create a list of diff hunks in Unified diff format.
Each hunk has a header generated by PrintHeader above plus a body with
lines prefixed with ' ' for no change, '-' for deletion and '+' for
addition.
'context' represents the desired unchanged prefix/suffix around the diff.
If two hunks are close enough that their contexts overlap, then they are
joined into one hunk.
Both TEST and TEST_F appear in same test case, which is incorrect.
Tell the user how to fix this.
Retuned process handle is not inheritable.
Retuned thread handle is not inheritable.
Child inherits all inheritable handles (for write_handle_).
Default creation flags.
Inherit the parent's environment.
Produces a string representing the test properties in a result as space
delimited XML attributes based on the property key="value" pairs.
Prints a ::wstring object.
Reconstruct the best path. We do it in reverse order.
comment: Helper function used by ValidateRegex() to format error messages.
label: code-design
Comparing two pointers of which only one is NULL is undefined.
Prints the given wide C string to the ostream.
The read() here blocks until data is available (signifying the
failure of the death test) or until the pipe is closed (signifying
its success), so it's okay to call this in the parent before
the child process has exited.
Returns the TestPartResult at the given index (0-based).
Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
This function is useful as an __except condition.
The helper function for {ASSERT|EXPECT}_STRNE.
Checks whether sharding is enabled by examining the relevant
environment variable values. If the variables are present,
but inconsistent (i.e., shard_index >= total_shards), prints
an error and exits. If in_subprocess_for_death_test, sharding is
disabled because it must only be applied to the original test
process. Otherwise, we could filter out death tests we intended to execute.
Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
Helper function for *_STRNE on wide strings.
We can safely call chdir() as it's a direct system call.
Find the first line to include in the hunk.
The maximum code-point a four-byte UTF-8 sequence can represent.
"$" only matches the end of a string. Note that regex being
valid guarantees that there's nothing after "$" in it.
comment: This function is a friend of UnitTest and as such has access to
AddTestPartResult.
label: code-design
On non-Windows platforms, we rely on the TERM variable.
Formats the count of test cases.
Gets the number of successful tests.
Recreates the pipe and event handles from the provided parameters,
signals the event, and returns a file descriptor wrapped around the pipe
handle. This function is called in the child process only.
The UnitTest object that owns this implementation object.
Tears down all environments in reverse order afterwards.
The event will automatically reset to non-signaled state.
The initial state is non-signalled.
The even is unnamed.
Produces a string representing the test properties in a result as space
delimited XML attributes based on the property key="value" pairs.
When the std::string is not empty, it includes a space at the beginning,
to delimit this attribute from prior attributes.
Destructs a TestInfo object.
The OS stack trace getter. Will be deleted when the UnitTest
object is destructed. By default, an OsStackTraceGetter is used,
but the user can set this field to use a custom getter if that is
desired.
Gets the number of failed test cases.
This points to the TestCase for the currently running test. It
changes as Google Test goes through one test case after another.
When no test is running, this is set to NULL and Google Test
stores assertion results in ad_hoc_test_result_. Initially NULL.
A helper class for implementing EXPECT_FATAL_FAILURE() and
EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
TestPartResultArray contains exactly one failure that has the given
type and contains the given substring. If that's not the case, a
non-fatal failure will be generated.
The list of listeners that receive events.
Prints the bytes in the given value to the given ostream.
Will be overridden by the flag before first use.
Will be reseeded before first use.
ExitedWithCode constructor.
Returns the size (in bytes) of a file.
Windows CE doesn't have a current directory. You should not use
the current directory in tests on Windows CE, but this at least
provides a reasonable fallback.
No info about the source file where the exception occurred.
We have no info on which line caused the exception.
Is the first test defined using TEST?
Indicates that this translation unit is part of Google Test's
implementation. It must come before gtest-internal-inl.h is
included, or there will be a compiler error. This trick is to
prevent a user from accidentally including gtest-internal-inl.h in
his code.
Sends the given message and a newline to the socket.
We need to flush the stream buffers into the console before each
SetConsoleTextAttribute call lest it affect the text that is already
printed but has not yet reached the console.
The default test part result reporters.
Adds an "exception thrown" fatal failure to the current test.
Resets the terminal to default.
GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
Creates an empty TestResult.
The mutex is already initialized and ready for use.
Note: Android applications are expected to call the framework's
Context.getExternalStorageDirectory() method through JNI to get
the location of the world-writable SD Card directory. However,
this requires a Context handle, which cannot be retrieved
globally from native code. Doing so also precludes running the
code as part of a regular standalone executable, which doesn't
run in a Dalvik process (e.g. when running it through 'adb shell').
The location /sdcard is directly accessible from native code
and is the only location (unofficially) supported by the Android
team. It's generally a symlink to the real SD Card mount point
which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
other OEM-customized locations. Never rely on these, and always
use /sdcard.
Android, Mac OS X and Cygwin don't define wcscasecmp.
Other unknown OSes may not define it either.
GTEST_HAS_EXCEPTIONS
The d'tor restores the test part result reporter used by Google Test
before.
Either the user wants Google Test to catch exceptions thrown by the
tests or this is executing in the context of death test child
process. In either case the user does not want to see pop-up dialogs
about crashes - they are expected.
comment: Shuffles all test cases, and the tests within each test case,
making sure that death tests are still run first.
label: test
Gets the i-th test case among all the test cases. i can range from 0 to
total_test_case_count() - 1. If i is not in that range, returns NULL.
(_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
If critical_section_init_phase_ was 0 before the exchange, we
are the first to test it and need to perform the initialization.
comment: On a POSIX system, this function may be called from a threadsafe-style
death test child process, which operates on a very small stack. Use
the heap for any additional non-minuscule memory requirements.
label: code-design
Not an escape sequence.
GTestIsInitialized() returns true iff the user has initialized
Google Test. Useful for catching the user mistake of not initializing
Google Test before calling RUN_ALL_TESTS().
A user must call testing::InitGoogleTest() to initialize Google
Test. g_init_gtest_count is set to the number of times
InitGoogleTest() has been called. We don't protect this variable
under a mutex as it is only accessed in the main thread.
Deletes every TestCase.
The maximum code-point a two-byte UTF-8 sequence can represent.
substr_expr
Returns the character attribute for the given color.
We want to preserve failures generated by ad-hoc test
assertions executed before RUN_ALL_TESTS().
The line number on which the death test is located.
A per-thread stack of traces created by the SCOPED_TRACE() macro.
Gets the number of successful tests in this test case.
Returns true iff the unit test failed (i.e. some test case failed
or something outside of all tests failed).
Reads and returns the Boolean environment variable corresponding to
the given flag; if it's not set, returns default_value.
The value is considered true iff it's not "0".
The value of GetTestTypeId() as seen from within the Google Test
library. This is solely for testing GetTestTypeId().
The textual content of the code this object is testing. This class
doesn't own this string and should not attempt to delete it.
0xxxxxxx
Runs each test case if there is at least one test to run.
The constructor remembers the arguments.
Swaps two AssertionResults.
Compares two C strings, ignoring case. Returns true iff they have
the same content.
Unlike strcasecmp(), this function can handle NULL argument(s). A
NULL C string is considered different to any non-NULL C string,
including the empty string.
Functions for processing the gtest_output flag.
Sends a string and a newline to the socket.
comment: TODO(yukawa): Consider to use _beginthreadex instead.
label: code-design
comment: Two utility routines that together determine the direction the stack
grows.
This could be accomplished more elegantly by a single recursive
function, but we want to guard against the unlikely possibility of
a smart compiler optimizing the recursion away.
GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
StackLowerThanAddress into StackGrowsDown, which then doesn't give
correct answer.
label: code-design
Clean up the ThreadIdToThreadLocals data structure while holding the
lock, but defer the destruction of the ThreadLocalValueHolderBases.
Returns true iff the test has a non-fatal failure.
True iff ?, *, or + can follow the previous atom.
Sets the default_xml_generator attribute to the provided listener. The
listener is also added to the listener list and previous
default_xml_generator is removed from it and deleted. The listener can
also be NULL in which case it will not be added to the list. Does
nothing if the previous and the current listener objects are the same.
Adds a TestProperty to the current TestResult object when invoked from
inside a test, to current TestCase's ad_hoc_test_result_ when invoked
from SetUpTestCase or TearDownTestCase, or to the global property set
when invoked elsewhere. If the result already contains a property with
the same key, the value will be updated.
comment: Helper functions for naming files in a directory for xml output.
label: code-design
We are on Windows CE.
Abstract base class for writing strings to a socket.
Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
Intercepts only thread local failures.
Intercepts all failures.
Treat '-test1' as the same as '*-test1'
Found a match. Consume it.
StringType here can be either ::std::string or ::std::wstring.
Returns success if val1 is less than val2,
Create the directory so that path exists. Returns true if successful or
if the directory already exists; returns false if unable to create the
directory for any reason, including if the parent directory does not
exist. Not named "CreateDirectory" because that's a macro on Windows.
Controls whether events will be forwarded to listeners_. Set to false
in death test child processes.
Requested privileges ignored since
DUPLICATE_SAME_ACCESS is used.
Request non-inheritable handler.
Creates a new XmlUnitTestResultPrinter.
This overloaded version can be used in Windows programs compiled in
UNICODE mode.
Adds a test property to the list. If a property with the same key as the
supplied property is already represented, the value of this test_property
replaces the old value for that key.
comment: How the death test concluded.
label: test
These two overloads allow streaming a wide C string to a Message
using the UTF-8 encoding.
Clears the test part results.
Given directory = "dir", base_name = "test", number = 0,
extension = "xml", returns "dir/test.xml". If number is greater
than zero (e.g., 12), returns "dir/test_12.xml".
On Windows platform, uses \ as the separator rather than /.
Populate for empty right.
protects all internal state
Helper class to convert string into ids with deduplication.
Runs the given method and handles SEH exceptions it throws, when
SEH is supported; returns the 0-value for type Result in case of an
SEH exception. (Microsoft compilers cannot handle SEH and C++
exceptions in the same function. Therefore, we provide a separate
wrapper function for handling SEH exceptions.)
This method expands all parameterized tests registered with macros TEST_P
and INSTANTIATE_TEST_CASE_P into regular tests and registers those.
This will be done just once during the program runtime.
Difference between 1970-01-01 and 1601-01-01 in milliseconds.
http://analogous.blogspot.com/2005/04/epoch.html
g_help_flag is true iff the --help flag or an equivalent form is
specified on the command line.
Normalizes the actual seed to range [1, kMaxRandomSeed] such that
it's easy to type.
We will run the test only if SetUp() was successful.
Registers parameterized tests. This makes parameterized tests
available to the UnitTest reflection API without running
RUN_ALL_TESTS.
Gets the number of all test parts. This is the sum of the number
of successful test parts and the number of failed test parts.
Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
Descriptor to the child's write end of the pipe to the parent process.
It is always -1 in the parent process. The parent keeps its end of the
pipe in read_fd_.
Does nothing if the current thread holds the mutex. Otherwise, crashes
with high probability.
comment: A macro for testing Google Test assertions or code that's expected to
generate Google Test non-fatal failures. It asserts that the given
statement will cause exactly one non-fatal Google Test failure with 'substr'
being part of the failure message.
There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
affects and considers failures generated in the current thread and
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
'statement' is allowed to reference local variables and members of
the current object.
The verification of the assertion is done correctly even when the statement
throws an exception or aborts the current function.
Known restrictions:
- You cannot stream a failure message to this macro.
Note that even though the implementations of the following two
macros are much alike, we cannot refactor them to use a common
helper macro, due to some peculiarity in how the preprocessor
works. If we do that, the code won't compile when the user gives
EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
expands to code containing an unprotected comma. The
AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
catches that.
For the same reason, we have to write
if (::testing::internal::AlwaysTrue()) { statement; }
instead of
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
to avoid an MSVC warning on unreachable code.
label: code-design
Matches any single character.
Picks a new random seed for each iteration.
Application pathname gotten in InitGoogleTest.
comment: Implements the TestPartResultReporterInterface. Reports the test part
result in the current test.
label: test
Event forwarding to the listeners of event listener API mush be shut
down in death test subprocesses.
Is this test defined using TEST?
Fail fast if the given string does not begin with a digit;
this bypasses strtoXXX's "optional leading whitespace and plus
or minus sign" semantics, which are undesirable here.
We don't protect writing to owner_thread_id_ here, as it's the
caller's responsibility to ensure that the current thread holds the
mutex when this is called.
Initializes the event listener performing XML output as specified by
UnitTestOptions. Must not be called before InitGoogleTest.
Runs all tests in this UnitTest object and prints the result.
Returns 0 if successful, or 1 otherwise.
We don't protect this under mutex_, as we only support calling it
from the main thread.
If, however, the last element in the array is not '\0', e.g.
const char kFoo[] = { 'f', 'o', 'o' };
we must print the entire array. We also print a message to indicate
that the array is not NUL-terminated.
Returns the list of event listeners that can be used to track events
inside Google Test.
Clear the following flags:
pop-up window, core dump.
We need to execute the test program in the same environment where
it was originally invoked. Therefore we change to the original
working directory first.
Initializes event listeners for streaming test results in string form.
Must not be called before InitGoogleTest.
Resets the index of each test case.
We know that the atom matches each of the first i characters in str.
Print at most this many characters for each type/value parameter.
We save the stack frame below the frame that calls user code.
We do this because the address of the frame immediately below
the user code changes between the call to UponLeavingGTest()
and any calls to CurrentStackTrace() from within the user code.
Matches any string (possibly empty) of characters.
Applies a function/functor to each element in the container.
Prints a TestPartResult to an std::string.
Gets the number of tests to be printed in the XML report.
The c'tor saves the values of all Google Test flags.
Depending on the value of a char (or wchar_t), we print it in one
of three formats:
- as is if it's a printable ASCII (e.g. 'a', '2', ' '),
- as a hexidecimal escape sequence (e.g. '\x7F'), or
- as a special escape sequence (e.g. '\r', '\n').
cpplint thinks that the header is already included, so we want to
silence it.
NOLINT
NOLINT
The child process will share the standard handles with the parent.
comment: Can we find a TestCase with the given name?
label: test
Starts capturing stderr.
Populate for empty left.
KilledBySignal function-call operator.
Removes the given event listener from the list and returns it. It then
becomes the caller's responsibility to delete the listener. Returns
NULL if the listener is not found in the list.
We need to to pass a valid thread ID pointer into CreateThread for it
to work correctly under Win98.
BiggestConvertible is the largest integer type that system-provided
string-to-number conversion routines can return.
comment: TODO(vladl@google.com): Convert this to compile time assertion when it is
available.
label: code-design
Gets the result and clears it.
results_expr
GTEST_HAS_SEH
We can safely call execve() as it's a direct system call. We
cannot use execvp() as it's a libc function and thus potentially
unsafe. Since execve() doesn't search the PATH, the user must
invoke the test program via a valid path that contains at least
one path separator.
This must be called *after* FilterTests() has been called.
Returns the number of TestPartResult objects in the array.
GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
Constants.
A predicate that checks the test name of a TestInfo against a known
value.
This is used for implementation of the TestCase class only. We put
it in the anonymous namespace to prevent polluting the outer
namespace.
TestNameIs is copyable.
Prints a wide or narrow character c and its code. '\0' is printed
as "'\\0'", other unprintable characters are also properly escaped
using the standard C++ escape sequence. The template argument
UnsignedChar is the unsigned version of Char, which is the type of c.
comment: We put these helper functions in the internal namespace as IBM's xlC
compiler rejects the code if they were declared static.
label: code-design
Transfers ownership.
Called after the unit test ends.
A replacement for CHECK that calls DeathTestAbort if the assertion
fails.
Returns a Boolean value indicating whether the caller is currently
executing in the context of the death test child process. Tools such as
Valgrind heap checkers may need this to modify their behavior in death
tests. IMPORTANT: This is an internal utility. Using it may break the
implementation of death tests. User code MUST NOT use it.
Advance indices, depending on edit type.
There is no next edit or it is too far away.
Returns the first valid random seed after 'seed'. The behavior is
undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
considered to be 1.
Creates a TestCase with the given name.
Arguments:
name: name of the test case
a_type_param: the name of the test case's type parameter, or NULL if
this is not a typed or a type-parameterized test case.
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
Returns the current OS stack trace as an std::string. Parameters:
max_depth - the maximum number of stack frames to be included
in the trace.
skip_count - the number of top frames to be skipped; doesn't count
against max_depth.
TestResult appropriate for property recording.
comment: GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
label: test
Flag characters for reporting a death test that did not die.
Gets the current text color.
If the object size is bigger than kThreshold, we'll have to omit
some details by printing only the first and the last kChunkSize
bytes.
TODO(wan): let the user control the threshold using a flag.
unit_test
GTEST_OS_WINDOWS_MOBILE
Parses a string for a bool flag, in the form of either
"--flag=value" or "--flag".
In the former case, the value is taken as true as long as it does
not start with '0', 'f', or 'F'.
In the latter case, the value is taken as true.
On success, stores the value of the flag in *value, and returns
true. On failure, returns false without changing *value.
Verifies that registered_tests match the test names in
defined_test_names_; returns registered_tests if successful, or
aborts the program otherwise.
Provides a level of indirection for the test case list to allow
easy shuffling and restoring the test case order. The i-th
element of this vector is the index of the i-th test case in the
shuffled order.
Returns a pointer to the parsed --gtest_internal_run_death_test
flag, or NULL if that flag was not specified.
This information is useful only in a death test child process.
Must not be called before a call to InitGoogleTest.
Default security.
Default stack size.
socket file descriptor
For strtoll/_strtoul64/malloc/free.
For memmove.
TestResult contains some private methods that should be hidden from
Google Test user but are required for testing. This class allow our tests
to access them.
This class is supplied only for the purpose of testing Google Test's own
constructs. Do not use it in user tests, either directly or indirectly.
Returns the given string with all characters invalid in XML removed.
Prints the names of the tests matching the user-specified filter flag.
The environment variable is not set.
namespace testing
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
This file implements death tests.
The maximum code-point a three-byte UTF-8 sequence can represent.
GTEST_OS_LINUX_ANDROID
Chops off the n lowest bits from a bit pattern. Returns the n
lowest bits. As a side effect, the original bit pattern will be
shifted to the right by n bits.
Appends the user-supplied message to the Google-Test-generated message.
Returns the i-th test part result among all the results. i can
range from 0 to total_part_count() - 1. If i is not in that range,
aborts the program.
The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
class TestCase
Pushes the given source file location and message onto a per-thread
trace stack maintained by Google Test.
Convenience wrapper around EscapeXml when str is an attribute value.
Runs every test in this TestCase.
10xxxxxx
10xxxxxx
10xxxxxx
11110xxx
Called at the start of streaming to notify the receiver what
protocol we are using.
Utilities
Do not run any test if the --help flag was specified.
This generic version is used when k is 0.
class CartesianProductGenerator3
Type and function utilities for implementing parameterized tests.
Generates a random number from [0, range). Crashes if 'range' is
0 or greater than kMaxRange.
A test case, which consists of a vector of TestInfos.
TestCase is not copyable.
A compile-time bool constant that is true if and only if x is a
null pointer literal (i.e. NULL or any 0-valued compile-time
integral constant).
These two compilers are known to support SEH.
Makes sure T is a complete type.
Inside a test, refer to TypeParam to get the type parameter.
Then prints the value itself.
Declares the flags.
Sets the should_run member.
Implements printing a non-reference type T by letting the compiler
pick the right overload of PrintTo() for T.
Appends an event listener to the end of the list. Google Test assumes
the ownership of the listener (i.e. it will delete the listener when
the test program finishes).
GTEST_INCLUDE_GTEST_GTEST_H_
Compares two wide C strings, ignoring case. Returns true iff they
have the same content.
Unlike wcscasecmp(), this function can handle NULL argument(s).
A NULL C string is considered different to any non-NULL wide C string,
including the empty string.
NB: The implementations on different platforms slightly differ.
On windows, this method uses _wcsicmp which compares according to LC_CTYPE
environment variable. On GNU platform this method uses wcscasecmp
which compares according to LC_CTYPE category of the current locale.
On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
current locale.
Defines the abstract factory interface that creates instances
of a Test object.
EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
The death testing framework causes this to have interesting semantics,
since the sideeffects of the call are only visible in opt mode, and not
in debug mode.
In practice, this can be used to test functions that utilize the
LOG(DFATAL) macro using the following style:
int DieInDebugOr12(int* sideeffect) {
if (sideeffect) {
*sideeffect = 12;
}
LOG(DFATAL) << "death";
return 12;
}
TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {
int sideeffect = 0;
// Only asserts in dbg.
EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
#ifdef NDEBUG
// opt-mode has sideeffect visible.
EXPECT_EQ(12, sideeffect);
#else
// dbg-mode no visible sideeffect.
EXPECT_EQ(0, sideeffect);
#endif
}
This will assert that DieInDebugReturn12InOpt() crashes in debug
mode, usually due to a DCHECK or LOG(DFATAL), but returns the
appropriate fallback value (12 in this case) in opt mode. If you
need to test that a function has appropriate side-effects in opt
mode, include assertions against the side-effects. A general
pattern for this is:
EXPECT_DEBUG_DEATH({
// Side-effects here will have an effect after this statement in
// opt mode, but none in debug mode.
EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
}, "death");
t2
#ifdef __GNUC__ is too general here. It is possible to use gcc without using
libstdc++ (which is where cxxabi.h comes from).
class CartesianProductGenerator9::Iterator
Returns the elapsed time, in milliseconds.
Initializes this object with a copy of the input.
Overloads for wide C strings
comment: We print a protobuf using its ShortDebugString() when the string
doesn't exceed this many characters; otherwise we print it using
DebugString() for better readability.
label: code-design
Provides a level of indirection for the test list to allow easy
shuffling and restoring the test order. The i-th element in this
vector is the index of the i-th test in the shuffled test list.
The test failure summary.
The test failure message.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: wan@google.com (Zhanyong Wan)
Low-level types and utilities for porting Google Test to various
platforms. All macros ending with _ and symbols defined in an
internal namespace are subject to change without notice. Code
outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't
end with _ are part of Google Test's public API and can be used by
code outside Google Test.
This file is fundamental to Google Test. All other Google Test source
files are expected to #include this. Therefore, it cannot #include
any other Google Test header.
class CartesianProductHolder5
When this flag is specified, a failed assertion will throw an
exception if exceptions are enabled, or exit the program with a
non-zero code otherwise.
'index' is the index of the test in the type list 'Types'
specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
Types). Valid values for 'index' are [0, N - 1] where N is the
length of Types.
GTEST_HAS_TYPED_TEST_P
Formats a source file path and a line number as they would appear
in an error message from the compiler used to compile this code.
class ValuesInIteratorRangeGenerator
CopyArray() copies a k-dimensional native array using the elements'
operator=, where k can be any integer >= 0. When k is 0,
CopyArray() degenerates into copying a single value.
A dummy implementation of synchronization primitives (mutex, lock,
and thread-local variable). Necessary for compiling Google Test where
mutex is not supported - using Google Test in multiple threads is not
supported on such platforms.
comment: Adds a failure if the key is a reserved attribute of Google Test
testcase tags. Returns true if the property is valid.
TODO(russr): Validate attribute names are legal and human readable.
label: code-design
Sets the default_result_printer attribute to the provided listener.
The listener is also added to the listener list and previous
default_result_printer is removed from it and deleted. The listener can
also be NULL in which case it will not be added to the list. Does
nothing if the previous and the current listener objects are the same.
__GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
comment: Prints the given value to the given ostream. If the value is a
protocol message, its debug string is printed; if it's an enum or
of a type implicitly convertible to BiggestInt, it's printed as an
integer; otherwise the bytes in the value are printed. This is
what UniversalPrinter<T>::Print() does when it knows nothing about
type T and T has neither << operator nor PrintTo().
A user can override this behavior for a class type Foo by defining
a << operator in the namespace where Foo is defined.
We put this operator in namespace 'internal2' instead of 'internal'
to simplify the implementation, as much code in 'internal' needs to
use << in STL, which would conflict with our own << were it defined
in 'internal'.
Note that this operator<< takes a generic std::basic_ostream<Char,
CharTraits> type instead of the more restricted std::ostream. If
we define it to take an std::ostream instead, we'll get an
"ambiguous overloads" compiler error when trying to print a type
Foo that supports streaming to std::basic_ostream<Char,
CharTraits>, as the compiler cannot tell whether
operator<<(std::ostream&, const T&) or
operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more
specific.
label: code-design
You can implement all the usual class fixture members here.
Take over ownership of a raw pointer. This should happen as soon as
possible after the object is created.
Initializes this object with a reference of the input.
DeathTest is a class that hides much of the complexity of the
GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
returns a concrete class that depends on the prevailing death test
style, as defined by the --gtest_death_test_style and/or
--gtest_internal_run_death_test flags.
__GXX_RTTI
Returns true iff the current test has a (either fatal or
non-fatal) failure.
comment: Separate the error generating code from the code path to reduce the stack
frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
when calling EXPECT_OP in a tight loop.
label: code-design
class CartesianProductHolder4
Fired before any test activity starts.
UnitTest class invokes this method to register tests in this
test case right before running them in RUN_ALL_TESTS macro.
This method should not be called more then once on any single
instance of a ParameterizedTestCaseInfoBase derived class.
GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
Copyright 2008 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Implements thread-local storage on Windows systems.
// Thread 1
ThreadLocal<int> tl(100); // 100 is the default value for each thread.
// Thread 2
tl.set(150); // Changes the value for thread 2 only.
EXPECT_EQ(150, tl.get());
// Thread 1
EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value.
tl.set(200);
EXPECT_EQ(200, tl.get());
The template type argument T must have a public copy constructor.
In addition, the default ThreadLocal constructor requires T to have
a public default constructor.
The users of a TheadLocal instance have to make sure that all but one
threads (including the main one) using that instance have exited before
destroying it. Otherwise, the per-thread objects managed for them by the
ThreadLocal instance are not guaranteed to be destroyed on all platforms.
Google Test only uses global ThreadLocal objects. That means they
will die after main() has returned. Therefore, no per-thread
object managed by Google Test will be leaked as long as all threads
using Google Test have exited when main() returns.
Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
Sun Pro CC, IBM Visual Age, and HP aCC support.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
Expands to the name of the variable used to remember the names of
the registered tests in the given test case.
Allows a controller thread to pause execution of newly created
threads until notified. Instances of this class must be created
and destroyed in the controller thread.
This class is only for testing Google Test's own constructs. Do not
use it in user tests, either directly or indirectly.
Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
STL-style container methods.
class CartesianProductGenerator2::Iterator
comment: Tell the compiler to warn about unused return values for functions declared
with this macro. The macro should be used on function declarations
following the argument list:
Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
label: code-design
The vector of TestPartResults
A secret type that Google Test users don't know about. It has no
definition on purpose. Therefore it's impossible to create a
Secret object, which is what we want.
Constructs and returns the message for an equality assertion
(e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
The first four parameters are the expressions used in the assertion
and their values, as strings. For example, for ASSERT_EQ(foo, bar)
where foo is 5 and bar is 6, we have:
expected_expression: "foo"
actual_expression: "bar"
expected_value: "5"
actual_value: "6"
The ignoring_case parameter is true iff the assertion is a
*_STRCASEEQ*. When it's true, the string " (ignoring case)" will
be inserted into the message.
Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
this in your code.
This assumes that non-Windows OSes provide unistd.h. For OSes where this
is not the case, we need to include headers that provide the functions
mentioned above.
GTEST_HAS_RTTI
GTEST_HAS_CLONE
comment: FullMatch(str, re) returns true iff regular expression re matches
the entire str.
PartialMatch(str, re) returns true iff regular expression re
matches a substring of str (including str itself).
TODO(wan@google.com): make FullMatch() and PartialMatch() work
when str contains NUL characters.
label: code-design
Helpers for ThreadLocal.
Defines RE.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
ParameterizedTestCaseInfoBase is a generic interface
to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase
accumulates test information provided by TEST_P macro invocations
and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
and uses that information to register all resulting test instances
in RegisterTests method. The ParameterizeTestCaseRegistry class holds
a collection of pointers to the ParameterizedTestCaseInfo objects
and calls RegisterTests() on each of them when asked.
If *pstr starts with the given prefix, modifies *pstr to be right
past the prefix and returns true; otherwise leaves *pstr unchanged
and returns false. None of pstr, *pstr, and prefix can be NULL.
Called by pthread to delete thread-local data stored by
pthread_setspecific().
The helper function for {ASSERT|EXPECT}_STRNE.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
comment: Formats a file location for compiler-independent XML output.
Although this function is not platform dependent, we put it next to
FormatFileLocation in order to contrast the two functions.
label: code-design
Determines whether test results can be streamed to a socket.
comment: The friend relationship of some of these classes is cyclic.
If we don't forward declare them the compiler might confuse the classes
in friendship clauses with same named classes on the scope.
label: code-design
This specialization is used when the first argument to ASSERT_EQ()
is a null pointer literal, like NULL, false, or 0.
Destructor of TestCase.
Determines whether Google Test can use tr1/tuple. You can define
this macro to 0 to prevent Google Test from using tuple (any
feature depending on tuple with be disabled in this mode).
The maximum number of elements to print.
ID of the test fixture class
True iff this test should run
True iff this test is disabled
True if this test matches the
user-specified filter.
The factory that creates
the test object
The text used in failure messages to indicate the start of the
stack trace.
The thread holding the mutex.
Used to print an STL-style container when the user doesn't define
a PrintTo() for it.
class CartesianProductHolder7
This flag controls whether Google Test emits a detailed XML report to a file
in addition to its normal textual output.
No type parameter.
Unary predicate assertion macros.
Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
time and thus not defined there.
Given directory = "dir", relative_path = "test.xml",
returns "dir/test.xml".
On Windows, uses \ as the separator rather than /.
Sets up, executes, and tears down the test.
Returns the result of the test.
TestEventListeners lets users add listeners to track events in Google Test.
namespace gtest_internal
When a thread exits, DeleteThreadLocalValue() will be called on
the object managed for that thread.
gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
A simple Linear Congruential Generator for generating random
numbers with a uniform distribution. Unlike rand() and srand(), it
doesn't use global state (and therefore can't interfere with user
code). Unlike rand_r(), it's portable. An LCG isn't very random,
but it's good enough for our purposes.
If the type list contains only one type, you can write that type
directly without Types<...>:
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
Tears down the test fixture.
Sun Pro CC supports exceptions. However, there is no compile-time way of
detecting whether they are enabled or not. Therefore, we assume that
they are enabled unless the user tells us otherwise.
State of the definition of a type-parameterized test case.
Returns true iff the test is disabled and will be reported in the XML
report.
Releases resources associated with the key. This will *not*
delete managed objects for other threads.
Fired before the test case starts.
Returns true iff the test case failed.
The user didn't tell us not to do it, so we assume it's OK.
line
Instead of 1/0, we want to see true/false for bool values.
GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW
This flag controls whether Google Test catches all test-thrown exceptions
and logs them as failures.
Returns the test case name.
GTEST_HAS_STD_MOVE_
Gets the number of all tests.
signed/unsigned mismatch
Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
this in your code.
STL-style container typedefs.
Logs a property for the current test, test case, or for the entire
invocation of the test program when used outside of the context of a
test case. Only the last value for a given key is remembered. These
are public static so they can be called from utility functions that are
not members of the test fixture. Calls to RecordProperty made during
lifespan of the test (from the moment its constructor starts to the
moment its destructor finishes) will be output in XML as attributes of
the <testcase> element. Properties recorded from fixture's
SetUpTestCase or TearDownTestCase are logged as attributes of the
corresponding <testsuite> element. Calls to RecordProperty made in the
global context (before or after invocation of RUN_ALL_TESTS and from
SetUp/TearDown method of Environment objects registered with Google
Test) will be output as attributes of the <testsuites> element.
Sets up the test fixture.
Returns true iff test is disabled.
comment: A TestInfo object stores the following information about a test:
Test case name
Test name
Whether the test should be run
A function pointer that creates the test object when invoked
Test result
The constructor of TestInfo registers itself with the UnitTest
singleton such that the RUN_ALL_TESTS() macro knows which tests to
run.
label: test
Pushes a trace defined by SCOPED_TRACE() on to the per-thread
Google Test trace stack.
comment: Provides leak-safe Windows kernel handle ownership.
Used in death tests and in threading support.
label: code-design
The user didn't tell us, so we need to figure it out.
Gets the number of failed tests in this test case.
Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
compiler error iff T1 and T2 are different types.
Returns a pathname for a file that does not currently exist. The pathname
will be directory/base_name.extension or
directory/base_name_<number>.extension if directory/base_name.extension
already exists. The number will be incremented until a pathname is found
that does not already exist.
Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
There could be a race condition if two or more processes are calling this
function at the same time -- they could both pick the same filename.
comment: Parses 'str' for a 32-bit signed integer. If successful, writes the result
to *value and returns true; otherwise leaves *value unchanged and returns
false.
TODO(chandlerc): Find a better way to refactor flag and environment parsing
out of both gtest-port.cc and gtest.cc to avoid exporting this utility
function.
label: code-design
comment: To write value-parameterized tests, first you should define a fixture
class. It is usually derived from testing::TestWithParam<T> (see below for
another inheritance scheme that's sometimes useful in more complicated
class hierarchies), where the type of your parameter values.
TestWithParam<T> is itself derived from testing::Test. T can be any
copyable type. If it's a raw pointer, you are responsible for managing the
lifespan of the pointed values.
label: code-design
The thread can be created only after all fields except thread_
have been initialized.
GTEST_IS_THREADSAFE
Returns a copy of the FilePath with the directory part removed.
Example: FilePath("path/to/file").RemoveDirectoryName() returns
FilePath("file"). If there is no directory part ("just_a_file"), it returns
the FilePath unmodified. If there is no file part ("just_a_dir/") it
returns an empty FilePath ("").
On Windows platform, '\' is the path separator, otherwise it is '/'.
It's a NAN if the exponent bits are all ones and the fraction
bits are not entirely zeros.
Static methods
TypeParameterizedTest<Fixture, TestSel, Types>::Register()
registers a list of type-parameterized tests with Google Test. The
return value is insignificant - we just need to return something
such that we can call this function in a namespace scope.
Implementation note: The GTEST_TEMPLATE_ macro declares a template
template parameter. It's defined in gtest-type-util.h.
Acquires this mutex.
LocalTestInfo structure keeps information about a single test registered
with TEST_P macro.
comment: Defines logging utilities:
GTEST_LOG_(severity) - logs messages at the specified severity level. The
message itself is streamed into the macro.
LogToStderr() - directs all log messages to stderr.
FlushInfoLog() - flushes informational log messages.
label: code-design
Creates an ANSI string from the given wide string, allocating
memory using new. The caller is responsible for deleting the return
value using delete[]. Returns the ANSI string, or NULL if the
input is NULL.
The returned string is created using the ANSI codepage (CP_ACP) to
match the behaviour of the ANSI versions of Win32 calls and the
C runtime.
Determines the platform on which Google Test is compiled.
Implements the helper function for {ASSERT|EXPECT}_LT
These two functions are overloaded. Given an expression
Helper(x), the compiler will pick the first version if x can be
implicitly converted to type To; otherwise it will pick the
second version.
The first version returns a value of size 1, and the second
version returns a value of size 2. Therefore, by checking the
size of Helper(x), which can be done at compile time, we can tell
which version of Helper() is used, and hence whether x can be
implicitly converted to type To.
Return value used only to run this method in namespace scope.
Returns the text representation of the value parameter, or NULL if this
is not a value-parameterized test.
We use our own TR1 tuple if we aren't sure the user has an
implementation of it already. At this time, libstdc++ 4.0.0+ and
MSVC 2010 are the only mainstream standard libraries that come
with a TR1 tuple implementation. NVIDIA's CUDA NVCC compiler
pretends to be GCC by defining __GNUC__ and friends, but cannot
compile GCC's tuple implementation. MSVC 2008 (9.0) provides TR1
tuple in a 323 MB Feature Pack download, which we cannot assume the
user has. QNX's QCC compiler is a modified GCC but it doesn't
support TR1 tuple. libc++ only provides std::tuple, in C++11 mode,
and it can be used with some compilers that define __GNUC__.
Since the lock is being released the owner_ field should no longer be
considered valid. We don't protect writing to has_owner_ here, as it's
the caller's responsibility to ensure that the current thread holds the
mutex when this is called.
NOLINT
GTEST_OS_WINDOWS
Ensures that there is at least one operator<< in the global namespace.
See Message& operator<<(...) below for why.
comment: String - an abstract class holding static string utilities.
label: code-design
RemoveFileName returns the directory path with the filename removed.
Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
If the FilePath is "a_file" or "/a_file", RemoveFileName returns
FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
not have a file, like "just/a/dir/", it returns the FilePath unmodified.
On Windows platform, '\' is the path separator, otherwise it is '/'.
Enough has been printed.
The relation between an NativeArray object (see below) and the
native array it represents.
We use 2 different structs to allow non-copyable types to be used, as long
as RelationToSourceReference() is passed.
Returns the text streamed into this AssertionResult. Test assertions
use it when they fail (i.e., the predicate's outcome doesn't match the
assertion's expectation). When nothing has been streamed into the
object, returns an empty string.
Overload for wchar_t type.
Prints a wchar_t as a symbol if it is printable or as its internal
code otherwise and also as its decimal code (except for L'\0').
The L'\0' char is printed as "L'\\0'". The decimal code is printed
as signed integer when wchar_t is implemented by the compiler
as a signed type and is printed as an unsigned integer when wchar_t
is implemented as an unsigned type.
comment: We don't want to require the users to write TemplatesN<...> directly,
as that would require them to count the length. Templates<...> is much
easier to write, but generates horrible messages when there is a
compiler error, as gcc insists on printing out each template
argument, even if it has the default value (this means Templates<list>
will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
errors).
Our solution is to combine the best part of the two approaches: a
user would write Templates<T1, ..., TN>, and Google Test will translate
that to TemplatesN<T1, ..., TN> internally to make error messages
readable. The translation is done by the 'type' member of the
Templates template.
label: code-design
If the compiler is not GCC 4.0+, we assume the user is using a
spec-conforming TR1 implementation.
IWYU pragma: export // NOLINT
GTEST_USE_OWN_TR1_TUPLE
Macros for defining flags.
Prints a TestPartResult object.
test_part_result
The Mutex class can only be used for mutexes created at runtime. It
shares its API with MutexBase otherwise.
Helper function for printing a tuple. T must be instantiated with
a tuple type.
namespace posix
Utilities for char.
Depending on the platform, different string classes are available.
On Linux, in addition to ::std::string, Google also makes use of
class ::string, which has the same interface as ::std::string, but
has a different implementation.
You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
::string is available AND is a distinct type to ::std::string, or
define it to 0 to indicate otherwise.
If ::std::string and ::string are the same class on your platform
due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0.
If you do not define GTEST_HAS_GLOBAL_STRING, it is defined
heuristically.
We disallow copying UnitTest.
This macro is used for implementing macros such as
EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
death tests are not supported. Those macros must compile on such systems
iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
systems that support death tests. This allows one to write such a macro
on a system that does not support death tests and be sure that it will
compile on a death-test supporting system.
Parameters:
statement - A statement that a macro such as EXPECT_DEATH would test
for program termination. This macro has to make sure this
statement is compiled but not executed, to ensure that
EXPECT_DEATH_IF_SUPPORTED compiles with a certain
parameter iff EXPECT_DEATH compiles with it.
regex - A regex that a macro such as EXPECT_DEATH would use to test
the output of statement. This parameter has to be
compiled but not evaluated by this macro, to ensure that
this macro only accepts expressions that a macro such as
EXPECT_DEATH would accept.
terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
and a return statement for ASSERT_DEATH_IF_SUPPORTED.
This ensures that ASSERT_DEATH_IF_SUPPORTED will not
compile inside functions where ASSERT_DEATH doesn't
compile.
The branch that has an always false condition is used to ensure that
statement and regex are compiled (and thus syntactically correct) but
never executed. The unreachable code macro protects the terminator
statement from generating an 'unreachable code' warning in case
statement unconditionally returns or throws. The Message constructor at
the end allows the syntax of streaming additional messages into the
macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
Prints a value using the type inferred by the compiler. The
difference between this and UniversalTersePrint() is that for a
(const) char pointer, this prints both the pointer and the
NUL-terminated string.
Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
ASSERT_XY(), which clashes with some users' own code.
GTEST_HASH_CXXABI_H_
Generates values from a range of two comparable values. Can be used to
generate sequences of user-defined types that implement operator+() and
operator<().
This class is used in the Range() function.
t
Two overloaded helpers for checking at compile time whether an
expression is a null pointer literal (i.e. NULL or any 0-valued
compile-time integral constant). Their return values have
different sizes, so we can use sizeof() to test which version is
picked by the compiler. These helpers have no implementations, as
we only need their signatures.
Given IsNullLiteralHelper(x), the compiler will pick the first
version if x can be implicitly converted to Secret*, and pick the
second version otherwise. Since Secret is a secret and incomplete
type, the only expression a user can write that has type Secret* is
a null pointer literal. Therefore, we know that x is a null
pointer literal if and only if the first version is picked by the
compiler.
Returns the current OS stack trace as an std::string.
The maximum number of stack frames to be included is specified by
the gtest_stack_trace_depth flag. The skip_count parameter
specifies the number of top frames to be skipped, which doesn't
count against the number of frames to be included.
For example, if Foo() calls Bar(), which in turn calls
GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
comment: MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
macro to enable exceptions, so we'll do the same.
Assumes that exceptions are enabled by default.
label: code-design
A concrete DeathTestFactory implementation for normal use.
Text representation of the value parameter, or NULL if this is not a
value-parameterized test.
The convenience class for users who need to override just one or two
methods and are not concerned that a possible change to a signature of
the methods they override will not be caught during the build. For
comments about each method please see the definition of TestEventListener
above.
Holds test properties recorded during execution of SetUpTestCase and
TearDownTestCase.
GTEST_HAS_GLOBAL_STRING
This namespace MUST NOT BE NESTED IN ::testing, or the name look-up
magic needed for implementing UniversalPrinter won't work.
comment: clang defines __EXCEPTIONS iff exceptions are enabled before clang 220714,
but iff cleanups are enabled after that. In Obj-C++ files, there can be
cleanups for ObjC exceptions which also need cleanups, even if C++ exceptions
are disabled. clang has __has_feature(cxx_exceptions) which checks for C++
exceptions starting at clang r206352, but which checked for cleanups prior to
that. To reliably check for C++ exception availability with clang, check for
__EXCEPTIONS && __has_feature(cxx_exceptions).
label: code-design
_MSC_VER
Override this to define how to tear down the environment.
GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
Appends the contents of message to message_.
This template class serves as a compile-time function from size to
type. It maps a size in bytes to a primitive type with that
size. e.g.
TypeWithSize<4>::UInt
is typedef-ed to be unsigned int (unsigned integer made up of 4
bytes).
Such functionality should belong to STL, but I cannot find it
there.
Google Test uses this class in the implementation of floating-point
comparison.
For now it only handles UInt (unsigned int) as that's all Google Test
needs. Other types can be easily added in the future if need
arises.
Uses a GTestFlagSaver to save and restore all Google Test flags.
Parses a bool/Int32/string from the environment variable
corresponding to the given Google Test flag.
Constructs a FloatingPoint from a raw floating-point number.
On an Intel CPU, passing a non-normalized NAN (Not a Number)
around may change its bits, although the new value is guaranteed
to be also a NAN. Therefore, don't expect this constructor to
preserve the bits in x when x is a NAN.
Gets the (immutable) vector of TestInfos in this TestCase.
Advances iterator to point to the next element
provided by the generator. The caller is responsible
for not calling Advance() on an iterator equal to
BaseGenerator()->End().
When the compiler sees expression IsContainerTest<C>(0), if C is an
STL-style container class, the first overload of IsContainerTest
will be viable (since both C::iterator* and C::const_iterator* are
valid types and NULL can be implicitly converted to them). It will
be picked over the second overload as 'int' is a perfect match for
the type of argument 0. If C::iterator or C::const_iterator is not
a valid type, the first overload is not viable, and the second
overload will be picked. Therefore, we can determine whether C is
a container class by checking the type of IsContainerTest<C>(0).
The value of the expression is insignificant.
Note that we look for both C::iterator and C::const_iterator. The
reason is that C++ injects the name of a class as a member of the
class itself (e.g. you can refer to class iterator as either
'iterator' or 'iterator::iterator'). If we look for C::iterator
only, for example, we would mistakenly think that a class named
iterator is an STL container.
Also note that the simpler approach of overloading
IsContainerTest(typename C::const_iterator*) and
IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
comment: Result of an assertion.
Represents a failure message.
Represents a test.
Information about a test.
Result of a test part.
A collection of test cases.
label: test
GTEST_n_TYPENAMES_(T) declares a list of n typenames.
Implements the helper function for {ASSERT|EXPECT}_NE
INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
about a generator.
Gets the line in the source file where the test part took place,
or -1 if it's unknown.
6.1.3.3 Tuple helper classes.
Listener responsible for the creation of the XML output file.
class CartesianProductGenerator5
EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
death tests are supported; otherwise they just issue a warning. This is
useful when you are combining death test assertions with normal test
assertions in one test.
Overloads for other simple built-in types.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Expands to the name of the typedef for the type parameters of the
given test case.
Implementation details of GTEST_COMPILE_ASSERT_:
(In C++11, we simply use static_assert instead of the following)
- GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
elements (and thus is invalid) when the expression is false.
- The simpler definition
#define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
does not work, as gcc supports variable-length arrays whose sizes
are determined at run-time (this is gcc's extension and not part
of the C++ standard). As a result, gcc fails to reject the
following code with the simple definition:
int foo;
GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
// not a compile-time constant.
- By using the type CompileAssert<(bool(expr))>, we ensures that
expr is a compile-time constant. (Template arguments must be
determined at compile-time.)
- The outter parentheses in CompileAssert<(bool(expr))> are necessary
to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
CompileAssert<bool(expr)>
instead, these compilers will refuse to compile
GTEST_COMPILE_ASSERT_(5 > 0, some_message);
(They seem to think the ">" in "5 > 0" marks the end of the
template argument list.)
- The array size is (bool(expr) ? 1 : -1), instead of simply
((expr) ? 1 : -1).
This is to avoid running into a bug in MS VC 7.1, which
causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
Elapsed time, in milliseconds.
We used to have a second template parameter instead of Secret*. That
template parameter would deduce to 'long', making this a better match
than the first overload even without the first overload's EnableIf.
Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
non-pointer argument" (even a deduced integral argument), so the old
implementation caused warnings in user code.
The actual list of listeners.
Define this macro to 1 to omit the definition of SUCCEED(), which
is a generic name and clashes with some other libraries.
The TypeList template makes it possible to use either a single type
or a Types<...> list in TYPED_TEST_CASE() and
INSTANTIATE_TYPED_TEST_CASE_P().
Gets the number of disabled tests.
Constructs an empty Message.
Gets the singleton UnitTest object. The first time this method
is called, a UnitTest object is constructed and returned.
Consecutive calls will return the same object.
Holds a value of T. Can be deleted via its base class without the caller
knowing the type of T.
Functions deprecated by MSVC 8.0.
This overload prints a (const) wchar_t array compactly.
For static mutexes, we rely on these members being initialized to zeros
by the linker.
Gets the summary of the failure message by omitting the stack
trace in it.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: keith.ray@gmail.com (Keith Ray)
Google Test filepath utilities
This header file declares classes and functions used internally by
Google Test. They are subject to change without notice.
This file is #included in <gtest/internal/gtest-internal.h>.
Do not include this header file separately!
The empty type list.
Returns true iff the given string ends with the given suffix, ignoring
case. Any string is considered to end with an empty suffix.
Holds a value of type T.
Clears the object.
These fields are immutable properties of the test.
Test case name
Test name
Name of the parameter type, or NULL if this is not a typed or a
type-parameterized test.
Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
Don't use this in your code.
Tersely prints the first N fields of a tuple to a string vector,
one element for each field.
This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
ASSERT_EXIT*, and EXPECT_EXIT*.
The line in the source file where the test part took place, or -1
if the line number is unknown.
We must report iterators equal if they both point beyond their
respective ranges. That can happen in a variety of fashions,
so we have to consult AtEnd().
Older versions of MSVC don't have __pragma.
comment: Returns true iff this number is at most kMaxUlps ULP's away from
rhs. In particular, this function:
- returns false if either number is (or both are) NAN.
- treats really large numbers as almost equal to infinity.
- thinks +0.0 and -0.0 are 0 DLP's apart.
label: code-design
!GTEST_OS_WINDOWS
The explicit constructor call suppresses a false warning
emitted by gcc when supplied with the -Wextra option.
comment: Shuffles the tests in this test case.
label: test
Like ASSERT_EXIT, but continues on to successive tests in the
test case, if any:
Returns true iff the test part passed.
dummy
Adds a test property to the list. The property is validated and may add
a non-fatal failure if invalid (e.g., if it conflicts with reserved
key names). If a property is already recorded for the same key, the
value will be updated, rather than storing multiple values for the same
key. xml_element specifies the element for which the property is being
recorded and is used for validation.
Interface for iterating over elements provided by an implementation
of ParamGeneratorInterface<T>.
The d'tor is virtual as we need to subclass Environment.
Since T has no << operator or PrintTo() but can be implicitly
converted to BiggestInt, we print it as a BiggestInt.
Most likely T is an enum type (either named or unnamed), in which
case printing it as an integer is the desired behavior. In case
T is not an enum, printing it as an integer is the best we can do
given that it has no user-defined printer.
comment: Define this macro to 1 to omit the definition of TEST(), which
is a generic name and clashes with some other libraries.
label: code-design
Implements Boolean test assertions such as EXPECT_TRUE. expression can be
either a boolean expression or an AssertionResult. text is a textual
represenation of expression as it was passed into the EXPECT_TRUE.
comment: We don't want to require the users to write TypesN<...> directly,
as that would require them to count the length. Types<...> is much
easier to write, but generates horrible messages when there is a
compiler error, as gcc insists on printing out each template
argument, even if it has the default value (this means Types<int>
will appear as Types<int, None, None, ..., None> in the compiler
errors).
Our solution is to combine the best part of the two approaches: a
user would write Types<T1, ..., TN>, and Google Test will translate
that to TypesN<T1, ..., TN> internally to make error messages
readable. The translation is done by the 'type' member of the
Types template.
label: code-design
By default, ::testing::internal::PrintTo() is used for printing
the value.
Thanks to Koenig look-up, if T is a class and has its own
PrintTo() function defined in its namespace, that function will
be visible here. Since it is more specific than the generic ones
in ::testing::internal, it will be picked by the compiler in the
following statement - exactly what we want.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
Appends the given TestPartResult to the array.
Returns the maximum representable finite floating-point number.
Clones the iterator object. Used for implementing copy semantics
of ParamIterator<T>.
namespace testing_internal
Stores result of the assertion predicate.
Clears the results of all tests in this test case.
Fired after the test ends.
Returns true if FilePath describes something in the file-system,
either a file, directory, or whatever, and that something exists.
Makes a failed assertion result.
GTEST_USE_OWN_TR1_TUPLE
The underlying pthread mutex.
has_owner_ indicates whether the owner_ field below contains a valid thread
ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
accesses to the owner_ field should be protected by a check of this field.
An alternative might be to memset() owner_ to all zeros, but there's no
guarantee that a zero'd pthread_t is necessarily invalid or even different
from pthread_self().
class CartesianProductHolder10
The key supplied by the user.
Returns true iff the test case passed.
Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
this in your code.
ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
StrError() aren't needed on Windows CE at this time and thus not
defined there.
TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
by the universal printer to print a value of type T when neither
operator<< nor PrintTo() is defined for T, where kTypeKind is the
"kind" of T as defined by enum TypeKind.
comment: A ScopedTrace object does its job in its
c'tor and d'tor. Therefore it doesn't
need to be used otherwise.
label: code-design
GTEST_HAS_STD_WSTRING
The vector of TestProperties
BOOST_HAS_TR1_TUPLE
See the comments in Message& operator <<(const T&) above for why
we need this using statement.
comment: Returns a human-readable outcome message regarding the outcome of
the last death test.
label: code-design
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: vladl@google.com (Vlad Losev)
Macros and functions for implementing parameterized tests
in Google C++ Testing Framework (Google Test)
This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
Returns the TestInfo object for the test that's currently running,
or NULL if no test is running.
_HAS_EXCEPTIONS
Returns the optimal edits to go from 'left' to 'right'.
All edits cost the same, with replace having lower priority than
add/remove.
Simple implementation of the Wagner-Fischer algorithm.
See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
Copy constructor.
Compiling in at least C++11 mode.
Range() returns generators providing sequences of values in a range.
Synopsis:
Range(start, end)
- returns a generator producing a sequence of values {start, start+1,
start+2, ..., }.
Range(start, end, step)
- returns a generator producing a sequence of values {start, start+step,
start+step+step, ..., }.
Notes:
* The generated sequences never include end. For example, Range(1, 5)
returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
returns a generator producing {1, 3, 5, 7}.
* start and end must have the same type. That type may be any integral or
floating-point type or a user defined type satisfying these conditions:
* It must be assignable (have operator=() defined).
* It must have operator+() (operator+(int-compatible type) for
two-operand version).
* It must have operator<() defined.
Elements in the resulting sequences will also have that type.
* Condition start < end must be satisfied in order for resulting sequences
to contain any elements.
If the type list contains only one type, you can write that type
directly without Types<...>:
TYPED_TEST_CASE(FooTest, int);
Returns true iff the assertion succeeded.
NOLINT
Known limitations: we don't support passing an
std::tr1::reference_wrapper<T> to make_tuple(). And we don't
implement tie().
A handy wrapper for AddRef.
const_it
This template class represents an IEEE floating-point number
(either single-precision or double-precision, depending on the
template parameters).
The purpose of this class is to do more sophisticated number
comparison. (Due to round-off error, etc, it's very unlikely that
two floating-points will be equal exactly. Hence a naive
comparison by the == operation often doesn't work.)
Format of IEEE floating-point:
The most-significant bit being the leftmost, an IEEE
floating-point looks like
sign_bit exponent_bits fraction_bits
Here, sign_bit is a single bit that designates the sign of the
number.
For float, there are 8 exponent bits and 23 fraction bits.
For double, there are 11 exponent bits and 52 fraction bits.
More details can be found at
http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
Template parameter:
RawType: the raw floating-point type (either float or double)
Returns the i-th test property. i can range from 0 to
test_property_count() - 1. If i is not in that range, aborts the
program.
A copy constructor is required by the Standard to initialize object
references from r-values.
class TestResult
pthread_key_create() requires DeleteThreadLocalValue() to have
C-linkage. Therefore it cannot be templatized to access
ThreadLocal<T>. Hence the need for class
ThreadLocalValueHolderBase.
Complain about incorrect usage of Google Test facilities
and terminate the program since we cannot guaranty correct
test case setup and tear-down in this case.
A function level attribute to disable ThreadSanitizer instrumentation.
comment: When you need to test the private or protected members of a class,
use the FRIEND_TEST macro to declare your tests as friends of the
class. For example:
class MyClass {
private:
void MyMethod();
FRIEND_TEST(MyClassTest, MyMethod);
};
class MyClassTest : public testing::Test {
// ...
};
TEST_F(MyClassTest, MyMethod) {
// Can call MyClass::MyMethod() here.
}
label: test
On Android, <regex.h> is only available starting with Gingerbread.
By default, we assume that stream redirection is supported on all
platforms except known mobile ones.
Prints the address of the value. We use reinterpret_cast here
as static_cast doesn't compile when T is a function type.
When building against STLport with the Android NDK and with
-frtti -fno-exceptions, the build fails at link time with undefined
references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
so disable RTTI when detected.
Definitions in the 'internal' and 'internal2' name spaces are
subject to change without notice. DO NOT USE THEM IN USER CODE!
The variables defined in the type-parameterized test macros are
static as typically these macros are used in a .h file that can be
#included in multiple translation units linked together.
IsSubstring() and IsNotSubstring() are intended to be used as the
first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
themselves. They check whether needle is a substring of haystack
(NULL is considered a substring of itself only), and return an
appropriate error message when they fail.
The {needle,haystack}_expr arguments are the stringified
expressions that generated the two real arguments.
Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
Don't use this in your code.
Adapts a native array to a read-only STL-style container. Instead
of the complete STL container concept, this adaptor only implements
members useful for Google Mock's container matchers. New members
should be added as needed. To simplify the implementation, we only
support Element being a raw type (i.e. having no top-level const or
reference modifier). It's the client's responsibility to satisfy
this requirement. Element can be an array type itself (hence
multi-dimensional arrays are supported).
Non-static methods
A handy wrapper for ByRef.
Runs SetUpTestCase() for this TestCase. This wrapper is needed
for catching exceptions thrown from SetUpTestCase().
NOLINT
NOLINT
NOLINT
NOLINT
comment: This helper reduces code bloat. If we instead put its logic inside
the previous ArrayEq() function, arrays with different sizes would
lead to different copies of the template code.
label: code-design
Overload for ::std::tr1::tuple. Needed for printing function arguments,
which are packed as tuples.
Running count of death tests.
Reinterprets a bit pattern as a floating-point number.
This function is needed to test the AlmostEquals() method.
Determines whether Google Test's own tr1 tuple implementation
should be used.
class CartesianProductHolder3
class CartesianProductGenerator8
for isspace, etc
for ptrdiff_t
scripts/fuse_gtest.py depends on gtest's own header being #included
*unconditionally*. Therefore these #includes cannot be moved
inside #if GTEST_HAS_PARAM_TEST.
Copyright 2003 Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: Dan Egnor (egnor@google.com)
A "smart" pointer type with reference tracking. Every pointer to a
particular object is kept on a circular linked list. When the last pointer
to an object is destroyed or reassigned, the object is deleted.
Used properly, this deletes the object when the last reference goes away.
There are several caveats:
- Like all reference counting schemes, cycles lead to leaks.
- Each smart pointer is actually two pointers (8 bytes instead of 4).
- Every time a pointer is assigned, the entire list of pointers to that
object is traversed. This class is therefore NOT SUITABLE when there
will often be more than two or three pointers to a particular object.
- References are only tracked as long as linked_ptr<> objects are copied.
If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS
will happen (double deletion).
A good use of this class is storing object references in STL containers.
You can safely put linked_ptr<> in a vector<>.
Other uses may not be as good.
Note: If you use an incomplete type with linked_ptr<>, the class
*containing* linked_ptr<> must have a constructor and destructor (even
if they do nothing!).
Bill Gibbons suggested we use something like this.
Thread Safety:
Unlike other linked_ptr implementations, in this implementation
a linked_ptr object is thread-safe in the sense that:
- it's safe to copy linked_ptr objects concurrently,
- it's safe to copy *from* a linked_ptr and read its underlying
raw pointer (e.g. via get()) concurrently, and
- it's safe to write to two linked_ptrs that point to the same
shared object concurrently.
TODO(wan@google.com): rename this to safe_linked_ptr to avoid
confusion with normal linked_ptr.
Helper class for testing Google Test's multi-threading constructs.
To use it, write:
void ThreadFunc(int param) { /* Do things with param */ }
Notification thread_can_start;
...
// The thread_can_start parameter is optional; you can supply NULL.
ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
thread_can_start.Notify();
These classes are only for testing Google Test's own constructs. Do
not use them in user tests, either directly or indirectly.
C++11 specifies that <tuple> provides std::tuple.
Some platforms still might not have it, however.
No value parameter.
C'tor. TestPartResult does NOT have a default constructor.
Always use this constructor (with parameters) to create a
TestPartResult object.
comment: Stores the message describing the condition in case the expectation
construct is not satisfied with the predicate's outcome.
Referenced via a pointer to avoid taking too much stack frame space
with test assertions.
label: code-design
Keeps pairs of <Instantiation name, Sequence generator creation function>
received from INSTANTIATE_TEST_CASE_P macros.
Prints a value tersely: for a reference type, the referenced value
(but not the address) is printed; for a (const) char pointer, the
NUL-terminated string (but not the pointer) is printed.
We must report iterator past the end of the range when either of the
component iterators has reached the end of its range.
Swap the contents of this AssertionResult with other.
comment: A UnitTest consists of a vector of TestCases.
This is a singleton class. The only instance of UnitTest is
created when UnitTest::GetInstance() is first called. This
instance is never deleted.
UnitTest is not copyable.
This class is thread-safe as long as the methods are called
according to their specification.
label: code-design
Removes the reference from a type if it is a reference type,
otherwise leaves it unchanged. This is the same as
tr1::remove_reference, which is not widely available yet.
GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
not conform to the TR1 spec, which requires the header to be <tuple>.
We only implement == and !=, as we don't have a need for the rest yet.
Given two numbers in the sign-and-magnitude representation,
returns the distance between them as an unsigned number.
The following family of struct and struct templates are used to
represent template lists. In particular, TemplatesN<T1, T2, ...,
TN> represents a list of N templates (T1, T2, ..., and TN). Except
for Templates0, every struct in the family has two member types:
Head for the selector of the first template in the list, and Tail
for the rest of the list.
comment: Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
executed:
1. It generates a warning if there is more than one active
thread. This is because it's safe to fork() or clone() only
when there is a single thread.
2. The parent process clone()s a sub-process and runs the death
test in it; the sub-process exits with code 0 at the end of the
death test, if it hasn't exited already.
3. The parent process waits for the sub-process to terminate.
4. The parent process checks the exit code and error message of
the sub-process.
Examples:
ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number");
for (int i = 0; i < 5; i++) {
EXPECT_DEATH(server.ProcessRequest(i),
"Invalid request .* in ProcessRequest()")
<< "Failed to die on request " << i;
}
ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
bool KilledBySIGHUP(int exit_code) {
return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;
}
ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
On the regular expressions used in death tests:
On POSIX-compliant systems (*nix), we use the <regex.h> library,
which uses the POSIX extended regex syntax.
On other platforms (e.g. Windows), we only support a simple regex
syntax implemented as part of Google Test. This limited
implementation should be enough most of the time when writing
death tests; though it lacks many features you can find in PCRE
or POSIX extended regex syntax. For example, we don't support
union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and
repetition count ("x{5,7}"), among others.
Below is the syntax that we do support. We chose it to be a
subset of both PCRE and POSIX extended regex, so it's easy to
learn wherever you come from. In the following: 'A' denotes a
literal character, period (.), or a single \\ escape sequence;
'x' and 'y' denote regular expressions; 'm' and 'n' are for
natural numbers.
c matches any literal character c
\\d matches any decimal digit
\\D matches any character that's not a decimal digit
\\f matches \f
\\n matches \n
\\r matches \r
\\s matches any ASCII whitespace, including \n
\\S matches any character that's not a whitespace
\\t matches \t
\\v matches \v
\\w matches any letter, _, or decimal digit
\\W matches any character that \\w doesn't match
\\c matches any literal character c, which must be a punctuation
. matches any single character except \n
A? matches 0 or 1 occurrences of A
A* matches 0 or many occurrences of A
A+ matches 1 or many occurrences of A
^ matches the beginning of a string (not that of each line)
$ matches the end of a string (not that of each line)
xy matches x followed by y
If you accidentally use PCRE or POSIX extended regex features
not implemented by us, you will get a run-time failure. In that
case, please try to rewrite your regular expression within the
above syntax.
This implementation is *not* meant to be as highly tuned or robust
as a compiled regex library, but should perform well enough for a
death test, which already incurs significant overhead by launching
a child process.
Known caveats:
A "threadsafe" style death test obtains the path to the test
program from argv[0] and re-executes it in the sub-process. For
simplicity, the current implementation doesn't search the PATH
when launching the sub-process. This means that the user must
invoke the test program via a path that contains at least one
path separator (e.g. path/to/foo_test and
/absolute/path/to/bar_test are fine, but foo_test is not). This
is rarely a problem as people usually don't put the test binary
directory in PATH.
TODO(wan@google.com): make thread-safe death tests search the PATH.
label: code-design
Copyright 2009 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
comment: A macro to disallow operator=
This should be used in the private: declarations for a class.
label: code-design
comment: Use this annotation at the end of a struct/class definition to
prevent the compiler from optimizing away instances that are never
used. This is useful when all interesting logic happens inside the
c'tor and / or d'tor. Example:
struct Foo {
Foo() { ... }
} GTEST_ATTRIBUTE_UNUSED_;
Also use it after a variable or parameter declaration to tell the
compiler the variable/parameter does not have to be used.
label: code-design
Create a diff of the input strings in Unified diff format.
Many linked_ptr operations may change p.link_ for some linked_ptr
variable p in the same circle as this object. Therefore we need
to prevent two such operations from occurring concurrently.
Note that different types of linked_ptr objects can coexist in a
circle (e.g. linked_ptr<Base>, linked_ptr<Derived1>, and
linked_ptr<Derived2>). Therefore we must use a single mutex to
protect all linked_ptr objects. This can create serious
contention in production code, but is acceptable in a testing
framework.
Override this to define how to set up the environment.
Name of the test case.
Registers thread_local_instance as having value on the current thread.
Returns a value that can be used to identify the thread from other threads.
comment: How many ULP's (Units in the Last Place) we want to tolerate when
comparing two numbers. The larger the value, the more error we
allow. A 0 value means that two numbers must be exactly the same
to be considered equal.
The maximum error of a single floating-point operation is 0.5
units in the last place. On Intel CPU's, all floating-point
calculations are done with 80-bit precision, while double has 64
bits. Therefore, 4 should be enough for ordinary use.
See the following article for more details on ULP:
http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
label: code-design
class CartesianProductHolder2
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Expands to the namespace name that the type-parameterized tests for
the given type-parameterized test case are defined in. The exact
name of the namespace is subject to change without notice.
Dereferences the current iterator and provides (read-only) access
to the pointed value. It is the caller's responsibility not to call
Current() on an iterator equal to BaseGenerator()->End().
Used for implementing ParamGenerator<T>::operator*().
Determines whether clone(2) is supported.
Usually it will only be available on Linux, excluding
Linux on the Itanium architecture.
Also see http://linux.die.net/man/2/clone.
Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
operand to be used in a failure message. The type (but not value)
of the other operand may affect the format. This allows us to
print a char* as a raw pointer when it is compared against another
char* or void*, and print it as a C string when it is compared
against an std::string object, for example.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Implements typed tests.
GTEST_HAS_POSIX_RE
Allows the user to #include
<tr1/functional> if he chooses to.
We'll hold the text streamed to this object here.
The user didn't tell us whether ::string is available, so we need
to figure it out.
comment: Used to print a value that is not an STL-style container when the
user doesn't define PrintTo() for it.
label: code-design
<regex.h> may not be available on this platform. Use our own
simple regex implementation instead.
Constructs an RE from a string.
NOLINT
The testing::internal::posix namespace holds wrappers for common
POSIX functions. These wrappers hide the differences between
Windows/MSVC and POSIX systems. Since some compilers define these
standard functions as macros, the wrapper cannot have the same name
as the wrapped function.
GTEST_USES_SIMPLE_RE
Helper class for testing Google Test's multi-threading constructs.
comment: Replaces multiple consecutive separators with a single separator.
For example, "bar///foo" becomes "bar/foo". Does not eliminate other
redundancies that might be in a pathname involving "." or "..".
A pathname with multiple consecutive separators may occur either through
user error or as a result of some scripts or APIs that generate a pathname
with a trailing separator. On other platforms the same API or script
may NOT generate a pathname with a trailing "/". Then elsewhere that
pathname may have another "/" and pathname components added to it,
without checking for the separator already being there.
The script language and operating system may allow paths like "foo//bar"
but some of the functions in FilePath will not handle that correctly. In
particular, RemoveTrailingPathSeparator() only removes one separator, and
it is called in CreateDirectoriesRecursively() assuming that it will change
a pathname from directory syntax (trailing separator) to filename syntax.
On Windows this method also replaces the alternate path separator '/' with
the primary path separator '\\', so that for example "bar\\/\\foo" becomes
"bar\\foo".
label: code-design
GTEST_ELLIPSIS_NEEDS_POD_
Names of the flags (needed for parsing Google Test flags).
Prints the given array, omitting some elements when there are too
many.
StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
This template is declared, but intentionally undefined.
class CartesianProductHolder9
Message assignment is a semantic trick to enable assertion
streaming; see the GTEST_MESSAGE_ macro below.
We disallow copying Tests.
Gets the number of failed tests.
gcc's implementation of typeid(T).name() mangles the type name,
so we have to demangle it.
Ask the compiler to never inline a given function.
This implementation of scoped_ptr is PARTIAL - it only contains
enough stuff to satisfy Google Test's need.
GCC 4.4.6
comment: MutexBase and Mutex implement mutex on pthreads-based platforms.
label: requirement
Returns a newly created InternalRunDeathTestFlag object with fields
initialized from the GTEST_FLAG(internal_run_death_test) flag if
the flag is specified; otherwise returns NULL.
Returns true if any test in this test case should run.
Gets the user supplied value.
Gets the number of all test cases.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
The Google C++ Testing Framework (Google Test)
This header file defines internal utilities needed for implementing
death tests. They are subject to change without notice.
Returns the exponent bits of this number.
Returns true iff the test part non-fatally failed.
comment: Gets the outcome of the test part.
label: test
GTEST_HAS_PTHREAD
Returns true if this test should run, that is if the test is not
disabled (or it is disabled but the also_run_disabled_tests flag has
been specified) and its full name matches the user-specified filter.
Google Test allows the user to filter the tests by their full names.
The full name of a test Bar in test case Foo is defined as
"Foo.Bar". Only the tests that match the filter will run.
A filter is a colon-separated list of glob (not regex) patterns,
optionally followed by a '-' and a colon-separated list of
negative patterns (tests to exclude). A test is run if it
matches one of the positive patterns and does not match any of
the negative patterns.
For example, *A*:Foo.* is a filter that matches any string that
contains the character 'A' or starts with "Foo.".
test_case
Returns the standard listener responsible for the default console
output. Can be removed from the listeners list to shut down default
console output. Note that removing this object from the listener list
with Release transfers its ownership to the caller and makes this
function return NULL the next time.
Determines whether RTTI is available.
Tests that an exit code describes a normal exit with a given exit code.
Fired after environment tear-down for each iteration of tests ends.
Value-parameterized tests allow you to test your code with different
parameters without writing multiple copies of the same test.
Here is how you use value-parameterized tests:
class ParameterizedTestCaseInfo
Creates the test object, runs it, records its result, and then
deletes it.
UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
value to the given ostream. The caller must ensure that
'ostream_ptr' is not NULL, or the behavior is undefined.
We define UniversalPrinter as a class template (as opposed to a
function template), as we need to partially specialize it for
reference types, which cannot be done with function templates.
We cannot use UniversalPrint(value.first, os) here, as T1 may be
a reference type. The same for printing value.second.
This flag specifies the random number seed.
Blacklist of patch releases of older branches:
A helper class for creating scoped traces in user programs.
Fired after a failed assertion or a SUCCEED() invocation.
Returns true iff the current test has a non-fatal failure.
A handy wrapper around RemoveConst that works when the argument
T depends on template parameters.
This is used internally by all instances of linked_ptr<>. It needs to be
a non-template class because different types of linked_ptr<> can refer to
the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)).
So, it needs to be possible for different types of linked_ptr to participate
in the same circular linked list, so we need a single class type here.
DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>.
A function to convert T* into linked_ptr<T>
Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation
for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
NDEBUG mode. In this case we need the statements to be executed, the regex is
ignored, and the macro must accept a streamed message even though the message
is never printed.
Downcasts the pointer of type Base to Derived.
Derived must be a subclass of Base. The parameter MUST
point to a class of type Derived, not any subclass of it.
When RTTI is available, the function performs a runtime
check to enforce this.
T is not a function type. We just call << to print p,
relying on ADL to pick up user-defined << for their pointer
types, if any.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
comment: The 'Types' template argument below must have spaces around it
since some compilers may choke on '>>' when passing a template
instance (e.g. Types<int>)
label: code-design
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
A class that enables one to stream messages to assertion macros
Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
this in your code.
GTEST_HAS_DEATH_TEST
We have to put the 'public' section after the 'private' section,
or MSVC refuses to compile the code.
Used to define __ANDROID_API__ matching the target NDK API level.
NOLINT
Notifies all threads created with this notification to start. Must
be called from the controller thread.
A copyable object representing the result of a test part (i.e. an
assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
Don't inherit from TestPartResult as its destructor is not virtual.
Defines types for pointers to functions that set up and tear down
a test case.
__CYGWIN__
FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
value of type ToPrint that is an operand of a comparison assertion
(e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
the comparison, and is used to help determine the best way to
format the value. In particular, when the value is a C string
(char pointer) and the other operand is an STL string object, we
want to format the C string as a string, since we know it is
compared by value with the string object. If the value is a char
pointer but the other operand is not an STL string object, we don't
know whether the pointer is supposed to point to a NUL-terminated
string, and thus want to print it as a pointer to be safe.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
The Google C++ Testing Framework (Google Test)
This header file declares functions and macros used internally by
Google Test. They are subject to change without notice.
A function that returns an instance of appropriate generator type.
This class provides implementation of TeastFactoryBase interface.
It is used in TEST and TEST_F macros.
D'tor
ParamIterator assumes ownership of the impl_ pointer.
Environment variables which we programmatically clear will be set to the
empty string rather than unset (NULL). Handle that case.
Like ASSERT_DEATH, but continues on to successive tests in the
test case, if any:
Copyright 2008 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: vladl@google.com (Vlad Losev)
NULL if not a type-parameterized test
NULL if not a value-parameterized test
The helper function for {ASSERT|EXPECT}_STREQ.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Returns true iff the test failed.
comment: Increments the number of death tests encountered in this test so
far.
label: test
Integer types of known sizes.
comment: When you upcast (that is, cast a pointer from type Foo to type
SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
always succeed. When you downcast (that is, cast a pointer from
type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
how do you know the pointer is really of type SubclassOfFoo? It
could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
when you downcast, you should use this macro. In debug mode, we
use dynamic_cast<> to double-check the downcast is legal (we die
if it's not). In normal mode, we do the efficient static_cast<>
instead. Thus, it's important to test in debug mode to make sure
the cast is legal!
This is the only place in the code we should use dynamic_cast<>.
In particular, you SHOULDN'T be using dynamic_cast<> in order to
do RTTI (eg code like this:
if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
You should design the code some other way not to need this.
This relatively ugly name is intentional. It prevents clashes with
similar functions users may have (e.g., down_cast). The internal
namespace alone is not enough because the function can be found by ADL.
use like this: DownCast_<T*>(foo);
so we only accept pointers
Ensures that To is a sub-type of From *. This test is here only
for compile-time type checking, and has no overhead in an
optimized build at run-time, as it will be optimized away
completely.
label: code-design
MS C++ compiler emits warning when a conditional expression is compile time
constant. In some contexts this warning is false positive and needs to be
suppressed. Use the following two macros in such cases:
GTEST_INTENTIONAL_CONST_COND_PUSH_()
while (true) {
GTEST_INTENTIONAL_CONST_COND_POP_()
}
Gets the number of all test cases that contain at least one test
that should run.
The default value for each thread.
Returns the type ID of ::testing::Test. Always call this instead
of GetTypeId< ::testing::Test>() to get the type ID of
::testing::Test, as the latter may give the wrong result due to a
suspected linker bug when compiling Google Test as a Mac OS X
framework.
class CartesianProductGenerator4
class CartesianProductHolder6
We rely on kStaticMutex being 0 as it is to what the linker initializes
type_ in static mutexes. critical_section_ will be initialized lazily
in ThreadSafeLazyInit().
Implements thread-local storage on pthreads-based systems.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Helper classes providing Combine() with polymorphic features. They allow
casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
convertible to U.
This flags control whether Google Test prints the elapsed time for each
test.
Only use C++11 library features if the library provides them.
Macros that execute statement and check that it doesn't generate new fatal
failures in the current thread.
* {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
Examples:
EXPECT_NO_FATAL_FAILURE(Process());
ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
class CartesianProductGenerator7::Iterator
Gets the time of the test program start, in ms from the start of the
UNIX epoch.
These predicate format functions work on floating-point values, and
can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
The user told us that ::std::string isn't available.
In order to avoid having to include <windows.h>, use forward declaration
assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
This assumption is verified by
WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
Gets the vector of TestPartResults.
comment: TODO(vladl@google.com): Remove this after making sure no clients use it.
Deprecated; please use message() instead.
label: code-design
Some libraries overload << for STL containers. These
overloads are defined in the global namespace instead of ::std.
C++'s symbol lookup rule (i.e. Koenig lookup) says that these
overloads are visible in either the std namespace or the global
namespace, but not other namespaces, including the testing
namespace which Google Test's Message class is in.
To allow STL containers (and other types that has a << operator
defined in the global namespace) to be used in Google Test
assertions, testing::Message must access the custom << operator
from the global namespace. With this using declaration,
overloads of << defined in the global namespace and those
visible via Koenig lookup are both exposed in this function.
sam represents a positive number.
A helper class that aborts a death test when it's deleted.
A function level attribute to disable AddressSanitizer instrumentation.
Used in the Values() function to provide polymorphic capabilities.
Pointer to the function that tears down the test case.
Name of the parameter type, or NULL if this is not a typed or a
type-parameterized test.
This flag controls whether Google Test includes Google Test internal
stack frames in failure stack traces.
Gets the summary of the failure message.
Listener responsible for the standard result output.
Import tuple and friends into the ::testing namespace.
It is part of our interface, having them in ::testing allows us to change
their types as needed.
deprecated function
Registers and returns a global test environment. When a test
program is run, all global test environments will be set-up in
the order they were registered. After all tests in the program
have finished, all global test environments will be torn-down in
the *reverse* order they were registered.
The UnitTest object takes ownership of the given environment.
This method can only be called from the main thread.
Factory interface for death tests. May be mocked out for testing.
Gets the content of the stringstream's buffer as an std::string. Each '\0'
character in the buffer is replaced with "\\0".
comment: We need the following helper functions only for their types.
They have no implementations.
label: code-design
comment: This interface knows how to report a test part result.
label: test
Sets the elapsed time.
fd
Returns true iff test failed.
This prevents <boost/tr1/detail/config.hpp>, which defines
BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
A static mutex may be used before main() is entered. It may even
be used before the dynamic initialization stage. Therefore we
must be able to initialize a static mutex object at link time.
This means MutexBase has to be a POD and its member variables
have to be public.
The specialization for size 8.
Formats an int value as "%X".
Combine() allows the user to combine two or more sequences to produce
values of a Cartesian product of those sequences' elements.
Synopsis:
Combine(gen1, gen2, ..., genN)
- returns a generator producing sequences with elements coming from
the Cartesian product of elements from the sequences generated by
gen1, gen2, ..., genN. The sequence elements will have a type of
tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
of elements from sequences produces by gen1, gen2, ..., genN.
Combine can have up to 10 arguments. This number is currently limited
by the maximum number of elements in the tuple implementation used by Google
Test.
Example:
This will instantiate tests in test case AnimalTest each one with
the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
tuple("dog", BLACK), and tuple("dog", WHITE):
enum Color { BLACK, GRAY, WHITE };
class AnimalTest
: public testing::TestWithParam<tuple<const char*, Color> > {...};
TEST_P(AnimalTest, AnimalLooksNice) {...}
INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
Combine(Values("cat", "dog"),
Values(BLACK, WHITE)));
This will instantiate tests in FlagDependentTest with all variations of two
Boolean flags:
class FlagDependentTest
: public testing::TestWithParam<tuple<bool, bool> > {
virtual void SetUp() {
// Assigns external_flag_1 and external_flag_2 values from the tuple.
tie(external_flag_1, external_flag_2) = GetParam();
}
};
TEST_P(FlagDependentTest, TestFeature1) {
// Test your code using external_flag_1 and external_flag_2 here.
}
INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
Combine(Bool(), Bool()));
comment: Defines a test.
The first parameter is the name of the test case, and the second
parameter is the name of the test within the test case.
The convention is to end the test case name with "Test". For
example, a test case for the Foo class can be named FooTest.
Test code should appear between braces after an invocation of
this macro. Example:
TEST(FooTest, InitializesCorrectly) {
Foo foo;
EXPECT_TRUE(foo.StatusIsOK());
}
label: code-design
Then, use TYPED_TEST_P() to define as many type-parameterized tests
for this type-parameterized test case as you want.
Determines whether to support Combine(). This only makes sense when
value-parameterized tests are enabled. The implementation doesn't
work on Sun Studio since it doesn't understand templated conversion
operators.
Class iterating over elements provided by an implementation of
ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
and implements the const forward iterator concept.
For now, the XML report includes all tests matching the filter.
In the future, we may trim tests that are excluded because of
sharding.
This constructor intentionally does nothing. It relies on type_ being
statically initialized to 0 (effectively setting it to kStatic) and on
ThreadSafeLazyInit() to lazily initialize the rest of the members.
Types of SetUpTestCase() and TearDownTestCase() functions.
The data type used to store the actual floating-point number.
Macros for indicating success/failure in test code.
Generator interface definition
Wraps ParamGeneratorInterface<T> and provides general generator syntax
compatible with the STL Container concept.
This class implements copy initialization semantics and the contained
ParamGeneratorInterface<T> instance is shared among all copies
of the original object. This is possible because that instance is immutable.
comment: Advance should not be called on beyond-of-range iterators
so no component iterators must be beyond end of range, either.
label: code-design
We define two overloaded versions of Compare(). The first
version will be picked when the second argument to ASSERT_EQ() is
NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
EXPECT_EQ(false, a_bool).
Implements the helper function for {ASSERT|EXPECT}_GE
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
The Google C++ Testing Framework (Google Test)
This header file defines the Message class.
IMPORTANT NOTE: Due to limitation of the C++ language, we have to
leave some internal implementation details in this header file.
They are clearly marked by comments like this:
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Such code is NOT meant to be used by a user directly, and is subject
to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
program!
comment: The tests from the instantiation above will have these names:
* AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
* AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
* AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
* AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
in the given test case, whether their definitions come before or
AFTER the INSTANTIATE_TEST_CASE_P statement.
Please also note that generator expressions (including parameters to the
generators) are evaluated in InitGoogleTest(), after main() has started.
This allows the user on one hand, to adjust generator parameters in order
to dynamically determine a set of tests to run and on the other hand,
give the user a chance to inspect the generated tests with Google Test
reflection API before RUN_ALL_TESTS() is executed.
You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
for more examples.
In the future, we plan to publish the API for defining new parameter
generators. But for now this interface remains part of the internal
implementation and is subject to change.
A parameterized test fixture must be derived from testing::Test and from
testing::WithParamInterface<T>, where T is the type of the parameter
values. Inheriting from TestWithParam<T> satisfies that requirement because
TestWithParam<T> inherits from both Test and WithParamInterface. In more
complicated hierarchies, however, it is occasionally useful to inherit
separately from Test and WithParamInterface. For example:
label: code-design
ADD_FAILURE unconditionally adds a failure to the current test.
SUCCEED generates a success - it doesn't automatically make the
current test successful, as a test is only successful when it has
no failure.
EXPECT_* verifies that a certain condition is satisfied. If not,
it behaves like ADD_FAILURE. In particular:
EXPECT_TRUE verifies that a Boolean condition is true.
EXPECT_FALSE verifies that a Boolean condition is false.
FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
that they will also abort the current function on failure. People
usually want the fail-fast behavior of FAIL and ASSERT_*, but those
writing data-driven tests often find themselves using ADD_FAILURE
and EXPECT_* more.
As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
Consequently, it cannot select a correct instantiation of ThreadWithParam
in order to call its Run(). Introducing ThreadWithParamBase as a
non-templated base class for ThreadWithParam allows us to bypass this
problem.
namespace internal
namespace testing
40302 means version 4.3.2.
test_names
Expands to the name of the class that implements the given test.
We disallow copying TestCases.
comment: A class for indicating whether an assertion was successful. When
the assertion wasn't successful, the AssertionResult object
remembers a non-empty message that describes how it failed.
To create an instance of this class, use one of the factory functions
(AssertionSuccess() and AssertionFailure()).
This class is useful for two purposes:
1. Defining predicate functions to be used with Boolean test assertions
EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
2. Defining predicate-format functions to be
used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
For example, if you define IsEven predicate:
testing::AssertionResult IsEven(int n) {
if ((n % 2) == 0)
return testing::AssertionSuccess();
else
return testing::AssertionFailure() << n << " is odd";
}
Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
will print the message
Value of: IsEven(Fib(5))
Actual: false (5 is odd)
Expected: true
instead of a more opaque
Value of: IsEven(Fib(5))
Actual: false
Expected: true
in case IsEven is a simple Boolean predicate.
If you expect your predicate to be reused and want to support informative
messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
about half as often as positive ones in our tests), supply messages for
both success and failure cases:
testing::AssertionResult IsEven(int n) {
if ((n % 2) == 0)
return testing::AssertionSuccess() << n << " is even";
else
return testing::AssertionFailure() << n << " is odd";
}
Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
Value of: IsEven(Fib(6))
Actual: true (8 is even)
Expected: false
NB: Predicates that support negative Boolean assertions have reduced
performance in positive ones so be careful not to use them in tests
that have lots (tens of thousands) of positive Boolean assertions.
To use this class with EXPECT_PRED_FORMAT assertions such as:
// Verifies that Foo() returns an even number.
EXPECT_PRED_FORMAT1(IsEven, Foo());
you need to define:
testing::AssertionResult IsEven(const char* expr, int n) {
if ((n % 2) == 0)
return testing::AssertionSuccess();
else
return testing::AssertionFailure()
<< "Expected: " << expr << " is even\n Actual: it's " << n;
}
If Foo() returns 5, you will see the following message:
Expected: Foo() is even
Actual: it's 5
label: code-design
Makes a failed assertion result with the given failure message.
Deprecated; use AssertionFailure() << msg.
Returns the i-th test among all the tests. i can range from 0 to
total_test_count() - 1. If i is not in that range, returns NULL.
First, define a fixture class template. It should be parameterized
by a type. Remember to derive it from testing::Test.
Returns the i-th test part result among all the results. i can range
from 0 to test_property_count() - 1. If i is not in that range, aborts
the program.
gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
-std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a
value for __cplusplus, and recent versions of clang, gcc, and
probably other compilers set that too in C++11 mode.
Returns true if FilePath ends with a path separator, which indicates that
it is intended to represent a directory. Returns false otherwise.
This does NOT check that a directory (or file) actually exists.
An Environment object is capable of setting up and tearing down an
environment. You should subclass this to define your own
environment(s).
An Environment object does the set-up and tear-down in virtual
methods SetUp() and TearDown() instead of the constructor and the
destructor, as:
1. You cannot safely throw from a destructor. This is a problem
as in some cases Google Test is used where exceptions are enabled, and
we may want to implement ASSERT_* using exceptions where they are
available.
2. You cannot use ASSERT_* directly in a constructor or
destructor.
# of bits in a number.
comment: The pure interface class that all value-parameterized tests inherit from.
A value-parameterized class must inherit from both ::testing::Test and
::testing::WithParamInterface. In most cases that just means inheriting
from ::testing::TestWithParam, but more complicated test hierarchies
may need to inherit from Test and WithParamInterface at different levels.
This interface has support for accessing the test parameter value via
the GetParam() method.
Use it with one of the parameter generator defining functions, like Range(),
Values(), ValuesIn(), Bool(), and Combine().
class FooTest : public ::testing::TestWithParam<int> {
protected:
FooTest() {
// Can use GetParam() here.
}
virtual ~FooTest() {
// Can use GetParam() here.
}
virtual void SetUp() {
// Can use GetParam() here.
}
virtual void TearDown {
// Can use GetParam() here.
}
};
TEST_P(FooTest, DoesBar) {
// Can use GetParam() method here.
Foo foo;
ASSERT_TRUE(foo.DoesBar(GetParam()));
}
INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
label: code-design
Base case.
The empty template list.
sam represents a negative number.
comment: We are on Windows CE, which has no environment variables.
To prevent 'unused argument' warning.
label: code-design
Fired after environment set-up for each iteration of tests ends.
prefix
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
Returns true if pathname describes a directory in the file-system
that exists.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Generates values from the Cartesian product of values produced
by the argument generators.
A class representing the parsed contents of the
--gtest_internal_run_death_test flag, as it existed when
RUN_ALL_TESTS was called.
class CartesianProductGenerator10
Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
Releases this mutex.
When this flag is specified, tests' order is randomized on every iteration.
The user didn't tell us whether ::wstring is available, so we need
to figure it out.
Generates a fatal failure with a generic message.
The template "selector" struct TemplateSel<Tmpl> is used to
represent Tmpl, which must be a class template with one type
parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
as the type Tmpl<T>. This allows us to actually instantiate the
template "selected" by TemplateSel<Tmpl>.
This trick is necessary for simulating typedef for class templates,
which C++ doesn't support directly.
comment: Internal utilities
------------------
The following macros and utilities are for Google Test's INTERNAL
use only. Code outside Google Test MUST NOT USE THEM DIRECTLY.
Macros for basic C++ coding:
GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a
variable don't have to be used.
GTEST_DISALLOW_ASSIGN_ - disables operator=.
GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
suppressed (constant conditional).
GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
is suppressed.
C++11 feature wrappers:
testing::internal::move - portability wrapper for std::move.
Synchronization:
Mutex, MutexLock, ThreadLocal, GetThreadCount()
- synchronization primitives.
Template meta programming:
is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
IteratorTraits - partial implementation of std::iterator_traits, which
is not available in libCstd when compiled with Sun C++.
Smart pointers:
scoped_ptr - as in TR2.
Regular expressions:
RE - a simple regular expression class using the POSIX
Extended Regular Expression syntax on UNIX-like
platforms, or a reduced regular exception syntax on
other platforms, including Windows.
Logging:
GTEST_LOG_() - logs messages at the specified severity level.
LogToStderr() - directs all log messages to stderr.
FlushInfoLog() - flushes informational log messages.
Stdout and stderr capturing:
CaptureStdout() - starts capturing stdout.
GetCapturedStdout() - stops capturing stdout and returns the captured
string.
CaptureStderr() - starts capturing stderr.
GetCapturedStderr() - stops capturing stderr and returns the captured
string.
Integer types:
TypeWithSize - maps an integer to a int type.
Int32, UInt32, Int64, UInt64, TimeInMillis
- integers of known sizes.
BiggestInt - the biggest signed integer type.
Command-line utilities:
GTEST_DECLARE_*() - declares a flag.
GTEST_DEFINE_*() - defines a flag.
GetInjectableArgvs() - returns the command line as a vector of strings.
Environment variable utilities:
GetEnv() - gets the value of an environment variable.
BoolFromGTestEnv() - parses a bool environment variable.
Int32FromGTestEnv() - parses an Int32 environment variable.
StringFromGTestEnv() - parses a string environment variable.
label: code-design
Defines this to true iff Google Test can use POSIX regular expressions.
Returns the name of the parameter type, or NULL if this is not a typed
or a type-parameterized test.
Type and function utilities for implementing parameterized tests.
This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
Currently Google Test supports at most 50 arguments in Values,
and at most 10 arguments in Combine. Please contact
googletestframework@googlegroups.com if you need more.
Please note that the number of arguments to Combine is limited
by the maximum arity of the implementation of tuple which is
currently set at 10.
Determines whether the system compiler uses UTF-16 for encoding wide strings.
When this flag is set with a "host:port" string, on supported
platforms test results are streamed to the specified port on
the specified host machine.
comment: Type-parameterized tests are abstract test patterns parameterized
by a type. Compared with typed tests, type-parameterized tests
allow you to define the test pattern without knowing what the type
parameters are. The defined pattern can be instantiated with
different types any number of times, in any number of translation
units.
If you are designing an interface or concept, you can define a
suite of type-parameterized tests to verify properties that any
valid implementation of the interface/concept should have. Then,
each implementation can easily instantiate the test suite to verify
that it conforms to the requirements, without having to write
similar tests repeatedly. Here's an example:
label: test
is_pointer
comment: We put our data in a struct so that the size of the AssertHelper class can
be as small as possible. This is important because gcc is incapable of
re-using stack space even for temporary variables, so every EXPECT_EQ
reserves stack space for another AssertHelper.
label: code-design
comment: Separate the error generating code from the code path to reduce the stack
frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
when calling EXPECT_* in a tight loop.
label: code-design
GTEST_OS_LINUX
IWYU pragma: export
Forward declarations of ValuesIn(), which is implemented in
include/gtest/gtest-param-test.h.
6.1.3.5 Relational operators
Constructs a TestInfo object. The newly constructed instance assumes
ownership of the factory object.
!GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
GTEST_HAS_STREAM_REDIRECTION
Asserts that val1 is less than, or almost equal to, val2. Fails
otherwise. In particular, it fails if either val1 or val2 is NaN.
Converts a streamable value to an std::string. A NULL pointer is
converted to "(null)". When the input value is a ::string,
::std::string, ::wstring, or ::std::wstring object, each NUL
character in it is replaced with "\\0".
A handy wrapper around RemoveReference that works when the argument
T depends on template parameters.
This default version is called when kTypeKind is kOtherType.
A cached value of *iterator_. We keep it here to allow access by
pointer in the wrapping iterator's operator->().
value_ needs to be mutable to be accessed in Current().
Use of scoped_ptr helps manage cached value's lifetime,
which is bound by the lifespan of the iterator itself.
comment: Compile-time assertion for type equality.
StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
the same type. The value it returns is not interesting.
Instead of making StaticAssertTypeEq a class template, we make it a
function template that invokes a helper class template. This
prevents a user from misusing StaticAssertTypeEq<T1, T2> by
defining objects of that type.
CAVEAT:
When used inside a method of a class template,
StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
instantiated. For example, given:
template <typename T> class Foo {
public:
void Bar() { testing::StaticAssertTypeEq<int, T>(); }
};
the code:
void Test1() { Foo<bool> foo; }
will NOT generate a compiler error, as Foo<bool>::Bar() is never
actually instantiated. Instead, you need:
void Test2() { Foo<bool> foo; foo.Bar(); }
to cause a compiler error.
label: code-design
Returns true if the given test should run.
Waits for the death test to finish and returns its status.
By default, print C string as pointers to be safe, as we don't know
whether they actually point to a NUL-terminated string.
If input name has a trailing separator character, removes it and returns
the name, otherwise return the name string unmodified.
On Windows platform, uses \ as the separator, other platforms use /.
GTEST_HAS_GLOBAL_WSTRING
This version will be picked when the second argument to ASSERT_EQ() is a
pointer, e.g. ASSERT_EQ(NULL, a_pointer).
The GNU compiler emits a warning if nested "if" statements are followed by
an "else" statement and braces are not used to explicitly disambiguate the
"else" binding. This leads to problems with code like:
if (gate)
ASSERT_*(condition) << "Some message";
The "switch (0) case 0:" idiom is used to suppress this.
Now the tricky part: you need to register all test patterns before
you can instantiate them. The first argument of the macro is the
test case name; the rest are the names of the tests in this test
case.
A helper for suppressing warnings on constant condition. It just
returns 'condition'.
Use this function in main() to run all tests. It returns 0 if all
tests are successful, or 1 otherwise.
RUN_ALL_TESTS() should be invoked after the command line has been
parsed by InitGoogleTest().
This function was formerly a macro; thus, it is in the global
namespace and has an all-caps name.
__has_feature(thread_sanitizer)
Predicate-formatters for implementing the HRESULT checking macros
{ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
We pass a long instead of HRESULT to avoid causing an
include dependency for the HRESULT type.
For other compilers, we assume exceptions are disabled to be
conservative.
Overloads for ::wstring and ::std::wstring.
Returns true iff the test passed (i.e. no test part failed).
Used in the EXPECT_TRUE/FALSE(bool_expression).
T must be contextually convertible to bool.
The second parameter prevents this overload from being considered if
the argument is implicitly convertible to AssertionResult. In that case
we want AssertionResult's copy constructor to be used.
Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
this in your code.
6.1.4 Pairs.
Unimplemented.
class RangeGenerator::Iterator
Sets a new value, overriding the one supplied in the constructor.
NDEBUG for EXPECT_DEBUG_DEATH
GTEST_HAS_DEATH_TEST
GTEST_INCLUDE_GTEST_GTEST_PROD_H_
Copyright 2008, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: mheule@google.com (Markus Heule)
WINAPI_FAMILY defined but no known partition matched.
Default to desktop.
The helper function for {ASSERT|EXPECT}_EQ.
Returns repeater that broadcasts the TestEventListener events to all
subscribers.
ParamGeneratorInterface<T> is the binary interface to access generators
defined in other translation units.
The following macros are useful for writing death tests.
Overloads for C strings.
Assume no SEH.
comment: The result of a single Test. This includes a list of
TestPartResults, a list of TestProperties, a count of how many
death tests there are in the Test, and how much time it took to run
the Test.
TestResult is not copyable.
label: test
Inspired by boost/config/stdlib/libstdcpp3.hpp,
http://gcc.gnu.org/gcc-4.2/changes.html and
http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x
Represents time in milliseconds.
Assumes one of the above roles.
A copy of all command line arguments. Set by InitGoogleTest().
Finally, you are free to instantiate the pattern with the types you
want. If you put the above code in a header file, you can #include
it in multiple C++ source files and instantiate it multiple times.
To distinguish different instances of the pattern, the first
argument to the INSTANTIATE_* macro is a prefix that will be added
to the actual test case name. Remember to pick unique prefixes for
different instances.
Compares two wide C strings. Returns true iff they have the same
content.
Unlike wcscmp(), this function can handle NULL argument(s). A
NULL C string is considered different to any non-NULL C string,
including the empty string.
With this overloaded version, we allow anonymous enums to be used
in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
enums can be implicitly cast to BiggestInt.
Even though its body looks the same as the above version, we
cannot merge the two, as it will make anonymous enums unhappy.
Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
this in your code.
Determines whether to support type-driven tests.
comment: The user didn't tell us whether ::std::wstring is available, so we need
to figure it out.
TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
is available.
label: requirement
Returns the test name.
A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
Regular Expression syntax.
This flag temporary enables the disabled tests.
comment: Gets the number of disabled tests that will be reported in the XML report.
label: test
class RangeGenerator
Copyright 2008 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Typed (aka type-driven) tests repeat the same test for types in a
list. You must know which types you want to test with when writing
typed tests. Here's how you do it:
namespace tr1
namespace std
Returns true iff this test will appear in the XML report.
This flag enables using colors in terminal output. Available values are
"yes" to enable colors, "no" (disable colors), or "auto" (the default)
to let Google Test decide.
Returns the random seed used at the start of the current test run.
The following line prevents this overload from being considered if T2
is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
expands to Compare("", "", NULL, my_ptr), which requires a conversion
to match the Secret* in the other overload, which would otherwise make
this template match better.
Not meant to be instantiated.
class String
This flag controls the style of death tests. Valid values are "threadsafe",
meaning that the death test child process will re-execute the test binary
from the start, running only a single death test, or "fast",
meaning that the child process will execute the test logic immediately
after forking.
The default case.
Defines scoped_ptr.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase
classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
macros use it to locate their corresponding ParameterizedTestCaseInfo
descriptors.
comment: A macro to disallow copy constructor and operator=
This should be used in the private: declarations for a class.
label: code-design
The elapsed time, in milliseconds.
Includes the auto-generated header that implements a family of
generic predicate assertion macros.
Copyright 2006, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Protects mutable state of the property vector and of owned
properties, whose values may be updated.
class FilePath
Next, associate a list of types with the test case, which will be
repeated for each type in the list. The typedef is necessary for
the macro to parse correctly.
D'tor. Do not inherit from TestResult.
INTERNAL IMPLEMENTATION - DO NOT USE.
GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
is not satisfied.
Synopsys:
GTEST_CHECK_(boolean_condition);
or
GTEST_CHECK_(boolean_condition) << "Additional message";
This checks the condition and if the condition is not satisfied
it prints message about the condition violation, including the
condition itself, plus additional message streamed into it, if any,
and then it aborts the program. It aborts the program irrespective of
whether it is built in the debug mode or not.
comment: Often a user misspells SetUp() as Setup() and spends a long time
wondering why it is never called by Google Test. The declaration of
the following method is solely for catching such an error at
compile time:
- The return type is deliberately chosen to be not void, so it
will be a conflict if void Setup() is declared in the user's
test fixture.
- This method is private, so it will be another compiler error
if the method is called from the user's test fixture.
DO NOT OVERRIDE THIS FUNCTION.
If you see an error about overriding the following function or
about it being private, you have mis-spelled SetUp() as Setup().
label: code-design
comment: NOLINT
NOLINT
GTEST_OS_WINDOWS
label: test
Gets the number of tests that should run.
Returns true if pathname describes an absolute path.
Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict
with our own definitions. Therefore using our own tuple does not work on
those compilers.
comment: Suppresses MSVC warnings 4072 (unreachable code) for the code following
statement if it returns or throws (or doesn't return or throw in some
situations).
label: code-design
Returns true if exit_status describes a process that was terminated
by a signal, or exited normally with a nonzero exit code.
Protects copying of all linked_ptr objects.
Gets the number of all tests in this test case.
GCC 4.4.7
Turns const U&, U&, const U, and U all into U.
Gets the number of successful test cases.
GTEST_OS_WINDOWS
Determines whether Google Test can use the pthreads library.
Allows streaming basic output manipulators such as endl or flush into
this object.
comment: Google Test - The Google C++ Testing Framework
This file implements a universal value printer that can print a
value of any type T:
void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
A user can teach this function how to print a class type T by
defining either operator<<() or PrintTo() in the namespace that
defines T. More specifically, the FIRST defined function in the
following list will be used (assuming T is defined in namespace
foo):
1. foo::PrintTo(const T&, ostream*)
2. operator<<(ostream&, const T&) defined in either foo or the
global namespace.
If none of the above is defined, it will print the debug string of
the value if it is a protocol buffer, or print the raw bytes in the
value otherwise.
To aid debugging: when T is a reference type, the address of the
value is also printed; when T is a (const) char pointer, both the
pointer value and the NUL-terminated string it points to are
printed.
We also provide some convenient wrappers:
// Prints a value to a string. For a (const or not) char
// pointer, the NUL-terminated string (but not the pointer) is
// printed.
std::string ::testing::PrintToString(const T& value);
// Prints a value tersely: for a reference type, the referenced
// value (but not the address) is printed; for a (const or not) char
// pointer, the NUL-terminated string (but not the pointer) is
// printed.
void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
// Prints value using the type inferred by the compiler. The difference
// from UniversalTersePrint() is that this function prints both the
// pointer and the NUL-terminated string for a (const or not) char pointer.
void ::testing::internal::UniversalPrint(const T& value, ostream*);
// Prints the fields of a tuple tersely to a string vector, one
// element for each field. Tuple support must be enabled in
// gtest-port.h.
std::vector<string> UniversalTersePrintTupleFieldsToStrings(
const Tuple& value);
Known limitation:
The print primitives print the elements of an STL-style container
using the compiler-inferred type of *iter where iter is a
const_iterator of the container. When const_iterator is an input
iterator but not a forward iterator, this inferred type may not
match value_type, and the print output may be incorrect. In
practice, this is rarely a problem as for most containers
const_iterator is a forward iterator. We'll fix this if there's an
actual need for it. Note that this fix cannot rely on value_type
being defined as many user-defined container types don't have
value_type.
label: code-design
The c'tor pushes the given source file location and message onto
a trace stack maintained by Google Test.
Brings in definitions for functions used in the testing::internal::posix
namespace (read, write, close, chdir, isatty, stat). We do not currently
use them on Windows Mobile.
Determines whether to support stream redirection. This is used to test
output correctness and to implement death tests.
Creates a Test object.
class CartesianProductGenerator4::Iterator
comment: The abstract class that all tests inherit from.
In Google Test, a unit test program contains one or many TestCases, and
each TestCase contains one or many Tests.
When you define a test using the TEST macro, you don't need to
explicitly derive from Test - the TEST macro automatically does
this for you.
The only time you derive from Test is when defining a test fixture
to be used a TEST_F. For example:
class FooTest : public testing::Test {
protected:
void SetUp() override { ... }
void TearDown() override { ... }
...
};
TEST_F(FooTest, Bar) { ... }
TEST_F(FooTest, Baz) { ... }
Test is not copyable.
label: code-design
This flag sets up the filter to select by name using a glob pattern
the tests to run. If the filter is not given all tests are executed.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
GTEST_HAS_STREAM_REDIRECTION
Base class for ValueHolder<T>. Allows a caller to hold and delete a value
without knowing its type.
comment: Returns the TestCase object for the test that's currently running,
or NULL if no test is running.
label: test
defined(_MSC_VER) || defined(__BORLANDC__)
GTEST_HAS_EXCEPTIONS
6.1.3.2 Tuple creation functions.
Anything in namespace gtest_internal is Google Test's INTERNAL
IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
This overload prints a (const) char array compactly.
comment: FilePath - a class for file and directory pathname manipulation which
handles platform-specific conventions (like the pathname separator).
Used for helper functions for naming files in a directory for xml output.
Except for Set methods, all methods are const or static, which provides an
"immutable value object" -- useful for peace of mind.
A FilePath with a value ending in a path separator ("like/this/") represents
a directory, otherwise it is assumed to represent a file. In either case,
it may or may not represent an actual file or directory in the file system.
Names are NOT checked for syntax correctness -- no checking for illegal
characters, malformed paths, etc.
label: code-design
GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
For FullMatch().
For PartialMatch().
STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
This is the only specialization that allows VC++ 7.1 to remove const in
'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC
and thus needs to be conditionally compiled.
IWYU pragma: export // NOLINT
namespace internal
Helper function for *_STRNE on wide strings.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
TestMetaFactory creates test factories for passing into
MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
ownership of test factory pointer, same factory object cannot be passed
into that method twice. But ParameterizedTestCaseInfo is going to call
it for each Test/Parameter value combination. Thus it needs meta factory
creator class.
Passing non-POD classes through ellipsis (...) crashes the ARM
compiler and generates a warning in Sun Studio. The Nokia Symbian
and the IBM XL C/C++ compiler try to instantiate a copy constructor
for objects passed through ellipsis (...), failing for uncopyable
objects. We define this to ensure that only POD is passed through
ellipsis on these systems.
Fired after all test activities have ended.
Returns the standard listener responsible for the default XML output
controlled by the --gtest_output=xml flag. Can be removed from the
listeners list by users who want to shut down the default XML output
controlled by this flag and substitute it with custom one. Note that
removing this object from the listener list with Release transfers its
ownership to the caller and makes this function return NULL the next
time.
GCC 4.5.3
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
ParameterizedTestCaseInfo accumulates tests obtained from TEST_P
macro invocations for a particular test case and generators
obtained from INSTANTIATE_TEST_CASE_P macro invocations for that
test case. It registers tests with all values generated by all
generators when asked.
Array.
Gets the user supplied key.
The type of basic IO manipulators (endl, ends, and flush) for
narrow streams.
We need to use cached value referenced by iterator_ because *iterator_
can return a temporary object (and of type other then T), so just
having "return &*iterator_;" doesn't work.
value_ is updated here and not in Advance() because Advance()
can advance iterator_ beyond the end of the range, and we cannot
detect that fact. The client code, on the other hand, is
responsible for not calling Current() on an out-of-range iterator.
The user didn't tell us whether exceptions are enabled, so we need
to figure it out.
Next, recurses (at compile time) with the tail of the type list.
This prevents the user from using TypeWithSize<N> with incorrect
values of N.
GTEST_OS_LINUX && !defined(__ia64__)
file
Thread annotations
Returns true iff the path is "".
Returns the TestResult that holds test properties recorded during
execution of SetUpTestCase and TearDownTestCase.
Returns the current working directory, or "" if unsuccessful.
To visit static members of the fixture, add the TestFixture::
prefix.
C'tor. TestProperty does NOT have a default constructor.
Always use this constructor (with parameters) to create a
TestProperty object.
Fired before the test starts.
Create returns false if there was an error determining the
appropriate action to take for the current death test; for example,
if the gtest_death_test_style flag is set to an invalid value.
The LastMessage method will return a more detailed message in that
case. Otherwise, the DeathTest pointer pointed to by the "test"
argument is set. If the death test should be skipped, the pointer
is set to NULL; otherwise, it is set to the address of a new concrete
DeathTest object that controls the execution of the current test.
comment: An enumeration of the three reasons that a test might be aborted.
label: test
Prints the given number of bytes in the given object to the given
ostream.
Converts a wide C string to a String using the UTF-8 encoding.
NULL will be converted to "(null)". If an error occurred during
the conversion, "(failed to convert from wide string)" is
returned.
Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
complain about _snprintf.
Macros for disabling Microsoft Visual C++ warnings.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
/* code that triggers warnings C4800 and C4385 */
GTEST_DISABLE_MSC_WARNINGS_POP_()
NOLINT
Returns a pointer to the last occurence of a valid path separator in
the FilePath. On Windows, for example, both '/' and '\' are valid path
separators. Returns NULL if no path separator was found.
TuplePolicy<TupleT> must provide:
- tuple_size
size of tuple TupleT.
- get<size_t I>(const TupleT& t)
static function extracting element I of tuple TupleT.
- tuple_element<size_t I>::type
type of element I of tuple TupleT.
The usual test fixture members go here too.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Stores a parameter value and later creates tests parameterized with that
value.
The d'tor is virtual as we intend to inherit from Test.
Increments the death test count, returning the new count.
A function level attribute to disable checking for use of uninitialized
memory when built with MemorySanitizer.
dummy_ must not have a const type. Otherwise an overly eager
compiler (e.g. MSVC 7.1 & 8.0) may try to merge
TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
The compiler is required to allocate a different
TypeIdHelper<T>::dummy_ variable for each T used to instantiate
the template. Therefore, the address of dummy_ is guaranteed to
be unique.
Accessors for the implementation object.
Constructs from a native array. Copies the source.
The base case for the compile time recursion.
The name of the source file where the test part took place, or
"" if the source file is unknown.
Returns the number of threads running in the process, or 0 to indicate that
we cannot detect it.
__BORLANDC__
A unique struct template used as the default value for the
arguments of class template Templates. This allows us to simulate
variadic templates (e.g. Templates<int>, Templates<int, double>,
and etc), which C++ doesn't support directly.
We include tr1::tuple even if std::tuple is available to define printers for
them.
Returns true iff this is NAN (not a number).
This helper template allows PrintTo() for tuples and
UniversalTersePrintTupleFieldsToStrings() to be defined by
induction on the number of tuple fields. The idea is that
TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
fields in tuple t, and can be defined in terms of
TuplePrefixPrinter<N - 1>.
The inductive case.
expected (NULL)
comment: The possible outcomes of a test part (i.e. an assertion or an
explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
label: test
Helper function for *_STREQ on wide strings.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Helper for suppressing false warning from Clang on a const char*
variable declared in a conditional expression always being NULL in
the else branch.
Implements printing an array type T[N].
GTEST_HAS_PARAM_TEST
Helper template function for comparing floating-points.
Template parameter:
RawType: the raw floating-point type (either float or double)
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
GCC >= 4.6.0
comment: Due to C++ preprocessor weirdness, we need double indirection to
concatenate two tokens when one of them is __LINE__. Writing
foo ## __LINE__
will result in the token foo__LINE__, instead of foo followed by
the current line number. For more details, see
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
label: code-design
Streams a custom failure message into this object.
scripts/fuse_gtest.py depends on gtest's own header being #included
*unconditionally*. Therefore these #includes cannot be moved
inside #if GTEST_HAS_PARAM_TEST.
The maximum number a BiggestInt can represent. This definition
works no matter BiggestInt is represented in one's complement or
two's complement.
We cannot rely on numeric_limits in STL, as __int64 and long long
are not part of standard C++ and numeric_limits doesn't need to be
defined for them.
The symbol "fail" here expands to something into which a message
can be streamed.
The raw floating-point number.
The bits that represent the number.
Gets the elapsed time, in milliseconds.
comment: We use a const char* instead of an std::string, as Google Test used to be
used where std::string is not available. TODO(wan@google.com): change to
std::string.
label: code-design
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
TestMetaFactoryBase is a base class for meta-factories that create
test factories for passing into MakeAndRegisterTestInfo function.
In order to catch the mistake of putting tests that use different
test fixture classes in the same test case, we need to assign
unique IDs to fixture classes and compare them. The TypeId type is
used to hold such IDs. The user should treat TypeId as an opaque
type: the only operation allowed on TypeId values is to compare
them for equality using the == operator.
GTEST_TUPLE_NAMESPACE_
__clang__
Formats a byte as "%02X".
Fired before environment set-up for each iteration of tests starts.
If a C string is compared with an STL string object, we know it's meant
to point to a NUL-terminated string, and thus can print it as a string.
!__BORLANDC__
# of fraction bits in a number.
comment: MSVC warns about implicitly converting from double to int for
possible loss of data, so we need to temporarily disable the
warning.
label: code-design
class ValuesInIteratorRangeGenerator::Iterator
Binary predicate assertion macros.
Leave whatever circle we're part of. Returns true if we were the
last member of the circle. Once this is done, you can join() another.
Define this macro to 1 to omit the definition of FAIL(), which is a
generic name and clashes with some other libraries.
Runs the test after the test fixture has been set up.
A sub-class must implement this to define the test logic.
DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
Instead, use the TEST or TEST_F macro.
namespace edit_distance
C++11 puts its tuple into the ::std namespace rather than
::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there.
This causes undefined behavior, but supported compilers react in
the way we intend.
Succeeded.
Failed but the test can continue.
Failed and the test should be terminated.
Destroys the managed object for the current thread, if any.
comment: True iff any test in this test case should run.
label: test
Platform-indicating macros
--------------------------
Macros indicating the platform on which Google Test is being used
(a macro is defined to 1 if compiled on the given platform;
otherwise UNDEFINED -- it's never defined to 0.). Google Test
defines these macros automatically. Code outside Google Test MUST
NOT define them.
GTEST_OS_AIX - IBM AIX
GTEST_OS_CYGWIN - Cygwin
GTEST_OS_FREEBSD - FreeBSD
GTEST_OS_HPUX - HP-UX
GTEST_OS_LINUX - Linux
GTEST_OS_LINUX_ANDROID - Google Android
GTEST_OS_MAC - Mac OS X
GTEST_OS_IOS - iOS
GTEST_OS_NACL - Google Native Client (NaCl)
GTEST_OS_OPENBSD - OpenBSD
GTEST_OS_QNX - QNX
GTEST_OS_SOLARIS - Sun Solaris
GTEST_OS_SYMBIAN - Symbian
GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
GTEST_OS_WINDOWS_MINGW - MinGW
GTEST_OS_WINDOWS_MOBILE - Windows Mobile
GTEST_OS_WINDOWS_PHONE - Windows Phone
GTEST_OS_WINDOWS_RT - Windows Store App/WinRT
GTEST_OS_ZOS - z/OS
Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
most stable support. Since core members of the Google Test project
don't have access to other platforms, support for them may be less
stable. If you notice any problems on your platform, please notify
googletestframework@googlegroups.com (patches for fixing them are
even more welcome!).
It is possible that none of the GTEST_OS_* macros are defined.
Asserts that a given statement causes the program to exit, with an
integer exit status that satisfies predicate, and emitting error output
that matches regex.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
The Google C++ Testing Framework (Google Test)
This header file defines the public API for Google Test. It should be
included by any test program that uses Google Test.
IMPORTANT NOTE: Due to limitation of the C++ language, we have to
leave some internal implementation details in this header file.
They are clearly marked by comments like this:
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Such code is NOT meant to be used by a user directly, and is subject
to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
program!
Acknowledgment: Google Test borrowed the idea of automatic test
registration from Barthelemy Dagenais' (barthelemy@prologique.com)
easyUnit framework.
GTEST_ASSERT_ is the basic statement to which all of the assertions
in this file reduce. Don't use this in your code.
On some platforms, <regex.h> needs someone to define size_t, and
won't compile otherwise. We can #include it here as we already
included <stdlib.h>, which is guaranteed to define size_t through
<stddef.h>.
NOLINT
GTEST_HAS_COMBINE
Runs every test in this TestCase.
Note: we deliberately don't call this PrintTo(), as that name
conflicts with ::testing::internal::PrintTo in the body of the
function.
The mask for the fraction bits.
Gets the (mutable) vector of TestInfos in this TestCase.
Inspired by boost/config/stdlib/dinkumware.hpp
Streams a value (either a pointer or not) to this object.
GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
A workarond for the bug in VC++ 7.1 that prevents us from instantiating
UniversalPrinter with T directly.
begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
current[i]_ is the actual traversing iterator.
Having the same base generator guarantees that the other
iterator is of the same type and we can downcast.
Most value-parameterized classes can ignore the existence of
WithParamInterface, and can just inherit from ::testing::TestWithParam.
Creates an empty UnitTest.
enabler
ByRef<T>::type is T if T is a reference; otherwise it's const T&.
The helper function for {ASSERT|EXPECT}_STRCASEEQ.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
GetParam works just the same here as if you inherit from TestWithParam.
Removes const from a type if it is a const type, otherwise leaves
it unchanged. This is the same as tr1::remove_const, which is not
widely available yet.
OS detection
We cannot use std::numeric_limits<T>::max() as it clashes with the max()
macro defined by <windows.h>.
This overload is used when k >= 1.
GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
Copyright 2006, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Google C++ Testing Framework definitions useful in production code.
comment: C++ doesn't allow casting from a function pointer to any object
pointer.
IsTrue() silences warnings: "Condition is always true",
"unreachable code".
label: code-design
Returns true iff the test fatally failed.
Helper macro for defining tests.
GTEST_HAS_TR1_TUPLE
The biggest signed integer type the compiler supports.
Generates a nonfatal failure with a generic message.
At this point we are sure that the object we found is of the same
type we are looking for, so we downcast it to that type
without further checks.
Pops a trace from the per-thread Google Test trace stack.
class CartesianProductGenerator2
gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
true.
NOLINT
6.1.3.4 Element access.
GetTypeName<T>() returns a human-readable name of type T.
NB: This function is also used in Google Mock, so don't move it inside of
the typed-test-only section below.
Returns true iff the current test has the same fixture class as
the first test in the current test case.
With this overloaded version, we allow anonymous enums to be used
in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
can be implicitly cast to BiggestInt.
Invoked when a ThreadLocal instance is destroyed.
Deletes self. We deliberately pick an unusual name for this
internal method to avoid clashing with names used in user TESTs.
In theory, defining stuff in the ::std namespace is undefined
behavior. We can do this as we are playing the role of a standard
library vendor.
Initializes owner_thread_id_ and critical_section_ in static mutexes.
Returns true iff the unit test passed (i.e. all test cases passed).
Bool() allows generating tests with parameters in a set of (false, true).
Synopsis:
Bool()
- returns a generator producing sequences with elements {false, true}.
It is useful when testing code that depends on Boolean flags. Combinations
of multiple flags can be tested when several Bool()'s are combined using
Combine() function.
In the following example all tests in the test case FlagDependentTest
will be instantiated twice with parameters false and true.
class FlagDependentTest : public testing::TestWithParam<bool> {
virtual void SetUp() {
external_flag = GetParam();
}
}
INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
The user didn't tell us explicitly, so we make reasonable assumptions about
which platforms have pthreads support.
To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
to your compiler flags.
Forward-declares a static mutex.
Initializes Google Test. This must be called before calling
RUN_ALL_TESTS(). In particular, it parses a command line for the
flags that Google Test recognizes. Whenever a Google Test flag is
seen, it is removed from argv, and *argc is decremented.
No value is returned. Instead, the Google Test flag variables are
updated.
Calling the function for the second time has no user-visible effect.
<regex.h> is not available on Windows. Use our own simple regex
implementation instead.
Converts the given wide string to a narrow string using the UTF-8
encoding, and streams the result to this Message object.
The user didn't tell us whether RTTI is enabled, so we need to
figure it out.
GetTypeId<T>() returns the ID of type T. Different values will be
returned for different types. Calling the function twice with the
same type argument is guaranteed to return the same ID.
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
The Google C++ Testing Framework (Google Test)
This header file defines the public API for death tests. It is
#included by gtest.h so a user doesn't need to include this
directly.
Returns the number of the test properties.
Returns the fraction bits of this number.
C++Builder cannot use member overload resolution during template
instantiation. The simplest workaround is to use its C++0x type traits
functions (C++Builder 2009 and above only).
When printing a plain char, we always treat it as unsigned. This
way, the output won't be affected by whether the compiler thinks
char is signed or not.
Skips to the first non-space char after the first comma in 'str';
returns NULL if no comma is found in 'str'.
comment: Helpers for suppressing warnings on unreachable code or constant
condition.
label: code-design
GTEST_OS_SYMBIAN
comment: A macro for implementing the helper functions needed to implement
ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
of similar code.
For each templatized helper function, we also define an overloaded
version for BiggestInt in order to reduce code bloat and allow
anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
with gcc 4.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
label: code-design
We don't support MSVC 7.1 with exceptions disabled now. Therefore
all the compilers we care about are adequate for supporting
value-parameterized tests.
Copy constructor.
Used in EXPECT_TRUE/FALSE(assertion_result).
namespace testing
iteration
Sets up the stuff shared by all tests in this test case.
Google Test will call Foo::SetUpTestCase() before running the first
test in test case Foo. Hence a sub-class can define its own
SetUpTestCase() method to shadow the one defined in the super
class.
namespace internal2
namespace testing
This flag specifies the maximum number of stack frames to be
printed in a failure message.
Pointer to the function that sets up the test case.
Returns true if pathname describes a root directory. (Windows has one
root directory per disk drive.)
Overload for std::pair.
Same as above, but the input is represented as strings.
comment: unused
label: code-design
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
Copyright 2007, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: wan@google.com (Zhanyong Wan)
Type lists of length 1, 2, 3, and so on.
Next, declare that you will define a type-parameterized test case
(the _P suffix is for "parameterized" or "pattern", whichever you
prefer):
AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
type. This can be used as a compile-time assertion to ensure that
two types are equal.
comment: Adds a test part result to the list.
label: test
Creates directories so that path exists. Returns true if successful or if
the directories already exist; returns false if unable to create
directories for any reason. Will also return false if the FilePath does
not represent a directory (that is, it doesn't end with a path separator).
!_WIN32_WCE
Returns the working directory when the first TEST() or TEST_F()
was executed. The UnitTest object owns the string.
An array of TestPartResult objects.
Don't inherit from TestPartResultArray as its destructor is not
virtual.
Constructor.
Postfix version of operator++.
Type utilities needed for implementing typed and type-parameterized
tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
Currently we support at most 50 types in a list, and at most 50
type-parameterized tests in one type-parameterized test case.
Please contact googletestframework@googlegroups.com if you need
more.
Utilities for native arrays.
Fired after the test case ends.
ValuesIn() function allows generation of tests with parameters coming from
a container.
Synopsis:
ValuesIn(const T (&array)[N])
- returns a generator producing sequences with elements from
a C-style array.
ValuesIn(const Container& container)
- returns a generator producing sequences with elements from
an STL-style container.
ValuesIn(Iterator begin, Iterator end)
- returns a generator producing sequences with elements from
a range [begin, end) defined by a pair of STL-style iterators. These
iterators can also be plain C pointers.
Please note that ValuesIn copies the values from the containers
passed in and keeps them to generate tests in RUN_ALL_TESTS().
Examples:
This instantiates tests from test case StringTest
each with C-string values of "foo", "bar", and "baz":
const char* strings[] = {"foo", "bar", "baz"};
INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
This instantiates tests from test case StlStringTest
each with STL strings with values "a" and "b":
::std::vector< ::std::string> GetParameterStrings() {
::std::vector< ::std::string> v;
v.push_back("a");
v.push_back("b");
return v;
}
INSTANTIATE_TEST_CASE_P(CharSequence,
StlStringTest,
ValuesIn(GetParameterStrings()));
This will also instantiate tests from CharTest
each with parameter values 'a' and 'b':
::std::list<char> GetParameterChars() {
::std::list<char> list;
list.push_back('a');
list.push_back('b');
return list;
}
::std::list<char> l = GetParameterChars();
INSTANTIATE_TEST_CASE_P(CharSequence2,
CharTest,
ValuesIn(l.begin(), l.end()));
To avoid conditional compilation everywhere, we make it
gtest-port.h's responsibility to #include the header implementing
tuple.
Template lists of length 1, 2, 3, and so on.
!defined(GTEST_HAS_STD_STRING)
Returns a copy of the FilePath with the case-insensitive extension removed.
Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
FilePath("dir/file"). If a case-insensitive extension is not
found, returns a copy of the original FilePath.
The helper class for {ASSERT|EXPECT}_EQ. The template argument
lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
is a null pointer literal. The following default implementation is
for lhs_is_null_literal being false.
comment: INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Outputs a message explaining invalid registration of different
fixture class for the same test case. This may happen when
TEST_P macro is used to define two tests with the same name
but in different namespaces.
label: code-design
Determines whether to support death tests.
Google Test does not support death tests for VC 7.1 and earlier as
abort() in a VC 7.1 application compiled as GUI in debug config
pops up a dialog window that cannot be suppressed programmatically.
This flag sets how many times the tests are repeated. The default value
is 1. If the value is -1 the tests are repeating forever.
GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
Copyright 2005, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
The Google C++ Testing Framework (Google Test)
This header file declares the String class and functions used internally by
Google Test. They are subject to change without notice. They should not used
by code external to Google Test.
This header file is #included by <gtest/internal/gtest-internal.h>.
It should not be #included by other files.
comment: We cannot name this class MutexLock because the ctor declaration would
conflict with a macro named MutexLock, which is defined on some
platforms. That macro is used as a defensive measure to prevent against
inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
"MutexLock l(&mu)". Hence the typedef trick below.
label: code-design
Returns the prefix of 'str' before the first comma in it; returns
the entire string if it contains no comma.
Smart pointer members.
Prints the fields of a tuple tersely to a string vector, one
element for each field. See the comment before
UniversalTersePrint() for how we define "tersely".
Creates a new ValueHolder<T> object holding a default value passed to
this ThreadLocal<T>'s constructor and returns it. It is the caller's
responsibility not to call this when the ThreadLocal<T> instance already
has a value on the current thread.
GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
Returns true iff the test part fatally failed.
GTEST_n_TUPLE_(T) is the type of an n-tuple.
Protects mutable state in *impl_. This is mutable as some const
methods need to lock it too.
5-ary predicate assertion macros.
Fired after each iteration of tests finishes.
Returns the bits that represents this number.
GTEST_HAS_STD_TUPLE_
Sleeps for (roughly) n milliseconds. This function is only for testing
Google Test's own constructs. Don't use it in user tests, either
directly or indirectly.
Adds a reference to const on top of T as necessary. For example,
it transforms
char ==> const char&
const char ==> const char&
char& ==> const char&
const char& ==> const char&
The argument T must depend on some template parameters.
The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
const T& and const T* in a function template. These compilers
_can_ decide between class template specializations for T and T*,
so a tr1::type_traits-like is_pointer works.
Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
first version with C++ support.
Values() allows generating tests from explicitly specified list of
parameters.
Synopsis:
Values(T v1, T v2, ..., T vN)
- returns a generator producing sequences with elements v1, v2, ..., vN.
For example, this instantiates tests from test case BarTest each
with values "one", "two", and "three":
INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
This instantiates tests from test case BazTest each with values 1, 2, 3.5.
The exact type of values will depend on the type of parameter in BazTest.
INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
Currently, Values() supports from 1 to 50 parameters.
Creates a TestCase with the given name.
TestCase does NOT have a default constructor. Always use this
constructor to create a TestCase object.
Arguments:
name: name of the test case
a_type_param: the name of the test's type parameter, or NULL if
this is not a type-parameterized test.
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
We already know that 'expected' is a null pointer.
Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
Don't use this in your code.
Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
this in your code.
IsAProtocolMessage<T>::value is a compile-time bool constant that's
true iff T is type ProtocolMessage, proto2::Message, or a subclass
of those.
Makes a successful assertion result.
is a pointer
GCC 4.5.4
Clones a 0-terminated C string, allocating memory using new. The
caller is responsible for deleting the return value using
delete[]. Returns the cloned string, or NULL if the input is
NULL.
This is different from strdup() in string.h, which allocates
memory using malloc().
Assignment operator.
comment: The current parameter value. Is also available in the test fixture's
constructor. This member function is non-static, even though it only
references static data, to reduce the opportunity for incorrect uses
like writing 'WithParamInterface<bool>::GetParam()' for a test that
uses a fixture whose parameter type is int.
label: code-design
The Message class works like an ostream repeater.
Typical usage:
1. You stream a bunch of values to a Message object.
It will remember the text in a stringstream.
2. Then you stream the Message object to an ostream.
This causes the text in the Message to be streamed
to the ostream.
For example;
testing::Message foo;
foo << 1 << " != " << 2;
std::cout << foo;
will print "1 != 2".
Message is not intended to be inherited from. In particular, its
destructor is not virtual.
Note that stringstream behaves differently in gcc and in MSVC. You
can stream a NULL char pointer to it in the former, but not in the
latter (it causes an access violation if you do). The Message
class hides this difference by treating a NULL char pointer as
"(null)".
comment: Gets the number of disabled tests in this test case.
label: test
On Android, clone() is only available on ARM starting with Gingerbread.
For timespec and nanosleep, used below.
NOLINT
MSVC can be configured to define wchar_t as a typedef of unsigned
short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
type. When wchar_t is a typedef, defining an overload for const
wchar_t* would cause unsigned short* be printed as a wide string,
possibly causing invalid memory accesses.
for param_it
for gen_it
for test_it
RegisterTests
Compares two C strings, ignoring case. Returns true iff they
have the same content.
Unlike strcasecmp(), this function can handle NULL argument(s).
A NULL C string is considered different to any non-NULL C string,
including the empty string.
Returns the TestResult containing information on test failures and
properties logged outside of individual test cases.
Generates a success with a generic message.
Next, recurses (at compile time) with the tail of the test list.
The IEEE standard says that any comparison operation involving
a NAN must return false.
Then, use the TEST_P macro to define as many parameterized tests
for this fixture as you want. The _P suffix is for "parameterized"
or "pattern", whichever you prefer to think.
comment: Gets the message associated with the test part.
label: test
Returns true iff the current test has a fatal failure.
Get the number of tests in this test case that should run.
__has_feature(address_sanitizer)
Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
both the typeid and dynamic_cast features are present.
ArrayEq() compares two k-dimensional native arrays using the
elements' operator==, where k can be any integer >= 0. When k is
0, ArrayEq() degenerates into comparing a single pair of values.
Restores the test order to before the first shuffle.
4-ary predicate assertion macros.
T is a function type, so '*os << p' doesn't do what we want
(it just prints p as bool). We want to print p as a const
void*. However, we cannot cast it to const void* directly,
even using reinterpret_cast, as earlier versions of gcc
(e.g. 3.4.5) cannot compile the cast when p is a function
pointer. Casting to UInt64 first solves the problem.
_WIN32_WCE
Utilities for command line flags and environment variables.
comment: The compiler used in Symbian has a bug that prevents us from declaring the
tuple template as a friend (it complains that tuple is redefined). This
hack bypasses the bug by declaring the members that should otherwise be
private as public.
Sun Studio versions < 12 also have the above bug.
label: code-design
Windows CE has no C library. The abort() function is used in
several places in Google Test. This implementation provides a reasonable
imitation of standard behaviour.
!GTEST_LANG_CXX11
Returns true iff the test part failed.
Controls whether events will be forwarded by the repeater to the
listeners in the list.
Constructs from a native array. References the source.
Exception handling is in effect by default in HP aCC compiler. It has to
be turned of by +noeh compiler option if desired.
comment: This helper reduces code bloat. If we instead put its logic inside
the previous CopyArray() function, arrays with different sizes
would lead to different copies of the template code.
label: code-design
Distinct from C++11 language support, some environments don't provide
proper C++11 library support. Notably, it's possible to build in
C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
with no C++11 support.
libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
20110325, but maintenance releases in the 4.4 and 4.5 series followed
this date, so check for those versions by their date stamps.
https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
Determine whether the compiler supports Microsoft's Structured Exception
Handling. This is supported by several Windows compilers but generally
does not exist on any other system.
To distinguish different instances of the pattern, (yes, you
can instantiate it more then once) the first argument to the
INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
actual test case name. Remember to pick unique prefixes for different
instantiations. The tests from the instantiation above will have
these names:
* InstantiationName/FooTest.DoesBlah/0 for "meeny"
* InstantiationName/FooTest.DoesBlah/1 for "miny"
* InstantiationName/FooTest.DoesBlah/2 for "moe"
* InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
* InstantiationName/FooTest.HasBlahBlah/1 for "miny"
* InstantiationName/FooTest.HasBlahBlah/2 for "moe"
You can use these names in --gtest_filter.
This statement will instantiate all tests from FooTest again, each
with parameter values "cat" and "dog":
Returns true iff the handle is a valid handle object that can be closed.
First, register the first test in 'Test' for each type in 'Types'.
For selecting which printer to use when a given type has neither <<
nor PrintTo().
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
This file was GENERATED by command:
pump.py gtest-type-util.h.pump
DO NOT EDIT BY HAND!!!
Returns the sign bit of this number.
Tears down the stuff shared by all tests in this test case.
Google Test will call Foo::TearDownTestCase() after running the last
test in test case Foo. Hence a sub-class can define its own
TearDownTestCase() method to shadow the one defined in the super
class.
Create a new circle that includes only this instance.
EnableIf<condition>::type is void when 'Cond' is true, and
undefined when 'Cond' is false. To use SFINAE to make a function
overload only apply when a particular expression is true, add
"typename EnableIf<expression>::type* = 0" as the last parameter.
Macros for testing exceptions.
* {ASSERT|EXPECT}_THROW(statement, expected_exception):
Tests that the statement throws the expected exception.
* {ASSERT|EXPECT}_NO_THROW(statement):
Tests that the statement doesn't throw any exception.
* {ASSERT|EXPECT}_ANY_THROW(statement):
Tests that the statement throws an exception.
Used to print a non-container, non-pointer value when the user
doesn't define PrintTo() for it.
Defines synchronization primitives.
Returns the string representation of the regex.
If you see an error about overriding the following function or
about it being private, you have mis-spelled SetUp() as Setup().
Fired before environment tear-down for each iteration of tests starts.
Implements the helper function for {ASSERT|EXPECT}_GT
A helper for implementing tuple_element<k, T>. kIndexValid is true
iff k < the number of fields in tuple type T.
A key pthreads uses for looking up per-thread values.
a protobuf type
a type implicitly convertible to BiggestInt
(e.g. a named or unnamed enum type)
anything else
unit_test
Constructs a Message from a C-string.
class CartesianProductGenerator8::Iterator
Returns the TestPartResult at the given index (0-based).
Creates a new TestInfo object and registers it with Google Test;
returns the created object.
Arguments:
test_case_name: name of the test case
name: name of the test
type_param the name of the test's type parameter, or NULL if
this is not a typed or a type-parameterized test.
value_param text representation of the test's value parameter,
or NULL if this is not a type-parameterized test.
fixture_class_id: ID of the test fixture class
set_up_tc: pointer to the function that sets up the test case
tear_down_tc: pointer to the function that tears down the test case
factory: pointer to the factory that creates a test object.
The newly created TestInfo instance will assume
ownership of the factory object.
Poor man's downcast.
Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
Join an existing circle.
Formats log entry severity, provides a stream object for streaming the
log message, and terminates the message with a newline when going out of
scope.
A pointer to the base generator instance.
Used only for the purposes of iterator comparison
to make sure that two iterators belong to the same generator.
Base part of test case name for display purposes.
Used to print a pointer that is neither a char pointer nor a member
pointer, when the user doesn't define PrintTo() for it. (A member
variable pointer or member function pointer doesn't really point to
a location in the address space. Their representation is
implementation-defined. Therefore they will be printed as raw
bytes.)
Cygwin 1.7 and below doesn't support ::std::wstring.
Solaris' libc++ doesn't support it either. Android has
no support for it at least as recent as Froyo (2.2).
A handy wrapper around AddReference that works when the argument T
depends on template parameters.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
Implements printing a reference type T&.
C-string Comparisons. All tests treat NULL and any non-NULL string
as different. Two NULLs are equal.
* {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
* {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
* {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
* {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
For wide or narrow string objects, you can use the
{ASSERT|EXPECT}_??() macros.
Don't depend on the order in which the arguments are evaluated,
which is undefined.
These macros evaluate their arguments exactly once.
Since the basic IO manipulators are overloaded for both narrow
and wide streams, we have to provide this specialized definition
of operator <<, even though its body is the same as the
templatized version above. Without this definition, streaming
endl or other basic IO manipulators to Message will confuse the
compiler.
This header implements a family of generic predicate assertion
macros:
ASSERT_PRED_FORMAT1(pred_format, v1)
ASSERT_PRED_FORMAT2(pred_format, v1, v2)
...
where pred_format is a function or functor that takes n (in the
case of ASSERT_PRED_FORMATn) values and their source expression
text, and returns a testing::AssertionResult. See the definition
of ASSERT_EQ in gtest.h for an example.
If you don't care about formatting, you can use the more
restrictive version:
ASSERT_PRED1(pred, v1)
ASSERT_PRED2(pred, v1, v2)
...
where pred is an n-ary function or functor that returns bool,
and the values v1, v2, ..., must support the << operator for
streaming to std::ostream.
We also define the EXPECT_* variations.
For now we only support predicates whose arity is at most 5.
Please email googletestframework@googlegroups.com if you need
support for higher arities.
xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
class CartesianProductGenerator10::Iterator
comment: MSVC defines this macro iff RTTI is enabled.
label: code-design
Gets the number of successful tests.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
Finds the first element in the iterator range [begin, end) that
equals elem. Element may be a native array type itself.
The vector of TestInfos in their original order. It owns the
elements in the vector.
Overloads for ::string and ::std::string.
Inspired by http://clang.llvm.org/docs/LanguageExtensions.html#__has_include
unsigned int has size 4 in both gcc and MSVC.
As base/basictypes.h doesn't compile on Windows, we cannot use
uint32, uint64, and etc here.
Gets the number of failed test cases.
The helper function for {ASSERT|EXPECT}_STRCASENE.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
A copyable object representing a user specified test property which can be
output as a key/value string pair.
Don't inherit from TestProperty as its destructor is not virtual.
pthread_create() accepts a pointer to a function type with the C linkage.
According to the Standard (7.5/1), function types with different linkages
are different even if they are otherwise identical. Some compilers (for
example, SunStudio) treat them as different types. Since class methods
cannot be defined with C-linkage we need to define a free C-function to
pass into pthread_create().
test_info
NOLINT
!GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
comment: Feature-indicating macros
-------------------------
Macros indicating which Google Test features are available (a macro
is defined to 1 if the corresponding feature is supported;
otherwise UNDEFINED -- it's never defined to 0.). Google Test
defines these macros automatically. Code outside Google Test MUST
NOT define them.
These macros are public so that portable tests can be written.
Such tests typically surround code using a feature with an #if
which controls that code. For example:
#if GTEST_HAS_DEATH_TEST
EXPECT_DEATH(DoSomethingDeadly());
#endif
GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
tests)
GTEST_HAS_DEATH_TEST - death tests
GTEST_HAS_PARAM_TEST - value-parameterized tests
GTEST_HAS_TYPED_TEST - typed tests
GTEST_HAS_TYPED_TEST_P - type-parameterized tests
GTEST_IS_THREADSAFE - Google Test is thread-safe.
GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with
GTEST_HAS_POSIX_RE (see above) which users can
define themselves.
GTEST_USES_SIMPLE_RE - our own simple regex is used;
the above two are mutually exclusive.
GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
label: code-design
Provides a way for a thread to send notifications to a ThreadLocal
regardless of its parameter type.
Signals that the death test did not die as expected.
We cannot call PrintTo(*it, os) here as PrintTo() doesn't
handle *it being a native array.
Prefix version of operator++.
Test case base name for display purposes.
Runs TearDownTestCase() for this TestCase. This wrapper is
needed for catching exceptions thrown from TearDownTestCase().
Generates a nonfatal failure at the given source file location with
a generic message.
Determines whether the given iterator and other point to the same
element in the sequence generated by the generator.
Used for implementing ParamGenerator<T>::operator==().
comment: INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Use ImplicitCast_ as a safe version of static_cast for upcasting in
the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
const Foo*). When you use ImplicitCast_, the compiler checks that
the cast is safe. Such explicit ImplicitCast_s are necessary in
surprisingly many situations where C++ demands an exact type match
instead of an argument type convertable to a target type.
The syntax for using ImplicitCast_ is the same as for static_cast:
ImplicitCast_<ToType>(expr)
ImplicitCast_ would have been part of the C++ standard library,
but the proposal was submitted too late. It will probably make
its way into the language in the future.
This relatively ugly name is intentional. It prevents clashes with
similar functions users may have (e.g., implicit_cast). The internal
namespace alone is not enough because the function can be found by ADL.
label: code-design
Helper function for printing a tuple.
Tuple must be either std::tr1::tuple or std::tuple type.
GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
The value supplied by the user.
MSVC warns about adding const to a function type, so we want to
disable the warning.
Creates an empty TestResult.
This file was GENERATED by command:
pump.py gtest-tuple.h.pump
DO NOT EDIT BY HAND!!!
This is an ordinary non-parameterized test.
Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
which is #included by <tr1/tuple>, to not compile when RTTI is
disabled. _TR1_FUNCTIONAL is the header guard for
<tr1/functional>. Hence the following #define is a hack to prevent
<tr1/functional> from being included.
GTEST_HAS_CXXABI_H_ || __HP_aCC
GTEST_HAS_EXCEPTIONS
The specialization for size 4.
comment: Prints the given number of elements in an array, without printing
the curly braces.
label: code-design
class CartesianProductGenerator3::Iterator
Gets the i-th test case among all the test cases. i can range from 0 to
total_test_case_count() - 1. If i is not in that range, returns NULL.
For ::std::pair.
We lose support for NULL detection where the compiler doesn't like
passing non-POD classes through ellipsis (...).
User-supplied thread function.
User-supplied parameter to the thread function.
When non-NULL, used to block execution until the controller thread
notifies.
Streams a Message to an ostream.
Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
this in your code.
Returns the death test count.
UniversalPrintArray(begin, len, os) prints an array of 'len'
elements, starting at address 'begin'.
Functions with a different name on Windows.
0 seconds.
And n ms.
MakeFrom() is an expression whose type is From. We cannot simply
use From(), as the type From may not have a public default
constructor.
TestClass must be a subclass of WithParamInterface<T> and Test.
Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
this in your code.
The mask for the sign bit.
Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
avoid including <windows.h> in this header file. Including <windows.h> is
undesirable because it defines a lot of symbols and macros that tend to
conflict with client code. This assumption is verified by
WindowsTypesTest.HANDLEIsVoidStar.
Always returns false.
Ternary predicate assertion macros.
Mutex implements mutex on Windows platforms. It is used in conjunction
with class MutexLock:
Mutex mutex;
...
MutexLock lock(&mutex); // Acquires the mutex and releases it at the
// end of the current scope.
A static Mutex *must* be defined or declared using one of the following
macros:
GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
(A non-static Mutex is defined/declared in the usual way).
Calculate the diff between 'left' and 'right' and return it in unified diff
format.
If not null, stores in 'total_line_count' the total number of lines found
in left + right.
Gets the number of successful tests in this test case.
Note that we call GetTestTypeId() instead of GetTypeId<
::testing::Test>() here to get the type ID of testing::Test. This
is to work around a suspected linker bug when using Google Test as
a framework on Mac OS X. The bug causes GetTypeId<
::testing::Test>() to return different values depending on whether
the call is from the Google Test framework itself or from user test
code. GetTestTypeId() is guaranteed to always return the same
value, as it always calls GetTypeId<>() from the Google Test
framework.
Returns true iff the unit test failed (i.e. some test case failed
or something outside of all tests failed).
Helper function for implementing ASSERT_NEAR.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Misc public macros
------------------
GTEST_FLAG(flag_name) - references the variable corresponding to
the given Google Test flag.
comment: Defines a test that uses a test fixture.
The first parameter is the name of the test fixture class, which
also doubles as the test case name. The second parameter is the
name of the test within the test case.
A test fixture class must be declared earlier. The user should put
his test code between braces after using this macro. Example:
class FooTest : public testing::Test {
protected:
virtual void SetUp() { b_.AddElement(3); }
Foo a_;
Foo b_;
};
TEST_F(FooTest, InitializesCorrectly) {
EXPECT_TRUE(a_.StatusIsOK());
}
TEST_F(FooTest, ReturnsElementCountCorrectly) {
EXPECT_EQ(0, a_.size());
EXPECT_EQ(1, b_.size());
}
label: code-design
RTTI: debug mode only!
Adds a TestInfo to this test case. Will delete the TestInfo upon
destruction of the TestCase object.
Gets the text streamed to this object so far as an std::string.
Each '\0' character in the buffer is replaced with "\\0".
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
The following family of struct and struct templates are used to
represent type lists. In particular, TypesN<T1, T2, ..., TN>
represents a type list with N types (T1, T2, ..., and TN) in it.
Except for Types0, every struct in the family has two member types:
Head for the first type in the list, and Tail for the rest of the
list.
0
Gets the name of the TestCase.
Fired before each iteration of tests starts. There may be more than
one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
index, starting from 0.
Returns true iff the test has a non-fatal failure.
Sets the default_xml_generator attribute to the provided listener. The
listener is also added to the listener list and previous
default_xml_generator is removed from it and deleted. The listener can
also be NULL in which case it will not be added to the list. Does
nothing if the previous and the current listener objects are the same.
Adds a TestProperty to the current TestResult object when invoked from
inside a test, to current TestCase's ad_hoc_test_result_ when invoked
from SetUpTestCase or TearDownTestCase, or to the global property set
when invoked elsewhere. If the result already contains a property with
the same key, the value will be updated.
Defines some utility macros.
dummy
This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
statement generates new fatal failures. To do so it registers itself as the
current test part result reporter. Besides checking if fatal failures were
reported, it only delegates the reporting to the former result reporter.
The original result reporter is restored in the destructor.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
A convenient wrapper for adding an environment for the test
program.
You should call this before RUN_ALL_TESTS() is called, probably in
main(). If you use gtest_main, you need to call this before main()
starts for it to take effect. For example, you can define a global
variable like this:
testing::Environment* const foo_env =
testing::AddGlobalTestEnvironment(new FooEnvironment);
However, we strongly recommend you to write your own main() and
call AddGlobalTestEnvironment() there, as relying on initialization
of global variables makes the code harder to read and may cause
problems when you register multiple environments from different
translation units and the environments have dependencies among them
(remember that the compiler doesn't guarantee the order in which
global variables from different translation units are initialized).
Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
This header implements typed tests and type-parameterized tests.
Copy an existing linked_ptr<>, adding ourselves to the list of references.
Create the directory so that path exists. Returns true if successful or
if the directory already exists; returns false if unable to create the
directory for any reason, including if the parent directory does not
exist. Not named "CreateDirectory" because that's a macro on Windows.
Adds the given test name to defined_test_names_ and return true
if the test case hasn't been registered; otherwise aborts the
program.
This overloaded version can be used in Windows programs compiled in
UNICODE mode.
AddRef<T>::type is T if T is a reference; otherwise it's T&. This
is the same as tr1::add_reference<T>::type.
Converts an integer from the sign-and-magnitude representation to
the biased representation. More precisely, let N be 2 to the
power of (kBitCount - 1), an integer x is represented by the
unsigned number x + N.
For instance,
-N + 1 (the most negative number representable using
sign-and-magnitude) is represented by 1;
0 is represented by N; and
N - 1 (the biggest number representable using
sign-and-magnitude) is represented by 2N - 1.
Read http://en.wikipedia.org/wiki/Signed_number_representations
for more details on signed number representations.
Streams a non-pointer value to this object.
TEST_P macro uses AddTestPattern() to record information
about a single test in a LocalTestInfo structure.
test_case_name is the base name of the test case (without invocation
prefix). test_base_name is the name of an individual test without
parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
test case base name and DoBar is test base name.
Determines the version of gcc that is used to compile this.
These two overloads allow streaming a wide C string to a Message
using the UTF-8 encoding.
Defines the unsigned integer type that has the same size as the
floating point number.
Asserts that a given statement causes the program to exit, either by
explicitly exiting with a nonzero exit code or being killed by a
signal, and emitting error output that matches regex.
GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
This file was GENERATED by command:
pump.py gtest-param-util-generated.h.pump
DO NOT EDIT BY HAND!!!
No implementation - assignment is unsupported.
Clears the test part results.
Sets parameter value. The caller is responsible for making sure the value
remains alive and unchanged throughout the current test.
GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
Creates a UTF-16 wide string from the given ANSI string, allocating
memory using new. The caller is responsible for deleting the return
value using delete[]. Returns the wide string, or NULL if the
input is NULL.
The wide string is created using the ANSI codepage (CP_ACP) to
match the behaviour of the ANSI versions of Win32 calls and the
C runtime.
Given directory = "dir", base_name = "test", number = 0,
extension = "xml", returns "dir/test.xml". If number is greater
than zero (e.g., 12), returns "dir/test_12.xml".
On Windows platform, uses \ as the separator rather than /.
Boolean assertions. Condition can be either a Boolean expression or an
AssertionResult. For more information on how to use AssertionResult with
these macros see comments on that class.
Maps a thread to a set of ThreadLocals that have values instantiated on that
thread and notifies them when the thread exits. A ThreadLocal instance is
expected to persist until all threads it has values on have terminated.
The mask for the exponent bits.
class CartesianProductGenerator9
The upper limit for valid stack trace depths.
true iff we know that the thread function has finished.
The native thread object.
Defines the stderr capturer:
CaptureStdout - starts capturing stdout.
GetCapturedStdout - stops capturing stdout and returns the captured string.
CaptureStderr - starts capturing stderr.
GetCapturedStderr - stops capturing stderr and returns the captured string.
ImplicitlyConvertible<From, To>::value is a compile-time bool
constant that's true iff type From can be implicitly converted to
type To.
Inside a test, access the test parameter with the GetParam() method
of the TestWithParam<T> class:
comment: Prints the given value using the << operator if it has one;
otherwise prints the bytes in it. This is what
UniversalPrinter<T>::Print() does when PrintTo() is not specialized
or overloaded for type T.
A user can override this behavior for a class type Foo by defining
an overload of PrintTo() in the namespace where Foo is defined. We
give the user this option as sometimes defining a << operator for
Foo is not desirable (e.g. the coding style may prevent doing it,
or there is already a << operator but it doesn't do what the user
wants).
label: code-design
Destructs a TestInfo object. This function is not virtual, so
don't inherit from TestInfo.
UnitTest class invokes this method to register tests in this test case
test cases right before running tests in RUN_ALL_TESTS macro.
This method should not be called more then once on any single
instance of a ParameterizedTestCaseInfoBase derived class.
UnitTest has a guard to prevent from calling this method more then once.
Assuming T is defined in namespace foo, in the next statement,
the compiler will consider all of:
1. foo::operator<< (thanks to Koenig look-up),
2. ::operator<< (as the current namespace is enclosed in ::),
3. testing::internal2::operator<< (thanks to the using statement above).
The operator<< whose type matches T best will be picked.
We deliberately allow #2 to be a candidate, as sometimes it's
impossible to define #1 (e.g. when foo is ::std, defining
anything in it is undefined behavior unless you are a compiler
vendor.).
Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
Returns the floating-point number that represent positive infinity.
forcing value to bool
DefaultPrintTo() is overloaded. The type of its first two
arguments determine which version will be picked. If T is an
STL-style container, the version for container will be called; if
T is a pointer, the pointer version will be called; otherwise the
generic version will be called.
Note that we check for container types here, prior to we check
for protocol message types in our operator<<. The rationale is:
For protocol messages, we want to give people a chance to
override Google Mock's format by defining a PrintTo() or
operator<<. For STL containers, other formats can be
incompatible with Google Mock's format for the container
elements; therefore we check for container types here to ensure
that our format is used.
The second argument of DefaultPrintTo() is needed to bypass a bug
in Symbian's C++ compiler that prevents it from picking the right
overload between:
PrintTo(const T& x, ...);
PrintTo(T* x, ...);
Does nothing if the current thread holds the mutex. Otherwise, crashes
with high probability.
Gets the number of all test parts. This is the sum of the number
of successful test parts and the number of failed test parts.
A helper for implementing get<k>().
comment: On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
defined, but we don't want to use MinGW's pthreads implementation, which
has conformance problems with some versions of the POSIX standard.
label: code-design
For FullMatch();
A unique type used as the default value for the arguments of class
template Types. This allows us to simulate variadic templates
(e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
support directly.
Opaque implementation object. This field is never changed once
the object is constructed. We don't mark it as const here, as
doing so will cause a warning in the constructor of UnitTest.
Mutable state in *impl_ is protected by mutex_.
This field is mutable and needs to be reset before running the
test for the second time.
defined(GTEST_TUPLE_NAMESPACE_)
__GNUC__
Macros for declaring flags.
Static value used for accessing parameter during a test lifetime.
Typedefs the instances of the FloatingPoint template class that we
care to use.
Returns the name of the parameter type, or NULL if this is not a
type-parameterized test case.
Implements the helper function for {ASSERT|EXPECT}_LE
Gets the vector of TestProperties.
A string containing a description of the outcome of the last death test.
How many times InitGoogleTest() has been called.
The following list of PrintTo() overloads tells
UniversalPrinter<T>::Print() how to print standard types (built-in
types, strings, plain arrays, and pointers).
Adds a TestPartResult to the current TestResult object. All
Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
eventually call this to report their results. The user code
should use the assertion macros instead of calling this directly.
An all-mode assert to verify that the given POSIX-style function
call returns 0 (indicating success). Known limitation: this
doesn't expand to a balanced 'if' statement, so enclose the macro
in {} if you need to use it as the only statement in an 'if'
branch.
Returns the ParameterizedTestCaseRegistry object used to keep track of
value-parameterized tests and instantiate and register them.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
We declare (but don't implement) this to prevent the compiler
from implementing the assignment operator.
Macros that test for HRESULT failure and success, these are only useful
on Windows, and rely on Windows SDK macros and APIs to compile.
* {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
When expr unexpectedly fails or succeeds, Google Test prints the
expected result and the actual result with both a human-readable
string representation of the error, if available, as well as the
hex result code.
Assignment releases the old value and acquires the new.
Clears the results of all tests in the given test case.
Per http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx,
we assume that 0 is an invalid value for thread IDs.
In describing the results of death tests, these terms are used with
the corresponding definitions:
exit status: The integer exit information in the format specified
by wait(2)
exit code: The integer code passed to exit(3), _exit(2), or
returned from main()
__has_feature(memory_sanitizer)
To refer to typedefs in the fixture, add the "typename
TestFixture::" prefix.
GTEST_HAS_CXXABI_H_
signed/unsigned char is often used for representing binary data, so
we print pointers to it as void* to be safe.
MSVC 2005 and above support variadic macros.
Defines and statically (i.e. at link time) initializes a static mutex.
The initialization list here does not explicitly initialize each field,
instead relying on default initialization for the unspecified fields. In
particular, the owner_ field (a pthread_t) is not explicitly initialized.
This allows initialization to work whether pthread_t is a scalar or struct.
The flag -Wmissing-field-initializers must not be specified for this to work.
Overloaded PrintTo() for tuples of various arities. We support
tuples of up-to 10 fields. The following implementation works
regardless of whether tr1::tuple is implemented using the
non-standard variadic template feature or not.
class CartesianProductGenerator7
This flag brings the debugger on an assertion failure.
Returns the list of event listeners that can be used to track events
inside Google Test.
_LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
Looks up or creates and returns a structure containing information about
tests and instantiations of a particular test case.
GTEST_HAS_PARAM_TEST
class CartesianProductGenerator6
1600 is Visual Studio 2010
SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
first k fields of t1 equals the first k fields of t2.
SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
k1 != k2.
Test case id to verify identity.
Gets the number of tests to be printed in the XML report.
scripts/fuse_gtest.py depends on gtest's own header being #included
*unconditionally*. Therefore these #includes cannot be moved
inside #if GTEST_HAS_PARAM_TEST.
Copyright 2008 Google Inc.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Author: vladl@google.com (Vlad Losev)
Returns true if the death test passed; that is, the test process
exited during the test, its exit status matches a user-supplied
predicate, and its stderr output matches a user-supplied regular
expression.
The user-supplied predicate may be a macro expression rather
than a function pointer or functor, or else Wait and Passed could
be combined.
C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
can build with clang but need to use gcc4.2's libstdc++).
Returns true iff test passed.
Removes the given event listener from the list and returns it. It then
becomes the caller's responsibility to delete the listener. Returns
NULL if the listener is not found in the list.
Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
Don't use this in your code.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
For all other compilers, we assume RTTI is enabled.
class CartesianProductGenerator6::Iterator
Makes sure this header is not included before gtest.h.
GTEST_HAS_SEH
On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
use STLport's tuple implementation, which unfortunately doesn't
work as the copy of STLport distributed with Symbian is incomplete.
By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
use its own tuple implementation.
We disallow copying TestEventListeners.
Implements a subset of TR1 tuple needed by Google Test and Google Mock.
Static utility methods
This file is AUTOMATICALLY GENERATED on 10/31/2011 by command
'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
Implements a family of generic predicate assertion macros.
Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
this in your code.
case_name
# of exponent bits in a number.
Returns the number of TestPartResult objects in the array.
class CartesianProductHolder8
GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
This file was GENERATED by command:
pump.py gtest-param-test.h.pump
DO NOT EDIT BY HAND!!!
comment: If the array has more than kThreshold elements, we'll have to
omit some details by printing only the first and the last
kChunkSize elements.
TODO(wan@google.com): let the user control the threshold using a flag.
label: code-design
The index for the end() iterator. All the elements in the generated
sequence are indexed (0-based) to aid iterator comparison.
The d'tor pops the info pushed by the c'tor.
Note that the d'tor is not virtual in order to be efficient.
Don't inherit from ScopedTrace!
We disallow copying TestResult.
Constants.
Prints the first N fields of a tuple.
This templatized version is for the general case.
The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
expression is true. For example, you could use it to verify the
size of a static array:
GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
names_incorrect_size);
or to make sure a struct is smaller than a certain size:
GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
The second argument to the macro is the name of the variable. If
the expression is false, most compilers will issue a warning/error
containing the name of the variable.
Inside a test, refer to TypeParam to get the type parameter.
Since we are inside a derived class template, C++ requires use to
visit the members of FooTest via 'this'.
Evaluates to the number of elements in 'array'.
This exception is thrown by (and only by) a failed Google Test
assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
are enabled). We derive it from std::runtime_error, which is for
errors presumably detectable only at run time. Since
std::runtime_error inherits from std::exception, many testing
frameworks know how to extract and print the message inside it.
other_operand
Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
case with any set of parameters you want. Google Test defines a number
of functions for generating test parameters. They return what we call
(surprise!) parameter generators. Here is a summary of them, which
are all in the testing namespace:
Range(begin, end [, step]) - Yields values {begin, begin+step,
begin+step+step, ...}. The values do not
include end. step defaults to 1.
Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
ValuesIn(container) - Yields values from a C-style array, an STL
ValuesIn(begin,end) container, or an iterator range [begin, end).
Bool() - Yields sequence {false, true}.
Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
for the math savvy) of the values generated
by the N generators.
For more details, see comments at the definitions of these functions below
in this file.
The following statement will instantiate tests from the FooTest test case
each with parameter values "meeny", "miny", and "moe".
First, registers the first type-parameterized test in the type
list.
Returns a Boolean value indicating whether the caller is currently
executing in the context of the death test child process. Tools such as
Valgrind heap checkers may need this to modify their behavior in death
tests. IMPORTANT: This is an internal utility. Using it may break the
implementation of death tests. User code MUST NOT use it.
Forward declarations.
comment: Traps C++ exceptions escaping statement and reports them as test
failures. Note that trapping SEH exceptions is not implemented here.
label: code-design
Creates a test instance to run. The instance is both created and destroyed
within TestInfoImpl::Run()
Causes a trace (including the source file path, the current line
number, and the given message) to be included in every test failure
message generated by code in the current scope. The effect is
undone when the control leaves the current scope.
The message argument can be anything streamable to std::ostream.
In the implementation, we include the current line number as part
of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
to appear in the same block - as long as they are on different
lines.
Implements type-parameterized tests.
Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
Don't use this in your code.
Functions producing parameter generators.
Google Test uses these generators to produce parameters for value-
parameterized tests. When a parameterized test case is instantiated
with a particular generator, Google Test creates and runs tests
for each element in the sequence produced by the generator.
In the following sample, tests from test case FooTest are instantiated
each three times with parameter values 3, 5, and 8:
class FooTest : public TestWithParam<int> { ... };
TEST_P(FooTest, TestThis) {
}
TEST_P(FooTest, TestThat) {
}
INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
The interface for tracing execution of tests. The methods are organized in
the order the corresponding events are fired.
These are needed as the Nokia Symbian Compiler cannot decide between
const T& and const T* in a function template. The Nokia compiler _can_
decide between class template specializations for T and T*, so a
tr1::type_traits-like is_pointer works, and we can overload on that.
These classes and funcions are friends as they need to access private
members of UnitTest.
comment: Environment-describing macros
-----------------------------
Google Test can be used in many different environments. Macros in
this section tell Google Test what kind of environment it is being
used in, such that Google Test can provide environment-specific
features and implementations.
Google Test tries to automatically detect the properties of its
environment, so users usually don't need to worry about these
macros. However, the automatic detection is not perfect.
Sometimes it's necessary for a user to define some of the following
macros in the build script to override Google Test's decisions.
If the user doesn't define a macro in the list, Google Test will
provide a default definition. After this header is #included, all
macros in this list will be defined to either 1 or 0.
Notes to maintainers:
- Each macro here is a user-tweakable knob; do not grow the list
lightly.
- Use #if to key off these macros. Don't use #ifdef or "#if
defined(...)", which will not work as these macros are ALWAYS
defined.
GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
is/isn't available.
GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions
are enabled.
GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
is/isn't available (some systems define
::string, which is different to std::string).
GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
is/isn't available (some systems define
::wstring, which is different to std::wstring).
GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular
expressions are/aren't available.
GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
is/isn't available.
GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
enabled.
GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
std::wstring does/doesn't work (Google Test can
be used where std::wstring is unavailable).
GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
is/isn't available.
GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
compiler supports Microsoft's "Structured
Exception Handling".
GTEST_HAS_STREAM_REDIRECTION
- Define it to 1/0 to indicate whether the
platform supports I/O stream redirection using
dup() and dup2().
GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
Test's own tr1 tuple implementation should be
used. Unused when the user sets
GTEST_HAS_TR1_TUPLE to 0.
GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
is building in C++11/C++98 mode.
GTEST_LINKED_AS_SHARED_LIBRARY
- Define to 1 when compiling tests that use
Google Test as a shared library (known as
DLL on Windows).
GTEST_CREATE_SHARED_LIBRARY
- Define to 1 when compiling Google Test itself
as a shared library.
label: code-design
Formats an int value as "%02d".
"%02d" for width == 2
Blocks until the controller thread notifies. Must be called from a test
thread.
comment: MSVC "deprecates" snprintf and issues warnings wherever it is used. In
order to avoid these warnings, we need to use _snprintf or _snprintf_s on
MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
function in order to achieve that. We use macro definition here because
snprintf is a variadic function.
label: code-design
It's this header's responsibility to #include <typeinfo> when RTTI
is enabled.
GTEST_OS_WINDOWS_MOBILE
string.h is not guaranteed to provide strcpy on C++ Builder.
index
Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
able to pass strings to Win32 APIs on CE we need to convert them
to 'Unicode', UTF-16.
Compares two C strings. Returns true iff they have the same content.
Unlike strcmp(), this function can handle NULL argument(s). A
NULL C string is considered different to any non-NULL C string,
including the empty string.
Verifies that registered_tests match the test names in
defined_test_names_; returns registered_tests if successful, or
aborts the program otherwise.
it
This flag causes the Google Test to list tests. None of the tests listed
are actually run if the flag is provided.
Generates values from a pair of STL-style iterators. Used in the
ValuesIn() function. The elements are copied from the source range
since the source can be located on the stack, and the generator
is likely to persist beyond that stack frame.
Macros for testing equalities and inequalities.
* {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
* {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
* {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
* {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
* {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
* {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
When they are not, Google Test prints both the tested expressions and
their actual values. The values must be compatible built-in types,
or you will get a compiler error. By "compatible" we mean that the
values can be compared by the respective operator.
Note:
1. It is possible to make a user-defined type work with
{ASSERT|EXPECT}_??(), but that requires overloading the
comparison operators and is thus discouraged by the Google C++
Usage Guide. Therefore, you are advised to use the
{ASSERT|EXPECT}_TRUE() macro to assert that two objects are
equal.
2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
pointers (in particular, C strings). Therefore, if you use it
with two C strings, you are testing how their locations in memory
are related, not how their content is related. To compare two C
strings by content, use {ASSERT|EXPECT}_STR*().
3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
{ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
what the actual value is when it fails, and similarly for the
other comparisons.
4. Do not depend on the order in which {ASSERT|EXPECT}_??()
evaluate their arguments, which is undefined.
5. These macros evaluate their arguments exactly once.
Examples:
EXPECT_NE(5, Foo());
EXPECT_EQ(NULL, a_pointer);
ASSERT_LT(i, array_size);
ASSERT_GT(records.size(), 0) << "There is no record left.";
Information about a trace point.
Implements scoped trace.
Opaque implementation of TestInfo
Opaque implementation of UnitTest
Always returns true.
Copy constructor.
NOLINT
ParamType and GeneratorCreationFunc are private types but are required
for declarations of public methods AddTestPattern() and
AddTestCaseInstantiation().
MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
definition to fail to remove the const in 'const int[3]' and 'const
char[3][4]'. The following specialization works around the bug.
is not a pointer
GTEST_HAS_TYPED_TEST
Tests that an exit code describes an exit due to termination by a
given signal.
Streams a pointer value to this object.
This function is an overload of the previous one. When you
stream a pointer to a Message, this definition will be used as it
is more specialized. (The C++ Standard, section
[temp.func.order].) If you stream a non-pointer, then the
previous definition will be used.
The reason for this overload is that streaming a NULL pointer to
ostream is undefined behavior. Depending on the compiler, you
may get "0", "(nil)", "(null)", or an access violation. To
ensure consistent result across compilers, we always treat NULL
as "(null)".
Then, use TYPED_TEST() instead of TEST_F() to define as many typed
tests for this test case as you want.
INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
Expands to the name of the variable used to remember the names of
the defined tests in the given test case.
TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
registers *all combinations* of 'Tests' and 'Types' with Google
Test. The return value is insignificant - we just need to return
something such that we can call this function in a namespace scope.
Adds reference to a type if it is not a reference type,
otherwise leaves it unchanged. This is the same as
tr1::add_reference, which is not widely available yet.
Appends the user-supplied message to the Google-Test-generated message.
With the following statement, during unqualified name lookup,
testing::internal2::operator<< appears as if it was declared in
the nearest enclosing namespace that contains both
::testing_internal and ::testing::internal2, i.e. the global
namespace. For more details, refer to the C++ Standard section
7.3.4-1 [namespace.udir]. This allows us to fall back onto
testing::internal2::operator<< in case T doesn't come with a <<
operator.
We cannot write 'using ::testing::internal2::operator<<;', which
gcc 3.3 fails to compile due to a compiler bug.
NOLINT
Overloads for various char types.
Overload for C arrays. Multi-dimensional arrays are printed
properly.
class CartesianProductGenerator5::Iterator
isspace(int ch) and friends accept an unsigned char or EOF. char
may be signed, depending on the compiler (or compiler flags).
Therefore we need to cast a char to unsigned char before calling
isspace(), etc.
You can inherit all the usual members for a non-parameterized test
fixture here.
An enumeration of possible roles that may be taken when a death
test is encountered. EXECUTE means that the death test logic should
be executed immediately. OVERSEE means that the program should prepare
the appropriate environment for a child process to execute the death
test, then wait for it to complete.
Gets the name of the source file where the test part took place, or
NULL if it's unknown.
t1
Macros for comparing floating-point numbers.
* {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
Tests that two float values are almost equal.
* {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
Tests that two double values are almost equal.
* {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
Tests that v1 and v2 are within the given distance to each other.
Google Test uses ULP-based comparison to automatically pick a default
error bound that is appropriate for the operands. See the
FloatingPoint template class in gtest-internal.h if you are
interested in the implementation details.
Macro for referencing flags.
comment: Even though we don't use this macro any longer, we keep it in case
some clients still depend on it.
label: code-design
Runs all tests in this UnitTest object and prints the result.
Returns 0 if successful, or 1 otherwise.
This method can only be called from the main thread.
INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
DestroyDB(db_path_, Options());
check with the default rocksdb options and expect failure
override the following options as db_bench will not take these
options from the options file
namespace
#ifdef GFLAGS
namespace rocksdb
normal run with universal compaction mode
total time for this script to test db_stress
normal run
use large ops per thread since we will kill it anyway
run with kill_random_test, with three modes.
Mode 0 covers all kill points. Mode 1 covers less kill points but
increases change of triggering them. Mode 2 covers even less
frequent kill points and further increases triggering change.
comment: normal run with FIFO compaction mode
ops_per_thread is divided by 5 because FIFO compaction
style is quite a bit slower on reads with lot of files
label: code-design
params overwrite priority:
for default:
default_params < blackbox|whitebox_default_params < args
for simple:
simple_default_params < blackbox|whitebox_simple_default_params < args
we need to clean up after ourselves -- only do this on test success
time for one db_stress instance to run
comment: TODO: May need to adjust random odds if kill_random_test
is too small.
label: test
This script runs and kills db_stress multiple times. It checks consistency
in case of unsafe crashes in RocksDB.
we need to clean up after ourselves -- only do this on test
success
time to stabilize before the next run
since we will be killing anyway, use large value for ops_per_thread
time to stabilize after a kill
we expect negative retncode if kill option was given
First half of the duration, keep doing kill test. For the next half,
try different modes.
This python script runs db_stress multiple times. Some runs with
kill_random_test that causes rocksdb to crash at various points in code.
! /usr/bin/env python
we expect zero retncode if no kill option
Run kill mode 0, 1 and 2 by turn.
comment: Suppress false positive clang static anaylzer warnings.
label: code-design
ROCKSDB_LITE
__clang_analyzer__
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
map input to expected outputs.
odd number of "hex" half bytes doesn't make sense
ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test on valid dbPath.
It is weird that GET and SCAN raise exception for
non-existent key, while delete does not
non-existing column family.
Dump only a portion of the key range
No param called he
Delete the file
Load into an existing db, create_if_missing is not specified
comment: Dump command fails because of typo in params
label: documentation
Running it with the copy we just created should pass.
db not specified
Pattern to expect from SST dump.
Pattern to expect from WAL dump.
max_keys is not applicable for put
Pattern to expect from manifest_dump.
Test with the default manifest file in dbPath.
comment: These tests need to be improved; for example with asserts about
whether compaction or level reduction actually took place.
label: code-design
Test with multiple manifest files in dbPath.
No results => FAIL
Dump with count_only
DB should have atleast one value for scan to work
Test on empty path.
Dump and load with WAL disabled
comment: TODO(dilip): Not sure what should be passed to WAL.Currently corrupted.
label: code-design
Just some paranoia
hex has invalid boolean value
Dump and load with lots of extra params specified
fails because timstamp's length is greater than value's
Make sure that using the dump with --path will result in identical
output as just using manifest_dump.
Given non-default column family to single CF DB.
Dump upto max_keys rows
Dump and load in hex
Modify the file
Dump and load without any additional params specified
Delete
comment: Clean up test database
label: code-design
Dump
Get and Put
WriteBatch
!ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
use `which time` to avoid using bash's internal time command
# run the db_bench
time
$1 --- name of the benchmark
$2 --- the filename of the output log of db_bench
# make sure no db_bench is running
The following statement is necessary make sure "eval $ps_cmd" will success.
Otherwise, if we simply check whether "$(eval $ps_cmd | grep db_bench)" is
successful or not, then it will always be false since grep will return
non-zero status when there's no matching output.
==============================================================================
perform the actual command to check whether db_bench is running
Parse the output of the time command
this will terminate all currently-running db_bench
key range
Obtain micros / op
checkpoint cannot build in directory already exists
Obtain percentile information
$1 --- benchmark name
$2 --- number of operations. Default: $NUM_KEYS
$3 --- number of threads. Default $NUM_THREADS
$4 --- use_existing_db. Default: 1
$5 --- update_report. Default: 1
###########################################################################
!/usr/bin/env bash
The RocksDB regression test script.
REQUIREMENT: must be able to run make db_bench in the current directory
This script will do the following things in order:
1. check out the specified rocksdb commit.
2. build db_bench using the specified commit
3. setup test directory $TEST_PATH. If not specified, then the test directory
will be "/tmp/rocksdb/regression_test"
4. run set of benchmarks on the specified host
(can be either locally or remotely)
5. generate report in the $RESULT_PATH. If RESULT_PATH is not specified,
RESULT_PATH will be set to $TEST_PATH/current_time
= Examples =
* Run the regression test using rocksdb commit abcdef that outputs results
and temp files in "/my/output/dir"
r
TEST_PATH=/my/output/dir COMMIT_ID=abcdef ./tools/regression_test.sh
* Run the regression test on a remost host under "/my/output/dir" directory
and stores the result locally in "/my/benchmark/results" using commit
abcdef and with the rocksdb options specified in /my/path/to/OPTIONS-012345
with 1000000000 keys in each benchmark in the regression test where each
key and value are 100 and 900 bytes respectively:
REMOTE_USER_AT_HOST=yhchiang@my.remote.host \
TEST_PATH=/my/output/dir \
RESULT_PATH=/my/benchmark/results \
COMMIT_ID=abcdef \
OPTIONS_FILE=/my/path/to/OPTIONS-012345 \
NUM_KEYS=1000000000 \
KEY_SIZE=100 \
VALUE_SIZE=900 \
./tools/regression_test.sh
= Regression test environmental parameters =
DEBUG: If true, then the script will not checkout master and build db_bench
if db_bench already exists
Default: 0
TEST_MODE: If 1, run fillseqdeterminstic and benchmarks both
if 0, only run fillseqdeterministc
if 2, only run benchmarks
Default: 1
TEST_PATH: the root directory of the regression test.
Default: "/tmp/rocksdb/regression_test"
RESULT_PATH: the directory where the regression results will be generated.
Default: "$TEST_PATH/current_time"
REMOTE_USER_AT_HOST: If set, then test will run on the specified host under
TEST_PATH directory and outputs test results locally in RESULT_PATH
The REMOTE_USER_AT_HOST should follow the format user-id@host.name
DB_PATH: the path where the rocksdb database will be created during the
regression test. Default: $TEST_PATH/db
WAL_PATH: the path where the rocksdb WAL will be outputed.
Default: $TEST_PATH/wal
OPTIONS_FILE: If specified, then the regression test will use the specified
file to initialize the RocksDB options in its benchmarks. Note that
this feature only work for commits after 88acd93 or rocksdb version
later than 4.9.
DELETE_TEST_PATH: If true, then the test directory will be deleted
after the script ends.
Default: 0
= db_bench parameters =
NUM_THREADS: The number of concurrent foreground threads that will issue
database operations in the benchmark. Default: 16.
NUM_KEYS: The key range that will be used in the entire regression test.
Default: 1G.
NUM_OPS: The number of operations (reads, writes, or deletes) that will
be issued in EACH thread.
Default: $NUM_KEYS / $NUM_THREADS
KEY_SIZE: The size of each key in bytes in db_bench. Default: 100.
VALUE_SIZE: The size of each value in bytes in db_bench. Default: 900.
CACHE_SIZE: The size of RocksDB block cache used in db_bench. Default: 1G
STATISTICS: If 1, then statistics is on in db_bench. Default: 0.
COMPRESSION_RATIO: The compression ratio of the key generated in db_bench.
Default: 0.5.
HISTOGRAM: If 1, then the histogram feature on performance feature is on.
STATS_PER_INTERVAL: If 1, then the statistics will be reported for every
STATS_INTERVAL_SECONDS seconds. Default 1.
STATS_INTERVAL_SECONDS: If STATS_PER_INTERVAL is set to 1, then statistics
will be reported for every STATS_INTERVAL_SECONDS. Default 60.
MAX_BACKGROUND_FLUSHES: The maxinum number of concurrent flushes in
db_bench. Default: 4.
MAX_BACKGROUND_COMPACTIONS: The maximum number of concurrent compactions
in db_bench. Default: 16.
SEEK_NEXTS: Controls how many Next() will be called after seek.
Default: 10.
SEED: random seed that controls the randomness of the benchmark.
Default: $( date +%s )
==============================================================================
CONSTANT
==============================================================================
compactall alone will not print ops or threads, which will fail update_report
p50
p75
p99
p99.9
p99.99
Verify that the sample dump file is undumpable and then redumpable.
Test for sst dump tool "raw" mode
!ROCKSDB_LITE return RUN_ALL_TESTS();
Populate slightly more than 1K keys
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2012 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace rocksdb
The value returned by Arena::MemoryAllocatedBytes() may be greater than
the requested memory. We choose a somewhat arbitrary upper bound of
max_expected = expected * 1.1 to detect critical overallocation.
Check the "i"th allocation for the known bit pattern
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Our arena disallows size 0 allocations.
comment: requested size < quarter of a block:
allocate a block with the default size, then try to use unused part
of the block. So one new block will be allocated for the first
Allocate(99) call. All the remaining calls won't lead to new allocation.
label: code-design
requested size
block size
requested size > quarter of a block:
allocate requested size separately
Make sure we didn't count the allocate but not used memory space in
Arena::ApproximateMemoryUsage()
first allocation
allocate inline bytes
namespace
namespace rocksdb
requested size > size of a block:
allocate requested size separately
Fill the "i"th allocation with a known bit pattern
Now the log file will be rolled
Log some headers explicitly using Header()
Also make sure the log size is increasing.
start=
reopens the log file and an empty log file will be created.
OS_WIN
-- Make the log file expire
If only 'log_max_size' options is specified, then every time
when rocksdb is restarted, a new empty log file will be created.
Normal logger
Only roll by size
Log enough data to cause a roll over
namespace rocksdb
Make sure we always write to the same log file (by
checking the create time);
log_file_time_to_roll=
Flush the log for the latest file
namespace
-- Test the existence of file during the server restart.
measure the size of each message, which is supposed
to be equal or greater than log_message.size()
comment: TODO: does not build for Windows because of PosixLogger use below. Need to
port
label: code-design
Return the number of lines where a given pattern was found in the file
again, messages with level smaller than log_level will not be logged.
!ROCKSDB_LITE
comment: HEADER_LEVEL should make this behave like calling Header()
label: code-design
Test the ability to roll by size
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
comment: Since rotation is checked before actual logging, we need to
trigger the rotation by logging another message.
label: code-design
comment: Replace all slashes in the path so windows CompSpec does not
become confused
label: code-design
roll by both Time and size
db_log_dir=
comment: an extra-scope to force the AutoRollLogger to flush the log file when it
becomes out of scope.
label: code-design
Test the ability to roll by Time
Test the logger Header function for roll over logs
We expect the new logs creates as roll over to carry the headers specified
verify that the old log contains all the header logs
Test the cases when the log file will not be rolled.
verify that the files rolled over
Only roll by Time
comment: In this test we only want to Log some simple log message with
no format. LogMessage() provides such a simple interface and
avoids the [format-security] warning which occurs when you
call ROCKS_LOG_INFO(logger, log_message) directly.
label: code-design
-- Write to the log for several times, which is supposed
to be finished before time.
comment: WORKAROUND:
avoid complier's complaint of "comparison between signed
and unsigned integer expressions" because literal 0 is
treated as "singed".
label: code-design
Notes:
(1) Need to pin the old logger before beginning the roll, as rolling grabs
the mutex, which would prevent us from accessing the old logger. This
also marks flush_thread with AutoRollLogger::Flush:PinnedLogger.
(2) Need to reset logger during PosixLogger::Flush() to exercise a race
condition case, which is executing the flush with the pinned (old)
logger after auto-roll logger has cut over to a new logger.
(3) PosixLogger::Flush() happens in both threads but its SyncPoints only
are enabled in flush_thread (the one pinning the old logger).
We know that the old log files are named [path]<something>
Return all entities that match the pattern
log messages with log level smaller than log_level will not be
logged.
test_num == 0 -> standard call to Header()
test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
At this time, the new log file should be created.
We run same operations for kOps times in order to get a more fair result.
comment: This test case only reports the performance between std::vector<std::string>
and autovector<std::string>. We chose string for comparison because in most
of our use cases we used std::vector<std::string>.
label: code-design
comment: Creation and insertion test
Test the case when there is:
* no element inserted: internal array of std::vector may not really get
initialize.
* one element inserted: internal array of std::vector must have
initialized.
* kSize elements inserted. This shows the most time we'll spend if we
keep everything in stack.
* 2 * kSize elements inserted. The internal vector of
autovector must have been initialized.
label: code-design
will always be in heap
forward and backward
Cannot use ASSERT_EQ since that macro depends on iostream serialization
Test both heap-allocated and stack-allocated cases.
pre-generated unique keys
comment: HACK: make sure -> works
label: code-design
comment: HACK avoid compiler's optimization to ignore total
label: code-design
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Sequence Access Test
const iterator
namespace rocksdb
non-const iterator
basic operator test
!ROCKSDB_LITE
GFLAGS
Must not be over 2%
Allowed, but not too often
Allowed, but not too often
Check false positive rate
All added keys must match
Must not be over 2%
Count number of filters that significantly exceed the false positive rate
Empty filter is not match, at this level
Different bits-per-byte
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2012 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Some special values
Test values near powers of two
Construct the list of values to check
comment: Test that encoding routines generate little-endian encodings
label: code-design
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
From rfc3720 section B.4.
namespace crc32c
namespace rocksdb
When we end up with 26 files in trash we will start
deleting new files immediately
Tests in this file are for DeleteScheduler component and dont create any
DBs, so we need to use set this value to 100% (instead of default 25%)
Deleting 100 files will need >28 hours to delete
we will delete the DeleteScheduler while delete queue is not empty
comment: 100 files
100 KB as a file size
1 byte per sec (very slow trash delete)
label: code-design
Hold BackgroundEmptyTrash
1- Create 10 dummy files
2- Delete the 10 files using DeleteScheduler (move them to trsah)
3- Delete the 10 files directly (using env_->DeleteFile)
--- Hold DeleteScheduler::BackgroundEmptyTrash ---
4- Make sure that DeleteScheduler failed to delete the 10 files and
reported 10 background errors
Generate 10 dummy files and move them to trash
namespace rocksdb
comment: Delete dummy files using 10 threads and measure time spent to empty trash
label: code-design
Testing that moving files to trash with the same name is not a problem
1- Create 10 files with the same name "conflict.data"
2- Delete the 10 files using DeleteScheduler
3- Make sure that trash directory contain 10 files ("conflict.data" x 10)
--- Hold DeleteScheduler::BackgroundEmptyTrash ---
4- Make sure that files are deleted from trash
1 Kb / sec
Create "conflict.data" and move it to trash 10 times
comment: Delete dummy files and measure time spent to empty trash
label: code-design
100 files
every file is 1 kb
10 files
every file is 1 kb
1 Byte / sec
10 files ("conflict.data" x 10) in trash
1 MB / sec
Test the basic functionality of DeleteScheduler (Rate Limiting).
1- Create 100 dummy files
2- Delete the 100 dummy files using DeleteScheduler
--- Hold DeleteScheduler::BackgroundEmptyTrash ---
3- Wait for DeleteScheduler to delete all files in trash
4- Verify that BackgroundEmptyTrash used to correct penlties for the files
5- Make sure that all created files were completely deleted
1- Delete the trash directory
2- Delete 10 files using DeleteScheduler
3- Make sure that the 10 files were deleted immediately since DeleteScheduler
failed to move them to trash directory
Same as the BasicRateLimiting test but delete files in multiple threads.
1- Create 100 dummy files
2- Delete the 100 dummy files using DeleteScheduler using 10 threads
--- Hold DeleteScheduler::BackgroundEmptyTrash ---
3- Wait for DeleteScheduler to delete all files in queue
4- Verify that BackgroundEmptyTrash used to correct penlties for the files
5- Make sure that all created files were completely deleted
ROCKSDB_LITE
10 files per thread
every file is 1 kb
comment: 1- Create a DeleteScheduler with very slow rate limit (1 Byte / sec)
2- Delete 100 files using DeleteScheduler
3- Delete the DeleteScheduler (call the destructor while queue is not empty)
4- Make sure that not all files were deleted from trash and that
DeleteScheduler background thread did not delete all files
label: code-design
Move files to trash, wait for empty trash, start again
1 Mb/sec
1- Create 10 dummy files
2- Delete 10 dummy files using DeleteScheduler
3- Wait for DeleteScheduler to delete all files in queue
4- Make sure all files in trash directory were deleted
5- Repeat previous steps 5 times
Create 100 dummy files, every file is 1 Kb
We will delete the trash directory, that mean that DeleteScheduler wont
be able to move files to trash and will delete files them immediately.
Delete 10 files from trash, this will cause background errors in
BackgroundEmptyTrash since we already deleted the files it was
goind to delete
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Disable rate limiting initially
Disable rate limiting by setting rate_bytes_per_sec_ to 0 and make sure
that when DeleteScheduler delete a file it delete it immediately and dont
move it to trash
Ignore "." and ".."
Every file we delete will be deleted immediately
GFLAGS
Allowed, but not too often
Check false positive rate
All added keys must match
Count number of filters that significantly exceed the false positive rate
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Locality enabled version
namespace rocksdb
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright 2014 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
This test uses a custom Env to keep track of the state of a filesystem as of
the last "sync". It then checks for data loss errors by purposely dropping
file data (or entire files) not protected by a "sync".
Return pair <parent directory name, file name> of a full path.
WritableFileWriter* file is opened
again then it will be truncated - so forget our saved state.
Assume a filename, and not a directory name like "/foo/bar/"
For every file that is not fully synced, make a call to `func` with
FileState of the file as the parameter.
A basic file truncation function suitable for this test.
Not allow overwriting files
Because DeleteFile access this container make a copy to avoid deadlock
namespace rocksdb
No need to actual sync.
Trim the tailing "/" in the end of `str`
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright 2014 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
This test uses a custom Env to keep track of the state of a filesystem as of
the last "sync". It then checks for data loss errors by purposely dropping
file data (or entire files) not protected by a "sync".
A wrapper around WritableFileWriter* file
is written to or sync'ed.
For every file that is not fully synced, make a call to `func` with
FileState of the file as the parameter.
UTIL_FAULT_INJECTION_TEST_ENV_H_
namespace rocksdb
Setting the filesystem to inactive is the test equivalent to simulating a
system reset. Setting to inactive will freeze our saved filesystem state so
that it will stop being recorded. It can then be reset back to the state at
the time of the reset.
Record flushes, syncs, writes
Next call to WritableFile::Append() should fail
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Make sure random writes generated enough writes.
In some attempts, flush in a chance of 1/10.
Flush in a chance of 1/10.
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
acquire a lock on a file
re-acquire the lock on the same file. This should fail.
release the lock
namespace rocksdb
The hash algorithm is part of the file format, for example for the Bloom
filters. Test that the hash values are stable for a set of random strings of
varying lengths.
Same as BloomHash.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2012 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Basic test, MAX_VALUE = 3*MAX_HEAP_SIZE (occasional duplicates)
namespace rocksdb
This test performs the same pseudorandom sequence of operations on a
BinaryHeap and an std::priority_queue, comparing output. The three
possible operations are insert, replace top and pop.
Insert is chosen slightly more often than the others so that the size of
the heap slowly grows. Once the size heats the MAX_HEAP_SIZE limit, we
disallow inserting until the heap becomes empty, testing the "draining"
scenario.
GFLAGS
* Compares the custom heap implementation in util/heap.h against
* std::priority_queue on a pseudo-random sequence of operations.
After every operation, check that the public methods give the same
results
hit max size, draining until we empty the heap
insert
pop
One-element heap
Probabilities should be set up to occasionally hit the max heap size and
drain it
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Mid-size heap with small values (many duplicates)
Small heap, large value range (no duplicates)
replace top
Two-element heap
stats
fairness
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
comment: The idea behind is to start a request first, then before it refills,
update limit to a different value (2X/0.5X). No starvation should
be guaranteed under any situation
TODO(lightmark): more test cases are welcome.
label: test
second iteration changes the target dynamically
Test for 2 seconds
refill per second
starvation test when limit changes to a smaller value
bytes
refill_period_us
rate_bytes_per_sec
namespace rocksdb
comment: TODO(yhchiang): the rate will not be accurate when we run test in parallel.
label: test
Return the current option configuration.
Destroy using last options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
namespace
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
int options
Duplicate the random data until we have filled "len" bytes
Make sure to generate a wide variety of characters so we
test the boundary conditions for short-key optimizations.
size_t options
uint64_t options
vector int options
custom typed options
double options
namespace test
namespace rocksdb
' ' .. '~'
namespace
boolean options
uint32_t options
std::string options
unsigned int options
pointer typed options
!ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Return a random key with the specified length that may contain interesting
characters (e.g. \x00, \xff, etc.).
A test comparator which compare two strings in this way:
(1) first compare prefix of 8 bytes in alphabet order,
(2) if two strings share the same prefix, sort the other part of the string
in the reverse alphabet order.
This helps simulate the case of compounded key of [entity][timestamp] and
latest timestamp first.
The following text is boilerplate that forwards all methods to target()
A dummy merge operator which can change its name
namespace test
namespace rocksdb
An internal comparator that just forward comparing results from the
user comparator in it. Can be used to test entities that have no dependency
on internal key structure but consumes InternalKeyComparator, like
BlockBasedTable.
Returns a dummy merge operator with random name.
Iterator over a vector of keys/values
A wrapper around a StringSink to give it a RandomRWFile interface
Like StringSink, this writes into a string. Unlink StringSink, it
has some initial content and overwrites it, just like a recycled
log file.
comment: TODO(yhchiang): Currently doesn't handle the overflow case.
label: code-design
A wrapper that allows injection of errors.
Signalled when background work finishes
Store in *dst a string of length "len" that will compress to
"N*compressed_fraction" bytes and return a Slice that references
the generated data.
Randomly initialize the given DBOptions
Randomly initialize the given ColumnFamilyOptions
Note that the caller is responsible for releasing non-null
cf_opt->compaction_filter.
Store in *dst a random string of length "len" and return a Slice that
references the generated data.
A dummy compaction filter factory which can change its name
Returns a name that identifies this compaction filter factory.
Filters merge operands and values that are equal to `num`.
Corrupts key by changing the type
Returns a dummy compaction filter with a random name.
comment: Returns a user key comparator that can be used for comparing two uint64_t
slices. Instead of comparing slices byte-wise, it compares all the 8 bytes
at once. Assumes same endian-ness is used though the database's lifetime.
Symantics of comparison would differ from Bytewise comparator in little
endian machines.
label: code-design
A dummy compaction filter which can change its name
Verify none of the threads are running
simulated tasks
ROCKSDB_USING_THREAD_STATUS
terminate compaction-write tasks and see if the thread-status
reflects this update
verify the global tables for operations and states are properly indexed.
schedule the simulated tasks
terminate compaction-wait tasks and see if the thread-status
reflects this update
setup right answers
terminate flush-write tasks and see if the thread-status
reflects this update
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
verify the thread-status
Verify the number of running threads in each pool.
Scrape all thread local data. No unref at thread
exit or ThreadLocalPtr destruction
Initiate 2 instnaces: one keeps writing and one keeps reading.
The read instance should not see data from the write instance.
Each thread local copy of the value are also different from each
other.
pick up 2
additional N threads exit unref for the left instance
next new id
Waiting for instruction to exit thread
Suppress false positive clang analyzer warnings.
instance destroy for N threads
Now we have 3, 1 in queue
pick up 1
The following test is disabled as it requires manual steps to run it
correctly.
Currently we have no way to acess SyncPoint w/o ASAN error when the
child thread dies after the main thread dies. So if you manually enable
this test and only see an ASAN error on SyncPoint, it means you pass the
test.
comment: Id used 1
label: code-design
namespace rocksdb
anonymous namespace
pick up 1
Fail Swap, still 2
Swap in 3
comment: Id used 2
label: code-design
pick up 3
return up 1
Triggers the initialization of singletons.
comment: Id used 0
label: code-design
namespace
N threads x 2 ThreadLocal instance cleanup on thread exit
Signal to exit
Case 1: unref triggered by thread exit
Let write threads write a different value from the read threads
Another new thread, read/write should not see value from previous thread
ROCKSDB_LITE
Wait for all threads to finish using Params
Swap in 2
__clang_analyzer__
After exit, id sequence in queue:
3, 1, 2, 0
Loop for 1 second
Case 0: no unref triggered if ThreadLocalPtr is never accessed
New ThreadLocal instance bumps id by 1
global id list carries over 3, 1, 2, 0
comment: Id used 3
label: code-design
Size_T switches size along with the ptr size
we want to cast to.
pick up 0
Case 2: unref triggered by ThreadLocal instance destruction
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Verify Fold() behavior
id 3, 2, 1, 0 are in the free queue in order
Now destroy one ThreadLocal instance
The person who associated a work with this deed has dedicated the work to the
public domain by waiving all of his or her rights to the work worldwide
under copyright law, including all related and neighboring rights, to the
extent allowed by law. You can copy, modify, distribute and perform the
work, even for
commercial purposes, all without asking permission. See Other Information
below.
////////////////////////////////////////
namespace Timing
auto ret = q.cancel(id);
assert(ret == 1);
q.cancelAll();
borrowed from
http://www.crazygaze.com/blog/2016/03/24/portable-c-timer-queue/
Timer Queue
License
The source code in this article is licensed under the CC0 license, so feel
free
to copy, modify, share, do whatever you want with it.
No attribution is required, but Ill be happy if you do.
CC0 license
Portions Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace rocksdb
Have not yet written to this key, so assume its value is 0
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
key format: [SET#][random#]
Non-optimistic transactions should only fail due to expiration
or write failures. For testing purproses, we do not expect any
write failures.
For each set, pick a key at random and increment it
return success if we didn't get any unexpected errors
Optimistic transactions can have write-conflict errors on commit.
Any other error is unexpected.
For each set of keys with the same prefix, sum all the values
ROCKSDB_LITE
stop when we reach a different prefix
prefix_buf needs to be large enough to hold a uint16 in string form
Found key, parse its value
Optimistic transactions should never return non-ok status here.
Non-optimistic transactions may return write-coflict/timeout errors.
Since we did a GetForUpdate, Put should not fail.
Pad prefix appropriately so we can iterate over each set
pick a random number to use to increment a key in each set
Increment key
Returns the number of successfully written calls to
TransactionDBInsert/OptimisticTransactionDBInsert/DBInsert
Returns the number of calls to
TransactionDBInsert/OptimisticTransactionDBInsert/DBInsert that did not
write any data.
Number of successful insert batches performed
Increment a key in each set without using a transaction. If this function
is called in parallel, then Verify() may fail.
Returns true if the write succeeds.
Error status may be obtained by calling GetLastStatus().
optimization: re-use allocated transaction objects.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Returns OK if Invariant is true.
Increment a key in each set using a Transaction on a TransactionDB.
Returns true if the transaction succeeded OR if any error encountered was
expected (eg a write-conflict). Error status may be obtained by calling
GetLastStatus();
Utility class for stress testing transactions. Can be used to write many
transactions in parallel and then validate that the data written is logically
consistent. This class assumes the input DB is initially empty.
Each call to TransactionDBInsert()/OptimisticTransactionDBInsert() will
increment the value of a key in #num_sets sets of keys. Regardless of
whether the transaction succeeds, the total sum of values of keys in each
set is an invariant that should remain equal.
After calling TransactionDBInsert()/OptimisticTransactionDBInsert() many
times, Verify() can be called to validate that the invariant holds.
To test writing Transaction in parallel, multiple threads can create a
RandomTransactionInserter with similar arguments using the same DB.
Input options
Returns the status of the previous Insert operation
Status returned by most recent insert operation
ROCKSDB_LITE
Number of failed insert batches attempted
namespace rocksdb
Increment a key in each set using a Transaction on an
OptimisticTransactionDB
Returns true if the transaction succeeded OR if any error encountered was
expected (eg a write-conflict). Error status may be obtained by calling
GetLastStatus();
num_keys is the number of keys in each set.
num_sets is the number of sets of keys.
Read from meta-file failure
test various kind of corruptions that may happen:
1. Not able to write a file for backup - that backup should fail,
everything else should work
2. Corrupted backup meta file or missing backuped file - we should
not be able to open that backup, but all other backups should be
fine
3. Corrupted checksum value - if the checksum is not a valid uint32_t,
db open should fail, otherwise, it aborts during the restore process.
should write 5 DB files + one meta file
implicit
pair<filename, alive?>
test purge old backups
when i == 4, purge to only 1 backup
when i == 3, purge to 2 backups
Verify manifest can roll while a backup is being created with the old
manifest.
set up backup db options
set share_files_with_checksum to true and do some more backups
has to be a big number, so that it triggers the memtable flush
what business do you have calling this method?
create backups 1, 2, 3, 4, 5
Backup the LATEST options file to
"<backup_dir>/private/<backup_id>/OPTIONS<number>"
files
1GB
Test that we properly propagate Env failures
namespace rocksdb
MANIFEST file size should be only 100
The last manifest roll would've already been cleaned up by the full scan
that happens when CreateNewBackup invokes EnableFileDeletions. We need to
trigger another roll to verify non-full scan purges stale manifests.
--------- case 2. corrupted backup meta or missing backuped file ----
128KB
backup overwrites file 000007.sst
delete old data
utility functions
---------- case 3. - corrupt a file -----------
Verify the specified max backups are opened, including skipping over
corrupted backups.
Setup:
- backups 1, 2, and 4 are valid
- backup 3 is corrupt
- max_valid_backups_to_open == 2
Expectation: the engine opens backups 4 and 2 since those are latest two
non-corrupt backups.
now, the backup can succeed
should never get here
no failure
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
share_table_files
!defined(ROCKSDB_LITE) && !defined(OS_WIN)
---- restore the DB ----
TestEnv
new backup should be 2!
this will make sure that backup does not copy the same file twice
checksum of backup 3 is an invalid value, this can be detected at
db open time, and it reverts to the previous backup automatically
This test verifies that the verifyBackup method correctly identifies
invalid backups
Create logger
00011.sst was only in backup 1, should be deleted
delete old files in db
should write 4 new DB files + one meta file
should not write/copy 00010.sst, since it's already there!
make sure that no corrupt backups have actually been deleted!
To avoid FlushWAL called on stacked db which is nullptr
---------- case 1. - valid backup -----------
size_bytes
we should get consistent results with flush_before_backup
set to both true and false
open DB, write, backup, write, backup, close, restore
Verify that you can backup and restore with share_files_with_checksum on
should not open 00010.sst - it's already there
logger_ must be above backup_engine_ such that the engine's destructor,
which uses a raw pointer to the logger, executes first.
set share_files_with_checksum to false
all the dbs!
BackupableDB owns dummy_db_
---------- case 4. - invalid backup -----------
destroy_old_data
checksum of the backup 2 appears to be valid, this can cause checksum
mismatch and abort restore process
every iteration --
1. insert new data in the DB
2. backup the DB
3. destroy the db
4. restore the db, check everything is still there
should fail creation
4 is corrupted, 3 is the latest backup now
in last iteration, put smaller amount of data,
latest backup should have all the keys
Interrupt backup creation by failing new writes and failing cleanup of the
partial state. Then verify a subsequent backup can still succeed.
we deleted backup 2
DummyDB
delete backup number 2, online delete!
create five backups
single digit value, safe to insert one more digit
check backup 5
DummyLogFile
Verify that you can backup and restore using share_files_with_checksum set to
false and then transition this option to true
close and destroy
anon namespace
Must reset() before reset(OpenDB()) again.
Calling OpenDB() while *db_ is existing will cause LOCK issue
first iter -- flush before backup
second iter -- don't flush before backup
---------- case 1. - fail a write -----------
try creating backup 6, but fail a write
--------- case 3. corrupted checksum value ----
restores backup backup_id and asserts the existence of
[start_exist, end_exist> and not-existence of
[end_exist, end>
if backup_id == 0, it means restore from latest
if end == 0, don't check AssertEmpty
delete the corrupt backups and then make sure they're actually deleted
should fail
---- insert new data and back up ----
check backup 3
BackupableDBTest
this seqnum guarantees the dummy file will be included in the backup
as long as it is alive.
the new backup fails because new table files
clash with old table files from backups 4 and 5
(since write_buffer_size is huge, we can be sure that
each backup will generate only one sst file and that
a file generated by a new backup is the same as
sst file generated by backup 4)
see https://github.com/facebook/rocksdb/issues/921
envs
open DB, write, close DB, backup, restore, repeat
all data should be there if we call with keep_log_files = true
assert that data from backup 5 is still here (even though LATEST_BACKUP
says 4 is latest)
. and ..
---- restore every backup and verify all the data is there ----
in last iteration, put smaller amount of data,
so that backups can share sst files
share_with_checksums
FileManager
new directory failure
dummy
comment: should also fail cleanup so the tmp directory stays behind
label: code-design
Behavior change: We now ignore LATEST_BACKUP contents. This means that
we should have 5 backups, even if LATEST_BACKUP says 4.
basically infinite
since 5 meta is now corrupted, latest backup should be 4
file 000007.sst was overwritten
always rollover manifest for file add
set up files
write some data, backup, repeat
get children failure
---- make sure it's empty ----
set up envs
iter 0 -- single threaded
iter 1 -- multi threaded
Some test cases do not actually create the test files (e.g., see
DummyDB::live_files_) - for those cases, we mock those files' attributes
so CreateNewBackup() can get their attributes.
This test verifies we don't delete the latest backup when read-only option is
set
---------- case 2. - delete a file -----------i
---- make sure the data is there ---
destroy old data
reset all the defaults
options
this depends on the fact that 00007.sst is the first file created by the DB
set up db options
most tests will use multi-threaded backups
restore 3
Need to call this explicitly to delete tmp files
created dir failure
delete some backups -- this should leave only backups 3 and 5 alive
context
Filter expired blob indexes regardless of snapshots.
new_value
skip_until
level
namespace blob_db
namespace rocksdb
ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Expired
Unable to decode blob index. Keeping the value.
CompactionFilter to delete expired blob index from base DB.
namespace blob_db
namespace rocksdb
!ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Iterator::Refresh() not supported.
Test for data in SST
Take a snapshot before compaction. Make sure expired blob indexes is
filtered regardless of snapshot.
First file
The file shouln't be deleted
Test for data in memtable
The call simply pass through to base db. It should succeed.
value_changed
The default ttl extractor return no ttl for every key.
Write to plain rocksdb.
Issue manual compaction to trigger compaction filter.
Second file
Putting another blob should fail as ading it would exceed the blob_dir_size
limit.
namespace blob_db
namespace rocksdb
i = when to take snapshot
The oldest simple blob file (i.e. blob_files[1]) has been selected for GC.
The snapshot shouldn't see data in bfile
Third file
wait
Test to verify that a NoSpace IOError Status is returned on reaching
blob_dir_size limit.
now
The snapshot will see data in bfile, so the file shouldn't be deleted
Fake blob index with TTL. See what it will do.
Open as blob db. Verify it can read existing data.
!ROCKSDB_LITE
new_value
very far in the future..
DB should be empty.
class BlobDBTest
Verify blob db contain expected data and nothing more.
The file is deleted this time
Adding another 100 byte blob would take the total size to 264 bytes
(2*132), which is more than 90% of blob_dir_size. So, the oldest file
should be evicted and put in obsolete files list.
Verify iterators
VerifyDB use iterator to scan the DB.
This test is no longer valid since we now return an error when we go
over the configured blob_dir_size.
The test needs to be re-written later in such a way that writes continue
after a GC happens.
context
override all the keys
Use mock env to stop wall clock.
comment: Each stored blob has an overhead of about 42 bytes currently.
So a small key + a 100 byte blob should take up ~150 bytes in the db.
label: code-design
run the same test for Get(), MultiGet() and Iterator each.
comment: Each stored blob has an overhead of 32 bytes currently.
So a 100 byte blob should take up 132 bytes.
label: code-design
Verify expired blob index are filtered.
Verify normal Get
Verify plain db return error for keys written by blob db.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
A black-box test for the ttl wrapper around rocksdb
If true, the keys in this file all has TTL. Otherwise all keys don't
have TTL.
Mark file as obsolete by garbage collection. The file is not visible to
snapshots with sequence greater or equal to the given sequence.
The last sequence number by the time the file marked as obsolete.
Data in this file is visible to a snapshot taken before the sequence.
namespace blob_db
namespace rocksdb
ROCKSDB_LITE
Compression type of blobs in the file
has a pass of garbage collection successfully finished on this file
obsolete_ still needs to do iterator/snapshot checks
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
BlobIndex is a pointer to the blob and metadata of the blob. The index is
stored in base DB as ValueType::kTypeBlobIndex.
There are three types of blob index:
kInlinedTTL:
+------+------------+---------------+
| type | expiration | value |
+------+------------+---------------+
| char | varint64 | variable size |
+------+------------+---------------+
kBlob:
+------+-------------+----------+----------+-------------+
| type | file number | offset | size | compression |
+------+-------------+----------+----------+-------------+
| char | varint64 | varint64 | varint64 | char |
+------+-------------+----------+----------+-------------+
kBlobTTL:
+------+------------+-------------+----------+----------+-------------+
| type | expiration | file number | offset | size | compression |
+------+------------+-------------+----------+----------+-------------+
| char | varint64 | varint64 | varint64 | varint64 | char |
+------+------------+-------------+----------+----------+-------------+
There isn't a kInlined (without TTL) type since we can store it as a plain
value (i.e. ValueType::kTypeValue).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace blob_db
namespace rocksdb
ROCKSDB_LITE
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Verify the deserialization.
Column1: Column
Column2: Tombstone
Verify the serialization.
namespace cassandra
namespace rocksdb
expired
not expired
Verify the ColumnBase::Deserialization.
Column0: ExpiringColumn
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Start each test with a fresh DB
expired
namespace cassandra
namespace rocksdb
The class for unit-testing
expired
not expired
Path to the database on file system
THE TEST CASES BEGIN HERE
If the tombstone's timestamp is the latest, then it returns a
row tombstone.
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
namespace cassandra
namespace rocksdb
Some of the column's row is smaller, some is larger.
All of the column's rows are larger than tombstone.
This row's timestamp is smaller than tombstone.
A row tombstone.
namespace cassandra
namespace rocksdb
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Return the current option configuration.
Destroy using last options
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Sequence of option configurations to try
Roll the manifest during checkpointing right after live files are
snapshotted.
Writing prepare into middle of first WAL, then flush WALs many times
Restore DB name
namespace rocksdb
Flush should never trigger.
Open snapshot and verify contents
always rollover manifest for file add
Create a database
Open snapshot and verify contents while DB is running
allow_2pc is implicitly set with tx prepare
options.allow_2pc = true;
Destroy it for not alternative WAL dir is used.
!ROCKSDB_LITE
One flush after preapare + one outstanding file before checkpoint + one log
file generated after checkpoint.
Syncpoint prevents us building and running tests in release
Insert something into CFB so lots of log files will be kept
before creating the checkpoint.
Destroy original DB
Successful Open() implies that CURRENT pointed to the manifest in the
checkpoint.
Take a snapshot
Get past the flush in the checkpoint thread before adding any keys to
the db so the checkpoint thread won't hit the WriteManifest
syncpoints.
No more than two logs files should exist.
Check correctness of decoded data
Check correctness of encoded string length
Check encoded string length: first value is original one (val - 0), the
coming three are encoded as 1, -1, 1, so they should take 1 byte in varint.
Check correctness of decoded value
Check encoded string length
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Check correctness of encoded value
ROCKSDB_LITE
namespace rocksdb
Check correctness of decoded string length
Database open and close should not affect
Multiple column families for time series data
Create key value pairs to insert
check all insertions done
Another time series column family is created
Resets the timestamp of a set of kvs by updating them and checks that they
are not deleted according to the old timestamp
T=2, keys put into database are already obsolete
Put data in database. Operations should not return OK
Put data in database
Explicitly drop obsolete column families
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
T=2, keys should not be retrieved
Iterator should be able to merge data from different column families
T=0, open the database and insert data
The first column family is deleted from database
Populates and returns a kv-map
T=5, keys should not be retrieved
!ROCKSDB_LITE
Empty iterator
Put more data
comment: A black-box test for the DateTieredDB around rocksdb
label: test
namespace rocksdb
Data should not be found in database
Puts a set of values and checks its presence using Get during ttl
Key should not be found
Only default column family
Puts a set of values and checks its presence using iterator during ttl
Iterator should be able to merge data from multiple column families
comment: Delete keys when they are not obsolete
label: code-design
A time series column family is created
comment: If the key in Put() is obsolete, the data should not be written into database
label: code-design
T=1, keys should still reside in database
inserting a document with existing primary key should return failure
Delete all whose progress is bigger than 50%
job_name == 'white' AND priority >= 2, index job_name
2 < priority <= 4, index priority
35.0 <= progress < 65.5, index progress
add index on the fly!
2 < priority < 4 AND progress > 10.0, index priority
2 < priority < 6, index priority
-2 < priority < 0
4 < priority
2 < priority < 4 AND progress > 10.0, index progress
find all -- only "Two" left, everything else should be deleted
update set priority to 10 where job_name is 'white'
now there is index present
!ROCKSDB_LITE
find equal to "Two"
priority < 0
remove less or equal to "Three"
namespace rocksdb
find less than "Three"
converts ' to ", so that we don't have to escape " all over the place
-1 <= priority <= 1, index priority
-2 <= priority < 0
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
update twice: set priority to 15 where job_name is 'white'
find less than "Three" without index
update twice: set priority to 15 and
progress to 40 where job_name is 'white'
Copy constructor from owner -> owner
Move constructor from owner -> owner
test deep copying
test iteration
kNull
!ROCKSDB_LITE
namespace rocksdb
kInt64
Move constructor from non-owner -> non-owner
Copy constructor from non-owner -> non-owner
properties
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
deserialization failure
kBool
kString
parse error
kDouble
Set a snapshot at start of transaction
* next, we actually connect to the cluster
open DB
comment: Optimize Rocksdb. This is the easiest way to get RocksDB to perform well
label: code-design
Read "foo".
comment: Optimize RocksDB. This is the easiest way to get RocksDB to perform well
label: code-design
Do some reads and writes to key "x"
//////////////////////////////////////////////////////
"Read Committed" (Monotonic Atomic Views) Example
--Using multiple Snapshots
//////////////////////////////////////////////////////
Check that the file exists.
Set a snapshot at start of transaction by setting set_snapshot=true
Read "d".
namespace rocksdb
Read "hello".
Check that the directory is empty.
get value
Attempt to read a key using the snapshot. This will fail since
the previous write outside this txn conflicts with this read.
Commit.
Write to the file.
Try to skip past end of file.
Check that opening non-existent file fails.
//////////////////////////////////////////////////////
Simple OptimisticTransaction Example ("Read Committed")
//////////////////////////////////////////////////////
Random reads.
Read a key OUTSIDE this transaction. Does not affect txn.
Check that renaming works.
Start a transaction
Commit transaction
comment:
* And now we're done, so let's remove our pool and then
* shut down the connection gracefully.
label: code-design
create the DB if it's not already present
Read "world".
Too high offset.
*********************************
use default env
**********************************
Copyright (c) 2016, Red Hat, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
just use the client.admin keyring
let's handle any error that might have come back
*********************************
use librados env
**********************************
//////////////////////////////////////////////////////
"Repeatable Read" (Snapshot Isolation) Example
-- Using a single Snapshot
//////////////////////////////////////////////////////
Do some reads and writes to key "y"
Since the snapshot was advanced, the write done outside of the
transaction does not conflict.
!ROCKSDB_LITE
Check that deleting works.
Read sequentially.
atomically apply a set of updates
These are no-ops, but we test they return success.
Check for expected size.
Do a write outside of the transaction to key "y"
Set a new snapshot in the transaction
Write a key OUTSIDE of transaction
we will use all of these below
Create a file.
Write a key OUTSIDE of this transaction.
Does not affect txn since this is an unrelated key. If we wrote key 'abc'
here, the transaction would fail to commit.
be careful not to
Read a key in this transaction
In this example, we set the snapshot multiple times. This is probably
only necessary if you have very strict isolation requirements to
implement.
Decide we want to revert the last write from this transaction.
Put key-value
comment: Cleanup
label: code-design
Try reading past EOF.
This could fail if the config file is malformed, but it'd be hard.
Clear snapshot from read options since it is no longer valid
Write a key in this transaction
Copyright (c) 2015, Red Hat, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Read "foo".
namespace rocksdb
Check that the file exists.
Read "d".
Read "hello".
Check that the directory is empty.
Write to the file.
Try to skip past end of file.
Check that opening non-existent file fails.
Random reads.
Check that renaming works.
Read "world".
Too high offset.
!ROCKSDB_LITE
Check that deleting works.
Read sequentially.
These are no-ops, but we test they return success.
Check for expected size.
Create a file.
Try reading past EOF.
namespace rocksdb
Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
ROCKSDB_LITE
search all objects centered at 46 degree latitude with
a radius of 2 kilometers. There should be none.
search all objects centered at 46 degree latitude with
a radius of 200 kilometers. We should find the one object that
we inserted earlier.
insert first object into database
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Search.
Verify distances via http://www.stevemorse.org/nearest/distance.php
check that we can still find second object
insert object at 45 degree latitude
Insert, Get and Remove
retrieve first object using position
retrieve first object using id
namespace rocksdb
insert second object into database
delete first object
!ROCKSDB_LITE
Performs the following logic:
If key[0] < 'h' --> replace value by reverse key
If key[0] >= 'r' --> keep the original key value
Otherwise, filter the key value
keeps all the key value pairs
removes all keys whose initial is less than 'r'
Issue full compaction and expect nothing is in the DB.
If nothing is set in the LuaCompactionFilterOptions, then
RocksDB will keep all the key / value pairs, but it will also
print our error log indicating failure.
removes all the key value pairs
Issue full compaction and expect everything is in the DB.
Copyright (c) 2016, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Create DB with 10 files
Filter() error when input key's initial >= 'r'
defined(LUA)
!defined(ROCKSDB_LITE)
removes all values whose initial is less than 'r'
namespace rocksdb
Replace all values by their reversed key
change the lua script to removes all the key value pairs
Issue full compaction and expect all keys which initial is < 'r'
will be deleted as we keep the key value when we hit an error.
namespace rocksdb
comment: Fill one memtable per Put to make memtable use more memory.
label: code-design
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Cache from table factories
Expect the usage history of the table readers increases
as we flush tables.
Create an iterator and flush all memtables for each db
Expect the usage history from the "usage_decay_point" is
monotonically decreasing.
Cache from DBImpl
Cache from DBOptions
Expect EQ as we didn't flush more memtables.
Expect the usage of all memtables decreasing as we delete iterators.
Expect the usage history is monotonically increasing
Since the memory usage of un-flushed memtables is only affected
by Put and flush, we expect EQ here as we only delete iterators.
Since memtables are pinned by iterators, we don't expect the
memory usage of all the memtables decreases as they are pinned
by iterators.
!ROCKSDB_LITE
Start each test with a fresh DB
we should have a place to store the result
implicit
Perform the following operations in limited scope
Get (Quick check for persistence of previous database)
Apply the similar "Append" to the parallel copy
start from k2 this time.
Append, Flush, Append, Get
!ROCKSDB_LITE
namespace
Allows user to open databases with different configurations.
e.g.: Can open a DB or a TtlDB, etc.
namespace rocksdb
Path to the database on file system
Should release the snapshot and be aware of the new stuff now
deterministic seed
THE TEST CASES BEGIN HERE
Constructor: specifies the rocksdb db
Generate a random query (Append or Get) and random parameters
Apply the query and any checks.
All changes should be on disk. This will test VersionSet Get()
NotFound is okay; just return empty (similar to std::map)
But network or db errors, etc, should fail the test (or at least yell)
Assumes that a non-existent key just returns <empty>
Append, Get
OpenDb opens a (possibly new) rocksdb database with a StringAppendOperator
/ StringLists represents a set of string-lists, each with a key-index.
/ Supports Append(list, string) and Get(list)
Construct the desired string. Default constructor doesn't like '\0' chars.
Verify that the string is right size.
Use null delimiter instead of comma.
Will store a local copy of all data in order to verify correctness
Either key does not exist, or there is some error.
Always return empty string (just for convention)
!ROCKSDB_LITE
Append string val onto the list defined by key; return true on success
Snapshot should still be the same. Should ignore a4 and v4.
The class for unit-testing
Generate semi random keys/words from a small distribution.
TtlDb is not supported in Lite
Open a TtlDB with a non-associative StringAppendTESTOperator
I omit the "assert(success)" checks here.
should not be hit
Append, Compact, Get
TtlDb is not supported in Lite
Run with TTL
Append, Flush, Get
deterministic seed; always get same results!
Append, Flush, Compact, Get
Always return false if s.ok() was not true
Apply the rocksdb test-harness Append defined above
apply the rocksdb append
Returns the list of strings associated with key (or "" if does not exist)
*
* An persistent map : key -> (list of strings), using rocksdb merge.
* This file is a test-harness / use-case for the StringAppendOperator.
*
* @author Deon Nicholas (dnicholas@fb.com)
* Copyright 2013 Facebook, Inc.
Verify it is still the correct size
Generate a bunch of random queries (Append and Get)!
The previous changes should be on disk (L0)
The most recent changes should be in memory (MemTable)
Hence, this will test both Get() paths.
Check that the rocksdb result string matches the desired string
Run with regular database
Reopen the database (the previous changes should persist / be remembered)
Apply the query and any checks.
All three keys should have been found
Generate a list of random keys and values
Compact, Get
namespace rocksdb
ROCKSDB_LITE
Env::Default() is a singleton so we can't grant ownership directly to the
caller - we must wrap it first.
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Make level target of L1, L2 to be 200KB and 600KB
Required if inheriting from testing::WithParamInterface<>
Wait for compaction to finish and make sure it can reopen
Will make sure exactly those keys are in the DB after migration.
ROCKSDB_LITE
namespace rocksdb
Generate at least 2MB of data
Issue a full compaction to generate some zero-out files
GFLAGS
It's okay to change prefix_extractor from nullptr to non-nullptr
prefix extractor
close the db
It's okay to set prefix_extractor to nullptr.
namespace rocksdb
perform sanity check
prefix extractor nullptr case
determine whether this is a valid src upon the function applies
determine whether dst=Transform(src) for some src
transform a src in domain to a dst in the range
namespace
!ROCKSDB_LITE
Assign non-null values to prefix_extractors except the first cf.
comparator
table factory
Return the name of this transformation.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
merge operator
open and persist the options
erase a few keys randomly
Copyright (c) 2013, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
insert
verify
ret=
namespace rocksdb
unfortunately we can't predict eviction value since it is from any one of
the lock stripe
small write buffer
page cache, block cache, compressed cache + KNoCompression
both block cache and compressed cache, but DB is not compressed
also, make block cache sizes bigger, to trigger block cache hits
cleanup files with the patter :digi:.rc
construct a tiered RAM+Block cache
max_usecase=
Copyright (c) 2013, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
compressed=
namespace rocksdb
direct_writes=
Simple logger that prints message on stdout
remember kNoCompression
nthreads=
number of insertion interations
create primary tier
is_compressed
page cache, no block cache, no compressed cache
page cache, block cache, compressed cache + KNoCompression
max_keys=
max_size=
Travis is unable to handle the normal version of the tests running out of
fds, out of space and timeouts. This is an easier version of the test
specifically written for Travis
we assume the directory does not exist
block_cache_size
page cache, no block cache, no compressed cache
Page cache caches compressed blocks
check that we triggered the appropriate code paths in the cache
create block cache
test table with block page cache
setup page cache
insert data
flush all data in cache to device
max_keys
Volatile cache tests
page cache, block cache, no-compressed cache
test template
test table with volatile page cache
page cache, block cache, compressed cache
test table with tiered page cache
size=
create secondary tier
create a new cache tier
Block cache tests
dbname
verify data
create tier out of the two caches
Tiered cache tests
memory_size=
the tests causes a lot of file deletions which Travis limited testing
environment cannot handle
is_compressed=
Wait for threads to join
template for negative insert test
assume that the key is evicted
eviction_enabled=
flush all data from memtable so that reads are from block cache
Copyright (c) 2013, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
insert data to table
pad 0 to numbers
Unit tests for testing PersistentCacheTier
template for insert with eviction test
namespace rocksdb
copy numbers
Flush cache
high compression ratio
count=
Run insert workload in threads
post condition
template for insert test
Write 8MB (80 values, each 100K)
create threaded workload
default column family doesn't have block cache
spawn threads
test template
Verification implementation
copy 0s
Run verification on the cache
Insert workload implementation
join with threads
RocksDB tests
verify data
Size should not change
Check
Get the list
Repopulate some stuff
Results in: [x, x, x, x, x, newbegin, z, x, aftera, x, newend, a, x]
Added by Deon
Exhaustive test of the Range() function
Partial / Broken indices
Block one: populate a single key in the database
Test Trim
[z, a, aftera, x] (do nothing)
PushRight, Length, Index, Range
Persistent, non-destructive
We have: [sad, nota, zz, happy, z, beforeba2, ba2, a, aftera, x, newend]
Simple Pushes (will yield: [v6, v4, v4, v1, v2, v3]
Test InsertAfter end
Testing Remove, RemoveFirst, RemoveLast
Empty
The length should not change
Test out of bounds (empty) trim
Check valid indices
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Set() with negative indices
Exhaustive test for InsertBefore(), and InsertAfter()
Block two: make sure changes were saved and add some other key
Test InsertAfter
[sad, a, happy, z, a, aftera, ...]
Test bad value on InsertAfter
Test removal from end
Check
operator== and operator<< are defined below for vectors (lists)
Needed for ASSERT_EQ
Bad indices (just out-of-bounds / off-by-one check)
InsertBefore start of list
InsertAfter end of list
Used below for all Index(), PopRight(), PopLeft()
Test Inserting before/after non-existent values
Ensure that the length doesn't change
namespace
Test Regular Set
[z, a, aftera]
A series of pushes and insertions
Will result in [newbegin, z, a, aftera, x, newend, a, a]
Testing Insert, Push, and Set, in a mixed environment
comment: / THE manual REDIS TEST begins here
/ THIS WILL ONLY OCCUR IF YOU RUN: ./redis_test -m
label: test
Make sure nothing weird happened.
Testing duplicate values/pivots (multiple occurrences of 'a')
[a, z, a, aftera, x, newend]
[a, happy, z, a, aftera, ...]
Check Length and Index() functions
Check length
Set on empty list (return false, and do not crash)
Check range function and vectors
Get the list
comment: Test over-shooting (removing more than there exists)
label: code-design
comment: USAGE: "./redis_test" for default (unit tests)
"./redis_test -m" for manual testing (redis command api)
"./redis_test -m -d" for destructive manual test (erase db before use)
label: test
Simple PushRight
Testing Trim, Pop
Simple Pushes (will yield: [v6, v4, v4, v1, v2, v3])
Removal from an empty-list
namespace rocksdb
Simple, non-negative indices
Try removing ALL!
REMOVE 0 will remove all!
Check RemoveFirst (Remove the first two 'a')
Results in [newbegin, z, aftera, x, newend, a]
Test InsertBefore
Exhaustive test of Set function
Test out of bounds Set
One last check (to make sure nothing weird happened)
Size should not change
Check for "want" argument in the argument list
Invalid indices
Empty Index check (return empty and should not crash or edit tempv)
Exhaustive Trim test (negative and invalid indices)
Will start in [newbegin, z, a, aftera, x, newend]
!ROCKSDB_LITE
We now have: [x, x, x, x, newbegin, z, aftera, newend, a]
Should do nothing
Destructive
Only really removed 4
Popping with empty list (return empty without error)
Negative indices (i.e.: measured from the end)
comment: Will run unit tests.
However, if -m is specified, it will do user manual/interactive testing
-m -d is manual and destructive (will clear the database before use)
label: test
Push some preliminary stuff [g, f, e, d, c, b, a]
Range matches Index
Simple PopLeft/Right test
Insert on empty list (return 0, and do not crash)
A series of pushes and insertions
Will result in [newbegin, z, a, aftera, x, newend]
Also, check the return value sometimes (should return length)
/ Allows the user to enter in REDIS commands into the command-line.
/ This is useful for manual / interacticve testing / debugging.
/ Use destructive=true to clean the database before use.
/ Use destructive=false to remember the previous state (i.e.: persistent)
/ Should be called from main function.
InsertBefore beginning of list
InsertAfter end of list
[sad, nota, zz, happy, z, a, ...]
[sad, nota, zz, happy, z, ba, a, ...]
Exhaustive test of the Index() function
Sanity check (check the length; make sure it's 6)
Last check
[sad, a, zz, happy, z, a, aftera, ...]
Set with negative indices
Block three: Verify the changes from block 2
Ensure Set worked correctly
Test Multiple keys and Persistence
A series of pushes and insertions
Will result in [newbegin, z, a, aftera, x, newend]
Out of bounds (return empty, no crash)
Simply Test the Set() function
PushLeft, Length, Index, Range
Simple PushRight (should return the new length each time)
Test bad value on InsertBefore
Negative indices
Now have: [z, a, aftera, x]
*
* A test harness for the Redis API built on rocksdb.
*
* USAGE: Build with: "make redis_test" (in rocksdb directory).
* Run unit tests with: "./redis_test"
* Manual/Interactive user testing: "./redis_test -m"
* Manual user testing + restart database: "./redis_test -m -d"
*
* TODO: Add LARGE random test cases to verify efficiency and scalability
*
* @author Deon Nicholas (dnicholas@fb.com)
[a]
Test InsertBefore beginning
C-version defined in <ctype.h>
We currently have: [sad, nota, zz, happy, z, ba, a, aftera, x, newend]
redis.Print("k1"); // manually check
Verify
Simple range
comment: TODO: Right now, please use spaces to separate each word.
In actual redis, you can use quotes to specify compound values
Example: RPUSH mylist "this is a compound value"
label: code-design
error margin of 100 bytes
We asked for every block twice
namespace rocksdb
count number of lookups
count number of additions
Log things again but stop logging automatically after reaching 512 bytes
Release iterators and access cache again.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Test with strict capacity limit.
Set a small enough block size so that each key-value get its own block.
options.compression = kNoCompression;
Load blocks into cache.
We added every block only once, since the cache can hold all blocks
Add kNumBlocks again
iter 0 -- not read only
iter 1 -- read only
namespace spatial
namespace rocksdb
null
corrupted serialization
serial
parallel
even though the bounding box doesn't intersect, we got "four" back
because
it's in the same tile
namespace
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
!ROCKSDB_LITE
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
TEST 3: Issues a lots of deletes, but their density is not
high enough to trigger compaction.
Only one section of a file satisfies the compaction trigger
randomize tests
deterministic tests
Simple test
Insert "kNumDeletionTrigger * 0.95" deletions for every
"kWindowSize" and verify compaction is not needed.
!ROCKSDB_LITE
Txn should commit
Rollback to beginning of txn
This Put outside of a transaction will conflict with the previous read
txn1 can commit since txn2's delete hasn't happened yet (it's just batched)
have to open default column family
This Put outside of a transaction will conflict with the previous write
Create N threads that use RandomTransactionInserter to write
many transactions.
This should not conflict in txn since the snapshot is later than the
previous write (spoiler alert: it will later conflict with txn2).
txn2 cannot commit since txn1 changed "4"
txn should commit since the flushed table is still in MemtableList History
Put a key which will conflict with the next txn using the previous snapshot
Write some data to the db
Put a random key so we have a MemTable to flush
Set a new snapshot
namespace rocksdb
Put a random key so we have a memtable to flush
Modify BBB before snapshot is taken
1
Wait for all threads to run
key "C" was modified in the db after txn's snapshot. txn will not commit.
Verify transaction rollback works for untracked keys.
Should commit since read/write was done after data changed
force a memtable flush
open the new column families
Write to the untracked key outside of the transaction and verify
it doesn't prevent the transaction from committing.
Txn should not commit
Conflicts with write done after snapshot taken
verify that we track multiple writes to the same key at different snapshots
Modify key after transaction start
Verify txn did not commit
Write some keys in a txn
2
This will conflict since the snapshot is earlier than another write to ZZZ
Rollback to 3
Verify that txn1 cannot commit since A will still be conflict checked
namespace
Verify that data is consistent
!ROCKSDB_LITE
Write some keys to the db
These keys do no conflict with existing writes since they're in
different column families
Write some keys to the db after the snapshot
unexpected failure
open DB with three column families
Write to tracked key outside of the transaction and verify that the
untracked keys are not written when the commit fails.
Test 2 transactions writing to the same key in multiple orders and
with/without snapshots
Potentially conflicting writes
Verify Txn Did not Commit
Make sure at least some of the transactions succeeded. It's ok if
some failed due to write-conflicts.
Read and write with snapshot
3
4
should not commit since txn2 wrote a key txn has read
This Put outside of a transaction will conflict with a later write
Create 2 new column families
Read all keys via iter and lock them all
Verify that transaction did not write anything
txn should not commit since MemTableList History is not large enough
This write will cause a conflict with the earlier batch write
Test to make sure transactions work when there are no other writes in an
empty db.
force a memtable flush
Since our test db has max_write_buffer_number=2, this flush will cause
the first memtable to get purged from the MemtableList history.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Setting the key-space to be 100 keys should cause enough write-conflicts
to make this test interesting.
Read and write without a snapshot
Rollback to 2
Verify that txn1 can commit since A isn't conflict checked
try rollback again
Txn should commit
This Put outside of a transaction will conflict with the previous read
should show the first txn log
verify foo is locked by txn
Verify that only "A" is locked
Snapshot is now set
This should not conflict in txn since the snapshot is later than the
previous write (spoiler alert: it will later conflict with txn2).
wait for friends
txn2 has a smaller lock timeout than txn1's expiration, so it will time out
should succeed since key was written before txn started
assure that all thread are in the same write group
Put a key which will conflict with the next txn using the previous snapshot
Write some data to the db
Put a random key so we have a MemTable to flush
Set a new snapshot
Verify A,B,D,E,F are still locked and C is not.
verify that txn has "A" locked
flush only cfb memtable
Locked keys exist in both column family.
Reinitilize txn1 and verify that Z gets unlocked
comment: TODO this test needs to be updated with serial commits
label: test
Create a txn and verify we can only lock up to 3 keys
Verify that "A" and "C" is still locked while "B" is not
Upsize the buffer and verify the 3 latest dealocks are preserved.
fails due to non-empty commit-time batch
valid name set
sleep override
Should commit since read/write was done after data changed
mix transaction writes and regular writes
force a memtable flush
Rollback the leaf transaction.
Test txn1 and txn2 sharing a lock and txn2 trying to upgrade lock.
Verify B is locked and A and C are not
Snapshot was created before change to '2'
heap should not show any logs
Verify "A" "C" "B" are no longer locked
Should fail since column family was dropped.
Test txn1 trying to downgrade its lock.
after memtable flush we can now relese the log
verify foo2 is locked by txn
valid set name
The iterator points to an unordered_multimap
thus the test can not assume any particular order.
commit time put
Calculate next buffer len, plateau at 5 when 5 records are inserted.
Write some keys to the db after the snapshot
comment: TODO(myabandeh): Instantiate the tests with other write policies
label: code-design
In this test, txn1 should succeed committing,
as the callback is called after txn1 starts committing.
unexpected failure
We want the last transaction in the chain to block and hold everyone
back.
Transaction should only write the keys that succeeded.
txn2 should be expired out since txn1 waiting until its timeout expired.
now we pause background work so that
imm()s are not flushed before we can check their status
ROCKSDB_LITE
deleting transaction should unregister transaction
Complete the cycle Tlen -> T1
Header (12 bytes) + NOOP (1 byte) + 2 * 8 bytes for data.
10ms
verify data txn data
Should fail after encountering a write to Z in SST file
This Put outside of a transaction will conflict with a later write
Committing txn should release its locks and allow txn2 to proceed
transaction writes have 10ms timeout,
db writes have infinite timeout
100 minutes
1ms
rollback to 1
Txn should commit, but only write foo2 and foo3
our log should be in the heap
name too long
The locked key is "foo" and is locked by txn1
Downsize to 0 and verify the size is consistent.
flush only cfa memtable
commit in LOG B
Verify A,B,D,E,F,H are still locked and C,G are not.
According to db.h, doing a SingleDelete on a key that has been
overwritten will have undefinied behavior. So it is unclear what the
result of fetching "A" should be. The current implementation will
return NotFound in this case.
log cannot be flushed because txn2 has not been commited
force a memtable flush
Since our test db has max_write_buffer_number=2, this flush will cause
the first memtable to get purged from the MemtableList history.
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
else commit it
dummy put to inc db seq
Rollback to 2
but now our memtable should be referencing the prep section
conflict
commit old txn
100 minutes
txn2 should be able to write to X since txn1 has expired
We want the leaf transactions to block and hold everyone back.
have to open default column family
assert that cfa has a flush requested
Conflict
Create N threads that use RandomTransactionInserter to write
many transactions.
Verify A,B,F are still locked and C,D,E,G,H are not.
Cannot lock B since it was written after the snapshot was set
put txn2 prep section in this log
make commit
dummy put to inc db seq
Should still fail after "downgrading".
cfb should not be flushed becuse it has no data from LOG A
make sure we are on a new log
1
can't rename after prepare
Set up a long wait for chain like this:
T1 -> T2 -> T3 -> ... -> Tlen
Now change "B".
"C" was modified after txn's snapshot
1 ms
shouldn't be able to prepare
Test shared access between txns
Force txn1 to expire
We increase the db seq artificailly by a dummy Put. Check that this
technique is effective and db seq is that same as ours.
namespace
verify that we track multiple writes to the same key at different snapshots
Safety check to make sure the test actually ran
Write some keys in a txn
Use small commit cache to trigger lots of eviction and fast advance of
max_evicted_seq_
will take effect after ReOpen
This will conflict since the snapshot is earlier than another write to ZZZ
find trans in list of prepared transactions
value is readable from txn
do prepare for a transaction
dummy put to inc db seq
All results should fail since there was a conflict
Write some keys to the db
Test txn1 holding an exclusive lock and txn2 trying to obtain shared
access.
nothing has been prepped yet
Number of snapshots taken so far
Conflict's with txn1's MultiGetForUpdate
Upsize from 0 to verify the size is persistent.
should show not dependency on logs
Test 2 transactions writing to the same key in multiple orders and
with/without snapshots
Snapshot was set before D was written
regular db read
transaction should no longer be visible
3
4
value is readable form txn
3
Rollback to 3
Read all keys via iter and lock them all
close
Verify that "A", "B", "C" are still locked
prepare
We keep the list of txns comitted before we take the last snaphot.
These should be the only seq numbers that will be found in the snapshot
Verify the size of the buffer and the single path.
Set txn expiration timeout to 0 microseconds (expires instantly)
Set up a wait for chain like this:
Tn -> T(n*2)
Tn -> T(n*2 + 1)
So we have:
T1 -> T2 -> T4 ...
| |> T5 ...
|> T3 -> T6 ...
|> T7 ...
up to T31, then T[16 - 31] -> T1.
Note that Tn holds lock on floor(n / 2).
Wait until all threads are waiting on each other.
to restart the db
Lock mostly for shared access, but exclusive 1/4 of the time.
Rollback the last transaction.
Column family is 1 or 0 (cfa).
Verify A,B,C are locked
Conflicts with previous GetForUpdate
No snapshot created yet
Should fail since column family was dropped
roll to LOG B
no longer is prpared results
txn1 has a lock timeout longer than txn2's expiration, so it will win
Setting the key-space to be 100 keys should cause enough write-conflicts
to make this test interesting.
Take the final snapshot if it is not already taken
Verify F is still locked and A,B,C,D,E,G,H are not.
Complete the cycle T2 -> T1 with a shared lock.
Take preliminary snapshots
Rollback to beginning of txn
kill and reopen
To stress the data structure that maintain prepared txns, at each cycle
we add a new prepare txn. These do not mean to be committed for
snapshot inspection.
Since we do not actually write to db, we mock the seq as it would be
increaased by the db. The only exception is that we need db seq to
advance for our snapshots. for which we apply a dummy put each time we
increase our mock of seq.
transaction put in two column families
Create a cycle of size 2.
regular put so that mem table can actually be flushed for log rolling
Snapshot was set before C was written
We compare whether the set of txns locking this key is the same. To do
this, we need to sort both vectors so that the comparison is done
correctly.
In the above the latest change to AAAZZZ in handles[1] is delete.
put new txn values
The original value should still be read
value is now available
Should fail after encountering a write to S in SST file
At each step we prepare a txn and then we commit it in the next txn.
This emulates the consecuitive transactions that write to the same key
Drop first column family
transaction expired!
rollback to 2
Test conflict checking against the very first write to a db.
The transaction's snapshot is a seq 0 while the following write
will have sequence 1.
Conflicts with previous GetForUpdate.
Since db writes do not have a timeout, this should eventually succeed when
the transaction expires.
Wait for some gap before taking the final snapshot
According to db.h, doing a SingleDelete on a key that has been
overwritten will have undefinied behavior. So it is unclear what the
result of fetching "F" should be. The current implementation will
return NotFound in this case.
If the snapshot is taken, verify seq numbers visible to it. We redo
it at each cycle to test that the system is still sound when
max_evicted_seq_ advances.
Verify that transaction wrote foo2 and foo3 but not foo
namespace rocksdb
re-locking same key shouldn't put us over the limit
Verify transaction rollback works for untracked keys.
cant prepare txn without name
Reinitialize transaction to no long expire
cant reset name
Snapshot should not have changed yet.
Conflicts with write done after snapshot taken
Contrived case of shared lock of cycle size 2 to verify that a shared
lock causing a deadlock is correctly reported as "shared" in the buffer.
heap should still see first log
new value is readable from txn
* 1) use prepare to keep first log around to determine starting sequence
* during recovery.
* 2) insert many values, skipping wal, to increase seqid.
* 3) insert final value into wal
* 4) recover and see that final value was properly recovered - not
* hidden behind improperly summed sequence ids
Test WritePreparedTxnDB's IsInSnapshot against different ordering of
snapshot, max_committed_seq_, prepared, and commit entries.
Any other operation does
Test conflict checking against the very first write to a db.
The transaction's snapshot will have seq 1 and the following write
will have sequence 1.
Offset of the final entry in the dlock path from the root's txn id.
open DB with three column families
commit txn1
comment: offset by 2 from the max depth to test edge case
label: test
txn2 should not be able to write to X since txn1 has it locked
comment: value is nolonger readable
label: code-design
request a flush for all column families such that the earliest
alive log file can be killed
log has been marked
Potentially conflicting writes
transaction put
Downsize the buffer and verify the 3 latest deadlocks are preserved.
Make sure at least some of the transactions succeeded. It's ok if
some failed due to write-conflicts.
Same for snapshot cache size
txn2 should now be able to write to X
3
4
A Get does not generate the snapshot
all data in LOG A resides in a memtable that has been
requested for a flush
Verify A,B,D,E,F are still locked and C,G,H are not.
Complete the cycle T[16 - 31] -> T1
create second cf
crash
we already committed
This write will cause a conflict with the earlier batch write
Special case for a deadlock path that exceeds the maximum depth.
do all the writes
write prep section to wal
lock limit reached
Should not conflict with txn2 since snapshot wasn't set until
GetForUpdate was called.
Verify that A and B are no longer locked
If cur_txn is not started, do prepare for it.
Lock keys in random order.
issue rollback
Rollback to 4
heap should not care about prepared section anymore
This Put outside of a transaction will conflict with the previous write
Write a bunch of keys to db to force a compaction
Verify snapshots get reinitialized correctly
Open DB with a lock limit of 3
Verify the exclusivity field of the transactions in the deadlock path.
expired!
txn should commit since the flushed table is still in MemtableList History
Verify A,B,C,D,E,F are still locked
Offset of each txn id from the root of the shared dlock tree's txn id.
we should see txn1s log refernced by the memtables
lock key in cfa
verify non txn data
Put a random key so we have a memtable to flush
Modify BBB before snapshot is taken
Untracked writes should succeed even though key was written after snapshot
As an extra check, check if prepared set will be properly empty after
they are committed.
txn read
Wait for all threads to run
flush to next wal
cant have duplicate name
Column family is 0 (default) or 1.
Test different table factories
500ms
These keys do not conflict with existing writes since they're in
different column families
Snapshot has now been cleared
open the new column families
lock key in default cf
Number of gaps applied so far
2
heap should now show txn2s log
Rollback to 3
100ms
Modify key after transaction start
We continue until max advances a bit beyond the snapshot.
Verify that A is now unlocked
exclusive
Should succeed after verifying there is no write to X in SST file
still not available to db
transaction writes have an infinite timeout,
but we will override this when we start a txn
db writes have infinite timeout
Verify that data is consistent
Iterates backwards over path verifying decreasing txn_ids.
cfb now has data from LOG A
commit txn2
Read and write without a snap
flush default cf to crate new log
verify foo3 is locked by txn
we should see that cfb now has a flush requested
Leave some gap between the preliminary snapshots and the final snapshot
that we check. This should test for also different overlapping scnearios
between the last snapshot and the commits.
The final snapshot that we will inspect
Read and write with snapshot
Test txn1 and txn2 sharing a lock and txn3 trying to obtain it.
name too short
issue rollback (marker written to WAL)
Create 2 new column families
Should commit since not expired
100ms
txn timeout no longer infinite
Verify A,B are locked and C is not
Verify that A and B are still locked
Test to make sure transactions work when there are no other writes in an
empty db.
txn1 should fail to commit since it is expired
comment: Take some preliminary snapshots first. This is to stress the data structure
that holds the old snapshots as it will be designed to be efficient when
only a few snapshots are below the max_evicted_seq_.
label: code-design
prepre transaction in LOG A
"X" currently locked
regular db put
Rollback to 1
Read and write without a snapshot
data not im mem yet
Verify that A is locked
Should fail after encountering a write to S in memtable
Verify A,B,E,F are still locked and C,D,G,H are not.
T=0:Insert Set1.
Puts num_entries starting from start_pos_map from kvmap_ into the database
If TTL is non positive or not provided, the behaviour is TTL = infinity
This test opens the db 3 times with such default behavior and inserts a
bunch of kvs each time. All kvs should accumulate in the db till the end
Partitions the sample-size provided into 3 sets over boundary1 and boundary2
T=0:Open the db with ttl = 2
T=0:Insert Set1. Delete at t=2
T=1:Set1 should still be there
Makes a write-batch with key-vals from kvmap_ and 'Write''s it
Choose carefully so that Put, Gets & Compaction complete in 1 second buffer
T=0:Open the db with ttl = 2
T=0:Insert Set1. Delete at t=2
T=2:Set1 should not be there
check all insertions done
only column family 1 should be alive after 4 seconds
T=2:Set1 should still be there
Works on keys of the form "key<number>"
Drops key if number at the end of key is in [0, kSampleSize_/3),
Keeps key if it is in [kSampleSize_/3, 2*kSampleSize_/3),
Change value if it is in [2*kSampleSize_/3, kSampleSize_)
Eg. kSampleSize_=6. Drop:key0-1...Keep:key2-3...Change:key4-5...
Resets the timestamp of a set of kvs by updating them and checks that they
are not deleted according to the old timestamp
dbiter should have found out kvmap_[st_pos]
T=0.Delete at t=1
T=2: Set should not be there
T=0:Open the db normally
T=0:Insert Set1. Delete at t=1
everything should be there after 1 second
Sleeps for slp_tim then runs a manual compaction
Checks span starting from st_pos from kvmap_ in the db and
Gets should return true if check is true and false otherwise
Also checks that value that we got is the same as inserted; and =kNewValue
if test_compaction_change is true
Part dropped
Part kept
Part changed
nothing should be there after 6 seconds
Checks presence while opening the same db more than once with the same ttl
Note: The second open will open the same db
Similar to PresentDuringTTL but uses Iterator
T=0: Insert. Delete at t=1
T=2: Should not be there
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Similar as SleepCompactCheck but uses TtlIterator to read from db
db should be closed before opening again
Open database with TTL support in read_only mode
T=0: Insert. Delete at t=2
Puts a set of values and checks its absence using Get after ttl
class TtlTest
T=0: Insert Set1. Delete at t=3
T=2
T=2: Insert Set1. Delete at t=5
T=4: Set1 should still be there
Populates and returns a kv-map
!ROCKSDB_LITE
checks the whole kvmap_ to return correct values using KeyMayExist
checks the whole kvmap_ to return correct values using MultiGet
T=3: Set3 never deleted
T=4: Sets 1,2,3 still there
namespace rocksdb
Keep keys not matching the format "key<NUMBER>"
Open database with TTL support when TTL provided with db_ttl_ pointer
Runs a manual compaction
T=0. Delete at t=2
T=1: Set should be there
T=0:Insert Set1. Delete at t=1
T=2: TTL logic takes precedence over TestFilter:-Set1 should not be there
ensure that compaction is kicked in to always strip timestamp from kvs
T=0: Insert. Delete at t=2
T=1: Set should be there
T=0: Set1 never deleted
T=1: Set1 still there
T=0: Set deleted at t=3
T=2: Set should be there
Insert some key-values which KeyMayExist should be able to get and check that
values returned are fine
Put a mock kv at the end because CompactionFilter doesn't delete last key
A black-box test for the ttl wrapper around rocksdb
Open with TestFilter compaction filter
Similar to AbsentAfterTTL but uses Iterator
Checks presence during ttl in read_only mode
Checks user's compaction filter for correctness with TTL logic
T=1: Set2 never deleted
T=2: Sets1 & 2 still there
compaction should take place always from level0 for determinism
Checks whether WriteBatch works well with TTL
Puts all kvs in kvmap_ in a batch and writes first, then deletes first half
T=0: Insert. Delete at t=1
Checks absence while opening the same db more than once with the same ttl
Note: The second open will open the same db
Puts a set of values and checks its presence using Get during ttl
Checks presence while opening the same db more than once with bigger ttl
Open database with TTL support when TTL not provided with db_ttl_ pointer
namespace rocksdb
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
This source code is licensed under both the GPLv2 (found in the
COPYING file in the root directory) and Apache 2.0 License
(found in the LICENSE.Apache file in the root directory).
Copyright (c) 2011 The LevelDB Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. See the AUTHORS file for names of contributors.
Verify index column family
only delta has it
Sort entries by value
rollback to 6
both has it. Delta should win
rollback to 4
Verify WriteBatch can be iterated
5
namespace anonymous
rollback to 5
In this test, we insert <key, value> to column family `data`, and
<value, key> to column family `index`. Then iterator them in order
and seek them by key.
Neither iterator has it.
Seek to First
Next
Seek to random key
Random walk and make sure iter and result_iter returns the
same key and value
new value
1
only delta has it. Delta is delete
Iterator all keys
Prev
Iterator all indexes
Seek to every key
2
namespace
no savepoint found
Seek the keys one by one in reverse order
Tests that we can write to the WBWI while we iterate (from a single thread).
iteration should see the newest writes
Test batch with overwrite_key=true
"mm" is deleted, so we're back at "m"
!ROCKSDB_LITE
both has it. Delta is delete
Seek to last
6
still the same value
stress testing mutations with IteratorWithBase
3
4
only base has it
Verify data column family
overwrite_key
rollback to 1
Clear batch and re-run test with new values
Sort entries by key
Test the case that there is one element in the write batch
Seek to every index
rollback to 3
same thing as above, but testing IteratorWithBase
No merge operator specified.
rollback to 2
default column family
comment: Do not drop data if compile with ASAN to suppress leak warning.
label: code-design
!__SANITIZE_ADDRESS__
Write batch into transaction db
Merge a key inside a transaction
Put a key outside a transaction
Read a key inside a transaction
Read a key inside a transaction
Merge a key outside a transaction
Create an iterator outside a transaction
Deletions obsoleted before bottom level due to file gap optimization.
avoid underflow
Whether there is an active snapshot in range [lower_bound, upper_bound).
Set memtable_info for memtable sealed callback
Blob DB only
Blob DB only
comment: TODO(yiwu): The property is currently available for fifo compaction
with allow_compaction = false. This is because we don't propagate
oldest_key_time on compaction.
label: code-design
version
db
If fail, the timestamp is already set.
if user keeps adding entries that exceeds write_buffer_size, we need to
flush earlier even though we still have much available memory left.
Dynamically change the memtable's capacity. If set below the current usage,
the next key added will trigger a flush. Can only increase size when
memtable prefix bloom is disabled, since we can't easily allocate more
space.
Timestamp of oldest key
Dynamically changeable memtable option
Returns an estimate of the timestamp of the earliest key.
retrieve all snapshot numbers up until max_seq. They are sorted in
ascending order.
Whether there is an active snapshot in range [lower_bound, upper_bound).
Make sure there are no files on or beyond num_levels().
comment: Store states of levels larger than num_levels_. We do this instead of
storing them in levels_ to avoid regression in case there are no files
on invalid levels. The version is not consistent if in the end the files
on invalid levels don't cancel out.
label: code-design
Whether there are invalid new files or invalid deletion on levels larger
than num_levels_.
Creating an already existing file on invalid level.
Deleting an non-existing file on invalid level.
Same as PutCF except for value type.
The Slice pointed by pinnable_val is not valid after this point
Reset PinnableSlice after each use and before each reuse
If the value is not pinned, the internal buffer must have the value.
If it cannot pin the value, it copies the value to its internal buffer.
The intenral buffer could be set during construction.
This snapshot should be freed using rocksdb_free
Move consturctor and move assignment is allowed.
No copy constructor and copy assignment allowed.
used internally by BlobDB.
"rocksdb.estimate-oldest-key-time" - returns an estimation of
oldest key timestamp in the DB. Currently only available for
FIFO compaction with
compaction_options_fifo.allow_compaction = false.
"rocksdb.estimate-oldest-key-time"
Determines whether the MergeOperator can be called with just a single
merge operand.
Override and return true for allowing a single operand. FullMergeV2 and
PartialMerge/PartialMergeMulti should be implemented accordingly to handle
a single operand.
bytes for vals returned by Get
bytes for vals returned by MultiGet
bytes for keys/vals decoded by iterator
No copy constructor and copy assignment allowed.
Deletions obsoleted before bottom level due to file gap optimization.
Timestamp of the earliest key. 0 means unknown.
An overload of the the above method that receives a PinnableSlice
For backward compatiblity a default implementation is provided
comment: TODO(myabandeh): Not implemented yet
write data after the prepare phase of 2pc
TODO(myabandeh): Not implemented yet
write data before the prepare phase of 2pc
label: requirement
empty path, limit exceeded constructor and default constructor
Stores the number of latest deadlocks to track
An overload of the the above method that receives a PinnableSlice
* Class: org_rocksdb_SstFileWriter
* Method: merge
* Signature: (J[B[B)V
* Class: org_rocksdb_SstFileWriter
* Method: delete
* Signature: (JJJ)V
exception thrown: OutOfMemoryError
* Class: org_rocksdb_SstFileWriter
* Method: put
* Signature: (JJJ)V
*
* Add a Merge key with value to currently opened file.
*
* @param key the specified key to be merged.
* @param value the value to be merged with the current value for
* the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*
* Add a deletion key to currently opened file.
*
* @param key the specified key to be deleted.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*
* Add a Put key with value to currently opened file.
*
* @param key the specified key to be inserted.
* @param value the value associated with the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
If you change this, you also need to change
size of array buckets_ in HistogramImpl
comment: Extracts two most significant digits to make histogram buckets more
human-readable. E.g., 172 becomes 170.
label: code-design
109==BucketMapper::BucketCount()
namespace rocksdb
to PlainTableOptions just like bloom_bits_per_key
comment: Separate inlines so they can be replaced if needed
label: code-design
Before read partitions, prefetch them to avoid lots of IOs
After prefetch, read the partitions one by one
The partitions of partitioned index are always stored in cache. They
are hence follow the configuration for pin and prefetch regardless of
the value of cache_index_and_filter_blocks
prefetch_buffer
Read the last block's offset
This is a possible scenario since block cache might not have had space
for the partition
on-stack BlockIter while the state is on heap. Currentlly it assumes
the first level iter is always on heap and will attempt to delete it
in its destructor.
Index partitions are assumed to be consecuitive. Prefetch them all.
Read the first block offset
pre-fetching of blocks is turned on
Refer to the comment above about paritioned indexes always being
cached
comment: unused
label: code-design
Prefetch all the blocks referenced by this index to the buffer
checksum type (char, 1 byte)
Blob value not supported. Stop.
comment: TODO(myabandeh): if instead of filter object we store only the blocks in
block cache, then we don't have to manually earse them from block cache
here.
label: code-design
Before read partitions, prefetch them to avoid lots of IOs
After prefetch, read the partitions one by one
comment: TODO(myabandeh): merge this with the same function in IndexReader
label: code-design
prefetch_buffer
Read the last block's offset
This is a possible scenario since block cache might not have had space
for the partition
Index partitions are assumed to be consecuitive. Prefetch them all.
Read the first block offset
comment: If enabled, blob DB periodically cleanup stale data by rewriting remaining
live data in blob files to new files. If garbage collection is not enabled,
blob files will be cleanup based on TTL.
label: code-design
The smallest value to store in blob log. Value larger than this threshold
will be inlined in base DB together with the key.
Disable all background job. Used for test only.
wopts
options
column_family
Blob DB doesn't support non-default column family.
comment: TODO(yiwu): Blob indexes will be remove by BlobIndexCompactionFilter.
We can just drop the blob record.
label: requirement
Write callback for garbage collection to check if key has been updated
since last read. Similar to how OptimisticTransaction works. See inline
comment in GCFileAndUpdateLSM().
Allocate the buffer. This is safe in C++11
Note that std::string::reserved() does not work, since previous value
of the buffer can be larger than blob_index.size().
Upper bound of sequence number to proceed.
Error.
error
value_found
Get a snapshot to avoid blob file get deleted between we
fetch and index entry and reading from the file.
Similar to OptimisticTransaction, we obtain latest_seq from
base DB, which is guaranteed to be no smaller than the sequence of
current key. We use a WriteCallback on write to check the key sequence
on write. If the key sequence is larger than latest_seq, we know
a new versions is inserted and the old blob can be disgard.
We cannot use OptimisticTransaction because we need to pass
is_blob_index flag to GetImpl.
allow_blob
concrete at this time. also necessary to add to open_ttl_files_
Key to check
Hold a lock in the beginning to avoid updates to base DB during the call
comment: TODO(yiwu): In case there are multiple writers the latest sequence would
not be the actually sequence we are writting. Need to get the sequence
from write batch after DB write instead.
label: code-design
Inlined with TTL
cache_only
Double check the file is not obsolete by others
Either the key is deleted or updated with a newer version whish is
inlined in LSM.
comment: Get a snapshot to avoid blob file get deleted between we
fetch and index entry and reading from the file.
TODO(yiwu): For Get() retry if file not found would be a simpler strategy.
label: code-design
reset oldest_file_evicted flag
comment: TODO(yiwu): If index_entry is a PinnableSlice, we can also pin the same
memory buffer to avoid extra copy.
label: code-design
Release write_mutex_ before DB write to avoid race condition with
flush begin listener, which also require write_mutex_ to sync
blob files.
Put as normal value
comment: TODO(yiwu): correct the stats and expose it.
label: code-design
comment: TODO(yiwu): Add an option to skip crc checking.
label: code-design
Close a file if its size exceeds blob_file_size
opened non-TTL blob file.
Close a file by appending a footer, and removes file from open files list.
when should oldest file be evicted:
on reaching 90% of blob_dir_size
Create a snapshot if there isn't one in read options.
Return true if a snapshot is created.
comment: TODO(yiwu): Should return column family id encoded in blob file after
we add blob db column family support.
label: code-design
Format of blob log file header (30 bytes):
+--------------+---------+---------+-------+-------------+-------------------+
| magic number | version | cf id | flags | compression | expiration range |
+--------------+---------+---------+-------+-------------+-------------------+
| Fixed32 | Fixed32 | Fixed32 | char | char | Fixed64 Fixed64 |
+--------------+---------+---------+-------+-------------+-------------------+
List of flags:
has_ttl: Whether the file contain TTL data.
Expiration range in the header is a rough range based on
blob_db_options.ttl_range_secs.
header include fields up to blob CRC
Format of blob log file footer (48 bytes):
+--------------+------------+-------------------+-------------------+------------+
| magic number | blob count | expiration range | sequence range | footer CRC |
+--------------+------------+-------------------+-------------------+------------+
| Fixed32 | Fixed64 | Fixed64 + Fixed64 | Fixed64 + Fixed64 | Fixed32 |
+--------------+------------+-------------------+-------------------+------------+
The footer will be presented only when the blob file is properly closed.
Unlike the same field in file header, expiration range in the footer is the
range of smallest and largest expiration of the data in this file.
Blob record format (32 bytes header + key + value):
+------------+--------------+------------+------------+----------+---------+-----------+
| key length | value length | expiration | header CRC | blob CRC | key | value |
+------------+--------------+------------+------------+----------+---------+-----------+
| Fixed64 | Fixed64 | Fixed64 | Fixed32 | Fixed32 | key len | value len |
+------------+--------------+------------+------------+----------+---------+-----------+
If file has has_ttl = false, expiration field is always 0, and the blob
doesn't has expiration.
Also note that if compression is used, value is compressed value and value
length is compressed value length.
Header CRC is the checksum of (key_len + val_len + expiration), while
blob CRC is the checksum of (key + value).
We could use variable length encoding (Varint64) to save more space, but it
make reader more complicated.
0x00248f37
comment: A very rare event, in which the commit entry is updated before we do.
Here we apply a very simple solution of retrying.
TODO(myabandeh): do precautions to detect bugs that cause infinite loops
label: code-design
We should not normally reach here
It is committed and also not evicted from commit cache
This is to avoid updating the snapshots_ if it already updated
with a more recent vesion by a concrrent thread
The list might get updated concurrently as we are reading from it. The
reader should be able to read all the snapshots that are still valid
after the update. Since the survived snapshots are written in a higher
place before gets overwritten the reader that reads bottom-up will
eventully see it.
comment: TODO(myabandeh): implement lock-free commit_cache_
label: code-design
then snapshot_seq < commit_seq
overlapping range
When advancing max_evicted_seq_, we move older entires from prepared to
delayed_prepared_. Also we move evicted entries from commit cache to
old_commit_map_ if it overlaps with any snapshot. Since prep_seq <=
max_evicted_seq_, we have three cases: i) in delayed_prepared_, ii) in
old_commit_map_, iii) committed with no conflict with any snapshot (i)
delayed_prepared_ is checked above
then (ii) cannot be the case
only (iii) is the case: committed
commit_seq <= max_evicted_seq_ < snapshot_seq => commit_seq <
snapshot_seq
initialized
comment: Here we try to infer the return value without looking into prepare list.
This would help avoiding synchronization over a shared map.
TODO(myabandeh): read your own writes
TODO(myabandeh): optimize this. This sequence of checks must be correct but
not necessary efficient
label: code-design
At this point we dont know if it was committed or it is still prepared
else (ii) might be the case: check the commit data saved for this snapshot.
If there was no overlapping commit entry, then it is committed with a
commit_seq lower than any live snapshot, including snapshot_seq.
When max_evicted_seq_ advances, move older entries from prepared_txns_
to delayed_prepared_. This guarantees that if a seq is lower than max,
then it is not in prepared_txns_ ans save an expensive, synchronized
lookup from a shared set. delayed_prepared_ is expected to be empty in
normal cases.
Not evicted from cache and also not present, so must be still prepared
continue the search if the next snapshot could be smaller than commit_seq
We update the list concurrently with the readers.
Both new and old lists are sorted and the new list is subset of the
previous list plus some new items. Thus if a snapshot repeats in
both new and old lists, it will appear upper in the new list. So if
we simply insert the new snapshots in order, if an overwritten item
is still valid in the new list is either written to the same place in
the array or it is written in a higher palce before it gets
overwritten by another item. This guarantess a reader that reads the
list bottom-up will eventaully see a snapshot that repeats in the
update, either before it gets overwritten by the writer or
afterwards.
We use this to identify how fresh are the snapshot list. Since this
is done atomically with obtaining the snapshot list, the one with
the larger seq is more fresh. If the seq is equal the full snapshot
list could be different since taking snapshots does not increase
the db seq. However since we only care about snapshots before the
new max, such recent snapshots would not be included the in the
list anyway.
snapshot_seq < prep_seq <= commit_seq => snapshot_seq < commit_seq
If we do not store an entry in old_commit_map we assume it is committed in
all snapshots. if commit_seq <= snapshot_seq, it is considered already in
the snapshot so we need not to keep the entry around for this snapshot.
comment: TODO(myabandeh) inc max in larger steps to avoid frequent updates
label: code-design
Storing once is enough. No need to check it for other snapshots.
continue the search if the next snapshot could be larger than prep_seq
We only care about snapshots lower then max
Returns true if commit_seq <= snapshot_seq
After each eviction from commit cache, check if the commit entry should
be kept around because it overlaps with a live snapshot.
First check the snapshot cache that is efficient for concurrent access
10m entry, 80MB size
Items could have moved from the snapshots_ to snapshot_cache_ before
accquiring the lock. To make sure that we do not miss a valid snapshot,
read snapshot_cache_ again while holding the lock.
With each change to max_evicted_seq_ fetch the live snapshots behind it
It is not committed, so it must be still prepared
with any concurrent transactions. The easiest way to do this is to wrap all
(ii) it the case: it is committed but after the snapshot_seq
Update the size at the end. Otherwise a parallel reader might read
items that are not set yet.
comment: Then access the less efficient list of snapshots_
label: code-design
comment: Insert them to a vector that is less efficient to access
concurrently
label: code-design
Then it is not committed yet
Rewrite the entry with the index indexed_seq in the commit table with the
commit entry <prep_seq, commit_seq>. If the rewrite results into eviction,
sets the evicted_entry and returns true.
Add the trasnaction with prepare sequence seq to the prepared list
Add a new entry to old_commit_map_ if prep_seq <= snapshot_seq <
commit_seq. Return false if checking the next snapshot(s) is not needed.
This is the case if the entry already added to old_commit_map_ or none of
the next snapshots could satisfy the condition. next_is_larger: the next
snapshot will be a larger value
comment: 2nd list for storing snapshots. The list sorted in ascending order.
Thread-safety is provided with snapshots_mutex_.
label: requirement
Rewrite the entry with the index indexed_seq in the commit table with the
commit entry new_entry only if the existing entry matches the
expected_entry. Returns false otherwise.
Check whether the transaction that wrote the value with seqeunce number seq
is visible to the snapshot with sequence number snapshot_seq
A heap of prepared transactions. Thread-safety is provided with
prepared_mutex_.
comment: A set of long-running prepared transactions that are not finished by the
time max_evicted_seq_ advances their sequence number. This is expected to
be empty normally. Thread-safety is provided with prepared_mutex_.
label: requirement
Already popped, ignore it.
comment: The list sorted in ascending order. Thread-safety for writes is provided
with snapshots_mutex_ and concurrent reads are safe due to std::atomic for
each entry. In x86_64 architecture such reads are compiled to simple read
instructions. 128 entries
TODO(myabandeh): avoid non-const static variables
label: requirement
comment: unused
label: code-design
Add the transaction with prepare sequence prepare_seq and commit sequence
commit_seq to the commit map
The largest evicted *commit* sequence number from the commit_cache_
A map of the evicted entries from commit_cache_ that has to be kept around
to service the old snapshots. This is expected to be empty normally.
Thread-safety is provided with old_commit_map_mutex_.
Update when delayed_prepared_.empty() changes. Expected to be true
normally.
The version of the latest list of snapshots. This can be used to avoid
rewrittiing a list that is concurrently updated with a more recent version.
The list of live snapshots at the last time that max_evicted_seq_ advanced.
The list stored into two data structures: in snapshot_cache_ that is
efficient for concurrent reads, and in snapshots_ if the data does not fit
into snapshot_cache_. The total number of snapshots in the two lists
A heap with the amortized O(1) complexity for erase. It uses one extra heap
to keep track of erased entries that are not yet on top of the main heap.
commit_cache_ must be initialized to zero to tell apart an empty index from
a filled one. Thread-safety is provided with commit_cache_mutex_.
Get the commit entry with index indexed_seq from the commit table. It
returns true if such entry exists.
(heap_.top() > seq)
Down the heap, remember to pop it later
comment: TODO(myabandeh): avoid non-const static variables
label: code-design
Update when old_commit_map_.empty() changes. Expected to be true normally.
else value is already assigned
read_only
Resize the buffer to the target size and restore the buffer's idx
Reversing the normalized vector returns the latest deadlocks first
Next write occurs at a nonexistent path's slot
Drop the deadlocks that will no longer be needed ater the normalize
callback
comment: TODO(myabandeh): prevent the users from writing to txn after the prepare
phase
label: code-design
log ref
any operations appended to this working_batch will be ignored from WAL
We take the commit-time batch and append the Commit marker.
The Memtable will ignore the Commit marker in non-recovery mode
else value is already assigned
Since the lifetime of the WriteBatch is the same as that of the transaction
we cannot pin it as otherwise the returned value will not be available
after the transaction finishes.